:root {
  --ink: #080d18;
  --ink-2: #101827;
  --paper: #f2ead8;
  --paper-dim: #b8af9d;
  --cinnabar: #e54834;
  --gold: #d9aa54;
  --jade: #53b887;
  --danger: #ef695b;
  --line: rgba(242, 234, 216, .15);
  --shadow: 0 18px 50px rgba(0, 0, 0, .42);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  color: var(--paper);
  background: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  overflow-x: hidden;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .22;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
  background-size: 38px 38px;
}
button { font: inherit; }
.screen { display: none; min-height: 100dvh; }
.screen.active { display: block; }

#home-screen { max-width: 900px; margin: auto; padding: max(36px, env(safe-area-inset-top)) 22px 44px; }
.hero { border-top: 1px solid var(--line); padding: 28px 0 30px; position: relative; }
.hero::after { content: "英"; position: absolute; right: 0; top: 20px; font: 700 92px/1 serif; color: rgba(229,72,52,.10); }
.eyebrow { color: var(--gold); letter-spacing: .22em; font-size: .72rem; font-weight: 700; }
h1 { margin: 8px 0 10px; font: 700 clamp(2.6rem, 9vw, 5.8rem)/.96 "Noto Serif TC", "PMingLiU", serif; letter-spacing: -.04em; }
.hero > p:last-child { margin: 0; max-width: 36rem; color: var(--paper-dim); line-height: 1.8; }
.mode-grid { display: grid; gap: 10px; }
.mode-card {
  width: 100%; min-height: 92px; display: grid; grid-template-columns: 48px 1fr auto; align-items: center;
  gap: 14px; border: 1px solid var(--line); border-radius: 4px; padding: 16px 18px;
  color: var(--paper); text-align: left; background: rgba(255,255,255,.025); transition: .2s ease;
}
.mode-card.available { cursor: pointer; border-color: rgba(217,170,84,.48); background: #141a24; }
.mode-card.available:hover, .mode-card.available:focus-visible { transform: translateX(5px); border-color: var(--gold); outline: none; }
.mode-card:disabled { opacity: .48; }
.mode-number { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid currentColor; border-radius: 50%; color: var(--gold); font-family: serif; }
.mode-copy { display: grid; gap: 5px; }
.mode-copy strong { font: 700 1.18rem/1.1 "Noto Serif TC", "PMingLiU", serif; }
.mode-copy small { color: var(--paper-dim); }
.mode-status { color: var(--gold); font-size: .72rem; letter-spacing: .08em; white-space: nowrap; }

#game-screen { min-height: 100dvh; max-width: 780px; margin: auto; padding: max(12px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom)); }
.game-shell { min-height: calc(100dvh - 28px); display: grid; grid-template-rows: auto auto minmax(300px, 1fr) auto auto; gap: 12px; }
.game-nav, .hud { display: flex; align-items: center; justify-content: space-between; }
.icon-btn { min-width: 46px; min-height: 44px; border: 1px solid var(--line); color: var(--paper); background: transparent; border-radius: 3px; cursor: pointer; }
.icon-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.game-title { font: 700 1rem/1 serif; letter-spacing: .18em; }
.hud { gap: 10px; border-block: 1px solid var(--line); padding: 11px 2px; }
.stat { display: grid; gap: 3px; }
.stat-label { color: var(--paper-dim); font-size: .63rem; letter-spacing: .15em; }
.stat-value { font: 700 1.25rem/1 ui-monospace, monospace; }
.health-value { color: var(--jade); }
.combo-value { color: var(--gold); }
.timer-wrap { flex: 1; max-width: 230px; }
.timer-track { height: 4px; background: rgba(255,255,255,.1); overflow: hidden; }
.timer-fill { width: 100%; height: 100%; background: var(--cinnabar); transform-origin: left; transition: transform .1s linear; }

.arena {
  position: relative; min-height: 310px; overflow: hidden; border: 1px solid var(--line); border-radius: 5px;
  background-color: #0c121e; touch-action: none; user-select: none; box-shadow: var(--shadow);
}
.arena::before { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(120deg, transparent 0 46px, rgba(255,255,255,.025) 47px 48px); }
.arena::after { content: "斬"; position: absolute; inset: 50% auto auto 50%; translate: -50% -50%; color: rgba(242,234,216,.025); font: 700 210px/1 serif; pointer-events: none; }
.answer-orb {
  position: absolute; z-index: 3; top: var(--lane); min-width: 100px; min-height: 54px; padding: 10px 17px;
  border: 1px solid rgba(242,234,216,.45); border-radius: 50%; color: var(--paper); background: #182232;
  font: 700 1.08rem/1.1 Georgia, serif; box-shadow: 0 10px 25px rgba(0,0,0,.35);
  scale: var(--option-scale, 1); animation-duration: var(--duration); animation-timing-function: linear; animation-fill-mode: forwards; will-change: transform;
}
.answer-orb::after { content: ""; position: absolute; inset: 5px; border: 1px solid rgba(217,170,84,.18); border-radius: inherit; }
.arena.frozen .answer-orb { animation-play-state: paused; }
.answer-orb.correct { border-color: var(--jade); background: #173629; color: #bdf4d8; }
.answer-orb.wrong { border-color: var(--danger); background: #40201f; color: #ffd2cd; }
.answer-orb.missed { opacity: .35; }
.answer-orb.from-left { left: -140px; animation-name: approach-from-left; }
.answer-orb.from-right { right: -140px; animation-name: approach-from-right; }
@keyframes approach-from-left { from { transform: translateX(0) rotate(-2deg); } to { transform: translateX(var(--travel)) rotate(2deg); } }
@keyframes approach-from-right { from { transform: translateX(0) rotate(2deg); } to { transform: translateX(calc(var(--travel) * -1)) rotate(-2deg); } }
.slash-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none; }
.swipe-hint { position: absolute; bottom: 12px; right: 14px; z-index: 1; color: rgba(242,234,216,.4); font-size: .68rem; letter-spacing: .12em; }

.clue { min-height: 74px; text-align: center; display: grid; place-items: center; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.clue p { margin: 0; font: 600 clamp(1.05rem, 4vw, 1.42rem)/1.55 Georgia, serif; text-wrap: pretty; }
.game-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.replay-btn { min-height: 46px; padding: 0 18px; border: 1px solid var(--gold); color: var(--gold); background: transparent; border-radius: 3px; cursor: pointer; }
.feedback { flex: 1; min-height: 46px; display: grid; align-content: center; text-align: right; color: var(--paper-dim); font-size: .82rem; }
.feedback strong { color: var(--paper); font-size: .98rem; }
.feedback.good strong { color: var(--jade); }
.feedback.bad strong { color: var(--danger); }

.loading-panel, .game-over { min-height: 70dvh; display: grid; place-items: center; text-align: center; padding: 30px; }
.loading-seal { width: 64px; height: 64px; border: 2px solid var(--gold); border-radius: 50%; display: grid; place-items: center; font-family: serif; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { scale: .88; opacity: .55; } }
.game-over-card { width: min(100%, 430px); border-block: 1px solid var(--gold); padding: 38px 22px; }
.game-over h2 { margin: 0 0 8px; font: 700 3.4rem/1 serif; }
.final-score { margin: 28px 0; font: 700 3rem/1 ui-monospace, monospace; color: var(--gold); }
.primary-btn { width: 100%; min-height: 52px; border: 0; color: var(--ink); background: var(--gold); font-weight: 800; cursor: pointer; }
.error-banner { padding: 14px; color: #ffd2cd; background: #3a1c1b; border: 1px solid var(--danger); }

@media (min-width: 720px) {
  .mode-grid { grid-template-columns: 1fr 1fr; }
  .mode-card:first-child { grid-column: 1 / -1; min-height: 112px; }
  .answer-orb { min-width: 124px; min-height: 60px; font-size: 1.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .answer-orb { animation: none !important; transform: none !important; }
  .answer-orb.from-left { left: calc(50% - 130px); }
  .answer-orb.from-right { right: calc(50% - 130px); }
}

/* The duel is a visual game surface, not a list of floating vocabulary. */
body.game-playing { overflow: hidden; overscroll-behavior: none; }
.arena {
  isolation: isolate;
  background:
    radial-gradient(circle at 68% 24%, rgba(217,170,84,.16), transparent 18%),
    linear-gradient(180deg, #101a2d 0%, #0c121e 58%, #070b13 100%);
}
.arena::before { z-index: 0; opacity: .55; }
.arena::after { z-index: 0; }
.arena-moon {
  position: absolute; z-index: 0; right: 13%; top: 9%; width: clamp(74px, 18vw, 144px); aspect-ratio: 1;
  border-radius: 50%; opacity: .6; background: radial-gradient(circle at 34% 30%, #fff8d8 0 3%, #d9c895 8% 38%, #8f815f 39% 41%, #d9c895 43% 56%, #9e916d 58% 61%, #d9c895 64%);
  box-shadow: 0 0 60px rgba(217,170,84,.18);
}
.duel-ground { position: absolute; z-index: 0; left: -10%; right: -10%; bottom: -7%; height: 33%; border-radius: 50% 50% 0 0; background: radial-gradient(ellipse at center, rgba(83,184,135,.18), rgba(6,11,18,.1) 60%, transparent 70%); }
.fighter { position: absolute; z-index: 1; bottom: -3%; width: min(36%, 245px); color: var(--gold); pointer-events: none; filter: drop-shadow(0 18px 16px rgba(0,0,0,.5)); }
.fighter-master { left: 50%; width: min(34%, 230px); transform: translateX(-50%); }
.fighter svg { display: block; width: 100%; height: auto; overflow: visible; }
.fighter-label { position: absolute; top: 10%; left: 50%; transform: translateX(-50%); z-index: 2; white-space: nowrap; color: currentColor; font-size: .64rem; font-weight: 700; letter-spacing: .1em; text-shadow: 0 2px 6px #000; }

.fighter-aura { fill: color-mix(in srgb, currentColor 9%, transparent); stroke: color-mix(in srgb, currentColor 38%, transparent); stroke-width: 2; }
.fighter-hat, .fighter-robe { fill: color-mix(in srgb, currentColor 48%, #080d18); stroke: color-mix(in srgb, currentColor 75%, #f2ead8); stroke-width: 2; }
.fighter-face { fill: #d7aa83; stroke: #0b1018; stroke-width: 3; }
.fighter-sleeve { fill: color-mix(in srgb, currentColor 33%, #080d18); stroke: color-mix(in srgb, currentColor 60%, #f2ead8); stroke-width: 2; }
.fighter-sword { fill: #dfe8ea; stroke: #fff; stroke-width: 1; }
.fighter-blade { fill: currentColor; }
.fighter-belt { fill: #080d18; stroke: currentColor; stroke-width: 3; }
.answer-orb { z-index: 3; }
.slash-canvas { z-index: 5; }
.swipe-hint { z-index: 6; }
.fullscreen-btn { font-size: .7rem; white-space: nowrap; }
.orientation-gate { display: none; }

@media (orientation: landscape) and (max-height: 600px) {
  #game-screen { max-width: none; padding: max(5px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  .game-shell { min-height: calc(100dvh - 11px); grid-template-rows: 32px 43px minmax(145px, 1fr) minmax(42px, auto) 42px; gap: 5px; }
  .game-nav { min-height: 32px; }
  .icon-btn { min-width: 42px; min-height: 32px; font-size: .72rem; }
  .game-title { font-size: .82rem; }
  .hud { padding: 6px 2px; }
  .stat { gap: 1px; }
  .stat-label { font-size: .54rem; }
  .stat-value { font-size: 1rem; }
  .timer-wrap { max-width: 42vw; }
  .arena { min-height: 145px; }
  .clue { min-height: 42px; padding: 5px 12px; }
  .clue p { font-size: clamp(.92rem, 2.8vw, 1.25rem); line-height: 1.2; }
  .game-actions { min-height: 42px; }
  .replay-btn { min-height: 40px; padding: 0 12px; font-size: .8rem; }
  .feedback { min-height: 40px; font-size: .7rem; }
  .feedback strong { font-size: .82rem; }
  .fighter { width: min(29%, 205px); bottom: -13%; }
  .fighter-label { font-size: .53rem; }
}

@media (orientation: portrait) and (max-width: 700px) {
  .game-shell > :not(.orientation-gate) { filter: blur(3px); opacity: .35; pointer-events: none; }
  .orientation-gate { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(4,7,13,.78); }
  .orientation-card { width: min(100%, 340px); display: grid; justify-items: center; gap: 14px; padding: 28px 22px; text-align: center; border: 1px solid rgba(217,170,84,.65); background: #101827; box-shadow: var(--shadow); }
  .orientation-mark { color: var(--gold); font: 700 4rem/1 serif; }
  .orientation-card strong { font: 700 1.45rem/1.2 "Noto Serif TC", serif; }
  .orientation-card small { color: var(--paper-dim); line-height: 1.65; }
  .orientation-card .primary-btn { margin-top: 3px; }
}
