:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-alt: #1f2630;
  --text: #e6edf3;
  --muted: #9aa4b2;
  --accent: #e10600;
  --good: #2ea043;
  --bad: #6e7681;
  --warn: #d29922;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(circle at top, #1a2230, var(--bg) 50%);
  color: var(--text);
}
.app-shell { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem;
}
h1 { margin: 0; }
.subtitle { margin: 0.25rem 0 0; color: var(--muted); }
.scoreboard { display: flex; gap: 1rem; flex-wrap: wrap; }
.scoreboard div {
  background: var(--panel); border: 1px solid #30363d; border-radius: 10px; padding: 0.5rem 0.75rem; min-width: 100px;
}
.scoreboard span { color: var(--muted); display: block; font-size: 0.75rem; }
.panel { position: relative; background: var(--panel); border: 1px solid #30363d; border-radius: 14px; padding: 1rem; margin-bottom: 1rem; }
.hidden { display: none; }

.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }
input, select, button {
  width: 100%; border-radius: 8px; border: 1px solid #3d444d; background: #0f141a; color: var(--text); padding: 0.6rem;
}
button { cursor: pointer; background: #222b36; font-weight: 600; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.status { color: var(--muted); margin-bottom: 0.75rem; }
.stage-head { display: flex; gap: 0.75rem; align-items: flex-start; justify-content: space-between; margin-bottom: 0.5rem; }
.stage-title { margin-top: 0; margin-bottom: 0.35rem; }
.team-grid, .driver-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0.65rem; }
.card {
  border: 1px solid #3d444d; border-radius: 10px; padding: 0.6rem; background: var(--panel-alt); transition: 0.2s;
}
.card h4 { margin: 0 0 0.35rem; }
.card p { margin: 0.1rem 0; font-size: 0.85rem; }
.card.selectable:hover { transform: translateY(-1px); border-color: var(--accent); }
.card.selected { outline: 2px solid var(--accent); }
.card.locked { border-color: var(--good); opacity: 0.9; }
.card.eliminated { background: #2a2f36; opacity: 0.55; }
.inline-list { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.5rem 0; }
.badge { background: #273142; padding: 0.25rem 0.5rem; border-radius: 999px; font-size: 0.75rem; }
.history { margin-top: 0.75rem; font-size: 0.9rem; }
.history ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }

.board-wrap { overflow-x: auto; }
.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(112px, auto);
  gap: 0.35rem;
  align-items: start;
  justify-content: start;
  width: max-content;
  min-width: 100%;
}
.board-col { border: 1px solid #3d444d; border-radius: 10px; padding: 0.35rem; background: #131920; min-width: 112px; }
.board-col h5 { margin: 0 0 0.35rem; font-size: 0.78rem; }
.slot {
  border: 1px dashed #4b5563;
  border-radius: 8px;
  height: 34px;
  margin-bottom: 0.25rem;
  padding: 0.12rem 0.22rem;
  font-size: 0.74rem;
  display: flex;
  align-items: center;
}
.slot.good { border-style: solid; border-color: var(--good); background: rgba(46,160,67,0.14); }
.slot.bad { border-style: solid; border-color: var(--bad); }
.slot.current { border-color: var(--warn); }
.slot.history-slot { border-style: solid; border-color: #384453; }

.driver-token {
  width: 100%;
  border: 1px solid #3d444d;
  border-radius: 8px;
  padding: 0.2rem 0.28rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-align: left;
  color: var(--text);
  background: var(--panel-alt);
}

.driver-token-btn {
  width: auto;
  min-width: 72px;
  cursor: pointer;
}

.slot .driver-token {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-info-slot {
  min-height: 34px;
  height: auto;
  align-items: flex-start;
}

.result-info-main {
  font-weight: 700;
  line-height: 1.2;
}

.result-info-detail {
  margin-top: 0.08rem;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.15;
}

.finish-overlay {
  position: absolute;
  inset: 0;
  background: rgba(7, 10, 14, 0.72);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 20;
}

.finish-modal {
  width: min(560px, 100%);
  background: linear-gradient(165deg, #1a222d, #111822);
  border: 1px solid #3d444d;
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.finish-modal h2 {
  margin-top: 0;
}

.finish-actions {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.finish-toolbar {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
  padding: 0.85rem;
  border: 1px solid #30363d;
  border-radius: 12px;
  background: #111822;
}

.finish-toolbar .status {
  margin: 0;
}


.backend-feedback {
  max-width: 1200px;
  margin: 0 auto 1rem;
  padding: 0 1rem;
  color: var(--muted);
  min-height: 1.3rem;
}

.session-chip {
  margin-left: auto;
  background: var(--panel);
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  min-width: 220px;
  text-align: right;
}

.session-chip span {
  color: var(--muted);
  display: block;
  font-size: 0.75rem;
}

.session-chip strong {
  font-size: 0.9rem;
}

.driver-select-grid {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.55rem;
}

.driver-choice {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 0.35rem 0.5rem;
  align-items: center;
  padding: 0.45rem 0.55rem;
  border: 1px solid #3d444d;
  border-radius: 10px;
  background: var(--panel-alt);
  font-size: 0.78rem;
}

.driver-choice input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--good);
}

.driver-choice span {
  font-weight: 700;
}

.driver-choice small {
  grid-column: 2;
  color: var(--muted);
  font-size: 0.7rem;
}

.driver-choice.selected {
  outline: 1px solid var(--good);
}


.stage2-driver-board {
  grid-auto-columns: minmax(220px, auto);
}

.stage2-driver-col {
  min-width: 220px;
}

.stage2-driver-slot {
  min-height: 34px;
  height: auto;
  align-items: flex-start;
  padding: 0.18rem 0.24rem;
}

.stage2-driver-row {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.22rem;
}

.stage2-driver-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  border: 1px solid #3d444d;
  border-radius: 7px;
  padding: 0.18rem 0.28rem;
  background: #111822;
  font-size: 0.68rem;
  font-weight: 700;
}

.stage2-driver-chip input {
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: var(--good);
}

.stage2-driver-chip.good {
  border-color: var(--good);
  background: rgba(46,160,67,0.15);
}

.stage2-driver-chip.bad {
  border-color: #a64d4d;
  background: rgba(166,77,77,0.18);
}

.stage2-driver-chip.neutral {
  border-color: rgba(222, 226, 230, 0.95);
  border-style: dashed;
  background: transparent;
}

.stage2-driver-chip.selected {
  outline: 1px solid var(--warn);
}

.stage2-driver-chip.selectable {
  cursor: pointer;
}

@media (max-width: 860px) {
  .grid-3 { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
  .stage-head { flex-direction: column; }
  .session-chip {
    margin-left: 0;
    text-align: left;
    width: 100%;
  }
}


.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(154, 164, 178, 0.35);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  pointer-events: none;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.team-token {
  display: inline-flex;
  flex-direction: column;
  gap: 0.12rem;
  align-items: flex-start;
}

.team-token span {
  font-size: 0.65rem;
  opacity: 0.88;
}

.stage-toggle-slot {
  min-height: 34px;
}

.driver-token-static {
  width: 100%;
  cursor: pointer;
}

.s2-row, .s3-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.3rem;
  font-size: 0.68rem;
}

.s2-team {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 56px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 30px;
  height: 16px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background-color: #3d444d;
  transition: .2s;
  border-radius: 999px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 2px;
  top: 2px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
}

.switch input:checked + .slider {
  background-color: var(--good);
}

.switch input:checked + .slider:before {
  transform: translateX(14px);
}


.stage123-board {
  grid-auto-columns: minmax(148px, auto);
  gap: 0.3rem;
}

.stage-mini-col {
  width: 148px;
  min-width: 148px;
}
