:root {
  --bg: #0b0d11;
  --panel: #12161d;
  --panel-2: #171c25;
  --border: #232a35;
  --text: #e8ecf1;
  --text-dim: #8b95a5;
  --accent: #2f6df6;
  --live: #ff3b30;
  --ok: #34d17a;
  --warn: #f5a623;
  color-scheme: dark;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font:
    16px/1.5 -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    system-ui,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition:
    background 0.12s ease,
    transform 0.05s ease;
}
button:active {
  transform: scale(0.97);
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 650;
}
button.danger {
  background: var(--live);
  border-color: var(--live);
  font-weight: 650;
}
button.ghost {
  background: transparent;
  border: none;
}
button.big {
  padding: 16px;
  font-size: 18px;
  font-weight: 700;
}

input[type='text'] {
  font: 20px/1.4 ui-monospace, Menlo, monospace;
  letter-spacing: 6px;
  text-align: center;
  color: inherit;
  background: #0e1219;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  width: 100%;
  text-transform: uppercase;
}
input[type='text']:focus {
  outline: none;
  border-color: var(--accent);
}

.screen {
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

/* ---- Màn nhập mã ---- */

#join {
  max-width: 420px;
  margin: 0 auto;
  padding-top: max(60px, env(safe-area-inset-top));
  display: grid;
  gap: 14px;
}
#join h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
#join .hint {
  color: var(--text-dim);
  font-size: 14px;
}
#join form {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}
.error {
  color: var(--live);
  font-size: 13px;
  min-height: 1em;
}

/* ---- Bảng điều khiển ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}
#app[data-status='live'] .dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent);
}
#app[data-status='waiting'] .dot {
  background: var(--warn);
}
#app[data-status='error'] .dot {
  background: var(--live);
}
.pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font: 13px/1 ui-monospace, Menlo, monospace;
  letter-spacing: 2px;
}
#disconnectBtn {
  padding: 6px 10px;
  font-size: 16px;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.tabs button {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 8px 8px 0 0;
  padding: 12px;
  color: var(--text-dim);
  font-weight: 550;
}
.tabs button.active {
  color: var(--text);
  background: var(--bg);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.tab {
  display: none;
  padding: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.tab.active {
  display: block;
}

/* ---- Trận đấu ---- */

.tournament-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 14px;
  min-height: 1em;
}

.teams {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}
@media (min-width: 640px) {
  .teams {
    grid-template-columns: 1fr 1fr;
  }
}

.team {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  gap: 10px;
}
.team header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}
.stripe {
  width: 6px;
  height: 22px;
  border-radius: 3px;
  background: var(--text-dim);
}
.team-name-input {
  flex: 1;
  min-width: 0;
  font: 650 15px/1.4 inherit;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 8px;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.team-name-input:hover {
  border-color: var(--border);
}
.team-name-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #0e1219;
}
.color-picker {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
}
.color-picker::-webkit-color-swatch-wrapper {
  padding: 3px;
}
.color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 5px;
}
.serve-pill {
  background: color-mix(in srgb, var(--ok) 20%, transparent);
  border: 1px solid color-mix(in srgb, var(--ok) 60%, transparent);
  color: var(--ok);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.timeout-pill {
  background: color-mix(in srgb, var(--warn) 20%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 60%, transparent);
  color: var(--warn);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
}
.score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.score-value {
  font-size: 56px;
  font-weight: 800;
  min-width: 80px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.score-adj {
  width: 44px;
  height: 44px;
  font-size: 22px;
  padding: 0;
  border-radius: 50%;
}
.games {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}
.games b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.row-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

/* ---- Bàn trộn tiếng ---- */

.audio-list {
  list-style: none;
  display: grid;
  gap: 10px;
}
.audio-channel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: grid;
  gap: 10px;
}
.audio-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.audio-head .name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.audio-head .value {
  color: var(--text-dim);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 34px;
  text-align: right;
}
.mute-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 18px;
  border-radius: 10px;
}
.mute-btn.muted {
  background: var(--live);
  border-color: var(--live);
}
.audio-slider {
  width: 100%;
  height: 32px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}
.audio-slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--ok), var(--warn) 78%, var(--live));
}
.audio-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  margin-top: -7px;
  border: 2px solid var(--border);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.audio-slider::-moz-range-track {
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--ok), var(--warn) 78%, var(--live));
}
.audio-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--border);
}

/* ---- Replay ---- */

#replayToggle {
  margin-bottom: 12px;
}
#replayToggle.armed {
  background: var(--live);
  border-color: var(--live);
  font-weight: 700;
}

.replay-actions {
  margin-top: 0;
}
.clips {
  list-style: none;
  display: grid;
  gap: 10px;
  margin-top: 16px;
}
.clip {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 8px;
}
.clip.playing {
  border-color: var(--live);
  background: color-mix(in srgb, var(--live) 8%, var(--panel));
}
.clip-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}
.clip-head .name {
  flex: 1;
  font-weight: 600;
}
.clip-head .duration {
  color: var(--text-dim);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
}
.clip-speed {
  display: flex;
  align-items: center;
  gap: 10px;
}
.clip-speed label {
  font-size: 12px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.clip-speed select {
  flex: 1;
  padding: 8px 10px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 550;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3e%3cpath fill='%238b95a5' d='M6 8L0 0h12z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
.clip.playing .clip-speed select {
  border-color: color-mix(in srgb, var(--live) 40%, var(--border));
}
.clip-actions {
  display: flex;
  gap: 8px;
}
.clip-actions button {
  flex: 1;
}
.empty {
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
  padding: 20px 12px;
  line-height: 1.6;
}
.hint {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 10px;
}
