  /* Bundled Outfit (variable font, Latin + Latin Extended). The Google
     Fonts <link> in index.html stays as a redundant CDN load on web; on
     Capacitor (Android shell) the cross-origin Google Fonts request was
     unreliable, so the local files below are the canonical source. The
     Outfit variable font carries weights 100-900 in a single ~32 KB file,
     so one @font-face per unicode-range covers all the weight calls our
     CSS makes (400/500/600/700/800). */
  @font-face {
    font-family: 'Outfit';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url(assets/fonts/outfit-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }
  @font-face {
    font-family: 'Outfit';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url(assets/fonts/outfit-latin-ext.woff2) format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
  }

  /* Bundled Space Grotesk (variable font, Latin + Latin Extended). Used for
     modal headers (#relic-shop-section-title, #pause-screen h2, stage-loading
     "STAGE" label, #shop-screen h2, #limit-break-section-title, etc.).
     Self-hosted so Capacitor Android doesn't fall back to system sans-serif
     when the Google Fonts CDN is unreachable from the WebView. */
  @font-face {
    font-family: 'Space Grotesk';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url(assets/fonts/space-grotesk-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }
  @font-face {
    font-family: 'Space Grotesk';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url(assets/fonts/space-grotesk-latin-ext.woff2) format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
  }

  /* Bundled Cinzel (carved-stone serif) — YOU DIED ceremony face. Variable
     font weight 400-900 in one file per unicode-range. Self-hosted for the
     same reason as Outfit / Space Grotesk. */
  @font-face {
    font-family: 'Cinzel';
    font-style: normal;
    font-weight: 400 900;
    font-display: swap;
    src: url(assets/fonts/cinzel-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }
  @font-face {
    font-family: 'Cinzel';
    font-style: normal;
    font-weight: 400 900;
    font-display: swap;
    src: url(assets/fonts/cinzel-latin-ext.woff2) format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
  }

  /* Bundled EB Garamond italic — ceremony subtitle. Only the italic 400
     latin subset ships with Google Fonts as a static woff (not woff2), so
     match that here. */
  @font-face {
    font-family: 'EB Garamond';
    font-style: italic;
    font-weight: 400;
    font-display: swap;
    src: url(assets/fonts/eb-garamond-italic-latin.woff) format('woff');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }
  /* Upright EB Garamond Bold — the shop's "UPGRADES" header (rc331, Figma
     match). The italic 400 face above stays for the death-ceremony subtitle;
     this adds the normal 700 weight the header needs (latin woff2). */
  @font-face {
    font-family: 'EB Garamond';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url(assets/fonts/eb-garamond-bold-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }

  /* Bundled Irish Grover — the chunky, hand-drawn display face used for the
     "BIN" word in the Daily Bin scroll title (Figma 3341:153). Single 400
     weight, latin subset only (Google Fonts ships no other). Self-hosted for
     the same Capacitor-offline reason as the faces above; it's a display-only
     accent so the latin subset is sufficient. */
  @font-face {
    font-family: 'Irish Grover';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url(assets/fonts/irish-grover-latin.woff2) format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }

  :root {
    --bg:          #323539;
    /* rc158 — opaque panel + card palette. Replaces the previous
       alpha-stacked surface system (translucent dark over translucent
       darker) which produced muddy mid-tones whenever a rarity hue or
       glow tried to layer through it. Solid colours below let
       gradients + tints land predictably on a known canvas. */
    --card-bg:     #1a2138;
    --card-border: #2a3454;
    --panel-bg:    #131a2e;      /* darker modal / floating panel */
    --panel-bg-2:  #0e1426;      /* deepest layer — modal backdrop fill */
    --row-bg:      #1a2030;      /* default eq-pick-row / eq-slot-card */
    --row-bg-soft: #232b3f;      /* hover lift one notch lighter */
    --text:        #f4f6fb;
    --text-dim:    #c6cee0;   /* WCAG AA on card-bg */
    --gold:        #ffd36e;
    --teal:        #5dd6c8;
    --coral:       #ff8a8a;
    --lilac:       #b89bff;
    --amber:       #ffa866;
    --radius-sm:   10px;
    --radius-md:   16px;
    --radius-lg:   22px;
    --radius-pill: 999px;
    /* ── z-index scale ─────────────────────────────────────────────── */
    --z-hud:        10;
    --z-controls:   50;
    --z-modal:      200;
    --z-modal-high: 300;
    --z-toast:      1000;
    --z-loader:     9000;
    --z-critical:   9999;
  }

  /* ── Shared keyframes ──────────────────────────────────────────────── */
  @keyframes spin-360 { to { transform: rotate(360deg); } }
  @keyframes halo-pulse {
    0%, 100% { opacity: 0.55; filter: blur(14px) brightness(1.25) saturate(1.15); }
    50%      { opacity: 0.90; filter: blur(22px) brightness(1.55) saturate(1.30); }
  }

  * { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  button, a, [role="button"] { -webkit-tap-highlight-color: transparent; }
  button:focus, button:focus-visible, button::-moz-focus-inner { outline: none; }
  button { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
  /* Pin html font-size + disable text-autosizing so Capacitor Android's
     WebView (and mobile Chrome with various accessibility settings) doesn't
     render text smaller than the web build. Without this, Android can
     auto-scale text down because viewport-fit=cover makes the page fit
     the device, AND it can pick a smaller default font-size depending
     on accessibility / accessibility-zoom settings. Web computed-style
     was 16px — match it explicitly. */
  html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  body {
    background: var(--bg); overflow: hidden;
    font-family: 'Outfit', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
    /* Inherits html's 16px so explicit-px sizing across the app reads
       identically on Capacitor Android and desktop web. */
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  #canvas { display: block; }

  #hud {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: var(--z-hud);
  }
  /* Gameplay HUD is invisible until the run starts — otherwise the stat pills,
     health/XP bars, ability bar and minimap all leak through the transparent
     landing overlay and make the title screen look like a paused game. The
     .playing class is toggled by playSelectedStage / restartGame / endGame. */
  body:not(.playing) #hud,
  body:not(.playing) #minimap,
  body:not(.playing) #top-bar,
  body:not(.playing) #ability-bar,
  body:not(.playing) #health-bar-wrap,
  body:not(.playing) #limit-break-meter,
  body:not(.playing) #wave-modifier {
    display: none !important;
  }

  #top-bar {
    position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 10px; align-items: center; pointer-events: none;
  }
  .stat-block {
    background: rgba(22, 26, 36, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-pill);
    padding: 4px 14px; color: var(--text); font-size: 12px;
    text-align: center; min-width: 64px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.75);
    display: flex; align-items: baseline; gap: 8px;
  }
  .stat-block .label {
    color: var(--text-dim); font-size: 9.5px;
    text-transform: uppercase; letter-spacing: 1.3px; font-weight: 600;
    /* Without nowrap, CJK labels (スコア, 得分, 점수) break between every
       character because the flex pill compresses them. Forcing a single
       line lets the pill grow naturally to fit the localized label. */
    white-space: nowrap;
  }
  .stat-block .value { font-size: 16px; font-weight: 700; letter-spacing: 0.3px; }
  /* Enraged state — "☠ ENRAGED" is ~2.5× wider than a normal 3:21 timer.
     Hide the "Time" label so the full phrase fits the pill and neighboring
     stat-blocks aren't pushed sideways. Compact letter-spacing keeps the
     content readable inside the block's natural width. */
  .stat-block.enraged .label { display: none; }
  .stat-block.enraged .value { font-size: 13px; letter-spacing: 0.4px; white-space: nowrap; }
  #score-val { color: var(--gold); }
  #level-val { color: var(--teal); }
  #kills-val { color: var(--coral); }

  #health-bar-wrap {
    position: fixed;
    /* Desktop original — mobile (touch class) repositions this to the
       top in the body.touch:not(.tablet) override further down. */
    bottom: 72px;
    left: 50%; transform: translateX(-50%);
    width: 320px; pointer-events: none;
  }
  .bar-label {
    color: var(--text); font-size: 11px; text-transform: uppercase;
    letter-spacing: 1.2px; margin-bottom: 5px; font-weight: 600;
    display: flex; justify-content: space-between;
    /* Close-in dark drop + soft halo — mirrors #wave-notice. Keeps the
       "Health" / "XP" labels and live values readable on bright stages
       (snow, kingdom) where the panel sits over a near-white sky. */
    text-shadow: 0 1px 3px rgba(0,0,0,0.6), 0 0 8px rgba(0,0,0,0.35);
  }
  .bar-bg {
    /* Darker (was rgba(18,24,44,0.55)) + ~40% more opaque so bright
       stages don't bleed through. Inset 1px line crisps the edge against
       a near-white sky; outer drop separates the panel from the floor. */
    background: rgba(8, 12, 24, 0.78);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-pill); height: 14px; overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.35), inset 0 0 0 1px rgba(0,0,0,0.30);
  }
  .bar-fill {
    height: 100%; border-radius: var(--radius-pill);
    /* Soft dark halo around the colored band so the fill pops against
       any background — block-element analogue of #wave-notice's
       text-shadow. xpDing's keyframes override during the gold flare
       and resettle to this same value afterward. */
    box-shadow: 0 0 6px rgba(0,0,0,0.45);
    transition: width 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  #health-fill { background: #4bd66a; width: 100%; transition: width 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.35s ease; }
  #xp-fill     { background: linear-gradient(90deg, #6ec1ff 0%, #b89bff 55%, #ff9ec4 100%); width: 0%; transition: width 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.35s ease; }
  #xp-fill.ding { animation: xpDing 520ms cubic-bezier(0.3, 0.8, 0.2, 1); }
  @keyframes xpDing {
    /* 0% / 100% match .bar-fill's resting halo so the bar settles back
       to its readability shadow after the gold ding flare at 25%. */
    0%   { filter: brightness(1); box-shadow: 0 0 6px rgba(0,0,0,0.45); }
    25%  { filter: brightness(1.7) saturate(1.3); box-shadow: 0 0 18px 4px rgba(255,215,110,0.75); }
    100% { filter: brightness(1); box-shadow: 0 0 6px rgba(0,0,0,0.45); }
  }
  #level-val.level-pop { animation: levelPop 620ms cubic-bezier(0.34, 1.56, 0.64, 1); }
  @keyframes levelPop {
    0%   { transform: scale(1); color: var(--teal); text-shadow: 0 0 0 rgba(255,215,110,0); }
    35%  { transform: scale(1.55); color: #ffe088; text-shadow: 0 0 18px rgba(255,215,110,0.95), 0 0 4px rgba(255,255,255,0.9); }
    100% { transform: scale(1); color: var(--teal); text-shadow: 0 0 0 rgba(255,215,110,0); }
  }

  #xp-bar-wrap {
    position: fixed;
    /* Desktop original — mobile (touch class) repositions this to the
       top in the body.touch:not(.tablet) override further down. */
    bottom: 16px;
    left: 50%; transform: translateX(-50%);
    width: 320px; pointer-events: none;
  }

  #wave-notice {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    color: var(--text); font-size: 40px; font-weight: 700; text-align: center;
    letter-spacing: 0.5px;
    text-shadow: 0 0 32px rgba(184, 155, 255, 0.55), 0 2px 12px rgba(0,0,0,0.4);
    pointer-events: none;
    opacity: 0; transition: opacity 0.5s;
  }

  /* Boss-name banner — short-lived identity card (4s) shown during the boss
     intro cinematic. Sits BELOW the top-bar score/wave/kills strip
     (top-bar = top:14px + ~32px height) so the two don't overlap. The
     banner is also intentionally compact — single horizontal pill rather
     than a stacked two-line block — so it doesn't dominate vertical space
     on mobile, where the top-bar already eats ~46px. --boss-color is set
     by spawnBoss to the current boss's rally color. */
  #boss-banner {
    position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
    display: flex; flex-direction: row; align-items: baseline; gap: 10px;
    padding: 6px 16px 7px;
    background: rgba(8, 10, 22, 0.62);
    border: 1px solid var(--boss-color, rgba(255, 46, 165, 0.85));
    border-radius: var(--radius-pill);
    color: var(--text);
    box-shadow: 0 0 14px var(--boss-color, rgba(255, 46, 165, 0.35));
    pointer-events: none;
    opacity: 0; transition: opacity 0.35s, transform 0.35s;
    z-index: 90;
    max-width: 92vw; white-space: nowrap;
  }
  #boss-banner.visible { opacity: 1; }
  #boss-banner .boss-banner-label {
    font-size: 9.5px; letter-spacing: 2px; font-weight: 600;
    color: var(--boss-color, #ff2ea5);
    text-transform: uppercase;
  }
  #boss-banner .boss-banner-name {
    font-size: 16px; font-weight: 700; letter-spacing: 0.4px;
    text-shadow: 0 0 10px var(--boss-color, rgba(255, 46, 165, 0.5));
  }
  /* Mobile — even tighter so the banner doesn't push past the wave-modifier
     line and into the play area. */
  @media (max-width: 480px) {
    #boss-banner { top: 54px; padding: 5px 12px 6px; gap: 8px; }
    #boss-banner .boss-banner-label { font-size: 9px; letter-spacing: 1.5px; }
    #boss-banner .boss-banner-name  { font-size: 14px; }
  }

  /* Stage-unlock banner — celebratory popup when a new stage is unlocked.
     Uses the .visible class to drive entrance/exit; confetti are dropped
     into the root host by _spawnVictoryConfetti. */
  #stage-unlock {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    /* 320 — above the game-over card (200), stage-select (250), and the
       leaderboard prompt (260-280): since 2026-06-07 the unlock fires at
       the same wave-15 clear that ends the run, so the banner pops OVER
       the victory card (delayed past the 5.6s ceremony in the game loop).
       pointer-events:none keeps the card's buttons tappable through it. */
    pointer-events: none; z-index: 320;
    opacity: 0;
    transition: opacity 0.32s ease-out;
  }
  #stage-unlock.visible { opacity: 1; }
  #stage-unlock .stage-unlock-panel {
    position: relative;
    width: min(420px, 88vw);
    padding: 20px 22px 22px;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(38, 30, 72, 0.96), rgba(14, 18, 34, 0.97));
    border: 2px solid rgba(126, 226, 255, 0.85);
    box-shadow:
      0 0 60px rgba(126, 226, 255, 0.45),
      0 0 120px rgba(184, 155, 255, 0.25),
      0 12px 40px rgba(0, 0, 0, 0.55);
    text-align: center;
    color: #f6f8fe;
    transform: scale(0.82) translateY(14px);
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  }
  #stage-unlock.visible .stage-unlock-panel {
    animation: stageUnlockPop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  }
  @keyframes stageUnlockPop {
    0%   { transform: scale(0.7) translateY(18px); }
    55%  { transform: scale(1.06) translateY(-2px); }
    100% { transform: scale(1) translateY(0); }
  }
  #stage-unlock .stage-unlock-eyebrow {
    font-size: 13px; font-weight: 800; letter-spacing: 2.4px;
    color: var(--gold);
    text-shadow: 0 0 14px rgba(255, 211, 110, 0.6);
    margin-bottom: 12px;
  }
  #stage-unlock .stage-unlock-thumb {
    width: 100%; aspect-ratio: 16 / 9;
    background-size: cover; background-position: center;
    border-radius: 10px;
    box-shadow: 0 0 24px rgba(126, 226, 255, 0.35), inset 0 0 0 1px rgba(255,255,255,0.08);
    margin-bottom: 12px;
  }
  #stage-unlock .stage-unlock-name {
    font-size: 26px; font-weight: 800; letter-spacing: 1.4px;
    color: #f6f8fe;
    text-shadow: 0 0 18px rgba(126, 226, 255, 0.55);
    margin-bottom: 4px;
  }
  #stage-unlock .stage-unlock-hint {
    font-size: 12px; color: rgba(246, 248, 254, 0.6);
    letter-spacing: 0.6px;
  }

  #powerup-screen {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(ellipse at center, rgba(60, 40, 100, 0.9), rgba(14, 18, 34, 0.96));
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; z-index: 100;
    display: none;
    overflow: hidden;
  }
  /* Soft rotating nebula behind the cards for depth. */
  #powerup-screen::before {
    content: ''; position: absolute; inset: -25%;
    background:
      radial-gradient(circle at 30% 40%, rgba(255, 211, 110, 0.18), transparent 45%),
      radial-gradient(circle at 70% 65%, rgba(184, 155, 255, 0.22), transparent 50%),
      radial-gradient(circle at 50% 50%, rgba(126, 226, 255, 0.12), transparent 55%);
    pointer-events: none;
    animation: nebulaSpin 32s linear infinite;
  }
  @keyframes nebulaSpin {
    0%   { transform: rotate(0deg)   scale(1); }
    50%  { transform: rotate(180deg) scale(1.08); }
    100% { transform: rotate(360deg) scale(1); }
  }
  #powerup-screen > * { position: relative; z-index: 1; }
  #powerup-screen h2 {
    font-size: 34px; margin-bottom: 10px; letter-spacing: 1px; font-weight: 700;
    background: linear-gradient(120deg, #ffd36e, #ff9ec4 35%, #b89bff 65%, #ffd36e);
    background-size: 220% 100%;
    -webkit-background-clip: text; background-clip: text; color: transparent;
    animation: titleSweep 2.4s ease-in-out infinite;
    filter: drop-shadow(0 4px 24px rgba(255, 211, 110, 0.35));
  }
  /* Replay entrance animations every time the screen opens by toggling
     .entering on #powerup-screen — the class restart gives us a fresh keyframe
     run instead of the one-shot animation on mount. */
  #powerup-screen.entering h2 {
    animation: titleSweep 2.4s ease-in-out infinite,
               titleEnter 620ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }
  #powerup-screen.entering p {
    animation: subEnter 520ms ease-out both; animation-delay: 180ms;
  }
  @keyframes titleSweep {
    0%, 100% { background-position: 0% 50%; }
    50%      { background-position: 100% 50%; }
  }
  @keyframes titleEnter {
    0%   { transform: translateY(-18px) scale(0.8); opacity: 0; }
    100% { transform: translateY(0)      scale(1);   opacity: 1; }
  }
  #powerup-screen p {
    color: var(--text-dim); font-size: 15px; margin-bottom: 32px;
  }
  @keyframes subEnter {
    0%   { transform: translateY(-8px); opacity: 0; }
    100% { transform: translateY(0);    opacity: 0.8; }
  }
  #powerup-choices {
    display: flex; gap: 22px; flex-wrap: wrap; justify-content: center;
    max-width: 940px;
    perspective: 900px;
  }
  .powerup-card {
    position: relative;
    background: linear-gradient(155deg, rgba(45, 40, 80, 0.92), rgba(24, 28, 54, 0.92));
    border: 1.5px solid rgba(184, 155, 255, 0.32);
    border-radius: var(--radius-lg);
    padding: 26px 22px; width: 210px; cursor: pointer;
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1),
                border-color 0.2s, box-shadow 0.28s, background 0.28s;
    text-align: center; pointer-events: all;
    transform-style: preserve-3d;
    animation: cardIn 520ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
    overflow: hidden;
  }
  .powerup-card:nth-child(1) { animation-delay: 140ms; }
  .powerup-card:nth-child(2) { animation-delay: 240ms; }
  .powerup-card:nth-child(3) { animation-delay: 340ms; }
  @keyframes cardIn {
    0%   { opacity: 0; transform: translateY(40px) rotateX(-18deg) scale(0.88); }
    70%  { opacity: 1; transform: translateY(-6px) rotateX(4deg)   scale(1.04); }
    100% { opacity: 1; transform: translateY(0)    rotateX(0)      scale(1); }
  }
  /* Shimmering highlight sweep on hover. */
  .powerup-card::before {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, 0.12) 50%, transparent 70%);
    transform: translateX(-120%);
    transition: transform 0.6s ease;
    pointer-events: none;
  }
  .powerup-card:hover, .powerup-card:focus-visible {
    border-color: var(--lilac);
    transform: translateY(-8px) rotateX(6deg) scale(1.03);
    box-shadow: 0 20px 48px rgba(184, 155, 255, 0.38), 0 0 0 1px rgba(255, 211, 110, 0.35) inset;
    background: linear-gradient(155deg, rgba(60, 50, 100, 0.96), rgba(30, 34, 66, 0.96));
    outline: none;
  }
  .powerup-card:hover::before { transform: translateX(120%); }
  .powerup-card .icon {
    /* SVG icons from src/powerup-icons.js — sized via the child svg rule.
       The font-size is a fallback in case the icon string is ever plain
       text (e.g. during a migration). */
    width: 54px; height: 54px;
    margin: 0 auto 12px;
    font-size: 38px; line-height: 54px;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.28s;
  }
  .powerup-card .icon svg { width: 100%; height: 100%; display: block; }
  .powerup-card:hover .icon {
    transform: scale(1.18) rotate(-6deg);
    filter: drop-shadow(0 4px 14px rgba(255, 211, 110, 0.55));
  }
  .powerup-card .name { color: var(--text); font-size: 15px; font-weight: 700; margin-bottom: 6px; }
  .powerup-card .desc { color: var(--text-dim); font-size: 12.5px; line-height: 1.55; }
  .powerup-card .tier {
    font-size: 10.5px; color: var(--lilac); margin-top: 10px;
    text-transform: uppercase; letter-spacing: 1.2px; font-weight: 600;
  }
  /* Per-tier hover accent — hint at what the card does through color. */
  .powerup-card[data-tier="Offense"]:hover  { box-shadow: 0 20px 48px rgba(255, 107, 107, 0.35), 0 0 0 1px rgba(255, 107, 107, 0.45) inset; border-color: #ff9e7a; }
  .powerup-card[data-tier="Defense"]:hover  { box-shadow: 0 20px 48px rgba(93, 214, 200, 0.35), 0 0 0 1px rgba(93, 214, 200, 0.45) inset; border-color: #7ee2d0; }
  .powerup-card[data-tier="Mobility"]:hover { box-shadow: 0 20px 48px rgba(126, 226, 255, 0.35), 0 0 0 1px rgba(126, 226, 255, 0.45) inset; border-color: #9fdfff; }
  .powerup-card[data-tier="Utility"]:hover  { box-shadow: 0 20px 48px rgba(255, 211, 110, 0.35), 0 0 0 1px rgba(255, 211, 110, 0.45) inset; border-color: var(--gold); }

  @keyframes card-burst {
    0%   { transform: scale(1); box-shadow: 0 0 0 rgba(255,215,0,0); filter: brightness(1); }
    30%  { transform: scale(1.18); box-shadow: 0 0 56px 8px rgba(255,215,0,0.7); filter: brightness(1.45) saturate(1.3); }
    75%  { transform: scale(1.08); box-shadow: 0 0 80px 12px rgba(255,215,0,0.5); filter: brightness(1.2); }
    100% { transform: scale(0); opacity: 0; filter: brightness(1); }
  }
  .powerup-card.card-picked, .shop-card.card-picked,
  .stage-hero-card.card-picked,
  #overlay #start-btn.card-picked,
  #overlay #relic-bar.card-picked,
  #overlay #rankings-bar.card-picked {
    animation: card-burst 380ms cubic-bezier(0.5, 0, 0.2, 1) forwards;
    pointer-events: none; z-index: 2;
  }
  .powerup-card.card-dismissed, .shop-card.card-dismissed,
  .stage-hero-card.card-dismissed {
    transition: opacity 200ms ease, transform 200ms ease, filter 200ms ease;
    opacity: 0.08; transform: scale(0.82) translateY(12px); filter: blur(2px); pointer-events: none;
  }

  /* Full-screen gold flash when level-up opens. Pinned to the overlay root. */
  #level-up-flash {
    position: fixed; inset: 0; z-index: 150;
    background: radial-gradient(ellipse at center, rgba(255, 225, 140, 0.55), rgba(255, 180, 80, 0.2) 45%, transparent 70%);
    pointer-events: none; opacity: 0;
  }
  #level-up-flash.fire { animation: levelUpFlash 700ms ease-out; }
  @keyframes levelUpFlash {
    0%   { opacity: 0; }
    15%  { opacity: 1; }
    100% { opacity: 0; }
  }

  /* LVL chip sitting above the modal title — replaces the old floating banner
     that used to overlap the card grid. Populated from showPowerupScreen and
     replayed each open via the #powerup-screen.entering class. */
  #level-up-chip {
    display: inline-flex; align-items: baseline; gap: 10px;
    margin-bottom: 14px;
    padding: 6px 18px 7px;
    border-radius: var(--radius-pill);
    background: linear-gradient(135deg, rgba(255, 211, 110, 0.24), rgba(184, 155, 255, 0.22));
    border: 1px solid rgba(255, 211, 110, 0.55);
    box-shadow: 0 6px 24px rgba(255, 211, 110, 0.22), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
    font-weight: 800; letter-spacing: 2.4px; text-transform: uppercase;
    color: #ffe7a8;
    transform-origin: center;
    opacity: 0;
  }
  #level-up-chip .lvl-word { font-size: 12px; color: rgba(255, 231, 168, 0.85); }
  #level-up-chip .lvl-num {
    font-size: 22px;
    background: linear-gradient(120deg, #fff3c8, #ffd36e 45%, #ff9ec4);
    -webkit-background-clip: text; background-clip: text; color: transparent;
    filter: drop-shadow(0 2px 8px rgba(255, 211, 110, 0.55));
  }
  #powerup-screen.entering #level-up-chip {
    animation: levelChipPop 720ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  }
  @keyframes levelChipPop {
    0%   { opacity: 0; transform: translateY(10px) scale(0.7); }
    55%  { opacity: 1; transform: translateY(0)    scale(1.15); }
    100% { opacity: 1; transform: translateY(0)    scale(1);   }
  }

  /* Orbital stars dropped into the picked card's center. */
  .pick-spark {
    position: fixed; pointer-events: none; z-index: 160;
    width: 10px; height: 10px; margin: -5px 0 0 -5px;
    background: radial-gradient(circle, #fff 0%, #ffd36e 45%, transparent 70%);
    border-radius: 50%;
    animation: sparkFly 620ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  }
  @keyframes sparkFly {
    0%   { transform: translate(0,0) scale(0.6); opacity: 1; }
    100% { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; }
  }

  #overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; z-index: var(--z-modal);
    isolation: isolate;
  }
  /* Background layer — hosts the dedicated Three.js landing scene canvas
     plus the rising photon DOM motes. A near-black radial gradient sits
     beneath the canvas so the dungeon scene blends into the page edges
     even on aspect ratios where the rendered scene under-fills. */
  #overlay-bg {
    position: absolute; inset: 0; z-index: -2;
    background:
      radial-gradient(ellipse 120% 90% at 50% -10%,
        rgba(14, 24, 48, 0.0) 0%,
        rgba(6, 14, 30, 0.85) 70%),
      #06101e;
    overflow: hidden;
  }
  /* Landing backdrop — two static dungeon plates (portrait + landscape)
     gated on the body.portrait / body.landscape class set by src/input.js.
     object-fit:cover fills any aspect ratio without distortion. Only one
     image is decoded + composited at a time.
     Parallax drift — object-position pans slowly between two anchors so
     the dungeon scene "breathes" behind the static title + panels.
     prefers-reduced-motion users get the static centred frame. */
  .landing-image-bg {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    object-position: 50% 50%;
    pointer-events: none;
    display: none;
    user-select: none; -webkit-user-drag: none;
    will-change: object-position;
  }
  body.portrait  .landing-image-bg-portrait  { display: block; }
  body.landscape .landing-image-bg-landscape { display: block; }
  @media (prefers-reduced-motion: no-preference) {
    .landing-image-bg-landscape {
      animation: bg-drift-landscape 24s ease-in-out infinite alternate;
    }
    .landing-image-bg-portrait {
      animation: bg-drift-portrait 26s ease-in-out infinite alternate;
    }
  }
  @keyframes bg-drift-landscape {
    0%   { object-position: 42% 46%; }
    100% { object-position: 58% 54%; }
  }
  @keyframes bg-drift-portrait {
    0%   { object-position: 48% 42%; }
    100% { object-position: 52% 58%; }
  }
  /* Three.js canvas remains in the DOM as fallback / future hook but is
     hidden because static media owns the backdrop now. landingScene3D.start()
     is no longer called from boot, so no GPU work happens here. */
  #landing-canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    display: none;
    pointer-events: none;
  }
