/* ══════════════════════════════════════════════════════════════════════
   誕生日クエスト — BIRTHDAY QUEST
   Dark ink theme. "Minimalist with intricacies."
   ══════════════════════════════════════════════════════════════════════ */

:root {
  --ink:        #0d0b0a;
  --ink-2:      #120f0e;
  --panel:      #171412;
  --panel-2:    #1d1917;
  --hairline:   #2a2523;
  --hairline-2: #383130;
  --text:       #f2ece1;
  --text-dim:   #9a9184;
  --text-faint: #6a6259;
  --red:        #a4161a;
  --red-bright: #e5383b;
  --red-deep:   #6b0f12;
  --gold:       #c9a227;
  --gold-soft:  #e6c76a;

  --font-serif: 'Shippori Mincho', 'Hiragino Mincho ProN', 'Yu Mincho', 'Noto Serif JP', serif;
  --font-ui:    'Zen Kaku Gothic New', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', 'Noto Sans JP', system-ui, -apple-system, sans-serif;

  --ease-out:   cubic-bezier(.16, 1, .3, 1);
  --ease-in-out:cubic-bezier(.65, 0, .35, 1);
  --ease-back:  cubic-bezier(.34, 1.56, .64, 1);

  --shell: 480px;
  --pad: 22px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
}

body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* desktop framing: a centered shell floating on a slightly deeper ground */
@media (min-width: 560px) {
  body {
    background:
      radial-gradient(120% 80% at 50% 0%, #151110 0%, #0a0908 70%),
      #0a0908;
  }
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
img { -webkit-user-drag: none; user-drag: none; }
svg { display: block; }
#sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

:focus-visible { outline: 2px solid var(--red-bright); outline-offset: 3px; border-radius: 4px; }

/* ── paper grain ─────────────────────────────────────────────────── */
#grain {
  position: fixed;
  inset: -50%;
  pointer-events: none;
  z-index: 900;
  opacity: .05;
  background-image:
    repeating-linear-gradient(0deg,   rgba(255,255,255,.9) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg,  rgba(255,255,255,.6) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(37deg,  rgba(0,0,0,.9)       0 1px, transparent 1px 5px);
  mix-blend-mode: overlay;
}

/* ══ shell + screen manager ══════════════════════════════════════ */

#app {
  position: relative;
  width: 100%;
  max-width: var(--shell);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: linear-gradient(180deg, #100d0c 0%, var(--ink) 30%, var(--ink) 100%);
  overflow-x: clip;
}
@media (min-width: 560px) {
  #app {
    box-shadow: 0 0 0 1px var(--hairline), 0 40px 120px -30px #000;
  }
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: max(18px, env(safe-area-inset-top)) 0 max(20px, env(safe-area-inset-bottom));
  overflow-x: clip;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.is-active { display: flex; }

/* enter / exit choreography */
.screen.is-entering { animation: screen-in .42s var(--ease-out) both; }
.screen.is-entering-back { animation: screen-in-back .42s var(--ease-out) both; }
.screen.is-leaving { animation: screen-out .22s var(--ease-in-out) both; pointer-events: none; }

@keyframes screen-in      { from { opacity: 0; transform: translateX(18px) scale(.99); } to { opacity: 1; transform: none; } }
@keyframes screen-in-back { from { opacity: 0; transform: translateX(-18px) scale(.99); } to { opacity: 1; transform: none; } }
@keyframes screen-out     { to   { opacity: 0; transform: scale(.995); } }

.screen--overlay { z-index: 500; background: rgba(6,5,5,.94); backdrop-filter: blur(6px); }

/* ══ shared components ═══════════════════════════════════════════ */

.hairline { height: 1px; background: linear-gradient(90deg, transparent, var(--hairline-2), transparent); margin: 20px auto; width: 70%; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 14px 34px;
  border-radius: 2px;
  font-family: var(--font-ui);
  font-weight: 500;
  letter-spacing: .04em;
  transition: transform .18s var(--ease-back), background-color .25s var(--ease-out), box-shadow .25s var(--ease-out);
}
.btn:active { transform: scale(.96); }

.btn-primary {
  background: var(--red);
  color: #fff5f0;
  box-shadow: 0 0 0 1px var(--red-bright) inset, 0 10px 30px -14px var(--red-bright);
}
.btn-primary:active { background: var(--red-bright); }
.btn-primary .btn-jp { font-family: var(--font-ui); font-weight: 700; font-size: 17px; }
.btn-primary .btn-en { font-size: 11px; letter-spacing: .22em; text-transform: uppercase; opacity: .72; }

.btn-gold {
  background: linear-gradient(180deg, #d8b23a, var(--gold));
  color: #241c05;
  font-weight: 700;
  box-shadow: 0 10px 30px -14px var(--gold);
}
.btn-quiet {
  border: 1px solid var(--hairline-2);
  color: var(--text-dim);
  font-size: 13px;
  letter-spacing: .12em;
  min-height: 48px;
}
.btn-quiet:active { border-color: var(--red); color: var(--text); }

.panel {
  position: relative;
  margin: 0 var(--pad);
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  overflow: hidden;
}

/* sub-screen headers */
.sub-header {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 8px;
  padding: 0 12px 14px;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 18px;
  flex: 0 0 auto;
}
.sub-header h2 { margin: 0; text-align: center; line-height: 1.2; }
.sub-header .sh-jp { display: block; font-family: var(--font-serif); font-size: 19px; letter-spacing: .16em; }
.sub-header .sh-en { display: block; font-size: 9.5px; letter-spacing: .3em; text-transform: uppercase; color: var(--text-faint); margin-top: 3px; }
.sh-count { font-size: 11px; letter-spacing: .12em; color: var(--text-faint); text-align: right; }

.btn-back {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  color: var(--text-dim);
  transition: color .2s var(--ease-out), transform .2s var(--ease-back);
}
.btn-back svg { width: 24px; height: 24px; }
.btn-back:active { color: var(--red-bright); transform: translateX(-3px); }

/* ══ 1. TITLE ════════════════════════════════════════════════════ */

#screen-title { justify-content: center; align-items: center; text-align: center; padding-inline: var(--pad); }
.title-inner { width: 100%; }

.boot-line { width: 160px; height: 1px; margin: 0 auto 40px; background: var(--hairline); overflow: hidden; }
.boot-line i { display: block; height: 100%; width: 0; background: var(--red-bright); box-shadow: 0 0 12px var(--red-bright); }
.boot-line.is-running i { animation: boot-fill 1.05s var(--ease-in-out) forwards; }
.boot-line.is-done { opacity: 0; transition: opacity .5s var(--ease-out); }
@keyframes boot-fill { from { width: 0; } to { width: 100%; } }

.title-logo { opacity: 0; }
.title-logo.is-in > * { animation: rise .7s var(--ease-out) both; }
.title-logo.is-in { opacity: 1; }
.title-logo.is-in > *:nth-child(1) { animation-delay: .00s; }
.title-logo.is-in > *:nth-child(2) { animation-delay: .08s; }
.title-logo.is-in > *:nth-child(3) { animation-delay: .16s; }
.title-logo.is-in > *:nth-child(4) { animation-delay: .24s; }
.title-logo.is-in > *:nth-child(5) { animation-delay: .34s; }
.title-logo.is-in > *:nth-child(6) { animation-delay: .46s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.logo-jp {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 800;
  font-size: clamp(30px, 9vw, 40px);
  letter-spacing: .1em;
  text-indent: .1em;
  color: var(--text);
  text-shadow: 0 0 40px rgba(164,22,26,.35);
}
.logo-en {
  margin: 8px 0 0;
  font-size: 11px;
  letter-spacing: .5em;
  text-indent: .5em;
  text-transform: uppercase;
  color: var(--red-bright);
}
.title-player { margin: 0; font-size: 12px; letter-spacing: .18em; color: var(--text-dim); text-transform: uppercase; }
.title-player span { color: var(--text-faint); font-size: 10px; letter-spacing: .3em; }
.title-player em { color: var(--red); font-style: normal; margin: 0 6px; }
.title-quote { margin: 26px 0 34px; font-size: 12px; line-height: 1.7; color: var(--text-faint); }
.title-quote small { font-size: 10.5px; opacity: .82; }

/* ══ 2. HUB ══════════════════════════════════════════════════════ */

#screen-hub { padding-inline: 0; }

.hub-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px var(--pad) 18px;
  border-bottom: 1px solid var(--hairline);
  flex: 0 0 auto;
}
.torii {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  color: var(--red);
  transition: color .3s var(--ease-out), transform .25s var(--ease-back), filter .3s var(--ease-out);
}
.torii svg { width: 30px; height: 30px; }
.torii:active { transform: scale(.9) rotate(-3deg); }
.torii.is-hit { color: var(--red-bright); filter: drop-shadow(0 0 10px var(--red-bright)); }
.torii.is-unlocked { color: var(--red-bright); filter: drop-shadow(0 0 6px rgba(229,56,59,.55)); animation: torii-pulse 3.4s var(--ease-in-out) infinite; }
@keyframes torii-pulse { 0%,100% { filter: drop-shadow(0 0 5px rgba(229,56,59,.4)); } 50% { filter: drop-shadow(0 0 14px rgba(229,56,59,.75)); } }

.hub-title { flex: 1; margin: 0; font-family: var(--font-serif); font-size: 20px; letter-spacing: .14em; }
.lv-badge {
  font-size: 10px; letter-spacing: .18em; text-transform: uppercase;
  padding: 5px 9px; border: 1px solid var(--hairline-2); border-radius: 2px;
  color: var(--text-dim);
}

.deco-vertical {
  position: absolute;
  top: 108px; right: 6px;
  margin: 0;
  writing-mode: vertical-rl;
  font-family: var(--font-serif);
  font-size: 12px;
  letter-spacing: .38em;
  color: var(--text);
  opacity: .28;
  user-select: none;
  pointer-events: none;
  max-height: calc(100% - 200px);
  overflow: hidden;
}

.menu { display: flex; flex-direction: column; padding: 26px var(--pad) 0; gap: 12px; flex: 0 0 auto; }

.menu-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 68px;
  padding: 14px 18px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  overflow: hidden;
  transition: transform .22s var(--ease-back), border-color .3s var(--ease-out), background-color .3s var(--ease-out);
}
.menu-item::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 2px; background: var(--red);
  transform: scaleY(0); transform-origin: 50% 50%;
  transition: transform .32s var(--ease-out);
}
.menu-item:active { transform: scale(.985); background: var(--panel-2); border-color: var(--hairline-2); }
.menu-item:active::before, .menu-item:hover::before { transform: scaleY(1); }
.mi-jp { font-family: var(--font-serif); font-size: 21px; letter-spacing: .12em; }
.mi-en { flex: 1 1 auto; font-size: 10px; letter-spacing: .28em; text-transform: uppercase; color: var(--text-faint); }
.mi-count { font-size: 11px; letter-spacing: .1em; color: var(--red-bright); }
.mi-chevron { width: 7px; height: 7px; border-right: 1px solid var(--text-faint); border-top: 1px solid var(--text-faint); transform: rotate(45deg); }

.menu-item--secret.is-revealed { animation: slide-in-secret .55s var(--ease-out) both; border-color: rgba(164,22,26,.4); }
@keyframes slide-in-secret {
  from { opacity: 0; transform: translateY(-12px) scaleY(.7); max-height: 0; }
  to   { opacity: 1; transform: none; max-height: 240px; }
}

/* kitchen steam curls on the menu item */
.steam { position: relative; display: inline-block; width: 20px; height: 1em; vertical-align: -2px; }
.steam b {
  position: absolute; bottom: 2px; width: 2px; height: 10px;
  background: linear-gradient(180deg, transparent, rgba(242,236,225,.55));
  border-radius: 2px; opacity: 0;
  animation: steam-rise 2.6s var(--ease-in-out) infinite;
}
.steam b:nth-child(1) { left: 2px;  animation-delay: 0s; }
.steam b:nth-child(2) { left: 8px;  animation-delay: .5s; }
.steam b:nth-child(3) { left: 14px; animation-delay: 1s; }
@keyframes steam-rise {
  0%   { opacity: 0; transform: translateY(4px) scaleY(.6); }
  35%  { opacity: .8; }
  100% { opacity: 0; transform: translateY(-14px) scaleY(1.3); }
}

.slime {
  position: absolute;
  left: 20px; bottom: 26px;
  width: 62px; height: 62px;
  display: grid; place-items: center;
  color: #4a86b8;
  animation: slime-idle 2.8s var(--ease-in-out) infinite;
  transform-origin: 50% 100%;
}
.slime svg { width: 46px; height: 46px; filter: drop-shadow(0 4px 10px rgba(74,134,184,.28)); }
@keyframes slime-idle {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  40%      { transform: translateY(-7px) scale(.96, 1.05); }
  70%      { transform: translateY(0) scale(1.05, .94); }
}
.slime.is-squished { animation: slime-squish .5s var(--ease-back); }
@keyframes slime-squish {
  0%   { transform: scale(1, 1); }
  30%  { transform: scale(1.32, .62); }
  60%  { transform: scale(.88, 1.16); }
  100% { transform: scale(1, 1); }
}

.slime-word {
  position: absolute;
  left: 76px; bottom: 62px;
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
  animation: float-word 1.9s var(--ease-out) forwards;
}
.slime-word small { display: block; font-family: var(--font-ui); font-size: 10px; letter-spacing: .18em; color: var(--text-faint); }
@keyframes float-word {
  0%   { opacity: 0; transform: translateY(6px); }
  18%  { opacity: 1; transform: translateY(0); }
  75%  { opacity: 1; transform: translateY(-8px); }
  100% { opacity: 0; transform: translateY(-16px); }
}

/* roaming sparkle */
.sparkle-field { position: absolute; inset: 0; pointer-events: none; }
.sparkle {
  position: absolute;
  width: 52px; height: 52px;
  display: grid; place-items: center;
  pointer-events: auto;
  color: var(--gold);
  font-size: 22px;
  line-height: 1;
  text-shadow: 0 0 14px rgba(201,162,39,.85);
  animation: sparkle-life 6s var(--ease-in-out) forwards;
}
@keyframes sparkle-life {
  0%       { opacity: 0; transform: scale(.4) rotate(-40deg); }
  10%      { opacity: 1; transform: scale(1) rotate(0deg); }
  15%,85%  { opacity: 1; }
  20%      { transform: scale(1.14) rotate(8deg); }
  50%      { transform: scale(.94) rotate(-6deg); }
  80%      { transform: scale(1.1) rotate(4deg); }
  100%     { opacity: 0; transform: scale(.5) rotate(40deg); }
}

/* ══ 3. PARTY ════════════════════════════════════════════════════ */

.party-scroller {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  padding: 4px var(--pad) 8px;
  flex: 0 0 auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.party-scroller::-webkit-scrollbar { display: none; }

.pcard {
  position: relative;
  flex: 0 0 min(300px, 78vw);
  scroll-snap-align: center;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 18px 18px 20px;
  overflow: hidden;
  animation: card-in .55s var(--ease-out) both;
}
@keyframes card-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.pcard::after {
  content: '';
  position: absolute; right: -1px; top: -1px;
  width: 84px; height: 84px;
  background: linear-gradient(225deg, rgba(164,22,26,.14), transparent 62%);
  pointer-events: none;
}
.pcard-pattern { position: absolute; right: 0; bottom: 0; width: 96px; height: 60px; color: var(--text); opacity: .05; pointer-events: none; }
.pcard-pattern svg, .final-pattern svg { width: 100%; height: 100%; }

.pcard .portrait {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 2px;
  overflow: hidden;
  background:
    radial-gradient(62% 62% at 50% 42%, rgba(164,22,26,.30), rgba(164,22,26,.06) 60%, transparent 72%),
    var(--ink-2);
  border: 1px solid var(--hairline);
  display: grid;
  place-items: center;
}
.pcard .portrait img { width: 100%; height: 100%; object-fit: contain; object-position: center bottom; }
.pcard .portrait img.blink-frame { position: absolute; inset: 0; }
.pcard .portrait img.is-hidden { visibility: hidden; }

.ph { display: grid; place-items: center; gap: 6px; width: 100%; height: 100%; }
.ph svg { width: 46%; height: auto; color: var(--text); opacity: .58; }
.ph-name { font-size: 9.5px; letter-spacing: .32em; text-transform: uppercase; color: var(--text-faint); }

.pcard--human .portrait { animation: bob 4s var(--ease-in-out) infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

.pcard h3 { margin: 16px 0 2px; font-size: 17px; letter-spacing: .2em; text-transform: uppercase; }
.pcard .pclass { margin: 0 0 14px; font-family: var(--font-serif); font-size: 12.5px; color: var(--red-bright); letter-spacing: .06em; }
.pcard .pclass em { font-style: normal; color: var(--text-faint); font-family: var(--font-ui); font-size: 10px; letter-spacing: .18em; text-transform: uppercase; }

.stats { display: flex; flex-direction: column; gap: 0; border-top: 1px solid var(--hairline); }
.stat { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--hairline); font-size: 11.5px; }
.stat b { font-weight: 400; color: var(--text-faint); letter-spacing: .1em; text-transform: uppercase; font-size: 9.5px; white-space: nowrap; }
.stat span { color: var(--text); text-align: right; letter-spacing: .04em; }
.stat span.hot { color: var(--red-bright); }
.stat span.gold { color: var(--gold-soft); }
.stat .meter { display: block; width: 74px; height: 3px; margin: 4px 0 0 auto; background: var(--hairline); border-radius: 2px; overflow: hidden; }
.stat .meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--red), var(--red-bright)); }

.pflavor { margin: 14px 0 0; font-family: var(--font-serif); font-size: 12.5px; line-height: 1.65; color: var(--text-dim); }
.psig { margin: 10px 0 0; font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); }

.pcard--mystery { background: #100e0d; border-style: dashed; border-color: var(--hairline-2); }
.pcard--mystery .portrait { background: radial-gradient(60% 60% at 50% 45%, rgba(164,22,26,.12), transparent 70%), #0b0a09; }
.pcard--mystery .ph svg { opacity: .22; }
.pcard--mystery h3 { color: var(--text-faint); letter-spacing: .3em; }
.pcard.is-wiggling { animation: wiggle .5s var(--ease-in-out); }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 20% { transform: rotate(-1.4deg); } 55% { transform: rotate(1.2deg); } 80% { transform: rotate(-.6deg); } }

.pcard.is-tapped { animation: card-tap .35s var(--ease-back); }
@keyframes card-tap { 0% { transform: scale(1); } 40% { transform: scale(.975); } 100% { transform: scale(1); } }

.scroll-hint { text-align: center; font-size: 10px; letter-spacing: .34em; color: var(--text-faint); margin: 14px 0 0; transition: opacity .4s var(--ease-out); }
.scroll-hint.is-hidden { opacity: 0; }

/* ══ 4. DICE ═════════════════════════════════════════════════════ */

.dice-stage {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 300px;
  display: grid;
  place-items: center;
  touch-action: none;
}
.dice-3d { position: absolute; inset: 0; z-index: 1; }
.dice-3d canvas { width: 100% !important; height: 100% !important; display: block; }
.dice-stage .slash, .dice-stage .crit-burst { z-index: 2; }
body:not(.reduced-motion) .dice-stage.is-3d .d20 { display: none; }
.reduced-motion .dice-3d { display: none; }
.dice-stage.is-3d { cursor: pointer; }

.d20 {
  width: min(250px, 66vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  transform-origin: 50% 54%;
  transition: transform .2s var(--ease-back);
}
.d20 svg { width: 100%; height: 100%; overflow: visible; }
.d20-body polygon { fill: var(--panel-2); stroke: var(--hairline-2); stroke-width: 2; stroke-linejoin: round; }
.d20-body .d20-face { fill: #221c1a; stroke: var(--red); stroke-width: 2.4; }
.d20-edges path { stroke: var(--hairline-2); stroke-width: 1.6; fill: none; }
.d20-num {
  fill: var(--text);
  font-family: var(--font-serif);
  font-weight: 800;
  font-size: 52px;
  text-anchor: middle;
  dominant-baseline: middle;
  letter-spacing: -.02em;
}
.d20:active { transform: scale(.97); }

.d20.is-winding { animation: d20-wind .34s var(--ease-in-out); }
@keyframes d20-wind {
  0%   { transform: rotate(0) scale(1); }
  60%  { transform: rotate(-9deg) scale(.94); }
  100% { transform: rotate(-4deg) scale(.97); }
}
.d20.is-rolling { animation: d20-tumble .92s var(--ease-out) forwards; }
@keyframes d20-tumble {
  0%   { transform: rotate(-4deg) scale(.97); filter: blur(0); }
  15%  { transform: rotate(160deg) scale(1.06); filter: blur(1.4px); }
  45%  { transform: rotate(430deg) scale(1.02); filter: blur(1.1px); }
  75%  { transform: rotate(690deg) scale(1);    filter: blur(.4px); }
  90%  { transform: rotate(722deg) scale(1.03); filter: blur(0); }
  100% { transform: rotate(720deg) scale(1);    filter: blur(0); }
}
.d20.is-settled { animation: d20-settle .5s var(--ease-back); }
@keyframes d20-settle {
  0%   { transform: scale(1.07, .93); }
  50%  { transform: scale(.97, 1.03); }
  100% { transform: scale(1); }
}
.d20.is-crit .d20-face { fill: #2b1108; stroke: var(--gold); }
.d20.is-crit .d20-num { fill: var(--gold-soft); }
.d20.is-crit .d20-body polygon:first-child { stroke: var(--gold); }
.d20.is-one .d20-face { stroke: var(--text-faint); }
.d20.is-one .d20-num { fill: var(--text-dim); }

.slash { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.slash.is-on::before, .slash.is-on::after {
  content: '';
  position: absolute; left: -20%; width: 140%; height: 3px;
  background: linear-gradient(90deg, transparent, var(--red-bright) 22%, #fff 50%, var(--red-bright) 78%, transparent);
  box-shadow: 0 0 26px var(--red-bright);
  transform-origin: 50% 50%;
}
.slash.is-on::before { top: 44%; transform: rotate(-24deg); animation: slash-go .52s var(--ease-out) forwards; }
.slash.is-on::after  { top: 56%; transform: rotate(-24deg); animation: slash-go .52s .09s var(--ease-out) forwards; }
@keyframes slash-go {
  0%   { opacity: 0; transform: rotate(-24deg) scaleX(0) ; }
  25%  { opacity: 1; transform: rotate(-24deg) scaleX(1); }
  100% { opacity: 0; transform: rotate(-24deg) scaleX(1.05); }
}

.crit-burst { position: absolute; inset: 0; pointer-events: none; }
.crit-burst i {
  position: absolute; left: 50%; top: 50%;
  width: 2px; height: 26px;
  background: linear-gradient(180deg, var(--gold-soft), transparent);
  transform-origin: 50% 0;
  opacity: 0;
}
.crit-burst.is-on i { animation: burst .8s var(--ease-out) forwards; }
@keyframes burst {
  0%   { opacity: 0; transform: rotate(var(--a)) translateY(0) scaleY(.3); }
  20%  { opacity: 1; }
  100% { opacity: 0; transform: rotate(var(--a)) translateY(120px) scaleY(1.4); }
}

.dice-crit {
  margin: 0;
  height: 30px;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 22px;
  letter-spacing: .16em;
  color: var(--gold);
  text-shadow: 0 0 24px rgba(201,162,39,.6);
  opacity: 0;
  transform: scale(.8);
}
.dice-crit.is-on { animation: crit-in .9s var(--ease-back) forwards; }
@keyframes crit-in {
  0%   { opacity: 0; transform: scale(.6); }
  35%  { opacity: 1; transform: scale(1.14); }
  60%  { transform: scale(1); }
  100% { opacity: 1; transform: scale(1); }
}

.dice-flavor {
  margin: 12px var(--pad) 0;
  min-height: 3.4em;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-dim);
  transition: opacity .3s var(--ease-out);
}
.dice-flavor.is-swapping { opacity: 0; }
.dice-caption { margin: 16px 0 4px; text-align: center; font-size: 10px; letter-spacing: .26em; text-transform: uppercase; color: var(--text-faint); }

/* ══ 5. ACHIEVEMENTS ═════════════════════════════════════════════ */

.ach-flavor { margin: 0 var(--pad) 16px; font-family: var(--font-serif); font-size: 12.5px; line-height: 1.7; color: var(--text-dim); text-align: center; }

.progress { height: 2px; margin: 0 var(--pad) 22px; background: var(--hairline); border-radius: 2px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--red-deep), var(--red-bright)); box-shadow: 0 0 10px rgba(229,56,59,.6); transition: width .7s var(--ease-out); }
.progress.is-full i { background: linear-gradient(90deg, var(--gold), var(--gold-soft)); box-shadow: 0 0 12px rgba(201,162,39,.7); }

.ach-complete {
  margin: 0 var(--pad) 20px;
  padding: 20px 18px;
  text-align: center;
  border: 1px solid rgba(201,162,39,.42);
  border-radius: 3px;
  background: linear-gradient(180deg, rgba(201,162,39,.10), rgba(201,162,39,.02));
  animation: rise .6s var(--ease-out) both;
}
.acx-jp { margin: 0; font-family: var(--font-serif); font-size: 22px; letter-spacing: .2em; color: var(--gold-soft); }
.acx-en { margin: 4px 0 16px; font-size: 9.5px; letter-spacing: .3em; text-transform: uppercase; color: var(--text-faint); }

.ach-list { display: flex; flex-direction: column; gap: 10px; padding: 0 var(--pad) 30px; }

.ach {
  position: relative;
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 14px;
  align-items: start;
  min-height: 74px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  overflow: hidden;
}
.ach-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 1px solid var(--hairline-2);
  border-radius: 50%;
  font-size: 15px;
  color: var(--text-faint);
  font-family: var(--font-serif);
}
.ach-name { margin: 0; font-family: var(--font-serif); font-size: 15.5px; letter-spacing: .1em; }
.ach-en { margin: 2px 0 0; font-size: 9px; letter-spacing: .28em; text-transform: uppercase; color: var(--text-faint); }
.ach-desc { margin: 8px 0 0; font-size: 12px; line-height: 1.6; color: var(--text-dim); }

.ach--locked .ach-name { color: var(--text-faint); letter-spacing: .24em; }
.ach--locked .ach-desc { color: var(--text-faint); font-style: italic; opacity: .8; }

.ach--unlocked { border-color: rgba(164,22,26,.42); background: linear-gradient(100deg, rgba(164,22,26,.09), var(--panel) 55%); }
.ach--unlocked .ach-mark { border-color: var(--red); color: var(--red-bright); box-shadow: 0 0 14px -4px var(--red-bright); }
.ach--unlocked .ach-name { color: var(--text); }
.ach--unlocked.is-fresh { animation: ach-flash .9s var(--ease-out); }
@keyframes ach-flash {
  0%   { background: rgba(229,56,59,.45); border-color: var(--gold); transform: scale(1.015); }
  40%  { background: rgba(201,162,39,.16); }
  100% { background: linear-gradient(100deg, rgba(164,22,26,.09), var(--panel) 55%); transform: scale(1); }
}

/* ══ 6. SETTINGS ═════════════════════════════════════════════════ */

.row-toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-height: 72px;
  padding: 16px 18px;
  text-align: left;
  border-bottom: 1px solid var(--hairline);
  transition: background-color .25s var(--ease-out);
}
.row-toggle:last-of-type { border-bottom: 0; }
.row-toggle:active { background: var(--panel-2); }
.rt-label b { display: block; font-family: var(--font-serif); font-weight: 400; font-size: 16px; letter-spacing: .1em; }
.rt-label em { display: block; margin-top: 3px; font-style: normal; font-size: 10px; letter-spacing: .18em; text-transform: uppercase; color: var(--text-faint); }
.rt-label .lock { display: inline-block; width: 13px; height: 13px; vertical-align: -1px; color: var(--text-faint); }

.switch {
  flex: 0 0 auto;
  position: relative;
  width: 52px; height: 30px;
  border-radius: 15px;
  background: #241f1d;
  border: 1px solid var(--hairline-2);
  transition: background-color .3s var(--ease-out), border-color .3s var(--ease-out);
}
.switch i {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform .32s var(--ease-back), background-color .3s var(--ease-out);
}
[aria-checked="true"] .switch { background: rgba(164,22,26,.34); border-color: var(--red); }
[aria-checked="true"] .switch i { transform: translateX(22px); background: var(--red-bright); box-shadow: 0 0 10px -1px var(--red-bright); }

.row-toggle--managed { background: linear-gradient(90deg, rgba(164,22,26,.05), transparent 60%); }
.rt-spinner {
  position: absolute; left: 18px; bottom: 6px;
  display: flex; align-items: center; gap: 7px;
  font-size: 10px; letter-spacing: .14em; color: var(--text-faint);
}
.rt-spinner i {
  width: 11px; height: 11px; border-radius: 50%;
  border: 1.5px solid var(--hairline-2); border-top-color: var(--red-bright);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.rt-note { margin: 12px var(--pad) 0; font-size: 11.5px; letter-spacing: .1em; color: var(--gold-soft); text-align: right; animation: rise .5s var(--ease-out) both; }

.version { margin: auto var(--pad) 4px; padding-top: 34px; text-align: center; font-size: 10.5px; letter-spacing: .24em; text-transform: uppercase; color: var(--text-faint); user-select: none; }
.version em { font-style: normal; opacity: .5; margin: 0 4px; }
.version .heart { color: var(--red); }
.version.is-tapped { animation: card-tap .3s var(--ease-back); }

/* ══ KITCHEN ═════════════════════════════════════════════════════ */

.kitchen-prompt {
  margin: 0 var(--pad) 6px;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 15px;
  letter-spacing: .1em;
  color: var(--text);
  min-height: 1.6em;
  transition: opacity .3s var(--ease-out);
}
.kitchen-prompt.is-swapping { opacity: 0; }
.kitchen-prompt.is-nope { animation: shake .4s var(--ease-in-out); color: var(--red-bright); }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 50% { transform: translateX(4px); } 75% { transform: translateX(-2px); } }

.bowl-wrap { position: relative; flex: 1 1 auto; display: grid; place-items: center; min-height: 230px; }

.bowl {
  position: relative;
  width: min(228px, 60vw);
  aspect-ratio: 1 / .78;
  margin-right: 52px;      /* keeps clear of the juice bottle */
  touch-action: none;
  transition: transform .2s var(--ease-out);
}
.bowl.is-target { transform: scale(1.04); }
.bowl.is-target .bowl-body { border-color: var(--red); box-shadow: 0 26px 50px -26px #000, inset 0 -14px 26px -14px rgba(0,0,0,.9), 0 0 22px -6px rgba(164,22,26,.55); }
.bowl-body {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, #2b2523 0%, #17110f 62%, #100c0b 100%);
  border: 1px solid #3a3230;
  border-radius: 6px 6px 48% 48% / 6px 6px 62% 62%;
  box-shadow: 0 26px 50px -26px #000, inset 0 -14px 26px -14px rgba(0,0,0,.9);
  pointer-events: none;
}
.bowl-body::before {
  content: '';
  position: absolute; left: 6%; right: 6%; top: 6px; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(242,236,225,.16), transparent);
}
.broth {
  position: absolute;
  left: 5%; right: 5%; top: 7px;
  height: 30%;
  border-radius: 50%;
  background: radial-gradient(70% 100% at 50% 30%, #6b5a33, #3d3320 70%, #2a2317);
  box-shadow: inset 0 3px 14px -4px rgba(0,0,0,.7);
  transition: background 1.1s var(--ease-out);
  overflow: hidden;
}
.broth.is-miso { background: radial-gradient(70% 100% at 50% 30%, #c78a3c, #9c6427 65%, #7a4d1d); }
.broth-shine { position: absolute; left: 16%; top: 14%; width: 34%; height: 26%; border-radius: 50%; background: rgba(255,255,255,.10); filter: blur(4px); }

.drops { position: absolute; left: 5%; right: 5%; top: 7px; height: 30%; pointer-events: none; }
.drop {
  position: absolute;
  transform: translate(-50%, -50%) scale(0);
  font-size: 17px;
  line-height: 1;
  animation: drop-in .55s var(--ease-back) forwards;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.6));
}
.drop img, .ing-ghost img { width: 26px; height: 26px; object-fit: contain; display: block; }
.ing-ghost img { width: 44px; height: 44px; }
@keyframes drop-in {
  0%   { transform: translate(-50%, -160%) scale(.5); opacity: 0; }
  55%  { transform: translate(-50%, -50%) scale(1.25); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
.drop.is-float { animation: drop-in .55s var(--ease-back) forwards, drop-bob 3.6s var(--ease-in-out) .55s infinite; }
@keyframes drop-bob { 0%,100% { margin-top: 0; } 50% { margin-top: -3px; } }

.ripples { position: absolute; left: 5%; right: 5%; top: 7px; height: 30%; pointer-events: none; overflow: hidden; border-radius: 50%; }
.ripple {
  position: absolute;
  width: 14px; height: 8px;
  margin: -4px 0 0 -7px;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 50%;
  animation: ripple-out .85s var(--ease-out) forwards;
}
@keyframes ripple-out { to { transform: scale(6); opacity: 0; } }

.stir-hint {
  position: absolute; left: 0; right: 0; top: 46%;
  margin: 0;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 17px;
  letter-spacing: .12em;
  color: var(--text);
  text-shadow: 0 2px 10px #000;
  pointer-events: none;
  animation: pulse-soft 1.9s var(--ease-in-out) infinite;
}
.stir-hint small { display: block; font-family: var(--font-ui); font-size: 9.5px; letter-spacing: .24em; text-transform: uppercase; color: var(--text-dim); margin-top: 3px; }
@keyframes pulse-soft { 0%,100% { opacity: .55; } 50% { opacity: 1; } }

.miso-tint {
  position: absolute; inset: 0;
  background: radial-gradient(70% 100% at 50% 30%, #c78a3c, #9c6427 65%, #7a4d1d);
  opacity: 0;
  transition: opacity .25s linear;
}

.spoon {
  position: absolute;
  left: 58%; top: 17%;
  width: 24px;
  z-index: 3;
  transform: translate(-50%, -30%);
  pointer-events: none;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.5));
}
.spoon svg { width: 100%; height: auto; }
.spoon.is-idle { animation: spoon-bob 2.1s var(--ease-in-out) infinite; }
@keyframes spoon-bob { 0%,100% { margin-top: 0; } 50% { margin-top: -4px; } }

.raid-dog {
  position: absolute;
  bottom: -8px; left: 0;
  height: 112px; width: auto;
  z-index: 6;
  pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.6));
  animation: raid-run 1.8s var(--ease-in-out) forwards;
}
@keyframes raid-run {
  0%   { transform: translateX(-130%) rotate(-4deg); }
  42%  { transform: translateX(26vw) rotate(3deg); }
  58%  { transform: translateX(28vw) rotate(-4deg); }
  100% { transform: translateX(115vw) rotate(2deg); }
}
.reduced-motion .raid-dog { animation-duration: .9s; }

.steam-field { position: absolute; left: 50%; top: 4%; width: 120px; height: 110px; transform: translateX(-50%); pointer-events: none; opacity: 0; transition: opacity .8s var(--ease-out); }
.steam-field.is-on { opacity: 1; }
.steam-field b {
  position: absolute; bottom: 0;
  width: 3px; height: 40px;
  background: linear-gradient(180deg, transparent, rgba(242,236,225,.5));
  border-radius: 3px;
  filter: blur(1.5px);
  animation: steam-big 3.4s var(--ease-in-out) infinite;
}
.steam-field b:nth-child(1) { left: 14%; animation-delay: 0s; }
.steam-field b:nth-child(2) { left: 32%; animation-delay: .6s; }
.steam-field b:nth-child(3) { left: 50%; animation-delay: 1.2s; }
.steam-field b:nth-child(4) { left: 68%; animation-delay: 1.8s; }
.steam-field b:nth-child(5) { left: 86%; animation-delay: 2.4s; }
@keyframes steam-big {
  0%   { opacity: 0; transform: translateY(10px) scaleY(.5) translateX(0); }
  30%  { opacity: .75; }
  100% { opacity: 0; transform: translateY(-70px) scaleY(1.5) translateX(12px); }
}

/* grape juice bottle */
.bottle {
  position: absolute;
  right: 4px; bottom: 0;
  width: 76px;
  display: grid;
  justify-items: center;
  transition: transform .2s var(--ease-back);
}
.bottle:active { transform: scale(.95) rotate(2deg); }
.bottle.is-glugging { animation: glug-tilt .45s var(--ease-in-out); }
@keyframes glug-tilt { 0%,100% { transform: rotate(0); } 40% { transform: rotate(-9deg) translateY(-3px); } }
.bottle-neck { width: 20px; height: 30px; background: linear-gradient(90deg, #1e2418, #33402a 45%, #1a2015); border: 1px solid #3f4d33; border-bottom: 0; border-radius: 4px 4px 0 0; }
.bottle-body {
  position: relative;
  width: 68px; height: 132px;
  background: linear-gradient(90deg, rgba(30,36,24,.9), rgba(51,64,42,.55) 45%, rgba(26,32,21,.9));
  border: 1px solid #3f4d33;
  border-radius: 8px 8px 12px 12px;
  overflow: hidden;
  box-shadow: inset 0 0 22px -6px #000;
}
.juice {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 100%;
  background: linear-gradient(180deg, #5c1a52, #3d0f38);
  box-shadow: inset 0 4px 8px -4px rgba(255,255,255,.28);
  transition: height .55s var(--ease-out);
}
.juice::before { content: ''; position: absolute; left: 0; right: 0; top: -3px; height: 6px; background: #7a2470; border-radius: 50%; }
.bottle-label {
  position: absolute; left: 6px; right: 6px; top: 44px;
  padding: 5px 0;
  background: rgba(242,236,225,.9);
  color: #3d0f38;
  font-family: var(--font-serif);
  font-size: 11px;
  font-style: normal;
  line-height: 1.15;
  text-align: center;
  letter-spacing: .06em;
  border-radius: 1px;
}
.bottle-label small { font-size: 7.5px; letter-spacing: .2em; opacity: .75; }
.bottle.is-empty { animation: bottle-sparkle 1.4s var(--ease-out); }
@keyframes bottle-sparkle {
  0%,100% { filter: none; }
  30%     { filter: drop-shadow(0 0 16px var(--gold-soft)) brightness(1.3); }
  65%     { filter: drop-shadow(0 0 6px var(--gold)) brightness(1.1); }
}

.tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 16px var(--pad) 6px;
  border-top: 1px solid var(--hairline);
  flex: 0 0 auto;
}
.ing {
  display: grid;
  place-items: center;
  gap: 1px;
  min-width: 62px;
  min-height: 62px;
  padding: 7px 8px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform .2s var(--ease-back), opacity .3s var(--ease-out), border-color .3s var(--ease-out);
}
.ing .ing-glyph { font-size: 20px; line-height: 1.15; pointer-events: none; }
.ing .ing-glyph svg { width: 22px; height: 22px; display: inline-block; vertical-align: middle; }
.ing .ing-glyph img { width: 30px; height: 30px; object-fit: contain; display: inline-block; vertical-align: middle; }
.ing .ing-name { pointer-events: none; }
.ing .ing-name { font-family: var(--font-serif); font-size: 10.5px; letter-spacing: .06em; color: var(--text-dim); }
.ing:active { transform: scale(.94); border-color: var(--hairline-2); }
.ing.is-used { opacity: .26; pointer-events: none; border-style: dashed; }
.ing.is-dragging { opacity: .3; }
.ing.is-nope { animation: nope-hop .5s var(--ease-back); border-color: var(--red); }
@keyframes nope-hop {
  0%   { transform: translateY(0) rotate(0); }
  30%  { transform: translateY(-12px) rotate(-7deg); }
  60%  { transform: translateY(0) rotate(5deg); }
  80%  { transform: translateY(-3px) rotate(-2deg); }
  100% { transform: translateY(0) rotate(0); }
}

.ing-ghost {
  position: fixed;
  z-index: 800;
  pointer-events: none;
  display: grid;
  place-items: center;
  width: 66px; height: 66px;
  font-size: 26px;
  background: var(--panel-2);
  border: 1px solid var(--red);
  border-radius: 3px;
  box-shadow: 0 14px 30px -12px #000;
  will-change: left, top;
  /* floats above the finger so the thumb never hides it */
  transform: translate(-50%, -130%) scale(1.1);
}

.kitchen-done {
  margin: 6px var(--pad) 0;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 24px;
  letter-spacing: .2em;
  color: var(--gold-soft);
  text-shadow: 0 0 26px rgba(201,162,39,.5);
  animation: crit-in 1s var(--ease-back) both;
}

/* ══ BATTLE ══════════════════════════════════════════════════════ */

/* Wild Chase — styled like a classic handheld Pokémon battle */
#screen-battle {
  padding: 0;
  background: linear-gradient(180deg, #cfe6f5 0%, #dcecc2 42%, #b7d789 68%, #a3c973 100%);
  backdrop-filter: none;
}
.pkb { display: flex; flex-direction: column; height: 100%; font-family: 'Press Start 2P', monospace; }
.pkb-field { position: relative; flex: 1 1 auto; min-height: 0; }

.pkb-box {
  position: absolute;
  background: #f8f4e0;
  border: 3px solid #3c3c44;
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px #fffdf2, 0 3px 0 rgba(0, 0, 0, .18);
  padding: 9px 11px 8px;
  color: #22222a;
  min-width: 182px;
}
.pkb-enemybox { left: 12px; top: max(14px, env(safe-area-inset-top)); }
.pkb-playerbox { right: 12px; bottom: 12px; }

.pkb-namerow { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.pkb-namerow b { font-size: 10px; font-weight: 400; letter-spacing: .02em; }
.pkb-lv { font-size: 8px; color: #444; }

.pkb-hprow { display: flex; align-items: center; gap: 5px; margin-top: 7px; }
.pkb-hprow i { font-style: normal; font-size: 7px; color: #f0a030; }
.pkb-hpbar {
  flex: 1;
  height: 8px;
  background: #585850;
  border-radius: 4px;
  padding: 1.5px;
}
.pkb-hpbar b {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 3px;
  background: linear-gradient(180deg, #78e888, #40b850);
  transition: width .8s var(--ease-out), background-color .4s;
}
.pkb-hpbar b.is-low { background: linear-gradient(180deg, #f08058, #d84028); }
.pkb-hpnum { display: block; text-align: right; font-size: 7.5px; margin-top: 5px; color: #444; }

.pkb-enemy {
  position: absolute;
  right: 5%;
  top: 20%;
  width: min(50vw, 230px);
}
.pkb-platform {
  width: 92%;
  height: 30px;
  margin: -14px auto 0;
  border-radius: 50%;
  background: radial-gradient(60% 60% at 50% 40%, #9fcb72, #7fb254 70%, #6e9e47);
  box-shadow: inset 0 3px 6px rgba(255, 255, 255, .35), 0 2px 4px rgba(0, 0, 0, .18);
}
#screen-battle .battle-portrait {
  position: relative;
  z-index: 1;
  width: 100%;
  aspect-ratio: 1;
  border: 0;
  background: none;
  display: grid;
  place-items: center;
  animation: chase-idle 2.2s var(--ease-in-out) infinite;
}
.battle-portrait img { width: 92%; height: 92%; object-fit: contain; filter: drop-shadow(0 8px 8px rgba(30, 60, 20, .3)); }
.battle-portrait .ph { color: #4a5a3a; }
@keyframes chase-idle {
  0%, 100% { transform: translateY(0) rotate(0) scale(1); }
  22%      { transform: translateY(-7px) rotate(-2deg) scale(1.015); }
  46%      { transform: translateY(-2px) rotate(.6deg) scale(.995); }
  72%      { transform: translateY(-5px) rotate(1.6deg) scale(1.01); }
}
#screen-battle .battle-portrait.is-attacking { animation: chase-lunge .5s var(--ease-back); }
@keyframes chase-lunge {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.24) translate(-34px, 16px) rotate(-6deg); }
  70%  { transform: scale(1.08) translate(-10px, 4px) rotate(2deg); }
  100% { transform: scale(1); }
}

.dmg-field { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.dmg {
  position: absolute;
  left: 50%; top: 40%;
  font-family: 'Press Start 2P', monospace;
  font-size: 20px;
  color: #d82828;
  text-shadow: 2px 2px 0 #fff, -2px 2px 0 #fff, 2px -2px 0 #fff, -2px -2px 0 #fff;
  transform: translate(-50%, 0);
  animation: dmg-pop 1.3s var(--ease-out) forwards;
  white-space: nowrap;
}
@keyframes dmg-pop {
  0%   { opacity: 0; transform: translate(-50%, 10px) scale(.6); }
  18%  { opacity: 1; transform: translate(-50%, -8px) scale(1.16); }
  32%  { transform: translate(-50%, -4px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -54px) scale(.95); }
}

.pkb-bottom {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
  padding: 8px 8px max(10px, env(safe-area-inset-bottom));
  background: #30404e;
  border-top: 3px solid #202a34;
}
.pkb-msg {
  background: #f8f8f8;
  border: 3px solid #5878a0;
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px #fff;
  padding: 10px 11px;
  min-height: 118px;
  color: #22222a;
}
.battle-banner { margin: 0 0 8px; font-size: 9px; line-height: 1.8; font-family: 'Press Start 2P', var(--font-ui), monospace; color: #22222a; }
.battle-log { font-size: 8.5px; line-height: 1.9; color: #33333a; }
.battle-log .move-name { display: block; font-size: 9px; color: #c02121; margin-bottom: 4px; font-family: 'Press Start 2P', var(--font-ui), monospace; }
.battle-log .en { display: block; font-size: 8.5px; color: #55555c; }
.battle-log .caret::after { content: '▼'; color: #c02121; margin-left: 4px; animation: blink-caret .8s steps(2) infinite; }
@keyframes blink-caret { 50% { opacity: 0; } }

.battle-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: 1fr;
  gap: 5px;
  background: #f8f4e0;
  border: 3px solid #3c3c44;
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px #fffdf2;
  padding: 7px;
}
.btn-action {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  padding: 6px 2px;
  border-radius: 4px;
  color: #22222a;
  transition: background-color .15s;
  position: relative;
}
.btn-action b { font-family: var(--font-ui); font-weight: 700; font-size: 12px; line-height: 1; }
.btn-action em { font-style: normal; font-family: 'Press Start 2P', monospace; font-size: 6.5px; color: #666; }
.btn-action:active { background: #e8dfc0; }
.btn-action:active::before { content: '▶'; position: absolute; left: 3px; font-size: 8px; color: #c02121; }
.btn-action[disabled] { opacity: .3; pointer-events: none; }
.btn-action.is-highlight { background: #fdeeb8; box-shadow: inset 0 0 0 2px #e0b430; animation: pulse-soft 1.6s var(--ease-in-out) infinite; }
.btn-action.is-highlight::before { content: '▶'; position: absolute; left: 3px; font-size: 8px; color: #c02121; }

/* ══ FINAL MESSAGE ═══════════════════════════════════════════════ */

#screen-final { background: rgba(6,5,5,.985); }
.final-scroll { width: 100%; padding: 8px var(--pad) 30px; margin: auto 0; }

.final-panel {
  position: relative;
  padding: 34px 22px 30px;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(164,22,26,.08), transparent 60%),
    var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  box-shadow: 0 40px 90px -40px #000;
}
.final-pattern {
  position: absolute;
  left: 0; top: 0;
  width: 110px; height: 140px;
  color: var(--text);
  opacity: .05;
  pointer-events: none;
}
.final-panel p {
  position: relative;
  margin: 0 0 20px;
  font-family: var(--font-serif);
  font-size: 14.5px;
  line-height: 2.05;
  color: var(--text);
  opacity: 0;
  animation: rise .9s var(--ease-out) forwards;
}
.final-panel p.lead { font-size: 19px; letter-spacing: .1em; margin-bottom: 26px; }
.final-panel p.jp { font-size: 17px; letter-spacing: .1em; color: var(--gold-soft); text-align: center; margin: 30px 0; }
.final-panel p.sign { font-size: 13px; color: var(--text-dim); text-align: right; line-height: 1.9; }

/* seven 40px chips + gaps stay inside 390px minus the page padding */
.final-portraits { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 26px 0 22px; opacity: 0; animation: rise .9s var(--ease-out) forwards; }
.fp {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border: 1px solid var(--hairline);
  border-radius: 50%;
  overflow: hidden;
  display: grid; place-items: center;
  background: radial-gradient(60% 60% at 50% 45%, rgba(164,22,26,.28), transparent 72%), var(--ink-2);
}
.fp img { width: 100%; height: 100%; object-fit: cover; }
.fp svg { width: 62%; color: var(--text); opacity: .6; }
#btn-final-close { display: block; margin: 0 auto; }

/* confetti */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 950; overflow: hidden; }
.conf {
  position: absolute;
  width: 6px; height: 12px;
  border-radius: 1px;
  animation: conf-fall linear forwards;
}
@keyframes conf-fall {
  0%   { opacity: 0; transform: translateY(-20px) rotate(0deg); }
  10%  { opacity: 1; }
  85%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(102vh) rotate(680deg); }
}

/* ══ TOASTS / ACHIEVEMENT POPUPS / MODAL ═════════════════════════ */

#toast-layer {
  position: fixed;
  left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(var(--shell), 100%);
  padding: 0 var(--pad);
  z-index: 960;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  max-width: 100%;
  padding: 12px 18px;
  background: rgba(23,20,18,.97);
  border: 1px solid var(--hairline-2);
  border-radius: 2px;
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
  box-shadow: 0 18px 40px -18px #000;
  animation: toast-in .4s var(--ease-back) both;
}
.toast .jp { display: block; font-family: var(--font-serif); font-size: 14.5px; letter-spacing: .08em; }
.toast .en { display: block; font-size: 11.5px; color: var(--text-dim); margin-top: 3px; }
.toast.is-gold { border-color: rgba(201,162,39,.5); }
.toast.is-out { animation: toast-out .35s var(--ease-in-out) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }

#ach-popup-layer {
  position: fixed;
  left: 50%; top: max(14px, env(safe-area-inset-top));
  transform: translateX(-50%);
  width: min(var(--shell), 100%);
  padding: 0 var(--pad);
  z-index: 970;
  pointer-events: none;
}
.ach-pop {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  background: linear-gradient(100deg, rgba(60,10,12,.98), rgba(23,20,18,.98));
  border: 1px solid var(--gold);
  border-radius: 2px;
  box-shadow: 0 20px 50px -20px #000, 0 0 40px -22px var(--gold);
  animation: pop-in .55s var(--ease-back) both;
}
.ach-pop.is-out { animation: pop-out .4s var(--ease-in-out) forwards; }
@keyframes pop-in  { from { opacity: 0; transform: translateY(-24px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes pop-out { to { opacity: 0; transform: translateY(-16px) scale(.97); } }
.ach-pop .mark {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 1px solid var(--gold);
  border-radius: 50%;
  font-family: var(--font-serif);
  font-size: 16px;
  color: var(--gold-soft);
}
.ach-pop .label { font-size: 8.5px; letter-spacing: .34em; text-transform: uppercase; color: var(--gold); }
.ach-pop .name { font-family: var(--font-serif); font-size: 16px; letter-spacing: .1em; margin-top: 1px; }

#modal-root { position: fixed; inset: 0; z-index: 980; display: none; }
#modal-root.is-open { display: grid; place-items: center; padding: var(--pad); }
.modal-scrim { position: absolute; inset: 0; background: rgba(4,3,3,.8); backdrop-filter: blur(3px); animation: fade-in .3s var(--ease-out) both; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  position: relative;
  width: 100%;
  max-width: 340px;
  padding: 26px 22px 20px;
  background: var(--panel);
  border: 1px solid var(--hairline-2);
  border-radius: 3px;
  text-align: center;
  box-shadow: 0 30px 80px -28px #000;
  animation: pop-in .45s var(--ease-back) both;
}
.modal h3 { margin: 0 0 10px; font-family: var(--font-serif); font-weight: 400; font-size: 18px; line-height: 1.6; letter-spacing: .08em; }
.modal p { margin: 0 0 20px; font-size: 12.5px; line-height: 1.7; color: var(--text-dim); }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.modal-actions .btn { flex: 1 1 120px; min-height: 48px; padding: 12px 18px; font-size: 13.5px; }

/* ══ reduced motion ══════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body.reduced-motion *,
body.reduced-motion *::before,
body.reduced-motion *::after {
  animation-duration: .01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .05s !important;
  scroll-behavior: auto !important;
}
body.reduced-motion .title-logo { opacity: 1; }
body.reduced-motion .title-logo > * { opacity: 1 !important; }
body.reduced-motion .final-panel p,
body.reduced-motion .final-portraits { opacity: 1 !important; }
body.reduced-motion .dice-crit.is-on { opacity: 1; transform: none; }
body.reduced-motion #confetti { display: none; }
body.reduced-motion #grain { opacity: .03; }

/* ── ultimate cut-in (long-press a party portrait) ───────────────── */
.ult {
  position: fixed; inset: 0;
  z-index: 900;
  overflow: hidden;
  background: rgba(8, 6, 5, .96);
  cursor: pointer;
}
.ult-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 2; }
.ult:not([hidden]) .ult-flash { animation: ult-flash .5s ease-out; }
@keyframes ult-flash { 0% { opacity: .85; } 100% { opacity: 0; } }

.ult-panel { margin: 0; position: absolute; inset: 0; }
.ult-panel img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 0 60px rgba(164, 22, 26, .35));
}
/* grows to fill the screen and keeps going past it */
.ult:not([hidden]) .ult-panel img { animation: ult-zoom 9s var(--ease-out) forwards; }
@keyframes ult-zoom {
  0%   { transform: scale(.34); opacity: 0; }
  6%   { opacity: 1; }
  22%  { transform: scale(1); opacity: 1; }
  100% { transform: scale(var(--ult-zoom, 2.1)); opacity: 1; }
}
.ult-panel figcaption {
  position: absolute;
  left: 0; right: 0;
  bottom: max(26px, env(safe-area-inset-bottom));
  z-index: 3;
  text-align: center;
  font-family: var(--font-serif);
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--text);
  text-shadow: 0 2px 14px #000, 0 0 30px #000;
}
.ult-jp { display: inline-block; margin-right: 12px; color: var(--red-bright); letter-spacing: .14em; }
.ult-panel b { font-weight: 600; }

.pcard .portrait.is-pressing { transform: scale(.96); transition: transform .3s var(--ease-out); }

body.reduced-motion .ult:not([hidden]) .ult-flash,
body.reduced-motion .ult:not([hidden]) .ult-panel img { animation: none; }


/* ── Chase's Pokémon-style trading card ──────────────────────────── */
.pokecard {
  background: linear-gradient(160deg, #f7dd6b 0%, #e8c23a 55%, #d9ae2b 100%);
  border: 1px solid #b8901f;
  border-radius: 12px;
  padding: 9px;
  color: #262019;
}
.pokecard::after { display: none; }

.pk-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: linear-gradient(175deg, #efe7d2 0%, #e4d9bd 100%);
  border: 1px solid rgba(120, 90, 20, .35);
  border-radius: 6px;
  padding: 10px 11px 8px;
  position: relative;
  font-family: 'Gill Sans', 'Trebuchet MS', var(--font-ui);
}

.pk-top { display: flex; align-items: baseline; gap: 8px; }
.pk-stage {
  font-size: 8.5px;
  font-style: italic;
  font-weight: 700;
  color: #4a3d28;
  border: 1px solid rgba(120, 90, 20, .4);
  border-radius: 6px;
  padding: 1px 6px;
  background: rgba(255, 255, 255, .45);
}
.pk-name { margin: 0; flex: 1; font-size: 17px; font-weight: 800; letter-spacing: .01em; color: #1c1610; }
.pk-hp { font-size: 14px; font-weight: 800; color: #c02121; display: inline-flex; align-items: center; gap: 4px; }

.pk-energy {
  display: inline-block;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fdfdf9, #cfc9bc 60%, #a49c8a);
  border: 1px solid #8d8574;
  position: relative;
}
.pk-energy::before {
  content: '★';
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 8px;
  color: #7d7461;
}

.pk-art {
  position: relative;
  margin-top: 7px;
  aspect-ratio: 4 / 3;
  border: 3px solid #c7a72e;
  border-radius: 3px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 90% at 20% 15%, rgba(255, 255, 255, .55), transparent 50%),
    linear-gradient(135deg, #8ec5e8 0%, #cfe3b8 45%, #e8d3ef 75%, #f2e3b8 100%);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, .25);
}
.pk-art img { width: 88%; height: 92%; object-fit: contain; filter: drop-shadow(0 4px 6px rgba(0,0,0,.3)); }
.pk-art .ph { color: #4a3d28; }
.pk-art .ph svg { opacity: .5; }

.pk-species {
  margin: 6px 2px 4px;
  text-align: center;
  font-size: 8.5px;
  font-style: italic;
  font-weight: 600;
  color: #4a3d28;
  border-bottom: 1px solid rgba(120, 90, 20, .3);
  padding-bottom: 4px;
}

.pk-attacks { display: flex; flex-direction: column; gap: 5px; flex: 1; }
.pk-attack {
  display: grid;
  grid-template-columns: 46px 1fr 34px;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(120, 90, 20, .18);
}
.pk-attack:last-child { border-bottom: 0; }
.pk-cost { display: inline-flex; gap: 2px; flex-wrap: wrap; }
.pk-atk b { display: block; font-size: 12px; font-weight: 800; color: #1c1610; line-height: 1.25; }
.pk-atk small { display: block; font-size: 8.6px; line-height: 1.35; color: #453a27; }
.pk-dmg { text-align: right; font-size: 15px; font-weight: 800; color: #1c1610; }

.pk-bottom {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  border-top: 2px solid rgba(120, 90, 20, .35);
  margin-top: 5px;
  padding-top: 4px;
  font-size: 8px;
  color: #453a27;
}
.pk-bottom b { display: block; font-size: 7px; text-transform: uppercase; letter-spacing: .08em; color: #6b5a35; }

.pk-flavor {
  margin: 5px 2px 0;
  font-size: 8.2px;
  font-style: italic;
  line-height: 1.4;
  color: #574a30;
  border-top: 1px solid rgba(120, 90, 20, .2);
  padding-top: 4px;
}
.pk-setnum { position: absolute; right: 9px; bottom: 5px; font-size: 7.5px; font-weight: 700; color: #6b5a35; }

.row-toggle--danger .rt-label b { color: var(--red-bright); }
.row-toggle--danger:active { background: rgba(164, 22, 26, .12); }


/* ── battle visual effects ───────────────────────────────────────── */
.pkb-fx {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  font-size: 30px;
  line-height: 1;
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.25));
}

/* player's hand reaches up to pet */
.fx-hand { left: 14%; top: 82%; animation: fx-hand 1.5s var(--ease-in-out) forwards; }
@keyframes fx-hand {
  0%   { left: 14%; top: 82%; opacity: 0; transform: rotate(0); }
  35%  { left: 52%; top: 38%; opacity: 1; transform: rotate(-14deg); }
  50%  { transform: rotate(14deg); }
  65%  { transform: rotate(-14deg); }
  80%  { left: 52%; top: 38%; opacity: 1; transform: rotate(8deg); }
  100% { left: 40%; top: 60%; opacity: 0; }
}

/* snack arcs over to Chase */
.fx-snack { left: 10%; top: 84%; animation: fx-snack 1.4s var(--ease-in-out) forwards; }
@keyframes fx-snack {
  0%   { left: 10%; top: 84%; opacity: 0; transform: rotate(0); }
  15%  { opacity: 1; }
  50%  { left: 44%; top: 14%; transform: rotate(200deg); }
  85%  { left: 66%; top: 34%; opacity: 1; transform: rotate(340deg); }
  100% { left: 68%; top: 40%; opacity: 0; transform: rotate(360deg) scale(.6); }
}

/* the thrown ball — bounces right off */
.fx-ball { left: 10%; top: 84%; width: 26px; height: 26px; animation: fx-ball 1.7s var(--ease-in-out) forwards; }
.fx-ball::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, #e04038 0 44%, #26262e 44% 56%, #f2f2f2 56% 100%);
  border: 2px solid #26262e;
}
.fx-ball::after {
  content: '';
  position: absolute; left: 50%; top: 50%;
  width: 8px; height: 8px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #f2f2f2;
  border: 2px solid #26262e;
}
@keyframes fx-ball {
  0%   { left: 10%; top: 84%; opacity: 0; transform: rotate(0); }
  12%  { opacity: 1; }
  48%  { left: 62%; top: 24%; transform: rotate(320deg); }   /* hits Chase */
  62%  { left: 52%; top: 14%; transform: rotate(400deg); }   /* bounces off */
  100% { left: 40%; top: 110%; opacity: 1; transform: rotate(560deg); }
}

/* claw swipe over the player's info box */
.fx-slash { right: 8%; bottom: 14%; width: 90px; height: 74px; }
.fx-slash::before, .fx-slash::after, .fx-slash i {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  width: 5px; height: 86px;
  background: linear-gradient(180deg, transparent, #d82828 25% 75%, transparent);
  border-radius: 3px;
  transform: translate(-50%, -50%) rotate(38deg) scaleY(0);
  animation: fx-slash .5s var(--ease-out) .15s forwards;
}
.fx-slash::before { margin-left: -20px; animation-delay: .05s; }
.fx-slash::after  { margin-left: 20px; animation-delay: .25s; }
@keyframes fx-slash {
  0%   { transform: translate(-50%, -50%) rotate(38deg) scaleY(0); opacity: 0; }
  30%  { transform: translate(-50%, -50%) rotate(38deg) scaleY(1.1); opacity: 1; }
  75%  { opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(38deg) scaleY(1); opacity: 0; }
}

/* hearts during the cuddle demand */
.fx-heart { left: calc(58% + var(--dx, 0%)); top: 34%; font-size: 24px; opacity: 0; animation: fx-heart 1.6s var(--ease-out) var(--d, 0s) forwards; }
@keyframes fx-heart {
  0%   { opacity: 0; transform: translateY(6px) scale(.5); }
  25%  { opacity: 1; transform: translateY(-8px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-52px) scale(.9); }
}

/* Miso flees across the field, bell and all */
.fx-miso { left: 68%; top: 58%; width: 84px; animation: fx-miso 1.5s linear forwards; }
.fx-miso img { width: 100%; transform: scaleX(-1); }
.fx-miso::after { content: '💨'; position: absolute; right: -22px; top: 30%; font-size: 20px; }
@keyframes fx-miso {
  0%   { left: 68%; opacity: 0; }
  12%  { opacity: 1; }
  100% { left: -30%; opacity: 1; }
}

/* dinner goes flying during the table raid */
.fx-plate { left: 60%; top: 30%; animation: fx-plate 1.2s var(--ease-out) var(--d, 0s) forwards; opacity: 0; }
@keyframes fx-plate {
  0%   { opacity: 0; transform: translate(0, 0) rotate(0) scale(.6); }
  20%  { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--tx, -80px), var(--ty, 60px)) rotate(320deg) scale(1); }
}

/* impact shake */
.pkb-field.is-shaking { animation: pkb-shake .5s linear; }
@keyframes pkb-shake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-7px, 3px); }
  30% { transform: translate(6px, -4px); }
  45% { transform: translate(-5px, -2px); }
  60% { transform: translate(4px, 3px); }
  75% { transform: translate(-3px, 1px); }
  90% { transform: translate(2px, -1px); }
}

/* player side panics on a failed run */
.pkb-playerbox.is-fleeing { animation: pkb-flee .7s var(--ease-in-out); }
@keyframes pkb-flee {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(26px); }
  55% { transform: translateX(10px); }
  75% { transform: translateX(20px); }
}

body.reduced-motion .pkb-fx { display: none; }
body.reduced-motion .pkb-field.is-shaking,
body.reduced-motion .pkb-playerbox.is-fleeing { animation: none; }
