* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:root {
  --bg: #eef3f8;
  --card: #ffffff;
  --primary: #0a4f7a;
  --accent: #2196d6;
  --text: #1a2733;
  --muted: #5b6b7a;
  --border: rgba(10, 79, 122, 0.08);
  --warm: #e8704c;
  --cool: #3aa6dd;
  --cold: #6bb7e3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1a26;
    --card: #16263a;
    --primary: #62b6e6;
    --accent: #4ab1e0;
    --text: #e8eef4;
    --muted: #93a3b1;
    --border: rgba(255, 255, 255, 0.06);
    --cool: #7cc1e6;
    --cold: #9fd0ec;
  }
}

html, body { margin: 0; padding: 0; }

.build-version {
  margin: 0.4rem 0 0;
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.6;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

header {
  background: linear-gradient(135deg, #0a4f7a, #2196d6);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 1rem) 1rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  position: sticky;
  top: 0;
  z-index: 5;
}

header .title-block { min-width: 0; flex: 1; }

header h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

header .subtitle {
  margin: 0.2rem 0 0;
  /* a11y: full opacity gives ~4.5:1 against the header gradient at the
     primary (dark) end; the lighter end of the gradient sits behind the
     refresh/lock buttons, not the subtitle. */
  opacity: 0.95;
  font-size: 0.85rem;
  font-weight: 400;
  line-height: 1.35;
}

#refresh {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.6s ease, background 0.2s ease;
}

#refresh:hover { background: rgba(255, 255, 255, 0.28); }
#refresh.spin { transform: rotate(360deg); }
#refresh:disabled {
  opacity: 0.65;
  cursor: progress;
  background: rgba(255, 255, 255, 0.10);
}
#refresh:disabled:hover { background: rgba(255, 255, 255, 0.10); }

.sort-bar {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.85rem 1rem 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.sort-label {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-right: 0.35rem;
  font-weight: 600;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 0.5rem 0.85rem;
  min-height: 44px;
  border-radius: 999px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.chip:hover { background: rgba(33, 150, 214, 0.08); }
@media (prefers-color-scheme: dark) {
  .chip:hover { background: rgba(124, 193, 230, 0.10); }
}

.chip:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
@media (prefers-color-scheme: dark) {
  .chip:focus-visible { outline-color: var(--accent); }
}
#refresh:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.chip[aria-pressed="true"] {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
@media (prefers-color-scheme: dark) {
  .chip[aria-pressed="true"] {
    background: var(--accent);
    color: #0e1a26;
    border-color: var(--accent);
  }
}

.chip-prio {
  display: none;
  font-size: 0.7rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  line-height: 1.2;
  min-width: 1.2em;
  text-align: center;
}

.chip[data-prio] .chip-prio { display: inline-block; }

.chip-arrow {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1;
}

.chip[aria-pressed="false"] .chip-arrow { display: none; }

main {
  padding: 1rem;
  display: grid;
  gap: 1.25rem;
  max-width: 720px;
  margin: 0 auto;
}

main section { display: grid; gap: 0.5rem; }

.section-heading {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding-left: 0.25rem;
}

.list { display: grid; gap: 0.6rem; }

.lake {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.9rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.lake .info { min-width: 0; flex: 1; }
.lake .level {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}
.lake .level:empty { display: none; }
.lake .level .delta-up { color: var(--warm); font-weight: 600; }
.lake .level .delta-down { color: var(--cool); font-weight: 600; }
.lake .level .delta-zero { color: var(--muted); }
.lake .name { margin: 0; font-size: 1.05rem; font-weight: 600; }
.lake .name .map-link {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: baseline;
  gap: 0.25rem;
  -webkit-tap-highlight-color: rgba(33, 150, 214, 0.18);
}
.lake .name .map-link::after {
  content: '↗';
  font-size: 0.75em;
  color: var(--muted);
  font-weight: 500;
  transform: translateY(-0.05em);
}
.lake .name .map-link:hover {
  color: var(--accent);
  text-decoration: underline;
}
.lake .name .map-link:hover::after { color: var(--accent); }
.lake .name .map-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}
.lake.skeleton .name .map-link::after { display: none; }
.lake .meta { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.8rem; }
.lake .timestamp { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.72rem; }

.lake .temps {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  flex-shrink: 0;
}

.lake .temps > div {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  gap: 0.1rem;
  text-align: right;
}

.lake .temps .label {
  grid-column: 1 / span 2;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.1rem;
}

.lake .temps .delta {
  grid-column: 1 / span 2;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  margin-top: 0.05rem;
  font-weight: 600;
}
.lake .temps .delta:empty { display: none; }
.lake .temps .delta.delta-up { color: var(--warm); }
.lake .temps .delta.delta-down { color: var(--cool); }
.lake .temps .delta.delta-zero { color: var(--muted); }

.lake .temps .value {
  font-size: 1.6rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--cool);
}

.lake .temps .unit { font-size: 0.85rem; color: var(--muted); margin-left: 0.05rem; }

.lake .water .value.cold { color: var(--cold); }
.lake .water .value.cool { color: var(--cool); }
.lake .water .value.warm { color: var(--warm); }

.lake .water.is-live .label {
  color: var(--accent);
  font-weight: 600;
}
.lake .water.is-live .label::before {
  content: '●';
  margin-right: 0.2em;
  font-size: 0.7em;
  vertical-align: 0.15em;
}

.lake .water.is-live.is-stale .label {
  color: var(--muted);
  font-weight: 500;
  font-style: italic;
}
.lake .water.is-live.is-stale .label::before {
  content: '○';
  color: var(--muted);
  /* keep visual size identical to filled ● dot for alignment */
}
.lake .water.is-live.is-stale .value { opacity: 0.78; }

.lake .water.is-corrected .label {
  color: var(--muted);
  font-weight: 500;
  font-style: italic;
  cursor: help;
}

.lake .air .value { color: var(--text); font-size: 1.1rem; font-weight: 500; }

.lake.skeleton .value { opacity: 0.35; }

footer {
  text-align: center;
  padding: 1rem 1rem calc(env(safe-area-inset-bottom) + 1.5rem);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  max-width: 720px;
  margin: 0 auto;
}

footer p { margin: 0.3rem 0; }
footer #last-updated {
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
footer a { color: var(--primary); text-decoration: underline; }
footer a:hover { text-decoration: underline; }
footer a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}
.data-source {
  margin-top: 0.3rem;
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

@media (max-width: 380px) {
  .lake { flex-direction: column; align-items: flex-start; }
  .lake .temps { align-self: stretch; justify-content: space-between; }
  header { padding-left: 0.85rem; padding-right: 0.85rem; gap: 0.5rem; }
  header h1 { font-size: 1.25rem; }
  main { padding: 0.85rem; }
  .sort-bar { padding-left: 0.85rem; padding-right: 0.85rem; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  #refresh.spin { transform: none; }
}
