/* Snowflud. Layout: full-screen map, a floating control card (top-left), a legend (bottom-left),
   a detail panel (right; bottom sheet on phones). Cool glacier neutrals, rescue-orange accent. */
:root {
  --bg: #edf1f4;
  --surface: #f8fafb;
  --ink: #0e1b26;
  --muted: #4d5f70;
  --line: #cbd5dd;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --focus: #1d4ed8;
  --warn-bg: #fff4e5;
  --warn-ink: #7a3a00;
  --bar-track: #dde5ec;
  --shadow: 0 6px 24px rgba(14, 27, 38, 0.18);
  --font-display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --font-body: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-data: 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1620; --surface: #122230; --ink: #e7eef4; --muted: #9bb0c2; --line: #27394a;
    --accent: #ff8a4c; --accent-ink: #1b0b00; --focus: #8ab4ff; --warn-bg: #3a2610; --warn-ink: #ffd9b0;
    --bar-track: #1d3042; --shadow: 0 6px 24px rgba(0, 0, 0, 0.5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1620; --surface: #122230; --ink: #e7eef4; --muted: #9bb0c2; --line: #27394a;
  --accent: #ff8a4c; --accent-ink: #1b0b00; --focus: #8ab4ff; --warn-bg: #3a2610; --warn-ink: #ffd9b0;
  --bar-track: #1d3042; --shadow: 0 6px 24px rgba(0, 0, 0, 0.5); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font-body);
  overflow: hidden;
}
h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: 0.02em; text-wrap: balance; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
a { color: var(--accent); }
.mono { font-family: var(--font-data); font-size: 0.92em; }
.muted { color: var(--muted); }

#map { position: fixed; inset: 0; }

/* ---------- top bar ---------- */
.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 8px max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px));
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--surface) 92%, transparent); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.wordmark { font-family: var(--font-display); font-weight: 700; font-size: 26px; letter-spacing: 0.04em; text-transform: uppercase; }
.pill {
  font-family: var(--font-display); font-weight: 600; font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em;
  background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--accent); border-radius: 999px; padding: 2px 10px;
}
.bar .spacer { flex: 1; }
.bar .logo { width: 30px; height: 30px; border-radius: 7px; flex: none; margin-right: -4px; }
.linkbtn { background: none; border: 0; padding: 4px 6px; text-decoration: underline; cursor: pointer; color: var(--ink); }

/* ---------- cards ---------- */
.card {
  position: fixed; z-index: 4; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow);
}
#controls { top: calc(58px + env(safe-area-inset-top, 0px)); left: max(12px, env(safe-area-inset-left, 0px)); width: min(380px, calc(100vw - 24px)); padding: 12px; display: grid; gap: 10px;  max-height: calc(100vh - 58px - 44px - env(safe-area-inset-top, 0px)); max-height: calc(100dvh - 58px - 44px - env(safe-area-inset-top, 0px)); overflow: auto; }
#controls[hidden], #panel[hidden] { display: none; }
#ctrlBody { display: grid; gap: 10px; }
.grow { flex: 1; }
.mobile-only { display: none; }
.pill { white-space: nowrap; }
.replay { display: grid; gap: 6px; margin-top: 6px; }
input[type="date"] { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); min-width: 0; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--muted); margin-top: 8px; }
label.check input { margin-top: 3px; accent-color: var(--accent); }
#legend { border-top: 1px solid var(--line); padding-top: 8px; }
#panel {
  top: calc(58px + env(safe-area-inset-top, 0px)); right: max(12px, env(safe-area-inset-right, 0px));
  bottom: calc(26px + env(safe-area-inset-bottom, 0px)); width: min(440px, calc(100vw - 24px)); overflow: auto; padding: 14px 16px 18px;
}
label.field { display: grid; gap: 4px; font-family: var(--font-display); font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
select { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.seg { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.seg .w3 { grid-column: span 3; }
.seg .w2 { grid-column: span 2; }
.seg .w6 { grid-column: span 6; }
.seg button {
  min-width: 0; padding: 7px 4px; border: 1px solid var(--line); background: var(--bg); border-radius: 6px; cursor: pointer;
  font-family: var(--font-display); font-size: 15px; letter-spacing: 0.03em; line-height: 1.1;
}
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { min-width: 0; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.btn { padding: 7px 12px; border-radius: 6px; border: 1px solid var(--ink); background: var(--bg); cursor: pointer; font-family: var(--font-display); font-size: 15px; letter-spacing: 0.04em; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
#status { font-size: 13px; color: var(--muted); min-height: 1.2em; }
#status.err { color: var(--accent); }
.summary { font-size: 13.5px; border-top: 1px solid var(--line); padding-top: 8px; }
.tag { font-family: var(--font-display); font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }

/* ---------- legend ---------- */
.legend-row { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 13px; }
.legend-row span { display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, 0.3); display: inline-block; }
.legend-note { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

/* ---------- panel ---------- */
#panel h2 { font-size: 22px; text-transform: uppercase; }
#panel h3 { font-size: 16px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 16px 0 6px; }
.empty { color: var(--muted); }
.kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 8px 0; }
.kv div { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.kv b { display: block; font-family: var(--font-data); font-weight: 600; font-size: 15px; }
.kv small { font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-size: 12.5px; }
.problem { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 8px 0; background: var(--bg); }
.problem header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.problem h4 { margin: 0; font-family: var(--font-display); font-size: 19px; text-transform: uppercase; letter-spacing: 0.03em; }
.lvl { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.meter { height: 8px; background: var(--bar-track); border-radius: 4px; margin: 6px 0; overflow: hidden; }
.meter i { display: block; height: 100%; }
.meta { font-size: 13.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 14px; }
details { margin-top: 6px; }
summary { cursor: pointer; font-weight: 600; }
.driver { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 6px; margin: 6px 0; font-size: 14px; }
.driver .ar { font-family: var(--font-data); font-weight: 700; }
.driver .up { color: var(--accent); }
.driver .down { color: var(--muted); }
.note { background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; margin: 8px 0; }
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--font-data); font-size: 9px; fill: var(--muted); }
.chart .bars { fill: var(--bar-track); }
.chart .depth { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.chart .cursor { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .axis { stroke: var(--line); }
ul.tight { margin: 6px 0; padding-left: 18px; }
ul.tight li { margin: 3px 0; }
.attr { font-size: 12px; color: var(--muted); }

/* ---------- footer strip ---------- */
#strip {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; text-align: center; font-size: 12.5px; padding: 4px 10px calc(4px + env(safe-area-inset-bottom, 0px));
  background: var(--warn-bg); color: var(--warn-ink); border-top: 1px solid var(--accent);
}

/* ---------- gate and dialogs ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 82%, #000 18%); display: grid; place-items: center; padding: 16px; overflow: auto; }
.overlay[hidden] { display: none; }
.dialog { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); width: min(600px, 100%); padding: 22px 22px 18px; max-height: 100%; overflow: auto; }
.dialog h1 { font-size: 34px; text-transform: uppercase; line-height: 1; margin-bottom: 8px; }
.dialog ul { padding-left: 20px; margin: 10px 0; }
.dialog li { margin: 7px 0; }
.ack { display: flex; gap: 10px; align-items: flex-start; margin: 14px 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.ack input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); }
.links { font-size: 14px; margin-top: 12px; }
.links a { margin-right: 12px; }

.maplibregl-ctrl-attrib { font-size: 11px; }

@media (max-width: 760px) {
  body { overflow: hidden; }
  #controls { width: calc(100vw - 24px); padding: 10px; gap: 8px; }
  #panel { top: auto; left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); width: auto; height: 44vh; bottom: calc(26px + env(safe-area-inset-bottom, 0px)); }
  .pill { font-size: 12px; }
  .wordmark { font-size: 22px; }
  .hide-sm { display: none; }
  .mobile-only { display: inline-block; }
  #controls.collapsed #ctrlBody { display: none; }
  #controls .row .grow select { padding: 6px; }
  #controls { max-height: 62dvh; }
  /* the spot sheet only shows once a spot is picked, and can be closed */
  #panel { height: 40dvh; }
  #panel.nosel, #panel.min { display: none; }
  .panel-close { float: right; margin: 0 0 6px 8px; padding: 4px 10px; }
  #strip { font-size: 11.5px; }
  /* compact first-run notice so the buttons are reachable without a long scroll */
  .overlay { padding: 8px; place-items: start center; }
  .dialog { padding: 14px 14px 10px; }
  .dialog h1 { font-size: 26px; }
  .dialog p, .dialog li { font-size: 14px; line-height: 1.35; }
  .dialog li { margin: 4px 0; }
  .ack { margin: 10px 0; padding: 8px; font-size: 14px; }
  #gate .row { position: sticky; bottom: -10px; background: var(--surface); padding: 8px 0 4px; }
  #gate .btn.primary { width: 100%; padding: 10px 12px; }
}
/* ---------- season weather chart under the time slider ---------- */
#wxChart { touch-action: pan-y; cursor: ew-resize; user-select: none; -webkit-user-select: none; margin-top: 6px; }
#wxChart svg { display: block; }
.wx .snow { fill: #3d7fc4; }
.wx .snow.fc { opacity: 0.4; }
.wx .nowline { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 2; }
.wx .cursor { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: none; }
.wxread { font-size: 12.5px; margin-top: 4px; }
.wxhelp summary { font-weight: 400; font-size: 12.5px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
