:root {
  --bg: #07090d;
  --panel: #0a1017;
  --teal: #00c8a8;
  --teal-dark: #007c6a;
  --gold: #ffd43b;
  --red: #eb2f2f;
  --cyan: #4ef6ff;
  --clay: #c44d29;
  --text: #f3f7fa;
  --muted: #8ea7b5;
  --font-pixel: "Press Start 2P", "Silkscreen", ui-monospace, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --font-ui: "Silkscreen", "Press Start 2P", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  background: radial-gradient(circle at top, #121c29 0%, var(--bg) 65%);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100%;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 10px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Player Switcher */
.player-bar {
  background: var(--panel);
  border: 2px solid var(--teal-dark);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.field-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 150px;
  min-width: 0;
}

.field-label {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--teal);
  white-space: nowrap;
}

.player-form input,
.player-form select {
  width: 100%;
  min-width: 0;
  background: #04070b;
  color: var(--text);
  border: 2px solid var(--teal-dark);
  border-radius: 4px;
  padding: 6px 8px;
  font-family: var(--font-ui);
  font-size: 13px;
  outline: none;
}

.player-form input:focus,
.player-form select:focus {
  border-color: var(--gold);
}

.btn-arcade {
  background: var(--teal);
  color: #041013;
  border: 2px solid #7cf5e2;
  border-radius: 4px;
  padding: 7px 10px;
  font-family: var(--font-pixel);
  font-size: 10px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-arcade:active {
  transform: translateY(1px);
}

.player-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.player-chip {
  background: #0d1822;
  color: var(--text);
  border: 1px solid var(--teal-dark);
  border-radius: 4px;
  padding: 4px 8px;
  font-family: var(--font-ui);
  font-size: 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.player-chip.active {
  background: #083a36;
  border-color: var(--gold);
  color: var(--gold);
}

.player-chip .chip-best {
  color: var(--cyan);
  font-size: 10px;
}

/* Arcade Cabinet */
.cabinet {
  background: #05070a;
  border: 3px solid var(--teal);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 0 28px rgba(0, 200, 168, 0.16), inset 0 0 12px rgba(0, 200, 168, 0.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Top HUD */
.top-hud {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: stretch;
  background: #04080d;
  border: 2px solid var(--teal-dark);
  padding: 7px 9px;
}

.hud-p1 {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.tag-1p {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--cyan);
}

.flag-pill {
  font-family: var(--font-pixel);
  font-size: 9px;
  background: #0b2b33;
  border: 1px solid var(--teal);
  color: var(--gold);
  padding: 2px 4px;
}

.player-title {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-score-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.score-label {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--teal);
}

.score-val {
  font-family: var(--font-pixel);
  font-size: 13px;
  color: var(--gold);
}

.hud-wr {
  border-left: 2px solid var(--teal-dark);
  padding-left: 9px;
  min-width: 0;
}

.wr-title {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--teal);
  margin-bottom: 4px;
}

.wr-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: var(--font-pixel);
  font-size: 9px;
}

.wr-list li {
  display: grid;
  grid-template-columns: 32px 48px 1fr;
  gap: 6px;
  color: var(--gold);
  white-space: nowrap;
  overflow: hidden;
}

.wr-list li .wr-name {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-toggles {
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
}

.btn-mini {
  background: #0d1620;
  color: var(--cyan);
  border: 1px solid var(--teal-dark);
  border-radius: 3px;
  padding: 4px 6px;
  font-family: var(--font-pixel);
  font-size: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-mini.off {
  color: var(--muted);
  border-color: #293640;
}

/* Canvas Viewport */
.screen-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 1;
  background: #000;
  border: 2px solid var(--teal-dark);
  overflow: hidden;
}

.screen-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.screen-wrap.scanlines::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.24) 3px,
    rgba(0, 0, 0, 0.24) 4px
  );
}

/* Speed Bar Strip */
.speed-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #04080d;
  border: 2px solid var(--teal-dark);
  padding: 6px 9px;
}

.speed-label {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--text);
  white-space: nowrap;
}

.speed-meter {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  gap: 2px;
  height: 14px;
}

.speed-seg {
  background: #17212b;
  border-radius: 1px;
}

.speed-seg.on-low {
  background: var(--red);
}

.speed-seg.on-mid {
  background: var(--gold);
}

.speed-seg.on-high {
  background: var(--cyan);
  box-shadow: 0 0 6px rgba(78, 246, 255, 0.7);
}

.speed-readout {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  min-width: 112px;
  text-align: right;
}

.speed-readout small {
  font-size: 8px;
  color: var(--teal);
}

/* Scoreboard */
.scoreboard {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 8px;
  background: #031117;
  border: 2px solid var(--teal);
  padding: 8px;
}

.board-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.live-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: #050b10;
  border: 1px solid var(--teal-dark);
  padding: 6px;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.m-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--teal);
}

.m-val {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-wrap {
  background: #050b10;
  border: 1px solid var(--teal-dark);
  padding: 6px;
}

.lb-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--teal);
  margin-bottom: 6px;
}

.btn-reset {
  background: transparent;
  color: var(--muted);
  border: 1px solid #354754;
  padding: 2px 6px;
  font-family: var(--font-pixel);
  font-size: 7px;
  cursor: pointer;
}

.btn-reset:hover {
  color: var(--red);
  border-color: var(--red);
}

.lb-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 145px;
  overflow-y: auto;
}

.lb-row {
  display: grid;
  grid-template-columns: 36px 34px 1fr 56px 46px;
  gap: 5px;
  align-items: center;
  font-family: var(--font-ui);
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 2px;
}

.lb-row.active-player {
  background: rgba(0, 200, 168, 0.16);
  color: var(--gold);
}

.lb-rank {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--cyan);
}

.lb-country {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--muted);
}

.lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-badge {
  font-family: var(--font-pixel);
  font-size: 7px;
  padding: 1px 3px;
  border-radius: 2px;
  text-align: center;
}

.lb-badge.cpu {
  background: #1a2430;
  color: #8ea7b5;
}

.lb-badge.p1 {
  background: #0b3c35;
  color: var(--teal);
}

.lb-time {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--gold);
  text-align: right;
}

.board-right {
  background: #050b10;
  border: 1px solid var(--teal-dark);
  padding: 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
}

.stat-box {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  border-bottom: 1px dashed #17303a;
  padding-bottom: 4px;
}

.stat-k {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--teal);
}

.stat-v {
  font-family: var(--font-pixel);
  font-size: 12px;
  color: var(--text);
}

.qualify-v {
  color: var(--cyan);
}

.pb-v {
  color: var(--gold);
}

.status-badge {
  margin-top: auto;
  text-align: center;
  font-family: var(--font-pixel);
  font-size: 11px;
  padding: 8px 6px;
  border: 2px solid var(--teal);
  background: #082328;
  color: var(--gold);
}

.status-badge.foul {
  border-color: var(--red);
  background: #2b090d;
  color: #ff6b6b;
}

.status-badge.wr {
  border-color: var(--gold);
  background: #332605;
  color: var(--gold);
}

.status-badge.qualify {
  border-color: var(--cyan);
  background: #062836;
  color: var(--cyan);
}

/* Controls */
.controls-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-actions {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 8px;
}

.btn-run,
.btn-start {
  touch-action: manipulation;
  user-select: none;
  border-radius: 6px;
  font-family: var(--font-pixel);
  cursor: pointer;
  padding: 14px 12px;
}

.btn-run {
  background: linear-gradient(180deg, #ff4f4f 0%, #c81d1d 100%);
  color: #fff;
  border: 3px solid #ff9c9c;
  font-size: 13px;
  box-shadow: 0 4px 0 #6e0e0e;
}

.btn-run:active,
.btn-run.pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #6e0e0e;
}

.btn-start {
  background: linear-gradient(180deg, #00d9b6 0%, #008972 100%);
  color: #041315;
  border: 3px solid #86fff0;
  font-size: 10px;
  box-shadow: 0 4px 0 #00473b;
}

.btn-start:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #00473b;
}

.control-hint {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

kbd {
  background: #13202c;
  color: var(--gold);
  border: 1px solid var(--teal-dark);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--font-pixel);
  font-size: 9px;
}

@media (max-width: 640px) {
  .shell {
    padding: 8px 6px 18px;
  }

  .top-hud {
    grid-template-columns: 1fr auto;
  }

  .hud-wr {
    grid-column: 1 / -1;
    border-left: none;
    border-top: 1px solid var(--teal-dark);
    padding-left: 0;
    padding-top: 6px;
  }

  .scoreboard {
    grid-template-columns: 1fr;
  }

  .live-metrics {
    grid-template-columns: repeat(3, 1fr);
  }

  .m-val {
    font-size: 9px;
  }

  .speed-readout {
    min-width: 96px;
    font-size: 9px;
  }

  .control-actions {
    grid-template-columns: 1fr;
  }

  .btn-run {
    padding: 16px 12px;
    font-size: 12px;
  }
}
