@font-face {
  font-family: "Kanit Local";
  src: url("./assets/fonts/kanit-regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Kanit Local";
  src: url("./assets/fonts/kanit-semibold.ttf") format("truetype");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: "Kanit Local";
  src: url("./assets/fonts/kanit-extrabold.ttf") format("truetype");
  font-style: normal;
  font-weight: 800;
  font-display: swap;
}

:root {
  --app-height: 100svh;
  --bg-ink: #10141b;
  --bg-panel: rgba(18, 23, 31, 0.88);
  --bg-panel-strong: rgba(11, 15, 21, 0.94);
  --bg-panel-soft: rgba(29, 35, 44, 0.72);
  --line-soft: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 197, 61, 0.32);
  --text-main: #f6f0de;
  --text-muted: #d1c8af;
  --text-dim: #a49676;
  --gold: #ffc739;
  --gold-deep: #ff9f0f;
  --red: #ff6a55;
  --green: #74e2a1;
  --shadow-heavy: 0 28px 60px rgba(0, 0, 0, 0.42);
  --shadow-soft: 0 12px 30px rgba(0, 0, 0, 0.24);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --ui-font: "Kanit Local", "Trebuchet MS", "Segoe UI", sans-serif;
  --display-font: "Kanit Local", "Arial Narrow Bold", sans-serif;
  --reading-font: "Trebuchet MS", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  color: var(--text-main);
  font-family: var(--ui-font);
  font-weight: 400;
  background:
    radial-gradient(circle at top, rgba(255, 170, 48, 0.16), transparent 26%),
    radial-gradient(circle at 20% 20%, rgba(255, 98, 87, 0.16), transparent 22%),
    linear-gradient(180deg, #1d242c 0%, #0f141b 55%, #0b0f15 100%);
}

button,
a,
canvas {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button,
a,
[tabindex]:not([tabindex="-1"]) {
  min-height: 44px;
}

button:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 3px solid #fff3bf;
  outline-offset: 4px;
  box-shadow:
    0 0 0 6px rgba(30, 20, 4, 0.72),
    0 0 24px rgba(255, 199, 57, 0.5);
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.hidden {
  display: none !important;
}

.page-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: var(--app-height);
  min-height: var(--app-height);
  width: 100%;
  padding: 0;
  gap: 0;
  transition:
    grid-template-rows 180ms ease,
    gap 180ms ease;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 0;
  z-index: 8;
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    min-height 180ms ease;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: 20px;
  background: rgba(11, 15, 21, 0.28);
  border: 1px solid rgba(255, 243, 211, 0.18);
  box-shadow:
    0 0 22px rgba(255, 199, 57, 0.1),
    0 12px 28px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(8px);
  justify-self: start;
  color: var(--text-main);
  text-decoration: none;
  opacity: 0.98;
}

.brand-link:hover {
  opacity: 1;
  border-color: rgba(255, 241, 202, 0.38);
}

.brand-logo {
  width: 146px;
  max-width: min(24vw, 146px);
  height: auto;
  object-fit: contain;
  filter:
    brightness(0)
    invert(1)
    sepia(0.16)
    saturate(0.72)
    drop-shadow(0 1px 0 rgba(255, 245, 220, 0.18))
    drop-shadow(0 8px 16px rgba(0, 0, 0, 0.34));
}

.topbar-copy {
  text-align: center;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.66rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.topbar-copy h1 {
  margin: 0;
  font-family: var(--display-font);
  font-weight: 800;
  font-size: clamp(2.55rem, 4.45vw, 4.2rem);
  letter-spacing: 0.04em;
  color: var(--gold);
  text-shadow: 0 10px 28px rgba(255, 188, 28, 0.28);
}

.icon-button,
.secondary-button,
.primary-button {
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  cursor: pointer;
  transition:
    transform 140ms ease,
    background-color 140ms ease,
    border-color 140ms ease,
    opacity 140ms ease;
}

.icon-button:hover,
.secondary-button:hover,
.primary-button:hover {
  transform: translateY(-1px);
}

.icon-button:active,
.secondary-button:active,
.primary-button:active {
  transform: translateY(0);
}

.icon-button {
  justify-self: end;
  padding: 0.62rem 0.95rem;
  min-width: 102px;
  background: rgba(15, 19, 26, 0.38);
  color: var(--text-main);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.stage-shell {
  display: grid;
  place-items: stretch;
  min-height: 0;
  overflow: hidden;
}

.stage-frame {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 0;
  overflow: hidden;
  border: 0;
  background: #0b0f15;
  box-shadow: none;
  isolation: isolate;
}

#game-canvas,
.canvas-shade,
.overlay-root,
.toast-stack,
.hud,
.level-banner {
  position: absolute;
  inset: 0;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
}

@media (hover: hover) and (pointer: fine) {
  body[data-screen="game"] #game-canvas {
    cursor: crosshair;
  }
}

.canvas-shade {
  background:
    linear-gradient(180deg, rgba(10, 14, 20, 0.16) 0%, rgba(10, 14, 20, 0.04) 20%, rgba(10, 14, 20, 0.2) 100%),
    radial-gradient(circle at top, rgba(255, 195, 57, 0.08), transparent 24%);
  pointer-events: none;
}

.hud {
  z-index: 2;
  pointer-events: none;
}

.hud-ability-dock {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  justify-content: flex-end;
  pointer-events: none;
}

.hud-row {
  padding: 10px 12px;
}

.hud-row-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
}

.hud-stat-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-stat-group-right {
  padding-right: 50px;
  justify-content: flex-end;
}

.hud-pill {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  min-width: 72px;
  padding: 7px 10px;
  border-radius: 14px;
  background: rgba(15, 20, 28, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

.hud-label,
.info-label {
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-dim);
}

.hud-pill strong,
.info-card strong,
.final-score-card strong {
  color: var(--text-main);
  font-size: 1rem;
}

#hud-arena {
  font-size: 0.88rem;
  line-height: 1.15;
  max-width: 8.6rem;
  text-wrap: balance;
}

.question-card {
  display: grid;
  gap: 5px;
  min-width: min(52vw, 360px);
  padding: 6px 22px 8px;
  text-align: center;
  border-radius: 22px;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.question-support {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  order: 2;
}

#question-text {
  order: 3;
  display: grid;
  place-items: center;
  min-width: 310px;
  min-height: 110px;
  padding: 12px 18px;
  border-radius: 14px;
  background: rgba(12, 17, 24, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
  backdrop-filter: blur(14px);
  font-family: var(--display-font);
  font-weight: 800;
  font-size: clamp(2rem, 5.4vw, 4.1rem);
  letter-spacing: 0.08em;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 189, 43, 0.24);
}

.question-expression {
  white-space: nowrap;
}

.question-mark {
  display: inline-block;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  transform: none;
}

.hud-action {
  pointer-events: auto;
  flex: 0 0 auto;
  min-width: 78px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(15, 20, 28, 0.82);
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.92rem;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

.hud-action:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
}

.hud-action-accent {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(39, 46, 59, 0.92);
  border-color: rgba(255, 199, 57, 0.2);
}

.hud-ability-button {
  min-width: 186px;
  min-height: 54px;
  padding: 0 18px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(39, 46, 59, 0.96), rgba(24, 29, 38, 0.92));
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.26),
    0 0 0 1px rgba(255, 199, 57, 0.08);
}

.hud-ability-button:disabled {
  opacity: 1;
  color: rgba(231, 241, 255, 0.88);
  border-color: rgba(173, 211, 255, 0.22);
  background:
    linear-gradient(180deg, rgba(111, 132, 160, 0.36), rgba(65, 79, 101, 0.5)),
    rgba(28, 36, 48, 0.88);
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.hud-ability-button:disabled #ability-button-label,
.hud-ability-button:disabled #ability-button-charges {
  color: rgba(226, 240, 255, 0.88);
}

.hud-brief,
.judge-card {
  border-radius: 14px;
  background: rgba(12, 17, 24, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
  backdrop-filter: blur(14px);
}

.hud-brief {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 148px;
  padding: 7px 10px;
  text-align: left;
}

.hud-brief strong {
  font-size: 0.92rem;
}

.hud-brief-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.judge-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 154px;
  padding: 7px 10px;
  text-align: left;
}

.judge-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.judge-copy strong {
  font-size: 0.9rem;
}

.judge-title {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.judge-copy-large strong {
  font-size: 1.26rem;
}

.judge-portrait {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 20px;
  font-family: var(--display-font);
  color: #211605;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.24);
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background-position: center;
  background-size: cover;
  overflow: hidden;
}

.judge-portrait::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(8, 10, 16, 0.18));
  pointer-events: none;
}

.judge-portrait.has-image {
  color: transparent;
  text-shadow: none;
}

.judge-portrait-mini {
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  border-radius: 12px;
}

.judge-portrait-large {
  width: min(100%, 220px);
  aspect-ratio: 1;
  font-size: clamp(3rem, 8vw, 5rem);
  border-radius: 28px;
}

.overlay-root {
  z-index: 3;
  pointer-events: none;
}

.fullscreen-button {
  position: absolute;
  z-index: 30;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 243, 211, 0.35);
  border-radius: 12px;
  color: var(--text-main);
  background: rgba(15, 20, 28, 0.92);
  font-size: 26px;
}

.fullscreen-button[hidden] { display: none; }

.storage-notice { margin: 0; font-size: 0.9rem; color: #ffe0a0; }

body[data-screen="confirm"] .topbar,
body[data-screen="confirm"] .footer { display: none; }
body[data-screen="confirm"] .page-shell { grid-template-rows: 0 minmax(0, 1fr) 0; }
body[data-screen="confirm"] .stage-shell { grid-row: 2; }

.screen-panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding:
    max(18px, calc(env(safe-area-inset-top) + 18px))
    max(18px, calc(env(safe-area-inset-right) + 18px))
    max(18px, calc(env(safe-area-inset-bottom) + 18px))
    max(18px, calc(env(safe-area-inset-left) + 18px));
  pointer-events: auto;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.panel {
  width: min(100%, 660px);
  border-radius: var(--radius-xl);
  border: 1px solid rgba(255, 255, 255, 0.09);
  background:
    linear-gradient(180deg, rgba(28, 34, 42, 0.72), rgba(12, 16, 23, 0.88)),
    var(--bg-panel);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-heavy);
}

.menu-panel {
  width: min(100%, 940px);
  max-height: min(100%, 760px);
  padding: clamp(20px, 2.8vw, 26px);
  display: grid;
  gap: 16px;
}

.menu-panel.is-completed {
  border-color: rgba(255, 207, 92, 0.3);
  background:
    radial-gradient(circle at top left, rgba(255, 199, 57, 0.12), transparent 38%),
    linear-gradient(180deg, rgba(30, 34, 40, 0.74), rgba(12, 16, 23, 0.9)),
    var(--bg-panel);
  box-shadow:
    var(--shadow-heavy),
    0 0 30px rgba(255, 176, 42, 0.1);
}

.menu-complete-badge {
  margin: 0 0 8px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.panel-intro h2,
.modal-header h2 {
  margin: 0;
  font-family: var(--display-font);
  font-weight: 800;
  letter-spacing: 0.01em;
  font-size: clamp(1.85rem, 3.3vw, 2.8rem);
}

.panel-intro p,
.modal-copy,
.help-card p,
.help-tip,
.score-meta {
  color: var(--text-muted);
  line-height: 1.55;
}

.modal-copy,
.help-card p,
.help-tip {
  font-family: var(--reading-font);
}

.panel-intro p {
  margin: 10px 0 0;
  max-width: 42rem;
}

.panel-badge {
  display: inline-flex;
  margin-bottom: 12px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 199, 57, 0.12);
  border: 1px solid rgba(255, 199, 57, 0.2);
  color: var(--gold);
  font-size: 0.84rem;
  letter-spacing: 0.05em;
}

.menu-meta,
.stats-grid,
.help-grid {
  display: grid;
  gap: 14px;
}

.menu-lower {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.88fr);
  align-items: center;
  gap: 20px;
}

.menu-meta {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
  align-content: start;
}

.info-card,
.help-card,
.final-score-card {
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.info-card {
  min-height: 112px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
}

.info-meta {
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--text-dim);
}

.menu-actions,
.stack-actions {
  display: grid;
  gap: 10px;
}

.menu-actions {
  align-content: center;
}

.primary-button,
.secondary-button {
  width: 100%;
  padding: 13px 18px;
  font-weight: 700;
}

.primary-button {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: #211605;
  border-color: rgba(255, 199, 57, 0.45);
  box-shadow: 0 14px 28px rgba(255, 166, 24, 0.24);
}

.menu-start-button {
  position: relative;
  overflow: hidden;
  border-color: rgba(255, 212, 98, 0.76);
  box-shadow:
    0 0 0 1px rgba(255, 219, 126, 0.24),
    0 0 18px rgba(255, 170, 30, 0.32),
    0 16px 34px rgba(255, 145, 10, 0.34);
  animation: menu-start-pulse 2.2s ease-in-out infinite;
}

.menu-start-button::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: inherit;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.34), transparent 28%, transparent 72%, rgba(255, 240, 200, 0.22)),
    radial-gradient(circle at 12% 50%, rgba(255, 247, 214, 0.55), transparent 26%);
  opacity: 0.85;
  pointer-events: none;
}

.menu-start-button span,
.menu-start-button {
  z-index: 0;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
}

.modal-panel {
  width: min(100%, 720px);
  padding: clamp(22px, 4vw, 32px);
}

#screen-gameover .modal-panel {
  width: min(100%, 420px);
  padding: 18px;
}

#screen-gameover.is-champion .modal-panel {
  width: min(100%, 500px);
  padding: 22px 20px 20px;
  border-color: rgba(255, 207, 92, 0.28);
  background:
    radial-gradient(circle at top, rgba(255, 191, 71, 0.12), transparent 36%),
    linear-gradient(180deg, rgba(34, 28, 20, 0.86), rgba(12, 16, 23, 0.94)),
    var(--bg-panel);
  box-shadow:
    0 28px 60px rgba(0, 0, 0, 0.42),
    0 0 0 1px rgba(255, 219, 126, 0.12),
    0 0 32px rgba(255, 176, 42, 0.12);
}

#screen-gameover .modal-header {
  margin-bottom: 14px;
}

#screen-gameover .modal-header h2 {
  font-size: clamp(1.6rem, 3vw, 2.3rem);
}

#screen-gameover.is-champion .modal-header {
  margin-bottom: 12px;
}

#screen-gameover.is-champion .modal-header h2 {
  font-size: clamp(2.3rem, 5vw, 3.2rem);
  line-height: 0.94;
  letter-spacing: 0.01em;
  text-wrap: balance;
}

#screen-gameover.is-champion .eyebrow {
  color: rgba(255, 223, 151, 0.88);
  letter-spacing: 0.26em;
}

.champion-banner {
  display: grid;
  justify-items: center;
  gap: 6px;
  margin-bottom: 14px;
  padding: 14px 16px;
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 213, 114, 0.12), rgba(255, 154, 30, 0.04)),
    rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 213, 114, 0.18);
  box-shadow:
    inset 0 1px 0 rgba(255, 243, 204, 0.08),
    0 12px 26px rgba(255, 170, 30, 0.08);
  text-align: center;
}

.champion-banner-mark {
  font-size: 0.68rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: rgba(255, 222, 149, 0.72);
}

.champion-banner strong {
  font-size: clamp(1.05rem, 2.2vw, 1.3rem);
  color: #fff2d3;
  line-height: 1.2;
}

#screen-gameover .final-score-card {
  margin-bottom: 14px;
  padding: 16px;
}

#screen-gameover .final-score-card strong {
  font-size: clamp(2.2rem, 8vw, 3.3rem);
}

#screen-gameover.is-champion .final-score-card {
  margin-bottom: 16px;
  padding: 22px 18px 20px;
  border-color: rgba(255, 208, 98, 0.16);
  background:
    radial-gradient(circle at top, rgba(255, 194, 82, 0.1), transparent 42%),
    rgba(255, 255, 255, 0.04);
}

#screen-gameover.is-champion .final-score-card strong {
  font-size: clamp(3rem, 8vw, 4.4rem);
  text-shadow: 0 0 24px rgba(255, 188, 32, 0.16);
}

#screen-gameover.is-champion #gameover-level {
  color: rgba(255, 234, 187, 0.92);
}

#screen-gameover .stats-grid {
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

#screen-gameover .info-card {
  min-height: 84px;
  padding: 14px 16px;
}

#screen-gameover .stack-actions {
  gap: 8px;
}

#screen-gameover.is-champion .wide-card {
  border-color: rgba(255, 208, 98, 0.14);
  background:
    linear-gradient(180deg, rgba(255, 197, 84, 0.06), rgba(255, 255, 255, 0.03)),
    rgba(255, 255, 255, 0.03);
}

.compact-modal {
  width: min(100%, 440px);
}

.tournament-panel {
  width: min(100%, 552px);
  padding: clamp(16px, 2.4vw, 22px);
}

.tournament-panel .modal-header {
  gap: 12px;
  margin-bottom: 14px;
}

.tournament-panel .modal-header h2 {
  font-size: clamp(1.7rem, 2.8vw, 2.3rem);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.tournament-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.7fr) minmax(0, 1.3fr);
  gap: 16px;
  margin-bottom: 16px;
}

.judge-spotlight {
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 14px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.tournament-copy {
  display: grid;
  gap: 10px;
}

.intro-stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.tournament-panel .info-card {
  min-height: 92px;
  padding: 14px 16px;
}

.tournament-panel .intro-stats .info-card strong {
  font-size: 0.88rem;
  line-height: 1.15;
}

.tournament-panel .judge-portrait-large {
  width: min(100%, 180px);
}

.tournament-panel .judge-copy-large strong {
  font-size: 1.12rem;
}

.tournament-panel .stack-actions {
  gap: 8px;
}

.scores-list {
  display: grid;
  gap: 12px;
}

#screen-scores .modal-panel {
  height: min(100%, 680px);
  max-height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

#screen-scores .scores-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 6px;
  -webkit-overflow-scrolling: touch;
}

#screen-scores .scores-list::-webkit-scrollbar {
  width: 8px;
}

#screen-scores .scores-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 216, 112, 0.28);
}

.score-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.score-rank {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #211605;
  background: linear-gradient(135deg, var(--gold), #ffed95);
  font-weight: 800;
}

.score-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.score-main strong {
  font-size: 1.06rem;
}

.score-meta {
  font-size: 0.88rem;
}

.score-value {
  font-size: 1.36rem;
  font-weight: 800;
  color: var(--gold);
}

.empty-state {
  padding: 28px;
  border-radius: 22px;
  text-align: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.help-panel {
  width: min(100%, 840px);
}

.help-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
}

.help-card {
  padding: 18px;
}

.help-card h3 {
  margin: 0 0 10px;
  color: var(--gold);
}

.help-tip {
  padding: 16px 18px;
  border-radius: 18px;
  background: rgba(255, 199, 57, 0.08);
  border: 1px solid rgba(255, 199, 57, 0.15);
}

.final-score-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  text-align: center;
  margin-bottom: 18px;
  padding: 22px;
}

.final-score-card strong {
  font-size: clamp(2.6rem, 7vw, 4.4rem);
  color: var(--gold);
}

.final-score-card span:last-child {
  color: var(--text-muted);
}

.stats-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 18px;
}

.wide-card {
  grid-column: 1 / -1;
}

.level-banner {
  z-index: 4;
  display: grid;
  place-items: start start;
  padding-top: 104px;
  padding-left: 14px;
  pointer-events: none;
}

.level-banner span {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  border-radius: 999px;
  background: rgba(255, 199, 57, 0.18);
  border: 1px solid rgba(255, 199, 57, 0.32);
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 20px 40px rgba(255, 170, 28, 0.18);
}

.toast-stack {
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 10px;
  padding: 18px;
  pointer-events: none;
}

body[data-screen="game"] .toast-stack {
  padding-bottom: 82px;
}

.toast {
  max-width: min(80vw, 380px);
  padding: 12px 16px;
  border-radius: 16px;
  background: rgba(12, 15, 22, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow-soft);
  color: var(--text-main);
  transform: translateY(8px);
  opacity: 0;
  animation: toast-in 160ms ease forwards;
}

.toast.is-success {
  border-color: rgba(116, 226, 161, 0.24);
}

.toast.is-error {
  border-color: rgba(255, 106, 85, 0.26);
}

.footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  min-height: 32px;
  padding: 0 10px;
  z-index: 8;
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    min-height 180ms ease;
}

.footer p {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.footer a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--text-muted);
}

body[data-screen="menu"] .page-shell {
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
}

body[data-screen="menu"] .topbar,
body[data-screen="menu"] .footer {
  position: absolute;
  left: max(18px, calc(env(safe-area-inset-left) + 18px));
  right: max(18px, calc(env(safe-area-inset-right) + 18px));
}

body[data-screen="menu"] .topbar {
  top: max(24px, calc(env(safe-area-inset-top) + 24px));
}

body[data-screen="menu"] .footer {
  bottom: max(10px, calc(env(safe-area-inset-bottom) + 10px));
}

body[data-screen="menu"] .stage-shell {
  grid-row: 1 / -1;
}

body[data-screen="menu"] #screen-menu {
  padding:
    clamp(96px, 13vh, 122px)
    clamp(22px, 4vw, 36px)
    clamp(58px, 8vh, 84px);
}

body[data-screen="game"] .screen-panel,
body[data-screen="pause"] #screen-menu,
body[data-screen="result"] #screen-menu {
  pointer-events: none;
}

body[data-screen="scores"] .page-shell,
body[data-screen="intro"] .page-shell,
body[data-screen="help"] .page-shell,
body[data-screen="game"] .page-shell,
body[data-screen="pause"] .page-shell,
body[data-screen="result"] .page-shell {
  grid-template-rows: 0 minmax(0, 1fr) 0;
  gap: 0;
}

body[data-screen="scores"] .topbar,
body[data-screen="intro"] .topbar,
body[data-screen="help"] .topbar,
body[data-screen="game"] .topbar,
body[data-screen="pause"] .topbar,
body[data-screen="result"] .topbar,
body[data-screen="scores"] .footer,
body[data-screen="intro"] .footer,
body[data-screen="help"] .footer,
body[data-screen="game"] .footer,
body[data-screen="pause"] .footer,
body[data-screen="result"] .footer {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  min-height: 0;
  overflow: hidden;
}

body[data-screen="scores"] .topbar,
body[data-screen="intro"] .topbar,
body[data-screen="help"] .topbar,
body[data-screen="game"] .topbar,
body[data-screen="pause"] .topbar,
body[data-screen="result"] .topbar {
  transform: translateY(-10px);
}

body[data-screen="scores"] .footer,
body[data-screen="intro"] .footer,
body[data-screen="help"] .footer,
body[data-screen="game"] .footer,
body[data-screen="pause"] .footer,
body[data-screen="result"] .footer {
  transform: translateY(10px);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes menu-start-pulse {
  0%,
  100% {
    box-shadow:
      0 0 0 1px rgba(255, 219, 126, 0.24),
      0 0 18px rgba(255, 170, 30, 0.32),
      0 16px 34px rgba(255, 145, 10, 0.34);
  }
  50% {
    box-shadow:
      0 0 0 1px rgba(255, 234, 172, 0.42),
      0 0 28px rgba(255, 192, 58, 0.46),
      0 20px 40px rgba(255, 145, 10, 0.42);
  }
}

@media (max-width: 1024px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .hud-row-top {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .hud-stat-group-left,
  .hud-stat-group-right {
    justify-content: center;
  }

  .question-card {
    min-width: min(78vw, 520px);
  }

  .hud-ability-dock {
    right: 14px;
    bottom: 14px;
  }

  .level-banner {
    padding-top: 166px;
    padding-left: 14px;
  }

  .tournament-grid {
    grid-template-columns: 1fr;
  }

  .menu-lower {
    grid-template-columns: 1fr;
  }

  body[data-screen="menu"] .topbar,
  body[data-screen="menu"] .footer {
    left: max(14px, calc(env(safe-area-inset-left) + 14px));
    right: max(14px, calc(env(safe-area-inset-right) + 14px));
  }

  body[data-screen="menu"] #screen-menu {
    padding-top: clamp(104px, 15vh, 136px);
    padding-bottom: clamp(56px, 8vh, 78px);
  }
}

@media (max-width: 720px) {
  .topbar-copy h1 {
    font-size: clamp(2.35rem, 7vw, 3rem);
  }

  .question-card {
    min-width: min(88vw, 360px);
    padding: 6px 16px 8px;
  }

  #question-text {
    min-width: min(88vw, 360px);
    min-height: 96px;
    width: 100%;
    font-size: clamp(1.9rem, 9vw, 3.1rem);
  }

  .question-support {
    width: 100%;
    justify-content: stretch;
  }

  .hud-ability-dock {
    right: 12px;
    bottom: 12px;
    left: 12px;
  }

  .hud-ability-button {
    min-width: 0;
    width: min(260px, 100%);
    margin-left: auto;
  }

  .level-banner {
    place-items: start center;
    padding-top: 178px;
    padding-left: 0;
  }

  .hud-brief,
  .judge-card {
    flex: 1 1 100%;
    min-width: 0;
  }

  .menu-meta,
  .stats-grid,
  .help-grid {
    grid-template-columns: 1fr;
  }

  .menu-lower {
    gap: 14px;
  }

  .intro-stats {
    grid-template-columns: 1fr;
  }

  .modal-panel,
  .menu-panel,
  .tournament-panel {
    padding: 20px;
  }

  body[data-screen="menu"] .topbar,
  body[data-screen="menu"] .footer {
    left: max(10px, calc(env(safe-area-inset-left) + 10px));
    right: max(10px, calc(env(safe-area-inset-right) + 10px));
  }

  body[data-screen="menu"] #screen-menu {
    padding-top: clamp(112px, 17vh, 148px);
    padding-bottom: clamp(52px, 7vh, 70px);
  }

  .score-row {
    grid-template-columns: auto 1fr;
  }

  .score-value {
    grid-column: 2;
  }
}

@media (max-width: 480px) {
  .topbar {
    gap: 10px;
  }

  .brand-logo {
    width: 126px;
  }

  .topbar-copy h1 {
    font-size: clamp(2.1rem, 9vw, 2.6rem);
  }

  .hud-row {
    padding: 12px;
  }

  .hud-ability-button {
    min-height: 50px;
    width: min(224px, 100%);
    padding: 0 16px;
  }

  .menu-panel,
  .modal-panel {
    width: min(100%, 344px);
    padding: 16px;
  }

  .panel-intro h2,
  .modal-header h2 {
    font-size: 1.9rem;
  }

  .panel-intro p,
  .modal-copy,
  .help-card p,
  .help-tip,
  .score-meta {
    font-size: 0.95rem;
  }

  .panel-badge {
    margin-bottom: 10px;
    padding: 6px 10px;
    font-size: 0.76rem;
  }

  .menu-meta,
  .stats-grid,
  .help-grid {
    gap: 10px;
  }

  .menu-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 16px 0 14px;
  }

  .menu-actions,
  .stack-actions {
    gap: 8px;
  }

  .info-card,
  .help-card,
  .final-score-card {
    padding: 14px;
  }

  .primary-button,
  .secondary-button {
    padding: 11px 14px;
  }

  .hud-pill {
    min-width: 68px;
    padding: 7px 9px;
  }

  .hud-action {
    min-width: 68px;
    min-height: 44px;
    padding-inline: 10px;
  }

  .footer {
    font-size: 0.8rem;
  }

  body[data-screen="menu"] #screen-menu {
    padding-top: clamp(118px, 18vh, 154px);
    padding-bottom: clamp(48px, 6vh, 62px);
  }
}

@media (min-width: 740px) and (max-height: 850px) and (orientation: landscape) {
  .hud-row-top {
    grid-template-columns: minmax(220px, 0.9fr) minmax(420px, 1.35fr) minmax(220px, 0.9fr);
    align-items: start;
  }

  .hud-stat-group-left {
    justify-content: flex-start;
  }

  .hud-stat-group-right {
    justify-content: flex-end;
  }

  .question-card {
    width: 100%;
    min-width: 0;
    padding-inline: 8px;
  }

  #question-text {
    min-width: 0;
    min-height: 92px;
  }

  #screen-gameover {
    padding: 12px;
  }

  #screen-gameover .modal-panel {
    width: min(100%, 760px);
    padding: 14px 16px;
  }

  #screen-gameover .modal-header {
    margin-bottom: 8px;
  }

  #screen-gameover .modal-header h2 {
    font-size: 1.75rem;
  }

  #screen-gameover .final-score-card {
    margin-bottom: 10px;
    padding: 10px 14px;
  }

  #screen-gameover .final-score-card strong {
    font-size: 2.5rem;
  }

  #screen-gameover .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 10px;
  }

  #screen-gameover .info-card {
    min-height: 70px;
    padding: 10px 12px;
  }

  #screen-gameover .wide-card {
    grid-column: 1 / -1;
  }

  #screen-gameover .stack-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  #screen-gameover .primary-button,
  #screen-gameover .secondary-button {
    min-height: 44px;
    padding-block: 10px;
  }
}

@media (min-width: 900px) and (max-height: 650px) {
  body[data-screen="menu"] .topbar {
    top: max(6px, env(safe-area-inset-top));
  }

  .brand-link {
    padding: 4px 8px;
    border-radius: 14px;
  }

  .brand-logo {
    width: 104px;
  }

  .topbar-copy h1 {
    font-size: clamp(2rem, 4.4vh, 2.5rem);
  }

  body[data-screen="menu"] #screen-menu {
    padding:
      max(62px, calc(env(safe-area-inset-top) + 62px))
      max(18px, calc(env(safe-area-inset-right) + 18px))
      max(46px, calc(env(safe-area-inset-bottom) + 46px))
      max(18px, calc(env(safe-area-inset-left) + 18px));
  }

  .menu-panel {
    width: min(100%, 900px);
    padding: 12px 14px;
    gap: 8px;
    border-radius: 20px;
  }

  .panel-intro h2 {
    font-size: clamp(1.4rem, 4.2vh, 1.8rem);
  }

  .menu-lower {
    grid-template-columns: minmax(0, 1.15fr) minmax(270px, 0.85fr);
    gap: 12px;
  }

  .menu-meta {
    gap: 8px;
  }

  .menu-meta .info-card {
    min-height: 68px;
    padding: 8px 12px;
    gap: 2px;
    border-radius: 14px;
  }

  .info-meta {
    font-size: 0.72rem;
  }

  .menu-actions,
  .stack-actions {
    gap: 6px;
  }

  .primary-button,
  .secondary-button {
    min-height: 46px;
    padding: 8px 14px;
  }

  body[data-screen="menu"] .footer {
    bottom: max(0px, env(safe-area-inset-bottom));
  }
}

@media (max-height: 499px) {
  .screen-panel:not(.hidden) {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
  }

  body[data-screen="menu"] #screen-menu {
    top: max(112px, calc(env(safe-area-inset-top) + 112px));
    bottom: max(60px, calc(env(safe-area-inset-bottom) + 60px));
    padding-top: 0;
    padding-bottom: 12px;
  }

  #screen-confirm,
  #screen-gameover,
  #screen-intro,
  #screen-help,
  #screen-scores,
  #screen-pause {
    padding-block: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 739px) {
  body[data-screen="menu"] #screen-menu { bottom: max(60px, calc(env(safe-area-inset-bottom) + 60px)); padding-bottom: 12px; }
  .screen-panel {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: max(62px, calc(env(safe-area-inset-top) + 62px));
  }
  .screen-panel > .panel { flex-shrink: 0; max-height: none; }
  .hud-row-top { padding: 58px 10px 0; gap: 6px; }
  .hud-stat-group-left { position: absolute; top: 8px; left: 10px; }
  .hud-stat-group-left .hud-pill:nth-child(2) { display: none; }
  .hud-pill { flex-direction: row; align-items: center; min-width: 0; gap: 6px; padding: 6px 8px; }
  .hud-pill strong { font-size: 1rem; }
  .hud-label { letter-spacing: 0.04em; }
  .question-card { width: 100%; min-width: 0; padding: 0; gap: 4px; }
  #question-text { order: 1; min-width: 0; min-height: 64px; padding: 8px; font-size: clamp(1.7rem, 8vw, 2.6rem); }
  .question-support { order: 2; }
  .question-support .judge-card { display: none; }
  .hud-brief { flex-direction: row; align-items: center; justify-content: center; padding: 5px 8px; gap: 6px; }
  .hud-brief strong { font-size: 0.82rem; }
  .hud-brief .hud-label { display: none; }
  .hud-brief-meta { font-size: 0.82rem; }
  .hud-stat-group-right { flex-wrap: nowrap; gap: 5px; }
  .hud-stat-group-right .hud-label { font-size: 0.62rem; }
  .hud-stat-group-right { padding-right: 0; }
}
