:root {
  --bg: #0b0c10;
  --panel: #111319;
  --muted: #9aa4b2;
  --text: #e6eaf2;
  --accent: #67b0ff;
  --accent-2: #ff6b6b;
  --blue: #4da3ff;
  --red: #ff5a6b;
  --point-dark: #151820;
  --point-light: #1f2530;
  --board-gap: 12px;
  --vbar-width: 64px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: radial-gradient(1000px 800px at 70% -20%, #17202e 0%, var(--bg) 60%);
}

.app-header {
  position: relative;
  padding: 16px 20px;
  border-bottom: 1px solid #1e2230;
  background: linear-gradient(180deg, #0f1118 0%, #0b0c10 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.header-content {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--text);
  white-space: nowrap;
}

.back-link-row {
  padding: 8px 20px;
  border-bottom: 1px solid #1e2230;
  background: linear-gradient(180deg, #0f1118 0%, #0b0c10 100%);
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  display: inline-block;
  transition: color 0.2s ease;
}

.back-link:hover {
  color: var(--accent);
}

.debug-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.debug-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.quiz-id-input {
  flex: 1;
  min-width: 0;
  background: #0e1118;
  border: 1px solid #1c2230;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-family: ui-monospace, 'Courier New', monospace;
  max-width: 300px;
}

.quiz-id-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(103, 176, 255, 0.1);
}

.player-filter-container {
  display: flex;
  align-items: center;
}

.player-filter {
  appearance: none;
  background: #0e1118;
  border: 1px solid #1c2230;
  color: var(--text);
  padding: 6px 28px 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  min-width: 140px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239aa4b2' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.player-filter:hover {
  border-color: #2a3142;
}

.player-filter:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(103, 176, 255, 0.1);
}

.player-filter option {
  background: #0e1118;
  color: var(--text);
}

.board-orientation-toggle {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.board-orientation-button {
  pointer-events: auto;
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 999px;
  background: linear-gradient(180deg, #1c2434 0%, #141a28 100%);
  border: 1px solid #2a3142;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
}

.board-orientation-button:hover {
  border-color: var(--accent);
  color: var(--text);
}

.board-orientation-button:active {
  transform: translateY(1px);
}

.debug-toggle-container {
  display: flex;
  align-items: center;
}

.debug-toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.debug-toggle-wrapper {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
}

.debug-toggle {
  appearance: none;
  width: 40px;
  height: 20px;
  background: #1c2230;
  border: 1px solid #2a3142;
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  margin: 0;
  padding: 0;
}

.debug-toggle:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.debug-toggle-slider {
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--text);
  border-radius: 50%;
  top: 50%;
  left: 3px;
  transform: translateY(-50%);
  transition: transform 0.2s ease;
  pointer-events: none;
}

.debug-toggle:checked~.debug-toggle-slider {
  transform: translateY(-50%) translateX(20px);
}

.debug-toggle-text {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.debug-toggle:checked+.debug-toggle-text {
  color: var(--accent);
}

.to-move {
  margin-left: 8px;
  font-weight: 700;
}

.to-move.blue {
  color: var(--blue);
}

.to-move.red {
  color: var(--red);
}

.match-info {
  margin-left: 16px;
  font-size: 18px;
  color: var(--muted);
  font-weight: 500;
  display: inline-block;
  vertical-align: middle;
}

.match-info strong {
  color: var(--text);
  font-weight: 600;
}

.match-info .score-blue {
  color: var(--blue);
  font-weight: 700;
}

.match-info .score-red {
  color: var(--red);
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 20px;
  padding: 20px;
}

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.board-area,
.quiz-area {
  background: var(--panel);
  border: 1px solid #1c2230;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.board-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.point-numbers {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  height: 24px;
  background: rgba(15, 17, 24, 0.6);
  border-radius: 6px;
  border: 1px solid rgba(42, 49, 66, 0.5);
  overflow: hidden;
}

.point-numbers-row {
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(6, 1fr) var(--vbar-width) repeat(6, 1fr);
  gap: 0;
  padding: 0 8px;
  align-items: center;
}

.point-number {
  text-align: center;
  font-size: 10px;
  font-weight: 500;
  color: rgba(154, 164, 178, 0.5);
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.point-number-spacer {
  /* Space for the vertical bar */
}

.board {
  position: relative;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  aspect-ratio: 2.1 / 1;
  background: linear-gradient(180deg, #11141c 0%, #0e1017 100%);
  border-radius: 12px;
  border: 1px solid #2a3142;
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  overflow: hidden;
}

.bearoff {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px 8px;
  background: linear-gradient(180deg, #10131b 0%, #0d0f16 100%);
  border-right: 1px solid #262d3e;
}

.bearoff-right {
  border-left: 1px solid #262d3e;
  border-right: none;
}

.cube {
  width: 46px;
  height: 46px;
  background: #f8fafc;
  color: #0b0c10;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .6);
}

.cube.owner-player1 {
  outline: 2px solid var(--blue);
}

.cube.owner-player2 {
  outline: 2px solid var(--red);
}

.bearoff-p1,
.bearoff-p2 {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #0b0c10;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .6);
}

.bearoff-p1 {
  background: var(--blue);
}

.bearoff-p2 {
  background: var(--red);
}

.pipcount {
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  padding: 2px 0;
}

.pipcount-p1 {
  color: var(--blue);
}

.pipcount-p2 {
  color: var(--red);
}

.points {
  display: grid;
  grid-template-rows: 1fr 72px 1fr;
}

.points-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr) var(--vbar-width) repeat(6, 1fr);
  gap: 0;
  padding: 8px 8px;
}

.points-top {
  border-bottom: 1px dashed #2a3142;
}

.points-bottom {
  border-top: 1px dashed #2a3142;
}

.vbar {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #141a28 0%, #0f1420 100%);
  border-left: 1px solid #2a3142;
  border-right: 1px solid #2a3142;
}

.vbar .stack {
  height: 88%;
}

.center-strip {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr;
  align-items: center;
  padding: 0 8px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.dice {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 8px;
}

.die {
  width: 40px;
  height: 40px;
  background: #f8fafc;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #0b0c10;
  font-weight: 800;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .6);
}

.point {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.point::before {
  content: "";
  position: absolute;
  width: 80%;
  height: 100%;
  max-width: 64px;
  background: linear-gradient(180deg, var(--point-dark) 0%, var(--point-light) 100%);
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  opacity: 0.9;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.35));
}

.points-bottom .point::before {
  clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
}

.point.striped::before {
  background: linear-gradient(180deg, #242d41 0%, #3c4d6c 100%);
}

.stack {
  position: relative;
  width: 64px;
  height: 88%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  z-index: 2;
}

.points-bottom .stack {
  justify-content: flex-start;
}

.checker {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #0b0c10;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .6);
}

.checker.p1 {
  background: var(--blue);
}

.checker.p2 {
  background: var(--red);
}

.checker.count {
  color: #0b0c10;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #f0f4fa 0%, #e8edf6 100%);
}

.quiz-area .meta {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}

.options {
  display: grid;
  gap: 10px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #0e1118;
  border: 1px solid #1c2230;
  padding: 10px 12px;
  border-radius: 10px;
}

.option.disabled {
  opacity: 0.7;
}

.option label {
  cursor: pointer;
  color: var(--text);
}

.option input[type="radio"] {
  margin-top: 2px;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

button {
  appearance: none;
  border: 1px solid #2a3142;
  background: linear-gradient(180deg, #1a2233 0%, #121826 100%);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

button.secondary {
  background: linear-gradient(180deg, #202636 0%, #151b28 100%);
}

.feedback {
  margin-top: 12px;
  background: #0e1118;
  border: 1px solid #1c2230;
  border-radius: 10px;
  padding: 12px;
  display: none;
}

.feedback.visible {
  display: block;
}

.feedback .result {
  font-weight: 700;
  margin-bottom: 8px;
}

.feedback .moves {
  display: grid;
  gap: 6px;
}

.feedback .move {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: #0b0f16;
  border: 1px solid #1a2030;
  border-radius: 8px;
}

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #2a3142;
  color: var(--muted);
}

.badge.good {
  color: #7cd67c;
  border-color: #2b5340;
  background: #112016;
}

.badge.bad {
  color: #ff8c8c;
  border-color: #5a2a2a;
  background: #1b0f10;
}

.dg-link-container {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #1c2230;
}

.dg-link-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #1a2233 0%, #121826 100%);
  border: 1px solid #2a3142;
  border-radius: 10px;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
  transition: all 0.2s ease;
  cursor: pointer;
}

.dg-link-button:hover {
  opacity: 0.9;
}

.dg-link-button::before {
  content: "↗";
  font-size: 14px;
}