/* ANIU WORLD — game shell UI (owner: E1).
 * Sticker / toy-box look shared with the main site (/styles.css tokens): ink outlines, hard "pop" shadows,
 * round shapes, ZCOOL KuaiLe + Fredoka. Covers: base + layers, shared components (panel, button, key glyph,
 * focus ring), screen stack animations, loading/splash, HUD, dialogue bubbles, transitions (letterbox, fade, iris,
 * title card, skip prompt), toasts, touch controls, rotate hint, fallback screens, fatal error, and a few settings /
 * pause additions (fullscreen toggle, phone help line). The web fonts are self-hosted: @font-face in
 * assets/fonts/fonts.css (tools/fonts/subset.mjs), linked + preloaded by index.html.
 * Menu screens add their own styles in src/ui/menus.css (E2). Everything inside #ui is sized in em: #ui's font-size
 * follows the viewport (16px at 1280×720), so the whole overlay scales as one. */

/* ZCOOL KuaiLe draws U+2014 short, so a Chinese 破折号 「——」 falls apart into '— —' in display text: take the dash
 * (and the 省略号) from the system CJK face instead. Falls through to ZCOOL where none of these exist. */
@font-face {
  font-family: 'Aniu CJK Punct';
  src: local('PingFang SC Regular'), local('PingFangSC-Regular'), local('Hiragino Sans GB W3'), local('HiraginoSansGB-W3'),
    local('Microsoft YaHei'), local('MicrosoftYaHei'), local('Noto Sans SC Regular'), local('NotoSansSC-Regular'),
    local('Noto Sans CJK SC Regular'), local('NotoSansCJKsc-Regular'), local('Source Han Sans SC Regular');
  unicode-range: U+2014, U+2026;
}

:root {
  --ink: #1E1B2E;
  --ink-2: #4A4660;
  --ink-3: #7C778F;
  --ink-deep: #120F1C;
  --paper: #FFF6E6;
  --paper-2: #FFFDF8;
  --white: #fff;

  --orange: #EE7A2E;
  --horn: #6272E0;
  --visor: #A9B3F2;
  --yellow: #F5CD51;
  --purple: #8F58FB;
  --tangerine: #FCA148;
  --green: #A6CC5F;
  --sky: #73C2FD;
  --pink: #FD749E;
  --teal: #6CE4D8;
  --gold-deep: #D9A21F;

  --line-w: .19em;
  --line: var(--line-w) solid var(--ink);
  --pop: .3em .3em 0 var(--ink);
  --pop-sm: .2em .2em 0 var(--ink);
  --r: 1.6em;

  --f-display: 'Aniu CJK Punct', 'ZCOOL KuaiLe', 'Fredoka', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --f-latin: 'Fredoka', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  --f-body: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', system-ui, -apple-system, sans-serif;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);

  --spring: cubic-bezier(.3, 1.55, .5, 1);
  --swift: cubic-bezier(.6, 0, .25, 1);
}

/* ------------------------------------------------------------------ base */

* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink-deep);
  color: var(--ink);
  font-family: var(--f-body);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
html:lang(en) body { font-family: var(--f-latin); }
button { font: inherit; color: inherit; }

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

#ui {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
  font-size: clamp(11px, min(1.25vw, 2.25vh), 19px);
  line-height: 1.35;
}
/* touch screens (phones, tablets in portrait): a higher floor so reading text never sits at 11 px */
@media (pointer: coarse) { #ui { font-size: clamp(12.5px, min(1.6vw, 2.6vh), 19px); } }
#ui * { -webkit-user-drag: none; }
.ui-layer { position: absolute; inset: 0; pointer-events: none; }
.ui-layer-hud { z-index: 10; }
.ui-layer-touch { z-index: 20; }
.ui-letterbox { z-index: 30; }
.ui-layer-dialogue { z-index: 40; }
.ui-titlecard { z-index: 45; }
.ui-layer-screens { z-index: 50; }
.ui-fade { z-index: 60; }
.ui-iris { z-index: 61; }
.ui-skip { z-index: 62; }
.ui-loading { z-index: 80; }
.ui-toasts { z-index: 90; }
.ui-fps { z-index: 95; }
.ui-fatal { z-index: 99; }

/* ------------------------------------------------------------------ shared components */

.ui-panel {
  position: relative;
  background: var(--paper-2);
  border: var(--line);
  border-radius: var(--r);
  box-shadow: .42em .42em 0 var(--ink);
  padding: 1.6em 1.8em 1.7em;
  max-width: calc(100vw - 2em);
  max-height: calc(100vh - 2em);
  overflow: auto;
  pointer-events: auto;
}
.ui-title {
  margin: 0 0 .7em;
  font-family: var(--f-display);
  font-weight: 400;
  font-size: 2.1em;
  line-height: 1.1;
  text-align: center;
}
.ui-kicker {
  font-family: var(--f-latin);
  font-weight: 600;
  font-size: .8em;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-2);
  text-align: center;
  margin-bottom: .3em;
}

.ui-btn {
  --btn-bg: var(--white);
  --btn-fg: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5em;
  min-height: 2.9em;
  padding: .55em 1.5em .6em;
  border: var(--line);
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-family: var(--f-latin), var(--f-body);
  font-weight: 600;
  font-size: 1.05em;
  line-height: 1.1;
  box-shadow: .26em .26em 0 var(--ink);
  cursor: pointer;
  outline: none;
  pointer-events: auto;
  white-space: nowrap;
  transition: transform .14s ease, box-shadow .14s ease, background .2s;
}
html:lang(zh-CN) .ui-btn { font-family: var(--f-display); font-weight: 400; font-size: 1.12em; letter-spacing: .02em; }
.ui-btn--primary { --btn-bg: var(--orange); --btn-fg: var(--white); }
.ui-btn--yellow { --btn-bg: var(--yellow); }
.ui-btn--horn { --btn-bg: var(--horn); --btn-fg: var(--white); }
.ui-btn--small { min-height: 2.3em; padding: .35em 1.1em .4em; font-size: .9em; box-shadow: .2em .2em 0 var(--ink); }
.ui-btn-icon { display: inline-flex; width: 1.3em; height: 1.3em; }
.ui-btn-icon svg { width: 100%; height: 100%; }
.ui-btn:disabled { opacity: .45; cursor: default; box-shadow: .12em .12em 0 var(--ink); }
.ui-btn.is-focus:not(:disabled) { transform: translate(-.12em, -.12em); box-shadow: .4em .4em 0 var(--ink); }
.ui-btn:active:not(:disabled) { transform: translate(.18em, .18em); box-shadow: .06em .06em 0 var(--ink); }

/* focus ring for keyboard / gamepad users on E1 components (.ui-btn, [data-ring]): a horn-blue outline that
   breathes. The manager puts .is-focus on whatever [data-focus] element has focus; menu screens style their own. */
.ui-root:not([data-input="touch"]) :is(.ui-btn, [data-ring]).is-focus {
  outline: .2em solid var(--horn);
  outline-offset: .24em;
  animation: focus-breathe 1.4s ease-in-out infinite;
}
@keyframes focus-breathe { 50% { outline-offset: .38em; outline-color: var(--purple); } }
:focus:not(.is-focus) { outline: none; }

.ui-key, kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.7em;
  height: 1.7em;
  padding: 0 .45em;
  border: .14em solid var(--ink);
  border-radius: .45em;
  background: var(--paper-2);
  box-shadow: 0 .16em 0 var(--ink);
  font-family: var(--f-latin);
  font-weight: 600;
  font-size: .78em;
  line-height: 1;
  color: var(--ink);
}

/* device-specific hints: <span class="only-touch">…</span> */
.ui-root[data-input="touch"] .not-touch,
.ui-root:not([data-input="touch"]) .only-touch,
.ui-root:not([data-input="gamepad"]) .only-gamepad,
.ui-root:not([data-input="keyboard"]) .only-keyboard { display: none !important; }

/* ------------------------------------------------------------------ screen stack */

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(1em + var(--safe-t)) calc(1em + var(--safe-r)) calc(1em + var(--safe-b)) calc(1em + var(--safe-l));
  pointer-events: auto;
  transition: opacity .16s ease, visibility .16s;
}
.screen.has-backdrop { background: rgba(18, 15, 28, .52); }
@media (pointer: fine) { .screen.has-backdrop { backdrop-filter: blur(3px) saturate(.85); -webkit-backdrop-filter: blur(3px) saturate(.85); } }
.screen.is-entering { animation: screen-in .24s ease-out both; }
.screen.is-entering > * { animation: pop-in .46s var(--spring) both; }
.screen.is-leaving { animation: screen-out .19s ease-in forwards; pointer-events: none; }
.screen.is-leaving > * { animation: pop-out .19s ease-in forwards; }
.screen.is-covered { opacity: 0; visibility: hidden; pointer-events: none; }
@keyframes screen-in { from { opacity: 0; } }
@keyframes screen-out { to { opacity: 0; } }
@keyframes pop-in { from { transform: translateY(1.2em) scale(.86); opacity: 0; } 60% { opacity: 1; } }
@keyframes pop-out { to { transform: translateY(.6em) scale(.94); opacity: 0; } }

/* ------------------------------------------------------------------ loading / splash */

.ui-loading, .loading {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  background-color: var(--paper);
  background-image:
    radial-gradient(60vmax 40vmax at 85% 110%, rgba(252, 161, 72, .28), transparent 70%),
    radial-gradient(50vmax 35vmax at 0% -10%, rgba(115, 194, 253, .26), transparent 70%),
    radial-gradient(rgba(30, 27, 46, .09) 1.4px, transparent 1.6px);
  background-size: auto, auto, 22px 22px;
  color: var(--ink);
  transition: opacity .42s ease;
}
.loading.is-on { display: flex; }
.loading.is-out { opacity: 0; }
.loading-center { display: flex; flex-direction: column; align-items: center; gap: .6em; margin-top: -6vh; }
.loading-mark {
  width: 7em;
  height: 7em;
  filter: drop-shadow(.3em .3em 0 var(--ink));
  animation: mark-bob 1.6s ease-in-out infinite;
}
.loading-mark svg { width: 100%; height: 100%; display: block; }
@keyframes mark-bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-.45em) rotate(3deg); }
}
.loading-logo { display: flex; flex-direction: column; align-items: center; text-align: center; }
.loading-kicker {
  font-family: var(--f-latin);
  font-weight: 600;
  font-size: .95em;
  letter-spacing: .22em;
  color: var(--orange);
  text-transform: uppercase;
}
.loading-kicker:empty { display: none; }
.loading-name {
  font-family: var(--f-display);
  font-size: 3.4em;
  line-height: 1.05;
  letter-spacing: .04em;
  text-shadow: .06em .06em 0 var(--yellow);
}
.loading-latin {
  font-family: var(--f-latin);
  font-weight: 700;
  font-size: 1.05em;
  letter-spacing: .32em;
  color: var(--ink-2);
  margin-top: .25em;
}
.loading-bottom {
  position: absolute;
  left: 50%;
  bottom: calc(10% + var(--safe-b));
  width: min(30em, 82vw);
  transform: translateX(-50%);
}
.loading-bar {
  position: relative;
  height: 1.15em;
  border: var(--line);
  border-radius: 999px;
  background: var(--paper-2);
  box-shadow: var(--pop-sm);
}
.loading-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: calc(var(--p, 0) * 100%);
  min-width: .9em;
  border-radius: 999px;
  background: repeating-linear-gradient(-45deg, var(--orange) 0 .55em, var(--tangerine) .55em 1.1em);
  background-size: 1.556em 1.556em;
  animation: stripes .9s linear infinite;
}
@keyframes stripes { to { background-position: 1.556em 0; } }
.loading-runner {
  position: absolute;
  left: calc(var(--p, 0) * 100%);
  top: 50%;
  width: 2.5em;
  height: 2.5em;
  transform: translate(-50%, -78%);
  filter: drop-shadow(.12em .12em 0 var(--ink));
}
.loading-runner svg { width: 100%; height: 100%; display: block; animation: runner-hop .34s ease-in-out infinite alternate; }
@keyframes runner-hop { from { transform: translateY(0) rotate(-6deg); } to { transform: translateY(-.35em) rotate(6deg); } }
.loading-tip {
  margin: 1.5em 0 0;
  min-height: 2.9em;
  text-align: center;
  font-size: 1em;
  line-height: 1.45;
  color: var(--ink-2);
  transition: opacity .26s ease, transform .26s ease;
  text-wrap: balance;
}
.loading-tip.is-swap { opacity: 0; transform: translateY(.3em); }
.loading-tip-label {
  display: inline-block;
  margin-right: .6em;
  padding: .12em .65em .16em;
  border: .14em solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  font-family: var(--f-display);
  font-weight: 400;
  font-size: .85em;
  vertical-align: .08em;
}
/* level loads: dark, cinematic — the iris closes to ink and the loader appears on ink */
.loading[data-mode="level"] {
  background-color: var(--ink);
  background-image:
    radial-gradient(60vmax 40vmax at 85% 110%, rgba(238, 122, 46, .22), transparent 70%),
    radial-gradient(rgba(255, 246, 230, .07) 1.4px, transparent 1.6px);
  background-size: auto, 22px 22px;
  color: var(--paper);
}
.loading[data-mode="level"] .loading-name { text-shadow: .06em .06em 0 var(--orange); color: var(--paper); }
.loading[data-mode="level"] .loading-latin { color: var(--visor); letter-spacing: .12em; font-weight: 500; }
.loading[data-mode="level"] .loading-tip { color: rgba(255, 246, 230, .75); }
.loading[data-mode="level"] .loading-bar { border-color: var(--paper); box-shadow: .2em .2em 0 rgba(0, 0, 0, .5); background: rgba(255, 255, 255, .06); }
.loading[data-mode="level"] .loading-mark { filter: drop-shadow(.3em .3em 0 rgba(0, 0, 0, .45)); }

/* ------------------------------------------------------------------ HUD */

.ui-hud { position: absolute; inset: 0; pointer-events: none; }
.hud-tl, .hud-tc, .hud-tr {
  position: absolute;
  top: calc(1em + var(--safe-t));
  display: flex;
  flex-direction: column;
  gap: .55em;
  transition: transform .5s var(--swift), opacity .35s ease;
}
.hud-tl { left: calc(1.2em + var(--safe-l)); align-items: flex-start; }
.hud-tc { left: 50%; transform: translateX(-50%); align-items: center; }
.hud-tr { right: calc(1.2em + var(--safe-r)); align-items: flex-end; }
.ui-root.has-touch .hud-tr { right: calc(1.1em + max(44px, 3em) + .7em + var(--safe-r)); } /* clear of the pause disc */
.ui-hud.is-hidden .hud-tl, .ui-hud.is-hidden .hud-tr { transform: translateY(calc(-100% - 3em)); opacity: 0; }
.ui-hud.is-hidden .hud-tc { transform: translate(-50%, calc(-100% - 3em)); opacity: 0; }
.ui-hud.is-instant .hud-tl, .ui-hud.is-instant .hud-tc, .ui-hud.is-instant .hud-tr { transition: none; }
.hud-row { display: flex; align-items: center; gap: .9em; }

.hud-plate {
  position: relative;
  display: flex;
  align-items: center;
  gap: .3em;
  height: 2.6em;
  padding: 0 .85em 0 .6em;
  background: var(--paper-2);
  border: var(--line);
  border-radius: 999px;
  box-shadow: .22em .22em 0 var(--ink);
}

.hud-life { padding-left: 2.9em; }
.hud-portrait {
  position: absolute;
  left: -.55em;
  top: 50%;
  width: 3.35em;
  height: 3.35em;
  margin-top: -1.72em;
  border: var(--line);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #a8dcff, var(--sky) 70%);
  box-shadow: .2em .2em 0 var(--ink);
  overflow: hidden;
  rotate: -5deg;
}
.hud-portrait svg { position: absolute; left: 6%; top: 10%; width: 88%; height: 88%; }
.hud-portrait.is-hurt { animation: portrait-hurt .6s ease-out; }
@keyframes portrait-hurt {
  0% { background: var(--pink); transform: scale(1.18) rotate(-10deg); }
  20% { transform: translateX(-.2em) rotate(8deg); }
  40% { transform: translateX(.2em) rotate(-6deg); }
  60% { transform: translateX(-.1em) rotate(3deg); background: var(--pink); }
}
.hud-portrait.is-derez svg { animation: derez 1.1s steps(1) both; }
@keyframes derez {
  0% { clip-path: inset(0 0 60% 0); transform: translateX(-.25em); filter: hue-rotate(40deg); }
  15% { clip-path: inset(40% 0 0 0); transform: translateX(.25em); }
  30% { clip-path: inset(10% 0 30% 0); transform: translateX(-.1em); opacity: .6; }
  45% { clip-path: inset(0); transform: none; opacity: .25; }
  70% { opacity: .5; filter: none; }
  100% { opacity: 1; }
}

.hud-hearts { display: flex; gap: .12em; }
.hud-heart { position: relative; display: block; width: 1.72em; height: 1.6em; }
.hud-heart svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.hh-fill { fill: rgba(30, 27, 46, .16); stroke: rgba(30, 27, 46, .5); stroke-width: 2; stroke-linejoin: round; transition: fill .2s; }
.hh-shine { fill: none; stroke: transparent; stroke-width: 1.8; stroke-linecap: round; }
.hud-heart.is-full .hh-fill { fill: var(--pink); stroke: var(--ink); }
.hud-heart.is-full .hh-shine { stroke: rgba(255, 255, 255, .85); }
.hud-heart.is-ghost { position: absolute; inset: 0; pointer-events: none; }
.hud-hearts.is-low .hud-heart.is-full { animation: heartbeat 1s ease-in-out infinite; }
@keyframes heartbeat { 0%, 60%, 100% { transform: scale(1); } 15% { transform: scale(1.22); } 30% { transform: scale(.98); } 42% { transform: scale(1.12); } }

.hud-coins { padding-left: 2.15em; gap: .15em; }
.hud-coin-icon { position: absolute; left: -.5em; top: 50%; width: 2.5em; height: 2.5em; margin-top: -1.25em; filter: drop-shadow(.14em .14em 0 var(--ink)); }
.hud-coin-icon svg { width: 100%; height: 100%; display: block; }
.hud-x { font-family: var(--f-latin); font-weight: 600; font-size: 1em; color: var(--ink-3); margin-right: .05em; }
.hud-num {
  display: inline-block;
  min-width: 1.4em;
  font-family: var(--f-latin);
  font-weight: 700;
  font-size: 1.45em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
}
.hud-combo {
  position: absolute;
  left: 1.4em;
  top: calc(100% + .35em);
  padding: .12em .6em .16em;
  background: var(--yellow);
  border: .15em solid var(--ink);
  border-radius: 999px;
  box-shadow: .14em .14em 0 var(--ink);
  font-family: var(--f-latin);
  font-weight: 700;
  font-size: .78em;
  white-space: nowrap;
  rotate: -4deg;
  opacity: 0;
  transform: translateY(-.4em) scale(.7);
  transition: opacity .2s, transform .25s var(--spring);
}
html:lang(zh-CN) .hud-combo { font-family: var(--f-display); font-weight: 400; }
.hud-combo.is-on { opacity: 1; transform: none; }

.hud-shards { gap: .35em; padding: 0 .75em; }
.hud-shard { position: relative; display: block; width: 1.62em; height: 1.78em; }
.hud-shard svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.hs-body { fill: rgba(30, 27, 46, .12); stroke: rgba(30, 27, 46, .45); stroke-width: 1.8; stroke-linejoin: round; stroke-dasharray: 2.4 2.2; transition: fill .3s; }
.hs-facet { fill: none; stroke: transparent; stroke-width: 1.1; }
.hud-shard.is-filled .hs-body { fill: url(#hudShardGrad) var(--visor); stroke: var(--ink); stroke-dasharray: none; }
.hud-shard.is-filled .hs-facet { stroke: rgba(255, 255, 255, .85); }
.hs-shine {
  position: absolute;
  inset: 0;
  clip-path: polygon(50% 7%, 86% 33%, 72% 91%, 28% 91%, 14% 33%);
  background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, .95) 45%, transparent 60%) no-repeat;
  background-size: 300% 100%;
  background-position: 150% 0;
  opacity: 0;
}
.hud-shard.is-filled .hs-shine { opacity: 1; animation: shard-shine 4.5s ease-in-out infinite; }
.hud-shard.is-new { animation: shard-pop .7s var(--spring); }
.hud-shard.is-new .hs-shine { animation: shard-shine .8s ease-out, shard-shine 4.5s ease-in-out .8s infinite; }
@keyframes shard-shine { 0%, 70% { background-position: 150% 0; } 100% { background-position: -50% 0; } }
@keyframes shard-pop { 0% { transform: scale(.4) rotate(-30deg); } 60% { transform: scale(1.45) rotate(8deg); } 100% { transform: none; } }

.hud-timer { gap: .4em; padding: 0 .9em 0 .55em; }
.hud-timer[hidden] { display: none; }
/* story bookends: no hearts (no fail state) and no shard slots until the prologue's visor crack reveals them */
.hud-hearts[hidden], .hud-shards[hidden] { display: none; }
/* Yun perched on the portrait (colour arc by stage), greyed and drooping while lost */
.hud-yun { position: absolute; z-index: 2; left: 1.75em; top: -.72em; width: 1.75em; height: 1.3em; filter: drop-shadow(.1em .12em 0 var(--ink)); animation: yun-bob 2.4s ease-in-out infinite; transition: filter .4s, opacity .4s; }
.hud-yun[hidden] { display: none; }
.hud-yun svg { width: 100%; height: 100%; display: block; overflow: visible; }
.hy-body { fill: #B8BCCB; stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; transition: fill .8s; }
.hud-yun[data-stage="1"] .hy-body { fill: #D9DCF7; }
.hud-yun[data-stage="2"] .hy-body { fill: #F4F1D6; }
.hud-yun[data-stage="2"] { filter: drop-shadow(.1em .12em 0 var(--ink)) drop-shadow(0 0 .35em rgba(245, 225, 120, .8)); }
.hud-yun[data-stage="3"] .hy-body { fill: #fff; }
.hud-yun.is-lost { opacity: .6; filter: grayscale(1) drop-shadow(.1em .12em 0 rgba(30, 27, 46, .5)); animation: yun-lost .6s ease-in-out 2, yun-droop 3s ease-in-out .6s infinite; }
.hud-yun.is-lost .hy-body { fill: #9A9CA8; stroke-dasharray: 3 2.4; }
@keyframes yun-bob { 50% { transform: translateY(-.12em); } }
@keyframes yun-lost { 25% { transform: translateX(-.14em) rotate(-8deg); } 75% { transform: translateX(.14em) rotate(8deg); } }
@keyframes yun-droop { 50% { transform: translateY(.1em) rotate(-4deg); } }
/* desktop pause disc (touch layouts use the bigger one from ui/touch.js) */
.hud-pause {
  display: grid;
  place-items: center;
  width: 2.3em;
  height: 2.3em;
  padding: 0;
  border: var(--line);
  border-radius: 50%;
  background: var(--paper-2);
  box-shadow: .18em .18em 0 var(--ink);
  pointer-events: auto;
  cursor: pointer;
  opacity: .82;
  transition: opacity .15s, transform .15s;
}
.hud-pause svg { width: 58%; height: 58%; display: block; }
.hud-pause:hover { opacity: 1; transform: translate(-.06em, -.06em); }
.hud-pause:active { transform: translate(.1em, .1em); box-shadow: .06em .06em 0 var(--ink); }
.ui-root.has-touch .hud-pause { display: none; }
.hud-life.is-nohearts { padding-left: 2.35em; padding-right: .35em; }
.hud-shards.is-reboot { animation: hud-reboot .9s steps(1) both; }
@keyframes hud-reboot {
  0% { opacity: 0; } 12% { opacity: 1; filter: hue-rotate(60deg) brightness(1.6); } 24% { opacity: .2; }
  36% { opacity: 1; transform: translateX(-.15em); } 48% { opacity: .5; transform: translateX(.15em); } 60%, 100% { opacity: 1; transform: none; filter: none; }
}
/* the cracked visor pane: a jagged hairline across the plate */
.hud-shards.is-cracked::after {
  content: '';
  position: absolute;
  inset: -.15em;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 30' preserveAspectRatio='none'%3E%3Cpath d='M8 2 22 12 17 17 38 21 46 14 63 27 71 18 92 24' fill='none' stroke='%231E1B2E' stroke-width='1.6' stroke-linejoin='round' opacity='.55'/%3E%3Cpath d='M22 12 27 3M46 14 52 6M71 18 78 9' fill='none' stroke='%231E1B2E' stroke-width='1.1' opacity='.4'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
}
.hud-clock { display: block; width: 1.5em; height: 1.5em; }
.hud-clock svg { width: 100%; height: 100%; display: block; }
.hud-time { font-family: var(--f-latin); font-weight: 600; font-size: 1.25em; font-variant-numeric: tabular-nums; }

.hud-abilities { display: flex; gap: .55em; padding-left: .2em; }
.hud-ability { position: relative; width: 2.7em; height: 2.7em; }
.hud-ability[hidden] { display: none; }
.ab-disc {
  position: absolute;
  inset: 0;
  border: var(--line);
  border-radius: 50%;
  background: var(--paper-2);
  box-shadow: .18em .18em 0 var(--ink);
}
.ab-icon { position: absolute; inset: 16%; display: block; transition: filter .2s, opacity .2s, transform .2s; }
.ab-icon svg { width: 100%; height: 100%; display: block; }
.ab-ring { position: absolute; inset: -12%; width: 124%; height: 124%; rotate: -90deg; overflow: visible; }
.ab-track { fill: none; stroke: transparent; stroke-width: 3.4; }
.ab-prog { fill: none; stroke: var(--teal); stroke-width: 3.4; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: calc(100 - var(--ring, 1) * 100); }
[data-phase="ready"] .ab-prog { stroke: transparent; }
[data-phase="cooldown"] .ab-prog { stroke: var(--horn); }
[data-phase="cooldown"] .ab-track, [data-phase="active"] .ab-track { stroke: rgba(30, 27, 46, .18); }
[data-phase="cooldown"] .ab-icon { filter: grayscale(.8); opacity: .55; transform: scale(.88); }
[data-phase="active"] .ab-disc { background: #e6fffb; box-shadow: .18em .18em 0 var(--ink), 0 0 0 .25em rgba(108, 228, 216, .45); }
[data-phase="active"] .ab-icon { animation: ab-pulse .5s ease-in-out infinite alternate; }
.is-spent .ab-icon { opacity: .4; filter: grayscale(1); }
@keyframes ab-pulse { to { transform: scale(1.12); } }
.ab-key {
  position: absolute;
  right: -.55em;
  bottom: -.45em;
  min-width: 1.5em;
  height: 1.5em;
  padding: 0 .35em;
  font-size: .62em;
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  box-shadow: none;
}
.ab-key[hidden] { display: none; }

.hud-fly { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.hud-flyer { position: absolute; left: 0; top: 0; display: block; will-change: transform; filter: drop-shadow(.1em .1em 0 var(--ink)); }
.hud-flyer svg { width: 100%; height: 100%; display: block; overflow: visible; }
.hud-flyer.is-shard .hs-body { fill: url(#hudShardGrad) var(--visor); stroke: var(--ink); stroke-dasharray: none; }
.hud-flyer.is-shard .hs-facet { stroke: #fff; }
.hud-flyer.is-shard { filter: drop-shadow(0 0 .4em rgba(169, 179, 242, .95)) drop-shadow(.1em .1em 0 var(--ink)); }
.hud-spark {
  position: absolute;
  left: 50%;
  top: 50%;
  width: .7em;
  height: .7em;
  background: var(--yellow);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  pointer-events: none;
}
.hud-shard .hud-spark { background: #fff; }

/* ------------------------------------------------------------------ dialogue */

.ui-layer-dialogue { overflow: hidden; }
.dlg-catch { position: absolute; inset: 0; pointer-events: none; }
.dlg-catch.is-on { pointer-events: auto; cursor: pointer; }
.dlg-bubble {
  --tail-x: 50%;
  position: absolute;
  left: 0;
  top: 0;
  width: max-content;
  max-width: min(23em, calc(100vw - 2em));
  padding: .8em 1.15em .85em;
  background: var(--paper-2);
  border: var(--line);
  border-radius: 1.25em;
  box-shadow: .28em .28em 0 var(--ink);
  pointer-events: auto;
  cursor: pointer;
  font-size: 1.14em;
  transform-origin: var(--tail-x) 100%;
  scale: .4;
  opacity: 0;
  transition: scale .34s var(--spring), opacity .16s ease;
  will-change: transform;
}
.dlg-bubble.is-below { transform-origin: var(--tail-x) 0; }
.dlg-bubble:not(.is-anon) { padding-top: 1.05em; }
.dlg-bubble.is-in { scale: 1; opacity: 1; }
.dlg-bubble.is-out { scale: .82; opacity: 0; transition: scale .18s ease-in, opacity .18s ease-in; }
.dlg-bubble.is-lost { opacity: 0 !important; }
.dlg-name {
  position: absolute;
  left: .9em;
  top: -.95em;
  padding: .16em .85em .2em;
  background: var(--spk, var(--orange));
  color: var(--spk-ink, #fff);
  border: .16em solid var(--ink);
  border-radius: 999px;
  box-shadow: .14em .14em 0 var(--ink);
  font-family: var(--f-display);
  font-size: .8em;
  line-height: 1.25;
  white-space: nowrap;
  rotate: -3deg;
}
html:lang(en) .dlg-name { font-family: var(--f-latin); font-weight: 600; letter-spacing: .02em; }
.dlg-text {
  position: relative;
  margin: 0;
  font-family: var(--f-body);
  font-weight: 600;
  line-height: 1.5;
  color: var(--ink);
  text-wrap: pretty;
}
.dlg-text:lang(en) { font-family: var(--f-latin); font-weight: 500; line-height: 1.38; }
.dlg-rest { visibility: hidden; }
.dlg-next {
  position: absolute;
  right: .7em;
  bottom: .38em;
  width: 0;
  height: 0;
  border-left: .38em solid transparent;
  border-right: .38em solid transparent;
  border-top: .46em solid var(--orange);
  opacity: 0;
  transition: opacity .15s;
}
.dlg-bubble.is-done:not(.is-auto) .dlg-next { opacity: 1; animation: dlg-bob .75s ease-in-out infinite; }
@keyframes dlg-bob { 50% { transform: translateY(.22em); } }
.dlg-tail {
  position: absolute;
  left: var(--tail-x);
  bottom: -.66em;
  width: 1.05em;
  height: 1.05em;
  background: var(--paper-2);
  border-right: var(--line);
  border-bottom: var(--line);
  border-bottom-right-radius: .2em;
  transform: translateX(-50%) rotate(45deg) skew(10deg, 10deg);
}
.dlg-bubble.is-below .dlg-tail { bottom: auto; top: -.66em; transform: translateX(-50%) rotate(225deg) skew(10deg, 10deg); }
.dlg-bubble.is-offscreen .dlg-tail { opacity: 0; }
/* shout / whisper styles: say({ style: 'shout' | 'whisper' }) */
.dlg-bubble.is-shout { border-radius: .5em; background: #fff8d8; font-size: 1.3em; }
.dlg-bubble.is-shout .dlg-tail { background: #fff8d8; }
.dlg-bubble.is-whisper { border-style: dashed; box-shadow: none; }
/* caption (anchor: null) — narration / off-screen voices, sits low like a subtitle */
.dlg-bubble.is-caption {
  left: 50%;
  top: auto;
  bottom: calc(1.6em + var(--safe-b));
  transform: translateX(-50%);
  transform-origin: 50% 100%;
  max-width: min(34em, calc(100vw - 2em));
  background: rgba(18, 15, 28, .88);
  border-color: rgba(255, 246, 230, .9);
  box-shadow: .22em .22em 0 rgba(0, 0, 0, .45);
  text-align: center;
}
.dlg-bubble.is-caption .dlg-text { color: var(--paper); }
.dlg-bubble.is-caption .dlg-next { border-top-color: var(--yellow); }
.ui-root.is-cinematic .dlg-bubble.is-caption { bottom: calc(var(--lb-h) * .5 - 1.4em); background: transparent; border-color: transparent; box-shadow: none; }
/* portrait: the bars are tall — captions take the upper half of the bottom bar, the skip pill its lower edge */
.ui-root.is-portrait.is-cinematic .dlg-bubble.is-caption { bottom: calc(var(--lb-h) * .5 + .2em + var(--safe-b)); }
/* gag bubbles (ui.dialogue.bubble): smaller, never interactive, a quick squash-pop in */
.dlg-bubble.is-gag {
  pointer-events: none;
  cursor: default;
  max-width: min(19em, calc(100vw - 2em));
  padding: .55em .95em .6em;
  border-radius: 1.05em;
  box-shadow: .2em .2em 0 var(--ink);
  font-size: 1em;
}
.dlg-bubble.is-gag:not(.is-anon) { padding-top: .85em; }
.dlg-bubble.is-gag .dlg-name { font-size: .7em; top: -.9em; left: .75em; }
.dlg-bubble.is-gag .dlg-tail { width: .85em; height: .85em; bottom: -.55em; }
.dlg-bubble.is-gag.is-below .dlg-tail { top: -.55em; }
.dlg-bubble.is-gag.is-in { animation: gag-pop .44s var(--spring) backwards; }
@keyframes gag-pop { 0% { scale: .35 .55; opacity: 0; } 55% { scale: 1.08 .93; opacity: 1; } 80% { scale: .97 1.03; } }
/* what-if thought bubble (grey, puff trail) and HUD lines (Aniu's visor talking: ink glass, visor rim, scanlines,
   blinking caret). One definition shared by the shell and the story (ui.dialogue bubble({ style }) / say({ style })). */
.dlg-bubble.is-hud { background: rgba(18, 15, 28, .9); border-color: #A9B3F2; box-shadow: .2em .2em 0 rgba(98,114,224,.75);
  border-radius: .45em; background-image: repeating-linear-gradient(0deg, rgba(169,179,242,.08) 0 .12em, transparent .12em .3em); }
.dlg-bubble.is-hud .dlg-text { color: #C9D0FF; font-family: var(--f-latin); font-weight: 600; letter-spacing: .04em; }
.dlg-bubble.is-hud .dlg-text:lang(zh-CN) { font-family: var(--f-body); letter-spacing: .08em; }
.dlg-bubble.is-hud .dlg-tail { background: rgba(18, 15, 28, .9); border-color: #A9B3F2; }
.dlg-bubble.is-hud .dlg-name { background: #A9B3F2; color: #1E1B2E; border-color: #1E1B2E; font-family: var(--f-latin); font-weight: 700; letter-spacing: .12em; rotate: 0deg; border-radius: .3em; }
.dlg-bubble.is-hud .dlg-next { border-top-color: #A9B3F2; }
.dlg-bubble.is-hud .dlg-shown::after { content: '▍'; color: #6CE4D8; animation: st-caret .7s steps(1) infinite; margin-left: .05em; }
.dlg-bubble.is-hud.is-done .dlg-shown::after { opacity: .6; }
@keyframes st-caret { 50% { opacity: 0; } }
.dlg-bubble.is-hud.is-alert { border-color: #FD749E; box-shadow: .2em .2em 0 rgba(253,116,158,.6); }
.dlg-bubble.is-hud.is-alert .dlg-text { color: #FFC2D4; }

.dlg-bubble.is-thought { background: #E9EAF0; border-color: #6F7388; box-shadow: .2em .2em 0 rgba(111,115,136,.55); border-radius: 1.8em; }
.dlg-bubble.is-thought .dlg-text { color: #4A4660; font-weight: 500; }
.dlg-bubble.is-thought .dlg-name { background: #8C90A6; color: #fff; border-color: #6F7388; }
.dlg-bubble.is-thought .dlg-tail { width: .7em; height: .7em; border: .16em solid #6F7388; border-radius: 50%; background: #E9EAF0;
  transform: translateX(-50%); bottom: -1.05em; box-shadow: none; }
.dlg-bubble.is-thought .dlg-tail::after { content: ''; position: absolute; width: .42em; height: .42em; left: .45em; top: .75em;
  border: .14em solid #6F7388; border-radius: 50%; background: #E9EAF0; }
.dlg-bubble.is-thought.is-below .dlg-tail { top: -1.05em; bottom: auto; transform: translateX(-50%); }
.dlg-bubble.is-thought.is-hope { background: #F3F4FF; border-color: #A9B3F2; }
.dlg-bubble.is-thought.is-hope .dlg-text { color: #6272E0; }
/* signposts: a painted plank on a post */
.dlg-bubble.is-sign {
  background: repeating-linear-gradient(180deg, #EFD29B 0 1.4em, #E2BF80 1.4em 1.5em);
  border-radius: .45em;
}
.dlg-bubble.is-sign .dlg-text { color: #3B2A17; }
.dlg-bubble.is-sign .dlg-name { background: #8A6A3E; color: var(--paper); rotate: -2deg; border-radius: .3em; }
.dlg-bubble.is-sign .dlg-tail {
  width: .55em; height: .95em; bottom: -1.05em; background: #8A6A3E; border: .14em solid var(--ink); border-top: 0;
  border-radius: 0 0 .15em .15em; transform: translateX(-50%);
}
.dlg-bubble.is-sign.is-below .dlg-tail { display: none; }

/* ------------------------------------------------------------------ transitions */

.ui-letterbox {
  --lb-h: clamp(28px, max(10.5vh, calc((100vh - 100vw / 2.35) / 2)), 22vh);
  --lb-dur: .6s;
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.ui-letterbox i {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--lb-h);
  background: var(--ink-deep);
  transition: transform var(--lb-dur) var(--swift);
}
.lb-top { top: 0; transform: translateY(-101%); box-shadow: 0 .1em 0 rgba(238, 122, 46, .0); }
.lb-bottom { bottom: 0; transform: translateY(101%); }
.ui-letterbox.is-on i { transform: none; }
.ui-root.is-cinematic { --lb-h: clamp(28px, max(10.5vh, calc((100vh - 100vw / 2.35) / 2)), 22vh); }

.ui-fade, .ui-iris { position: absolute; inset: 0; display: none; pointer-events: auto; }
.ui-fade { background: var(--ink); opacity: 0; }

.ui-titlecard { position: absolute; inset: 0; pointer-events: none; }
.tc {
  position: absolute;
  left: 50%;
  top: 24%;
  transform: translateX(-50%);
  padding: 1em 3.2em 1.15em;
  text-align: center;
  white-space: nowrap;
  color: var(--paper);
  transition: opacity .5s ease, transform .6s var(--swift);
}
.tc-ribbon {
  position: absolute;
  inset: 0;
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform .55s var(--swift);
  filter: drop-shadow(.3em .3em 0 var(--orange));
}
.tc-ribbon::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--ink);
  clip-path: polygon(2.5% 10%, 100% 0, 97.5% 90%, 0 100%);
}
.tc > div { position: relative; opacity: 0; transform: translateY(.5em); transition: opacity .4s ease, transform .5s var(--spring); }
.tc-kicker { font-family: var(--f-latin); font-weight: 600; font-size: .95em; letter-spacing: .28em; color: var(--yellow); text-transform: uppercase; }
html:lang(zh-CN) .tc-kicker { font-family: var(--f-display); font-weight: 400; letter-spacing: .3em; }
.tc-title { font-family: var(--f-display); font-size: 3.6em; line-height: 1.12; letter-spacing: .04em; text-shadow: .05em .05em 0 var(--orange); }
.tc-sub { font-family: var(--f-latin); font-weight: 500; font-size: 1.05em; color: var(--visor); letter-spacing: .06em; }
.tc.is-in .tc-ribbon { transform: scaleX(1); }
.tc.is-in > div { opacity: 1; transform: none; }
.tc.is-in .tc-kicker { transition-delay: .25s; }
.tc.is-in .tc-title { transition-delay: .33s; }
.tc.is-in .tc-sub { transition-delay: .45s; }
.tc.is-out { opacity: 0; transform: translateX(calc(-50% + 2.5em)); }

/* 「长按跳过」 hold-to-skip: an ink pill in the lower letterbox bar; the ring fills while held (1 s) */
.ui-skip {
  position: absolute;
  right: calc(1.3em + var(--safe-r));
  bottom: calc(max(.8em, var(--lb-h, 3em) * .5 - 1.25em) + var(--safe-b));
  display: inline-flex;
  align-items: center;
  gap: .6em;
  padding: .3em .7em .3em .3em;
  border: .14em solid rgba(255, 246, 230, .5);
  border-radius: 999px;
  background: rgba(18, 15, 28, .72);
  color: var(--paper);
  font-family: var(--f-latin);
  font-weight: 600;
  font-size: .95em;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  opacity: 0;
  transform: translateY(.5em) scale(.94);
  transition: opacity .3s, transform .35s var(--spring), border-color .2s, background .2s;
}
html:lang(zh-CN) .ui-skip { font-family: var(--f-display); font-weight: 400; letter-spacing: .06em; }
.ui-skip.is-in { opacity: .78; transform: none; }
.ui-skip:hover { opacity: .95; }
.ui-skip.is-holding { opacity: 1; transform: scale(1.07); border-color: var(--yellow); background: rgba(18, 15, 28, .9); }
.skip-ring {
  --p: 0;
  position: relative;
  display: grid;
  place-items: center;
  width: 2.3em;
  height: 2.3em;
  border-radius: 50%;
  background: rgba(255, 246, 230, .08);
  color: var(--yellow);
}
.skip-ring::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--yellow) calc(var(--p) * 360deg), rgba(255, 246, 230, .2) 0);
  -webkit-mask: radial-gradient(closest-side, transparent 72%, #000 76%);
  mask: radial-gradient(closest-side, transparent 72%, #000 76%);
}
.skip-icon { display: block; width: 1em; height: 1em; }
.skip-icon svg { display: block; width: 100%; height: 100%; }
.skip-key {
  min-width: 1.9em;
  height: 1.75em;
  margin-left: -.1em;
  font-size: .72em;
  background: var(--paper);
  box-shadow: 0 .16em 0 var(--ink-3);
}
.skip-key[hidden] { display: none; }
.ui-skip[data-device="gamepad"] .skip-key { min-width: 1.75em; border-radius: 50%; padding: 0; background: var(--green); box-shadow: 0 .16em 0 #5E9B3E; }
.ui-skip.is-holding .skip-icon { animation: skip-throb .45s ease-in-out infinite; }
@keyframes skip-throb { 50% { transform: translateX(.12em) scale(.9); } }
.ui-skip.is-done { opacity: 0; transform: scale(1.18); transition: opacity .35s ease .08s, transform .3s var(--spring); }
.ui-skip.is-done .skip-ring::before { background: var(--yellow); }

/* unlock stamp (ui.stamp): a red seal slammed onto paper, STORY §4 "New abilities" */
.ui-stamps { position: absolute; inset: 0; z-index: 46; pointer-events: none; }
.ui-stamp {
  position: absolute;
  left: 50%;
  top: 30%;
  translate: -50% -50%;
  display: grid;
  place-items: center;
}
.stamp-seal {
  position: relative;
  display: grid;
  justify-items: center;
  gap: .15em;
  padding: .7em 1.4em .8em;
  background: #E0524A;
  color: var(--paper);
  border: .22em solid var(--paper);
  outline: .19em solid #E0524A;
  border-radius: .5em;
  box-shadow: .3em .3em 0 var(--ink);
  text-align: center;
  white-space: nowrap;
  rotate: -5deg;
  scale: 2.2;
  opacity: 0;
}
.stamp-kicker { font-family: var(--f-latin); font-weight: 700; font-size: .78em; letter-spacing: .32em; opacity: .9; }
html:lang(zh-CN) .stamp-kicker { font-family: var(--f-display); font-weight: 400; letter-spacing: .5em; margin-right: -.5em; }
.stamp-title { font-family: var(--f-display); font-weight: 400; font-size: 2.3em; line-height: 1.05; letter-spacing: .06em; }
html:lang(en) .stamp-title { font-family: var(--f-latin); font-weight: 700; font-size: 1.9em; letter-spacing: .08em; }
.stamp-sub { font-family: var(--f-display); font-size: 1em; letter-spacing: .3em; margin-right: -.3em; color: #FFE3C4; }
.stamp-ink {
  position: absolute;
  inset: -1.2em;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(224, 82, 74, .35) 0 30%, transparent 62%);
  scale: .2;
  opacity: 0;
}
.ui-stamp.is-in .stamp-seal { animation: stamp-slam .5s cubic-bezier(.55, 0, .3, 1.4) forwards; }
.ui-stamp.is-in .stamp-ink { animation: stamp-ink .7s ease-out .16s forwards; }
.ui-stamp.is-out { transition: opacity .4s ease, translate .45s var(--swift); opacity: 0; translate: -50% -80%; }
@keyframes stamp-slam {
  0% { scale: 2.2; opacity: 0; rotate: -14deg; }
  32% { scale: .9; opacity: 1; rotate: -4deg; }
  48% { scale: 1.06 .94; }
  68% { scale: .98 1.02; }
  100% { scale: 1; opacity: 1; rotate: -5deg; }
}
@keyframes stamp-ink { 0% { scale: .3; opacity: .9; } 100% { scale: 1.5; opacity: 0; } }

/* ------------------------------------------------------------------ toasts */

.ui-toasts {
  position: absolute;
  left: 50%;
  bottom: calc(1.8em + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .55em;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 2em);
}
.ui-root.has-touch .ui-toasts { bottom: calc(9.5em + var(--safe-b)); }
/* portrait + touch: the button cluster fills the lower corners — toasts sit under the HUD instead */
.ui-root.has-touch.is-portrait .ui-toasts { top: calc(8.6em + var(--safe-t)); bottom: auto; flex-direction: column-reverse; }
.ui-toast {
  display: inline-flex;
  align-items: center;
  gap: .6em;
  max-width: 100%;
  padding: .5em 1.25em .55em .6em;
  background: var(--ink);
  color: var(--white);
  border: .16em solid var(--ink);
  border-radius: 999px;
  box-shadow: .25em .25em 0 var(--orange);
  font-weight: 700;
  font-size: 1em;
  line-height: 1.25;
  opacity: 0;
  transform: translateY(1.2em) scale(.9);
  transition: opacity .3s ease, transform .4s var(--spring);
}
.ui-toast:not(:has(.ui-toast-icon)) { padding-left: 1.25em; }
html:lang(zh-CN) .ui-toast { font-family: var(--f-display); font-weight: 400; font-size: 1.08em; letter-spacing: .02em; }
.ui-toast.is-in { opacity: 1; transform: none; }
.ui-toast.is-out { opacity: 0; transform: translateY(-.8em) scale(.96); transition-duration: .3s; }
.ui-toast.is-gold { box-shadow: .25em .25em 0 var(--yellow); }
.ui-toast.is-horn { box-shadow: .25em .25em 0 var(--horn); }
.ui-toast-icon { display: block; flex: none; width: 1.6em; height: 1.6em; }
.ui-toast-icon svg { width: 100%; height: 100%; display: block; }

/* ------------------------------------------------------------------ touch controls */

.ui-touch {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.ui-touch.is-on { display: block; }
.tzone { position: absolute; left: 0; bottom: 0; width: 45%; height: 70%; pointer-events: auto; touch-action: none; }
.tstick {
  --stick-w: max(150px, 11em);
  position: absolute;
  left: calc(1.8em + var(--safe-l));
  bottom: calc(1.8em + var(--safe-b));
  width: var(--stick-w);
  height: calc(var(--stick-w) * .56);
  border: 3px solid rgba(30, 27, 46, .75);
  border-radius: 999px;
  background: rgba(255, 253, 248, .42);
  box-shadow: 4px 4px 0 rgba(30, 27, 46, .45);
  opacity: .78;
  transition: opacity .2s, transform .22s var(--swift);
}
.tstick.is-active { opacity: 1; transition: opacity .1s; }
.tstick-arrow {
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  margin-top: -9px;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  opacity: .7;
  transition: opacity .12s, transform .12s;
}
.tstick-arrow.is-l { left: 13%; border-right: 13px solid var(--ink); }
.tstick-arrow.is-r { right: 13%; border-left: 13px solid var(--ink); }
.tstick.is-left .is-l, .tstick.is-right .is-r { opacity: 1; transform: scale(1.3); }
.tstick.is-left .is-l { border-right-color: var(--orange); }
.tstick.is-right .is-r { border-left-color: var(--orange); }
.tstick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--stick-w) * .38);
  height: calc(var(--stick-w) * .38);
  transform: translate(-50%, -50%);
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, var(--paper) 60%, #f1e2c6);
  box-shadow: 3px 3px 0 var(--ink);
}
.tstick:not(.is-active) .tstick-knob { transition: transform .18s var(--spring); }

.tbtns {
  position: absolute;
  right: calc(1.5em + var(--safe-r));
  bottom: calc(2em + var(--safe-b));
  width: max(196px, 15em);
  height: max(176px, 13.4em);
  pointer-events: none;
}
.tbtn {
  --size: max(64px, 4.9em);
  --bg: var(--horn);
  position: absolute;
  width: var(--size);
  height: var(--size);
  padding: 0;
  border: 0;
  background: none;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
}
.tbtn[hidden] { display: none; }
.tbtn-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform .07s ease, box-shadow .07s ease;
}
.tbtn-face > svg:not(.ab-ring) { width: 58%; height: 58%; }
.tbtn-face .ab-ring { inset: -9%; width: 118%; height: 118%; position: absolute; }
.tbtn-label {
  position: absolute;
  left: 50%;
  top: calc(100% + 3px);
  transform: translateX(-50%);
  font-family: var(--f-display);
  font-weight: 400;
  font-size: max(11px, .85em);
  color: var(--paper);
  text-shadow: 0 1px 0 var(--ink), 1px 0 0 var(--ink), -1px 0 0 var(--ink), 0 -1px 0 var(--ink), 1.5px 1.5px 0 var(--ink);
  white-space: nowrap;
  pointer-events: none;
}
html:lang(en) .tbtn-label { font-family: var(--f-latin); font-weight: 600; }
.tbtn.is-down .tbtn-face { transform: translate(3px, 3px) scale(.95); box-shadow: 1px 1px 0 var(--ink); filter: brightness(1.08); }
.tbtn-jump { --size: max(86px, 6.6em); --bg: var(--orange); right: 0; bottom: .9em; }
.tbtn-dash { --bg: var(--horn); right: calc(max(86px, 6.6em) + 1.1em); bottom: .5em; }
.tbtn-decode { --bg: var(--teal); right: calc(max(86px, 6.6em) * .22); bottom: calc(max(86px, 6.6em) + 2.6em); }
.tbtn-dash .tbtn-face > svg:not(.ab-ring) path:first-child { fill: #fff; }
.tbtn[data-phase="cooldown"] .tbtn-face { filter: saturate(.35) brightness(.92); }
.tbtn.is-spent .tbtn-face { filter: saturate(.2) brightness(.85); }
.tbtn[data-phase="active"] .tbtn-face { box-shadow: 4px 4px 0 var(--ink), 0 0 0 6px rgba(108, 228, 216, .5); }
.tbtn .ab-prog { stroke: var(--paper); }
.tbtn[data-phase="active"] .ab-prog { stroke: #fff; }

.tpause {
  position: absolute;
  top: calc(.95em + var(--safe-t));
  right: calc(1.1em + var(--safe-r));
  width: max(44px, 3em);
  height: max(44px, 3em);
  padding: 0;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--paper-2);
  box-shadow: 3px 3px 0 var(--ink);
  pointer-events: auto;
  cursor: pointer;
}
.tpause svg { width: 54%; height: 54%; }
.tpause:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

/* portrait hint (ui/touch.js): a compact tap-to-dismiss pill just above the controls — clear of the jump / decode
   buttons and the key-hint pill (.st-prompt, 16 % up); .is-top = the toast column under the HUD, when Aniu stands in
   the bottom slot. Its own font-size stays 1em so the offsets match .tbtns / .ui-toasts; .is-yield = stepped aside
   (a line is up, or Aniu / a bubble / a toast is in its way). */
.ui-rotate {
  position: absolute;
  left: 50%;
  bottom: calc(max(2em + max(176px, 13.4em), 16% + 3.6em) + .7em + var(--safe-b));
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: .6em;
  width: max-content;
  max-width: calc(100% - 2em - var(--safe-l) - var(--safe-r));
  padding: .35em .4em .35em .55em;
  background: var(--paper-2);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 3px 3px 0 var(--ink);
  text-align: left;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  animation: pop-in .45s var(--spring) both;
  transition: opacity .2s ease, visibility 0s linear 0s;
}
.ui-rotate[hidden] { display: none; }
.ui-rotate.is-top { bottom: auto; top: calc(8.6em + var(--safe-t)); }
.ui-rotate.is-yield { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .2s ease, visibility 0s linear .2s; }
.ui-rotate:active { translate: calc(-50% + 2px) 2px; box-shadow: 1px 1px 0 var(--ink); }
.ui-rotate-icon { flex: none; width: max(32px, 2.6em); height: max(32px, 2.6em); animation: rotate-hint 2.4s ease-in-out infinite; }
.ui-rotate-icon svg, .ui-rotate-x svg { width: 100%; height: 100%; display: block; }
@keyframes rotate-hint { 0%, 30% { transform: rotate(0); } 55%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
.ui-rotate-text { min-width: 0; line-height: 1.2; text-wrap: balance; }
.ui-rotate-title { display: block; font-family: var(--f-display); font-weight: 400; font-size: max(14px, 1.2em); }
.ui-rotate-sub { display: block; color: var(--ink-2); font-size: max(11px, .9em); margin-top: .1em; }
.ui-rotate-x { flex: none; width: max(26px, 2.1em); height: max(26px, 2.1em); padding: .38em; border: 2px solid var(--ink); border-radius: 50%; background: var(--paper); box-sizing: border-box; }

/* phones: tighter HUD spacing, larger reading text */
@media (max-height: 500px), (max-width: 560px) {
  .hud-tl, .hud-tc, .hud-tr { top: calc(.7em + var(--safe-t)); }
  .hud-tl { left: calc(1em + var(--safe-l)); }
  .dlg-bubble { font-size: 1.3em; max-width: min(21em, calc(100vw - 2em)); }
  .dlg-bubble.is-gag { font-size: 1.15em; max-width: min(18em, calc(100vw - 2em)); } /* the gag rule would otherwise win */
  .dlg-bubble.is-gag .dlg-name { font-size: .78em; }
  .ui-skip { font-size: 1.05em; }
}
.ui-root.is-portrait .ui-skip { bottom: calc(.9em + var(--safe-b)); }
/* on touch the ability buttons carry the cooldown rings — no duplicate HUD discs */
.ui-root.has-touch .hud-abilities { display: none; }
.ui-root.is-portrait .hud-tc { top: calc(4.6em + var(--safe-t)); }
.ui-root.is-portrait .tc { top: 38%; }
.ui-root.is-portrait .tc-title { font-size: 2.6em; }
@media (max-height: 500px) {
  .tc { top: 16%; font-size: .78em; }
}
/* latin names read better in Fredoka than in ZCOOL's latin glyphs */
html:lang(en) :is(.tc-title, .loading-name, .ui-title, .ui-rotate-title) { font-family: var(--f-latin); font-weight: 700; letter-spacing: .01em; }

/* ------------------------------------------------------------------ fallback screens (before ui/menus.js exists) */

.screen-title:has(> .fb-title) { background: linear-gradient(90deg, rgba(255, 246, 230, .75), rgba(255, 246, 230, 0) 60%); place-items: center start; padding-left: calc(6vw + var(--safe-l)); }
.fb-title { display: flex; flex-direction: column; align-items: center; text-align: center; gap: .5em; }
.fb-title-mark { width: 8.5em; height: 8.5em; filter: drop-shadow(.35em .35em 0 var(--ink)); animation: mark-bob 2s ease-in-out infinite; }
.fb-title-mark svg { width: 100%; height: 100%; display: block; }
.fb-title-logo { margin: 0; display: flex; flex-direction: column; align-items: center; font-weight: 400; }
.fb-title-logo span { font-family: var(--f-display); font-size: 4.6em; line-height: 1; letter-spacing: .04em; text-shadow: .05em .05em 0 var(--yellow), .09em .09em 0 var(--ink); }
.fb-title-logo small { font-family: var(--f-latin); font-weight: 700; font-size: 1.2em; letter-spacing: .35em; color: var(--ink-2); margin-top: .35em; }
.fb-title-tag { font-family: var(--f-display); font-size: 1.3em; color: var(--orange); margin: 0; }
.fb-title-actions { display: flex; gap: .9em; flex-wrap: wrap; justify-content: center; margin-top: 1em; }
.fb-title-press { margin: .8em 0 0; font-family: var(--f-latin); font-weight: 600; color: var(--ink-2); animation: press-blink 1.6s ease-in-out infinite; }
@keyframes press-blink { 50% { opacity: .35; } }
.fb-title-legal { position: absolute; left: 50%; bottom: calc(1em + var(--safe-b)); transform: translateX(-50%); width: min(44em, 92vw); margin: 0; font-size: .78em; color: var(--ink-2); text-align: center; }
.fb-panel { width: min(24em, calc(100vw - 2em)); text-align: center; }
.fb-wide { width: min(40em, calc(100vw - 2em)); }
.fb-stack { display: flex; flex-direction: column; gap: .8em; align-items: stretch; }
.fb-row-actions { display: flex; gap: .8em; justify-content: center; margin-top: 1.2em; }
.fb-rows { margin: 0 0 1.3em; display: flex; flex-direction: column; gap: .35em; }
.fb-row { display: flex; justify-content: space-between; padding: .45em .2em; border-bottom: .12em dashed rgba(30, 27, 46, .2); font-size: 1.05em; }
.fb-row b { font-family: var(--f-latin); font-variant-numeric: tabular-nums; }
.fb-medal {
  display: inline-block;
  margin: -.2em 0 1em;
  padding: .3em 1.2em .35em;
  border: var(--line);
  border-radius: 999px;
  box-shadow: var(--pop-sm);
  font-family: var(--f-display);
  font-size: 1.2em;
  background: #e7b36a;
}
.fb-medal[data-medal="gold"] { background: var(--yellow); }
.fb-medal[data-medal="silver"] { background: #dfe3ee; }
.fb-levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(10em, 1fr)); gap: .9em; margin-bottom: 1.3em; }
.fb-level { flex-direction: column; min-height: 5.4em; border-radius: 1.1em; gap: .15em; white-space: normal; }
.fb-level small { font-size: .7em; color: var(--ink-3); font-family: var(--f-latin); letter-spacing: .08em; }
.fb-level em { font-style: normal; font-size: .7em; color: var(--orange); min-height: 1em; }
.fb-body { margin: 0 0 1em; font-size: 1.05em; }
.fb-legal { margin: 0 0 1.4em; font-size: .85em; color: var(--ink-2); line-height: 1.5; }

/* ------------------------------------------------------------------ misc: fps meter, fatal error */

.ui-fps {
  position: absolute;
  left: calc(.6em + var(--safe-l));
  bottom: calc(.5em + var(--safe-b));
  padding: .15em .5em;
  border-radius: .4em;
  background: rgba(18, 15, 28, .7);
  color: #bdf5c9;
  font: 600 11px/1.3 ui-monospace, Menlo, monospace;
  white-space: pre;
}
.ui-fatal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1em;
  background: rgba(18, 15, 28, .9);
  pointer-events: auto;
}
.ui-fatal .ui-panel { width: min(26em, 100%); text-align: center; }
.ui-fatal p { margin: 0 0 1.2em; color: var(--ink-2); }
.ui-fatal pre { max-height: 8em; overflow: auto; text-align: left; font-size: .7em; background: var(--paper); padding: .6em; border-radius: .5em; white-space: pre-wrap; margin: 0 0 1.2em; user-select: text; }

/* ------------------------------------------------------------------ menu additions from the shell (fullscreen, phone help)
 * Settings / pause markup is ui/screens/settings.js + pause.js; these few rules ride on menus.css's px-based look. */

/* fullscreen toggle: a pill in the settings header, a round button in the pause title row (ui.fullscreen) */
.mn-panel__head .mn-fs { margin-left: auto; gap: 7px; padding-left: 10px; }
.mn-panel__head .mn-fs + .mn-btn { margin-left: 0; }
.mn-panel__head .mn-fs .mn-btn__label { font-family: var(--f-display); font-weight: 400; font-size: 1.1em; letter-spacing: .01em; color: inherit; } /* not the head's small caps span */
.mn[data-lang="en"] .mn-panel__head .mn-fs .mn-btn__label { font-family: var(--f-latin); font-weight: 600; font-size: 1em; }
.mn-fs .mn-ico { font-size: 22px; }
.mn-fs.is-on { background: var(--visor); }
.mn-pause__title .mn-pause__fs { margin-left: auto; align-self: center; flex: none; }
.mn-pause__title .mn-pause__fs .mn-ico { font-size: 24px; }

/* phones hide the settings footer's help line (menus.css): the rows that need explaining (quality, hints, assist,
 * fullscreen) speak up under the toggles instead, once touched */
.mn-settings__tip { display: none; }
.mn-settings__tip, .mn-settings__help, .mn-controls__note { text-wrap: pretty; } /* no lone 「行！」 on the last line */
@media (max-width: 640px), (max-height: 520px) {
  .mn-settings__tip:not(:empty) {
    display: block;
    margin: 2px 0 0;
    padding: 9px 12px;
    border: 2px dashed var(--ink-3);
    border-radius: 14px;
    background: rgba(255, 255, 255, .55);
    color: var(--ink-2);
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.45;
  }
  .mn-panel__head .mn-fs { min-height: 38px; padding: 5px 12px 5px 8px; font-size: 14px; }
}
/* landscape phones: the half-width toggle tiles broke 「辅助模 / 式」 and "Screen / shake" over two lines — one per row */
@media (max-height: 520px) {
  .mn-settings .mn-settings__grid { grid-template-columns: 1fr; } /* .mn-settings: menus.css loads after this file */
  .mn-settings .mn-settings__grid .mn-toggle__txt { display: block; }
}
/* the header row never gives way: the close circle keeps its size and the small subtitle stays on one line */
.mn-panel__head > h2, .mn-panel__head > span, .mn-panel__head > .mn-btn { flex: none; white-space: nowrap; }
/* portrait phones too narrow for the worded pill fold it to the icon alone, a circle like the close button (aria-label +
 * title keep its name). The whole header row needs 358 px of screen with 「退出全屏」 but 407 px with "Exit fullscreen"
 * (measured), hence the wider English breakpoint: 384 / 393 / 412 px Androids, where fullscreen is on after Start */
@media (max-width: 380px) {
  .mn-panel__head .mn-fs .mn-btn__label { display: none; }
  .mn-panel__head .mn-fs { width: 44px; height: 44px; min-height: 44px; padding: 0; justify-content: center; }
}
@media (max-width: 440px) {
  .mn[data-lang="en"] .mn-panel__head .mn-fs .mn-btn__label { display: none; }
  .mn[data-lang="en"] .mn-panel__head .mn-fs { width: 44px; height: 44px; min-height: 44px; padding: 0; justify-content: center; }
}

/* ------------------------------------------------------------------ reduced motion */

@media (prefers-reduced-motion: reduce) {
  #ui *, #ui *::before, #ui *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .05s !important;
    transition-delay: 0s !important;
  }
}
