/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1f2937;
  --text-primary: #f0f0f0;
  --text-secondary: #a0a0b0;
  --accent: #c9a84c;
  --accent-alt: #4a9e8e;
  --danger: #e55039;
  --success: #27ae60;
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.2s ease;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
select { font: inherit; }
input[type="number"] { font: inherit; }

/* === HOME SCREEN === */
.home-header {
  text-align: center;
  padding: 2rem 1rem 1rem;
}
.home-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.home-tagline {
  color: var(--text-secondary);
  margin-top: 0.25rem;
  font-size: 0.9rem;
}

.game-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  padding: 1rem;
  max-width: 600px;
  margin: 0 auto;
}
@media (min-width: 480px) {
  .game-grid { grid-template-columns: 1fr 1fr; }
}

.game-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1rem;
  min-height: 80px;
  text-align: left;
  transition: transform var(--transition), box-shadow var(--transition);
  touch-action: manipulation;
}
.game-card:active {
  transform: scale(0.97);
}
.game-card-swatch {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--swatch-color, #888);
  flex-shrink: 0;
}
.game-card-info h2 {
  font-size: 1.1rem;
  font-weight: 600;
}
.game-card-info p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

/* === GAME VIEW === */
.game-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 100;
}
.game-header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#game-content {
  padding: 1rem;
  max-width: 600px;
  margin: 0 auto;
  padding-bottom: 3rem;
}

/* === BUTTONS === */
.btn-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  border-radius: var(--radius-sm);
  touch-action: manipulation;
}
.btn-icon:active { opacity: 0.7; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--bg-primary);
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.75rem 2rem;
  border-radius: var(--radius);
  min-height: 60px;
  width: 100%;
  touch-action: manipulation;
  transition: transform var(--transition), opacity var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.btn-primary:active { transform: scale(0.96); opacity: 0.9; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 600;
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius-sm);
  min-height: 44px;
  touch-action: manipulation;
  transition: transform var(--transition);
}
.btn-secondary:active { transform: scale(0.96); }

.btn-sm {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 1.3rem;
  font-weight: 700;
  touch-action: manipulation;
}
.btn-sm:active { opacity: 0.7; }

/* === MAP / SCENARIO SELECTOR === */
.map-select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  min-height: 36px;
}

/* === DICE === */
.dice-section { margin-bottom: 1.25rem; }

.dice-tray {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  min-height: 70px;
  align-items: center;
}

.die {
  width: 64px;
  height: 64px;
  background: #fff;
  border-radius: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 8px;
  position: relative;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.die[data-highlight="high"] { box-shadow: 0 0 0 3px var(--accent), 0 2px 8px rgba(0,0,0,0.3); }
.die[data-highlight="low"]  { opacity: 0.6; }

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

/* Pip positions for each die face */
.die[data-value="1"] .pip-5 { display: block; }

.die[data-value="2"] .pip-1 { display: block; }
.die[data-value="2"] .pip-9 { display: block; }

.die[data-value="3"] .pip-1 { display: block; }
.die[data-value="3"] .pip-5 { display: block; }
.die[data-value="3"] .pip-9 { display: block; }

.die[data-value="4"] .pip-1 { display: block; }
.die[data-value="4"] .pip-3 { display: block; }
.die[data-value="4"] .pip-7 { display: block; }
.die[data-value="4"] .pip-9 { display: block; }

.die[data-value="5"] .pip-1 { display: block; }
.die[data-value="5"] .pip-3 { display: block; }
.die[data-value="5"] .pip-5 { display: block; }
.die[data-value="5"] .pip-7 { display: block; }
.die[data-value="5"] .pip-9 { display: block; }

.die[data-value="6"] .pip-1 { display: block; }
.die[data-value="6"] .pip-2 { display: block; }
.die[data-value="6"] .pip-3 { display: block; }
.die[data-value="6"] .pip-7 { display: block; }
.die[data-value="6"] .pip-8 { display: block; }
.die[data-value="6"] .pip-9 { display: block; }

.die-number {
  position: absolute;
  bottom: 2px;
  right: 5px;
  font-size: 0.65rem;
  font-weight: 700;
  color: #666;
  pointer-events: none;
}

/* Roll animation */
.die.rolling {
  animation: die-roll 0.5s ease-out;
}
@keyframes die-roll {
  0%   { transform: rotate(0deg) scale(0.8); opacity: 0.5; }
  25%  { transform: rotate(15deg) scale(1.1) translateY(-8px); }
  50%  { transform: rotate(-10deg) scale(1.05) translateX(4px); }
  75%  { transform: rotate(5deg) scale(1.02); }
  100% { transform: rotate(0deg) scale(1); opacity: 1; }
}

/* Roll history */
.roll-history {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.roll-history-entry {
  display: flex;
  gap: 3px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  opacity: 0.6;
  font-size: 0.75rem;
}
.roll-history-entry:first-child { opacity: 1; }
.roll-history-die {
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #222;
}

/* === SECTIONS === */
.section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.section-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

/* === COUNTERS === */
.counter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.counter-value {
  font-size: 1.5rem;
  font-weight: 700;
  min-width: 2ch;
  text-align: center;
}
.counter-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* === SCORE TABLE === */
.score-table {
  width: 100%;
  border-collapse: collapse;
}
.score-table th,
.score-table td {
  padding: 0.5rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 0.9rem;
}
.score-table th {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.8rem;
}
.score-table .score-input {
  width: 60px;
  background: var(--bg-primary);
  border: 1px solid var(--text-secondary);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0.35rem 0.5rem;
  text-align: center;
  font-size: 1rem;
}
.score-table .score-total td {
  font-weight: 700;
  font-size: 1.1rem;
  border-top: 2px solid var(--accent);
  border-bottom: none;
  color: var(--accent);
}

/* === COLLAPSIBLE PANEL === */
.panel-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  font-weight: 600;
  font-size: 0.9rem;
  touch-action: manipulation;
}
.panel-toggle::after {
  content: '\25BC';
  font-size: 0.7rem;
  transition: transform var(--transition);
}
.panel-toggle[aria-expanded="true"]::after {
  transform: rotate(180deg);
}
.panel-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.panel-content.open {
  max-height: 2000px;
}

/* === BADGES / TAGS === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-accent { background: var(--accent); color: var(--bg-primary); }
.badge-danger { background: var(--danger); color: #fff; }
.badge-success { background: var(--success); color: #fff; }

/* === TOGGLE BUTTONS === */
.toggle-group {
  display: flex;
  gap: 2px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.toggle-btn {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  min-height: 44px;
  touch-action: manipulation;
  transition: background var(--transition), color var(--transition);
}
.toggle-btn.active {
  background: var(--accent);
  color: var(--bg-primary);
}

/* === TRACKER ROW === */
.tracker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
}
.tracker-row + .tracker-row {
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* === INDICATOR === */
.indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
}
.indicator-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
}

/* === STAR TRACKER === */
.star-tracker {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.star-slot {
  width: 32px;
  height: 32px;
  border: 2px solid var(--text-secondary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--transition);
  touch-action: manipulation;
}
.star-slot.earned {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-primary);
}

/* === UTILITY === */
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.text-sm { font-size: 0.8rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.hidden { display: none !important; }
