:root {
  color-scheme: dark;
  --paper: #f4e8c1;
  --ink: #17152a;
  --violet: #6250a7;
  --cyan: #46d7d0;
  --coral: #ff746c;
  --gold: #ffd269;
  --deep: #111022;
}

* { box-sizing: border-box; }

html { background: #0d0d1b; }

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  color: var(--paper);
  background:
    radial-gradient(circle at 20% 15%, rgba(98, 80, 167, .26), transparent 32rem),
    linear-gradient(165deg, #0d0d1b 0%, #18142d 62%, #101524 100%);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
}

button { font: inherit; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.shell { width: min(1120px, 100%); margin: 0 auto; padding: 18px clamp(12px, 3vw, 32px) 48px; }
.masthead { display: flex; align-items: end; justify-content: space-between; gap: 16px; padding: 8px 2px 14px; border-bottom: 1px solid rgba(244,232,193,.32); }
.eyebrow, .stamp { margin: 0 0 4px; color: var(--cyan); font: 700 .76rem/1.2 ui-monospace, monospace; letter-spacing: .15em; text-transform: uppercase; }
h1 { margin: 0; font-family: serif; font-size: clamp(2rem, 7vw, 4.5rem); line-height: .9; letter-spacing: .08em; }
h2 { margin: 0 0 12px; font-size: clamp(1.3rem, 3vw, 2rem); }
.header-actions, .result-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.square-button { min-height: 44px; padding: 9px 13px; border: 1px solid rgba(244,232,193,.48); color: var(--paper); background: #1a1930; cursor: pointer; }
.help-panel { margin: 12px 0; padding: 16px 18px; border-left: 5px solid var(--cyan); background: #17172a; }
.help-panel p { margin: 6px 0; line-height: 1.7; }

.game-frame { position: relative; margin-top: 16px; border: 1px solid rgba(244,232,193,.36); box-shadow: 0 24px 70px rgba(0,0,0,.32); background: #121226; }
.hud-ribbon { display: grid; grid-template-columns: repeat(5, 1fr); border-bottom: 1px solid rgba(244,232,193,.2); background: #0c0c19; }
.hud-ribbon > div { padding: 9px 11px; border-right: 1px solid rgba(244,232,193,.13); }
.hud-label { display: block; color: #b8b0d3; font-size: .68rem; letter-spacing: .08em; }
.hud-ribbon strong { display: block; margin-top: 2px; color: #fff8d8; font-size: clamp(.95rem, 2.3vw, 1.25rem); }
.context-strip { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; padding: 12px clamp(12px, 3vw, 22px); background: var(--paper); color: var(--ink); border-bottom: 5px double var(--ink); }
#contextBadge { grid-row: 1 / 3; align-self: center; padding: 5px 8px; background: var(--ink); color: var(--paper); font-weight: 800; writing-mode: vertical-rl; letter-spacing: .18em; }
#contextText { margin: 0; font-family: serif; font-size: clamp(1rem, 2.4vw, 1.32rem); font-weight: 800; line-height: 1.5; }
#contextHint { margin: 0; color: #554b55; font-size: .88rem; }

.arena-wrap { position: relative; overflow: hidden; background: #0b0c18; }
#arena { display: block; width: 100%; height: auto; max-height: 66vh; min-height: 300px; touch-action: pan-y; cursor: crosshair; background: #0b0c18; }
.toast { position: absolute; top: 14px; left: 50%; z-index: 4; transform: translateX(-50%); min-width: min(92%, 280px); padding: 9px 14px; border: 1px solid var(--gold); color: #151223; background: var(--gold); font-weight: 900; text-align: center; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; }
.toast.show { opacity: 1; transform: translate(-50%, 6px); }
.overlay { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 18px; background: rgba(9,8,22,.82); }
.overlay[hidden] { display: none; }
.overlay-card { width: min(600px, 100%); max-height: 95%; overflow-y: auto; padding: clamp(20px, 4vw, 34px); border: 2px solid var(--paper); border-left: 10px solid var(--coral); background: #18162d; box-shadow: 12px 12px 0 rgba(70,215,208,.24); }
.overlay-card.compact { max-width: 480px; }
.overlay-card p, .overlay-card li { line-height: 1.65; }
.overlay-card ul { padding-left: 1.4em; }
.launch-button { min-height: 48px; padding: 11px 20px; border: 0; color: #10101e; background: var(--cyan); box-shadow: 5px 5px 0 #2a2355; font-weight: 900; cursor: pointer; }

.ammo-deck { display: grid; grid-template-columns: minmax(130px, .65fr) 2fr; align-items: stretch; border-top: 1px solid rgba(244,232,193,.2); border-bottom: 1px solid rgba(244,232,193,.2); }
.deck-title { padding: 12px 14px; background: #0b0b18; }
.deck-title span { display: block; color: var(--coral); font: 700 .68rem ui-monospace, monospace; letter-spacing: .12em; }
.deck-title strong { display: block; margin-top: 6px; font-size: .86rem; }
.ammo-buttons { display: grid; grid-template-columns: repeat(3, 1fr); }
.ammo-button { min-height: 62px; padding: 8px; border: 0; border-left: 1px solid rgba(244,232,193,.22); color: var(--paper); background: #1a1930; cursor: pointer; }
.ammo-button strong, .ammo-button small { display: block; }
.ammo-button small { margin-top: 3px; color: #bdb5d3; }
.ammo-button[aria-pressed="true"] { color: #121222; background: var(--gold); box-shadow: inset 0 -5px 0 var(--coral); }
.ammo-button[aria-pressed="true"] small { color: #352f44; }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: center; padding: 14px; background: #111123; }
.move-pad { display: grid; grid-template-columns: repeat(3, minmax(44px, 62px)); grid-template-rows: repeat(3, 44px); gap: 4px; justify-content: center; }
.move-button { border: 1px solid rgba(244,232,193,.44); color: var(--paper); background: #23213b; touch-action: manipulation; user-select: none; }
.move-button.active { color: #10101f; background: var(--cyan); }
.move-button.up { grid-column: 2; }
.move-button.left { grid-column: 1; grid-row: 2; }
.pad-core { grid-column: 2; grid-row: 2; display: grid; place-items: center; color: #8e87a7; font-size: .68rem; }
.move-button.right { grid-column: 3; grid-row: 2; }
.move-button.down { grid-column: 2; grid-row: 3; }
.fire-zone { display: grid; gap: 8px; justify-items: stretch; }
.charge-track { height: 10px; border: 1px solid rgba(244,232,193,.34); background: #090916; overflow: hidden; }
.charge-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--gold), var(--coral)); }
.fire-button { min-height: 76px; border: 2px solid var(--coral); color: var(--paper); background: #311c38; touch-action: manipulation; user-select: none; cursor: pointer; }
.fire-button.charging { background: #573042; box-shadow: 0 0 20px rgba(255,116,108,.35); }

.quiz-panel, .result-panel { margin-top: 18px; padding: clamp(18px, 4vw, 30px); border: 1px solid rgba(244,232,193,.42); background: #17162a; }
.quiz-question { font-family: serif; font-size: clamp(1.1rem, 3vw, 1.45rem); line-height: 1.7; }
.quiz-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.quiz-choice { min-height: 52px; padding: 10px; border: 1px solid #77708e; color: var(--paper); background: #24213a; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.quiz-choice.correct { border-color: var(--cyan); background: #123c40; }
.quiz-choice.wrong { border-color: var(--coral); background: #4a252f; }
.quiz-explanation { margin: 14px 0; padding: 12px; border-left: 5px solid var(--gold); color: #191529; background: var(--paper); line-height: 1.65; }
.result-score { display: flex; align-items: baseline; gap: 16px; margin: 18px 0; padding: 15px 0; border-block: 1px solid rgba(244,232,193,.25); }
.result-score strong { color: var(--gold); font: 900 clamp(2rem, 8vw, 4.5rem) ui-monospace, monospace; }
.leaderboard-panel { margin-top: 16px; max-width: 100%; overflow-x: auto; padding: 12px; border: 1px solid rgba(244,232,193,.3); color: var(--paper); background: #0d0d1b; }

@media (max-width: 640px) {
  .shell { padding-inline: 8px; }
  .masthead { align-items: center; }
  .header-actions { max-width: 150px; }
  .hud-ribbon { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .hud-ribbon > div { padding: 7px 5px; text-align: center; }
  .hud-label { font-size: .58rem; }
  .context-strip { grid-template-columns: 32px 1fr; }
  #arena { min-height: 340px; }
  .ammo-deck { grid-template-columns: 1fr; }
  .deck-title { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
  .deck-title strong { text-align: right; }
  .ammo-button { border-left: 0; border-top: 1px solid rgba(244,232,193,.2); font-size: .84rem; }
  .controls { gap: 8px; padding-inline: 8px; }
  .quiz-choices { grid-template-columns: 1fr; }
  .overlay { align-items: start; overflow-y: auto; }
  .overlay-card { margin: 8px 0 20px; box-shadow: 7px 7px 0 rgba(70,215,208,.24); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition-duration: .01ms !important; }
}
