/* ============================================================
   ScoreBlaze — Design System
   Palette: Volcanic Glass (#1A1A1A, #333, #FF6B2B, #FFB088)
   Fonts: Clash Display + Newsreader + Space Mono
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep:    #111111;
  --bg-card:    #1C1C1C;
  --bg-card2:   #242424;
  --bg-input:   #2A2A2A;
  --border:     #333333;
  --border-lit: #444444;
  --text-primary:   #F0EDE8;
  --text-secondary: #9A9590;
  --text-muted:     #5A5550;
  --orange:     #FF6B2B;
  --orange-lt:  #FFB088;
  --orange-dim: rgba(255,107,43,0.15);
  --orange-glow:rgba(255,107,43,0.35);
  --winner-color: #4ADE80;
  --winner-bg:    rgba(74,222,128,0.12);
  --loser-color:  #F87171;
  --loser-bg:     rgba(248,113,113,0.12);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --shadow-card: 0 4px 24px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 32px rgba(255,107,43,0.25);
  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Newsreader', Georgia, serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* --- Ambient Background --- */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,107,43,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,107,43,0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
}

.ember {
  position: fixed;
  bottom: -20px;
  left: var(--x);
  width: calc(4px * var(--s));
  height: calc(4px * var(--s));
  background: var(--orange);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--orange);
  animation: float-up var(--d) ease-in infinite;
  opacity: 0;
  pointer-events: none;
  z-index: 0;
}

@keyframes float-up {
  0%   { transform: translateY(0) scale(1); opacity: 0; }
  10%  { opacity: 0.8; }
  80%  { opacity: 0.4; }
  100% { transform: translateY(-100vh) scale(0.3); opacity: 0; }
}

/* --- Screen System --- */
.screen {
  display: none;
  position: relative;
  z-index: 1;
  min-height: 100vh;
}
.screen.active { display: block; }

/* ============================================================
   SETUP SCREEN
   ============================================================ */
#setup-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#setup-screen.active { display: flex; }

.setup-container {
  width: 100%;
  max-width: 480px;
  text-align: center;
  animation: fade-up 0.6s ease both;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.logo-mark {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 20px var(--orange));
  animation: pulse-glow 2.5s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 16px var(--orange)); }
  50%       { filter: drop-shadow(0 0 32px var(--orange)) drop-shadow(0 0 60px rgba(255,107,43,0.4)); }
}

.site-title {
  font-family: 'Clash Display', sans-serif;
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #FF6B2B 0%, #FFB088 50%, #FF6B2B 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmer 3s linear infinite;
  margin-bottom: 8px;
}

@keyframes shimmer {
  0%   { background-position: 0% center; }
  100% { background-position: 200% center; }
}

.site-subtitle {
  font-family: 'Newsreader', serif;
  font-style: italic;
  color: var(--text-secondary);
  font-size: 1.05rem;
  margin-bottom: 40px;
}

.player-inputs {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
}

.player-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.player-input-row:focus-within {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-dim);
}

.player-badge {
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--pc);
  background: color-mix(in srgb, var(--pc) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--pc) 30%, transparent);
  border-radius: 6px;
  padding: 3px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.name-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: 'Clash Display', sans-serif;
  font-size: 1rem;
  font-weight: 500;
}

.name-input::placeholder { color: var(--text-muted); }

/* --- Buttons --- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(135deg, #FF6B2B, #FF8C42);
  color: #fff;
  font-family: 'Clash Display', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px 32px;
  cursor: pointer;
  width: 100%;
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
  box-shadow: 0 4px 20px rgba(255,107,43,0.4);
  text-decoration: none;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(255,107,43,0.55);
  filter: brightness(1.08);
}

.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg-card2);
  color: var(--text-primary);
  font-family: 'Clash Display', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  border: 1px solid var(--border-lit);
  border-radius: var(--radius-md);
  padding: 14px 32px;
  cursor: pointer;
  text-decoration: none;
  transition: border-color var(--transition), background var(--transition);
}

.btn-secondary:hover {
  border-color: var(--orange);
  background: var(--orange-dim);
}

.history-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-family: 'Newsreader', serif;
  font-size: 0.9rem;
  text-decoration: none;
  margin-top: 20px;
  transition: color var(--transition);
}

.history-link:hover { color: var(--orange-lt); }

/* ============================================================
   GAME SCREEN
   ============================================================ */
#game-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: 40px;
}
#game-screen.active { display: flex; }

/* --- Game Header --- */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(17,17,17,0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-small {
  font-family: 'Clash Display', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--orange);
  letter-spacing: 0.02em;
}

.round-badge {
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  color: var(--text-secondary);
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
}

.limit-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
}

.limit-label { color: var(--text-muted); }
.limit-value { color: var(--orange-lt); font-weight: 700; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  transition: border-color var(--transition), color var(--transition);
}

.icon-btn:hover { border-color: var(--orange); color: var(--orange); }

/* --- Scoreboard --- */
.scoreboard {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 20px 16px 8px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.score-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  cursor: default;
}

.score-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--pc);
  opacity: 0.7;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.score-card:hover {
  border-color: var(--border-lit);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

.score-card.is-leading {
  border-color: var(--orange);
  box-shadow: 0 0 0 1px var(--orange), var(--shadow-glow);
}

.score-card.is-leading::after {
  content: 'LEADING';
  position: absolute;
  top: 12px; right: 12px;
  font-family: 'Space Mono', monospace;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--orange);
  background: var(--orange-dim);
  border: 1px solid var(--orange-glow);
  border-radius: 4px;
  padding: 2px 6px;
  letter-spacing: 0.08em;
}

.card-rank {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.06em;
}

.card-name {
  font-family: 'Clash Display', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-score-wrap {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 12px;
}

.card-score {
  font-family: 'Clash Display', sans-serif;
  font-size: clamp(2rem, 6vw, 2.8rem);
  font-weight: 700;
  color: var(--pc);
  line-height: 1;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

.card-score.bump {
  animation: score-bump 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes score-bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.card-score-unit {
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Progress bar */
.progress-track {
  height: 5px;
  background: var(--bg-input);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--pc), color-mix(in srgb, var(--pc) 60%, #fff));
  border-radius: 99px;
  transition: width 0.5s cubic-bezier(0.4,0,0.2,1);
  min-width: 4px;
}

/* --- Input Panel --- */
.input-panel {
  padding: 16px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.input-panel-inner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.panel-title {
  font-family: 'Clash Display', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  flex-wrap: wrap;
}

.select-wrapper {
  position: relative;
  flex: 1;
  min-width: 130px;
}

.select-wrapper select {
  width: 100%;
  height: 48px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'Clash Display', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0 36px 0 14px;
  appearance: none;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}

.select-wrapper select:focus { border-color: var(--orange); }

.select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.points-input-wrapper {
  position: relative;
  flex: 1;
  min-width: 100px;
}

.points-input-wrapper input {
  width: 100%;
  height: 48px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'Space Mono', monospace;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0 40px 0 16px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.points-input-wrapper input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-dim);
}

.points-input-wrapper input::-webkit-inner-spin-button,
.points-input-wrapper input::-webkit-outer-spin-button { -webkit-appearance: none; }

.pts-label {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  pointer-events: none;
}

.btn-add {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #FF6B2B, #FF8C42);
  color: #fff;
  font-family: 'Clash Display', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  padding: 0 22px;
  height: 48px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
  box-shadow: 0 4px 16px rgba(255,107,43,0.35);
}

.btn-add:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(255,107,43,0.5);
  filter: brightness(1.08);
}

.btn-add:active { transform: translateY(0); }

.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-undo {
  display: flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  color: var(--text-secondary);
  font-family: 'Clash Display', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.btn-undo:not(:disabled):hover {
  color: var(--orange-lt);
  border-color: var(--orange-lt);
  background: rgba(255,176,136,0.08);
}

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

.last-entry {
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
}

/* --- Round Log --- */
.round-log-section {
  padding: 8px 16px 0;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.log-title {
  font-family: 'Clash Display', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.round-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
  padding-right: 4px;
}

.round-log::-webkit-scrollbar { width: 4px; }
.round-log::-webkit-scrollbar-track { background: transparent; }
.round-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

.log-empty {
  font-family: 'Newsreader', serif;
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 16px 0;
}

.log-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  animation: slide-in 0.25s ease both;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

.log-entry.undone {
  opacity: 0.4;
  text-decoration: line-through;
  border-style: dashed;
}

.log-round-num {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  min-width: 28px;
}

.log-player-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pc);
  flex-shrink: 0;
}

.log-player-name {
  font-family: 'Clash Display', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
}

.log-points {
  font-family: 'Space Mono', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--orange-lt);
}

/* ============================================================
   GAME OVER SCREEN
   ============================================================ */
#gameover-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#gameover-screen.active { display: flex; }

.gameover-container {
  width: 100%;
  max-width: 520px;
  text-align: center;
  animation: fade-up 0.5s ease both;
}

.fireworks {
  font-size: 2.5rem;
  margin-bottom: 16px;
  display: flex;
  justify-content: center;
  gap: 16px;
}

.fireworks span {
  display: inline-block;
  animation: bounce-in 0.6s cubic-bezier(0.34,1.56,0.64,1) both;
}
.fireworks span:nth-child(1) { animation-delay: 0.0s; }
.fireworks span:nth-child(2) { animation-delay: 0.15s; }
.fireworks span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce-in {
  from { opacity: 0; transform: scale(0.3) rotate(-20deg); }
  to   { opacity: 1; transform: scale(1) rotate(0deg); }
}

.gameover-title {
  font-family: 'Clash Display', sans-serif;
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 700;
  background: linear-gradient(135deg, #FF6B2B, #FFB088);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}

.gameover-subtitle {
  font-family: 'Newsreader', serif;
  font-style: italic;
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 32px;
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 32px;
}

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  position: relative;
  overflow: hidden;
  animation: fade-up 0.5s ease both;
}

.result-card:nth-child(1) { animation-delay: 0.1s; }
.result-card:nth-child(2) { animation-delay: 0.2s; }
.result-card:nth-child(3) { animation-delay: 0.3s; }
.result-card:nth-child(4) { animation-delay: 0.4s; }

.result-card.winner {
  border-color: var(--winner-color);
  background: var(--winner-bg);
  box-shadow: 0 0 24px rgba(74,222,128,0.15);
}

.result-card.loser {
  border-color: var(--loser-color);
  background: var(--loser-bg);
  box-shadow: 0 0 24px rgba(248,113,113,0.1);
}

.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  border-radius: 4px;
  padding: 3px 8px;
  margin-bottom: 10px;
}

.result-card.winner .result-badge {
  color: var(--winner-color);
  background: rgba(74,222,128,0.15);
  border: 1px solid rgba(74,222,128,0.3);
}

.result-card.loser .result-badge {
  color: var(--loser-color);
  background: rgba(248,113,113,0.15);
  border: 1px solid rgba(248,113,113,0.3);
}

.result-name {
  font-family: 'Clash Display', sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-score {
  font-family: 'Space Mono', monospace;
  font-size: 1.5rem;
  font-weight: 700;
}

.result-card.winner .result-score { color: var(--winner-color); }
.result-card.loser  .result-score { color: var(--loser-color); }

.result-rank {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.gameover-actions {
  display: flex;
  gap: 12px;
  flex-direction: column;
}

/* ============================================================
   HISTORY PAGE
   ============================================================ */
.history-page {
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(17,17,17,0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 12px;
}

.header-center { flex: 1; text-align: center; }

.back-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-secondary);
  font-family: 'Clash Display', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: color var(--transition);
  white-space: nowrap;
}

.back-btn:hover { color: var(--orange-lt); }

.btn-reset {
  display: flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  color: var(--loser-color);
  font-family: 'Clash Display', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid rgba(248,113,113,0.3);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}

.btn-reset:hover {
  background: rgba(248,113,113,0.1);
  border-color: var(--loser-color);
}

.history-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 16px 60px;
}

.history-title-block {
  margin-bottom: 28px;
  animation: fade-up 0.5s ease both;
}

.history-page-title {
  font-family: 'Clash Display', sans-serif;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.history-page-sub {
  font-family: 'Newsreader', serif;
  font-style: italic;
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Stats bar */
.history-stats {
  display: flex;
  gap: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
  animation: fade-up 0.5s 0.1s ease both;
}

.stat-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  flex: 1;
  min-width: 100px;
  text-align: center;
}

.stat-value {
  font-family: 'Clash Display', sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--orange);
  display: block;
}

.stat-label {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: block;
  margin-top: 2px;
}

/* History list */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: fade-up 0.4s ease both;
  transition: border-color var(--transition);
}

.history-card:hover { border-color: var(--border-lit); }

.history-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card2);
}

.history-game-num {
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

.history-date {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.history-card-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.history-player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.history-player-row:nth-child(even) { border-right: none; }
.history-player-row:nth-last-child(-n+2) { border-bottom: none; }

.history-player-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.history-player-name {
  font-family: 'Clash Display', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-player-score {
  font-family: 'Space Mono', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  margin-right: 6px;
}

.history-result-badge {
  font-family: 'Space Mono', monospace;
  font-size: 0.6rem;
  font-weight: 700;
  border-radius: 4px;
  padding: 2px 6px;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.badge-winner {
  color: var(--winner-color);
  background: rgba(74,222,128,0.12);
  border: 1px solid rgba(74,222,128,0.25);
}

.badge-loser {
  color: var(--loser-color);
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.2);
}

/* Empty state */
.history-empty {
  text-align: center;
  padding: 80px 24px;
  animation: fade-up 0.5s ease both;
}

.empty-icon { font-size: 3rem; margin-bottom: 16px; }

.empty-title {
  font-family: 'Clash Display', sans-serif;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.empty-sub {
  font-family: 'Newsreader', serif;
  font-style: italic;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.history-empty .btn-primary { max-width: 220px; margin: 0 auto; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-lit);
  border-radius: var(--radius-xl);
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  transform: scale(0.92);
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1);
}

.modal-overlay.open .modal { transform: scale(1); }

.modal-icon { font-size: 2.5rem; margin-bottom: 14px; }

.modal-title {
  font-family: 'Clash Display', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.modal-body {
  font-family: 'Newsreader', serif;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 24px;
}

.modal-body strong { color: var(--text-primary); }

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

.btn-modal-cancel {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-secondary);
  font-family: 'Clash Display', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}

.btn-modal-cancel:hover { border-color: var(--border-lit); color: var(--text-primary); }

.btn-modal-confirm {
  flex: 1;
  background: rgba(248,113,113,0.15);
  color: var(--loser-color);
  font-family: 'Clash Display', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid rgba(248,113,113,0.35);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.btn-modal-confirm:hover {
  background: rgba(248,113,113,0.25);
  border-color: var(--loser-color);
}

/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-card2);
  border: 1px solid var(--border-lit);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  font-family: 'Clash Display', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  z-index: 200;
  white-space: nowrap;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.toast-success { border-color: rgba(74,222,128,0.4); color: var(--winner-color); }
.toast.toast-error   { border-color: rgba(248,113,113,0.4); color: var(--loser-color); }
.toast.toast-info    { border-color: var(--orange-glow); color: var(--orange-lt); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 600px) {
  .scoreboard {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px 10px 4px;
  }

  .score-card { padding: 14px 12px; }
  .card-name { font-size: 0.95rem; }

  .input-row { flex-direction: column; }
  .select-wrapper, .points-input-wrapper { min-width: unset; }
  .btn-add { width: 100%; justify-content: center; }

  .results-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .result-card { padding: 14px 12px; }

  .history-card-body { grid-template-columns: 1fr; }
  .history-player-row { border-right: none; }
  .history-player-row:nth-last-child(-n+2) { border-bottom: 1px solid var(--border); }
  .history-player-row:last-child { border-bottom: none; }

  .gameover-actions { flex-direction: column; }

  .history-header { flex-wrap: wrap; gap: 8px; }
  .header-center { order: -1; width: 100%; }
}

@media (max-width: 380px) {
  .scoreboard { grid-template-columns: 1fr; }
  .results-grid { grid-template-columns: 1fr; }
}

@media (min-width: 768px) {
  .scoreboard { grid-template-columns: repeat(4, 1fr); }
  .gameover-actions { flex-direction: row; }
}