/* ==========================================================================
   Poké Arena — handheld-era design system

   Spacing  4 / 8 / 12 / 16 / 24 / 32 / 48 / 64 / 96 (4-point scale, no exceptions)
   Type     Heading: Press Start 2P, sizes on its 8px grid — 16/24 · 24/32 · 32/48 · 48/64
            Body:    Pixelify Sans — 14/20 · 16/24 · 18/28
   Shape    Square corners everywhere. 2px ink borders. Hard, un-blurred drop
            shadows: 4px for containers, 2px for controls.
   Color    Paper + ink, with the series primaries: red (brand, P1), blue (P2,
            focus), green (HP, success), yellow (HP mid, round wins).
   Motion   Stepped timing (steps()) so movement reads like sprite frames.
   ========================================================================== */

:root {
  --paper: #F3EDD7;
  --surface: #FFFCF0;
  --surface-2: #EAE2C6;
  --surface-3: #DCD2AE;
  --ink: #26242C;
  --muted: #5D5848;
  --subtle: #857E68;

  --red: #C8412F;
  --red-hover: #B23826;
  --blue: #3567C8;
  --green: #2F7D3A;
  --yellow: #F2C230;

  --hp-high: #4DB04F;
  --hp-mid: #E8B828;
  --hp-low: #D8483A;

  --accent: var(--red);
  --on-accent: #FFFCF0;
  --p1: var(--red);
  --p2: var(--blue);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;
  --s6: 32px; --s7: 48px; --s8: 64px; --s9: 96px;

  --bw: 2px;
  --border: var(--bw) solid var(--ink);
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 2px 2px 0 var(--ink);

  --font-head: 'Press Start 2P', ui-monospace, 'Cascadia Mono', monospace;
  --font-body: 'Pixelify Sans', ui-monospace, 'Cascadia Mono', monospace;

  --dur: 120ms;
  --step: steps(3, end);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--paper);
  /* Faint 2px dot every 16px — the paper grain of an old instruction booklet. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Crect width='2' height='2' fill='%2326242C' fill-opacity='0.1'/%3E%3C/svg%3E");
  color: var(--ink);
  font: 400 16px/24px var(--font-body);
}

h1, h2, h3, p, dl, dd, figure { margin: 0; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
a { color: var(--ink); text-decoration-thickness: 2px; text-underline-offset: 4px; }
a:hover { color: var(--red); }
[hidden] { display: none !important; }

:focus-visible {
  outline: var(--bw) solid var(--blue);
  outline-offset: 2px;
}

::selection { background: var(--yellow); color: var(--ink); }

.pixel { image-rendering: pixelated; image-rendering: crisp-edges; }

/* Pixel icons: drawn on a 12×12 grid, rendered at 2× */
.px-icon {
  display: block;
  width: 24px;
  height: 24px;
  fill: currentColor;
  shape-rendering: crispEdges;
}

/* ==========================================================================
   Typography
   ========================================================================== */

.display {
  font: 400 32px/48px var(--font-head);
}

.h2 {
  font: 400 24px/32px var(--font-head);
}

.h3 {
  font: 400 16px/24px var(--font-head);
}

.lead {
  font-size: 18px;
  line-height: 28px;
  color: var(--muted);
}

.eyebrow,
.label {
  display: block;
  font: 600 14px/20px var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--red);
}

.label { color: var(--muted); }

.muted { color: var(--muted); }

.hint {
  margin-top: var(--s4);
  font-size: 14px;
  line-height: 20px;
  color: var(--muted);
}

code {
  padding: 0 var(--s1);
  background: var(--surface-2);
  font: 500 14px/20px var(--font-body);
  color: var(--ink);
}

kbd {
  display: inline-block;
  min-width: 24px;
  padding: 0 var(--s1);
  border: var(--border);
  background: var(--surface);
  box-shadow: 0 2px 0 var(--ink);
  font: 600 14px/18px var(--font-body);
  text-align: center;
  color: var(--ink);
}

/* ==========================================================================
   Layout
   ========================================================================== */

.container {
  width: 100%;
  max-width: 1168px;
  margin: 0 auto;
  padding: 0 var(--s5);
}

.container--narrow { max-width: 880px; }

.page { padding-top: var(--s7); padding-bottom: var(--s8); }

.section { margin-top: var(--s9); }
.section > .h2 { margin-bottom: var(--s5); }

.screen { display: none; }
.screen.is-active { display: block; animation: screen-in 200ms steps(4, end); }

@keyframes screen-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.screen-head {
  display: flex;
  align-items: flex-start;
  gap: var(--s4);
  margin-bottom: var(--s6);
}

.screen-head .muted { margin-top: var(--s2); }

/* ==========================================================================
   Components
   ========================================================================== */

.card {
  background: var(--surface);
  border: var(--border);
  box-shadow: var(--shadow);
}

/* Buttons ----------------------------------------------------------------- */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: 44px;
  padding: 0 var(--s5);
  border: var(--border);
  box-shadow: var(--shadow-sm);
  font: 600 16px/24px var(--font-body);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur) var(--step), color var(--dur) var(--step);
}

.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }

.btn--sm { height: 36px; padding: 0 var(--s4); font-size: 14px; line-height: 20px; }

.btn--primary { background: var(--red); color: var(--on-accent); }
.btn--primary:hover { background: var(--red-hover); }

.btn--secondary { background: var(--surface); color: var(--ink); }
.btn--secondary:hover { background: var(--surface-2); }

.btn--ghost {
  padding: 0 var(--s3);
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
}
.btn--ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn--ghost .px-icon { width: 24px; height: 24px; }

.btn:disabled {
  border-color: var(--subtle);
  background: var(--surface-2);
  box-shadow: none;
  color: var(--subtle);
  cursor: not-allowed;
}

.btn.is-loading { pointer-events: none; }
.btn.is-loading .btn__label { visibility: hidden; }
.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: var(--bw) solid currentColor;
  background: conic-gradient(currentColor 0 25%, transparent 0);
  animation: spin 800ms steps(4, end) infinite;
}
.btn--primary.is-loading,
.btn--primary.is-loading:disabled { background: var(--red); border-color: var(--ink); color: var(--on-accent); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  cursor: pointer;
  transition: background-color var(--dur) var(--step);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: translate(2px, 2px); box-shadow: none; }
.icon-btn .icon-off { display: none; }
.icon-btn[aria-pressed='true'] .icon-on { display: none; }
.icon-btn[aria-pressed='true'] .icon-off { display: block; }

/* Inputs ------------------------------------------------------------------ */

.input {
  width: 100%;
  height: 44px;
  padding: 0 var(--s4);
  border: var(--border);
  background: var(--surface);
  box-shadow: inset 2px 2px 0 var(--surface-3);
  color: var(--ink);
  font: 400 16px/24px var(--font-head);
  letter-spacing: 0.25em;
  text-transform: uppercase;
}
.input::placeholder { color: var(--subtle); }
.input:focus { outline: var(--bw) solid var(--blue); outline-offset: 2px; }

/* Chips: player tags and type labels share one shape --------------------- */

.tag,
.type {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 var(--s2);
  border: var(--border);
  font: 600 14px/20px var(--font-body);
  white-space: nowrap;
}

.tag { color: #FFFCF0; letter-spacing: 0.04em; }
.tag--p1 { background: var(--p1); }
.tag--p2 { background: var(--p2); }

.types { display: flex; flex-wrap: wrap; gap: var(--s1); justify-content: center; }

/* Loading ----------------------------------------------------------------- */

.spinner {
  display: inline-block;
  flex: none;
  width: 16px;
  height: 16px;
  border: var(--bw) solid var(--ink);
  background: conic-gradient(var(--red) 0 25%, var(--surface) 0);
  animation: spin 800ms steps(4, end) infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background:
    linear-gradient(90deg, transparent 0 33%, rgba(255, 252, 240, 0.7) 33% 66%, transparent 66%) 0 0 / 300% 100%,
    var(--surface-2);
  animation: shimmer 1200ms steps(6, end) infinite;
}
@keyframes shimmer { from { background-position: 100% 0, 0 0; } to { background-position: -50% 0, 0 0; } }

.status {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 14px;
  line-height: 20px;
  color: var(--muted);
}

.alert {
  margin-top: var(--s5);
  padding: var(--s3) var(--s4);
  border: var(--border);
  border-left-width: 8px;
  border-left-color: var(--red);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  font-size: 14px;
  line-height: 20px;
}

/* ==========================================================================
   Home
   ========================================================================== */

.topbar {
  border-bottom: var(--border);
  background: var(--surface);
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s3);
  font: 400 16px/24px var(--font-head);
  text-decoration: none;
  color: var(--ink);
}
.brand img { width: 32px; height: 32px; image-rendering: pixelated; }
.brand:hover { color: var(--ink); }

.topbar__actions { display: flex; align-items: center; gap: var(--s4); }

.asset-status {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 14px;
  line-height: 20px;
  color: var(--muted);
  transition: opacity 400ms steps(4, end);
}
.asset-status.is-done { opacity: 0; }

.asset-status__bar {
  width: 64px;
  height: 12px;
  padding: 2px;
  border: var(--border);
  background: var(--surface);
}
.asset-status__bar span {
  display: block;
  height: 100%;
  width: 0;
  background: repeating-linear-gradient(90deg, var(--hp-high) 0 4px, transparent 4px 6px);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: var(--s7);
  align-items: center;
  padding-top: var(--s8);
}

.hero__copy .display { margin-top: var(--s4); }
.hero__copy .lead { margin-top: var(--s5); max-width: 560px; }

/* Mode list: a handheld start menu with a ▶ cursor */
.mode-list {
  display: grid;
  margin-top: var(--s6);
  max-width: 560px;
  border: var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mode {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  padding: var(--s4) var(--s4) var(--s4) var(--s2);
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--dur) var(--step);
}
.mode + .mode { border-top: var(--bw) dashed var(--surface-3); }
.mode:hover,
.mode:focus-visible { background: var(--surface-2); }
.mode:focus-visible { outline-offset: -4px; }

.mode__cursor { flex: none; color: var(--red); visibility: hidden; }
.mode:hover .mode__cursor,
.mode:focus-visible .mode__cursor { visibility: visible; animation: blink 800ms steps(1, end) infinite; }

@keyframes blink { 50% { opacity: 0; } }

.mode__badge {
  display: grid;
  place-items: center;
  flex: none;
  width: 48px;
  height: 48px;
  border: var(--border);
  background: var(--paper);
  font: 400 12px/16px var(--font-head);
  color: var(--ink);
}

.mode__text { display: flex; flex-direction: column; gap: var(--s1); flex: 1; min-width: 0; }
.mode__title { font: 400 16px/24px var(--font-head); }
.mode__desc { font-size: 14px; line-height: 20px; color: var(--muted); }

/* Preview: a framed slice of the arena */
.preview { padding: var(--s4); }

.preview__field {
  position: relative;
  aspect-ratio: 16 / 11;
  overflow: hidden;
  border: var(--border);
  background:
    conic-gradient(#78C060 25%, #70B858 0 50%, #78C060 0 75%, #70B858 0) 0 0 / 32px 32px;
  box-shadow: inset 0 0 0 8px #C9A46A, inset 0 0 0 12px #8F6C3C;
  image-rendering: pixelated;
}

.preview__line {
  position: absolute;
  top: 20px;
  bottom: 20px;
  left: calc(50% - 2px);
  width: 4px;
  background: rgba(248, 248, 236, 0.65);
}

.preview__circle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 96px;
  height: 96px;
  border: 4px solid rgba(248, 248, 236, 0.65);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.preview__mon {
  position: absolute;
  bottom: 20%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
}
.preview__art { display: block; }
.preview__art canvas { display: block; }
.preview__mon--p1 { left: 12%; }
.preview__mon--p2 { right: 10%; }

.preview__stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s4);
  padding: var(--s4) var(--s2) 0;
}
.preview__stats dt { font-size: 14px; line-height: 20px; color: var(--muted); }
.preview__stats dd { margin-top: var(--s1); font: 600 18px/28px var(--font-body); }

.controls-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s5);
}

.control-card { padding: var(--s5); }
.control-card .muted { margin-top: var(--s2); font-size: 14px; line-height: 20px; }

.control-card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--s2) var(--s4);
  margin-top: var(--s4);
  padding-top: var(--s4);
  border-top: var(--bw) dashed var(--surface-3);
  align-items: center;
}
.control-card dt { font-size: 14px; line-height: 20px; color: var(--muted); }
.control-card dd { display: flex; flex-wrap: wrap; gap: var(--s1); justify-content: flex-end; }

.rules-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s5);
}
.rule { padding: var(--s5); }
.rule p { margin-top: var(--s3); color: var(--muted); }

.footer {
  margin-top: var(--s9);
  border-top: var(--border);
  background: var(--surface);
}
.footer__inner {
  display: grid;
  gap: var(--s2);
  padding-top: var(--s6);
  padding-bottom: var(--s6);
  font-size: 14px;
  line-height: 20px;
  color: var(--muted);
}

/* ==========================================================================
   Lobby
   ========================================================================== */

.lobby-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s5);
  align-items: start;
}

.lobby-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s4);
  padding: var(--s5);
}
.lobby-card .muted { margin-top: calc(var(--s2) * -1); }

.room {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s3);
  width: 100%;
  padding-top: var(--s4);
  border-top: var(--bw) dashed var(--surface-3);
}

.room__code {
  font: 400 32px/48px var(--font-head);
  letter-spacing: 0.25em;
  color: var(--red);
}

.join { width: 100%; display: grid; gap: var(--s2); }
.join__row { display: flex; gap: var(--s3); }

/* ==========================================================================
   Character select
   ========================================================================== */

.select {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr) 288px;
  gap: var(--s5);
  align-items: start;
}

.roster {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s3);
}

.mon {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  padding: var(--s3) var(--s2) var(--s4);
  border: var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: background-color var(--dur) var(--step);
}
.mon:hover { background: var(--surface-2); }
.mon:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
.mon:disabled { cursor: default; }
.mon:disabled:hover { background: var(--surface); }

.mon.is-p1 { background: #F8E3D8; box-shadow: 0 0 0 2px var(--p1), 4px 4px 0 2px var(--ink); }
.mon.is-p2 { background: #DFE6F4; box-shadow: 0 0 0 2px var(--p2), 4px 4px 0 2px var(--ink); }
.mon.is-p1.is-p2 { background: var(--surface); box-shadow: 0 0 0 2px var(--p1), 0 0 0 4px var(--p2), 4px 4px 0 4px var(--ink); }

.mon__badges {
  position: absolute;
  top: var(--s2);
  left: var(--s2);
  right: var(--s2);
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.mon__badges .tag { visibility: hidden; }
.mon.is-p1 .mon__badges .tag--p1,
.mon.is-p2 .mon__badges .tag--p2 { visibility: visible; }

.mon__art {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  height: 112px;
}
.mon__art canvas { display: block; }
.mon__art .skeleton { width: 64px; height: 64px; }

.mon__name { font: 600 16px/24px var(--font-body); text-align: center; }

.slot {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  min-height: 456px;
  padding: var(--s5);
  border: var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.slot.is-clickable { cursor: pointer; }
.slot.is-active[data-slot='0'] { box-shadow: 0 0 0 2px var(--p1), 4px 4px 0 2px var(--ink); }
.slot.is-active[data-slot='1'] { box-shadow: 0 0 0 2px var(--p2), 4px 4px 0 2px var(--ink); }

.slot__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
}
.slot__who { display: flex; align-items: center; gap: var(--s2); font: 600 16px/24px var(--font-body); }
.slot__state { font-size: 14px; line-height: 20px; color: var(--muted); }
.slot__state--ready { color: var(--green); font-weight: 600; }

.slot__art {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 144px;
  padding-bottom: var(--s3);
  border: var(--border);
  background:
    linear-gradient(transparent 0 70%, #C9A46A 70% 72%, transparent 72%),
    conic-gradient(#78C060 25%, #70B858 0 50%, #78C060 0 75%, #70B858 0) 0 0 / 16px 16px;
}
.slot__art canvas { display: block; }

.slot__empty {
  display: grid;
  place-items: center;
  flex: 1;
  padding: var(--s5);
  border: var(--bw) dashed var(--subtle);
  color: var(--muted);
  font-size: 14px;
  line-height: 20px;
  text-align: center;
}

.slot__title { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); }
.slot__role { font-size: 14px; line-height: 20px; color: var(--muted); }
.slot .types { justify-content: flex-start; }

.stat { display: grid; grid-template-columns: 48px 1fr 32px; align-items: center; gap: var(--s2); font-size: 14px; line-height: 20px; }
.stat__label { color: var(--muted); }
.stat__value { text-align: right; font-weight: 600; }
.stat__bar { height: 12px; padding: 2px; border: var(--border); background: var(--surface); }
.stat__bar span { display: block; height: 100%; background: repeating-linear-gradient(90deg, var(--ink) 0 4px, transparent 4px 6px); }

.moves { display: grid; gap: var(--s3); }

.select__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s4) var(--s5);
  margin-top: var(--s6);
}

.select__buttons { display: flex; gap: var(--s3); margin-left: auto; }

/* CPU level --------------------------------------------------------------- */

.level { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s2); }
.level__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--s3); }
.level__desc { font-size: 14px; line-height: 20px; color: var(--muted); }
.level__options { display: flex; gap: var(--s1); }

.level__opt {
  width: 36px;
  height: 36px;
  border: var(--border);
  background: var(--surface);
  font: 12px/16px var(--font-head);
  color: var(--ink);
  cursor: pointer;
  transition: background-color var(--dur) var(--step), color var(--dur) var(--step);
}
.level__opt:hover { background: var(--surface-2); }
.level__opt[aria-checked='true'] { background: var(--ink); color: var(--surface); box-shadow: var(--shadow-sm); }
.level__opt[aria-checked='true']:hover { background: var(--ink); }

/* Loadout + move picker --------------------------------------------------- */

.loadout { display: grid; gap: var(--s2); }
.loadout__head { display: flex; align-items: baseline; justify-content: space-between; }
.loadout__hint { font-size: 14px; line-height: 20px; color: var(--muted); }

.loadout__slot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s1) var(--s2);
  width: 100%;
  padding: var(--s2) var(--s3);
  border: var(--border);
  border-left: 8px solid var(--type, var(--ink));
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--dur) var(--step);
}
.loadout__slot:hover { background: var(--surface-2); }
.loadout__slot:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
.loadout__slot:disabled { cursor: default; }
.loadout__slot:disabled:hover { background: var(--surface); }
.loadout__label { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; font: 600 14px/20px var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.loadout__label .type { text-transform: none; letter-spacing: 0; }
.loadout__name { display: flex; align-items: center; gap: var(--s2); min-width: 0; font: 600 16px/24px var(--font-body); }
.loadout__name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loadout__change { font: 600 14px/20px var(--font-body); color: var(--red); text-transform: uppercase; letter-spacing: 0.04em; }
.loadout__slot:disabled .loadout__change { display: none; }
.loadout__desc { grid-column: 1 / -1; font-size: 14px; line-height: 20px; color: var(--muted); }

.modal.modal--picker {
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  padding: 0;
  text-align: left;
}

.picker__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s5);
  border-bottom: var(--border);
  background: var(--surface-2);
}
.picker__head .h2 { margin-top: var(--s2); }
.picker__head .muted { margin-top: var(--s2); font-size: 14px; line-height: 20px; }

.picker__list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s3);
  padding: var(--s4) var(--s5) var(--s5);
  overflow-y: auto;
}

.move-opt {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  padding: var(--s3) var(--s4);
  border: var(--border);
  border-left: 8px solid var(--type, var(--ink));
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--dur) var(--step);
}
.move-opt:hover { background: var(--surface-2); }
.move-opt:active { transform: translate(2px, 2px); box-shadow: none; }
.move-opt.is-equipped { background: #FBF1C8; }
.move-opt__top { display: flex; align-items: center; gap: var(--s2); }
.move-opt__name { font: 600 16px/24px var(--font-body); }
.move-opt__badge { margin-left: auto; font: 600 14px/20px var(--font-body); color: var(--red); white-space: nowrap; }
.move-opt__badge--other { color: var(--muted); }
.move-opt__desc { font-size: 14px; line-height: 20px; color: var(--muted); }
.move-opt__stats { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); font-size: 14px; line-height: 20px; color: var(--muted); }
.move-opt__stats b { color: var(--ink); font-weight: 600; }

/* ==========================================================================
   Battle
   ========================================================================== */

.screen--battle.is-active {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
}

.stage-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1280px;
  height: 720px;
  transform-origin: center;
  overflow: hidden;
  outline: 4px solid var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

.stage.is-mouse { cursor: crosshair; }

.stage__world, .stage__sprites { position: absolute; inset: 0; }

/* Faint scanlines, one per art pixel row. */
.stage::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(38, 36, 44, 0.07) 0 2px, transparent 2px 4px);
}

.stage__layer {
  position: absolute;
  inset: 0;
  width: 1280px;
  height: 720px;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.stage__layer--ui { image-rendering: auto; }

.fighter { position: absolute; left: 0; top: 0; will-change: transform; }
.fighter__body { position: absolute; left: 0; bottom: 0; transform-origin: 50% 100%; }
.fighter__pose { transform-origin: 50% 100%; transition: opacity 120ms steps(2, end); }
.fighter__img {
  display: block;
  transition: transform 500ms steps(6), opacity 500ms steps(6), filter 80ms linear;
}
.fighter__img canvas { display: block; }
.fighter.is-hit .fighter__img { filter: brightness(2.4) saturate(0.3); }
.fighter.is-hidden .fighter__pose { opacity: 0; }
.fighter.is-dashing .fighter__pose { opacity: 0.6; }
.fighter.is-asleep .fighter__img { filter: saturate(0.5) brightness(0.85); }
.fighter.is-down .fighter__img { transform: translateY(24px); opacity: 0.3; filter: grayscale(1); }

/* HUD: two status boxes and a timer, like a handheld battle screen */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 144px minmax(0, 1fr);
  gap: var(--s5);
  padding: var(--s4) var(--s5);
  pointer-events: none;
}

.hud-player {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-width: 0;
  padding: var(--s2);
  border: var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.hud-player--p2 { flex-direction: row-reverse; text-align: right; }

.hud-player__portrait {
  display: grid;
  place-items: center;
  flex: none;
  width: 72px;
  height: 72px;
  border: var(--border);
  background: var(--paper);
  overflow: hidden;
}
.hud-player__portrait canvas { display: block; }
.hud-player--p1 .hud-player__portrait { border-color: var(--p1); }
.hud-player--p2 .hud-player__portrait { border-color: var(--p2); }

.hud-player__info { display: flex; flex-direction: column; gap: var(--s2); flex: 1; min-width: 0; }

.hud-player__row { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.hud-player--p2 .hud-player__row { flex-direction: row-reverse; }

.hud-player__name { font: 400 16px/24px var(--font-head); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pips { display: flex; gap: var(--s1); }
.hud-player__row .hp__text { margin-left: auto; }
.hud-player--p2 .hud-player__row .hp__text { margin-left: 0; margin-right: auto; }
.pips i {
  width: 12px;
  height: 12px;
  border: var(--border);
  background: var(--surface);
  transition: background-color 240ms steps(2, end);
}
.pips i.is-won { background: var(--yellow); }

.hp {
  position: relative;
  height: 16px;
  border: var(--border);
  background: var(--ink);
  overflow: hidden;
}
.hp::before {
  content: '';
  position: absolute;
  inset: 2px;
  background: var(--surface-3);
}
.hp__fill, .hp__lag { position: absolute; inset: 2px; transform-origin: left center; }
.hud-player--p2 .hp__fill, .hud-player--p2 .hp__lag { transform-origin: right center; }
.hp__lag { background: #F2A08F; }
.hp__fill { background: var(--hp-high); transition: background-color 240ms steps(2, end); }

.hp__text {
  font: 600 14px/20px var(--font-body);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.cds { display: flex; gap: var(--s1); min-width: 0; }
.hud-player--p2 .cds { flex-direction: row-reverse; }

.cd {
  --cd: 1;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  height: 24px;
  padding: 0 var(--s2) 0 var(--s3);
  border: var(--border);
  background: var(--surface);
  font: 500 14px/20px var(--font-body);
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  flex: 1 1 0;
  min-width: 0;
}
.cd::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--type, var(--ink));
}
.cd--dash { flex: none; }
.cd__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cd::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  width: 100%;
  background: var(--hp-high);
  transform-origin: left center;
  transform: scaleX(var(--cd));
}
.cd.is-cooling { background: var(--surface-2); color: var(--subtle); }
.cd.is-cooling::after { background: var(--subtle); }
.cd__key { font-weight: 700; color: var(--red); }
.cd__key:empty { display: none; }
.cd.is-cooling .cd__key { color: var(--subtle); }

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s1);
  padding: var(--s2) var(--s4);
  border: var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.hud-center__round {
  font: 600 14px/20px var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.hud-center__timer {
  font: 400 32px/48px var(--font-head);
  font-variant-numeric: tabular-nums;
}
.hud-center__timer.is-low { color: var(--red); animation: blink 1000ms steps(1, end) infinite; }

/* Banner */
.banner {
  position: absolute;
  left: 0;
  right: 0;
  top: 320px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms steps(4, end), transform 200ms steps(4, end);
}
.banner.is-visible { opacity: 1; transform: none; }
.banner__title {
  font: 400 48px/64px var(--font-head);
  color: #FFFCF0;
  text-shadow:
    -4px 0 0 var(--ink), 4px 0 0 var(--ink), 0 -4px 0 var(--ink), 0 4px 0 var(--ink),
    4px 4px 0 var(--ink), -4px -4px 0 var(--ink), 4px -4px 0 var(--ink), -4px 4px 0 var(--ink),
    8px 8px 0 var(--ink);
}
.banner__sub {
  display: inline-block;
  margin-top: var(--s4);
  padding: var(--s2) var(--s4);
  border: var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  font: 400 16px/24px var(--font-head);
  color: var(--ink);
}

/* Battle bar */
.battle-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  height: 64px;
  padding: 0 var(--s5);
  border-top: var(--border);
  background: var(--surface);
}
.battle-bar__hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s1) var(--s4);
  font-size: 14px;
  line-height: 20px;
  color: var(--muted);
  min-width: 0;
}
.battle-bar__hint span { display: inline-flex; align-items: center; gap: var(--s1); }
.battle-bar__actions { display: flex; align-items: center; gap: var(--s3); flex: none; }

/* Overlays: a 2px ink dither instead of a modern blur */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: var(--s5);
  background:
    conic-gradient(rgba(38, 36, 44, 0.5) 25%, transparent 0 50%, rgba(38, 36, 44, 0.5) 0 75%, transparent 0) 0 0 / 4px 4px,
    rgba(38, 36, 44, 0.25);
  animation: screen-in 160ms steps(3, end);
}

.modal {
  width: min(400px, 100%);
  padding: var(--s6);
  border: var(--border);
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px var(--ink), 10px 10px 0 6px var(--ink);
  text-align: center;
  animation: modal-in 160ms steps(3, end);
}
@keyframes modal-in { from { transform: translateY(8px); } to { transform: none; } }

.modal > .muted { margin-top: var(--s3); }
.modal .status { justify-content: center; margin-top: var(--s4); }

.modal__actions { display: grid; gap: var(--s3); margin-top: var(--s5); }

.modal__sprite {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 128px;
  margin: 0 auto var(--s4);
}
.modal__sprite canvas { display: block; }
.modal--results .eyebrow { margin-bottom: var(--s2); }
.modal--results .h2 { font-size: 16px; line-height: 24px; }

/* Touch controls */
.touch {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 64px;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: var(--s4) var(--s5);
  pointer-events: none;
}
.touch__stick {
  position: relative;
  width: 144px;
  height: 144px;
  border: var(--border);
  background: rgba(255, 252, 240, 0.6);
  pointer-events: auto;
  touch-action: none;
}
.touch__knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border: var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.touch__buttons {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 64px);
  gap: var(--s3);
  pointer-events: auto;
}
.touch__btn {
  border: var(--border);
  background: rgba(255, 252, 240, 0.85);
  box-shadow: var(--shadow-sm);
  font: 600 14px/20px var(--font-body);
  color: var(--ink);
  touch-action: none;
}
.touch__btn.is-pressed { background: var(--red); color: var(--on-accent); transform: translate(2px, 2px); box-shadow: none; }
.touch__btn--atk { grid-column: 3; grid-row: 2; }
.touch__btn--sp { grid-column: 3; grid-row: 1; }
.touch__btn--sp2 { grid-column: 2; grid-row: 1; }
.touch__btn--sp3 { grid-column: 1; grid-row: 1; }
.touch__btn--dash { grid-column: 2; grid-row: 2; }

.noscript { padding: var(--s5); text-align: center; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1080px) {
  .hero { grid-template-columns: 1fr; padding-top: var(--s7); }
  .controls-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .select { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .roster { grid-column: 1 / -1; order: -1; }
  .slot { min-height: 0; }
}

@media (max-width: 720px) {
  .container { padding: 0 var(--s4); }
  .display { font-size: 24px; line-height: 36px; }
  .h2 { font-size: 16px; line-height: 24px; }
  .lead { font-size: 16px; line-height: 24px; }
  .section { margin-top: var(--s8); }
  .page { padding-top: var(--s5); }
  .controls-grid, .rules-grid, .lobby-grid { grid-template-columns: 1fr; }
  .roster { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .select { grid-template-columns: 1fr; }
  .select__actions { position: sticky; bottom: 0; padding: var(--s3) 0; background: var(--paper); }
  .select__actions { gap: var(--s3); }
  .select__buttons { width: 100%; margin-left: 0; }
  .select__buttons .btn { flex: 1; }
  .level { width: 100%; }
  .level__opt { flex: 1; width: auto; min-width: 0; }
  .picker__list { grid-template-columns: 1fr; padding: var(--s3) var(--s4) var(--s4); }
  .picker__head { padding: var(--s4); }
  .asset-status span:last-child { display: none; }
  .screen-head { flex-direction: column; gap: var(--s2); }
  .screen-head .btn--ghost { margin-left: calc(var(--s3) * -1); }
  .brand span { font-size: 12px; line-height: 16px; }
  .room__code { font-size: 24px; line-height: 32px; }
  .battle-bar { padding: 0 var(--s4); }
  .battle-bar__hint { display: none; }
  .modal { padding: var(--s5); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
