:root {
  --bg: #10151e;
  --bg-elev: #18202c;
  --bg-panel: #1c2533;
  --border: rgba(212, 168, 79, 0.22);
  --border-strong: rgba(212, 168, 79, 0.5);
  --text: #f3ede2;
  --text-muted: #aab4c4;
  --gold: #dfb457;
  --gold-bright: #f7d683;
  --gold-dark: #9c7224;
  --emerald: #3dbb83;
  --crimson: #e05d53;
  --amber: #f0a846;
  --teal: #4ab3c2;
  --radius: 14px;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.42);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 20% 0%, #1d2738 0%, #10151e 65%);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.45;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
label {
  font: inherit;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 12px 16px 28px;
}

/* Topbar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  padding: 10px 14px;
  background: rgba(24, 32, 44, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

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

.brand-icon {
  border-radius: 8px;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.brand-title {
  font-weight: 700;
  font-size: 1.08rem;
  letter-spacing: 0.02em;
  color: var(--gold-bright);
}

.brand-badge {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

.mode-switch {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mode-btn {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.16s, color 0.16s, border-color 0.16s;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.mode-btn.active {
  background: linear-gradient(135deg, rgba(223, 180, 87, 0.22), rgba(156, 114, 36, 0.22));
  border-color: var(--gold);
  color: var(--gold-bright);
}

.mode-btn-ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.12);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-pill {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

.profile-pill:hover {
  border-color: var(--gold);
}

.pill-label {
  color: var(--gold);
  font-weight: 600;
}

.pill-stats {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Main Workspace */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 356px;
  gap: 16px;
  align-items: start;
}

.board-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

/* Match HUD */
.match-hud {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.player-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: border-color 0.2s, background 0.2s;
}

.player-badge.active-turn {
  background: rgba(223, 180, 87, 0.12);
  border-color: var(--gold);
}

.checker-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
}

.swatch-white {
  background: radial-gradient(circle at 32% 30%, #fffdf8, #dfd0b1);
  border: 2px solid #b58d43;
}

.swatch-black {
  background: radial-gradient(circle at 32% 30%, #374050, #12161e);
  border: 2px solid #c99d45;
}

.player-name {
  font-weight: 700;
  font-size: 0.92rem;
}

.player-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.turn-center {
  text-align: center;
  min-width: 0;
}

.turn-status {
  font-weight: 700;
  font-size: 0.96rem;
  color: var(--gold-bright);
}

.turn-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* SVG Board Stage */
.board-stage {
  background: #1a120c;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  padding: 6px;
  overflow: hidden;
}

#board-svg {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  touch-action: manipulation;
}

.svg-point-hit {
  cursor: pointer;
}

.svg-point-hit:focus-visible {
  outline: 2px solid var(--gold-bright);
}

@keyframes pulseRing {
  0% {
    opacity: 0.55;
    transform: scale(0.96);
  }
  50% {
    opacity: 1;
    transform: scale(1.03);
  }
  100% {
    opacity: 0.55;
    transform: scale(0.96);
  }
}

.hint-glow {
  animation: pulseRing 1.5s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}

/* Control Strip */
.control-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

button {
  cursor: pointer;
}

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

.btn-primary,
.btn-secondary,
.btn-mentor,
.btn-subtle {
  min-height: 44px;
  padding: 9px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.92rem;
  border: 1px solid transparent;
  transition: transform 0.08s ease, filter 0.15s ease, background 0.15s ease;
}

.btn-primary:active:not(:disabled),
.btn-secondary:active:not(:disabled),
.btn-mentor:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(135deg, #ecc56c, #c5912e);
  color: #161108;
  box-shadow: 0 4px 14px rgba(223, 180, 87, 0.25);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.07);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
}

.btn-mentor {
  background: rgba(61, 187, 131, 0.16);
  border-color: rgba(61, 187, 131, 0.5);
  color: #8bf0c2;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-mentor:hover:not(:disabled) {
  background: rgba(61, 187, 131, 0.25);
}

.hint-step-tag {
  font-size: 0.76rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(16, 21, 30, 0.6);
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
}

.btn-subtle {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--text-muted);
}

.btn-subtle:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-tiny {
  min-height: 36px;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.toggle-chip {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.toggle-chip input {
  width: 18px;
  height: 18px;
  accent-color: var(--emerald);
  cursor: pointer;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold-bright);
}

.panel-sub {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Mentor Panel */
.mentor-stage-pill {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(61, 187, 131, 0.16);
  border: 1px solid rgba(61, 187, 131, 0.45);
  color: #8bf0c2;
}

.mentor-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
}

.mentor-placeholder {
  margin: 0;
  color: var(--text-muted);
}

.mentor-card {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(16, 21, 30, 0.55);
  border-left: 3px solid var(--emerald);
}

.mentor-card.stage-2 {
  border-left-color: var(--teal);
}

.mentor-card.stage-3 {
  border-left-color: var(--gold-bright);
  background: rgba(223, 180, 87, 0.1);
}

.mentor-card-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold);
  margin-bottom: 3px;
}

.mentor-card p {
  margin: 0;
}

.mentor-legend {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.dot-make {
  background: var(--emerald);
}
.dot-hit {
  background: var(--crimson);
}
.dot-blot {
  background: var(--amber);
}
.dot-off {
  background: var(--gold-bright);
}

/* AI Difficulty */
.difficulty-grid {
  display: grid;
  gap: 7px;
}

.diff-card {
  width: 100%;
  min-height: 44px;
  text-align: left;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.diff-card:hover {
  border-color: var(--border-strong);
}

.diff-card.active {
  background: rgba(223, 180, 87, 0.14);
  border-color: var(--gold);
}

.diff-name {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--gold-bright);
}

.diff-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.fairness-note {
  margin: 10px 0 0;
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* Move Log */
.move-log {
  margin: 0;
  padding: 0 0 0 20px;
  max-height: 170px;
  overflow-y: auto;
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.move-log li {
  font-variant-numeric: tabular-nums;
}

.move-log strong {
  color: var(--text);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 16, 0.78);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 40;
}

.modal-card {
  width: min(460px, 100%);
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-eyebrow {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
}

.modal-title {
  margin: 4px 0 8px;
  font-size: 1.4rem;
  color: var(--gold-bright);
}

.modal-desc,
.modal-note {
  margin: 0 0 14px;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.modal-stats,
.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.stat-box {
  background: rgba(16, 21, 30, 0.65);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}

.stat-val {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
}

.stat-lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.roadmap-list {
  margin: 0 0 16px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.roadmap-list strong {
  color: var(--text);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

/* Tablet / iPad layout (641px - 1079px) */
@media (max-width: 1079px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .log-panel {
    grid-column: 1 / -1;
  }
}

/* Phone layout (<= 640px) */
@media (max-width: 640px) {
  .app-shell {
    padding: 8px 8px 20px;
  }

  .topbar {
    padding: 8px 10px;
    gap: 8px;
  }

  .brand-title {
    font-size: 0.98rem;
  }

  .mode-btn {
    padding: 8px 10px;
    font-size: 0.84rem;
  }

  .match-hud {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px 10px;
  }

  .turn-center {
    grid-column: 1 / -1;
    order: -1;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .player-badge {
    padding: 4px 6px;
  }

  .player-name {
    font-size: 0.82rem;
  }

  .player-meta {
    font-size: 0.72rem;
  }

  .board-stage {
    padding: 3px;
  }

  .control-strip {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  #btn-roll {
    grid-column: 1 / -1;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }
}
