/* learnfromx — atmospheric design system.
 *
 * Full-viewport SVG landscape with mountains, stones, water
 * (partials/atmosphere.html), canvas particles and birds (js/atmosphere.js),
 * per-page mood tinting. Nunito for English, Zen Maru Gothic for Japanese.
 */

/* Fonts: each page links its one Google Fonts sheet in its <head>. */

:root {
  --primary: #4A4878;
  --rule: rgba(74, 72, 120, 0.12);
  --ink: #484668;
  --ink-soft: #504E68;
  --ink-muted: #7E7C94;
  --ink-faint: #A8A6B8;
  --bg: #ffffff;
  /* Dark base for the dusk scene: the sunrise dusk-tint is translucent, so it
     composites against this rather than the white --bg. Shared by both moods
     here (marketing, legal) so their dusk reads identically. */
  --dusk-base: #41395f;
  --font-display: 'Nunito', 'Helvetica Neue', sans-serif;
  --font-en: 'Nunito', 'Helvetica Neue', sans-serif;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --radius-lg: 14px;   /* cards — snapped down from 18 (read "too soft") */

  /* ── Type scale ──────────────────────────────────────────────────────────
     One deliberate scale (~1.22 ratio) so sizes stay consistent across every
     surface. Components reference these roles, never raw px. Sizes were chosen
     to absorb the prior ad-hoc values (9–96px) into named steps. */
  --fs-sm:      14px;   /* small / secondary body */
  --fs-body:    16px;   /* default body, inputs, button text */
  --fs-lead:    18px;   /* lead text, emphasized body, list items */

  /* ── Weights ── */
  --fw-light: 300;
  --fw-medium: 500;

  /* The bottom safe-area inset. Every bottom-anchored rule (here and in
     partials/cookie_consent.html) reads this instead of `env(safe-area-inset-bottom)` directly,
     so the Gecko override below has one place to act. */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
/* Firefox for Android (150+) reports the system navigation bar as the bottom
   inset while it never draws the page under that bar, so the space is counted
   twice and everything bottom-anchored floats high by that bar's height
   (Mozilla bug 2057232, regressed by bug 1994149; not drawing under
   the bar: bug 2015636). `-moz-appearance` is a Gecko-only property: Chrome, Safari and
   every iOS browser (all WebKit) keep their real inset. Desktop Firefox
   reports 0 anyway. Revisit once Firefox on Android draws edge to edge. */
@supports (-moz-appearance: none) {
  :root { --safe-bottom: 0px; }
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, input, select, textarea { font: inherit; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  color: var(--ink);
  font-family: var(--font-display);
  min-height: 100vh; min-height: 100dvh;
  background: var(--bg);
}

/* ── Atmosphere (fixed SVG landscape) ── */
/* The scene layer is pinned to the LARGE viewport (`lvh` = browser UI
   retracted) rather than sized by `inset: 0`. A fixed element sized by `inset`
   tracks the CURRENT visual viewport, so when Android retracts the URL bar the
   viewport grows ~60px before this layer does, and the strip that opens at the
   bottom paints the page background (--dusk-base, a blue-violet) as a bar.
   The `+ 2px` is an older bleed: under `viewport-fit=cover` a fixed bottom
   rounds a hair short of the physical screen and shows a sub-pixel line of
   `body` bg. The SVG uses `slice`, so painting past the fold is free.

   `#birdCanvas` and `#particles` must NOT join this rule — atmosphere.js sizes
   those to `innerHeight`.

   Known trade: things placed against the horizon still resolve against the
   CURRENT viewport, so on Android they and the scene can disagree by a toolbar
   height. One member so far: the ambient particle band in atmosphere.js,
   which spawns and attracts off `window.innerHeight * 0.65..0.95`. Anything
   new that anchors to the waterline joins it. Unverifiable headless; needs a
   real-device check. */
.atmosphere {
  position: fixed; top: 0; left: 0; right: 0; z-index: 54; pointer-events: none;
  height: calc(100vh + 2px);
  height: calc(100lvh + 2px);
}
.atmosphere svg { width: 100%; height: 100%; pointer-events: none; }
#birdCanvas { position: fixed; inset: 0; z-index: 54; pointer-events: none; }
#particles { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
/* Long-read pages: the text layer is z-55, so the motes stay in the scene and never cross the words. */
body:has(.atmosphere--legal) #particles { z-index: 54; }

.stone {
  cursor: pointer;
  transition: transform 0.6s var(--ease-out-expo);
  transform-origin: center bottom;
  pointer-events: auto;
}
/* .is-touched: the page covers the scene, so stone_touch.js follows the mouse
   and marks the stone it is over; :hover only matches where nothing covers it. */
.stone:is(:hover, .is-touched) { transform: translateX(3px); }
@media (prefers-reduced-motion: reduce) {
  .stone { transition: none; }
  .stone:is(:hover, .is-touched) { transform: none; }
}
.stone, .stone .stone-hit { pointer-events: auto !important; }
/* Reflection rides along with its stone's hover transform, but must not
   widen the hover hit area (it lives in the water below the stone). */
.stone .stone-reflection { pointer-events: none; }

/* The mountains no longer move, but this keeps them on their own layer, and
   dropping it shifts the scene's colours by a few levels. */
.mountain { will-change: transform; }

/* ── The dusk sky ──
   Every page shows the same dusk; no page has its own colour filter. This one
   dims the scene and pushes it toward amber, under the sunrise tint below. */
.atmosphere.is-caught-up {
  filter: brightness(0.89) saturate(1.12);
}

/* The caught-up dusk tint: a warm sunrise — a medium violet sky up top warming
   down through mauve/magenta to a coral/amber horizon, with a soft radial
   sun-glow cresting the bottom edge. The mid stops stay opaque enough (~0.56)
   behind hero/card text to keep thin light type legible. This is the single
   dusk tint for every mood. */
.atmosphere-dusk-tint {
  position: absolute; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 58% at 50% 109%,
      rgba(255, 179, 121, 0.34) 0%,
      rgba(255, 149, 108, 0.15) 36%,
      rgba(255, 149, 108, 0) 64%),
    linear-gradient(to bottom,
      rgba(71, 63, 113, 0.64) 0%,
      rgba(102, 68, 119, 0.60) 34%,
      rgba(151, 83, 113, 0.56) 60%,
      rgba(213, 121, 104, 0.50) 85%,
      rgba(242, 168, 113, 0.45) 100%);
}

/* The dusk scene needs a dark base under the translucent sunrise tint; on the
   default white body it washes out lighter. Keyed on the mood class, so the
   base is dark from first paint with no white flash. */
body:has(.atmosphere--marketing),
body:has(.atmosphere--legal) {
  background: var(--dusk-base);
}

/* ── Enchantment layer ── */
.noise-overlay {
  position: fixed; inset: 0; z-index: 48; pointer-events: none;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

/* ── Shared components ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 0; flex-shrink: 0; position: relative; z-index: 2;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
@media (min-width: 800px) { .topbar { padding: 20px 32px 0; } }

.brand {
  font: var(--fw-light) var(--fs-lead)/1 var(--font-en);
  color: var(--ink-faint); letter-spacing: 0.15em; text-transform: uppercase;
  text-decoration: none;
}

/* The topbar back-link paints straight onto the dusk sky. Behind the topbar
   that sky is a LIT mauve (rgb(126,119,151)) where white tops out near 4.2:1
   and near-black near 4.8:1, so the dusk rule below gives the link DARK ink on
   a soft frosted chip that lifts its own ground; the base ink measured
   1.05:1 there. The chip only paints the padding from "Touch target minimums"
   below, so the text does not move. The document pages (`body.is-night`, the
   dark-glass theme) show the same sky and take the same chip: their light ink
   measured 2.06:1 there. The dusk rule outranks `.back-link:hover`, so it
   restates the hover. */
.back-link {
  font: var(--fw-light) var(--fs-sm)/1 var(--font-en); color: var(--ink-soft);
  letter-spacing: 0.1em; text-transform: lowercase;
  border: none; background: none; cursor: pointer;
  padding: 8px 0; transition: color 0.2s, background-color 0.2s; text-decoration: none;
  opacity: 0; animation: settingsFade 0.3s 0.02s ease forwards;
}
.back-link:hover { color: var(--primary); }
.atmosphere.is-caught-up ~ * .back-link {
  color: #0e0a1c; background: rgba(255,255,255,0.32); border-radius: 999px;
}
.atmosphere.is-caught-up ~ * .back-link:hover { background: rgba(255,255,255,0.55); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font: var(--fw-medium) var(--fs-body)/1 var(--font-en);
  padding: 15px 32px; border-radius: var(--radius-lg);
  letter-spacing: 0.04em; text-decoration: none;
  cursor: pointer; transition: all 0.25s; border: 1px solid transparent;
}
/* Solid indigo (the toggle on the dontcount page). */
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: #5A588A; }

/* ── Dark-glass overrides (the document pages) ──
   Triggered by `body.is-night` (layouts/document.html). These pages render
   the caught_up sunrise sky with dark frosted panes, matching the landing's
   glass-over-sunrise look. The class name is historical: it selects the
   dark-card theme, not a night sky. */
body.is-night .brand { color: rgba(210,205,230,0.88); }

/* ── Dusk-mode overrides ──
   Near-white with a lavender lean, matching the landing palette direction. */
.atmosphere.is-caught-up ~ * .brand { color: rgba(235,232,245,0.92); }

/* The back link's fade-in. */
@keyframes settingsFade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ── PWA standalone mode ──
   Safe area insets for notched devices, touch target minimums. */
@supports (padding-top: env(safe-area-inset-top)) {
  .topbar { padding-top: calc(20px + env(safe-area-inset-top)); }
  @media (min-width: 800px) { .topbar { padding-top: calc(20px + env(safe-area-inset-top)); } }
}

/* Touch target minimums (44px per Apple HIG) */
.back-link { min-height: 44px; display: inline-flex; align-items: center; padding: 8px 12px; }
