/* ═══════════════════════════════════════════════════════════
   The world: HUD, the page shell, and (from Task 5) the terrain.
   ═══════════════════════════════════════════════════════════ */

/* ── HUD ─────────────────────────────────────────────────
   Fixed across the top. Pixel type, short strings only. */
.hud {
  position: fixed; inset: 0 0 auto 0; z-index: 200;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px clamp(10px, 2.4vw, 18px);
  padding-left: max(clamp(10px, 2.4vw, 18px), env(safe-area-inset-left));
  padding-right: max(clamp(10px, 2.4vw, 18px), env(safe-area-inset-right));
  padding-top: max(9px, env(safe-area-inset-top));
  /* solid first: color-mix() is 2023+ and older WebViews drop the whole
     declaration, which left the HUD transparent over bright sky */
  /* Solid, not 92%. A fixed overlay cannot be contrast-checked against what
     is painted behind it, and "mostly opaque over an unknown backdrop" is not
     an answer you can give about the one element that is always on screen. */
  background: var(--ink);
  border-bottom: var(--bw) solid var(--ink);
  font: 400 var(--t-pixel-sm)/1 var(--f-pixel);
  color: var(--cream);
}
.hud__l { display: flex; align-items: center; gap: clamp(8px, 2vw, 15px); min-width: 0; }
.hud__name { color: var(--gold); }
.hud__hp { font-family: var(--f-body); font-size: 11px; color: #FF5C7A; letter-spacing: 1px; }
.hud__world { color: var(--ore-cyan); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud__r { display: flex; align-items: center; gap: 5px; flex: none; }

/* Controls are ≥44px tall for touch; the visible chrome is smaller. */
.ctl {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; padding: 0 9px;
  font: 700 10px/1 var(--f-body); letter-spacing: .1em; text-transform: uppercase;
  color: var(--cream);
}
.ctl > span {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 8px; border: 2px solid currentColor;
}
.lang { gap: 0; padding: 0; }
.lang__opt {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 7px; border: 2px solid var(--cream); border-right-width: 1px;
}
.lang__opt + .lang__opt { border-left-width: 1px; border-right-width: 2px; }
.lang__opt.is-on { background: var(--gold); color: var(--ink); border-color: var(--gold); }

.ic { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; }

/* the theme button shows the state you'd switch TO */
.ic--night { display: none; }
:root[data-theme="night"] .ic--day { display: none; }
:root[data-theme="night"] .ic--night { display: inline; }

/* ── page shell ───────────────────────────────────────── */
.page {
  position: relative; z-index: 10;
  max-width: var(--page); margin: 0 auto;
  padding: 0 var(--gut);
}

.world {
  position: relative;
  padding: clamp(54px, 9vw, 104px) 0;
  scroll-margin-top: 70px;
}
/* .world--first, not :first-of-type — a pseudo-class outranks the modifier
   class and quietly beat every responsive override of this padding. */

/* Section heading: pixel label over a display title. */
.world__label {
  display: inline-block; margin-bottom: 11px;
  font: 400 var(--t-pixel-sm)/1.5 var(--f-pixel);
  letter-spacing: .06em;
  color: var(--ink); background: var(--gold);
  padding: 7px 9px; border: var(--bw) solid var(--ink);
}
.world__h {
  overflow: hidden;
  font: 400 var(--t-h2)/1.02 var(--f-display);
  letter-spacing: -.015em;
  margin-bottom: .32em;
}
.world__deck {
  font-size: var(--t-lead); max-width: 56ch;
  color: var(--muted-on-ink);
}

/* Worlds 1-2 sit on the sky; 3-6 are underground. Each world carries the
   ground it is read against, so contrast is answerable at every step.
   Task 5 turns these flat fills into the parallax terrain. */
.world { background-color: var(--deep); }

/* background-color is the colour text is actually read against; the gradient
   and the speckle ride on top as background-image. Keeping both in sync is
   what makes the contrast check meaningful rather than decorative. */
.world--surface {
  background-color: var(--sky-hi);
  background-image: linear-gradient(180deg, var(--sky-hi), var(--sky-lo));
}
#world3 { background-color: var(--cave-dirt); }
#world4 { background-color: var(--cave-deep); }
#world5 { background-color: var(--cave-stone); }
#world6 { background-color: var(--deep); }

/* the material, visible but never bright enough to fight the text */
#world3, #world4, #world5 {
  background-image: radial-gradient(rgba(255,246,229,.055) 1.6px, transparent 1.8px);
  background-size: 11px 11px;
}

/* The page shell is the content column; the ground must span the viewport. */
.page { max-width: none; padding: 0; }
.world > * { max-width: var(--page); margin-inline: auto; min-width: 0; }
.world { padding-inline: var(--gut); }

.world--surface { color: var(--on-sky); }
.world--surface .world__deck { color: var(--muted-on-sky); }
.world--surface .world__label { background: var(--ink); color: var(--gold); }

/* ═══════════════════════════════════════════════════════════
   Terrain.

   The stacked world backgrounds ARE the cross-section — they stay opaque
   so the contrast check has a truthful ground to measure against. What
   floats over them is decoration: sun, clouds, torches, ore. Task 12
   parallaxes these; the ground itself never moves, so no amount of
   motion can change what the text is read against.
   ═══════════════════════════════════════════════════════════ */

.world { position: relative; overflow: hidden; isolation: isolate; }
.world > *:not(.terrain) { position: relative; z-index: 2; }

.terrain {
  position: absolute; inset: 0; z-index: 1;
  pointer-events: none; display: block;
}
.terrain > i { position: absolute; display: block; }

/* ── sky furniture ── */
.sun {
  right: clamp(18px, 7vw, 92px); top: clamp(58px, 9vw, 104px);
  width: clamp(30px, 5vw, 52px); aspect-ratio: 1;
  background: var(--gold); border: var(--bw) solid var(--ink);
  box-shadow: 0 0 36px 13px rgba(255,199,0,.4);
}
:root[data-theme="night"] .sun {
  background: #E8E4D4;
  box-shadow: 0 0 30px 10px rgba(232,228,212,.26);
  clip-path: polygon(0 0,100% 0,100% 100%,0 100%,0 0,62% 0,62% 100%,0 100%);
}

.cloud {
  background: #fff; border: var(--bw) solid var(--ink);
  opacity: .96;
}
:root[data-theme="night"] .cloud { background: #44536B; opacity: .7; }
.cloud { border-radius: 2px; }
.cloud::before {
  content: ''; position: absolute; background: inherit;
  border: var(--bw) solid var(--ink); border-radius: 3px;
  /* sit the lump so its own bottom border lands under the body's top border */
  clip-path: inset(0 0 var(--bw) 0);
}
.cloud--a { left: 5%;  top: clamp(74px, 11vw, 132px); width: 62px; height: 17px; }
.cloud--a::before { width: 34px; height: 21px; top: -21px; left: 12px; }
.cloud--b { right: 26%; top: clamp(126px, 17vw, 206px); width: 44px; height: 14px; }
.cloud--b::before { width: 25px; height: 18px; top: -18px; left: 10px; }
.cloud--c { left: 8%;  top: clamp(40px, 6vw, 76px); width: 50px; height: 15px; }
.cloud--c::before { width: 28px; height: 19px; top: -19px; left: 11px; }

/* ── the grass line: where the sky stops and the digging starts ── */
#world3::before {
  content: ''; position: absolute; inset: 0 0 auto 0; z-index: 3;
  height: 20px; background: var(--grass);
  border-bottom: 4px solid var(--ink);
  box-shadow: inset 0 5px 0 var(--grass-lit);
}
/* a little soil hanging off the underside of the turf */
#world3::after {
  content: ''; position: absolute; inset: 20px 0 auto 0; z-index: 3; height: 14px;
  background:
    linear-gradient(90deg, var(--grass) 0 14px, transparent 14px) 0 0/46px 14px repeat-x,
    linear-gradient(90deg, transparent 0 26px, var(--grass) 26px 34px, transparent 34px) 0 0/46px 7px repeat-x;
}

/* ── torches: the underground light source ── */
.torch { width: 8px; height: 22px; background: var(--dirt-dk); border: 2px solid var(--ink); }
.torch::after {
  content: ''; position: absolute; top: -15px; left: -6px;
  width: 19px; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, #FFE066, var(--torch) 54%, transparent 72%);
  opacity: var(--torch-glow);
}
.torch--a { left: 4%;  top: 16%; }
.torch--b { right: 6%; top: 24%; }
.torch--c { left: 7%;  top: 20%; }

/* ── ore: buried colour ── */
.ore {
  width: 13px; aspect-ratio: 1; transform: rotate(45deg);
  background: var(--ore-cyan); border: 2px solid var(--ink);
  box-shadow: 0 0 10px var(--ore-cyan);
}
.ore--b, .ore--d, .ore--f { background: var(--ore-mag); box-shadow: 0 0 10px var(--ore-mag); }
.ore--a { left: 7%;   bottom: 22%; }
.ore--b { left: 12%;  bottom: 14%; }
.ore--c { right: 11%; bottom: 30%; }
.ore--d { right: 17%; bottom: 20%; }
.ore--e { left: 5%;   bottom: 26%; }
.ore--f { right: 9%;  bottom: 16%; }

/* ── night dims the whole underground a little further ── */
.world:not(.world--surface) .terrain::after {
  content: ''; position: absolute; inset: 0; background: var(--ambient);
}

@media (prefers-reduced-motion: no-preference) {
  .torch::after { animation: flick .42s steps(2, end) infinite; }
  .ore { animation: glint 3.4s ease-in-out infinite; }
  .ore--b { animation-delay: .7s; } .ore--c { animation-delay: 1.3s; }
  .ore--d { animation-delay: 2s; }  .ore--e { animation-delay: .4s; }
  .ore--f { animation-delay: 1.7s; }
}
@keyframes flick { 0%, 100% { opacity: var(--torch-glow); transform: scale(1); }
                   50% { opacity: calc(var(--torch-glow) * .72); transform: scale(.86); } }
@keyframes glint { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.45); } }

/* ═══════════════════════════════════════════════════════════
   Cimol. Orange, four poses, drawn as SVG so she recolours with the
   theme and stays sharp at any size.
   ═══════════════════════════════════════════════════════════ */
.cat { display: block; fill: none; }
.cat use { pointer-events: none; }

/* walking the ground line; Task 12 drives --walk from scroll progress */
.rider {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 150;
  height: 0; pointer-events: none;
}
.cat--rider {
  width: 54px; height: 32px;
  position: absolute; bottom: max(8px, env(safe-area-inset-bottom)); left: 0;
  transform: translateX(calc(var(--walk, 0) * (100vw - 62px)));
}

.cat--sheet {
  width: clamp(52px, 8vw, 78px); aspect-ratio: 150 / 156;
  margin: -14px 0 0 clamp(8px, 2vw, 22px);
}

.cat--sleep { width: clamp(72px, 11vw, 108px); aspect-ratio: 230 / 116; margin: 12px 0 6px; opacity: .85; }

/* ── the Duck Hunt payload ──────────────────────────────
   The dog that pops up and laughs at you is the only thing most people
   remember about Duck Hunt. Cimol inherits it, on the one joke that
   earns it. */
.bugbox {
  position: relative; margin-top: clamp(20px, 3.6vw, 32px);
  padding: clamp(14px, 2.6vw, 20px);
  padding-right: clamp(86px, 15vw, 130px);
  background: #141019;  /* fallback: color-mix is 2023+ */
  background: color-mix(in srgb, var(--ink) 88%, transparent);
  border: var(--bw) solid var(--torch); box-shadow: var(--shadow-sm);
}
.bugbox__l { margin: 0 0 4px; font: 400 var(--t-pixel-xs)/1.4 var(--f-pixel); color: var(--torch); }
.bugbox__n {
  margin: 0 0 5px; font: 400 clamp(30px, 6vw, 52px)/1 var(--f-display); color: var(--cream);
}
.bugbox__b { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--muted-on-ink); max-width: 44ch; }
.cat--taunt {
  position: absolute; right: clamp(8px, 2vw, 18px); bottom: 0;
  width: clamp(68px, 12vw, 104px); aspect-ratio: 150 / 156;
}

@media (prefers-reduced-motion: no-preference) {
  .cat--sheet .c-tail, .cat--sleep .c-tail { transform-origin: 70% 80%; animation: sway 2.6s ease-in-out infinite; }
  .cat--taunt .c-paw { transform-origin: 70% 70%; animation: wave .7s ease-in-out infinite; }
  .cat .c-eye { animation: blink 4.2s steps(1, end) infinite; }
  .cat--rider .c-legf { animation: step .36s steps(2, end) infinite; }
  .cat--rider .c-legb { animation: step .36s steps(2, end) infinite reverse; }
}
@keyframes sway  { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(7deg); } }
@keyframes wave  { 0%, 100% { transform: rotate(-12deg); } 50% { transform: rotate(16deg); } }
@keyframes blink { 0%, 95% { transform: scaleY(1); } 96%, 100% { transform: scaleY(.12); } }
@keyframes step  { 0% { transform: translateY(0); } 100% { transform: translateY(-4px); } }
.cat .c-eye { transform-origin: center; }

/* ═══════════════════════════════════════════════════════════
   Boot screen.

   Only shown when scripts run: .boot is display:none by default and the
   loader turns it on. A reader without JavaScript never sees a spinner
   they cannot dismiss, and the page underneath is already complete.
   ═══════════════════════════════════════════════════════════ */
.boot { display: none; }

html.booting .boot {
  display: grid; place-items: center;
  position: fixed; inset: 0; z-index: 900;
  background: var(--deep);
  background-image:
    linear-gradient(180deg, rgba(74,144,226,.16), transparent 45%),
    radial-gradient(rgba(255,246,229,.06) 1.4px, transparent 1.6px);
  background-size: 100% 100%, 13px 13px;
}
html.booted .boot { display: none; }
html.booting:not(.booted) body { overflow: hidden; }

.boot__in { width: min(520px, 86vw); text-align: left; }

.boot__brand {
  margin: 0; display: block;
  font: 400 clamp(26px, 6.4vw, 52px)/1.02 var(--f-display);
  letter-spacing: -.025em; color: var(--cream);
}
.boot__brand { overflow: hidden; }
.boot__brand span { display: block; color: var(--gold); }
.boot__brand b { display: block; font-weight: 400; }

.boot__role {
  margin: 10px 0 0; display: inline-block;
  background: var(--ink); color: var(--gold);
  padding: 6px 9px;
  font: 700 clamp(9px, 1.6vw, 11px)/1 var(--f-body);
  letter-spacing: .13em; text-transform: uppercase;
}

.boot__sub {
  margin: clamp(16px, 4vw, 26px) 0 9px;
  font: 400 var(--t-pixel-sm)/1.6 var(--f-pixel);
  letter-spacing: .1em; color: var(--ore-cyan);
}

.boot__bar {
  height: 20px; border: var(--bw) solid var(--cream);
  background: rgba(0,0,0,.4); padding: 3px; overflow: hidden;
}
.boot__bar i {
  display: block; height: 100%; width: 0;
  background: var(--gold);
  box-shadow: inset -4px 0 0 rgba(0,0,0,.22);
}
.boot__pct {
  margin: 9px 0 0; text-align: right;
  font: 400 var(--t-pixel-md)/1 var(--f-pixel); color: var(--gold);
}

.boot__log {
  margin: clamp(14px, 3vw, 22px) 0 0; min-height: 5.6em;
  font: 400 var(--t-pixel-xs)/1.9 var(--f-pixel); color: var(--muted-on-ink);
}
.boot__log li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.boot__log li::before { content: '> '; color: var(--grass-lit); }
.boot__log li.ok::after { content: ' OK'; color: var(--gold); }

.boot__cat {
  position: absolute; bottom: 12%; left: 0;
  width: 58px; height: 34px;
  transform: translateX(calc(var(--boot, 0) * (100vw - 70px)));
}

/* the handover: a solid block wipes across and reveals the world behind it */
.boot__wipe {
  position: absolute; inset: 0; background: var(--gold);
  transform: scaleY(0); transform-origin: bottom center;
}

@media (prefers-reduced-motion: reduce) {
  html.booting .boot { display: none; }
  html.js:not(.booted) body { overflow: auto; }
}
