/* One screen, no scrolling during a duel: header, arena, move panel and chat share
   the viewport height. On wide screens the chat sits beside the arena. */
@font-face { font-family: "Press Start 2P"; src: url("fonts/PressStart2P-Regular.ttf") format("truetype"); font-display: swap; }
:root {
  --night: #050B24; --panel: #0D1A3F; --panel-2: #142A63; --line: #24397A;
  --blue: #19A6EB; --blue-dark: #0B6FA3; --ink: #EAF4FB; --muted: #8FA3C8;
  --gold: #FFC83D; --win: #1FD49E; --lose: #FF5A6A; --paper: #FFFFFF; --paper-ink: #050B24;
  --pixel: "Press Start 2P", ui-monospace, Menlo, monospace;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--night); color: var(--ink); font: 16px/1.5 var(--font);
  background-image: radial-gradient(1px 1px at 12% 18%, #ffffff55 50%, transparent 51%), radial-gradient(1px 1px at 72% 8%, #ffffff44 50%, transparent 51%), radial-gradient(1.5px 1.5px at 88% 32%, #ffffff33 50%, transparent 51%), radial-gradient(1px 1px at 36% 42%, #ffffff33 50%, transparent 51%);
  background-size: 260px 260px;
}
[hidden] { display: none !important; }
a { color: inherit; }
.shell { max-width: 1400px; height: 100%; margin: 0 auto; padding: 14px max(16px, env(safe-area-inset-right, 0px)) 14px max(16px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 12px; }
.shell > * { flex: none; }

header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
header > div:first-child { min-width: 0; }
.brand { font-family: var(--pixel); font-size: 9px; letter-spacing: .06em; color: var(--muted); text-decoration: none; }
.brand span { color: var(--line); }
.brand:hover { color: var(--ink); }
h1 { margin: 6px 0 0; font-family: var(--pixel); font-weight: 400; font-size: clamp(15px, 4.6vw, 24px); line-height: 1.35; color: var(--blue); text-shadow: 3px 3px 0 var(--blue-dark), 6px 6px 0 #000; }
.tagline { margin: 6px 0 0; color: var(--muted); font-size: .95rem; }
body.in-game .tagline { display: none; }
body.in-game h1 { font-size: clamp(12px, 3.4vw, 18px); text-shadow: 2px 2px 0 var(--blue-dark), 4px 4px 0 #000; }
.game-nav { display: flex; align-items: center; gap: 12px; flex: none; color: var(--muted); }

.panel { background: var(--panel); border: 3px solid var(--line); border-radius: 6px; padding: 18px; display: grid; gap: 14px; min-width: 0; box-shadow: 0 6px 0 #00000066; }
.panel h2 { margin: 0; font-family: var(--pixel); font-weight: 400; font-size: 12px; line-height: 1.6; color: var(--gold); letter-spacing: .04em; }
.panel p { margin: 0; }
#msg-view, #start-view, #join-view { max-width: 620px; width: 100%; }
.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: .85rem; }
.error { color: var(--lose); font-weight: 600; }
.label, .field > label { font-family: var(--pixel); font-size: 9px; letter-spacing: .06em; color: var(--muted); }
.field { display: grid; gap: 8px; }
fieldset { border: 0; margin: 0; padding: 0; }
legend { padding: 0; margin-bottom: 8px; }
#start-form, #join-form { gap: 16px; }
input[type="text"] { font: inherit; color: var(--ink); background: var(--night); border: 3px solid var(--line); border-radius: 4px; padding: 10px 12px; width: 100%; min-width: 0; }
input[type="text"]:focus-visible { outline: none; border-color: var(--blue); }

.btn { font-family: var(--pixel); font-size: 11px; line-height: 1.4; border: 0; border-radius: 4px; padding: 14px 18px; cursor: pointer; background: var(--blue); color: var(--paper-ink); box-shadow: 0 4px 0 var(--blue-dark); transition: transform .06s, box-shadow .06s; }
.btn:hover { filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--blue-dark); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: transparent; color: var(--muted); box-shadow: none; border: 3px solid var(--line); padding: 8px 10px; font-size: 8px; }
.btn.ghost:hover { color: var(--ink); border-color: var(--blue); }
.btn:focus-visible, .move:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.copyrow { display: flex; gap: 8px; }
.copyrow input { font-size: .85rem; }
.copyrow .btn { white-space: nowrap; padding: 10px 14px; font-size: 9px; }

.targets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.targets input { position: absolute; opacity: 0; pointer-events: none; }
.targets label { font-family: var(--pixel); font-size: 12px; color: var(--ink); text-align: center; padding: 12px 4px; border: 3px solid var(--line); border-radius: 4px; background: var(--panel-2); cursor: pointer; box-shadow: 0 4px 0 #050B24; }
.targets input:checked + label { border-color: var(--gold); color: var(--gold); }
.targets input:focus-visible + label { outline: 3px solid var(--gold); outline-offset: 2px; }

.fighters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fighters input { position: absolute; opacity: 0; pointer-events: none; }
.fighters label { display: grid; justify-items: center; gap: 4px; padding: 8px 6px 10px; border: 3px solid var(--line); border-radius: 6px; background: var(--panel-2); cursor: pointer; box-shadow: 0 4px 0 #050B24; font-family: var(--pixel); font-size: 9px; color: var(--muted); }
.fighters label .sprite { width: min(120px, 100%); }
.fighters input:checked + label { border-color: var(--gold); color: var(--gold); }
.fighters input:focus-visible + label { outline: 3px solid var(--gold); outline-offset: 2px; }
.solo { display: flex; align-items: center; gap: 14px; }
.solo .sprite { width: 132px; flex: none; }
.solo > div:last-child { min-width: 0; display: grid; gap: 6px; }

/* ---------- Game layout: fills the screen; chat beside the arena on wide screens ---------- */
.game { flex: 1 1 auto; min-height: 0; display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(140px, 280px) auto auto; grid-template-areas: "invite" "arena" "controls" "chat"; align-content: center; }
#invite { grid-area: invite; } #arena { grid-area: arena; } #controls { grid-area: controls; } .game > .chat { grid-area: chat; }
.game > .panel { padding: 12px 14px; gap: 10px; }
.chat { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.chat h2 { display: none; }
.chat .log { max-height: 64px; }
@media (min-width: 900px) {
  .game { gap: 14px; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: auto minmax(0, 360px) auto; grid-template-areas: "invite chat" "arena chat" "controls chat"; }
  .game > .chat { contain: size; }
  /* Without the invite the chat starts level with the arena, not in the empty row's gap above it. */
  .game:has(> #invite[hidden]) > .chat { grid-row: 2 / span 2; }
  .chat h2 { display: block; }
  .chat .log { max-height: none; min-height: 0; flex: 1 1 0; }
}

/* ---------- Arena ---------- */
.arena { position: relative; overflow: hidden; border: 3px solid var(--line); border-radius: 6px; min-height: 0; container-type: size; background: linear-gradient(#081446 0%, #12307C 58%, #091640 58.2%); box-shadow: 0 6px 0 #00000066; isolation: isolate; }
.arena .shelves { position: absolute; left: -2%; right: -2%; top: 16%; height: 42%; opacity: .5; z-index: -1;
  background:
    repeating-linear-gradient(180deg, transparent 0 calc(33.3% - 5px), #2A4CA8 calc(33.3% - 5px) 33.3%),
    repeating-linear-gradient(90deg, transparent 0 18%, #1B3A8E 18% 19.5%),
    repeating-linear-gradient(90deg, #C98B4B33 0 6%, transparent 6% 9%, #C98B4B22 9% 13%, transparent 13% 18%); }
.arena .floor { position: absolute; left: 0; right: 0; bottom: 0; height: 41.8%; z-index: -1; background: repeating-conic-gradient(#0E2264 0 25%, #0A1950 0 50%) 0 0 / 28px 28px; }
.arena .floor::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--blue); opacity: .55; }

.hud { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; z-index: 3; }
.plate { background: #050B24D9; border: 2px solid var(--line); border-radius: 4px; padding: 6px 8px; display: grid; gap: 5px; min-width: 0; max-width: 30%; }
.plate.right { text-align: right; }
.plate .nm { font-family: var(--pixel); font-size: clamp(7px, 2.2vw, 10px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate .st { font-family: var(--pixel); font-size: clamp(7px, 2vw, 9px); color: var(--gold); font-variant-numeric: tabular-nums; }
.plate.me { border-color: var(--blue); }
.round { font-family: var(--pixel); font-size: clamp(7px, 2vw, 9px); color: var(--muted); padding-top: 8px; white-space: nowrap; }

.fighter { position: absolute; bottom: 2%; width: min(70cqh, 40cqw, 220px); z-index: 2; transform: translateX(-50%); transition: transform .38s cubic-bezier(.5, 0, .7, 1); }
.fighter.left { left: 29%; }
.fighter.right { left: 71%; }
.sprite { display: block; width: 100%; aspect-ratio: 32 / 30; }
.fighter .shadow { position: absolute; left: 28%; right: 28%; bottom: 1%; height: 6%; border-radius: 50%; background: #00000066; z-index: -1; }
.arena.dash .fighter.left { transform: translateX(-20%); }
.arena.dash .fighter.right { transform: translateX(-80%); }

.bubble { position: absolute; left: 50%; bottom: 86%; transform: translateX(-50%); background: var(--paper); color: var(--paper-ink); border: 3px solid var(--paper-ink); border-radius: 6px; padding: 4px 10px; font-family: var(--pixel); font-size: 10px; line-height: 1.5; white-space: nowrap; max-width: 150%; overflow: hidden; text-overflow: ellipsis; box-shadow: 3px 3px 0 #00000088; }
.bubble::after { content: ""; position: absolute; left: 50%; top: 100%; margin-left: -6px; border: 6px solid transparent; border-top-color: var(--paper-ink); }
.bubble.big { font-size: clamp(20px, min(10cqh, 8cqw), 44px); padding: 2px 8px; font-family: var(--font); line-height: 1.15; }
.bubble.chat { font-family: var(--font); font-size: 13px; font-weight: 600; white-space: normal; width: max-content; max-width: min(170px, 42vw); text-align: center; }
.bubble.pop { animation: pop .35s cubic-bezier(.3, 1.7, .5, 1) both; }
.bubble.trophy { border-color: var(--gold); box-shadow: 0 0 0 3px var(--paper-ink), 0 0 18px var(--gold); animation: pop .35s cubic-bezier(.3, 1.7, .5, 1) both, bob 1.2s ease-in-out .35s infinite; }
@keyframes bob { 50% { translate: 0 -6px; } }
.confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 6; }
@keyframes pop { from { transform: translateX(-50%) scale(.2); opacity: 0; } }

/* The verdict takes the place of the round label in the HUD, clear of both Pickis. */
.banner { position: absolute; left: 30%; right: 30%; top: 12px; text-align: center; z-index: 4; font-family: var(--pixel); font-size: clamp(9px, 3cqw, 20px); line-height: 1.2; text-shadow: 3px 3px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000; animation: slam .5s cubic-bezier(.3, 1.6, .5, 1) both; }
.banner.win { color: var(--win); } .banner.lose { color: var(--lose); } .banner.draw { color: var(--gold); }
@keyframes slam { from { transform: scale(2.6); opacity: 0; } }

.arena::after { content: ""; position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 5; }
.arena.clash::after { animation: flash .35s ease-out; }
.arena.clash { animation: shake .35s linear; }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }
@keyframes shake { 20% { translate: -5px 2px; } 40% { translate: 5px -2px; } 60% { translate: -3px 1px; } 80% { translate: 3px 0; } }

/* ---------- Moves ---------- */
.moves { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.move { font: inherit; color: var(--ink); background: var(--panel-2); border: 3px solid var(--line); border-radius: 6px; padding: 10px 4px 9px; display: grid; justify-items: center; gap: 6px; cursor: pointer; box-shadow: 0 5px 0 #050B24; transition: transform .08s, border-color .08s, box-shadow .08s; }
.move .e { font-size: clamp(24px, 7vw, 36px); line-height: 1; }
.move .l { font-family: var(--pixel); font-size: clamp(7px, 2.2vw, 10px); letter-spacing: .04em; }
.move:hover:not(:disabled) { border-color: var(--blue); transform: translateY(-3px); box-shadow: 0 8px 0 #050B24; }
.move:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #050B24; }
.move:disabled { cursor: default; opacity: .35; }
.move.chosen { opacity: 1; border-color: var(--gold); }
@media (max-height: 700px) { .move .e { font-size: 24px; } .move { padding: 7px 4px 6px; } .game > .panel { padding: 10px 12px; gap: 8px; } }

/* ---------- Chat ---------- */
.log { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding-right: 4px; }
.msg { max-width: 82%; display: grid; gap: 2px; }
.msg .who { font-family: var(--pixel); font-size: 8px; color: var(--muted); }
.msg .tx { background: var(--panel-2); border: 2px solid var(--line); border-radius: 6px; padding: 6px 10px; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; text-align: right; }
.msg.me .tx { background: var(--blue); color: var(--paper-ink); border-color: var(--blue-dark); text-align: left; }
.chat-empty { color: var(--muted); font-size: .9rem; }

@media (prefers-reduced-motion: reduce) {
  .fighter, .move, .btn { transition: none; }
  .bubble.pop, .bubble.trophy, .banner, .arena.clash, .arena.clash::after { animation: none; }
}
