:root {
  --bg: #0b1320;
  --panel: #111c2f;
  --panel-2: #18253c;
  --ink: #e7eef7;
  --ink-dim: #93a4bb;
  --accent: #38bdf8;
  --accent-2: #22d3ee;
  --warn: #fbbf24;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

header {
  padding: 12px 18px;
  background: linear-gradient(90deg, #0b1320 0%, #142136 100%);
  border-bottom: 1px solid #1f2c44;
  display: flex;
  align-items: baseline;
  gap: 14px;
}
header h1 { margin: 0; font-size: 18px; letter-spacing: 0.3px; }
header .hint { color: var(--ink-dim); font-size: 13px; }

main { flex: 1; position: relative; overflow: hidden; }
#map { position: absolute; inset: 0; }

#panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 420px;
  max-width: 100vw;
  background: var(--panel);
  border-left: 1px solid #1f2c44;
  padding: 18px;
  overflow-y: auto;
  z-index: 1100;
  box-shadow: -10px 0 30px rgba(0,0,0,0.35);
  transform: translateX(0);
  transition: transform 0.22s ease;
}

/* While the report panel is open, hide map controls that overlap it */
body.report-open .leaflet-top.leaflet-right,
body.report-open .leaflet-bottom.leaflet-right {
  display: none;
}
#panel.hidden { transform: translateX(105%); }

#panel-close {
  position: sticky;
  top: 0;
  float: right;
  width: 40px;
  height: 40px;
  margin: -8px -8px 0 8px;
  background: var(--panel-2);
  border: 1px solid #2a3a58;
  border-radius: 50%;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
}
#panel-close:hover, #panel-close:active {
  background: var(--accent);
  color: #0b1320;
  border-color: var(--accent);
}

#panel h2 { margin: 0 0 4px; font-size: 20px; }
#panel .meta { margin: 0 0 14px; color: var(--ink-dim); font-size: 13px; }

.now { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.now-card {
  background: var(--panel-2);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.now-label { color: var(--ink-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; }
.now-value { font-size: 18px; font-weight: 600; margin-top: 4px; color: var(--accent); }
.now-sub { font-size: 11px; color: var(--ink-dim); margin-top: 2px; }

.cam-block { margin-bottom: 22px; }
.cam-block.hidden { display: none; }
.cam-block h3 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#cam-img-link { display: block; line-height: 0; }
#cam-img {
  width: 100%;
  height: auto;
  max-height: 240px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--panel-2);
  display: block;
}
.cam-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  font-size: 11px;
}
.cam-updated { color: var(--ink-dim); }
#cam-link { color: var(--accent); text-decoration: none; }
#cam-link:hover { text-decoration: underline; }

.chart-block { margin-bottom: 22px; }
.chart-block h3 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.chart-wrap {
  position: relative;
  height: 200px;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 6px;
}
.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.wind-quality-legend, .period-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.wq { padding: 2px 6px; border-radius: 4px; color: #0b1320; }
.wq-offshore { background: #22c55e; }
.wq-cross    { background: #eab308; }
.wq-onshore  { background: #ef4444; color: #fff; }
.period-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 10px;
  color: var(--ink-dim);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.period-gradient {
  flex: 0 0 130px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(
    to right,
    rgb(71,85,105) 0%,
    rgb(14,165,233) 30%,
    rgb(6,182,212) 50%,
    rgb(20,184,166) 70%,
    rgb(168,85,247) 100%
  );
}
.period-legend-note { color: #6b7a92; margin-left: 4px; font-style: italic; }

.tide-events {
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-dim);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 12px;
}
.tide-events .hi { color: var(--accent-2); }
.tide-events .lo { color: var(--warn); }

/* Surf shops nearby (collapsible) */
.shops-block { margin-bottom: 18px; }
.shops-block .shops-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.shops-block .shops-summary::-webkit-details-marker { display: none; }
.shops-block .shops-summary::before {
  content: '▸';
  display: inline-block;
  font-size: 11px;
  color: var(--ink-dim);
  transition: transform 0.18s ease;
  width: 12px;
  text-align: center;
}
.shops-block[open] .shops-summary::before { transform: rotate(90deg); }
.shops-count {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-dim);
  text-transform: none;
  letter-spacing: 0;
}
.shops-block > #shops-list {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid #1f2c44;
}
.shop-card {
  background: var(--panel-2);
  border: 1px solid #1f2c44;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}
.shop-photo {
  width: 100%;
  height: 130px;
  object-fit: cover;
  display: block;
  background: #0e1a2c;
}
.shop-photo-fav {
  height: 64px;
  object-fit: contain;
  padding: 14px;
  background: #0e1a2c;
}
.shop-photo-empty {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--ink-dim);
  background: #0e1a2c;
}
.shop-card-body { padding: 10px 12px 12px; }
.shop-card-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  justify-content: space-between;
}
.shop-card .shop-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.shop-card .shop-dist {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(56, 189, 248, 0.14);
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}
.shop-card-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 3px 0 4px;
}
.shop-rating {
  font-size: 12px;
  color: #fbbf24;
  font-weight: 600;
}
.shop-rating-count { color: var(--ink-dim); font-weight: 400; }
.shop-source {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--ink-dim);
  border: 1px solid #2a3a58;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
}
.shop-addr {
  font-size: 12px;
  color: var(--ink-dim);
  line-height: 1.4;
}
.shop-hours {
  margin-top: 6px;
  font-size: 12px;
}
.shop-hours summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.shop-hours[open] summary { margin-bottom: 4px; }
.shop-hours div {
  color: var(--ink-dim);
  padding: 1px 0;
}
.shop-hours-line { font-size: 12px; color: var(--ink-dim); margin-top: 4px; }
.shop-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.shop-btn {
  flex: 1 1 auto;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid #2a3a58;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.shop-btn:hover, .shop-btn:active {
  background: var(--accent);
  color: #0b1320;
  border-color: var(--accent);
}
.shop-btn-call { color: #22c55e; }
.shop-btn-web  { color: var(--accent); }
.shop-btn-map  { color: #fbbf24; }
.shops-loading, .shops-empty {
  font-size: 12px;
  color: var(--ink-dim);
  margin: 4px 0;
}
.shops-attr {
  font-size: 10px;
  color: var(--ink-dim);
  text-align: right;
  margin-top: 4px;
}

/* Locals Only events */
.locals-block { margin-bottom: 18px; }
.locals-block h3 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.local-event {
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.local-when {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--accent);
}
.local-title { font-size: 13px; font-weight: 600; margin-top: 2px; }
.local-info  { font-size: 12px; color: var(--ink-dim); margin-top: 4px; line-height: 1.4; }
.local-link  { font-size: 12px; color: var(--accent); text-decoration: none; margin-top: 4px; display: inline-block; }
.local-link:hover { text-decoration: underline; }
.locals-empty, .locals-cta { font-size: 11px; color: var(--ink-dim); margin: 4px 0 0; }
.locals-cta a { color: var(--accent); }

/* Sponsor banner */
.sponsor-block { margin-bottom: 18px; }
.sponsor-block.hidden { display: none; }
.sponsor-block a {
  display: flex;
  flex-direction: column;
  background: linear-gradient(90deg, #0e1a2c 0%, #1a2742 100%);
  border: 1px solid #2a3a58;
  border-radius: 8px;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.15s;
}
.sponsor-block a:hover { border-color: var(--accent); }
.sponsor-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.sponsor-tag {
  font-size: 11px;
  color: var(--ink-dim);
  margin-top: 2px;
}

/* Shop markers */
.shop-marker { background: transparent !important; border: 0 !important; }
.shop-dot {
  width: 10px;
  height: 10px;
  border: 2px solid #fff;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
}
.shop-surf  { background: #06b6d4; }
.shop-skate { background: #f97316; }
.shop-mixed { background: #a855f7; }

.spot-tooltip .tt-shop-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 5px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  border-radius: 3px;
  vertical-align: middle;
  color: #0b1320;
}
.tt-shop-surf  { background: #06b6d4; }
.tt-shop-skate { background: #f97316; }
.tt-shop-mixed { background: #a855f7; color: #fff; }

.status { color: var(--warn); font-size: 12px; min-height: 16px; }

/* Leaflet popup tweak */
.leaflet-popup-content { font-size: 13px; }

/* Shop popup (map markers) */
.leaflet-popup.shop-popup .leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid #2a3a58;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  padding: 0;
}
.leaflet-popup.shop-popup .leaflet-popup-tip { background: var(--panel); }
.leaflet-popup.shop-popup .leaflet-popup-content { margin: 0; padding: 12px 14px; min-width: 220px; }
.leaflet-popup.shop-popup .leaflet-popup-close-button { color: var(--ink-dim); padding: 6px 8px 0 0; font-size: 18px; }
.map-pop-name { font-size: 14px; font-weight: 600; color: var(--ink); }
.map-pop-rating { font-size: 12px; color: #fbbf24; margin-top: 2px; font-weight: 600; }
.map-pop-rating .muted { color: var(--ink-dim); font-weight: 400; }
.map-pop-addr { font-size: 12px; color: var(--ink-dim); margin-top: 4px; line-height: 1.4; }
.map-pop-row { font-size: 12px; margin-top: 4px; color: var(--ink-dim); }
.map-pop-row .muted { color: var(--ink-dim); margin-right: 4px; }
.map-pop-row a { color: var(--accent); text-decoration: none; }
.map-pop-hours { margin-top: 6px; font-size: 12px; }
.map-pop-hours summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.map-pop-hours div { color: var(--ink-dim); padding: 1px 0; }
.map-pop-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.map-pop-btn {
  flex: 1 1 auto;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid #2a3a58;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.map-pop-btn-primary {
  background: var(--accent);
  color: #0b1320;
  border-color: var(--accent);
}
.map-pop-btn:hover { filter: brightness(1.1); }

/* Hover tooltip on markers */
.leaflet-tooltip.spot-tooltip {
  background: rgba(17, 28, 47, 0.96);
  color: var(--ink);
  border: 1px solid #2a3a58;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  font-size: 12px;
  line-height: 1.5;
  padding: 8px 10px;
  white-space: nowrap;
}
.leaflet-tooltip.spot-tooltip::before { border-top-color: #2a3a58; }
.spot-tooltip .tt-name { font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.spot-tooltip .tt-cam {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.6px;
  background: #ef4444;
  color: #fff;
  border-radius: 3px;
  vertical-align: middle;
}
.spot-tooltip .tt-row { display: flex; gap: 8px; }
.spot-tooltip .tt-label { color: var(--ink-dim); width: 38px; }
.spot-tooltip .tt-loading { color: var(--ink-dim); font-style: italic; }
.spot-popup-btn {
  background: var(--accent);
  color: #0b1320;
  border: 0;
  padding: 5px 10px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
}

/* Wave overlay control + legend */
.wave-toggle button {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid #2a3a58;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.wave-toggle button:hover { border-color: var(--accent); }
.wave-toggle button.active { background: var(--accent); color: #0b1320; border-color: var(--accent); }
.wave-toggle button:disabled { opacity: 0.6; cursor: wait; }

.wave-legend {
  background: rgba(17, 28, 47, 0.95);
  color: var(--ink);
  border: 1px solid #2a3a58;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.6;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
}
.wave-legend .legend-title {
  font-weight: 600;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 10px;
  margin-bottom: 4px;
}
.wave-legend .legend-row { display: flex; align-items: center; gap: 6px; }
.wave-legend .sw {
  width: 16px;
  height: 10px;
  display: inline-block;
  border-radius: 2px;
}

/* Animated wave canvas — drawn under markers */
.wave-field-canvas {
  pointer-events: none;
}

/* Time slider control */
.time-controls {
  background: rgba(17, 28, 47, 0.95);
  border: 1px solid #2a3a58;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink);
  min-width: 380px;
  max-width: calc(100vw - 24px);
}

/* Compact attribution top-left so it doesn't crowd the bottom controls */
.leaflet-top.leaflet-left .leaflet-control-attribution {
  font-size: 9px;
  padding: 2px 6px;
  background: rgba(17, 28, 47, 0.7);
  color: var(--ink-dim);
  border-radius: 4px;
  margin: 6px 0 0 6px;
  max-width: 200px;
}
.leaflet-top.leaflet-left .leaflet-control-attribution a {
  color: var(--ink-dim);
}
.time-controls button {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid #2a3a58;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}
.time-controls button:hover { border-color: var(--accent); }
.time-controls #time-slider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}
.time-controls #time-label {
  color: var(--ink-dim);
  min-width: 110px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* NDBC buoy marker */
.buoy-marker { background: transparent !important; border: 0 !important; }
.buoy-dot {
  width: 12px;
  height: 12px;
  background: #facc15;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 0 6px rgba(250, 204, 21, 0.8);
  animation: buoy-pulse 2s ease-in-out infinite;
}
@keyframes buoy-pulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 0 4px rgba(250, 204, 21, 0.6); }
  50%      { box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 0 10px rgba(250, 204, 21, 1); }
}
.spot-tooltip .tt-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 5px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: #facc15;
  color: #1f1700;
  border-radius: 3px;
  vertical-align: middle;
}
.spot-tooltip .tt-foot {
  margin-top: 4px;
  color: var(--ink-dim);
  font-size: 10px;
}

@media (max-width: 600px) {
  #panel {
    width: 100%;
    padding-top: max(18px, env(safe-area-inset-top));
  }
  #panel-close {
    width: 44px;
    height: 44px;
    font-size: 26px;
    background: var(--accent);
    color: #0b1320;
    border-color: var(--accent);
  }
  .wave-legend { font-size: 10px; padding: 6px 8px; }

  /* Compact time slider on phones — no min-width, hide the date label */
  .time-controls {
    min-width: 0;
    width: calc(100vw - 16px);
    padding: 6px 8px;
    gap: 6px;
    font-size: 11px;
  }
  .time-controls #time-label { display: none; }
  .time-controls button { padding: 6px 10px; min-height: 32px; }
}
