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

:root {
  --bg: #1a1a2e;
  --panel-bg: #16213e;
  --card-bg: #0f3460;
  --accent: #8ace00;
  --accent-hover: #a3e635;
  --text: #eee;
  --text-muted: #999;
  --held-bg: #2a5a3a;
  --held-border: #4caf50;
  --score-available: #8ace00;
  --score-hover: rgba(138, 206, 0, 0.2);
  --border: #2a2a4a;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Overlay (loading / game over) */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.hidden, .overlay.hidden { display: none; }

.overlay-content {
  text-align: center;
  padding: 2rem;
}

.overlay-content h1 {
  font-family: 'Anton', sans-serif;
  text-transform: uppercase;
  font-weight: 400;
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 1rem auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Buttons */
.btn {
  padding: 0.75rem 2rem;
  border: none;
  border-radius: 2px;
  font-family: 'Arial Narrow', 'Helvetica Neue', Arial, sans-serif;
  text-transform: lowercase;
  font-size: 1.1rem;
  cursor: pointer;
  font-weight: 400;
  transition: background 0.2s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #1a1a2e;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Game Title */
.game-title {
  font-family: 'Arial Narrow', 'Helvetica Neue', Arial, sans-serif;
  text-transform: lowercase;
  font-weight: 400;
  font-size: 2.4rem;
  color: var(--text);
  text-align: left;
  max-width: 1200px;
  margin: 1rem auto 0;
  padding: 0 1rem;
}

.game-title.hidden { display: none; }

/* Game Grid */
.game-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  min-height: 100vh;
  align-items: start;
}

.game-grid.hidden { display: none; }

.panel {
  background: var(--panel-bg);
  border-radius: 12px;
  padding: 1.25rem;
}

.panel h2 {
  text-align: center;
  margin-bottom: 1rem;
  font-family: 'Anton', sans-serif;
  text-transform: uppercase;
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--accent);
}

/* Scorecard */
#scorecard {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

#scorecard th, #scorecard td {
  padding: 0.4rem 0.5rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

#scorecard th {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

#scorecard th:first-child,
#scorecard td:first-child {
  text-align: left;
}

.score-cell {
  min-width: 40px;
}

.score-cell.available {
  cursor: pointer;
  color: var(--score-available);
  font-weight: 600;
}

.score-cell.available:hover {
  background: var(--score-hover);
  border-radius: 4px;
}

.score-cell.scored {
  color: #999;
}

.score-cell.preview {
  color: var(--score-available);
  opacity: 0.6;
}

.subtotal-row td {
  font-size: 0.85rem;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}

.total-row td {
  font-size: 1rem;
  padding-top: 0.6rem;
  border-bottom: none;
}

tr[data-cat="5"] td {
  border-bottom: 2px solid var(--border);
}

tr.npc-just-scored td {
  animation: npcScore 0.6s ease;
}

@keyframes npcScore {
  0%, 100% { background: transparent; }
  50% { background: rgba(233, 69, 96, 0.3); }
}

tr.best-pick-blink td {
  animation: bestPickBlink 1.2s ease-in-out infinite;
}

@keyframes bestPickBlink {
  0%, 100% { background: transparent; }
  50% { background: rgba(138, 206, 0, 0.2); }
}

/* Dice Tray */
.dice-panel {
  text-align: center;
}

.dice-panel h2 {
  font-family: 'Arial Narrow', 'Helvetica Neue', Arial, sans-serif;
  text-transform: lowercase;
  font-size: 1.4rem;
  font-weight: 400;
}

#round-label {
  color: var(--text-muted);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.dice-tray {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.dice-row {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.die {
  width: 64px;
  height: 64px;
  background: white;
  border-radius: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 8px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 3px solid transparent;
  position: relative;
}

.die.empty {
  background: var(--card-bg);
  cursor: default;
}

.die.held {
  border-color: var(--held-border);
  box-shadow: 0 0 12px rgba(76, 175, 80, 0.4);
  transform: translateY(-4px);
}

.die.held::after {
  content: 'HOLD';
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--held-border);
  letter-spacing: 1px;
}

.die.rolling {
  animation: dieRoll 0.4s ease;
}

@keyframes dieRoll {
  0% { transform: rotateX(0deg); }
  25% { transform: rotateX(90deg) scale(0.9); }
  50% { transform: rotateX(180deg) scale(0.85); }
  75% { transform: rotateX(270deg) scale(0.9); }
  100% { transform: rotateX(360deg); }
}

.die.npc-held {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(233, 69, 96, 0.4);
  transform: translateY(-4px);
}

.pip {
  width: 10px;
  height: 10px;
  background: #333;
  border-radius: 50%;
  align-self: center;
  justify-self: center;
}

.rolls-label {
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.charli-avatar {
  margin-top: 1rem;
}

.charli-avatar.hidden {
  display: none;
}

.charli-img {
  width: 120px;
  border-radius: 4px;
}

.npc-status {
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--card-bg);
  border-radius: 8px;
  color: var(--accent);
  font-style: italic;
}

.npc-status.hidden { display: none; }

/* Moves Section */
.moves-section {
  margin-bottom: 1rem;
}

.moves-section.hidden { display: none; }

.moves-section h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

#moves-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

#moves-table th, #moves-table td {
  padding: 0.35rem 0.5rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

#moves-table th {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
}

#moves-table th:first-child,
#moves-table td:first-child {
  text-align: left;
}

#moves-table tr.best-move td {
  color: var(--held-border);
  font-weight: 600;
}

.keep-dice {
  display: inline-flex;
  gap: 3px;
}

.mini-die {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 3px;
  padding: 2px;
}

.mini-pip {
  width: 4px;
  height: 4px;
  background: #333;
  border-radius: 50%;
  align-self: center;
  justify-self: center;
}

.keep-reroll-all {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.8rem;
}

.dist-bar {
  display: flex;
  height: 20px;
  border-radius: 4px;
  overflow: hidden;
  min-width: 70px;
  background: var(--border);
}

.dist-seg {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 600;
  color: white;
  overflow: hidden;
  white-space: nowrap;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

.dist-seg.neg, .swatch.neg { background: #e94560; }
.dist-seg.low, .swatch.low { background: #b8860b; }
.dist-seg.mid, .swatch.mid { background: #2196f3; }
.dist-seg.high, .swatch.high { background: #4caf50; }

.dist-legend {
  display: flex;
  gap: 0.75rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
  justify-content: flex-end;
}

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

.swatch {
  display: block;
  width: 10px;
  height: 10px;
  min-width: 10px;
  border-radius: 2px;
}

/* Probability Panel */
#prob-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

#prob-table th, #prob-table td {
  padding: 0.4rem 0.4rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

#prob-table th {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
}

#prob-table th:first-child,
#prob-table td:first-child {
  text-align: left;
}

#prob-table tr.section-header td {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  padding-top: 0.75rem;
}

#prob-table tr.section-header td:first-child {
  text-align: left;
}

#prob-table tr.unavailable td {
  color: var(--text-muted);
  opacity: 0.4;
  text-decoration: line-through;
}

#prob-table tr.best-ev td {
  color: var(--held-border);
  font-weight: 600;
}

.prob-panel.hidden-panel {
  opacity: 0.3;
}

/* Final Scores */
#final-scores {
  margin: 1.5rem 0;
}

#final-scores table {
  margin: 0 auto;
  border-collapse: collapse;
  font-size: 1rem;
}

#final-scores th, #final-scores td {
  padding: 0.5rem 1.5rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

#final-scores th {
  color: var(--text-muted);
}

/* Toast reactions */
.toast {
  text-align: center;
  font-family: 'Arial Narrow', 'Helvetica Neue', Arial, sans-serif;
  text-transform: lowercase;
  font-size: 1.8rem;
  font-weight: 400;
  padding: 3.5rem 1.5rem;
  border-radius: 2px;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  opacity: 0;
  transform: scale(0.8);
  margin-top: 1rem;
}

.toast.hidden {
  display: none;
}

.toast.show {
  opacity: 1;
  transform: scale(1);
}

.toast-positive {
  background: var(--accent);
  color: #1a1a2e;
}

.toast-negative {
  background: #e94560;
  color: white;
}

/* Responsive: stack on mobile */
@media (max-width: 900px) {
  .game-grid {
    grid-template-columns: 1fr;
    max-width: 500px;
  }

  .die {
    width: 56px;
    height: 56px;
  }
}
