/* ============================================================================
   Atmosphere — 3D vertical cross-section of the sky
   tinyblue.dev · feature slug: atmosphere-3d-vertical-cross-section-of-
   Apple Liquid Glass chrome over a Three.js scene. Scoped under .atm-* so it
   cannot collide with the rest of the weather page. Theme + reduced-motion aware.
   ============================================================================ */

.atm-shell,
.atm-sheet,
.atm-toast,
.atm-boot {
  --atm-glass: color-mix(in oklab, var(--tb-surface) 64%, transparent);
  --atm-glass-strong: color-mix(in oklab, var(--tb-surface) 86%, transparent);
  --atm-edge: color-mix(in oklab, var(--tb-ink) 12%, transparent);
  --atm-edge-spec: color-mix(in oklab, #ffffff 60%, transparent);
  --atm-ink: var(--tb-ink);
  --atm-ink-2: var(--tb-ink-2);
  --atm-ink-3: var(--tb-ink-3);
  --atm-accent: var(--tb-accent-2, #2997ff);
  --atm-cloud: #cfe2ff;
  --atm-humid: #5aa6ff;
  --atm-wind: #21d7c4;
  --atm-pressure: #b78bff;
  --atm-soil-s: #f5b84b;
  --atm-soil-m: #d98a4a;
  --atm-soil-d: #9c5b3b;
  --atm-rain: #6fb6ff;
  --atm-snow: #e6f2ff;
  /* clearance so bottom-anchored controls never sit under the shared
     network-bar (#tbn-root), which occupies ~the bottom 72px of the viewport */
  --atm-navbar: 84px;
}

html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(120% 120% at 50% -10%,
      color-mix(in oklab, var(--atm-accent) 14%, var(--tb-bg)) 0%,
      var(--tb-bg) 60%);
  color: var(--tb-ink);
  font-family: var(--tb-font-sans, -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── boot overlay ──────────────────────────────────────────────────────── */
.atm-boot {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: radial-gradient(120% 120% at 50% 10%,
      color-mix(in oklab, var(--atm-accent) 18%, var(--tb-bg)), var(--tb-bg));
  transition: opacity .5s var(--tb-ease, ease), visibility .5s;
}
.atm-boot.is-gone { opacity: 0; visibility: hidden; pointer-events: none; }
.atm-boot-inner { text-align: center; display: grid; gap: 10px; justify-items: center; }
.atm-boot-inner b { font-size: 17px; letter-spacing: -.01em; }
.atm-boot-inner span { font-size: 12.5px; color: var(--tb-ink-3); }
.atm-boot-orbit { position: relative; width: 64px; height: 64px; }
.atm-boot-orbit span {
  position: absolute; inset: 0; margin: auto;
  border-radius: 50%; border: 2px solid transparent;
  border-top-color: var(--atm-accent);
  animation: atm-spin 1.1s linear infinite;
}
.atm-boot-orbit span:nth-child(2) { inset: 10px; border-top-color: var(--atm-wind); animation-duration: 1.6s; animation-direction: reverse; }
.atm-boot-orbit span:nth-child(3) { inset: 20px; border-top-color: var(--atm-soil-s); animation-duration: 2.1s; }
@keyframes atm-spin { to { transform: rotate(360deg); } }

/* ── shell + stage ─────────────────────────────────────────────────────── */
.atm-shell {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.atm-topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px clamp(12px, 2.4vw, 22px);
  background: linear-gradient(180deg,
      color-mix(in oklab, var(--tb-bg) 72%, transparent),
      color-mix(in oklab, var(--tb-bg) 30%, transparent));
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  border-bottom: 1px solid var(--atm-edge);
  z-index: 20;
}
.atm-topbar-spacer { flex: 1 1 auto; }

.atm-brand {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: inherit;
}
.atm-brand-mark {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(150deg, color-mix(in oklab, var(--atm-accent) 36%, transparent), color-mix(in oklab, var(--atm-wind) 26%, transparent));
  box-shadow: inset 0 1px 0 var(--atm-edge-spec), var(--tb-shadow-1);
}
.atm-brand-mark svg { width: 19px; height: 19px; fill: none; stroke: var(--tb-ink); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.atm-brand-text { display: grid; line-height: 1.05; }
.atm-brand-text b { font-size: 15px; letter-spacing: -.015em; }
.atm-brand-text span { font-size: 11px; color: var(--tb-ink-3); }

.atm-place {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--tb-ink-2);
  padding: 5px 10px; border-radius: 999px;
  background: var(--atm-glass);
  border: 1px solid var(--atm-edge);
}
.atm-place svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; }
@media (max-width: 720px) { .atm-place { display: none; } }

.atm-modeled {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11.5px; color: var(--tb-ink-2);
  padding: 5px 11px; border-radius: 999px;
  background: var(--atm-glass);
  border: 1px solid var(--atm-edge);
  cursor: help;
}
.atm-modeled-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--atm-pressure);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--atm-pressure) 28%, transparent);
}
@media (max-width: 560px) { .atm-modeled { font-size: 0; gap: 0; padding: 9px; } }

.atm-iconbtn {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px; cursor: pointer;
  background: var(--atm-glass);
  border: 1px solid var(--atm-edge);
  color: var(--tb-ink-2);
  transition: background var(--tb-d-fast, .16s), color var(--tb-d-fast, .16s), transform var(--tb-d-fast, .16s);
}
.atm-iconbtn:hover { background: var(--atm-glass-strong); color: var(--tb-ink); }
.atm-iconbtn:active { transform: scale(.94); }
.atm-iconbtn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.atm-iconbtn[data-on="1"] { color: var(--atm-accent); border-color: color-mix(in oklab, var(--atm-accent) 40%, transparent); }

/* stage */
.atm-stage { position: relative; overflow: hidden; }
.atm-canvas-wrap { position: absolute; inset: 0; touch-action: none; cursor: grab; }
.atm-canvas-wrap:active { cursor: grabbing; }
.atm-canvas-wrap canvas { display: block; width: 100% !important; height: 100% !important; }

.atm-grab-hint {
  position: absolute; left: 50%; bottom: calc(var(--atm-navbar) + 4px); transform: translateX(-50%);
  font-size: 11px; color: var(--tb-ink-3);
  padding: 5px 12px; border-radius: 999px;
  background: var(--atm-glass);
  border: 1px solid var(--atm-edge);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  pointer-events: none; opacity: .85;
  transition: opacity .6s;
}
.atm-grab-hint.is-gone { opacity: 0; }

/* ── HUD (left) ────────────────────────────────────────────────────────── */
.atm-hud {
  position: absolute; top: 14px; left: 14px;
  width: min(280px, calc(100vw - 28px));
  padding: 14px;
  border-radius: var(--tb-radius-lg, 22px);
  background: var(--atm-glass);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid var(--atm-edge);
  box-shadow: inset 0 1px 0 var(--atm-edge-spec), var(--tb-shadow-2);
  display: grid; gap: 7px;
  z-index: 12;
}
.atm-hud-stamp {
  font-size: 11px; font-weight: 650; letter-spacing: .02em; text-transform: uppercase;
  color: var(--atm-accent);
}
.atm-hud-cond { font-size: 16px; font-weight: 600; letter-spacing: -.01em; margin-bottom: 4px; }
.atm-hud-row {
  display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 9px;
  font-size: 12.5px; color: var(--tb-ink-2);
  padding: 3px 0;
}
.atm-hud-row .atm-hud-v { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--tb-ink); font-size: 13px; }
.atm-hud-swatch { width: 11px; height: 11px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.atm-hud-swatch[data-sw="cloud"]    { background: var(--atm-cloud); }
.atm-hud-swatch[data-sw="humidity"] { background: var(--atm-humid); }
.atm-hud-swatch[data-sw="wind"]     { background: var(--atm-wind); }
.atm-hud-swatch[data-sw="pressure"] { background: var(--atm-pressure); }
.atm-hud-swatch[data-sw="soil-s"]   { background: var(--atm-soil-s); }
.atm-hud-swatch[data-sw="soil-m"]   { background: var(--atm-soil-m); }
.atm-hud-swatch[data-sw="soil-d"]   { background: var(--atm-soil-d); }
.atm-hud-strata {
  margin-top: 4px; padding-top: 6px;
  border-top: 1px dashed var(--atm-edge);
}
.atm-hud-precip[hidden] { display: none !important; }
.atm-hud-precip {
  margin-top: 4px; padding: 7px 10px;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600;
  border-radius: 12px;
  background: color-mix(in oklab, var(--atm-rain) 18%, transparent);
  border: 1px solid color-mix(in oklab, var(--atm-rain) 40%, transparent);
  color: var(--tb-ink);
}
.atm-hud-precip-glyph { font-size: 16px; }
.atm-hud-row.is-off { opacity: .32; }

/* ── layer toggles (bottom-left) ───────────────────────────────────────── */
.atm-layers {
  position: absolute; left: 14px; bottom: var(--atm-navbar);
  width: min(220px, calc(100vw - 28px));
  padding: 12px 12px 8px;
  border-radius: var(--tb-radius-card, 16px);
  background: var(--atm-glass);
  -webkit-backdrop-filter: blur(24px) saturate(170%);
  backdrop-filter: blur(24px) saturate(170%);
  border: 1px solid var(--atm-edge);
  box-shadow: inset 0 1px 0 var(--atm-edge-spec), var(--tb-shadow-1);
  z-index: 12;
}
.atm-layers h4 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--tb-ink-3); }
.atm-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 2px; font-size: 12.5px; cursor: pointer; color: var(--tb-ink-2);
  border-radius: 8px;
}
.atm-toggle:hover { color: var(--tb-ink); }
.atm-toggle:focus-visible { outline: 2px solid var(--atm-accent); outline-offset: 2px; }
.atm-switch {
  position: relative; width: 34px; height: 20px; flex: none;
  border-radius: 999px; background: color-mix(in oklab, var(--tb-ink) 22%, transparent);
  transition: background var(--tb-d-fast, .16s);
}
.atm-switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: var(--tb-shadow-1);
  transition: transform var(--tb-d-fast, .16s) var(--tb-ease, ease);
}
.atm-toggle[aria-checked="true"] .atm-switch { background: var(--atm-accent); }
.atm-toggle[aria-checked="true"] .atm-switch::after { transform: translateX(14px); }

/* ── vertical scrubber (right) ─────────────────────────────────────────── */
.atm-scrubber {
  position: absolute; top: 14px; right: 14px; bottom: var(--atm-navbar);
  width: 64px;
  display: grid; grid-template-rows: auto 1fr auto; gap: 8px; justify-items: center;
  padding: 12px 8px;
  border-radius: var(--tb-radius-lg, 22px);
  background: var(--atm-glass);
  -webkit-backdrop-filter: blur(26px) saturate(175%);
  backdrop-filter: blur(26px) saturate(175%);
  border: 1px solid var(--atm-edge);
  box-shadow: inset 0 1px 0 var(--atm-edge-spec), var(--tb-shadow-2);
  z-index: 12;
}
.atm-scrub-cap { font-size: 10px; color: var(--tb-ink-3); font-weight: 600; letter-spacing: .02em; }
.atm-scrub-track {
  position: relative; width: 8px; height: 100%;
  border-radius: 999px;
  background: linear-gradient(180deg,
      color-mix(in oklab, var(--atm-accent) 34%, transparent),
      color-mix(in oklab, var(--tb-ink) 16%, transparent));
  cursor: pointer; touch-action: none;
  overflow: visible;
}
.atm-scrub-track:focus-visible { outline: 2px solid var(--atm-accent); outline-offset: 4px; }
.atm-scrub-fill {
  position: absolute; left: 0; right: 0; top: 0;
  border-radius: 999px;
  background: color-mix(in oklab, var(--tb-ink) 22%, transparent);
  height: 0%;
}
.atm-scrub-ticks { position: absolute; inset: 0; pointer-events: none; }
.atm-scrub-ticks i {
  position: absolute; left: -3px; right: -3px; height: 1px;
  background: color-mix(in oklab, var(--tb-ink) 24%, transparent);
}
.atm-scrub-thumb {
  position: absolute; left: 50%; top: 0;
  width: 22px; height: 22px; transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #fff; border: 3px solid var(--atm-accent);
  box-shadow: var(--tb-shadow-2);
  cursor: grab;
}
.atm-scrub-thumb:active { cursor: grabbing; }
.atm-scrub-bubble {
  position: absolute; right: 30px; top: 50%; transform: translateY(-50%);
  white-space: nowrap; font-size: 11px; font-weight: 650; font-variant-numeric: tabular-nums;
  padding: 4px 9px; border-radius: 8px;
  background: var(--atm-glass-strong);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--atm-edge);
  color: var(--tb-ink);
  box-shadow: var(--tb-shadow-1);
  pointer-events: none;
}
@media (max-width: 560px) {
  .atm-scrubber { width: 54px; }
  .atm-hud { width: min(220px, calc(100vw - 80px)); }
}

/* ── AI explainer FAB + sheet ──────────────────────────────────────────── */
.atm-explain-fab {
  position: absolute; right: 90px; bottom: var(--atm-navbar);
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 16px 11px 13px;
  border: 0; border-radius: 999px; cursor: pointer;
  font-size: 13.5px; font-weight: 650; color: #fff;
  background: linear-gradient(135deg, var(--atm-accent), color-mix(in oklab, var(--atm-pressure) 70%, var(--atm-accent)));
  box-shadow: 0 14px 40px -10px color-mix(in oklab, var(--atm-accent) 70%, transparent), inset 0 1px 0 rgba(255,255,255,.4);
  transition: transform var(--tb-d-fast, .16s);
  z-index: 14;
}
.atm-explain-fab:hover { transform: translateY(-2px); }
.atm-explain-fab:active { transform: translateY(0) scale(.97); }
.atm-explain-fab svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.atm-fab-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 0 rgba(255,255,255,.6);
  animation: atm-pulse 2.4s ease-out infinite;
}
@keyframes atm-pulse { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.5); } 70%,100% { box-shadow: 0 0 0 10px rgba(255,255,255,0); } }
@media (max-width: 560px) {
  .atm-explain-fab { right: 14px; bottom: calc(var(--atm-navbar) + 56px); }
  .atm-layers { bottom: calc(var(--atm-navbar) + 56px); }
}

.atm-sheet-scrim {
  position: fixed; inset: 0; z-index: 40;
  background: color-mix(in oklab, #04060c 52%, transparent);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s;
}
.atm-sheet-scrim.is-open { opacity: 1; visibility: visible; }
.atm-sheet {
  position: fixed; z-index: 42; top: 0; right: 0; bottom: 0;
  width: min(420px, 92vw);
  padding: 22px clamp(16px, 3vw, 26px) calc(28px + env(safe-area-inset-bottom, 0));
  background: var(--atm-glass-strong);
  -webkit-backdrop-filter: blur(34px) saturate(180%);
  backdrop-filter: blur(34px) saturate(180%);
  border-left: 1px solid var(--atm-edge);
  box-shadow: var(--tb-shadow-soft);
  transform: translateX(100%); transition: transform .42s var(--tb-ease, cubic-bezier(.32,.72,0,1));
  overflow-y: auto;
  display: grid; grid-template-rows: auto auto auto 1fr; gap: 12px; align-content: start;
}
.atm-sheet.is-open { transform: translateX(0); }
.atm-sheet-head { display: flex; align-items: center; gap: 10px; }
.atm-sheet-mark {
  width: 32px; height: 32px; flex: none; display: grid; place-items: center;
  border-radius: 10px; background: linear-gradient(150deg, color-mix(in oklab, var(--atm-accent) 34%, transparent), color-mix(in oklab, var(--atm-pressure) 30%, transparent));
}
.atm-sheet-mark svg { width: 17px; height: 17px; fill: none; stroke: var(--tb-ink); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.atm-sheet-head h3 { margin: 0; font-size: 17px; letter-spacing: -.015em; flex: 1; }
.atm-sheet-sub { margin: 0; font-size: 12px; color: var(--tb-ink-3); line-height: 1.5; }
.atm-sheet-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.atm-sheet-chips span {
  font-size: 10.5px; font-weight: 600; letter-spacing: .01em;
  padding: 4px 9px; border-radius: 999px;
  background: var(--atm-glass);
  border: 1px solid var(--atm-edge);
  color: var(--tb-ink-2);
  font-variant-numeric: tabular-nums;
}
.atm-sheet-body { font-size: 14px; line-height: 1.62; color: var(--tb-ink); }
.atm-sheet-body p { margin: 0 0 12px; }
.atm-sheet-cursor {
  display: inline-block; width: 8px; height: 1.05em; vertical-align: -2px;
  margin-left: 2px; border-radius: 2px;
  background: var(--atm-accent);
  animation: atm-blink 1s step-end infinite;
}
@keyframes atm-blink { 50% { opacity: 0; } }

/* ── toast ─────────────────────────────────────────────────────────────── */
.atm-toast {
  position: fixed; left: 50%; bottom: 78px; transform: translate(-50%, 14px);
  z-index: 50; max-width: 84vw;
  padding: 9px 16px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
  background: var(--atm-glass-strong);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border: 1px solid var(--atm-edge);
  box-shadow: var(--tb-shadow-2);
  color: var(--tb-ink);
  opacity: 0; visibility: hidden; transition: opacity .3s, transform .3s, visibility .3s;
}
.atm-toast.is-on { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

/* ── 2D fallback ───────────────────────────────────────────────────────── */
.atm-fallback[hidden] { display: none !important; }
.atm-fallback {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 12px;
  padding: 24px; text-align: center;
}
.atm-fallback h3 { margin: 0; font-size: 20px; }
.atm-fallback-sub { margin: 0; font-size: 13px; color: var(--tb-ink-3); }
.atm-fallback-strata {
  width: min(440px, 88vw); margin: 8px auto 0;
  display: grid; gap: 2px;
  border-radius: 16px; overflow: hidden;
  border: 1px solid var(--atm-edge);
  box-shadow: var(--tb-shadow-2);
}
.atm-fallback-strata .atm-fb-band {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; font-size: 13px; color: #0b1020;
  text-shadow: 0 1px 0 rgba(255,255,255,.35);
}
.atm-fallback-strata .atm-fb-band b { font-variant-numeric: tabular-nums; }

/* ── reduced motion ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .atm-boot-orbit span,
  .atm-fab-dot { animation: none !important; }
  .atm-sheet, .atm-sheet-scrim, .atm-toast { transition-duration: .01ms !important; }
  .atm-grab-hint { display: none; }
}
