:root {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-elev: #121826;
  --bg-card: #141c2b;
  --text: #f2f6ff;
  --muted: #b9c6d9;
  --border: rgba(255, 255, 255, 0.12);
  --accent: #2dd4bf;
  --accent-strong: #22c1b3;
  --danger: #ff6b6b;
  --shadow: 0 20px 60px rgba(4, 9, 20, 0.5);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Avenir", "Segoe UI Variable", "Segoe UI", "Helvetica Neue", sans-serif;
  background:
    radial-gradient(1200px 520px at 15% -10%, rgba(45, 212, 191, 0.22), transparent 60%),
    radial-gradient(900px 460px at 110% 10%, rgba(59, 130, 246, 0.18), transparent 55%),
    linear-gradient(180deg, #0b0f16 0%, #0f1624 100%);
  color: var(--text);
  min-height: 100vh;
  padding: 24px;
}

.wrap {
  width: min(920px, 100%);
  margin: 30px auto;
  display: grid;
  gap: 16px;
}

.hidden {
  display: none !important;
}

.head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

h1 {
  margin: 0 0 6px 0;
}

.hint {
  margin: 0;
  color: var(--muted);
}

.auth {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.auth-status {
  font-size: 12px;
  color: var(--muted);
}

.auth-btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  cursor: pointer;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  background: var(--bg-card);
  display: grid;
  gap: 18px;
  box-shadow: var(--shadow);
}

.setup-panel .field {
  display: grid;
  gap: 6px;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
}

button {
  padding: 12px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #051319;
  font-weight: bold;
  transition: transform 0.08s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(45, 212, 191, 0.35);
}

.ghost-btn {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-weight: 600;
}

.grid-two {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.mode-toggle {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.toggle-btn {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
}

.toggle-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.mode-row {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.actions-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.video-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.video-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
  overflow: hidden;
  min-height: 180px;
}

.video-card video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

body[data-mode="online"] {
  background: var(--bg);
  color: var(--text);
  margin: 0;
  overflow: hidden;
  touch-action: manipulation;
}

body[data-mode="training"] {
  touch-action: manipulation;
}

body[data-mode="online"] .game-panel {
  position: fixed;
  inset: 0;
  padding: 0;
  display: block;
}

body[data-mode="online"] .video-grid {
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  gap: 0;
  grid-template-columns: 1fr;
  z-index: 1;
}

body[data-mode="online"] .video-card {
  border: 0;
  border-radius: 0;
  min-height: 0;
  background: #000;
}

body[data-mode="online"] .video-card.video-local {
  display: none;
}

body[data-mode="online"] .hud-overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  align-items: end;
  justify-items: center;
  padding: 16px;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  pointer-events: none;
}

body[data-mode="online"] .hud-overlay > * {
  pointer-events: auto;
}

body[data-mode="online"] .game-head {
  align-self: start;
  justify-self: start;
  margin: 8px;
  position: relative;
  z-index: 20;
}

body[data-mode="online"] .hud-panel {
  width: min(960px, 94vw);
  background: rgba(12, 18, 30, 0.72);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: grid;
  gap: 12px;
  backdrop-filter: blur(8px);
  position: relative;
  z-index: 10;
}

body[data-mode="online"] .topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 26;
}

body[data-mode="online"] #camera-status {
  min-height: 18px;
  color: #f2c46d;
}

body[data-mode="online"] #status {
  min-height: 18px;
  color: #f2c46d;
}

body[data-mode="online"] #game-panel.turn-locked .controls,
body[data-mode="training"] #game-panel.turn-locked .controls {
  opacity: 0.1;
  filter: grayscale(0.6);
  pointer-events: none;
}

body[data-mode="online"] #game-panel.turn-locked .hud-panel,
body[data-mode="online"] #game-panel.turn-locked {
  opacity: 0.1;
}

body[data-mode="online"] #game-panel.turn-locked {
  opacity: 1;
  pointer-events: auto;
}

.tag {
  position: absolute;
  left: 10px;
  bottom: 10px;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 999px;
}

.pick-row {
  border: 1px dashed var(--border);
  padding: 12px;
  border-radius: 12px;
}

.pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.pick-grid label {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  background: var(--bg-elev);
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.game-head {
  display: flex;
  justify-content: flex-end;
}

.small {
  font-size: 12px;
  color: var(--muted);
}

.room-label {
  font-size: 16px;
}

.scoreboard {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
}

.round-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev);
}

.checkout-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev);
  margin-top: 8px;
}

.round-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 70px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #d8fff6;
  background: rgba(45, 212, 191, 0.18);
  border: 1px solid rgba(45, 212, 191, 0.5);
}

.hud-overlay {
  position: fixed; 
}

.topbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  align-items: center;
  position: relative;
  z-index: 20;
}

.topbar .label {
  font-size: 12px;
  color: var(--muted);
}

.topbar .value {
  font-size: 16px;
  font-weight: 700;
}

.topbar .meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.corner-controls {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 30;
}

.info-toggle {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.info-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 25;
}

.lang-toggle {
  justify-self: end;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

@media (max-width: 900px) {
  body .topbar {
    display: none;
  }

  body .info-toggle {
    display: block;
  }

  body.info-open .topbar {
    display: grid;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 26;
  }

  body.info-open .info-backdrop {
    display: block;
  }
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 360px;
}

.score-table th,
.score-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.score-table th {
  background: var(--bg-elev);
  white-space: nowrap;
}

.score-table th.turn-cell {
  text-align: left;
  font-weight: 700;
  font-size: 13px;
  color: var(--muted);
}

.score-table td.target {
  font-weight: 700;
  color: #d8fff6;
}

.marks {
  display: flex;
  justify-content: center;
  gap: 3px;
}

.mark {
  width: 9px;
  height: 9px;
  border: 1px solid var(--border);
  border-radius: 50%;
}

.mark.filled {
  background: var(--accent);
  border-color: var(--accent);
}

.mark.closed {
  background: #7dd77d;
  border-color: #7dd77d;
}

.score-cell {
  font-weight: bold;
}

@media (max-width: 520px) {
  .scoreboard {
    overflow-x: hidden;
  }

  .score-table {
    min-width: 0;
    table-layout: fixed;
  }

  .score-table th,
  .score-table td {
    padding: 4px 3px;
    font-size: 11px;
  }

  .score-table th {
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .score-table th.turn-cell {
    font-size: 11px;
  }

  .marks {
    gap: 2px;
  }

  .mark {
    width: 7px;
    height: 7px;
  }

  .score-table tbody tr td:last-child {
    display: none;
  }
}

.active-col {
  background: rgba(45, 212, 191, 0.08);
}

.turns {
  display: grid;
  grid-template-columns: 1fr;
}

.turn {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--bg-elev);
  min-height: 40px;
}

.turn.compact {
  margin-top: -6px;
  margin-bottom: 0;
}

.turn .label {
  font-size: 12px;
  color: var(--muted);
}

.throws {
  margin-top: 4px;
  font-size: 18px;
  min-height: 20px;
}

.log {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  display: grid;
  gap: 4px;
}

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.multis {
  display: flex;
  gap: 8px;
}

.multi {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
}

.multi.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.throw-boxes {
  display: flex;
  gap: 8px;
}

.throw-box {
  min-width: 48px;
  padding: 10px;
  border: 1px solid var(--danger);
  border-radius: 8px;
  text-align: center;
  font-weight: 700;
  background: rgba(255, 107, 107, 0.12);
  color: var(--text);
}

.grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(50px, 1fr));
  gap: 8px;
}

.grid button {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.status {
  min-height: 20px;
  color: #f2c46d;
}

.mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

@media (max-width: 780px) {
  body {
    padding: 12px;
  }
  .grid {
    grid-template-columns: repeat(4, minmax(60px, 1fr));
  }
}
