:root {
  color-scheme: light;
  --surface-0: #eef1f5;
  --surface-1: #ffffff;
  --surface-2: #f1f4f8;
  --surface-3: #e3e8ef;
  --border: #d7dde6;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #7b8798;
  --gfs: #2a78d6;
  --ecmwf: #eb6834;
  --local: #1baf7a;
  --ens: #6250d6;
  --ens-band: rgba(42, 120, 214, 0.16);
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --grid: #e5e9f0;
  --accent: #2a78d6;
  --accent-2: #6250d6;
  --hero: linear-gradient(135deg, #dbeafe 0%, #ede9fe 60%, #fce7f3 100%);
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #0d1117;
    --surface-1: #161b22;
    --surface-2: #1f2630;
    --surface-3: #2a323e;
    --border: #2b3340;
    --text-primary: #f0f3f7;
    --text-secondary: #c2cad6;
    --text-muted: #8b96a5;
    --gfs: #3987e5;
    --ecmwf: #e8683a;
    --local: #22b37f;
    --ens: #9085e9;
    --ens-band: rgba(57, 135, 229, 0.22);
    --grid: #27303b;
    --accent: #3987e5;
    --accent-2: #9085e9;
    --hero: linear-gradient(135deg, #10203a 0%, #1b1a3d 60%, #2a1630 100%);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #0d1117;
  --surface-1: #161b22;
  --surface-2: #1f2630;
  --surface-3: #2a323e;
  --border: #2b3340;
  --text-primary: #f0f3f7;
  --text-secondary: #c2cad6;
  --text-muted: #8b96a5;
  --gfs: #3987e5;
  --ecmwf: #e8683a;
  --local: #22b37f;
  --ens: #9085e9;
  --ens-band: rgba(57, 135, 229, 0.22);
  --grid: #27303b;
  --accent: #3987e5;
  --accent-2: #9085e9;
  --hero: linear-gradient(135deg, #10203a 0%, #1b1a3d 60%, #2a1630 100%);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--surface-0); color: var(--text-primary);
  font: 14.5px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-block: 0 40px; padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: max(20px, env(safe-area-inset-right, 0px)); max-width: 1800px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }
h3 { font-size: 15px; margin: 0 0 10px; font-weight: 600; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
h3 .muted { font-weight: 400; font-size: 12.5px; }
a { color: var(--accent); }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
.pre { white-space: pre-wrap; font: 13px/1.55 ui-monospace, Consolas, monospace; max-height: 460px; overflow: auto;
  background: var(--surface-2); padding: 12px; border-radius: 8px; }

/* ---------------------------------------------------------------- header */
.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 0 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 34px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.25)); }
.sub { color: var(--text-secondary); font-size: 13px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { white-space: nowrap; }
.chip { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-secondary); }
.chip b { color: var(--text-primary); }
.status { font-size: 12px; color: var(--text-muted); }
.btn { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 13px; cursor: pointer; font: inherit; font-size: 13px; transition: border-color .15s, background .15s, transform .05s; }
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }
.select { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font: inherit; font-size: 13px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; position: sticky; top: 0;
  background: var(--surface-0); z-index: 20; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { white-space: nowrap; flex: none; }
.tab { background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-secondary); padding: 10px 16px;
  cursor: pointer; font: inherit; font-size: 14.5px; font-weight: 500; transition: color .15s; }
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--text-primary); border-bottom-color: var(--accent); }
.tabpane { display: none; animation: fade .2s ease-out; }
.tabpane.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin: 22px 0 12px; flex-wrap: wrap; }
.legend-inline { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-secondary); flex-wrap: wrap; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -2px; }
.sw.gfs { background: var(--gfs); } .sw.ecmwf { background: var(--ecmwf); } .sw.ens { background: var(--ens); } .sw.local { background: var(--local); }

/* ---------------------------------------------------------------- hero */
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; background: var(--hero); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px 24px; box-shadow: var(--shadow); align-items: stretch; }
@media (max-width: 1100px) { .hero { grid-template-columns: 1fr; } }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 11.5px; color: var(--text-secondary); font-weight: 600; }
.hero-headline { font-size: 26px; font-weight: 700; margin: 6px 0 4px; letter-spacing: -0.015em; line-height: 1.25; }
.hero-sub { color: var(--text-secondary); font-size: 14px; }
.hero-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 16px; }
.tile { background: color-mix(in srgb, var(--surface-1) 75%, transparent); backdrop-filter: blur(6px); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; }
.tile .k { font-size: 11.5px; color: var(--text-muted); }
.tile .v { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.tile .v small { font-size: 12px; font-weight: 500; color: var(--text-muted); margin-left: 2px; }
.tile .s { font-size: 12px; color: var(--text-secondary); }
.hero-map { display: block; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: #fff; position: relative;
  min-height: 220px; text-decoration: none; color: inherit; }
.hero-map img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-map-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 10px; font-size: 12px; background: rgba(0,0,0,.55); color: #fff; }

/* ---------------------------------------------------------------- cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(360px, 100%), 1fr)); gap: 14px; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; cursor: pointer;
  display: flex; flex-direction: column; gap: 10px; transition: transform .15s, box-shadow .15s, border-color .15s; box-shadow: var(--shadow); }
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card.powder { border-color: var(--gfs); background: linear-gradient(180deg, color-mix(in srgb, var(--gfs) 12%, var(--surface-1)), var(--surface-1)); }
.card .name { display: flex; justify-content: space-between; align-items: baseline; }
.card .name b { font-size: 17px; }
.card .elev { color: var(--text-muted); font-size: 12px; }
.card .headline { font-size: 13.5px; color: var(--text-secondary); min-height: 2.6em; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); font-weight: 600; }
.badge.alert { background: var(--critical); color: #fff; }
.badge.powder { background: var(--gfs); color: #fff; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.stat .k { font-size: 11px; color: var(--text-muted); }
.stat .v { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.stat .v small { font-size: 11px; font-weight: 400; color: var(--text-muted); }
.stat .small { font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.mini .d { text-align: center; font-size: 11px; color: var(--text-muted); }
.mini .bar { height: 44px; display: flex; align-items: flex-end; gap: 2px; justify-content: center; border-bottom: 1px solid var(--grid); }
.mini .bar i { display: block; width: 8px; border-radius: 2px 2px 0 0; min-height: 1px; transition: height .3s; }
.mini .bar i.g { background: var(--gfs); } .mini .bar i.e { background: var(--ecmwf); } .mini .bar i.m { background: var(--ens); }
.mini .p { font-size: 11px; text-align: center; }
.card .spark { height: 36px; }
.card .spark svg { width: 100%; height: 36px; display: block; }
.temps { font-size: 12.5px; color: var(--text-secondary); display: flex; justify-content: space-between; }

/* ---------------------------------------------------------------- logos / crests */
/* A crest is a fixed-height tile; wide wordmarks widen it (up to a cap), square marks stay square. */
.crest { height: 56px; min-width: 56px; max-width: 170px; flex: none; border-radius: 12px; overflow: hidden; background: #fff; display: flex;
  align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.25); padding: 6px 8px; }
.crest img { height: 100%; width: auto; max-width: 100%; object-fit: contain; display: block; }
.crest .ini { font-weight: 800; font-size: 20px; color: #fff; letter-spacing: -0.02em; }
.crest.sm { height: 24px; min-width: 24px; max-width: 84px; border-radius: 6px; box-shadow: none; padding: 2px 4px; } .crest.sm .ini { font-size: 10px; }
.crest.md { height: 40px; min-width: 40px; max-width: 130px; border-radius: 9px; padding: 4px 6px; } .crest.md .ini { font-size: 13px; }
.crest.xl { height: 100px; min-width: 100px; max-width: 320px; border-radius: 20px; padding: 10px 14px; } .crest.xl .ini { font-size: 34px; }
.card { border-top: 4px solid var(--mc, var(--border)); }
.card .name { align-items: center; gap: 12px; justify-content: flex-start; }
.card .name b { display: block; }
.card .name .tag { font-size: 12px; color: var(--mc, var(--text-muted)); font-weight: 600; }
.card .name .elev { margin-left: auto; text-align: right; }
.card.powder { border-top-color: var(--gfs); }
.pills button { display: inline-flex; align-items: center; gap: 8px; padding: 5px 14px 5px 6px; }
.pills button.active { background: var(--mc, var(--accent)); border-color: var(--mc, var(--accent)); }
.mtn-id { display: flex; align-items: center; gap: 18px; }
.tagline { color: var(--mc, var(--text-secondary)); font-weight: 600; font-size: 13.5px; letter-spacing: .02em; }
#tab-mountain .headline { border-left: 4px solid var(--mc, var(--accent)); padding-left: 12px; }
#tab-mountain .tiles .tile:first-child { border-top: 3px solid var(--mc, var(--accent)); }
table.matrix th .rowhead { display: flex; align-items: center; gap: 8px; }
.hero-crests { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.hero-crests .crest { cursor: pointer; transition: transform .15s; border-bottom: 3px solid var(--mc); }
.hero-crests .crest:hover { transform: translateY(-3px) scale(1.06); }

/* ---------------------------------------------------------------- matrix */
.matrix-wrap { overflow-x: auto; background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
table.matrix { border-collapse: separate; border-spacing: 3px; font-size: 12.5px; white-space: nowrap; width: 100%; }
table.matrix th { font-weight: 500; color: var(--text-secondary); padding: 2px 8px; text-align: left; }
table.matrix th.day { text-align: center; font-size: 11.5px; }
table.matrix td { text-align: center; padding: 6px 2px; border-radius: 6px; min-width: 52px; color: var(--text-primary); cursor: pointer; transition: transform .1s; }
table.matrix td:hover { transform: scale(1.06); outline: 2px solid var(--accent); }
table.matrix td.c0 { background: var(--surface-2); color: var(--text-muted); }
table.matrix td.c1 { background: #cde2fb; color: #0b0b0b; }
table.matrix td.c2 { background: #9ec5f4; color: #0b0b0b; }
table.matrix td.c3 { background: #5598e7; color: #fff; }
table.matrix td.c4 { background: #256abf; color: #fff; }
table.matrix td.c5 { background: #0d366b; color: #fff; }

/* ---------------------------------------------------------------- mountain */
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 14px; }
.pills button { background: var(--surface-1); border: 1px solid var(--border); color: var(--text-secondary); border-radius: 999px;
  padding: 7px 14px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 500; transition: all .15s; }
.pills button:hover { border-color: var(--accent); color: var(--text-primary); }
.pills button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pills.small button { padding: 4px 10px; font-size: 12px; }
.pills .grp { font-size: 11px; color: var(--text-muted); align-self: center; margin-left: 6px; text-transform: uppercase; letter-spacing: .08em; }
.mtn-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.range-ctl { display: flex; gap: 10px; align-items: center; }
.headline { font-size: 17px; margin: 8px 0 10px; }
.alert { background: var(--surface-1); border-left: 4px solid var(--critical); padding: 10px 14px; margin: 6px 0; border-radius: 8px; }
.alert b { display: block; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 6px 0 16px; }
.tiles .tile { background: var(--surface-1); box-shadow: var(--shadow); }
.grid1 { display: grid; grid-template-columns: 1fr; gap: 14px; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(560px, 100%), 1fr)); gap: 14px; margin-bottom: 14px; }
.panel { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; min-width: 0; box-shadow: var(--shadow); }
.chart { width: 100%; min-width: 0; overflow: hidden; }
.subhead { font-size: 13.5px; font-weight: 600; margin: 6px 0 4px; }
.subhead .muted { font-weight: 400; font-size: 12px; }
.subhead + div + .subhead { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--grid); }
.chart svg { width: 100%; height: auto; display: block; }
.axis text { fill: var(--text-muted); font-size: 11.5px; }
.axis line, .axis path { stroke: var(--grid); }
.grid line { stroke: var(--grid); }
.lbl { fill: var(--text-secondary); font-size: 11.5px; }
.xhair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-secondary); margin-top: 8px; flex-wrap: wrap; }
.legend span { cursor: pointer; user-select: none; padding: 2px 6px; border-radius: 6px; transition: background .15s; }
.legend span:hover { background: var(--surface-2); }
.legend span.off { opacity: .4; text-decoration: line-through; }
.series-off { display: none; }

.periods { display: grid; gap: 8px; max-height: 620px; overflow: auto; }
.period { display: grid; grid-template-columns: 44px 120px 64px 1fr; gap: 10px; padding: 10px; background: var(--surface-2); border-radius: 10px; align-items: center; }
.period img { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; }
.period .pn { font-weight: 600; }
.period .pt { font-weight: 700; font-size: 18px; }
.period .ps { color: var(--text-secondary); font-size: 12.5px; }
.period .pd { font-size: 12.5px; grid-column: 1 / -1; color: var(--text-secondary); }
.table-wrap { overflow: auto; max-height: 620px; }
table.daily { border-collapse: collapse; width: 100%; font-size: 13px; }
table.daily th, table.daily td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.daily th:first-child, table.daily td:first-child { text-align: left; }
table.daily th { position: sticky; top: 0; background: var(--surface-1); color: var(--text-secondary); font-weight: 500; }
table.daily td.snow { color: var(--text-primary); font-weight: 600; }
table.daily tr:hover td { background: var(--surface-2); }

/* ---------------------------------------------------------------- loops */
.loop-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 6px 0 8px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--surface-2); color: var(--text-secondary); border: none; padding: 7px 14px; cursor: pointer; font: inherit; font-size: 13px; }
.seg button.active { background: var(--accent); color: #fff; }
.scrub { margin: 4px 0 8px; }
.slider { width: 100%; margin: 0; accent-color: var(--accent); }
.day-strip { display: flex; font-size: 11px; color: var(--text-muted); position: relative; height: 16px; }
.day-strip span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.day-strip span::before { content: ""; position: absolute; left: 50%; top: -6px; width: 1px; height: 5px; background: var(--border); }
.loop-stage { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 8px; text-align: center; position: relative; box-shadow: var(--shadow); }
.loop-stage img { width: 100%; max-width: 1400px; height: auto; border-radius: 8px; background: #fff; min-height: 300px; cursor: crosshair; }
.frame-badge { position: absolute; top: 16px; right: 16px; background: rgba(0,0,0,.6); color: #fff; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; pointer-events: none; }
.caption { font-size: 13px; color: var(--text-secondary); margin: 8px 0 4px; }
.cmp-stage { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cmp-stage > div { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 8px; }
.cmp-stage img { width: 100%; height: auto; border-radius: 8px; background: #fff; cursor: crosshair; }
@media (max-width: 1100px) { .cmp-stage { grid-template-columns: 1fr; } }

.tooltip { position: fixed; pointer-events: none; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 11px; font-size: 12.5px; z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,.3); max-width: min(340px, calc(100vw - 24px)); line-height: 1.45; }
.tooltip b { display: block; margin-bottom: 3px; }
.tooltip i.sw { width: 9px; height: 9px; }
footer { margin-top: 28px; border-top: 1px solid var(--border); padding-top: 12px; }
.empty { color: var(--text-muted); padding: 24px; text-align: center; }

/* ---------------------------------------------------------------- phones */
@media (max-width: 600px) {
  body { padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px)); }
  html, body { font-size: 14px; }
  h1 { font-size: 19px; } h2 { font-size: 17px; }
  .top { padding: 12px 0 8px; gap: 8px; }
  .logo { font-size: 28px; }
  .tab { padding: 9px 11px; font-size: 13.5px; }
  .hero { padding: 16px 14px; gap: 12px; }
  .hero-headline { font-size: 21px; }
  .hero-tiles, .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 8px 10px; } .tile .v { font-size: 19px; }
  .card { padding: 12px; }
  .stats { gap: 6px; } .stat { padding: 6px 8px; } .stat .v { font-size: 17px; }
  .panel { padding: 12px 10px; }
  h3 { font-size: 14px; gap: 6px; } h3 .muted { font-size: 11.5px; }
  .crest.xl { height: 64px; min-width: 64px; max-width: 200px; border-radius: 14px; padding: 6px 8px; } .crest.xl .ini { font-size: 22px; }
  .mtn-id { gap: 12px; }
  .headline { font-size: 15.5px; }
  .period { grid-template-columns: 36px 1fr auto; }
  .period img { width: 36px; height: 36px; }
  .period .ps, .period .pd { grid-column: 1 / -1; }
  .legend { gap: 8px; font-size: 12px; }
  .legend-inline { gap: 10px; font-size: 12px; }
  .axis text { font-size: 11px; }
  .loop-bar { gap: 8px; }
  .loop-stage img { min-height: 160px; }
  .seg button { padding: 6px 10px; }
  .tooltip { font-size: 12px; }
}

/* model maps are canvases here (drawn in the browser from the Worker's grids) */
.hero-map canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.loop-stage canvas { width: 100%; max-width: 1400px; height: auto; border-radius: 8px; background: #fff; cursor: crosshair; display: block; margin: 0 auto; }
.cmp-stage canvas { width: 100%; height: auto; border-radius: 8px; background: #fff; cursor: crosshair; display: block; }
