/* Dark (default) — Android MAYDA palette */
:root,
html[data-theme="dark"] {
  --bg: #05080f;
  --bg-page: #02040a;
  --nav: #0b111d;
  --card-weather: rgba(22, 35, 58, 0.55);
  --card-tide: rgba(22, 35, 58, 0.5);
  --card-hourly: rgba(22, 35, 58, 0.32);
  --card-solid: #16233a;
  --chip: #16233a;
  --chip-dim: rgba(22, 35, 58, 0.55);
  --chip-sel: #1a2b47;
  --stroke: #22334f;
  --text: #ffffff;
  --secondary: #aab6c9;
  --muted: #71809a;
  --blue: #4c9bff;
  --green: #4caf50;
  --green-soft: #81c784;
  --low: #f45b4e;
  --wave: #90cae8;
  --gust: #ff5959;
  --temp-hot: #ff550d;
  --temp-cold: #4c9bff;
  --weekend: #e57373;
  --tab-active-bg: #121a2a;
  --toggle-bg: rgba(11, 17, 29, 0.95);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --rail-icon-opacity: 0.9;
  --font: "Roboto", "Segoe UI", system-ui, -apple-system, sans-serif;
  --col: 72px;
  --max: 1100px;
}

/* Light theme */
html[data-theme="light"] {
  --bg: #f4f7fb;
  --bg-page: #e8eef6;
  --nav: #ffffff;
  --card-weather: #ffffff;
  --card-tide: #ffffff;
  --card-hourly: #ffffff;
  --card-solid: #ffffff;
  --chip: #e8eef6;
  --chip-dim: #f0f4f9;
  --chip-sel: #dce8f8;
  --stroke: #cfd9e8;
  --text: #0f1724;
  --secondary: #5a6b82;
  --muted: #8494a8;
  --blue: #2b7de9;
  --green: #2e7d32;
  --green-soft: #43a047;
  --low: #e53935;
  --wave: #5ba3d9;
  --gust: #e53935;
  --temp-hot: #e65100;
  --temp-cold: #1565c0;
  --weekend: #c75b5b;
  --tab-active-bg: #f0f5fc;
  --toggle-bg: #ffffff;
  --shadow: 0 8px 28px rgba(15, 40, 80, 0.08);
  --rail-icon-opacity: 0.75;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-page);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 80% 45% at 50% -5%, color-mix(in srgb, var(--blue) 12%, transparent), transparent 55%),
    var(--bg-page);
}

.shell {
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
  min-height: 100vh;
  padding: 24px 20px 36px;
  background: var(--bg);
  box-shadow: var(--shadow);
}

@media (min-width: 900px) {
  body { padding: 28px 0 40px; }
  .shell {
    min-height: calc(100vh - 56px);
    border-radius: 20px;
    border: 1px solid var(--stroke);
    padding: 28px 28px 40px;
  }
  :root, html[data-theme="dark"], html[data-theme="light"] {
    --col: 80px;
  }
}

@media (max-width: 600px) {
  .shell {
    width: 100%;
    padding: 18px 12px 28px;
    box-shadow: none;
  }
  :root, html[data-theme="dark"], html[data-theme="light"] {
    --col: 65px;
  }
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-logo {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: contain;
  background: #fff;
}
.brand-text { min-width: 0; }
.brand h1 {
  margin: 0;
  font-size: clamp(28px, 3vw, 36px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-weight: 700;
}
.date-header {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--secondary);
}

.top-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: var(--card-solid);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}
.theme-toggle:hover { border-color: var(--blue); }
html[data-theme="dark"] .theme-icon-moon { display: none; }
html[data-theme="light"] .theme-icon-sun { display: none; }

.moon {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 88px;
}
.moon-img {
  width: 52px;
  height: 52px;
  object-fit: contain;
  display: block;
}
.moon-name { font-size: 12px; font-weight: 700; }
.sun-times { margin-top: 1px; font-size: 9px; color: var(--muted); }

.tabs {
  display: flex;
  margin-top: 18px;
  background: var(--nav);
  border-radius: 14px;
  border: 1px solid var(--stroke);
  overflow: hidden;
  max-width: 420px;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.tab.active {
  color: var(--text);
  background: var(--tab-active-bg);
  box-shadow: inset 0 -2px 0 var(--blue);
}

.main { padding-top: 8px; }
.panel { display: none; }
.panel.active { display: block; }
.panel[hidden] { display: none !important; }

.weather-top-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 14px;
}
@media (min-width: 860px) {
  .weather-top-grid {
    grid-template-columns: 1.6fr 1fr;
    align-items: stretch;
  }
  .card-tide-near { margin-top: 0 !important; }
  .card-weather { margin-top: 0 !important; }
}

.card {
  border: 1px solid var(--stroke);
  border-radius: 18px;
  margin-top: 12px;
}
.card-weather {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 0;
  padding: 18px 16px;
  background: var(--card-weather);
}
.card-tide-near {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 18px 16px;
  background: var(--card-tide);
  margin-top: 0;
}
.card-hourly {
  position: relative;
  padding: 14px 10px 48px;
  background: var(--card-hourly);
}
.card-solid { background: var(--card-solid); padding: 16px; }

.wx-main-icon {
  width: 92px;
  height: 92px;
  object-fit: contain;
  flex-shrink: 0;
  cursor: help;
}
.wx-main { flex: 1; min-width: 0; }
.temp {
  font-size: clamp(40px, 5vw, 52px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}
.condition {
  margin: 6px 0 0 2px;
  font-size: 15px;
  font-weight: 700;
  white-space: pre-line;
  line-height: 1.2;
}
.feels {
  margin: 5px 0 0 2px;
  font-size: 12px;
  color: var(--secondary);
}
.divider {
  width: 1px;
  align-self: stretch;
  margin: 0 12px;
  background: var(--stroke);
}
.wind-label { font-size: 13px; color: var(--secondary); }
.wind-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 7px;
}
.wind-speed { font-size: 30px; font-weight: 700; line-height: 1; }
.wind-unit { font-size: 14px; font-weight: 700; color: var(--secondary); }
.wind-arrow {
  width: 22px;
  height: 22px;
  margin-left: 6px;
  display: inline-block;
  flex-shrink: 0;
  background: var(--blue);
  transform-origin: center center;
  -webkit-mask: url("../icons/ic_wind_arrow.svg") center / contain no-repeat;
  mask: url("../icons/ic_wind_arrow.svg") center / contain no-repeat;
}
.wind-dir { font-size: 16px; font-weight: 700; margin-left: 3px; }
.gusts { margin-top: 6px; font-size: 12px; color: var(--secondary); }
.gusts .hot { color: var(--gust); font-weight: 700; }

.label-sec { font-size: 12px; color: var(--secondary); }
.tide-time { font-size: 24px; font-weight: 700; margin-top: 4px; }
.tide-time.high { color: var(--blue); }
.tide-time.low { color: var(--low); }
.tide-in { font-size: 11px; color: var(--muted); margin-top: 2px; }

.days {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 0 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--stroke) transparent;
}
.day-chip {
  flex: 0 0 72px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 2px;
  text-align: center;
  background: var(--chip);
  color: var(--secondary);
  cursor: pointer;
  font-family: inherit;
}
.day-chip:nth-child(even) { background: var(--chip-dim); }
.day-chip.selected {
  background: var(--chip-sel);
  border-color: var(--blue);
  color: var(--text);
}
.day-chip .name { font-size: 14px; font-weight: 700; }
.day-chip .name.long { font-size: 11px; letter-spacing: -0.02em; }
.day-chip .name.weekend { color: var(--weekend); }
.day-chip .date { font-size: 9px; color: var(--muted); margin-top: 2px; }
.day-chip .icon {
  width: 38px;
  height: 38px;
  margin: 8px auto 0;
  display: block;
  object-fit: contain;
  cursor: help;
}
.day-chip .tmax { font-size: 15px; font-weight: 700; margin-top: 8px; }
.day-chip .tmin { font-size: 12px; margin-top: 3px; opacity: 0.85; }

.hourly-wrap { display: flex; min-height: 0; }
.hourly-rail {
  width: 40px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.hourly-rail .rail-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}
.hourly-rail img {
  width: 15px;
  height: 15px;
  object-fit: contain;
  opacity: var(--rail-icon-opacity);
}
.hourly-scroll {
  overflow-x: auto;
  flex: 1;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--stroke) transparent;
  cursor: grab;
}
.hourly-scroll:active { cursor: grabbing; }
.hourly-inner {
  display: inline-flex;
  flex-direction: column;
  min-width: 100%;
}
#hourlyTable { display: flex; flex-direction: column; }
.hour-row { display: flex; align-items: center; }
.hour-cell {
  width: var(--col);
  flex-shrink: 0;
  text-align: center;
  font-size: 13px;
  color: var(--text);
}
.hour-cell.time { font-size: 11px; color: var(--secondary); }
.hour-cell.temp { font-size: 15px; font-weight: 700; }
.hour-cell img.wx {
  width: 36px;
  height: 36px;
  object-fit: contain;
  cursor: help;
}

/* rp5-style weather decode tooltip */
.wx-tooltip {
  position: fixed;
  z-index: 9999;
  max-width: min(320px, calc(100vw - 24px));
  padding: 10px 14px;
  border-radius: 8px;
  background: #fff;
  color: #222;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.22);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.wx-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}
.wx-tooltip .wx-tip-title {
  display: block;
  font-weight: 700;
  font-size: 13.5px;
  color: #1a1a1a;
}
.wx-tooltip .wx-tip-detail {
  display: block;
  margin-top: 4px;
  font-weight: 400;
  font-size: 12.5px;
  color: #444;
  font-style: italic;
}
.wind-block { cursor: help; }
.hour-cell .wind-cell { cursor: help; }
.hour-cell .g {
  font-size: 10px;
  line-height: 1.2;
  color: var(--muted);
  font-weight: 400;
}
.hour-cell .g.hot { color: var(--gust); font-weight: 700; }

.spark-wrap {
  margin-top: 10px;
  /* chart width is set in JS to match hourly columns — scrolls with table */
}
#tideSpark {
  display: block;
  height: 260px;
}

.zone-toggle {
  position: absolute;
  left: 48px;
  display: flex;
  background: var(--toggle-bg);
  border-radius: 10px;
  padding: 3px;
  border: 1px solid var(--stroke);
  z-index: 3;
  box-shadow: var(--shadow);
}
.zone-btn, .zone-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 11px;
  padding: 5px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}
.zone-btn.active { background: color-mix(in srgb, var(--blue) 22%, transparent); color: var(--blue); }
.zone-btn[data-zone="river"].active {
  background: color-mix(in srgb, var(--green) 22%, transparent);
  color: var(--green-soft);
}

.zone-tabs { display: flex; gap: 8px; margin-top: 10px; }
.zone-tab.active { color: var(--blue); box-shadow: inset 0 -2px 0 var(--blue); }
.zone-tab[data-zone="river"].active {
  color: var(--green-soft);
  box-shadow: inset 0 -2px 0 var(--green);
}

.tide-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.tide-head h2 { margin: 0; font-size: clamp(18px, 2.2vw, 22px); font-weight: 700; }
.lag { margin: 6px 0 0; }
.day-nav {
  display: flex;
  align-items: center;
  margin: 8px 0;
  min-height: 48px;
}
.nav-btn {
  border: 0;
  background: transparent;
  color: var(--secondary);
  font-size: 16px;
  padding: 8px 14px;
  cursor: pointer;
}
.day-label { flex: 1; text-align: center; font-weight: 700; font-size: 16px; }
.chart-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  border: 1px solid var(--stroke);
  border-radius: 16px;
  background: var(--card-hourly);
  padding: 8px 0;
}
#tideChart { display: block; height: 280px; }

.tides-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 700px) {
  .tides-cards { grid-template-columns: 1fr 1fr; }
  .tides-cards .card { margin-top: 12px; }
}

.tide-now, .tide-next {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.height { font-size: 28px; font-weight: 700; }
.trend { font-size: 16px; font-weight: 700; color: var(--blue); margin-top: 4px; }
.next-type { font-size: 14px; margin-top: 2px; }
.section-title {
  margin: 16px 0 6px;
  font-size: 12px;
  color: var(--secondary);
  font-weight: 600;
}
.events { list-style: none; margin: 0; padding: 8px 12px; }
.events li {
  display: flex;
  justify-content: space-between;
  padding: 10px 4px;
  border-bottom: 1px solid var(--stroke);
  font-size: 14px;
}
.events li:last-child { border-bottom: 0; }
.ev-high { color: var(--blue); font-weight: 700; }
.ev-low { color: var(--low); font-weight: 700; }

.loading, .error {
  text-align: center;
  padding: 28px 12px;
  color: var(--secondary);
  font-size: 14px;
}
.error { color: var(--low); }
.hidden { display: none !important; }
.foot {
  text-align: center;
  margin-top: 28px;
  font-size: 11px;
  color: var(--muted);
}
