:root {
  --bg: #0a1220;
  --panel: #121d30;
  --text: #eaf1fb;
  --muted: #8195b0;
  --border: #22324b;
  --accent: #ff9f1c;
  --rain: #4a8cff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1100;   /* above Leaflet's map controls */
}

h1 { font-size: 20px; margin: 0; letter-spacing: 0.3px; }

.actions { display: flex; gap: 6px; }

.icon-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
}

.icon-btn.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 16px);
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}

.place { margin: 0; color: var(--muted); font-size: 13px; }
.summary { margin: 6px 0 4px; font-size: 24px; font-weight: 650; line-height: 1.25; }
.status { margin: 0 0 6px; color: var(--muted); font-size: 14px; min-height: 1em; }
.status:empty { display: none; }

#chart { width: 100%; height: 150px; display: block; margin-top: 8px; }

.legend { margin: 4px 0 0; color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sw { display: inline-block; width: 14px; height: 10px; }
.sw.bar { background: var(--rain); border-radius: 2px; }
.sw.line { border-top: 2px dashed var(--accent); height: 0; margin-left: 8px; }

.source { margin: 8px 0 0; color: var(--muted); font-size: 12px; }

.card h2 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; margin: 0 0 10px; }

.card h2 .units { text-transform: none; letter-spacing: 0; font-weight: 400; }

.hourly { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.hour { flex: 0 0 52px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 13px; }
.h-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.h-icon { font-size: 22px; line-height: 1.2; }
.h-temp { font-weight: 600; }
.pop { color: var(--rain); font-size: 12px; min-height: 1.2em; }
.h-wind { color: var(--muted); font-size: 12px; white-space: nowrap; }
.arrow { display: inline-block; margin-right: 1px; }

.daily { display: flex; flex-direction: column; }
.day {
  display: grid;
  grid-template-columns: 44px 30px 34px 38px 1fr 38px;
  grid-template-areas: "name icon pop lo bar hi" "label label label label wind wind";
  align-items: center; column-gap: 6px; row-gap: 2px;
  padding: 8px 0; border-top: 1px solid var(--border); font-size: 14px;
}
.day:first-child { border-top: none; }
.d-name { grid-area: name; font-weight: 600; }
.d-icon { grid-area: icon; font-size: 20px; }
.day .pop { grid-area: pop; }
.d-lo { grid-area: lo; color: var(--muted); text-align: right; }
.d-hi { grid-area: hi; font-weight: 600; }
.d-bar { grid-area: bar; position: relative; height: 6px; border-radius: 3px; background: var(--bg); }
.d-bar span { position: absolute; top: 0; bottom: 0; border-radius: 3px; background: linear-gradient(90deg, #4a8cff, #ff9f1c); }
.d-label { grid-area: label; color: var(--muted); font-size: 12px; }
.d-wind { grid-area: wind; color: var(--muted); font-size: 12px; text-align: right; white-space: nowrap; }
.d-wind small { font-size: 11px; }

.map-card { padding: 0; overflow: hidden; }
#map { height: 360px; background: #0d1626; }
.radar-img { image-rendering: auto; }

.map-bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px 0; }
.map-bar input { flex: 1; min-width: 0; accent-color: var(--accent); }
.play {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; width: 36px; height: 32px; cursor: pointer;
}
.frame-label { font-size: 12px; color: var(--muted); min-width: 132px; text-align: right; font-variant-numeric: tabular-nums; }
.frame-label.fc { color: var(--accent); }
.play.arrows, .play.vel { color: var(--muted); font-weight: 700; }
.play.vel.on { color: var(--text); border-color: #3ee6c1; }
.play:disabled { opacity: 0.4; cursor: default; }
.vel-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 12px 0; font-size: 12px; color: var(--muted); }
.vel-legend .sw { width: 14px; height: 10px; border-radius: 2px; margin-left: 6px; }
.vel-legend .sw:first-child { margin-left: 0; }
.sw.toward { background: linear-gradient(90deg, #02fc02, #017e01); }
.sw.away { background: linear-gradient(90deg, #fd0000, #7f0000); }
.sw.folded { background: #7f00cf; }
.vel-note { flex-basis: 100%; }
.play.arrows.on { color: var(--text); border-color: var(--accent); }

.hint { margin: 8px 12px 12px; color: var(--muted); font-size: 12px; }
.link-btn { background: none; border: none; color: var(--accent); padding: 0; font-size: 12px; cursor: pointer; text-decoration: underline; }

.details { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; font-size: 14px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }

.settings { background: #1e1a14; border: 1px solid #5a3f1a; border-left: 4px solid var(--accent); }
.settings h3 { color: var(--accent); }
#settingsBtn[aria-expanded="true"] { background: var(--accent); color: #111; border-color: var(--accent); }
.settings label { display: block; margin-bottom: 10px; font-size: 14px; }
.settings select { display: block; margin-top: 4px; width: 100%; padding: 8px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 15px; }
.settings .check { display: flex; gap: 8px; align-items: center; }
.note { color: var(--muted); font-size: 12px; margin: 0; }
.settings h3 { font-size: 15px; margin: 16px 0 6px; display: flex; align-items: center; gap: 8px; }
.settings h3:first-of-type { margin-top: 12px; }
.pill { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.row { display: flex; gap: 8px; margin: 8px 0; }
.row input { flex: 1; min-width: 0; padding: 8px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 15px; }
.btn { background: var(--accent); color: #111; border: none; border-radius: 8px; padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.msg { min-height: 0; }
.msg.bad { color: #ff8a80; }
.places { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.places li { display: flex; align-items: baseline; gap: 8px; padding: 6px 0; border-top: 1px solid var(--border); }
.places li:first-child { border-top: none; }
.places li span { flex: 1; }
.places small { color: var(--muted); }
.places .none { color: var(--muted); }
.advanced { margin-top: 14px; font-size: 13px; color: var(--muted); }
.advanced label { margin-top: 8px; }
.advanced input { display: block; width: 100%; margin-top: 4px; padding: 8px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }

footer { color: var(--muted); font-size: 11px; text-align: center; padding: 4px 8px 12px; line-height: 1.5; }

.leaflet-container { font: inherit; }

/* tropical storms */
.storms h2 { display: flex; align-items: center; justify-content: space-between; }
.storm-toggle { text-transform: none; letter-spacing: 0; font-weight: 400; display: flex; gap: 6px; align-items: center; }
.storm { border-top: 1px solid var(--border); padding: 10px 0; }
.storm:first-child { border-top: none; padding-top: 0; }
.storm-head { display: flex; align-items: center; gap: 8px; }
.storm-head strong { font-size: 17px; }
.cat { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 10px; color: #111; }
.storm p { margin: 4px 0; font-size: 14px; }
.storm .threat { color: #ff8a65; font-weight: 600; }
.storm .threat.none { color: var(--muted); font-weight: 400; }
.storm .meta { color: var(--muted); font-size: 12px; }
.storm .meta a { color: var(--accent); }
.storm .row { margin: 6px 0 0; }
.storm-label { background: none; border: none; }
.storm-label div { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; color: #111; font: 700 12px/22px -apple-system, system-ui, sans-serif; text-align: center; box-shadow: 0 0 0 2px rgba(0,0,0,.4); }
.storm-label span { position: absolute; left: 30px; top: 3px; white-space: nowrap; color: #fff; font: 600 12px -apple-system, system-ui, sans-serif; text-shadow: 0 0 3px #000, 0 0 3px #000; }

/* storm surge */
.surge-bar { display: flex; align-items: center; gap: 8px; padding: 0 12px; font-size: 13px; color: var(--muted); }
.surge-bar select { flex: 1; min-width: 0; padding: 6px 8px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.surge-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 8px 12px 0; font-size: 12px; color: var(--muted); }
.surge-legend span { display: inline-flex; align-items: center; gap: 5px; }
.surge-legend i { width: 14px; height: 10px; border-radius: 2px; display: inline-block; }
#surgeNote { margin-top: 6px; }
.leaflet-surge-pane img { image-rendering: auto; }

/* Gulf marine forecast */
.marine select { width: 100%; padding: 8px; margin-bottom: 8px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.marine-alerts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.marine-alerts span { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 10px; color: #111; }
.marine-period { border-top: 1px solid var(--border); padding: 8px 0; cursor: pointer; }
.marine-period:first-child { border-top: none; }
.marine-period h4 { margin: 0 0 3px; font-size: 14px; }
.marine-period p { margin: 2px 0; font-size: 13px; }
.marine-period .lbl { color: var(--muted); display: inline-block; min-width: 44px; }
.marine-period .full { color: var(--muted); font-size: 12px; margin-top: 4px; }
.marine-meta { margin-top: 6px; }

/* Navy waves + second opinion */
.navy-bar { margin-top: 8px; }
.waves-ctl { display: flex; align-items: center; gap: 10px; padding: 8px 12px 0; }
.waves-ctl input { flex: 1; min-width: 0; accent-color: #3ee6c1; }
.second table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.second th { color: var(--muted); font-weight: 500; text-align: right; padding: 4px 3px; font-size: 11px; }
.second th:first-child, .second td:first-child { text-align: left; }
.second td { text-align: right; padding: 5px 3px; border-top: 1px solid var(--border); white-space: nowrap; }
.second td small { display: block; color: var(--muted); font-size: 11px; }
.second td.flag { color: #ffb74d; font-weight: 600; }
.second .summary { margin: 0 0 8px; font-size: 14px; }
.second .key { color: var(--muted); font-size: 11px; margin: 6px 0 0; }

/* sailing weather */
.passage { padding: 14px 0 0; overflow: hidden; }
.passage h2 { padding: 0 14px; }
.pw-regions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; }
.chip { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 14px; padding: 5px 10px; font-size: 12px; cursor: pointer; }
.chip.on { border-color: var(--accent); color: var(--accent); }
.pw-row { display: flex; gap: 8px; padding: 0 12px 8px; }
.pw-row select { flex: 1; min-width: 0; padding: 7px 8px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
#pwMap { height: 420px; background: #0d1626; }
.isobar-label { color: #fff; font: 600 11px -apple-system, system-ui, sans-serif; text-align: center; text-shadow: 0 0 3px #000, 0 0 3px #000; background: none; border: none; }

/* tabs */
.topbar { position: sticky; top: calc(env(safe-area-inset-top) + 60px); z-index: 1050; background: var(--bg); padding: 0 0 8px; }
.tabs { display: flex; gap: 4px; }
.tabs button { flex: 1; background: var(--panel); color: var(--muted); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 4px; font-size: 14px; font-weight: 600; cursor: pointer; }
.tabs button.on { color: var(--text); border-color: var(--accent); background: var(--panel-2, #17304d); }
.map-card[data-tab-map="local"] [data-only]:not([data-only~="local"]),
.map-card[data-tab-map="storms"] [data-only]:not([data-only~="storms"]),
.map-card[data-tab-map="seas"] [data-only]:not([data-only~="seas"]) { display: none !important; }

/* tropical weather outlook */
.outlook p { margin: 6px 0; font-size: 14px; line-height: 1.4; }
.outlook .chance { display: block; margin: 2px 0 2px 10px; font-weight: 600; }
.outlook .risk { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 9px; color: #111; margin-left: 4px; }
.outlook .none { color: var(--accent-2, #2ec4b6); font-weight: 600; }
.outlook-x { background: none; border: none; font: 700 18px/22px -apple-system, system-ui, sans-serif; text-align: center; text-shadow: 0 0 3px #000, 0 0 3px #000; }

/* water temperature */
.wt-now { margin: 4px 0 6px; font-size: 14px; }
.wt-id, .wt-where { color: var(--muted); font-weight: 400; font-size: 12px; }

/* tides */
.tides select { width: 100%; padding: 8px; margin-bottom: 8px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.tide-now { margin: 4px 0 6px; font-size: 14px; }
#tideChart { width: 100%; height: 150px; display: block; }
.tide-table table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.tide-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 5px 6px 5px 0; vertical-align: top; white-space: nowrap; }
.tide-table td { padding: 5px 0; border-top: 1px solid var(--border); }
.tide-table tr:first-child td { border-top: none; }
.tide-table span { display: inline-block; margin-right: 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tide-table .hi { color: var(--text); }
.tide-table .lo { color: var(--muted); }

/* saved places switcher */
.place-bar { display: flex; gap: 6px; overflow-x: auto; padding-top: 8px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.place-bar::-webkit-scrollbar { display: none; }
.place-bar .chip { flex: 0 0 auto; }
.place-bar .chip.add { color: var(--accent); }

/* scroll slider on the right edge (iPhone hides the normal scrollbar) */
.scroll-rail { position: fixed; right: 0; width: 22px; z-index: 1040; touch-action: none; }
.scroll-rail::before { content: ''; position: absolute; top: 0; bottom: 0; right: 4px; width: 4px; border-radius: 2px; background: rgba(127, 150, 179, 0.18); }
.scroll-thumb { position: absolute; right: 2px; width: 8px; border-radius: 4px; background: rgba(127, 150, 179, 0.75); }
.scroll-rail.dragging .scroll-thumb, .scroll-rail:hover .scroll-thumb { background: var(--accent); }
.tide-measured { margin: 0 0 6px; font-size: 13px; }
.tide-measured .above { color: #ff9f1c; font-weight: 600; }
.tide-measured .below { color: #7fb4ff; font-weight: 600; }
.tide-measured .muted { color: var(--muted); }
.level-label { color: #fff; font: 700 11px -apple-system, system-ui, sans-serif; text-shadow: 0 0 3px #000, 0 0 3px #000; white-space: nowrap; background: none; border: none; }
