:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  --text: #fff3e4;
  --muted: #d8c9e1;
  --gold: #ffcb78;
  --line: #d3afdb55;
  --surface: #1f142de8;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
  background: #140d25;
  color: var(--text);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; overflow-x: clip; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .46; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
#game { position: relative; min-height: 100svh; isolation: isolate; }
#game::before { content: ""; position: fixed; z-index: -1; inset: 0; background: linear-gradient(95deg, #130b22f0, #1c113655 70%), url('/art/moonfall.jpg') center 72% / cover; }
#game:has(.selection:not([hidden]))::before, #game:has(.waiting:not([hidden]))::before { background-image: linear-gradient(#140c26c9, #160d2ce8), url('/art/moonfall.jpg'); }
#game:has(.arena:not([hidden]))::before { background-image: linear-gradient(#100819e8, transparent 34%, transparent 70%, #140a22d9), url('/art/moonfall.jpg'); }
.topbar { position: absolute; inset: 0 0 auto; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: 14px clamp(14px, 4vw, 52px); gap: 10px; }
.brand, .eyebrow { color: var(--gold); font: 750 .83rem/1.4 var(--mono); letter-spacing: .11em; }
.brand span { margin-right: 3px; }
.top-actions, .setup-actions, .input-row { display: flex; gap: 9px; align-items: stretch; }
.primary, .quiet { min-height: 40px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); font-weight: 750; }
.primary { color: #211127; background: var(--gold); border-color: #ffe2ad; }
.primary:hover:not(:disabled) { background: #ffdfa4; }
.quiet { background: #1a1129d9; color: var(--text); }
.quiet:hover:not(:disabled) { border-color: var(--gold); }
.input-row input { min-width: 0; flex: 1; width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: #130d20f5; color: var(--text); }
.input-row input::placeholder { color: #cdbbd9; }
.screen { min-height: 100svh; padding: 70px clamp(15px, 5vw, 70px) 28px; }
.welcome { display: grid; align-items: center; position: relative; overflow: hidden; }
.welcome-copy { z-index: 1; width: min(100%, 620px); margin-left: max(0px, calc((100vw - 1380px) / 2)); }
h1 { margin: 0; font-size: clamp(2.6rem, 6vw, 5.2rem); line-height: .97; letter-spacing: -.065em; font-weight: 900; }
.welcome h1 { font-size: clamp(4.25rem, 12vw, 10rem); line-height: .78; }
.welcome h1 em { display: block; font-style: normal; color: var(--gold); }
.eyebrow { margin: 0 0 12px; }
.welcome-art { position: absolute; right: 7%; bottom: 7%; height: 76%; width: 46%; display: flex; justify-content: center; align-items: end; }
.welcome-art img { width: 100%; height: 100%; object-fit: contain; object-position: bottom; transform: scaleX(-1); filter: drop-shadow(0 0 42px #b28bec60); }
#name-form { margin-top: clamp(24px, 5vh, 55px); max-width: 450px; }
#name-form label, .online-actions label { display: block; margin-bottom: 8px; color: var(--muted); }
.feedback { color: var(--muted); line-height: 1.35; margin: 7px 0 0; }
.selection { display: grid; place-items: center; }
.selection-panel { width: min(100%, 870px); padding: clamp(16px, 3.2vw, 34px); border: 1px solid var(--line); background: var(--surface); border-radius: 16px; box-shadow: 0 25px 75px #07020d90; }
.selection h1 { font-size: clamp(2.3rem, 5vw, 4.3rem); }
fieldset { padding: 0; margin: 15px 0 0; border: 0; min-width: 0; }
legend { color: var(--muted); font: 700 .84rem var(--mono); margin-bottom: 8px; }
.option { position: relative; display: block; cursor: pointer; min-width: 0; }
.option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.option > span { display: flex; justify-content: center; align-items: center; height: 100%; min-height: 36px; padding: 6px; border: 1px solid var(--line); border-radius: 7px; background: #170f25; color: var(--muted); font-weight: 700; text-align: center; }
.option > span:hover { border-color: var(--gold); }
.option input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }
.option input:checked + span { background: #382344; color: var(--text); border-color: var(--gold); }
.option:has(input:disabled) { opacity: .48; cursor: default; }
.mode-options, .segments, .roster { display: grid; gap: 7px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mode-options .option > span { flex-direction: column; min-height: 82px; }
.mode-icon { color: var(--gold); font: 800 1.55rem var(--mono); }
.setup-options { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.roster { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.roster .option > span { gap: 7px; justify-content: start; min-height: 60px; text-align: left; font-size: .88rem; }
.roster small { font-size: .75rem; color: var(--muted); display: block; }
.portrait { position: relative; width: 43px; height: 48px; flex: 0 0 43px; overflow: hidden; background: #2f2040; border-radius: 3px; }
.portrait img { position: absolute; left: -9px; width: 63px; }
.lore { min-height: 1.4em; color: var(--muted); margin: 7px 0 0; font-size: .88rem; }
.setup-actions { margin-top: 15px; flex-wrap: wrap; }
.online-actions { margin-top: 10px; max-width: 350px; }
#verification:not(:empty) { margin-top: 10px; min-width: 0; }
.waiting { display: flex; justify-content: center; align-items: start; flex-direction: column; max-width: 1080px; margin: auto; }
.room-code { font: 900 clamp(2.1rem, 8vw, 4.4rem) var(--mono); color: var(--gold); letter-spacing: .14em; }
.arena { display: grid; grid-template-rows: auto minmax(275px, 1fr) auto; min-height: 100svh; padding-bottom: 16px; overflow-x: clip; }
.hud { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 15px; align-items: end; z-index: 2; }
.nameplate { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 3px 8px; margin-bottom: 5px; overflow-wrap: anywhere; text-shadow: 0 2px 4px #13081d; }
.nameplate strong { font-size: clamp(1rem, 2.3vw, 1.55rem); }
.nameplate span { color: var(--gold); font: 800 .83rem var(--mono); }
.rival .nameplate { flex-direction: row-reverse; text-align: right; }
.health { height: clamp(11px, 2vh, 17px); border: 1px solid #f6dfaa; background: #27152e; overflow: hidden; transform: skewX(-9deg); }
.health i { display: block; height: 100%; width: var(--remaining, 100%); transition: width .3s; background: linear-gradient(#ffe197, #ff9556); }
.rival .health i { margin-left: auto; background: linear-gradient(#e3ceff, #a284ff); }
.arena-label { text-align: center; min-width: 3.75rem; }
.arena-label b { display: block; color: var(--gold); font: italic 900 clamp(1.25rem, 3vw, 2.4rem) system-ui; }
.arena-label small { display: block; font: 700 .67rem var(--mono); }
#match-score { margin-top: 3px; color: var(--gold); font-size: .85rem; }
.stage { position: relative; isolation: isolate; min-height: 275px; }
.fighter-side { position: absolute; bottom: 0; height: min(68%, 560px); width: 32%; container-type: size; --toward: 1; --accent: #ffb258; }
.player-side { left: 7%; }
.cpu-side { right: 7%; --toward: -1; --accent: #9eaaff; }
.combatant { position: absolute; inset: 0 -36% -2.6%; transform-origin: center 96%; z-index: 1; }
.combatant img, .combatant canvas { width: 100%; height: 100%; object-fit: contain; object-position: bottom; transform: scaleX(var(--toward)); filter: drop-shadow(0 5px 7px #120c22a0); }
.combat-timer { position: absolute; bottom: min(95%, 105cqw); left: 50%; translate: -50% 0; min-width: 57px; border: 1px solid #e6bee6; padding: 3px 7px 4px; background: #1a102ce8; border-radius: 7px; overflow: hidden; color: var(--gold); text-align: center; font: 900 clamp(1.35rem, 4vw, 2.35rem)/1.15 var(--mono); z-index: 3; }
.combat-timer i { position: absolute; left: 0; bottom: 0; height: 3px; width: var(--remaining, 100%); background: var(--gold); }
.prompt-card { position: absolute; z-index: 2; top: 8%; left: 50%; translate: -50% 0; width: min(560px, 87%); padding: 12px 16px; text-align: center; border: 1px solid #d0ace59e; border-radius: 10px; background: #1d122dbf; box-shadow: 0 5px 22px #160b30a0; }
.prompt-card .eyebrow { margin-bottom: 4px; }
.prompt-card h1 { font-size: clamp(1.85rem, 5.5vw, 4.1rem); overflow-wrap: anywhere; }
.prompt-card p:last-child { margin: 6px 0 0; color: var(--muted); }
#score-form { margin-top: 8px; }
.console { width: min(660px, 93%); margin: 10px 0 0 7%; z-index: 4; }
.console-footer { display: flex; align-items: center; gap: 7px; margin-top: 6px; }
.console-footer p { flex: 1; margin: 0; text-shadow: 0 2px 2px #10091d; }
.console-footer .quiet { font-size: .85rem; min-height: 33px; padding: 4px 8px; }
.combatant img { padding-inline: 20%; }
.combatant[data-flash] { filter: brightness(1.35); }
.combatant[data-charge]::before {
  content: "";
  position: absolute;
  inset: 13% 20% 1%;
  background: radial-gradient(ellipse at 50% 70%, #fff4d3a0, transparent 29%),
    repeating-conic-gradient(from 8deg, transparent 0 19deg, var(--accent) 24deg 27deg, transparent 31deg 38deg);
  mask-image: radial-gradient(ellipse, #000 15%, #000b 42%, transparent 69%);
  animation: energy-charge .46s ease-in both;
  pointer-events: none;
}
@keyframes energy-charge {
  from { opacity: 0; scale: .68; rotate: -16deg; }
  to { opacity: .84; scale: 1.2; rotate: 12deg; }
}
.stage.resolving :is(.prompt-card, .combat-timer) { opacity: 0; pointer-events: none; }
.duel-impact {
  --hit-color: #ffcb78;
  position: absolute;
  z-index: 3;
  width: clamp(54px, 11vw, 150px);
  aspect-ratio: 1;
  translate: -50% -50%;
  opacity: 0;
  pointer-events: none;
  color: var(--hit-color);
  filter: drop-shadow(0 0 10px var(--hit-color));
}
.duel-impact::before, .duel-impact::after { content: ""; position: absolute; inset: 0; }
.duel-impact::before {
  background: radial-gradient(circle, #fff 0 9%, #fff7d0 16%, var(--hit-color) 42%, transparent 77%);
  clip-path: polygon(50% 0, 56% 36%, 83% 8%, 66% 41%, 100% 35%, 74% 52%, 95% 78%, 65% 67%, 57% 100%, 46% 69%, 15% 92%, 34% 58%, 0 51%, 34% 46%, 8% 18%, 43% 34%);
}
.duel-impact::after { inset: 25%; border: 2px solid currentColor; border-radius: 50%; }
.duel-impact[data-effect="guard"]::before { inset: 9%; background: #a6efff88; clip-path: polygon(50% 0, 95% 20%, 91% 63%, 50% 100%, 9% 63%, 5% 20%); }
.duel-impact[data-effect="guard"]::after { inset: 12%; border: 4px double #e2faff; box-shadow: 0 0 12px #83def6; }
.duel-impact[data-effect="slash"]::after { inset: 2% 5%; border-width: 0 8px 4px 2px; border-color: transparent currentColor #fff; rotate: -22deg; }
.duel-energy {
  position: absolute;
  z-index: 4;
  width: clamp(86px, 20vw, 290px);
  aspect-ratio: 1.6;
  translate: -50% -50%;
  opacity: 0;
  pointer-events: none;
  color: var(--hit-color);
  filter: drop-shadow(0 0 11px currentColor);
}
.duel-energy::before, .duel-energy::after { content: ""; position: absolute; inset: 0; border-radius: 50%; }
.duel-energy::before { border: 8px solid transparent; border-top-color: currentColor; border-inline-end-color: #fff8db; }
.duel-energy::after { inset: 12% 18%; border: 3px solid transparent; border-top-color: #fff; border-inline-end-color: currentColor; }
dialog { width: min(540px, calc(100% - 25px)); color: var(--text); background: #21152e; border: 1px solid var(--line); border-radius: 12px; }
dialog::backdrop { background: #0a0513b6; }
dialog header { display: flex; justify-content: space-between; gap: 8px; }
dialog h2, dialog p { margin: 0 0 7px; }
#scores { padding-left: 24px; }
#scores li { margin-block: 5px; }
#scores em { margin-left: .55em; color: var(--muted); }
#scores strong { float: right; color: var(--gold); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (min-width: 850px) {
  .console { width: min(480px, 46%); margin-left: 2%; }
  .stage { min-height: 330px; }
}
@media (641px <= width < 850px) {
  .fighter-side { width: 38%; }
  .player-side { left: 4%; }
  .cpu-side { right: 4%; }
}
@media (max-width: 640px) {
  .topbar { padding-inline: 12px; }
  .topbar .quiet { font-size: .78rem; min-height: 33px; padding: 4px 7px; }
  .brand { font-size: .72rem; }
  .welcome-art { right: -13%; width: 75%; height: 72%; opacity: .5; }
  .setup-options { grid-template-columns: 1fr; gap: 0; }
  .roster { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mode-options .option > span { min-height: 68px; font-size: .84rem; }
  .segments .option > span { font-size: .82rem; }
  .hud { gap: 7px; }
  .fighter-side { width: 44%; height: 58%; }
  .player-side { left: 0; }
  .cpu-side { right: 0; }
  .prompt-card { top: 6%; }
  .combat-timer { min-width: 42px; }
  .console { width: 100%; margin-left: 0; }
  .console-footer { font-size: .82rem; }
  .arena { grid-template-rows: auto minmax(230px, 1fr) auto; }
  .stage { min-height: 230px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }

}
