:root {
  --bg: #070911;
  --panel: #10141f;
  --panel-2: #171d2c;
  --line: #232b3d;
  --text: #e8ecf6;
  --muted: #8d97ae;
  --accent: #22d3ee;
  --danger: #ff5f7a;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

#app {
  display: flex;
  gap: 14px;
  height: 100%;
  padding: 14px;
  /* Flex items default to min-height/min-width:auto, which lets an oversized
     child push past the viewport instead of shrinking. Without these the
     arena overflows the window on small screens. */
  min-height: 0;
  min-width: 0;
}

#stage {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

canvas#game {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius);
  background: #0a0d16;
  box-shadow: 0 0 0 1px var(--line), 0 24px 60px rgba(0, 0, 0, 0.55);
}

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#overlay > * { pointer-events: auto; }

#hud {
  flex: 0 0 258px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  overflow-y: auto;
}

/* ---------------------------------------------------------------- HUD --- */

.hud-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.hud-round { font-weight: 650; font-size: 15px; letter-spacing: 0.01em; }
.hud-target { color: var(--muted); font-size: 12px; }
.hud-target b { color: var(--text); }

.score-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid transparent;
  transition: opacity 0.25s ease, border-color 0.25s ease;
}
.score-row.leader { border-color: rgba(255, 212, 41, 0.45); }
.score-row.dead { opacity: 0.42; }

.swatch {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.score-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.score-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-sub { font-size: 10.5px; color: var(--muted); letter-spacing: 0.02em; }
.score-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

.effects { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 2px; }
.effect-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 5px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 9.5px;
  line-height: 1.5;
}
.effect-chip b { font-size: 10px; }
.effect-chip i { font-style: normal; opacity: 0.75; font-variant-numeric: tabular-nums; }

.hud-foot {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--panel-2);
  font: inherit;
  font-size: 10.5px;
  color: var(--text);
}

/* ------------------------------------------------------------ overlays --- */

#overlay.blocking { background: rgba(5, 7, 14, 0.72); backdrop-filter: blur(3px); }

.panel {
  width: min(560px, 92%);
  max-height: 92%;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px 28px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.65);
  animation: pop 0.18s ease-out;
}
.panel.wide { width: min(880px, 96%); }

@keyframes pop { from { transform: scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }

.title {
  margin: 0 0 4px;
  font-size: 30px;
  font-weight: 750;
  letter-spacing: -0.02em;
}
.title .accent {
  background: linear-gradient(92deg, #22d3ee, #a78bfa 55%, #ff5fa8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { margin: 0 0 22px; color: var(--muted); font-size: 13.5px; }
h2.section { margin: 22px 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 560;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}
.btn:hover { background: #1e2637; border-color: #33405c; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #29c9e6, #12a7c4);
  border-color: transparent;
  color: #05131a;
  font-weight: 700;
}
.btn.primary:hover { background: linear-gradient(180deg, #37d8f4, #17b6d4); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(255, 95, 122, 0.35); }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn.block { width: 100%; }

.stack { display: flex; flex-direction: column; gap: 9px; }
.row { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1 1 auto; }

.field {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid rgba(35, 43, 61, 0.6);
}
.field:last-child { border-bottom: 0; }
.field-label { font-size: 13.5px; }
.field-hint { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button {
  padding: 7px 12px;
  background: var(--panel-2);
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button.on { background: #22d3ee1f; color: var(--accent); font-weight: 650; }

input[type="range"] { width: 170px; accent-color: var(--accent); }
input[type="text"], input[type="number"] {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
input[type="text"]:focus, input[type="number"]:focus { outline: 2px solid #22d3ee55; border-color: var(--accent); }
.num { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12.5px; min-width: 54px; text-align: right; }

/* ----------------------------------------------------------- countdown --- */

.countdown {
  font-size: 130px;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: #fff;
  text-shadow: 0 0 46px rgba(34, 211, 238, 0.55);
  animation: cd 0.6s ease-out;
}
.countdown.go { font-size: 92px; color: var(--accent); }
@keyframes cd { from { transform: scale(1.5); opacity: 0; } to { transform: none; opacity: 1; } }

.banner {
  position: absolute;
  top: 26px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(10, 14, 24, 0.9);
  border: 1px solid var(--line);
  font-size: 15px;
  font-weight: 620;
  white-space: nowrap;
}

.keybtn { min-width: 96px; font-variant-numeric: tabular-nums; }
.keybtn.listening { border-color: var(--accent); color: var(--accent); background: #22d3ee14; }

.color-dot {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  padding: 0;
}

.howto { margin: 0; padding-left: 20px; color: #c4ccdd; font-size: 13.5px; line-height: 1.75; }
.howto li { margin-bottom: 7px; }
.howto b { color: var(--text); }

.standings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.standing {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px solid transparent;
}
.standing.first { border-color: rgba(255, 212, 41, 0.5); background: #ffd4290d; }
.place { width: 26px; color: var(--muted); font-size: 12.5px; font-weight: 650; }
.standing-name { font-weight: 620; font-size: 14.5px; }
.standing-sub { color: var(--muted); font-size: 11.5px; }
.standing .spacer, .standing-sub { margin-left: auto; }
.standing .score-value { min-width: 34px; text-align: right; }

.hist-chip {
  padding: 3px 9px;
  border: 1px solid;
  border-radius: 999px;
  font-size: 11px;
  opacity: 0.85;
}

.pu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 7px; }
.pu-cell {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}
.pu-cell.on { opacity: 1; border-color: #33405c; }
.pu-cell input { accent-color: var(--accent); }
.pu-glyph {
  width: 24px; height: 24px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border: 1px solid; border-radius: 7px;
  font-size: 13px;
}
.pu-name { display: block; font-size: 12.5px; font-weight: 600; }
.pu-target { display: block; font-size: 10px; color: var(--muted); letter-spacing: 0.03em; }

#hud.hidden { display: none; }

/* --------------------------------------------------------------- lobby --- */

.roster { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.roster-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-2);
  flex-wrap: wrap;
}
.name-input { width: 132px; }
.roster-row .remove { padding: 5px 9px; }

.keybtn.conflict {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(255, 95, 122, 0.09);
}

.lobby-warning {
  min-height: 18px;
  margin: 12px 0 0;
  font-size: 12.5px;
  color: var(--danger);
  opacity: 0;
  transition: opacity 0.15s ease;
}
.lobby-warning.visible { opacity: 1; }

/* ---------------------------------------------------------- responsive --- */

@media (max-width: 900px), (max-aspect-ratio: 1/1) {
  #app { flex-direction: column; padding: 10px; gap: 10px; }
  #hud { flex: 0 0 auto; max-height: 34vh; }
  .score-list { flex-direction: row; flex-wrap: wrap; }
  .score-row { flex: 1 1 150px; }
  .hud-foot { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .countdown { animation: none !important; }
  * { transition-duration: 0.01ms !important; }
}
