:root {
  color-scheme: dark;
  --bg: #0c1018;
  --surface: #141c29;
  --control: #202a3b;
  --border: #344157;
  --text: #edf2fa;
  --muted: #b5c2d4;
  --blue: #89bdff;
  --gold: #ffd16b;
  --danger: #ffb291;
  font: 16px/1.5 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--text); background: var(--bg); }
button, input, select { font: inherit; }
a { color: var(--blue); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 70rem;
  margin: auto;
  padding: 1.25rem clamp(1rem, 4vw, 2.5rem);
}

.bar h1 { margin: 0; font-size: clamp(1.1rem, 3vw, 1.65rem); line-height: 1.15; letter-spacing: -.02em; }
.bar h1 span { display: block; margin-top: .3rem; color: var(--blue); font-size: .875rem; letter-spacing: 0; }
.bar-actions { display: flex; gap: .5rem; }
#langToggle { min-width: 3.6rem; justify-content: center; }

.btn, select, input::file-selector-button {
  border: 1px solid var(--border);
  border-radius: .45rem;
  background: var(--control);
  color: var(--text);
  padding: .5rem .75rem;
  font-size: .875rem;
  font-weight: 600;
}

.btn { display: inline-flex; align-items: center; gap: .35rem; text-decoration: none; white-space: nowrap; }
.btn, select, input::file-selector-button { cursor: pointer; }
.btn:hover:not(:disabled), select:hover:not(:disabled) { border-color: var(--blue); }
.btn:disabled, select:disabled { opacity: .5; cursor: default; }

main { padding: 0 clamp(.75rem, 3vw, 2rem) 2rem; }
.cabinet {
  width: min(100%, max(36rem, calc(69svh * 1.28)));
  max-width: 60rem;
  margin-inline: auto;
  overflow: clip;
  border: 1px solid var(--border);
  border-top: 3px solid var(--blue);
  border-radius: .75rem;
  background: var(--surface);
  box-shadow: 0 16px 48px #0005;
}
.cabinet-head, .cabinet-foot { padding: .75rem 1rem; }
.cabinet-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.cabinet-head label { color: var(--muted); font-size: .875rem; }
.cabinet-head select { margin-right: auto; min-width: 0; }
select {
  appearance: none;
  padding-right: 1.85rem;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) right .89rem center / 5px 5px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) right .6rem center / 5px 5px no-repeat,
    var(--control);
}

.stage { aspect-ratio: 256 / 200; max-height: max(10rem, calc(100svh - 14.25rem)); background: #030507; }
.cabinet:has(.gate:not(.hidden)) .stage { display: none; }
.stage:fullscreen { display: grid; place-items: center; width: 100vw; height: 100vh; max-height: none; aspect-ratio: auto; }
#view { display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }

.gate {
  display: grid;
  align-content: center;
  justify-items: start;
  gap: .8rem;
  min-height: clamp(18rem, 50svh, 34rem);
  padding: clamp(1.25rem, 6vw, 4rem);
  border-block: 1px solid var(--border);
  background: radial-gradient(ellipse at 15% 25%, #1d3252, #101a29 65%);
}
.gate.hidden { display: none; }
.gate h2 { margin: 0; font-size: clamp(1.45rem, 4vw, 2.45rem); line-height: 1.15; }
.gate p { margin: 0; max-width: 34rem; }
.file-label { font-weight: 600; }
.file-label + .file { max-width: 100%; color: var(--muted); font-size: .875rem; }
.file::file-selector-button { margin-right: .65rem; }
.gate .file::file-selector-button { background: var(--blue); border-color: var(--blue); color: #0c1729; }
.note.warn { color: var(--danger); overflow-wrap: anywhere; }
.rom-pick { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .9rem; }
.rom-verdict { margin: 0; color: var(--muted); font-size: .875rem; }
.rom-verdict[data-status="ok"] { color: var(--blue); }
.rom-verdict[data-status="error"] { color: var(--danger); }
.rom-verdict[data-status="ok"]::before { content: "✓ "; }
.rom-verdict[data-status="error"]::before { content: "✗ "; }
.rom-detail { margin: 0; color: var(--muted); font-size: .8125rem; overflow-wrap: anywhere; }
.rom-detail[data-status="error"] { color: var(--danger); }
.launch dd[data-status="ok"] { color: var(--blue); }
.launch dd[data-status="error"] { color: var(--danger); }
.hint { color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; }
.launch { width: min(100%, 26rem); }
.launch-label { margin: .1rem 0 .25rem; color: var(--text); font-size: .8125rem; font-weight: 600; }
.launch-total { display: flex; align-items: center; gap: .6rem; margin: 0 0 .2rem; }
.launch-total progress {
  flex: 1;
  height: .55rem;
  border: 0;
  border-radius: 99px;
  overflow: hidden;
  background: #0a1220;
  appearance: none;
}
.launch-total progress::-webkit-progress-bar { background: #0a1220; }
.launch-total progress::-webkit-progress-value {
  border-radius: 99px;
  background: linear-gradient(90deg, #5c96e8, var(--blue));
  transition: width .25s ease-out;
}
.launch-total progress::-moz-progress-bar { border-radius: 99px; background: var(--blue); }
.launch-total b { min-width: 3.2em; text-align: right; color: var(--blue); font-size: .8125rem; font-variant-numeric: tabular-nums; }
.launch .hint { margin: .15rem 0 0; }
.launch dl { margin: .25rem 0 0; border-top: 1px solid var(--border); }
.launch dl div {
  display: grid;
  grid-template-columns: 5.4rem minmax(0, 1fr);
  gap: .4rem;
  padding: .35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .875rem;
}
.launch dt { color: var(--text); }
.launch dd { margin: 0; color: var(--muted); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.launch button { margin-top: .65rem; }
.gate:has(#romFile:disabled) .rom-picker { opacity: .55; cursor: wait; }

.battle-status { display: flex; align-items: center; flex-wrap: nowrap; gap: .65rem 1.25rem; min-width: 0; }
.battle-status div { min-width: 0; }
.battle-status .stat-label { display: block; color: var(--muted); font-size: .875rem; }
.battle-status strong {
  display: block;
  min-height: 1.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#actionLabel { color: var(--gold); }
#holdInput { margin-left: auto; flex: 0 0 auto; touch-action: none; }
#holdInput[aria-pressed="true"] { color: #131b2a; background: var(--gold); border-color: var(--gold); }
.note { margin: .55rem 0 0; color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; }
.note:empty { display: none; }
.cabinet-foot:has(.battle-status[hidden] + .note:empty) { display: none; }

.backdrop { position: fixed; inset: 0; z-index: 2; background: #0009; }
.drawer {
  position: fixed;
  z-index: 3;
  inset: 0 0 0 auto;
  width: min(28rem, 100%);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--surface);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform .18s, visibility .18s;
}
.drawer.open { visibility: visible; transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 1.15rem; margin: 0; }
.icon { padding: .3rem .55rem; color: var(--text); border: 1px solid var(--border); border-radius: .35rem; background: var(--control); cursor: pointer; }
.drawer-body { overflow-y: auto; padding: 0 1.25rem 1.5rem; }
.group { padding: 1rem 0; border-bottom: 1px solid var(--border); }
.group h3 { margin: 0 0 .75rem; font-size: 1rem; }
.field, .switch { display: flex; align-items: center; gap: .6rem; }
.field { justify-content: space-between; }
.slider { display: grid; gap: .3rem; margin-top: .85rem; }
.slider b { color: var(--blue); font-variant-numeric: tabular-nums; }
.drawer .file, .drawer output { display: block; margin-top: .45rem; }
input[type="range"], input[type="checkbox"] { accent-color: var(--blue); }
.hint { color: var(--muted); font-size: .875rem; }
kbd { padding: .05rem .3rem; border: 1px solid var(--border); border-radius: .2rem; font: inherit; }
.settings.disabled { opacity: .55; }

@media (max-width: 29rem) {
  .cabinet-head, .cabinet-foot { padding-inline: .65rem; }
  .cabinet-head select { flex: 1 1 9rem; }
  .battle-status { gap: .5rem .8rem; }
  .delay-queue { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .drawer { transition: none; }
}

/* Arcade cabinet framing and control deck. */
:root {
  --bg: #070912;
  --surface: #11182b;
  --control: #1a223a;
  --border: #354464;
  --text: #f1f4ff;
  --muted: #aab8d2;
  --blue: #8ce5ef;
  --gold: #ffd275;
  --hot: #ff7057;
}
body {
  min-height: 100svh;
  background:
    radial-gradient(ellipse at 75% -20%, #283062 0, transparent 54%),
    radial-gradient(ellipse at 0% 58%, #211632 0, transparent 42%),
    var(--bg);
}

.bar { max-width: 76rem; padding-block: 1.1rem; }
.bar h1 {
  font-family: Bahnschrift, "Arial Narrow", "Segoe UI", sans-serif;
  font-size: clamp(1.2rem, 3.5vw, 2.15rem);
  font-weight: 800;
  font-style: italic;
  letter-spacing: -.045em;
  text-transform: uppercase;
}
.bar h1 em { color: var(--hot); font-style: inherit; }
.bar h1 span {
  margin-top: .26rem;
  color: var(--muted);
  font-family: "Microsoft YaHei", system-ui, sans-serif;
  font-size: .875rem;
  font-style: normal;
  font-weight: 600;
  letter-spacing: .08em;
}
.bar-actions .btn { background: #11182bd9; }

.cabinet {
  position: relative;
  max-width: 64rem;
  border: 1px solid #3b4b76;
  border-top: 3px solid var(--hot);
  border-radius: .85rem;
  background: #11172a;
  box-shadow: 0 0 0 4px #101427, 0 24px 84px #0008;
}
.cabinet-head {
  background: linear-gradient(108deg, #202742, #141c31 68%);
  border-bottom: 1px solid #454c70;
}
.cabinet-head select { border-color: #41557a; }
.cabinet-head .btn, .cabinet-head select {
  box-shadow: inset 0 1px #ffffff0a, 0 2px #0005;
}
.stage {
  position: relative;
  margin: 0;
  background: #04060c;
  box-shadow: inset 0 0 0 2px #000;
}
.stage::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border: 1px solid #a6b8ff22;
  box-shadow: inset 0 1px 7px #0009;
  content: "";
}
.stage:fullscreen::after { display: none; }

.gate {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: clamp(19rem, 50svh, 36rem);
  background:
    linear-gradient(104deg, #10172a 16%, #172a4c 74%, #3c315a),
    #12192c;
}
.gate::before, .gate::after {
  position: absolute;
  z-index: -1;
  pointer-events: none;
  content: "";
}
.gate::before {
  inset: 0 0 0 33%;
  background: linear-gradient(130deg, transparent 17%, #59c5e519 56%, #ff735826 95%);
  clip-path: polygon(55% 0%, 100% 0%, 100% 100%, 0% 100%);
}
.gate::after {
  width: 64%;
  height: 170%;
  right: -20%;
  top: -32%;
  transform: rotate(33deg);
  background: repeating-linear-gradient(90deg, #a6b8ff20 0 1px, transparent 1px 18px);
  mask-image: linear-gradient(90deg, transparent, black 65%);
}
.gate h2 { max-width: 24rem; font-weight: 800; text-wrap: balance; }
.gate p { color: var(--muted); }
.rom-picker {
  display: inline-flex;
  align-items: center;
  min-height: 2.8rem;
  margin-top: .4rem;
  padding: .6rem 1.25rem;
  border: 1px solid #ffb29a;
  border-radius: .45rem;
  background: var(--hot);
  color: #1c1020;
  box-shadow: 0 4px 0 #923a42, 0 8px 24px #ff70572d;
  font-weight: 750;
  cursor: pointer;
}
.rom-picker:hover { background: #ff8973; }
.gate:has(#romFile:focus-visible) .rom-picker { outline: 2px solid var(--blue); outline-offset: 5px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.cabinet-foot {
  border-top: 1px solid #384460;
  background: linear-gradient(160deg, #161f37, #101527);
}
.battle-status { gap: .5rem .8rem; }
.battle-status div {
  min-width: 0;
  padding-inline: .65rem;
  border-inline-start: 2px solid #45607d;
}
/* Fixed bases: the labels never move when an action name or frame count
   changes; text is clipped inside the box instead of resizing it. */
.battle-status div:first-child { flex: 0 1 12.5rem; }
.battle-status div:nth-child(2) { flex: 0 1 12.5rem; }
.battle-status div:first-child { border-color: var(--hot); }
.battle-status strong { font-size: clamp(1rem, 2vw, 1.2rem); }
#actionLabel { color: #ffdc88; }
#activeDelay { color: var(--blue); font-variant-numeric: tabular-nums; }
#holdInput {
  background: #222c47;
  min-height: 2.7rem;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#holdInput span { user-select: none; -webkit-user-select: none; }
#holdInput[aria-pressed="true"] { background: var(--blue); color: #0d2130; border-color: var(--blue); }
.drawer { background: #11192d; }
.drawer-head { background: #19223b; }

@media (max-width: 29rem) {
  .bar { gap: .5rem; }
  .bar-actions .btn { padding-inline: .55rem; }
  .bar h1 { font-size: clamp(1rem, 5vw, 1.4rem); }
  .gate h2 { max-width: 14ch; }
  .gate { min-height: 20rem; }
  .battle-status div { min-width: 0; padding-inline: .45rem; }
  .battle-status div:first-child { flex-basis: 5.8rem; }
  .battle-status div:nth-child(2) { flex-basis: 5.4rem; }
  #holdInput { margin-left: auto; min-height: 2.55rem; }
}
#holdInput .hold-active,
#holdInput[aria-pressed="true"] .hold-ready { display: none; }
#holdInput[aria-pressed="true"] .hold-active { display: inline; color: inherit; }
#holdInput .hold-ready { color: inherit; }
