@font-face {
  font-family: 'BHS';
  src: url('./assets/fonts/BlackHanSans-Regular.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg: #05060d;
  --ink: #f3f6ff;
  --muted: #9aa3c7;
  --p1: #19e3ff;
  --p1-deep: #0a6cff;
  --p2: #ff3b5c;
  --p2-deep: #ff8a00;
  --hp: #ffe14a;
  --hp-low: #ff5a3c;
  --panel: rgba(8, 10, 24, 0.78);
  --line: rgba(160, 190, 255, 0.22);
  --display: 'BHS', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', system-ui, sans-serif;
  --body: system-ui, 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: var(--body); -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; touch-action: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; }
.hud-top {
  position: absolute; top: max(10px, env(safe-area-inset-top, 0px)); left: calc(14px + var(--safe-l)); right: calc(14px + var(--safe-r));
  display: grid; grid-template-columns: 1fr auto 1fr; gap: clamp(8px, 1.6vw, 22px); align-items: start;
}
.hud-top { isolation: isolate; }
.hud-top::before {
  content: ""; position: absolute; z-index: -1;
  inset: calc(-1 * max(10px, env(safe-area-inset-top, 0px))) calc(-14px - var(--safe-r)) -16px calc(-14px - var(--safe-l));
  background: linear-gradient(to bottom, rgba(8,10,20,.68), rgba(8,10,20,.58) 78%, transparent);
}
.side { position: relative; display: grid; gap: 5px; min-width: 0; }
.nameplate { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-size: clamp(15px, 2vw, 24px); letter-spacing: 0.04em; text-shadow: 0 2px 0 #000, 0 0 14px rgba(0,0,0,0.8); }
.p2 .nameplate { justify-content: flex-end; }
.tag { font-size: 0.62em; padding: 2px 7px; border-radius: 4px; background: var(--p1); color: #001; letter-spacing: 0.08em; }
.p2 .tag { background: var(--p2); }
.pips { display: inline-flex; gap: 5px; margin: 0 4px; }
.pips i { width: 13px; height: 13px; transform: rotate(45deg); border: 2px solid rgba(255,255,255,0.55); background: rgba(0,0,0,0.4); }
.pips i.on { background: var(--hp); border-color: #fff; box-shadow: 0 0 10px var(--hp); }

.health {
  position: relative; height: clamp(18px, 2.6vw, 30px); background: rgba(10, 10, 25, 0.75);
  border: 2px solid rgba(255,255,255,0.85); transform: skewX(-18deg); overflow: hidden;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.6), 0 0 18px rgba(25, 227, 255, 0.35);
}
.p2 .health { transform: skewX(18deg); box-shadow: 0 0 0 2px rgba(0,0,0,0.6), 0 0 18px rgba(255, 59, 92, 0.35); }
.health .fill, .health .trail { position: absolute; top: 0; bottom: 0; right: 0; width: 100%; transform-origin: right center; }
.p2 .health .fill, .p2 .health .trail { right: auto; left: 0; transform-origin: left center; }
.health .trail { background: #ff2a3a; transition: transform 0.5s ease-in 0.35s; }
.health .fill { background: linear-gradient(180deg, #fff6b0 0%, var(--hp) 45%, #e8a400 100%); }
.health.low .fill { background: linear-gradient(180deg, #ffc2a8 0%, var(--hp-low) 50%, #b31d00 100%); animation: low 0.5s steps(2) infinite; }
@keyframes low { 50% { filter: brightness(1.5); } }
.health.hit { animation: shake 0.18s linear; }
@keyframes shake { 25% { translate: -3px 1px; } 50% { translate: 3px -1px; } 75% { translate: -2px 0; } }

.meter { position: relative; height: 9px; width: 62%; background: rgba(0,0,0,0.55); border: 1px solid rgba(255,255,255,0.35); transform: skewX(-18deg); overflow: hidden; }
.p2 .meter { justify-self: end; transform: skewX(18deg); }
.meter .fill { position: absolute; inset: 0; transform-origin: left; background: linear-gradient(90deg, var(--p1-deep), var(--p1)); }
.p2 .meter .fill { transform-origin: right; background: linear-gradient(270deg, var(--p2-deep), var(--p2)); }
.meter.full .fill { animation: pulse 0.6s ease-in-out infinite; }
@keyframes pulse { 50% { filter: brightness(1.8) saturate(1.4); } }
.meter-label { position: absolute; top: 12px; left: 0; white-space: nowrap; font-size: 11px; font-weight: 800; letter-spacing: 0.1em; color: var(--muted); opacity: 0; transform: skewX(18deg); }
.meter.full .meter-label { opacity: 1; color: #fff; text-shadow: 0 0 8px var(--hp); }
.p2 .meter-label { left: auto; right: 0; transform: skewX(-18deg); }
.meter.full { overflow: visible; }

.clock {
  display: grid; place-items: center; min-width: clamp(64px, 8vw, 96px); padding: 4px 10px 6px;
  background: linear-gradient(180deg, rgba(20, 24, 50, 0.92), rgba(5, 6, 16, 0.92));
  border: 2px solid rgba(255,255,255,0.8); clip-path: polygon(0 0, 100% 0, 88% 100%, 12% 100%);
}
#timer { font-family: var(--display); font-size: clamp(30px, 4.4vw, 52px); line-height: 1; text-shadow: 0 0 12px rgba(120, 200, 255, 0.6); }
#timer.urgent { color: #ff5a5a; }
#round-label { font-size: 10px; letter-spacing: 0.2em; color: var(--muted); font-weight: 800; }

.combo {
  position: absolute; top: calc(100% + 5px); max-width: calc(100% - 24px); width: max-content;
  overflow-wrap: anywhere; font-family: var(--display); font-size: clamp(18px, 3vw, 40px); line-height: 1.04;
  opacity: 0; transition: opacity 0.25s; text-shadow: 0 3px 0 #000, 0 0 20px currentColor; font-style: italic;
}
.combo small { display: block; font-size: 0.42em; letter-spacing: 0.2em; }
.combo.p1 { left: 0; color: var(--p1); }
.combo.p2 { right: 0; color: var(--p2); text-align: right; }
.meter.full + .combo { margin-top: 16px; }
.combo.named { border-bottom: 2px solid currentColor; padding: 2px 6px; background: rgba(5,9,20,.76); }
.combo.show { opacity: 1; animation: pop 0.18s ease-out; }
@keyframes pop { from { transform: scale(1.5); } }

/* ---------- Banner ---------- */
.banner {
  position: fixed; left: 0; right: 0; top: 38%; translate: 0 -50%; text-align: center; pointer-events: none;
  font-family: var(--display); font-size: clamp(54px, 11vw, 150px); line-height: 1; letter-spacing: 0.02em;
  color: #fff; opacity: 0; font-style: italic;
  text-shadow: 0 0 2px #fff, 0 6px 0 rgba(0,0,0,0.7), 0 0 40px var(--glow, #19e3ff), 0 0 90px var(--glow, #19e3ff);
}
.banner small { display: block; font-size: 0.3em; letter-spacing: 0.3em; margin-top: 0.25em; color: #dfe8ff; font-style: normal; }
.banner.show { animation: banner-in 0.32s cubic-bezier(.2,1.6,.4,1) forwards; }
.banner.hide { animation: banner-out 0.25s ease-in forwards; }
.banner.ko { --glow: #ff2244; font-size: clamp(90px, 18vw, 240px); }
@keyframes banner-in { from { opacity: 0; transform: scale(2.4) skewX(-12deg); filter: blur(8px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes banner-out { to { opacity: 0; transform: scaleX(1.6) scaleY(0.2); } }

.screen-flash { position: fixed; inset: 0; pointer-events: none; background: #fff; opacity: 0; mix-blend-mode: screen; }
.screen-flash.on { animation: flash 0.22s ease-out; }
@keyframes flash { from { opacity: 0.55; } to { opacity: 0; } }

/* ---------- Corner buttons ---------- */
.corner-buttons { position: fixed; top: max(10px, env(safe-area-inset-top, 0px)); right: calc(12px + var(--safe-r)); display: flex; gap: 8px; z-index: 30; }
body.in-fight .corner-buttons { top: auto; bottom: auto; right: 50%; translate: 50% 0; top: calc(max(10px, env(safe-area-inset-top, 0px)) + clamp(64px, 7.6vw, 90px)); }
.round-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: rgba(8, 10, 24, 0.7);
  font-weight: 900; font-size: 15px; display: grid; place-items: center; backdrop-filter: blur(6px);
}
.round-btn[aria-pressed="true"] { color: #ff6b6b; text-decoration: line-through; }

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; }
.screen.dim { background: radial-gradient(circle at 50% 45%, rgba(5, 6, 13, 0.55), rgba(5, 6, 13, 0.88)); }
.title-screen {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(16px, 3vw, 40px); align-content: stretch;
  padding: clamp(16px, 4vw, 56px) calc(clamp(16px, 4vw, 56px) + var(--safe-r)) clamp(16px, 4vw, 56px) calc(clamp(16px, 4vw, 56px) + var(--safe-l));
  background: linear-gradient(90deg, rgba(3, 4, 10, 0.8) 0%, rgba(3, 4, 10, 0.25) 42%, rgba(3, 4, 10, 0) 60%);
}
.title-card { display: grid; gap: clamp(12px, 2vh, 22px); justify-items: start; align-self: center; }
.kicker { margin: 0; font-weight: 900; letter-spacing: 0.35em; font-size: 12px; color: var(--p1); }
.logo { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(48px, min(9vw, 13.5vh), 124px); line-height: 0.9; display: grid; font-style: italic; letter-spacing: -0.01em; }
.logo span { text-shadow: 0 5px 0 rgba(0,0,0,0.6); }
.logo .accent { color: transparent; -webkit-text-stroke: 2px var(--p2); text-shadow: 0 0 30px rgba(255, 59, 92, 0.65); padding-left: 0.6em; }
.logo span:last-child { padding-right: 0.4em; background: linear-gradient(180deg, #fff 30%, #7fe8ff 100%); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; filter: drop-shadow(0 0 22px rgba(25, 227, 255, 0.5)); }

.vs-strip { display: flex; align-items: center; gap: 12px; }
.fighter-chip { display: grid; padding: 6px 14px; border-left: 4px solid var(--p1); background: linear-gradient(90deg, rgba(25, 227, 255, 0.18), transparent); }
.fighter-chip.p2 { border-left-color: var(--p2); background: linear-gradient(90deg, rgba(255, 59, 92, 0.2), transparent); }
.fighter-chip b { font-family: var(--display); font-weight: 400; font-size: 22px; }
.fighter-chip small { font-size: 10px; letter-spacing: 0.25em; color: var(--muted); font-weight: 800; }
.vs { font-family: var(--display); font-size: 26px; font-style: italic; color: var(--hp); }

.menu { display: grid; gap: 10px; width: min(380px, 100%); }
.menu-btn {
  position: relative; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; width: 100%;
  padding: clamp(9px, 1.7vh, 14px) 22px; font-family: var(--display); font-size: clamp(20px, 2.4vw, 26px); letter-spacing: 0.03em;
  border: 1px solid var(--line); background: rgba(10, 14, 32, 0.78); clip-path: polygon(14px 0, 100% 0, calc(100% - 14px) 100%, 0 100%);
  transition: transform 0.1s, background 0.15s;
}
.menu-btn small { font-family: var(--body); font-size: 13px; font-weight: 800; color: var(--muted); letter-spacing: 0.1em; }
.menu-btn:hover, .menu-btn:focus-visible { background: rgba(25, 227, 255, 0.18); transform: translateX(6px); outline: none; }
.menu-btn.primary { background: linear-gradient(90deg, #0a6cff, #19e3ff); color: #00111d; border-color: transparent; }
.menu-btn.primary small { color: rgba(0, 17, 29, 0.7); }
.menu-btn:active { transform: scale(0.97); }
.menu-btn:disabled { opacity: 0.45; cursor: wait; }

.settings-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.chip-btn { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: rgba(10, 14, 32, 0.7); font-size: 13px; font-weight: 800; }
.hint { font-size: 13px; color: var(--muted); }

.controls-card {
  align-self: end; padding: 16px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  backdrop-filter: blur(10px); max-width: 520px; justify-self: end;
}
.controls-card h2 { margin: 0 0 8px; font-family: var(--display); font-weight: 400; font-size: 20px; letter-spacing: 0.05em; }
.controls-card table { border-collapse: collapse; width: 100%; font-size: 13px; text-align: center; }
.controls-card thead th { font-size: 12px; color: var(--muted); font-weight: 800; padding-bottom: 6px; }
.controls-card tbody th { font-size: 13px; letter-spacing: 0.1em; padding-right: 8px; text-align: left; }
.controls-card th.p1 { color: var(--p1); } .controls-card th.p2 { color: var(--p2); }
.controls-card td, .controls-card tbody th { padding: 5px 2px; border-top: 1px solid rgba(255,255,255,0.07); white-space: nowrap; }
kbd {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 6px; margin: 0 1px;
  border-radius: 5px; background: linear-gradient(180deg, #2a3158, #161a33); border: 1px solid #4a5590; border-bottom-width: 3px;
  font-family: var(--body); font-size: 13px; font-weight: 800;
}
.moves { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; font-size: 13px; color: #c9d1f2; }
.moves b { display: inline-block; min-width: 68px; color: var(--hp); font-family: var(--display); font-weight: 400; letter-spacing: 0.03em; }
.tips { margin: 12px 0 0; font-size: 13px; line-height: 1.55; color: #c9d1f2; }
.tips b { color: var(--hp); }
.touch-only { display: none; }
body.touch-device .keyboard-only { display: none; }
body.touch-device .touch-only { display: block; }

.panel { display: grid; gap: 12px; width: min(360px, 90vw); padding: 26px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; text-align: center; backdrop-filter: blur(10px); }
.panel h2 { margin: 0 0 8px; font-family: var(--display); font-weight: 400; font-size: 34px; }
.result-panel { width: min(480px, 92vw); }
.result-panel h2 { word-break: keep-all; font-size: clamp(34px, 5.4vw, 52px); font-style: italic; color: var(--winner, #fff); text-shadow: 0 0 30px var(--winner, #fff); }
.result-score { margin: -6px 0 8px; font-family: var(--display); font-size: 28px; color: var(--muted); }
.panel .menu-btn { justify-content: center; }

/* ---------- Touch ---------- */
/* Everything is sized from the short screen side (vmin) with clamps and
   anchored in the bottom band: pad radius ≈ clamp(40px, 8vmin, 72px),
   buttons ≈ 0.85 × the pad. Controls never rise above ~45% of the height,
   so they stay clear of the HUD and the pause/mute buttons at the top. */
.touch {
  --pad: clamp(80px, min(16vmin, 14.5vw), 144px); /* the vw cap keeps a 2P cluster inside its half on a portrait tablet */
  --btn: calc(var(--pad) * 0.85);
  --gap: clamp(8px, 1.6vmin, 16px);
  --edge-l: 16px;
  --edge-r: 16px;
  --edge-b: max(16px, var(--safe-b));
  position: fixed; inset: 0; display: grid; grid-template-columns: 1fr 1fr; pointer-events: none; z-index: 10;
}
.touch.solo { grid-template-columns: 1fr; }
.touch.solo .cockpit[data-player="1"] { display: none; }
.cockpit { position: relative; pointer-events: auto; touch-action: none; }
.cockpit + .cockpit { border-left: 1px dashed rgba(255,255,255,0.08); }
.cockpit[data-player="0"] { --edge-l: max(16px, var(--safe-l)); }
.touch.solo .cockpit, .cockpit[data-player="1"] { --edge-r: max(16px, var(--safe-r)); }
.stick {
  position: absolute; left: var(--edge-l); bottom: var(--edge-b); width: var(--pad); height: var(--pad);
  border-radius: 50%; border: 2px solid rgba(255,255,255,0.25); background: radial-gradient(circle, rgba(255,255,255,0.05), rgba(255,255,255,0.12));
  touch-action: none;
}
.stick-knob { position: absolute; left: 50%; top: 50%; width: 42%; aspect-ratio: 1; border-radius: 50%; translate: -50% -50%; background: radial-gradient(circle at 35% 30%, #fff, #8aa0d0 60%, #4a5785); box-shadow: 0 4px 14px rgba(0,0,0,0.5); }
.cockpit[data-player="0"] .stick-knob { box-shadow: 0 0 18px rgba(25, 227, 255, 0.55); }
.cockpit[data-player="1"] .stick-knob { box-shadow: 0 0 18px rgba(255, 59, 92, 0.55); }
/* Direction hints sit inside the ring so nothing sticks out of the screen. */
.dir { position: absolute; left: 50%; translate: -50% 0; font-size: clamp(9px, 1.7vmin, 12px); font-weight: 800; color: rgba(255,255,255,0.72); text-shadow: 0 1px 3px #000; white-space: nowrap; pointer-events: none; }
.dir.up { top: 6%; } .dir.down { bottom: 6%; }
.buttons {
  position: absolute; right: var(--edge-r); bottom: var(--edge-b); display: grid; gap: var(--gap);
  grid-template-columns: repeat(2, var(--btn)); align-items: end;
}
/* Phones keep their corner controls. On tablets the group's outer width
   includes half of each control on top of the 5.5-radius thumb reach. */
@media (min-width: 700px) and (min-height: 700px) {
  .cockpit {
    --cluster: calc(2 * var(--btn) + var(--gap));
    --group: min(calc(100% - var(--edge-l) - var(--edge-r)),
                 calc(var(--pad) / 2 + 2.75 * var(--pad) + var(--cluster) / 2));
    --group-left: clamp(var(--edge-l), (100% - var(--group)) / 2, 100% - var(--edge-r) - var(--group));
  }
  .stick { left: var(--group-left); }
  .buttons { left: calc(var(--group-left) + var(--group) - var(--cluster)); right: auto; }
}
.tbtn {
  width: var(--btn); height: var(--btn); border-radius: 50%; border: 2px solid rgba(255,255,255,0.45); font-family: var(--display); font-size: clamp(15px, 3.4vmin, 24px);
  background: rgba(10, 14, 32, 0.55); color: #fff; touch-action: none; transition: transform 0.06s; backdrop-filter: blur(4px); padding: 0;
}
.tbtn.punch { border-color: #ffd34a; box-shadow: inset 0 0 18px rgba(255, 211, 74, 0.35); }
.tbtn.kick { translate: 0 -38%; border-color: #ff7a3c; box-shadow: inset 0 0 18px rgba(255, 122, 60, 0.35); }
.tbtn.down { scale: 0.9; background: rgba(255,255,255,0.28); }

/* ---------- Rotate-to-landscape overlay (touch devices held upright) ---------- */
.rotate-overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 22px; text-align: center; padding: 24px;
  background: radial-gradient(circle at 50% 40%, #101a3a, #05060d 70%);
}
.rotate-icon { position: relative; width: clamp(84px, 14vmin, 140px); aspect-ratio: 3 / 5; border: 5px solid var(--p1); border-radius: 16px; box-shadow: 0 0 24px rgba(25, 227, 255, 0.5); animation: tilt 2.4s ease-in-out infinite; }
.rotate-icon::before { content: ''; position: absolute; left: 50%; bottom: 8px; width: 22px; height: 4px; margin-left: -11px; border-radius: 2px; background: var(--p1); }
.rotate-icon::after { content: '↻'; position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(36px, 6vmin, 56px); color: var(--hp); }
@keyframes tilt { 0%, 20% { transform: rotate(0); } 55%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
.rotate-overlay h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(24px, 7vw, 40px); line-height: 1.25; word-break: keep-all; }
.rotate-overlay p { margin: 0; color: var(--muted); font-size: 15px; }

@media (max-width: 820px) {
  .title-screen { grid-template-columns: 1fr; overflow-y: auto; align-content: start; }
  .controls-card { justify-self: stretch; max-width: none; }
}
@media (max-height: 560px) and (min-width: 821px) {
  .logo { font-size: clamp(40px, 7vw, 80px); }
  .menu-btn { padding: 10px 18px; }
  .controls-card { padding: 14px 18px; }
  .controls-card td { padding: 2px 0; }
  .controls-card h2 { display: none; }
  .tips, .moves { display: none; }
}

/* Landscape phones (about 360-480 px tall): keep the whole title menu on one screen. */
@media (max-height: 500px) {
  .title-screen { grid-template-columns: 1fr; align-content: center; overflow-y: auto; padding-top: 12px; padding-bottom: 12px; }
  .title-card { gap: 10px; }
  .kicker, .settings-row .hint { display: none; }
  .logo { display: flex; gap: 0.25em; font-size: clamp(30px, 11vh, 52px); }
  .logo .accent { padding-left: 0; }
  .logo span:last-child { padding-right: 0.15em; }
  .vs-strip small { display: none; }
  .menu { grid-template-columns: repeat(4, minmax(0, 1fr)); width: min(720px, 100%); }
  .menu-btn { padding: 10px 14px; }
  .controls-card { display: none; }
}

/* 로봇 선택판: 두 플레이어가 각자 자기 쪽에서 골라요. */
.select-screen {
  --edge: clamp(10px, 2.4vmin, 32px);
  --gap: clamp(8px, 1.4vmin, 18px);
  padding: max(var(--edge), env(safe-area-inset-top)) max(var(--edge), var(--safe-r))
           max(var(--edge), var(--safe-b)) max(var(--edge), var(--safe-l));
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  background: radial-gradient(ellipse at top, #162940, #080a17 72%);
}
.select-content {
  width: min(100%, 1440px); height: min(100%, 1120px);
  display: flex; flex-direction: column; gap: var(--gap); text-align: center;
}
.select-content h2, .picker h3 { font-family: var(--display); margin: 0; }
.select-content h2 { font-size: clamp(28px, 5vmin, 52px); line-height: 1.1; }
.select-content p { margin: 0; }
#select-hint, .identity small { color: var(--muted); }
#pickers {
  flex: 1; min-height: 0; display: grid; grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  gap: clamp(12px, 2.4vmin, 28px);
}
.picker { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: var(--gap); }
.picker header { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.picker h3 { font-size: clamp(20px, 3vmin, 32px); color: var(--p1); }
.picker + .picker h3 { color: var(--p2); }
.release { min-height: 44px; }
.robot-grid {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  grid-auto-rows: minmax(0, 1fr); gap: var(--gap);
}
.robot-card {
  min-width: 0; min-height: 64px; display: grid; position: relative;
  grid-template: minmax(0, 1fr) auto auto auto / minmax(0, 1fr);
  gap: var(--card-gap, clamp(4px, 1vmin, 12px)); padding: var(--card-pad, clamp(8px, 1.6vmin, 20px));
  border: 2px solid var(--line); border-radius: 10px; background: #101728; text-align: left;
}
.robot-card[aria-pressed="true"] { border-color: var(--glow); }
.robot-card.highlight, .robot-card:focus-visible { outline: 2px solid white; outline-offset: 1px; }
.robot-card:disabled { filter: saturate(.35); color: var(--muted); }
.portrait {
  display: grid; place-items: center; min-height: 0; border-radius: 5px;
  background: linear-gradient(135deg, var(--body-color), #111b30 57%, var(--glow));
  font: italic 900 clamp(32px, 8vmin, 88px)/1 var(--display);
  color: white; text-shadow: 2px 2px var(--body-color);
}
.portrait { position: relative; overflow: hidden; }
.portrait img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: center bottom; }
.identity { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 8px; }
.identity strong { font: clamp(18px, 3.2vmin, 34px)/1.1 var(--display); }
.card-status { position: absolute; top: 6px; right: 6px; background: #101728; color: white; border-radius: 4px; padding: 2px 4px; }
.card-status:empty { display: none; }
.stats { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 2px 8px; font-size: var(--stat-size, clamp(12px, 2vmin, 20px)); line-height: 1.2; }
.stats meter { appearance: none; min-width: 0; width: 100%; height: var(--meter-height, clamp(10px, 1.5vmin, 16px)); background: #283244; border: none; border-radius: 4px; }
.stats meter::-webkit-meter-bar { background: #283244; border: none; height: 100%; }
.stats meter::-webkit-meter-optimum-value { background: var(--glow); }
.stats meter::-moz-meter-bar { background: var(--glow); }
.super-name { font-size: clamp(14px, 2vmin, 20px); line-height: 1.2; color: var(--glow); }
.select-actions { width: min(100%, 520px); align-self: center; display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
.select-actions button { justify-content: center; align-items: center; min-height: 56px; }

@media (orientation: portrait) {
  #pickers { grid-auto-flow: row; grid-template-rows: none; grid-auto-rows: minmax(0, 1fr); }
}
@media (orientation: portrait) and (min-width: 700px) {
  .select-content:has(.picker:only-child) { max-height: 780px; }
}

@media (max-height: 570px) and (orientation: landscape) {
  .select-screen { --edge: 6px; --gap: 4px; }
  .select-content h2 { font-size: 22px; }
  #select-hint, #cpu-opponent { font-size: 12px; }
  .picker header, .release { min-height: 30px; }
  .release { padding: 3px 12px; }
  .robot-card { padding: 4px; gap: 3px; }
  .portrait { font-size: 28px; padding-top: 12px; }
  .card-status { top: 3px; right: 3px; padding: 1px 3px; font-size: 10px; }
  .identity { gap: 1px 4px; }
  .identity strong { font-size: 16px; }
  .identity small { font-size: 10px; }
  .stats { gap: 1px 3px; font-size: 11px; }
  .stats meter { height: 6px; }
  .select-actions button { padding: 4px 12px; font-size: 18px; }
}

/* Reserve the same caption space across a row, including narrow five-card layouts. */
.robot-card { container-type: inline-size; }
.identity { display: grid; gap: 1px; }
.identity strong { font-size: min(clamp(16px, 3.2vmin, 34px), 16cqw); white-space: nowrap; }
.identity small { line-height: 1.1; white-space: nowrap; }
.robot-card .super-name { height: 2.4em; font-size: min(clamp(12px, 2vmin, 20px), 18cqw); }

@media (orientation: landscape) and (min-height: 571px) {
  .picker:not(:only-child) .robot-grid { --card-pad: 6px; --card-gap: 4px; --stat-size: 12px; --meter-height: 7px; }
}

#challenger, #result.champion {
  overflow: hidden;
  background: radial-gradient(ellipse at 32% 44%, #996132, #4c3025 50%, #191924 90%);
}
.challenger-content { width: min(90vw, 790px); }
.progress { color: #ffdb94; letter-spacing: .12em; font-weight: 800; margin: 0; }
#challenger-title { margin: .12em 0 .4em; font: italic 900 clamp(26px, 5.6vmin, 58px)/1.12 var(--display); }
.challenger-card { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: clamp(16px, 4vw, 54px); }
.challenger-card .portrait, #winner-portrait {
  height: min(45vh, 390px);
  background: radial-gradient(ellipse at 50% 84%, #e6b46955, transparent 70%);
}
.challenger-info { display: grid; gap: clamp(5px, 1vh, 12px); }
.challenger-info strong { font: 900 clamp(26px, 5vmin, 50px)/1.1 var(--display); }
.challenger-info small { color: #ffd89d; letter-spacing: .14em; }
.challenger-info p { margin: .35em 0; }
.challenger-info .stats { gap: 4px 12px; }
.challenger-info button, .arcade-result button { min-height: 64px; align-items: center; justify-content: center; }
.challenger-info button { margin-top: .4em; }
.challenger-info button.primary, .champion button.primary { background: linear-gradient(95deg, #ffb53d, #ffebae); color: #382211; }
.arcade-result .kicker { display: none; }
.champion .result-panel {
  position: relative; grid-template-columns: minmax(0, .9fr) minmax(0, 1fr);
  column-gap: 20px; width: min(88vw, 760px); background: #271f22ee; border-color: #cd9d57;
}
#winner-portrait { grid-column: 1; grid-row: 1 / span 6; height: auto; align-self: stretch; }
.champion .result-panel > :is(h2, .result-score, button) { grid-column: 2; }
.arcade-result .result-score { font: 700 clamp(16px, 2.8vmin, 24px)/1.2 var(--body); margin: 0; }
.champion::before {
  content: ''; position: absolute; inset: -80px 0 0; pointer-events: none; opacity: .75;
  background-image: radial-gradient(ellipse, #ffdf92 0 2px, transparent 3px), radial-gradient(ellipse, #ffb64e 0 1px, transparent 2px);
  background-size: 73px 80px, 113px 80px; background-position: 0 0, 31px 45px;
  animation: golden-sparkles 4s linear infinite;
}
@keyframes golden-sparkles { to { transform: translateY(80px); } }
@media (prefers-reduced-motion: reduce) { .champion::before { animation: none; } }
@media (orientation: portrait) {
  .challenger-content { max-width: 650px; }
  .challenger-card .portrait { height: min(38vh, 380px); }
}
@media (max-height: 450px) {
  .challenger-card .portrait { height: 58vh; }
  .challenger-info { gap: 2px; }
  .arcade-result .result-panel { padding: 10px 18px; gap: 4px 18px; }
  .arcade-result h2 { margin: 0; font-size: 32px; }
}

.language-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #101428;
}
.language-toggle button {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.language-toggle button[aria-pressed="true"] { background: var(--p1); color: #061323; }
.title-screen { padding-top: max(64px, calc(env(safe-area-inset-top) + 56px)); overflow-y: auto; }
.title-card { min-width: 0; max-width: 100%; }
.controls-card { min-width: 0; }
.title-screen, #pause { touch-action: pan-y; }
.menu-btn, .hint, .moves, .super-name { overflow-wrap: anywhere; }
.robot-card .super-name { height: 2.4em; min-height: 1.2em; }
.pause-language, .pause-settings { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; }
.pause-settings button { min-height: 44px; }
#pause { overflow-y: auto; align-items: safe center; }
body:has(#pause:not([hidden])) .corner-buttons { display: none; }
.settings-row .error { display: inline; }
@media (max-height: 500px) {
  .title-screen { align-content: safe center; }
  .menu-btn { flex-wrap: wrap; gap: 4px 8px; }
  #pause .panel { padding: 10px; gap: 5px; }
  #pause h2 { font-size: 24px; margin: 0; }
}

.select-actions { width: min(100%, 700px); grid-template-columns: 1fr 1.2fr 1.6fr; }
#move-list {
  width: min(960px, 96vw); max-height: 94dvh; padding: 0; color: var(--ink);
  background: #0c1222; border: 1px solid var(--accent); border-radius: 12px;
  overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
#move-list::backdrop { background: rgba(3, 6, 15, .88); }
#move-list header {
  position: sticky; top: 0; z-index: 1; background: #101728;
  padding: 8px 16px; display: grid; grid-template-columns: 1fr auto; align-items: center;
  gap: 4px 12px; border-bottom: 1px solid var(--accent);
}
#move-list h2, #move-list h3 { font-family: var(--display); margin: 0; }
#move-list h3 { margin: 18px 0 6px; color: var(--accent); }
#blink-overlay { position: fixed; inset: 0; z-index: 19; pointer-events: none; visibility: hidden; background: #11100f; }
@media (prefers-reduced-motion: no-preference) {
  #blink-overlay.active { visibility: visible; animation: statue-blink 240ms ease-in-out both; }
  #blink-overlay.active.drum { animation: drum-dim 950ms ease-in-out both; }
  @keyframes drum-dim { 0%, 100% { opacity: 0; } 30%, 65% { opacity: .4; } }
  @keyframes statue-blink { 0%, 100% { opacity: 0; } 50% { opacity: .55; } }
}
.list-tabs { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 5px; }
.list-tabs button[aria-pressed="true"] { border-color: var(--glow); color: var(--accent); }
#move-list button, #training-panel :is(button, select, label) { min-height: 44px; min-width: 44px; }
.list-content { padding: 0 16px 16px; }
.list-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.move-entry { display: flex; align-items: center; gap: 12px; background: #161e30; border-radius: 6px; }
.move-entry .portrait { flex: 0 0 120px; height: 120px; }
.move-entry :is(strong, small, kbd) { display: block; margin: 4px 0; }
.move-entry kbd { width: fit-content; color: var(--accent); }
.hud.practice .clock, .hud.practice .pips { display: none; }
.hud.practice .hud-top { grid-template-columns: 1fr 1fr; }
#training-panel, #input-display { position: fixed; z-index: 15; font-size: 14px; }
#training-panel { right: max(16px, var(--safe-r)); top: max(100px, 14vh); text-align: right; }
#training-panel .chip-btn, #training-controls, #input-display { background: #101728ef; }
#training-controls {
  display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 3px 6px;
  max-width: min(400px, 48vw); max-height: 50dvh; overflow: auto; padding: 6px;
  touch-action: pan-y; border-radius: 6px;
}
#training-controls label { display: flex; align-items: center; justify-content: center; gap: 4px; }
#training-controls label:first-child { grid-column: 1 / -1; }
#input-display {
  left: max(12px, var(--safe-l)); bottom: max(16px, var(--safe-b)); max-width: 45vw;
  pointer-events: none; padding: 6px 9px; border-left: 2px solid var(--p1); border-radius: 4px;
}
#input-history { font-family: monospace; white-space: pre-wrap; }
.touch-device #input-display { bottom: auto; top: max(100px, 14vh); max-width: 38vw; }
@media (max-height: 500px), (max-width: 650px) {
  .list-grid { grid-template-columns: minmax(0, 1fr); }
  .move-entry .portrait { flex-basis: 96px; height: 96px; }
  #move-list header { padding: 4px 8px; }
  .touch-device #input-display, #training-panel { top: 84px; font-size: 12px; }
  #training-controls { max-height: calc(100dvh - 136px - 92px); }
}
@media (max-height: 500px) {
  .menu { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
#input-display .combo { display: none; position: static; font-size: 1em; margin-top: 3px; }
#input-display .combo.show { display: block; }
#input-display .combo small { display: inline; margin-left: .5em; font-size: .85em; }

.select-actions {
  position: relative;
  grid-template-columns: minmax(0,1.25fr) 1fr 1.2fr 1.6fr;
}
#stage-control { min-width: 0; align-self: center; }
#stage-control summary {
  display: flex; flex-wrap: wrap; gap: 0 .24em; justify-content: center; align-content: center; min-height: 44px; padding: 1px 6px;
  cursor: pointer; border: 1px solid #648187; border-radius: 6px;
  color: #e0eeed; background: #192b36; font-size: clamp(12px,1.7vmin,16px);
}
#stage-control summary::-webkit-details-marker { display: none; }
#stage-current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-popover {
  position: absolute; z-index: 5; bottom: calc(100% + 5px); inset-inline: 0;
  padding: 8px; background: #14232f; border: 1px solid #819494; border-radius: 8px;
  box-shadow: 0 4px 20px #0008; text-align: start;
}
.stage-popover label { display: inline-flex; align-items: center; gap: .8em; }
.stage-popover select { min-height: 44px; }
#stage-strip { display: flex; gap: 4px; overflow-x: auto; padding: 4px 1px; }
#stage-strip button {
  position: relative; display: block; flex: 0 0 96px; padding: 0; overflow: hidden;
  aspect-ratio: 16/9; min-height: 44px; border: 2px solid transparent; border-radius: 4px;
  color: white; background: linear-gradient(155deg,#8caaae,#63574f);
}
#stage-strip img { width: 100%; height: 100%; object-fit: cover; }
#stage-strip span {
  position: absolute; inset: auto 0 0; padding: 3px 1px; font-size: 11px;
  background: linear-gradient(transparent,#12202ae8 40%); text-align: center;
}
#stage-strip button[aria-pressed=true] { border-color: #a4f6ef; }
#stage-strip button:disabled { opacity: .59; }
#stage-caption {
  position: absolute; top: calc(100% + 5px); right: calc(50% + 64px); width: max-content; max-width: calc(50% - 65px);
  border-inline-start: 3px solid #eed7a5; padding: 4px 12px;
  background: #17252dee; color: #fff5dd; font-size: clamp(12px,1.8vmin,18px);
}
#stage-caption.arrive { animation: stage-arrival 2s both; }
@keyframes stage-arrival { 0%,100% { opacity: 0; } 12%,85% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #stage-caption.arrive { animation: none; } }
@media (max-height: 570px) and (orientation: landscape) {
  #stage-strip button { flex-basis: 76px; }
}

/* Independent scroll strips preserve the height of the art and keep both
   players' pickers and the shared action buttons on screen. */
.picker { min-width: 0; min-height: 0; }
.robot-grid {
  min-width: 0; min-height: 0; overflow-x: auto; overflow-y: hidden;
  grid-auto-columns: minmax(144px,1fr); scroll-snap-type: x mandatory;
  padding: 3px; --card-pad: 6px; --card-gap: 4px;
}
.robot-card { scroll-snap-align: start; grid-template-rows: minmax(0,1fr) 40px 32px 64px; }
.robot-card .identity { align-content: center; }
.robot-card .identity strong { font-size: 17px; }
.robot-card .stats { font-size: 12px; }
.robot-card .super-name { font-size: 12px; }
@media (max-height: 570px) and (orientation: landscape) {
  .robot-grid { grid-auto-columns: minmax(104px,1fr); }
  .robot-card {
    grid-template: "identity" 14px "art" minmax(0,1fr) "super" 21px "stats" 23px / minmax(0,1fr);
    padding: 2px; gap: 1px;
  }
  .robot-card .identity { grid-area: identity; }
  .robot-card .identity strong { font-size: 12px; }
  .robot-card .identity small { display: none; }
  .robot-card .portrait { grid-area: art; }
  .robot-card .super-name { grid-area: super; font-size: 9px; }
  .robot-card .stats { grid-area: stats; grid-template-columns: auto 1fr auto 1fr; font-size: 9px; }
}
#stage canvas { transition: filter .3s ease-out; }
#stage.cartoon-time canvas { filter: grayscale(1) contrast(1.1); transition-duration: 0s; }
@media (prefers-reduced-motion: no-preference) {
  #stage.cartoon-time::after {
    content: ''; position: absolute; inset: 0; pointer-events: none;
    background-image: linear-gradient(90deg, transparent 16%, #eee3 16.1%, transparent 16.2%,
      transparent 71%, #1113 71.1%, transparent 71.2%, transparent 90%, #ddd2 90.1%, transparent 90.2%),
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3'/%3E%3C/filter%3E%3Cpath fill='%23777' opacity='.10' filter='url(%23n)' d='M0 0h160v160H0z'/%3E%3C/svg%3E");
    animation: film-drift 4s ease-in-out infinite alternate;
  }
  @keyframes film-drift { to { background-position: 16px 0, 0 0; } }
}
@media (prefers-reduced-motion: reduce) {
  #stage.cartoon-time canvas { filter: grayscale(1); }
}

.title-tools {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: calc(12px + var(--safe-l));
  right: calc(60px + var(--safe-r)); display: flex; align-items: center; gap: 6px;
}
.title-tools [data-action="hub"] { margin-right: auto; }
.title-tools .chip-btn, [data-shell], #portrait-play, #install-help button { min-height: 44px; font-size: 14px; }
[data-action="hub"] { min-height: 44px; }
#install-help { max-width: min(340px, 90vw); color: var(--ink); background: #101428; border: 1px solid var(--line); border-radius: 12px; }
#install-help::backdrop { background: #0009; }
#pause, #result { padding: max(6px, env(safe-area-inset-top)) max(10px, var(--safe-r)) max(6px, var(--safe-b)) max(10px, var(--safe-l)); }
@media (max-height: 500px) and (orientation: landscape) {
  #pause .panel, #result .result-panel { width: min(690px, 100%); grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; padding: 8px; }
  #pause h2, #result :is(h2, .result-score, .kicker) { grid-column: 1 / -1; margin: 0; }
  #result.champion .result-panel { grid-template-columns: minmax(100px, .8fr) repeat(2, minmax(0, 1fr)); }
  #result.champion #winner-portrait { grid-column: 1; grid-row: 1 / span 4; }
  #result.champion :is(h2, .result-score) { grid-column: 2 / -1; }
  #result.champion button { grid-column: auto; }
  #pause .menu-btn { min-height: 44px; }
}
@media (orientation: portrait) and (max-width: 699px) {
  .title-screen { padding-top: max(112px, calc(env(safe-area-inset-top) + 104px)); }
  .title-tools { flex-wrap: wrap; }
  .title-tools [data-shell] { order: 3; flex-basis: 100%; }
  .touch:not(.solo) { --pad: clamp(56px, 17vw, 80px); --btn: max(56px, calc(var(--pad) * .85)); }
  .touch:not(.solo) .buttons { grid-template-columns: var(--btn); }
  .touch:not(.solo) .kick { translate: none; }
  .nameplate { gap: 3px; }
  .nameplate .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .select-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
