/* Launch + Home v2 (web/screens.js). Board #7 (launch A2 temple) and #10 (Home v2, msg #290).
   Theme tokens only (web/theme.css, assets/ui/kit.css). Motion: transform / opacity only.
   Every image has a fallback layer: a missing file shows the next layer, never a broken box. */

/* ============ Launch ============ */
.launch {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: end center;
  overflow: hidden; cursor: pointer;
  background: radial-gradient(circle at 50% 38%, var(--table-2), var(--arena-3) 70%);
  -webkit-tap-highlight-color: transparent;
  transition: opacity 300ms var(--ease-out);
}
.launch.is-leaving { opacity: 0; pointer-events: none; }
.launch__bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* it starts after the logo (#730), so it fades in over the CSS gradient instead of popping */
.launch__bg { opacity: 0; transition: opacity 300ms var(--ease-out); }
.launch__bg.is-in { opacity: 1; }
.launch__front {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  gap: clamp(8px, 3dvh, 28px);
  padding-bottom: max(clamp(20px, 7dvh, 72px), env(safe-area-inset-bottom));
  width: 100%;
}
.launch__logo {
  width: min(64vw, 92dvh * 1400 / 452 * 0.36, 860px); height: auto; aspect-ratio: 1400 / 452;
  filter: drop-shadow(0 8px 18px color-mix(in srgb, var(--arena-3) 70%, transparent));
  animation: launch-pop 700ms var(--ease-bounce) both;
}
.launch__brand { margin: 0; display: flex; flex-direction: column; align-items: center; } /* the page h1 (a11y #987) */
.launch__title {
  display: block; margin: 0; color: var(--gold); text-align: center;
  font: var(--fw-display) clamp(40px, 9dvh, 88px) / 1 var(--font-display);
  -webkit-text-stroke: var(--text-stroke) var(--ink); paint-order: stroke fill;
  text-shadow: var(--text-lip);
  animation: launch-pop 700ms var(--ease-bounce) both;
}
.launch__go {
  min-height: clamp(72px, 13dvh, 120px); min-width: min(46vw, 540px);
  font-size: clamp(32px, 6.4dvh, 60px);
  background: var(--cel-gold);
  /* rises, never shrinks below ~90%: the tap target stays >= 48px even mid-animation */
  animation: launch-rise 500ms 250ms var(--ease-bounce) both, launch-breathe 1.8s 1s ease-in-out infinite;
}
/* transform only, never opacity 0: an element that first paints invisible is no LCP candidate (#207) */
@keyframes launch-pop { from { transform: scale(0.7); } to { transform: none; } }
@keyframes launch-rise { from { transform: translateY(24px) scale(0.92); } to { transform: none; } }
@keyframes launch-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

/* ============ Home ============ */
/* While Launch is up, Home stays out of the render tree: its lazy images and CSS background wait,
   so the launch art gets the bandwidth (Lighthouse LCP, #207). screens.js drops .launching on tap. */
.launching #setup { display: none; }
.home {
  --pad-x: max(clamp(16px, 2.6vw, 32px), env(safe-area-inset-left), env(safe-area-inset-right));
  --gap: clamp(8px, 1.3vw, 16px);
  position: relative;
  height: 100dvh; overflow: hidden;
  display: grid; grid-template-rows: auto auto minmax(0, 1fr); gap: clamp(6px, 1.6dvh, 18px);
  padding: max(clamp(8px, 1.8dvh, 18px), env(safe-area-inset-top)) var(--pad-x) max(clamp(10px, 2.4dvh, 24px), env(safe-area-inset-bottom));
  /* temple art (Artist export home-bg.webp), else the launch temple, else flat arena */
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--arena-3) 35%, transparent), transparent 30%, color-mix(in srgb, var(--arena-3) 45%, transparent)),
    url('assets/ui/home-bg.webp') center / cover no-repeat,
    url('assets/ui/launch-bg.webp') center / cover no-repeat,
    linear-gradient(var(--arena-2), var(--arena-3));
  color: var(--hud-ink);
}

/* top row: logo · Pick your hero · gear */
.home__top { display: contents; }
.home__brand { grid-row: 1; grid-column: 1; justify-self: start; align-self: center; margin: 0; display: flex; } /* the page h1 (#987) */
.home__logo {
  grid-row: 1; grid-column: 1; justify-self: start; align-self: center;
  height: clamp(40px, 9dvh, 84px); width: auto; aspect-ratio: 1400 / 452;
  filter: drop-shadow(0 4px 8px color-mix(in srgb, var(--arena-3) 70%, transparent));
}
.home__gear { grid-row: 1; grid-column: 1; justify-self: end; align-self: center; }
.home__pick {
  grid-row: 1; grid-column: 1; justify-self: center; align-self: center;
  display: flex; align-items: center; gap: 14px; margin: 0;
  font: var(--fw-display) clamp(22px, 4.6dvh, 40px) / 1 var(--font-display); color: var(--gold-hi);
  -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--ink);
}
.home__pick::before, .home__pick::after {
  content: ''; width: clamp(24px, 6vw, 90px); height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--gold));
}
.home__pick::after { transform: scaleX(-1); }
/* a dark plaque behind screen titles so the gold text reads over the bright stained glass (a11y #982);
   online.css reuses it for .on-title */
.home__pick > span {
  padding: 0.12em 0.6em 0.2em; border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--arena-3) 80%, transparent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--gold) 50%, transparent), 0 4px 12px color-mix(in srgb, var(--arena-3) 60%, transparent);
}
/* the title sits between logo and gear; on narrow rows it would collide, so shrink the rules */
@media (max-aspect-ratio: 4/3) { .home__pick::before, .home__pick::after { width: 18px; } }

/* Hero medallions: Character Picker A (board #551, Silas msg 716; art/ui/mockups/picker/A.css).
   A round portrait in a thick element ring with a thin gold rim, the element mark on a badge, the name
   on a plum pill. Picked = grows (transform), gold ring + glow, gold check-star, a little gold dais.
   Sizes come from --pk-d (portrait diameter) on the row; the online screens set their own. */
.home__heroes {
  grid-row: 2;
  --pk-col: calc((100vw - 2 * var(--pad-x) - 5 * var(--gap)) / 6);
  --pk-d: min(calc(var(--pk-col) * 0.66), 14dvh, 124px);
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--gap);
}

.pk {
  --d: var(--pk-d, 118px);              /* portrait diameter */
  --ring: calc(var(--d) * 0.085);       /* element ring */
  --rim: 4px;                           /* gold rim */
  --grow: var(--pk-grow, 1.28);         /* picked size */
  -webkit-appearance: none; appearance: none;
  position: relative; margin: 0; padding: 0; border: 0; background: none; color: inherit;
  min-width: 0; display: grid; grid-template-rows: calc(var(--d) * 1.52) auto; justify-items: center; align-items: center;
  cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  font: inherit;
}
.pk:focus-visible { outline: 4px solid var(--focus); outline-offset: 6px; border-radius: 24px; }

.pk__medal {
  position: relative; grid-row: 1; width: var(--d); height: var(--d); border-radius: 50%;
  background:
    radial-gradient(circle at 50% 18%, color-mix(in srgb, var(--l) 85%, transparent) 0 22%, transparent 48%),
    var(--m);
  box-shadow:
    0 0 0 3px var(--edge),
    0 0 0 calc(3px + var(--rim)) var(--gold),
    0 0 0 calc(5px + var(--rim)) var(--edge),
    0 8px 14px calc(2px + var(--rim)) rgba(10, 4, 24, 0.55);
  transition: transform var(--dur-fast) var(--ease-out);
}
/* the portrait: square hero art, cropped to head and chest; missing art leaves the element disc */
.pk__art {
  position: absolute; inset: var(--ring); border-radius: 50%; overflow: hidden;
  background: var(--l) var(--art) center / cover no-repeat;
  box-shadow: 0 0 0 3px var(--edge), inset 0 calc(var(--d) * -0.08) calc(var(--d) * 0.1) rgba(0, 0, 0, 0.18);
}
.pk__mark {
  position: absolute; left: 50%; bottom: calc(var(--d) * -0.1); translate: -50% 0;
  width: calc(var(--d) * 0.34); aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 28%, var(--l), var(--m) 62%);
  color: var(--on); font-size: calc(var(--d) * 0.2);
  box-shadow: 0 0 0 3px var(--edge), 0 0 0 6px var(--gold), 0 0 0 8px var(--edge);
}
.pk__name {
  grid-row: 2; position: relative; z-index: 2;
  min-width: 0; max-width: 100%; padding: 0.26em 0.72em 0.3em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-radius: var(--radius-pill); border: var(--stroke) solid var(--edge);
  background: var(--table-2); color: var(--hud-ink);
  box-shadow: inset 0 3px 0 var(--table-hi), 0 4px 0 var(--table-3);
  font: var(--fw-display) clamp(16px, calc(var(--d) * 0.165), 26px) / 1 var(--font-display); letter-spacing: 0.01em; /* >= 16 px for young readers (a11y #984) */
}

/* gold check-star (picked only; Artist export picker-star.svg) */
.pk__star {
  position: absolute; right: calc(var(--d) * -0.12); top: calc(var(--d) * -0.12);
  width: calc(var(--d) * 0.46); aspect-ratio: 1; display: none;
  background: url('assets/ui/picker-star.svg') center / contain no-repeat;
  filter: drop-shadow(0 3px 0 var(--edge)) drop-shadow(0 0 10px rgba(255, 180, 0, 0.9));
}

/* little gold dais under the picked medallion */
.pk__dais {
  position: absolute; left: 50%; top: calc(50% + var(--d) * 0.43); translate: -50% 0; z-index: -1;
  width: calc(var(--d) * 1.25); height: calc(var(--d) * 0.36); display: none;
}
.pk__dais::before {
  content: ''; position: absolute; inset: -60% -30%;
  background: radial-gradient(closest-side, rgba(255, 224, 138, 0.85), rgba(255, 180, 0, 0.35) 55%, transparent);
}
.pk__dais::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(ellipse at 50% 35%, var(--gold-hi), var(--gold) 55%, var(--gold-lip) 100%);
  box-shadow: 0 0 0 3px var(--edge), 0 5px 0 3px var(--gold-lip), 0 5px 0 6px var(--edge);
}

/* picked: grows (transform only), gold rim + glow, star, dais, gold name */
.pk.is-picked { --rim: 6px; z-index: 1; }
.pk.is-picked .pk__medal {
  transform: scale(var(--grow));
  box-shadow:
    0 0 0 4px var(--edge),
    0 0 0 calc(4px + var(--rim)) var(--gold),
    0 0 0 calc(6px + var(--rim)) var(--edge),
    0 0 28px calc(6px + var(--rim)) rgba(255, 180, 0, 0.55),
    0 0 56px calc(10px + var(--rim)) rgba(255, 224, 138, 0.25);
}
.pk.is-picked .pk__medal::after { /* bright highlight sweeping over the gold rim */
  content: ''; position: absolute; inset: calc(-4px - var(--rim)); border-radius: 50%; pointer-events: none;
  background: conic-gradient(from 200deg, transparent 0 20%, rgba(255, 248, 220, 0.9) 28%, transparent 36% 70%, rgba(255, 248, 220, 0.6) 76%, transparent 82%);
  -webkit-mask: radial-gradient(closest-side, transparent calc(100% - var(--rim)), #000 calc(100% - var(--rim) + 1px));
  mask: radial-gradient(closest-side, transparent calc(100% - var(--rim)), #000 calc(100% - var(--rim) + 1px));
}
.pk.is-picked .pk__star { display: block; }
.pk.is-picked .pk__dais { display: block; }
.pk.is-picked .pk__name {
  background: var(--cel-gold); color: var(--gold-ink);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.45), 0 4px 0 var(--gold-lip);
}
/* pressed: sinks */
button.pk:active .pk__medal { transform: translateY(4px) scale(0.93); }
button.pk.is-picked:active .pk__medal { transform: translateY(4px) scale(calc(var(--grow) * 0.95)); }

/* square portrait crops by the Artist (web/assets/ui/picker-<el>[-320].webp, board #551 msg 723);
   big medallions (online) use the 512 crop. Missing art leaves the element disc. */
.pk[data-el="fire"]     { --art: url('assets/ui/picker-fire-320.webp');     --art-big: url('assets/ui/picker-fire.webp'); }
.pk[data-el="ice"]      { --art: url('assets/ui/picker-ice-320.webp');      --art-big: url('assets/ui/picker-ice.webp'); }
.pk[data-el="leaf"]     { --art: url('assets/ui/picker-leaf-320.webp');     --art-big: url('assets/ui/picker-leaf.webp'); }
.pk[data-el="electric"] { --art: url('assets/ui/picker-electric-320.webp'); --art-big: url('assets/ui/picker-electric.webp'); }
.pk[data-el="water"]    { --art: url('assets/ui/picker-water-320.webp');    --art-big: url('assets/ui/picker-water.webp'); }
.pk[data-el="rock"]     { --art: url('assets/ui/picker-rock-320.webp');     --art-big: url('assets/ui/picker-rock.webp'); }
.pk--big .pk__art { background-image: var(--art-big); }

/* bottom: big hero on the pedestal | three modes */
.home__bottom {
  grid-row: 3; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: clamp(12px, 3vw, 40px);
  align-items: center;
}
.home__stage {
  --pw: min(34vw, 44dvh, 420px);      /* pedestal width; its art is 1140x426 */
  --feet: calc(var(--pw) * 0.224);    /* hero feet land ~40% down the pedestal top */
  position: relative; height: 100%; min-height: 0; display: grid; place-items: center;
}
.home__pedestal { /* Artist export (alpha). Missing: the CSS glow below carries it */
  position: absolute; left: 50%; bottom: 0; width: var(--pw); height: auto;
  transform: translateX(-50%);
}
/* transparent hero cut-out (home-hero-<el>.webp), standing on the pedestal, bottom-aligned */
.home__cutout {
  position: absolute; left: 0; right: 0; bottom: var(--feet);
  width: 100%; height: calc(100% - var(--feet) - 4px);
  object-fit: contain; object-position: 50% 100%;
  filter: drop-shadow(0 0 18px color-mix(in srgb, var(--m) 75%, transparent));
  transform-origin: 50% 100%;
}
.home__cutout.is-pop { animation: home-pop 420ms var(--ease-bounce) both; }
.home__cutout:not([hidden]) ~ .home__hero { display: none; }
.home__pedestal-glow {
  position: absolute; left: 50%; bottom: 2%; width: calc(var(--pw) * 0.9); aspect-ratio: 4 / 1;
  transform: translateX(-50%); border-radius: 50%;
  background: radial-gradient(closest-side, var(--gold-hi), color-mix(in srgb, var(--m) 70%, transparent) 55%, transparent);
  opacity: 0.85;
}
.home__pedestal:not([hidden]) + .home__pedestal-glow { opacity: 0.45; }
.home__hero {
  --size: min(34dvh, 30vw, 300px);
  position: relative; margin-bottom: 8%;
}
.home__hero.is-pop { animation: home-pop 420ms var(--ease-bounce) both; }
@keyframes home-pop { from { transform: scale(0.7) translateY(12%); opacity: 0.4; } to { transform: none; opacity: 1; } }

.home__modes { display: flex; flex-direction: column; gap: clamp(8px, 2dvh, 18px); justify-content: center; }
.home-mode {
  --lip-color: var(--rival-lip);
  -webkit-appearance: none; appearance: none;
  position: relative; display: flex; align-items: center; gap: 16px;
  min-height: clamp(56px, 11dvh, 104px); margin: 0 0 var(--btn-lip); padding: 0 32px 0 10px;
  border: var(--stroke) solid var(--ink); border-radius: var(--radius-pill);
  background: var(--table-2); color: var(--hud-ink);
  box-shadow: inset 0 0 0 4px var(--el-ice), var(--hi-inset), var(--lip-rival);
  font: var(--fw-display) clamp(24px, 5dvh, 44px) / 1 var(--font-display);
  cursor: pointer; text-align: left;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.home-mode > span:last-child { flex: 1; text-align: center; }
.home-mode__art {
  flex: none; display: grid; place-items: center;
  width: clamp(44px, 8.5dvh, 80px); aspect-ratio: 1; border-radius: 50%;
  background: var(--table-3); color: var(--el-ice-light); font-size: 0.95em;
  box-shadow: 0 0 0 3px var(--el-ice);
}
.home-mode--gold {
  --lip-color: var(--gold-lip);
  background: var(--cel-gold); color: var(--gold-ink);
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.45), var(--lip-gold), var(--glow-gold);
}
.home-mode--gold .home-mode__art { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 3px var(--ink); }
.home-mode:active { transform: translateY(calc(var(--btn-lip) - 2px)); box-shadow: inset 0 0 0 4px var(--el-ice), var(--lip-pressed); }
.home-mode--gold:active { box-shadow: var(--lip-pressed), var(--glow-gold); }
.home-mode:focus-visible { outline: 4px solid var(--focus); outline-offset: 4px; }

.home__error { position: absolute; left: 0; right: 0; bottom: 4px; margin: 0; text-align: center; }
.home__error:empty { display: none; }

@media (prefers-reduced-motion: reduce) {
  .launch__logo, .launch__title, .launch__go, .home__hero.is-pop, .home__cutout.is-pop { animation: none; }
}

/* read by screen readers, not shown (a11y #987: the table's h1) */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
