@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=IBM+Plex+Mono:wght@500;600;700&family=Manrope:wght@500;700;800&family=Press+Start+2P&display=swap');

:root {
  --night: #07120f;
  --ink: #f2f0df;
  --muted: #b9b08e;
  --grass: #54c46e;
  --moss: #20583b;
  --ember: #f26a3d;
  --gold: #efc35c;
  --aqua: #58dfcf;
  --danger: #f34e55;
  --panel: rgba(8, 18, 16, 0.72);
  --panel-solid: rgba(8, 18, 16, 0.92);
  --border: rgba(239, 195, 92, 0.3);
  --font-body: 'Manrope', system-ui, sans-serif;
  --font-display: 'DM Serif Display', serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --font-pixel: 'Press Start 2P', monospace;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--night);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

button,
a {
  font: inherit;
}

#app {
  position: relative;
  isolation: isolate;
}

#gameCanvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: var(--night);
  touch-action: none;
}

.moon-haze,
.pixel-grain,
.lightning-flash,
.damage-flash,
.shield-flash,
.shield-screen-overlay,
.labels-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.moon-haze {
  --moon-haze-x: 72%;
  --moon-haze-y: 16%;
  z-index: 1;
  opacity: 0;
  background:
    radial-gradient(circle at var(--moon-haze-x) var(--moon-haze-y), rgba(242, 240, 223, 0.28), transparent 11%),
    radial-gradient(circle at var(--moon-haze-x) var(--moon-haze-y), rgba(84, 196, 110, 0.12), transparent 35%);
  mix-blend-mode: screen;
  transition: background 2s ease, opacity 1.5s ease;
}

body.final-wave-active .moon-haze {
  background:
    radial-gradient(circle at 30% 20%, rgba(90, 40, 180, 0.35), transparent 30%),
    radial-gradient(circle at 72% 75%, rgba(40, 20, 140, 0.22), transparent 38%);
  opacity: 1;
}

/* ── Space background: wave 10 starfield ── */

#starfield {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: screen;
  background-image:
    radial-gradient(1px 1px at 20% 15%, rgba(255, 255, 255, 0.60), transparent),
    radial-gradient(1px 1px at 75% 35%, rgba(255, 255, 255, 0.50), transparent),
    radial-gradient(1.5px 1.5px at 42% 70%, rgba(255, 255, 255, 0.75), transparent),
    radial-gradient(2px 2px at 88% 82%, rgba(220, 235, 255, 0.85), transparent),
    radial-gradient(1px 1px at 10% 60%, rgba(255, 255, 255, 0.45), transparent),
    radial-gradient(1.5px 1.5px at 55% 25%, rgba(255, 245, 210, 0.70), transparent),
    radial-gradient(1px 1px at 65% 90%, rgba(255, 255, 255, 0.40), transparent),
    radial-gradient(2px 2px at 30% 45%, rgba(255, 255, 255, 0.80), transparent),
    radial-gradient(1px 1px at 95% 50%, rgba(255, 255, 255, 0.55), transparent),
    radial-gradient(1.5px 1.5px at 5% 90%, rgba(210, 220, 255, 0.65), transparent);
  background-size: 320px 260px;
  background-position: 0 0;
  transition: opacity 1.5s ease;
}

body.final-wave-active #starfield {
  opacity: 1;
  animation: starfield-scroll 22s linear infinite;
}

body.final-wave-active {
  background: #020409;
  transition: background 1.5s ease;
}

@keyframes starfield-scroll {
  from { background-position: 0 0; }
  to   { background-position: 0 -260px; }
}

.pixel-grain {
  z-index: 5;
  opacity: 0.14;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 4px 4px;
  mask-image: radial-gradient(circle, black 48%, transparent 87%);
}

.lightning-flash {
  z-index: 4;
  opacity: 0;
  background:
    radial-gradient(circle at 48% 18%, rgba(255, 255, 255, 0.72), transparent 17%),
    linear-gradient(180deg, rgba(183, 220, 255, 0.5), rgba(255, 255, 255, 0.16) 48%, transparent 82%);
  mix-blend-mode: screen;
  transition: opacity 80ms ease-out;
}

.damage-flash {
  z-index: 9;
  opacity: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.62), rgba(243, 78, 85, 0.46) 44%, transparent 72%);
  transition: opacity 150ms ease;
}

.damage-flash.show {
  opacity: 1;
}

.shield-flash {
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  background: radial-gradient(circle, rgba(255, 34, 0, 0.28) 20%, transparent 80%);
}

.shield-flash.show {
  opacity: 1;
  animation: shield-flash-anim 0.45s ease-out forwards;
}

.shield-screen-overlay {
  z-index: 3;
  opacity: 0;
  background-color: rgba(255, 34, 0, 0.08); /* Translucent red field extends to screen */
}

.flash-oct {
  fill: none;
  stroke: #ff2200;
  stroke-width: 2.2;
  filter: drop-shadow(0 0 8px rgba(255, 34, 0, 0.85));
  transform-origin: 50% 50%;
}

.flash-outer {
  animation: oct-pulse-out 0.45s ease-out forwards;
}

.flash-middle {
  animation: oct-pulse-mid 0.45s ease-out forwards;
}

.flash-inner {
  animation: oct-pulse-in 0.45s ease-out forwards;
}

@keyframes shield-flash-anim {
  0% { opacity: 0.95; }
  100% { opacity: 0; }
}

@keyframes oct-pulse-out {
  0% { transform: scale(0.5); stroke-width: 4.5; }
  100% { transform: scale(1.15); stroke-width: 0.5; }
}

@keyframes oct-pulse-mid {
  0% { transform: scale(0.4); stroke-width: 4.5; }
  100% { transform: scale(1.08); stroke-width: 0.5; }
}

@keyframes oct-pulse-in {
  0% { transform: scale(0.3); stroke-width: 4.5; }
  100% { transform: scale(1.0); stroke-width: 0.5; }
}

.labels-layer {
  z-index: 7;
  overflow: hidden;
}

.game-bar {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  z-index: 12;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background:
    linear-gradient(135deg, rgba(14, 32, 24, 0.86), rgba(4, 12, 15, 0.66)),
    repeating-linear-gradient(90deg, transparent 0 18px, rgba(239, 195, 92, 0.08) 18px 19px);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.38), inset 0 -1px 0 rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(14px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

body.is-running:not(.is-paused) .game-bar {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
}

.corner-controls {
  position: fixed;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 14px;
  z-index: 12;
  display: grid;
  grid-template-columns: repeat(2, 44px);
  gap: 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(239, 195, 92, 0.26);
  border-radius: 8px;
  background: rgba(239, 195, 92, 0.08);
}

.brand-mark img {
  display: block;
  width: 32px;
  height: auto;
  filter: drop-shadow(0 0 12px rgba(84, 196, 110, 0.5));
}

.game-title {
  min-width: 0;
}

.game-title span,
.readout span,
.typing-strip span,
.message-panel p {
  display: block;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.game-title h1 {
  overflow: hidden;
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(1.42rem, 2.8vw, 2rem);
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.1;
  text-overflow: ellipsis;
  text-shadow: 0 0 18px rgba(88, 223, 207, 0.34);
  white-space: nowrap;
}


.icon-button,
.message-panel > button {
  min-height: 44px;
  border: 1px solid rgba(239, 195, 92, 0.38);
  border-radius: 8px;
  background: rgba(239, 195, 92, 0.1);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  transition: transform 160ms ease, border-color 160ms ease, filter 160ms ease;
}

.icon-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  min-width: 44px;
  font-family: var(--font-mono);
  font-size: 0.94rem;
}

.svg-button {
  overflow: hidden;
  padding: 0;
  background:
    radial-gradient(circle at 32% 26%, rgba(88, 223, 207, 0.18), transparent 34%),
    rgba(239, 195, 92, 0.1);
}

.button-svg {
  width: 34px;
  height: 34px;
  overflow: visible;
}

.button-ring {
  fill: rgba(7, 18, 15, 0.52);
  stroke: rgba(239, 195, 92, 0.42);
  stroke-width: 2;
  transform-origin: 24px 24px;
  transition: fill 180ms ease, stroke 180ms ease, transform 180ms ease;
}

.svg-button:not(:disabled):hover .button-ring {
  fill: rgba(88, 223, 207, 0.13);
  stroke: rgba(88, 223, 207, 0.82);
  transform: scale(1.04);
}

.play-glyph,
.pause-glyph rect,
.speaker-glyph {
  fill: currentColor;
  transform-origin: 24px 24px;
  transition: opacity 170ms ease, transform 210ms cubic-bezier(0.2, 0.9, 0.2, 1), fill 170ms ease;
}

.transport-button .pause-glyph {
  opacity: 0;
  transform: scaleX(0.72);
  transform-origin: 24px 24px;
  transition: opacity 170ms ease, transform 210ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

.transport-button .play-glyph {
  opacity: 1;
  transform: translateX(1px) scale(1);
}

.transport-button.is-playing .pause-glyph {
  opacity: 1;
  transform: scaleX(1);
}

.transport-button.is-playing .play-glyph {
  opacity: 0;
  transform: translateX(5px) scale(0.62);
}

.sound-wave,
.mute-slash,
.fullscreen-enter-glyph path,
.fullscreen-exit-glyph path {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound-wave {
  stroke-width: 2.4;
  transform-origin: 26px 24px;
}

.sound-wave-one {
  animation: sound-wave-pulse 950ms ease-in-out infinite;
}

.sound-wave-two {
  animation: sound-wave-pulse 950ms ease-in-out 130ms infinite;
}

.mute-slash {
  opacity: 0;
  stroke: var(--danger);
  stroke-width: 3.2;
  stroke-dasharray: 29;
  stroke-dashoffset: 29;
  filter: drop-shadow(0 0 5px rgba(243, 78, 85, 0.5));
  transition: opacity 170ms ease, stroke-dashoffset 210ms ease;
}

.battery-saver-toggle .leaf-path {
  stroke: var(--ink);
  transition: stroke 170ms ease;
}

.battery-saver-toggle .leaf-stem {
  stroke: var(--muted);
  transition: stroke 170ms ease;
}

.battery-saver-toggle .saver-slash {
  opacity: 1;
  stroke: var(--danger);
  stroke-width: 3.2;
  stroke-dasharray: 29;
  stroke-dashoffset: 0;
  filter: drop-shadow(0 0 5px rgba(243, 78, 85, 0.5));
  transition: opacity 170ms ease, stroke-dashoffset 210ms ease;
}

.battery-saver-toggle.is-active .leaf-path {
  stroke: var(--grass);
}

.battery-saver-toggle.is-active .leaf-stem {
  stroke: var(--grass);
}

.battery-saver-toggle.is-active .saver-slash {
  opacity: 0;
  stroke-dashoffset: 29;
}

.fullscreen-enter-glyph path,
.fullscreen-exit-glyph path {
  stroke-width: 2.8;
  transition: opacity 170ms ease, transform 210ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

.fullscreen-enter-glyph {
  opacity: 1;
  transform-origin: 24px 24px;
  transition: opacity 170ms ease, transform 210ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

.fullscreen-exit-glyph {
  opacity: 0;
  transform: scale(0.72);
  transform-origin: 24px 24px;
  transition: opacity 170ms ease, transform 210ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

.fullscreen-toggle.is-fullscreen .fullscreen-enter-glyph {
  opacity: 0;
  transform: scale(1.18);
}

.fullscreen-toggle.is-fullscreen .fullscreen-exit-glyph {
  opacity: 1;
  transform: scale(1);
}

.icon-button:not(:disabled):hover,
.message-panel > button:hover {
  border-color: rgba(88, 223, 207, 0.74);
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.icon-button:disabled {
  cursor: default;
  opacity: 0.36;
}

.icon-button.is-muted {
  color: var(--muted);
}

.icon-button.is-muted .sound-wave {
  opacity: 0.2;
  animation-play-state: paused;
  transform: translateX(-2px) scaleX(0.62);
}

.icon-button.is-muted .mute-slash {
  opacity: 1;
  stroke-dashoffset: 0;
}

.hud-grid {
  position: fixed;
  top: calc(max(14px, env(safe-area-inset-top)) + 82px);
  left: 14px;
  z-index: 11;
  display: grid;
  width: min(238px, calc(100vw - 28px));
  gap: 8px;
  pointer-events: none;
  transition: top 0.35s ease;
}

body.is-running:not(.is-paused) .hud-grid {
  top: max(14px, env(safe-area-inset-top));
}

.readout {
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto;
  align-items: baseline;
  gap: 10px;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid rgba(88, 223, 207, 0.22);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: inset 0 0 18px rgba(88, 223, 207, 0.06);
  backdrop-filter: blur(10px);
}

.readout strong {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  text-align: right;
  white-space: nowrap;
}

.life-readout {
  grid-template-columns: auto minmax(122px, auto);
}

.life-meter {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  min-width: 122px;
  min-height: 24px;
}

.life-heart {
  display: block;
  width: 22px;
  height: 22px;
  transform-origin: center;
}

.life-heart svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 0 8px rgba(243, 78, 85, 0.28));
}

.life-heart .heart-shell {
  fill: rgba(242, 240, 223, 0.1);
  stroke: rgba(242, 240, 223, 0.56);
  stroke-width: 1.5;
}

.life-heart .heart-fill {
  fill: var(--danger);
  stroke: rgba(255, 232, 190, 0.86);
  stroke-width: 1;
  transition: clip-path 260ms cubic-bezier(0.2, 0.9, 0.2, 1), filter 160ms ease;
}

.life-heart.is-full .heart-fill {
  clip-path: inset(0 0 0 0);
}

.life-heart.is-half .heart-fill {
  clip-path: inset(0 50% 0 0);
}

.life-heart.is-empty .heart-fill {
  clip-path: inset(0 100% 0 0);
  filter: saturate(0.4);
}

.life-heart.is-hit {
  animation: heart-hit 420ms ease;
}

.life-heart.is-hit .heart-shell {
  animation: heart-shell-flash 420ms ease;
}

.typing-strip {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 12;
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: min(680px, calc(100vw - 28px));
  min-height: 58px;
  padding: 10px 14px;
  border: 1px solid rgba(239, 195, 92, 0.42);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(8, 18, 16, 0.86), rgba(33, 15, 15, 0.78));
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.4), inset 0 0 24px rgba(242, 106, 61, 0.08);
  transform: translateX(-50%);
  backdrop-filter: blur(14px);
}

.typing-strip strong {
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: clamp(1rem, 3vw, 1.28rem);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.1;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.typing-strip small {
  color: var(--aqua);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.typing-strip.mistake {
  border-color: rgba(243, 78, 85, 0.82);
  animation: shake 190ms linear;
}

.message-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 14;
  display: grid;
  width: min(460px, calc(100vw - 36px));
  gap: 14px;
  padding: 24px;
  border: 1px solid rgba(239, 195, 92, 0.4);
  border-radius: 10px;
  background:
    linear-gradient(135deg, rgba(10, 28, 20, 0.94), rgba(9, 11, 15, 0.9)),
    repeating-linear-gradient(0deg, transparent 0 22px, rgba(84, 196, 110, 0.08) 22px 23px);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.52), inset 0 0 30px rgba(88, 223, 207, 0.07);
  transform: translate(-50%, -50%);
  backdrop-filter: blur(18px);
}

.message-panel[hidden] {
  display: none;
}

.message-panel h2 {
  margin: 0;
  color: var(--gold);
  font-family: var(--font-pixel);
  font-size: clamp(1.35rem, 6.8vw, 2.7rem);
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.42;
  text-shadow:
    2px 0 0 #000,
    -2px 0 0 #000,
    0 2px 0 #000,
    0 -2px 0 #000,
    2px 2px 0 rgba(0, 0, 0, 0.82),
    -2px 2px 0 rgba(0, 0, 0, 0.82),
    2px -2px 0 rgba(0, 0, 0, 0.82),
    -2px -2px 0 rgba(0, 0, 0, 0.82),
    0 0 18px rgba(239, 195, 92, 0.42);
  text-transform: uppercase;
  text-wrap: balance;
}

.message-panel .message-copy {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.45;
  text-transform: none;
  white-space: pre-line;
}

.message-panel.is-cleared .message-copy {
  font-size: 0.84rem;
  line-height: 1.7;
}

.message-score {
  color: var(--aqua);
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 700;
}

.message-panel > button {
  width: 100%;
  padding: 0 18px;
  background: linear-gradient(135deg, rgba(242, 106, 61, 0.92), rgba(239, 195, 92, 0.92));
  color: #1a120b;
}

.support-link {
  justify-self: center;
  color: rgba(242, 240, 223, 0.58);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-decoration: none;
  text-transform: uppercase;
  text-shadow: 0 0 8px rgba(239, 195, 92, 0.08);
  transform-origin: center;
  animation: support-link-breathe 2.8s ease-in-out infinite;
  transition: color 160ms ease, opacity 160ms ease, text-shadow 160ms ease;
}

.support-link:hover,
.support-link:focus-visible {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(239, 195, 92, 0.44);
  animation-play-state: paused;
}

@keyframes support-link-breathe {
  0%,
  100% {
    opacity: 0.58;
    transform: scale(1);
    text-shadow: 0 0 8px rgba(239, 195, 92, 0.08);
  }

  50% {
    opacity: 1;
    transform: scale(1.045);
    text-shadow: 0 0 16px rgba(239, 195, 92, 0.36);
  }
}

.word-tag {
  position: absolute;
  display: grid;
  min-width: 104px;
  max-width: 210px;
  gap: 3px;
  padding: 7px 9px 8px;
  border: 1px solid rgba(242, 240, 223, 0.38);
  border-radius: 7px;
  background: rgba(4, 9, 10, 0.74);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.38), inset 0 0 18px rgba(88, 223, 207, 0.06);
  color: var(--ink);
  font-family: var(--font-mono);
  line-height: 1;
  text-align: center;
  text-shadow: 0 1px 0 #000;
  transform: translate(-50%, -100%);
  transform-origin: center bottom;
  transition: border-color 100ms ease, background 100ms ease, box-shadow 100ms ease, filter 100ms ease, opacity 100ms ease;
}

.word-tag .prompt-kind {
  justify-self: center;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(88, 223, 207, 0.12);
  color: var(--aqua);
  font-size: 0.54rem;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.1;
  text-transform: uppercase;
}

.word-tag .definition {
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: normal;
}

.word-tag .prompt {
  font-size: clamp(0.82rem, 2vw, 1.05rem);
  font-weight: 700;
  overflow-wrap: break-word;
}

.word-tag .typed {
  color: var(--aqua);
}

.word-tag .remaining {
  color: var(--ink);
}

.word-tag .given-tok {
  color: rgba(242, 240, 223, 0.35);
}

.word-tag .given-sup {
  color: rgba(242, 240, 223, 0.28);
}

.word-tag .threat-meter {
  display: block;
  width: 100%;
  height: 3px;
  margin-top: 2px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(242, 240, 223, 0.12);
}

.word-tag .threat-meter i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--aqua), var(--gold));
  transform: scaleX(var(--threat-progress, 0));
  transform-origin: left;
  transition: transform 120ms linear, background 120ms ease;
}

.word-tag::after {
  position: absolute;
  left: 50%;
  bottom: -18px;
  width: 1px;
  height: 18px;
  background: linear-gradient(rgba(242, 240, 223, 0.6), rgba(242, 240, 223, 0));
  content: '';
  transform: translateX(-50%);
}

.word-tag.is-target {
  border-color: rgba(88, 223, 207, 0.9);
  background: rgba(7, 24, 25, 0.9);
  box-shadow: 0 0 0 1px rgba(88, 223, 207, 0.42), 0 0 28px rgba(88, 223, 207, 0.34), inset 0 0 22px rgba(88, 223, 207, 0.1);
  filter: brightness(1.1);
}

.word-tag.is-target .prompt-kind {
  background: rgba(88, 223, 207, 0.2);
  color: #d7fffa;
}

.word-tag.is-target::after {
  bottom: -24px;
  height: 24px;
  background: linear-gradient(rgba(88, 223, 207, 0.92), rgba(88, 223, 207, 0));
  box-shadow: 0 0 12px rgba(88, 223, 207, 0.46);
}

.word-tag.is-warning {
  border-color: rgba(239, 195, 92, 0.68);
}

.word-tag.is-warning .threat-meter i {
  background: linear-gradient(90deg, var(--gold), var(--ember));
}

.word-tag.is-danger {
  border-color: rgba(243, 78, 85, 0.86);
  background: rgba(29, 8, 10, 0.88);
}

.word-tag.is-danger .threat-meter i,
.word-tag.is-critical .threat-meter i {
  background: linear-gradient(90deg, var(--ember), var(--danger));
}

.word-tag.is-critical {
  animation: critical-pulse 520ms ease-in-out infinite;
}

.word-tag.is-hidden {
  opacity: 0;
}

.word-tag.is-revealing {
  animation: label-pop 280ms ease-out;
}

.word-tag.is-medic {
  border-color: rgba(255, 143, 179, 0.8);
  background:
    linear-gradient(135deg, rgba(58, 7, 24, 0.92), rgba(4, 14, 14, 0.86)),
    linear-gradient(90deg, rgba(255, 49, 95, 0.22), transparent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.36), 0 0 24px rgba(255, 49, 95, 0.3), inset 0 0 18px rgba(242, 240, 223, 0.08);
}

.word-tag.is-medic .prompt-kind {
  background: rgba(255, 49, 95, 0.24);
  color: #ffe1ea;
}

.word-tag.is-medic .threat-meter i {
  background: linear-gradient(90deg, #ff8fb3, #ff315f);
}

.word-tag.is-mimic {
  border-color: rgba(217, 70, 239, 0.8);
  background:
    linear-gradient(135deg, rgba(32, 5, 36, 0.92), rgba(4, 14, 14, 0.86)),
    linear-gradient(90deg, rgba(217, 70, 239, 0.22), transparent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.36), 0 0 24px rgba(217, 70, 239, 0.3), inset 0 0 18px rgba(242, 240, 223, 0.08);
}

.word-tag.is-mimic .prompt-kind {
  background: rgba(217, 70, 239, 0.24);
  color: #fdf5ff;
}

.word-tag.is-mimic .threat-meter i {
  background: linear-gradient(90deg, #f472b6, #d946ef);
}

.word-tag.is-stunned {
  border-color: rgba(56, 189, 248, 0.8) !important;
  background: linear-gradient(135deg, rgba(8, 24, 36, 0.94), rgba(4, 14, 14, 0.9)) !important;
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.4), inset 0 0 18px rgba(56, 189, 248, 0.15) !important;
  filter: brightness(1.1);
}

.word-tag.is-stunned .threat-meter i {
  background: linear-gradient(90deg, #38bdf8, #bae6fd) !important;
}

.word-tag.is-boss {
  min-width: 160px;
  max-width: 300px;
  gap: 6px;
  padding: 10px 13px 11px;
  border-color: color-mix(in srgb, var(--boss-accent, var(--danger)) 62%, transparent);
  background:
    linear-gradient(135deg, rgba(22, 4, 4, 0.9), rgba(4, 9, 10, 0.88)),
    linear-gradient(90deg, color-mix(in srgb, var(--boss-accent, var(--danger)) 20%, transparent), transparent);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.48), inset 0 0 18px color-mix(in srgb, var(--boss-accent, var(--danger)) 16%, transparent);
}

.word-tag.is-boss .prompt-kind {
  background: color-mix(in srgb, var(--boss-accent, var(--danger)) 18%, transparent);
  color: color-mix(in srgb, var(--boss-glow, var(--gold)) 82%, white 18%);
}

.word-tag.is-boss .definition {
  font-size: 0.8rem;
}

.word-tag.is-boss .prompt {
  font-size: clamp(1rem, 2.5vw, 1.3rem);
}

.word-tag.is-boss.is-target {
  border-color: color-mix(in srgb, var(--boss-accent, var(--danger)) 90%, white 10%);
  background:
    linear-gradient(135deg, rgba(36, 6, 6, 0.94), rgba(5, 18, 19, 0.9)),
    linear-gradient(90deg, color-mix(in srgb, var(--boss-accent, var(--danger)) 28%, transparent), transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--boss-accent, var(--danger)) 48%, transparent), 0 0 32px color-mix(in srgb, var(--boss-glow, var(--gold)) 32%, transparent), inset 0 0 24px color-mix(in srgb, var(--boss-accent, var(--danger)) 18%, transparent);
}

.word-tag.is-boss.is-danger {
  border-color: color-mix(in srgb, var(--boss-accent, var(--danger)) 82%, white 18%);
}

.word-tag[data-kind="equation"] .definition,
.word-tag[data-kind="equation"] .prompt-kind {
  color: #ffe39a;
}

.word-tag[data-kind="equation"] .definition {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.word-tag[data-kind="equation"] .prompt-kind {
  background: rgba(239, 195, 92, 0.18);
}

#comboValue.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.score-popup {
  position: fixed;
  z-index: 20;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 800;
  letter-spacing: 0;
  pointer-events: none;
  text-shadow: 0 0 12px rgba(239, 195, 92, 0.72);
  transform: translate(-50%, -100%);
  animation: score-float 820ms ease-out forwards;
  white-space: nowrap;
}

@keyframes score-float {
  0% {
    opacity: 1;
    transform: translate(-50%, -100%);
  }

  70% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, calc(-100% - 48px));
  }
}

.run-glossary {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid rgba(88, 223, 207, 0.18);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.24);
}

.run-glossary[hidden] {
  display: none;
}

.glossary-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  gap: 6px 10px;
  padding: 6px 10px;
  border-bottom: 1px solid rgba(242, 240, 223, 0.06);
  align-items: baseline;
}

.glossary-item:last-child {
  border-bottom: none;
}

.glossary-item.is-defeated .gl-term {
  color: var(--aqua);
}

.glossary-item.is-leaked .gl-term {
  color: var(--ember);
}

.gl-term {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: none;
}

.gl-def {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.35;
}

.glossary-item.is-equation {
  grid-template-columns: minmax(0, 1fr);
  gap: 3px;
}

.glossary-item.is-equation .gl-term {
  font-family: var(--font-mono);
  font-size: 0.7rem;
}

.keyboard-input {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: 1px;
  height: 1px;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.score-popup.is-heal {
  color: #b9ffcf;
  text-shadow: 0 0 14px rgba(45, 212, 191, 0.58);
}

.score-popup.is-missed-heal {
  color: #ff8fb3;
  text-shadow: 0 0 14px rgba(255, 49, 95, 0.52);
}

.score-popup.is-loot-reward {
  color: #fdf5ff;
  text-shadow: 0 0 14px rgba(217, 70, 239, 0.8), 0 0 24px rgba(217, 70, 239, 0.4);
}

.score-popup.is-inventory-full {
  color: #f87171;
  text-shadow: 0 0 14px rgba(239, 68, 68, 0.8);
}

.score-popup.is-loot-escaped {
  color: #94a3b8;
  text-shadow: 0 0 14px rgba(148, 163, 184, 0.5);
}

.boss-banner {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 16;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-family: var(--font-pixel);
  font-size: clamp(1.0rem, 3.5vw, 2.0rem);
  font-weight: 400;
  color: var(--danger);
  text-align: center;
  text-shadow:
    2px 0 0 #000,
    -2px 0 0 #000,
    0 2px 0 #000,
    0 -2px 0 #000,
    2px 2px 0 rgba(0, 0, 0, 0.8),
    -2px 2px 0 rgba(0, 0, 0, 0.8),
    2px -2px 0 rgba(0, 0, 0, 0.8),
    -2px -2px 0 rgba(0, 0, 0, 0.8),
    0 0 18px rgba(243, 78, 85, 0.5);
  letter-spacing: 0.04em;
  line-height: 1.6;
  opacity: 0;
  white-space: nowrap;
}

.boss-banner.is-medic-hint {
  color: #ff8fb3;
  text-shadow:
    2px 0 0 #000,
    -2px 0 0 #000,
    0 2px 0 #000,
    0 -2px 0 #000,
    2px 2px 0 rgba(0, 0, 0, 0.8),
    -2px 2px 0 rgba(0, 0, 0, 0.8),
    2px -2px 0 rgba(0, 0, 0, 0.8),
    -2px -2px 0 rgba(0, 0, 0, 0.8),
    0 0 18px rgba(255, 49, 95, 0.45);
}

.boss-banner.is-mimic-hint {
  color: #d946ef;
  text-shadow:
    2px 0 0 #000,
    -2px 0 0 #000,
    0 2px 0 #000,
    0 -2px 0 #000,
    2px 2px 0 rgba(0, 0, 0, 0.8),
    -2px 2px 0 rgba(0, 0, 0, 0.8),
    2px -2px 0 rgba(0, 0, 0, 0.8),
    -2px -2px 0 rgba(0, 0, 0, 0.8),
    0 0 18px rgba(217, 70, 239, 0.45);
}


.boss-banner.is-active {
  animation: boss-banner-flash 2.2s ease-out forwards;
}

@keyframes boss-banner-flash {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.7);
  }

  10% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }

  20% {
    transform: translate(-50%, -50%) scale(0.97);
  }

  30% {
    transform: translate(-50%, -50%) scale(1.02);
  }

  40% {
    transform: translate(-50%, -50%) scale(1.0);
  }

  75% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.0);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.0);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(-50%);
  }

  25% {
    transform: translateX(calc(-50% - 8px));
  }

  75% {
    transform: translateX(calc(-50% + 8px));
  }
}

@keyframes label-pop {
  0% {
    opacity: 0;
    filter: brightness(1.8);
  }

  45% {
    opacity: 1;
    filter: brightness(1.35);
  }

  100% {
    opacity: 1;
    filter: brightness(1);
  }
}

@keyframes critical-pulse {
  0%,
  100% {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.38), inset 0 0 18px rgba(88, 223, 207, 0.06);
  }

  50% {
    box-shadow: 0 0 0 1px rgba(243, 78, 85, 0.56), 0 0 28px rgba(243, 78, 85, 0.34), inset 0 0 22px rgba(243, 78, 85, 0.12);
  }
}

@keyframes heart-hit {
  0% {
    transform: scale(1);
  }

  28% {
    transform: scale(1.26) rotate(-8deg);
    filter: brightness(1.5);
  }

  58% {
    transform: scale(0.86) rotate(5deg);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes heart-shell-flash {
  0%,
  100% {
    stroke: rgba(242, 240, 223, 0.56);
  }

  35% {
    stroke: rgba(255, 232, 190, 0.98);
  }
}

@keyframes sound-wave-pulse {
  0%,
  100% {
    opacity: 0.58;
    transform: scaleX(0.82);
  }

  50% {
    opacity: 1;
    transform: scaleX(1.06);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sound-wave {
    animation: none;
  }

  .button-ring,
  .play-glyph,
  .pause-glyph,
  .pause-glyph rect,
  .speaker-glyph,
  .mute-slash {
    transition: none;
  }
}

@media (max-width: 760px) {
  .game-bar {
    gap: 10px;
    min-height: 58px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .brand-mark img {
    width: 29px;
  }

  .corner-controls {
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + 80px);
  }

  .hud-grid {
    top: calc(max(14px, env(safe-area-inset-top)) + 72px);
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: calc(100vw - 28px);
  }

  .readout {
    min-height: 38px;
  }

  .life-readout {
    grid-template-columns: minmax(0, 1fr);
    gap: 5px;
  }

  .life-meter {
    justify-content: flex-start;
    min-width: 0;
  }

  .life-heart {
    width: 19px;
    height: 19px;
  }

  .typing-strip {
    grid-template-columns: 1fr;
    gap: 4px;
    min-height: 72px;
    text-align: center;
  }

  .typing-strip small {
    justify-self: center;
  }

  .message-panel {
    padding: 20px;
  }

}

@media (pointer: coarse) {
  .icon-button,
  .message-panel > button {
    min-height: 48px;
  }
}

/* — God Mode — */

.god-mode-veil {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(circle, transparent 52%, rgba(255, 196, 0, 0.08) 100%);
  opacity: 0;
  transition: opacity 1.4s ease;
}

body.is-god-mode .god-mode-veil {
  opacity: 1;
}

.god-mode-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid rgba(255, 200, 50, 0.44);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(28, 20, 4, 0.92), rgba(18, 14, 2, 0.88));
  box-shadow: 0 0 16px rgba(255, 196, 0, 0.08), inset 0 0 12px rgba(255, 196, 0, 0.05);
  backdrop-filter: blur(10px);
  color: #ffd060;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-shadow: 0 0 10px rgba(255, 196, 0, 0.72);
  animation:
    godMode-appear 0.52s cubic-bezier(0.2, 0.9, 0.2, 1) both,
    godMode-pulse 2.8s ease-in-out 0.52s infinite;
}

@keyframes godMode-appear {
  from {
    opacity: 0;
    transform: scaleY(0.5);
    letter-spacing: 0.32em;
  }
  to {
    opacity: 1;
    transform: scaleY(1);
    letter-spacing: 0.14em;
  }
}

@keyframes godMode-pulse {
  0%, 100% {
    border-color: rgba(255, 200, 50, 0.38);
    box-shadow: 0 0 12px rgba(255, 196, 0, 0.06), inset 0 0 10px rgba(255, 196, 0, 0.03);
  }
  50% {
    border-color: rgba(255, 200, 50, 0.78);
    box-shadow: 0 0 30px rgba(255, 196, 0, 0.26), inset 0 0 18px rgba(255, 196, 0, 0.11);
  }
}

body.is-god-mode .life-heart svg {
  filter: drop-shadow(0 0 8px rgba(255, 196, 0, 0.58));
}

body.is-god-mode .life-heart .heart-fill {
  fill: #ffd060;
  stroke: rgba(255, 240, 150, 0.86);
}

body.is-god-mode .life-heart .heart-shell {
  stroke: rgba(255, 220, 80, 0.52);
}

body.is-god-mode .damage-flash.show {
  background: radial-gradient(circle, rgba(255, 255, 200, 0.58), rgba(255, 200, 50, 0.3) 44%, transparent 72%);
}

/* Potion Bar & Slots UI */
.potion-bar {
  position: fixed;
  bottom: max(18px, env(safe-area-inset-bottom));
  right: max(18px, env(safe-area-inset-right));
  z-index: 11;
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(2, 44px);
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: auto;
}

body:not(.is-running) .potion-bar {
  opacity: 0.5;
  pointer-events: none;
}

.potion-slot {
  position: relative;
  width: 44px;
  height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.potion-slot[data-slot="1"] {
  grid-column: 2;
  grid-row: 1;
}
.potion-slot[data-slot="0"] {
  grid-column: 1;
  grid-row: 2;
}
.potion-slot[data-slot="3"] {
  grid-column: 2;
  grid-row: 2;
}
.potion-slot[data-slot="2"] {
  grid-column: 3;
  grid-row: 2;
}

.potion-slot.occupied {
  border: 1px solid var(--gold);
  background: rgba(239, 195, 92, 0.08);
  box-shadow: 0 0 12px rgba(239, 195, 92, 0.15);
  cursor: pointer;
}

.potion-slot.occupied:hover {
  transform: scale(1.08);
  border-color: var(--ink);
  box-shadow: 0 0 16px rgba(239, 195, 92, 0.3);
}

.slot-key {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--muted);
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.potion-slot.occupied .slot-key {
  color: var(--gold);
  opacity: 1;
}

.potion-icon {
  width: 32px;
  height: 32px;
  position: relative;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

/* Magic SVG Icons */
.svg-magic {
  width: 32px;
  height: 32px;
  display: block;
}

/* Time Freeze (Stopwatch) Animation */
.magic-time .clock-rim {
  fill: rgba(88, 223, 207, 0.12);
  stroke: #58dfcf;
  stroke-width: 2.5;
  filter: drop-shadow(0 0 3px rgba(88, 223, 207, 0.8));
  animation: pulse-clock 2s ease-in-out infinite alternate;
}
.magic-time .clock-top {
  fill: none;
  stroke: #e7ffff;
  stroke-width: 2.5;
  stroke-linecap: round;
}
.magic-time .clock-hand {
  stroke: #e7ffff;
  stroke-width: 2.5;
  stroke-linecap: round;
  transform-origin: 22px 22px;
}
.magic-time .hour-hand {
  animation: rotate-hand 8s linear infinite;
}
.magic-time .minute-hand {
  animation: rotate-hand 1.5s linear infinite;
}
.magic-time .clock-center {
  fill: #58dfcf;
}

@keyframes rotate-hand {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@keyframes pulse-clock {
  0% { opacity: 0.6; filter: drop-shadow(0 0 2px rgba(88, 223, 207, 0.4)); }
  100% { opacity: 1; filter: drop-shadow(0 0 6px rgba(88, 223, 207, 0.9)); }
}

/* Chain Lightning Animation */
.magic-lightning .bolt-path {
  fill: #efc35c;
  stroke: #bf55ec;
  stroke-width: 1.5;
  filter: drop-shadow(0 0 4px rgba(191, 85, 236, 0.8));
  animation: lightning-flicker 1.8s ease-in-out infinite;
}
.magic-lightning .spark {
  fill: #fff;
  filter: drop-shadow(0 0 3px #efc35c);
  animation: spark-pulse 1s ease-in-out infinite alternate;
  transform-origin: center;
}
.magic-lightning .spark-2 {
  animation-delay: 0.5s;
}

@keyframes lightning-flicker {
  0%, 100% { opacity: 0.8; filter: drop-shadow(0 0 2px rgba(191, 85, 236, 0.6)); }
  5% { opacity: 0.3; }
  10% { opacity: 1; filter: drop-shadow(0 0 8px rgba(191, 85, 236, 0.9)); }
  15% { opacity: 0.6; }
  25% { opacity: 1; }
  50% { opacity: 0.8; }
}
@keyframes spark-pulse {
  0% { transform: scale(0.6); opacity: 0.4; }
  100% { transform: scale(1.3); opacity: 1; }
}

/* Shockwave Animation */
.magic-shockwave .shockwave-crest {
  stroke: #0088ff;
  stroke-width: 2.5;
  stroke-linecap: round;
  fill: none;
  opacity: 0.45;
  filter: drop-shadow(0 0 1.5px rgba(0, 136, 255, 0.4));
  animation: shockwave-wifi-glow 1.2s infinite;
}
.magic-shockwave .shockwave-crest-1 {
  animation-delay: 0s;
}
.magic-shockwave .shockwave-crest-2 {
  animation-delay: 0.2s;
}
.magic-shockwave .shockwave-crest-3 {
  animation-delay: 0.4s;
}

@keyframes shockwave-wifi-glow {
  0%, 10% {
    opacity: 0.45;
    filter: drop-shadow(0 0 1.5px rgba(0, 136, 255, 0.4));
  }
  20%, 45% {
    opacity: 1;
    filter: drop-shadow(0 0 6px rgba(0, 136, 255, 0.9));
  }
  55%, 100% {
    opacity: 0.45;
    filter: drop-shadow(0 0 1.5px rgba(0, 136, 255, 0.4));
  }
}

/* Shield (A.T. Field Octagon) SVG Icon Styles */
.magic-shield .shield-oct {
  fill: rgba(255, 34, 0, 0.08);
  stroke: #ff2200;
  stroke-width: 2.2;
  filter: drop-shadow(0 0 3px rgba(255, 34, 0, 0.8));
  transform-origin: 22px 22px;
  animation: shield-breath-icon 2.5s ease-in-out infinite;
}
.magic-shield .shield-outer {
}
.magic-shield .shield-middle {
  fill: none;
}
.magic-shield .shield-inner {
  fill: rgba(255, 34, 0, 0.18);
}

@keyframes shield-breath-icon {
  0%, 100% {
    opacity: 0.55;
    filter: drop-shadow(0 0 2px rgba(255, 34, 0, 0.6));
    transform: scale(0.97);
  }
  50% {
    opacity: 1.0;
    filter: drop-shadow(0 0 6px rgba(255, 34, 0, 1.0));
    transform: scale(1.03);
  }
}

body.chain-lightning-primed .typing-strip {
  border-color: rgba(239, 195, 92, 0.88);
  box-shadow:
    0 18px 52px rgba(0, 0, 0, 0.4),
    inset 0 0 24px rgba(242, 106, 61, 0.08),
    0 0 24px rgba(191, 85, 236, 0.22);
}

@keyframes potion-shake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-4px, 0); }
  75% { transform: translate(4px, 0); }
}
.potion-bar.full-shake {
  animation: potion-shake 0.2s ease-in-out 2;
  border-color: var(--danger);
}

@keyframes flash-active {
  0% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.2); filter: brightness(2) drop-shadow(0 0 15px currentColor); }
  100% { transform: scale(1); filter: brightness(1); }
}
.potion-slot.activating {
  animation: flash-active 0.3s ease-out;
}

@keyframes flash-blocked {
  0% { transform: scale(1); filter: brightness(1); }
  25% { transform: scale(1.1) translateX(-4px); filter: brightness(1.5) drop-shadow(0 0 10px rgba(255, 60, 60, 0.8)); color: rgba(255, 60, 60, 1); }
  50% { transform: scale(1.1) translateX(4px); filter: brightness(1.5) drop-shadow(0 0 10px rgba(255, 60, 60, 0.8)); color: rgba(255, 60, 60, 1); }
  75% { transform: scale(1.1) translateX(-2px); filter: brightness(1.5) drop-shadow(0 0 10px rgba(255, 60, 60, 0.8)); color: rgba(255, 60, 60, 1); }
  100% { transform: scale(1); filter: brightness(1); }
}
.potion-slot.blocked-active {
  animation: flash-blocked 0.3s ease-in-out;
}

.boss-banner.is-final-wave {
  font-size: clamp(2.4rem, 8vw, 5.2rem);
  color: #ff2200;
  text-shadow:
    3px 0 0 #000,
    -3px 0 0 #000,
    0 3px 0 #000,
    0 -3px 0 #000,
    0 0 24px rgba(255, 80, 0, 0.95),
    0 0 48px rgba(255, 40, 0, 0.75),
    0 0 72px rgba(255, 10, 0, 0.45);
}

.boss-banner.is-final-wave.is-active {
  animation: final-wave-banner 3.4s ease-out forwards;
}

.boss-banner.is-boss-kill {
  font-size: clamp(1.8rem, 5.5vw, 4.2rem);
  color: #ff2200;
  text-shadow:
    3px 0 0 #000,
    -3px 0 0 #000,
    0 3px 0 #000,
    0 -3px 0 #000,
    0 0 28px rgba(255, 0, 0, 0.95),
    0 0 54px rgba(255, 0, 0, 0.75);
}

.boss-banner.is-boss-kill.is-active {
  animation: boss-kill-banner 2.5s ease-out forwards;
}

@keyframes boss-kill-banner {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2.5);
  }
  8% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.85);
  }
  14% {
    transform: translate(-50%, -50%) scale(1.05);
  }
  20% {
    transform: translate(-50%, -50%) scale(0.98);
  }
  25% {
    transform: translate(-50%, -50%) scale(1.0);
  }
  /* shake */
  27% { transform: translate(calc(-50% + 12px), -50%) scale(1.0); }
  30% { transform: translate(calc(-50% - 12px), -50%) scale(1.0); }
  33% { transform: translate(calc(-50% + 8px), -50%) scale(1.0); }
  36% { transform: translate(calc(-50% - 8px), -50%) scale(1.0); }
  39% { transform: translate(calc(-50% + 4px), -50%) scale(1.0); }
  42% { transform: translate(-50%, -50%) scale(1.0); }
  
  80% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
}

@keyframes final-wave-banner {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2.2);
  }

  7% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.88);
  }

  13% {
    transform: translate(-50%, -50%) scale(1.06);
  }

  20% {
    transform: translate(-50%, -50%) scale(0.97);
  }

  27% {
    transform: translate(-50%, -50%) scale(1.01);
  }

  32% {
    transform: translate(-50%, -50%) scale(1.0);
  }

  /* shake */
  34% { transform: translate(calc(-50% + 8px), -50%) scale(1.0); }
  36% { transform: translate(calc(-50% - 8px), -50%) scale(1.0); }
  38% { transform: translate(calc(-50% + 5px), -50%) scale(1.0); }
  40% { transform: translate(calc(-50% - 5px), -50%) scale(1.0); }
  42% { transform: translate(calc(-50% + 2px), -50%) scale(1.0); }
  44% { transform: translate(-50%, -50%) scale(1.0); }

  72% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.0);
  }

  88% {
    opacity: 0.9;
    transform: translate(-50%, -50%) scale(1.04);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.0);
  }
}

.boss-banner.is-time-freeze {
  color: var(--aqua);
  text-shadow:
    2px 0 0 #000,
    -2px 0 0 #000,
    0 2px 0 #000,
    0 -2px 0 #000,
    0 0 18px rgba(88, 223, 207, 0.7);
}

.boss-banner.is-shockwave {
  color: #0088ff;
  text-shadow:
    2px 0 0 #000,
    -2px 0 0 #000,
    0 2px 0 #000,
    0 -2px 0 #000,
    0 0 18px rgba(0, 136, 255, 0.8),
    0 0 30px rgba(0, 136, 255, 0.4);
}

.boss-banner.is-chain-lightning {
  color: #f5de7a;
  text-shadow:
    2px 0 0 #000,
    -2px 0 0 #000,
    0 2px 0 #000,
    0 -2px 0 #000,
    0 0 18px rgba(191, 85, 236, 0.72),
    0 0 30px rgba(239, 195, 92, 0.5);
}

/* Time Freeze visual filter on canvas */
body.time-frozen #gameCanvas {
  filter: saturate(0.2) contrast(1.1) brightness(0.9) sepia(0.2) hue-rotate(180deg);
  transition: filter 0.4s ease;
}
body:not(.time-frozen) #gameCanvas {
  transition: filter 0.4s ease;
}

/* === Magic Acquired Burst overlay === */
.magic-acquired-burst {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 200;
  animation: mab-enter 1.9s ease-out forwards;
}
.mab-line1 {
  font-family: var(--font-mono, monospace);
  font-size: 1.1rem;
  letter-spacing: 0.2em;
  color: #f5d5ff;
  text-shadow: 0 0 12px #d946ef, 0 0 26px #a21caf;
}
.mab-line2 {
  font-family: var(--font-mono, monospace);
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #d946ef;
  text-shadow:
    0 0 10px #d946ef,
    0 0 30px #a21caf,
    0 0 56px rgba(217, 70, 239, 0.55);
}
@keyframes mab-enter {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  18%  { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  32%  { transform: translate(-50%, -50%) scale(1.0); }
  70%  { opacity: 1; transform: translate(-50%, -62%); }
  100% { opacity: 0; transform: translate(-50%, -80%); }
}

/* ── End-game scene ── */

.game-ending {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #02030a;
  pointer-events: none;
}

.game-ending[hidden] {
  display: none;
}

.ending-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

/* Star Wars Victory Cinematic styles */
.ending-intro-text {
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, 82vw);
  font-family: var(--font-pixel);
  font-size: clamp(1.1rem, 2vw, 1.6rem);
  color: #6dd8ff;
  text-align: center;
  line-height: 1.85;
  text-shadow:
    0 0 14px rgba(109, 216, 255, 0.75),
    0 0 38px rgba(109, 216, 255, 0.25);
  opacity: 0;
  z-index: 7;
  pointer-events: none;
  letter-spacing: 0.02em;
}

.game-ending.phase-nebula .ending-intro-text {
  animation: intro-fade-in-out 3.5s ease-in-out forwards;
}

@keyframes intro-fade-in-out {
  0% { opacity: 0; filter: blur(4px); }
  15% { opacity: 1; filter: blur(0); }
  85% { opacity: 1; filter: blur(0); }
  100% { opacity: 0; filter: blur(4px); }
}

.ending-logo {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1.6);
  font-family: var(--font-pixel);
  font-size: clamp(2.5rem, 7.5vw, 5.5rem);
  color: #ffe18a;
  text-align: center;
  text-shadow:
    0 0 28px rgba(255, 225, 138, 0.95),
    0 0 72px rgba(255, 200, 80, 0.50),
    0 0 140px rgba(100, 160, 255, 0.30);
  font-weight: 700;
  letter-spacing: 0.05em;
  opacity: 0;
  z-index: 7;
  pointer-events: none;
}

.game-ending.phase-title-fly .ending-logo {
  animation: logo-fly-away 4s cubic-bezier(0.12, 0.65, 0.3, 1) forwards;
}

@keyframes logo-fly-away {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.8);
    filter: blur(12px) brightness(2.0);
  }
  12% {
    opacity: 1;
    filter: blur(0) brightness(1.4);
  }
  50% {
    opacity: 1;
    filter: blur(0) brightness(1.0);
  }
  88% {
    opacity: 0.85;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.04);
    filter: blur(3px) brightness(2.5);
  }
}

.ending-crawl-container {
  position: absolute;
  width: min(920px, 90vw);
  height: 65vh;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  perspective: 300px;
  perspective-origin: 50% 25%;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, transparent 0%, #000 18%, #000 80%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 18%, #000 80%, transparent 100%);
  z-index: 6;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
}

.game-ending.phase-crawl .ending-crawl-container {
  opacity: 1;
}

.ending-crawl-content {
  position: absolute;
  top: 100%;
  width: 100%;
  font-family: var(--font-pixel);
  font-size: clamp(1.2rem, 2.2vw, 1.7rem);
  line-height: 2.1;
  color: #ffe18a;
  text-align: center;
  transform-origin: 50% 100%;
  transform: rotateX(25deg) translateZ(0);
}

.game-ending.phase-crawl .ending-crawl-content {
  animation: crawl-animation 24s linear forwards;
}

.ending-crawl-content p {
  margin: 0 0 1.8rem 0;
  text-shadow:
    0 0 4px rgba(255, 225, 138, 0.35);
}

.ending-crawl-content .crawl-episode {
  text-align: center;
  font-family: var(--font-pixel);
  font-weight: 700;
  color: #b8d4ff;
  letter-spacing: 0.16em;
  margin-bottom: 0.8rem;
  font-size: clamp(1.3rem, 2.4vw, 1.85rem);
  text-shadow: 0 0 12px rgba(160, 200, 255, 0.6);
}

.ending-crawl-content .crawl-title {
  text-align: center;
  font-family: var(--font-pixel);
  font-size: clamp(1.6rem, 3.2vw, 2.6rem);
  color: #fff;
  margin-top: 0;
  margin-bottom: 2.4rem;
  letter-spacing: 0.05em;
  text-shadow:
    0 0 14px rgba(255, 255, 255, 0.88),
    0 0 38px rgba(160, 200, 255, 0.42);
}

@keyframes crawl-animation {
  0% {
    top: 100%;
    transform: rotateX(25deg) translateY(0);
  }
  100% {
    top: -190%;
    transform: rotateX(25deg) translateY(0);
  }
}


.game-ending:not([hidden]) {
  pointer-events: auto;
}

.ending-flash {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 50%, #ffffff 0%, #fff8d7 32%, rgba(255, 255, 255, 0.85) 58%, transparent 76%);
  opacity: 0;
  pointer-events: none;
  z-index: 6;
  mix-blend-mode: screen;
}

.game-ending.phase-flash .ending-flash {
  animation: ending-flash-in 1.15s ease-out forwards;
}

@keyframes ending-flash-in {
  0%   { opacity: 0; }
  18%  { opacity: 1; }
  38%  { opacity: 0.94; }
  100% { opacity: 0; }
}

.ending-starfield {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 54%, rgba(255, 255, 255, 0.12), transparent 18%),
    #000;
  opacity: 1;
  pointer-events: none;
  z-index: 2;
  background-image:
    radial-gradient(1px 1px at 20% 15%, rgba(255,255,255,0.75), transparent),
    radial-gradient(1px 1px at 75% 35%, rgba(255,255,255,0.62), transparent),
    radial-gradient(1.5px 1.5px at 42% 70%, rgba(255,255,255,0.88), transparent),
    radial-gradient(2px 2px at 88% 82%, rgba(220,235,255,0.96), transparent),
    radial-gradient(1px 1px at 10% 60%, rgba(255,255,255,0.58), transparent),
    radial-gradient(1.5px 1.5px at 55% 25%, rgba(255,245,210,0.82), transparent),
    radial-gradient(1px 1px at 65% 90%, rgba(255,255,255,0.55), transparent),
    radial-gradient(2px 2px at 30% 45%, rgba(255,255,255,0.92), transparent),
    radial-gradient(1px 1px at 95% 50%, rgba(255,255,255,0.68), transparent),
    radial-gradient(1.5px 1.5px at 5% 90%, rgba(210,220,255,0.78), transparent);
  background-size: 320px 260px;
  background-position: 0 0;
  transform: scale(1.02);
}

/* Canvas handles all star/nebula rendering; legacy starfield div is removed */

@keyframes ending-star-drift {
  from { background-position: 0 0; }
  to   { background-position: 0 -260px; }
}

.ending-horizon {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100vh;
  z-index: 4;
  opacity: 0;
  background: radial-gradient(ellipse 80vw 55vh at 50% 100%,
    rgba(255, 235, 174, 0.92) 0%,     /* Intense bright golden center */
    rgba(255, 155, 80, 0.52) 28%,     /* Vibrant orange glow */
    rgba(100, 160, 255, 0.28) 60%,    /* Soft cyan/blue transition */
    rgba(40, 20, 100, 0.08) 82%,      /* Deep cosmic purple edge */
    transparent 100%                  /* Smooth space blend */
  );
  filter: blur(2px);
  transform: translateY(22vh);
  pointer-events: none;
}

.game-ending.phase-nebula .ending-horizon,
.game-ending.phase-stats .ending-horizon,
.game-ending.phase-replay .ending-horizon {
  animation: ending-horizon-rise 2.2s ease-out forwards;
}

@keyframes ending-horizon-rise {
  0%   { opacity: 0; transform: translateY(22vh) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.ending-constellation {
  position: absolute;
  inset: 0;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
}

.ending-constellation::before,
.ending-constellation::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 42%;
  width: min(76vw, 760px);
  aspect-ratio: 1;
  border: 1px solid rgba(255, 224, 139, 0.18);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0.7);
  box-shadow:
    0 0 42px rgba(110, 160, 255, 0.18),
    inset 0 0 46px rgba(255, 235, 172, 0.08);
}

.ending-constellation::after {
  width: min(52vw, 520px);
  border-color: rgba(155, 205, 255, 0.2);
  transform: translate(-50%, -50%) scale(0.9) rotate(18deg);
}

.ending-constellation .star {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff8cb;
  box-shadow:
    0 0 14px #fff3b0,
    0 0 34px rgba(116, 176, 255, 0.78);
}

.ending-constellation .s1 { left: 21%; top: 33%; }
.ending-constellation .s2 { left: 35%; top: 20%; }
.ending-constellation .s3 { left: 57%; top: 24%; }
.ending-constellation .s4 { left: 73%; top: 39%; }
.ending-constellation .s5 { left: 64%; top: 63%; }
.ending-constellation .s6 { left: 30%; top: 61%; }

.game-ending.phase-nebula .ending-constellation,
.game-ending.phase-stats .ending-constellation,
.game-ending.phase-replay .ending-constellation {
  animation: constellation-arrive 1.8s ease-out forwards;
}

@keyframes constellation-arrive {
  0%   { opacity: 0; transform: scale(1.35) rotate(-9deg); filter: blur(6px); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); filter: blur(0); }
}

.ending-content {
  position: relative;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(920px, calc(100vw - 32px));
  gap: 0.78rem;
  padding: clamp(1rem, 3vw, 2rem);
  opacity: 0;
  pointer-events: none;
  text-align: center;
}

.game-ending.phase-stats .ending-content,
.game-ending.phase-replay .ending-content {
  pointer-events: auto;
  opacity: 1;
  animation: ending-content-in 0.45s ease-out forwards;
}

@keyframes ending-content-in {
  0%   { opacity: 0.72; transform: translateY(8px) scale(0.99); }
  100% { opacity: 1; transform: scale(1); }
}

.ending-sigil {
  position: relative;
  width: clamp(64px, 8vw, 92px);
  aspect-ratio: 1;
  opacity: 0;
  transform: scale(0.72);
}

.ending-sigil span {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(255, 221, 134, 0.76);
  border-radius: 50%;
  box-shadow:
    0 0 18px rgba(255, 221, 134, 0.64),
    inset 0 0 22px rgba(108, 165, 255, 0.24);
}

.ending-sigil span:nth-child(2) {
  inset: 16%;
  border-color: rgba(138, 195, 255, 0.66);
  transform: rotate(45deg);
}

.ending-sigil span:nth-child(3) {
  inset: 34%;
  background: radial-gradient(circle, #fffbe6 0 18%, rgba(255, 221, 134, 0.38) 19% 54%, transparent 55%);
  border: 0;
}

.game-ending.phase-stats .ending-sigil,
.game-ending.phase-replay .ending-sigil {
  animation: ending-sigil-open 1.4s ease-out forwards;
}

@keyframes ending-sigil-open {
  0%   { opacity: 0; transform: scale(0.72) rotate(-22deg); }
  62%  { opacity: 1; transform: scale(1.08) rotate(7deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

.ending-kicker {
  margin: 0;
  opacity: 0;
  color: rgba(207, 224, 255, 0.78);
  font-family: var(--font-pixel);
  font-size: clamp(0.55rem, 1.1vw, 0.72rem);
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.game-ending.phase-stats .ending-kicker,
.game-ending.phase-replay .ending-kicker {
  opacity: 1;
  animation: ending-copy-in 0.45s ease-out forwards;
}

.ending-title {
  font-family: var(--font-pixel);
  font-size: clamp(1.3rem, 3.8vw, 2.4rem);
  font-weight: 700;
  color: #ffe18a;
  text-align: center;
  text-shadow:
    0 0 18px rgba(255, 234, 166, 0.95),
    0 0 54px rgba(110, 166, 255, 0.72),
    0 0 110px rgba(255, 180, 80, 0.35);
  margin: 0;
  letter-spacing: 0.02em;
  line-height: 1.25;
  opacity: 0;
  transform: translateY(12px) scale(0.95);
}

.game-ending.phase-stats .ending-title,
.game-ending.phase-replay .ending-title {
  opacity: 1;
  transform: translateY(0) scale(1);
  animation: ending-title-arrive 0.58s cubic-bezier(0.15, 0.9, 0.22, 1) forwards;
}

@keyframes ending-title-arrive {
  0%   { opacity: 0.45; transform: translateY(8px) scale(0.98); filter: blur(2px); }
  74%  { opacity: 1; transform: translateY(0) scale(1.01); filter: blur(0); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

.ending-subtitle,
.ending-run-summary {
  margin: 0;
  max-width: 680px;
  opacity: 0;
}

.ending-subtitle {
  color: rgba(244, 241, 220, 0.82);
  font-family: var(--font-pixel);
  font-size: clamp(0.5rem, 1.1vw, 0.65rem);
  line-height: 1.85;
  letter-spacing: 0.02em;
}

.game-ending.phase-stats .ending-subtitle,
.game-ending.phase-replay .ending-subtitle {
  opacity: 1;
  animation: ending-copy-in 0.5s 0.15s ease-out forwards;
}

@keyframes ending-copy-in {
  0%   { opacity: 0; transform: translateY(14px); }
  100% { opacity: 1; transform: translateY(0); }
}

.ending-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
  max-width: 640px;
  width: 100%;
  opacity: 0;
  transform: translateY(26px);
}

.game-ending.phase-stats .ending-stats,
.game-ending.phase-replay .ending-stats {
  animation: stats-slide-in 0.95s ease-out forwards;
}

@keyframes stats-slide-in {
  0%   { opacity: 0; transform: translateY(26px); }
  100% { opacity: 1; transform: translateY(0); }
}

.ending-stat {
  min-height: 96px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.035));
  border: 1px solid rgba(166, 201, 255, 0.24);
  border-radius: 8px;
  padding: 0.8rem 0.9rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  box-shadow:
    inset 0 0 28px rgba(255, 255, 255, 0.035),
    0 12px 34px rgba(0, 0, 0, 0.22);
}

.stat-label {
  font-family: var(--font-pixel);
  font-size: clamp(0.42rem, 0.8vw, 0.5rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(207, 224, 255, 0.68);
}

.stat-value {
  font-family: var(--font-pixel);
  font-size: clamp(0.8rem, 1.6vw, 1.15rem);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 18px rgba(128, 185, 255, 0.38);
}

.ending-run-summary {
  color: rgba(255, 226, 139, 0.82);
  font-family: var(--font-pixel);
  font-size: clamp(0.5rem, 1.1vw, 0.65rem);
  font-weight: 700;
  line-height: 1.85;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.game-ending.phase-replay .ending-run-summary {
  animation: ending-copy-in 0.75s ease-out forwards;
}

.ending-replay {
  opacity: 0;
  margin-top: 0.1rem;
  padding: 0.85rem 2.2rem;
  font-family: var(--font-pixel);
  font-size: clamp(0.65rem, 1.3vw, 0.85rem);
  font-weight: 700;
  color: #08060c;
  background:
    linear-gradient(135deg, #fff5bd, #ffd368 48%, #8fc7ff);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  min-height: 48px;
  letter-spacing: 0.02em;
  box-shadow:
    0 0 26px rgba(255, 211, 104, 0.42),
    0 18px 38px rgba(0, 0, 0, 0.32);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.game-ending.phase-replay .ending-replay {
  animation: replay-fade-in 0.6s ease-out forwards;
}

@keyframes replay-fade-in {
  0%   { opacity: 0; transform: scale(0.9); }
  100% { opacity: 1; transform: scale(1); }
}

.ending-replay:hover {
  transform: scale(1.04);
  box-shadow:
    0 0 34px rgba(255, 211, 104, 0.64),
    0 22px 44px rgba(0, 0, 0, 0.38);
}

.ending-replay:active {
  transform: scale(0.97);
}

@media (max-width: 760px) {
  .ending-content {
    width: min(100vw - 24px, 560px);
    gap: 0.78rem;
    padding: 1.3rem 0.8rem;
  }

  .ending-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
  }

  .ending-stat {
    min-height: 82px;
    padding: 0.65rem 0.55rem;
  }

  .ending-title {
    font-size: clamp(1.0rem, 5vw, 1.6rem);
  }

  .ending-subtitle {
    font-size: clamp(0.44rem, 1.2vw, 0.56rem);
  }

  .ending-kicker {
    font-size: clamp(0.44rem, 1.2vw, 0.56rem);
    letter-spacing: 0.08em;
  }

  .ending-run-summary {
    font-size: clamp(0.44rem, 1.2vw, 0.56rem);
    letter-spacing: 0.08em;
  }
}

@media (max-height: 760px) and (min-width: 761px) {
  .ending-content {
    gap: 0.56rem;
    padding: 0.85rem 1.5rem;
  }

  .ending-sigil {
    width: 58px;
  }

  .ending-kicker {
    font-size: clamp(0.48rem, 1vw, 0.6rem);
  }

  .ending-title {
    font-size: clamp(1.1rem, 3.2vw, 1.8rem);
  }

  .ending-subtitle {
    font-size: clamp(0.48rem, 1vw, 0.6rem);
  }

  .ending-stats {
    gap: 0.55rem;
  }

  .ending-stat {
    min-height: 72px;
    padding: 0.48rem 0.62rem;
  }

  .stat-label {
    font-size: clamp(0.36rem, 0.75vw, 0.44rem);
  }

  .stat-value {
    font-size: clamp(0.72rem, 1.4vw, 1.05rem);
  }

  .ending-run-summary {
    font-size: clamp(0.48rem, 1vw, 0.6rem);
  }

  .ending-replay {
    min-height: 44px;
    padding: 0.65rem 2.0rem;
    font-size: clamp(0.55rem, 1.2vw, 0.7rem);
  }
}

/* ── Battery Saver overrides (performance optimization) ── */
body.battery-saver .game-bar,
body.battery-saver .readout,
body.battery-saver .typing-strip,
body.battery-saver .message-panel,
body.battery-saver .god-mode-badge,
body.battery-saver .potion-bar {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

body.battery-saver .game-bar {
  background: linear-gradient(135deg, rgba(14, 32, 24, 0.96), rgba(4, 12, 15, 0.92)) !important;
}

body.battery-saver .readout {
  background: var(--panel-solid) !important;
  box-shadow: inset 0 0 10px rgba(88, 223, 207, 0.04) !important;
}

body.battery-saver .typing-strip {
  background: linear-gradient(135deg, rgba(8, 18, 16, 0.96), rgba(33, 15, 15, 0.92)) !important;
}

body.battery-saver .message-panel {
  background: linear-gradient(135deg, rgba(10, 28, 20, 0.98), rgba(9, 11, 15, 0.96)) !important;
}

body.battery-saver .god-mode-badge {
  background: linear-gradient(135deg, rgba(28, 20, 4, 0.98), rgba(18, 14, 2, 0.96)) !important;
}

body.battery-saver .potion-bar {
  background: var(--panel-solid) !important;
}

/* ── Custom highlights and Skip button styles for ending ── */
.ending-stat.highlighted {
  border: 1px solid rgba(255, 211, 104, 0.45);
  background:
    radial-gradient(circle at 50% 24%, rgba(255, 238, 166, 0.2), transparent 45%),
    linear-gradient(180deg, rgba(255, 226, 139, 0.15), rgba(255, 255, 255, 0.045));
  box-shadow:
    inset 0 0 24px rgba(255, 211, 104, 0.05),
    0 12px 34px rgba(0, 0, 0, 0.3);
}

.ending-stat.highlighted .stat-label {
  color: rgba(255, 226, 139, 0.9);
}

.ending-stat.highlighted .stat-value {
  color: #ffe18a;
  font-size: clamp(1.15rem, 2.3vw, 1.6rem);
  text-shadow:
    0 0 16px rgba(255, 211, 104, 0.8),
    0 0 32px rgba(255, 211, 104, 0.3);
}

.ending-skip {
  position: absolute;
  bottom: 24px;
  right: 24px;
  z-index: 1005;
  padding: 0.6rem 1.2rem;
  font-family: var(--font-pixel);
  font-size: clamp(0.55rem, 1vw, 0.72rem);
  font-weight: 700;
  color: rgba(255, 221, 134, 0.85);
  background: rgba(15, 10, 25, 0.6);
  border: 1px solid rgba(255, 221, 134, 0.4);
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  backdrop-filter: blur(4px);
  pointer-events: auto;
  transition: all 0.2s ease;
  box-shadow: 0 0 10px rgba(255, 221, 134, 0.1);
}

.ending-skip:hover {
  color: #08060c;
  background: rgba(255, 221, 134, 0.95);
  border-color: rgba(255, 221, 134, 0.95);
  transform: translateY(-2px);
  box-shadow: 0 0 18px rgba(255, 221, 134, 0.4);
}

.ending-skip:active {
  transform: translateY(0);
}

.game-ending.phase-stats .ending-skip,
.game-ending.phase-replay .ending-skip {
  display: none;
}

/* ── Leaderboard panel ───────────────────────────── */

.sw-leaderboard {
  position: fixed;
  top: calc(max(14px, env(safe-area-inset-top)) + 82px);
  right: 14px;
  z-index: 11;
  width: min(210px, calc(100vw - 28px));
  padding: 11px 12px 10px;
  border: 1px solid rgba(88, 223, 207, 0.22);
  border-top: 2px solid var(--aqua);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: inset 0 0 18px rgba(88, 223, 207, 0.06);
  backdrop-filter: blur(10px);
  pointer-events: none;
  transition: top 0.35s ease;
}

body.is-running:not(.is-paused) .sw-leaderboard {
  top: max(14px, env(safe-area-inset-top));
}

.sw-leaderboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}

.sw-leaderboard-header p {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.sw-leaderboard-header span {
  flex: 0 0 auto;
  color: var(--aqua);
  font-family: var(--font-mono);
  font-size: 0.60rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sw-score-list {
  display: grid;
  gap: 2px;
  min-height: 120px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: score-rank;
}

.sw-score-list li {
  counter-increment: score-rank;
  display: grid;
  grid-template-columns: 22px minmax(40px, 1fr) auto;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 4px 5px;
  border-left: 1px solid rgba(88, 223, 207, 0.18);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  line-height: 1;
}

.sw-score-list li::before {
  content: counter(score-rank, decimal-leading-zero);
  color: rgba(242, 240, 223, 0.28);
  font-size: 0.60rem;
}

.sw-score-list li:first-child {
  color: var(--gold);
}

.sw-score-list li:first-child::before {
  color: rgba(239, 195, 92, 0.52);
}

.sw-score-list li.sw-highlight {
  background: rgba(88, 223, 207, 0.1);
  border-color: var(--aqua);
  box-shadow: inset 0 0 0 1px rgba(88, 223, 207, 0.16);
}

.sw-score-list .sw-initials {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sw-score-list .sw-score-val {
  color: var(--aqua);
  font-size: 0.72rem;
  white-space: nowrap;
}

.sw-score-list li:first-child .sw-score-val {
  color: var(--gold);
}

.sw-score-list .sw-loading {
  grid-template-columns: 1fr;
  align-content: center;
  min-height: 48px;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

.sw-score-list .sw-loading::before {
  content: none;
}

@media (max-width: 760px) {
  .sw-leaderboard {
    display: none;
  }
}

/* ── Initials modal ─────────────────────────────── */

.sw-initials-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 9, 10, 0.78);
  backdrop-filter: blur(6px);
}

.sw-initials-modal[hidden] {
  display: none;
}

.sw-initials-card {
  display: grid;
  width: min(340px, 100%);
  gap: 12px;
  padding: 22px 20px 20px;
  border: 1px solid rgba(88, 223, 207, 0.28);
  border-top: 2px solid var(--aqua);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(6, 18, 14, 0.97), rgba(4, 10, 15, 0.95));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.62), 0 0 40px rgba(88, 223, 207, 0.05);
}

.sw-modal-kicker {
  margin: 0;
  color: var(--aqua);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.sw-initials-card h2 {
  margin: 0;
  color: var(--gold);
  font-family: var(--font-pixel);
  font-size: clamp(1rem, 5vw, 1.6rem);
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.45;
  text-shadow: 0 0 18px rgba(239, 195, 92, 0.34);
  text-transform: uppercase;
}

.sw-modal-score {
  color: var(--aqua);
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
}

.sw-initials-card label {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sw-initials-card input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid rgba(88, 223, 207, 0.28);
  border-radius: 8px;
  background: rgba(0, 16, 14, 0.82);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-align: center;
  text-transform: uppercase;
}

.sw-initials-card input:focus {
  outline: none;
  border-color: var(--aqua);
  box-shadow: 0 0 0 2px rgba(88, 223, 207, 0.18), 0 0 14px rgba(88, 223, 207, 0.1);
}

.sw-error-text {
  min-height: 14px;
  margin: 0;
  color: var(--danger);
  font-family: var(--font-mono);
  font-size: 0.62rem;
}

.sw-initials-card button {
  width: 100%;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid rgba(239, 195, 92, 0.36);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(242, 106, 61, 0.88), rgba(239, 195, 92, 0.88));
  color: #1a120b;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 800;
  transition: filter 160ms ease, transform 160ms ease;
}

.sw-initials-card button:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.sw-initials-card button:disabled {
  cursor: progress;
  opacity: 0.52;
  transform: none;
}

.sw-initials-card .sw-skip-button {
  margin-top: 8px;
  background: transparent;
  border-color: rgba(242, 240, 223, 0.22);
  color: rgba(242, 240, 223, 0.66);
  font-weight: 600;
}

.sw-initials-card .sw-skip-button:hover {
  filter: none;
  border-color: rgba(242, 240, 223, 0.45);
  color: rgba(242, 240, 223, 0.92);
}
