/* ===== Design Tokens: Warm Board Game Cafe ===== */
:root {
  --bg-deep: #0c1a14;
  --bg-surface: #132820;
  --bg-card: #1a3a2c;
  --bg-elevated: #224a38;

  --felt: #1a5c3a;
  --felt-light: #247a4e;
  --felt-glow: rgba(36, 122, 78, 0.35);

  --amber: #e8a840;
  --amber-glow: rgba(232, 168, 64, 0.3);
  --amber-deep: #c4872a;
  --gold: #f0c860;

  --cream: #faf3e3;
  --cream-muted: #e8dcc8;
  --ivory: #fff8ec;

  --wood: #5c3a1e;
  --wood-light: #8b5e34;
  --wood-dark: #3a2210;

  --red: #d94040;
  --red-deep: #a82828;
  --green-accent: #3cb868;

  --text-primary: #faf3e3;
  --text-secondary: #b8a88c;
  --text-muted: #7a6e5a;
  --text-dark: #2a1e10;

  --suit-red: #d94040;
  --suit-black: #1a1a1a;
  --color-red-suit: #d94040;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-card: 8px;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px var(--amber-glow);
  --shadow-felt: 0 0 30px var(--felt-glow);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(36, 122, 78, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(232, 168, 64, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--wood); border-radius: var(--r-sm); }
::-webkit-scrollbar-thumb:hover { background: var(--wood-light); }

/* ===== Start Screen ===== */
#start-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--sp-5);
}

.start-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-7) var(--sp-6);
  background: rgba(19, 40, 32, 0.85);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(232, 168, 64, 0.15);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg), 0 0 60px rgba(36, 122, 78, 0.1);
  max-width: 420px;
  width: 100%;
  animation: fadeUp 0.6s var(--ease-out);
}

#start-screen h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: -1px;
  line-height: 1;
}

.tagline {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-top: calc(var(--sp-2) * -1);
  font-style: italic;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 300;
}

#username {
  padding: var(--sp-3) var(--sp-4);
  font-size: 1.05rem;
  border: 1.5px solid rgba(232, 168, 64, 0.2);
  border-radius: var(--r-md);
  background: rgba(12, 26, 20, 0.6);
  color: var(--cream);
  width: 100%;
  max-width: 280px;
  text-align: center;
  transition: all 0.3s var(--ease-out);
}

#username:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-glow);
}

#username::placeholder { color: var(--text-muted); }

#difficulty-selector { display: flex; gap: var(--sp-2); }

.difficulty-btn {
  padding: var(--sp-2) var(--sp-4);
  border: 1.5px solid rgba(232, 168, 64, 0.2);
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.25s var(--ease-out);
}

.difficulty-btn:hover {
  border-color: var(--amber);
  color: var(--cream);
  transform: translateY(-1px);
}

.difficulty-btn.selected {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--bg-deep);
  font-weight: 600;
  box-shadow: var(--shadow-glow);
}

#start-btn {
  padding: var(--sp-3) var(--sp-6);
  font-size: 1.1rem;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  letter-spacing: 0.5px;
  border: 1.5px solid var(--amber);
  border-radius: var(--r-md);
  background: transparent;
  color: var(--amber);
  cursor: pointer;
  transition: all 0.3s var(--ease-out);
  margin-top: var(--sp-2);
}

#start-btn:hover {
  background: var(--amber);
  color: var(--bg-deep);
  box-shadow: var(--shadow-glow);
  transform: translateY(-2px);
}

#start-btn:active { transform: translateY(0); }

#difficulty-desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
  min-height: 1.2em;
}

#stats-display { width: 100%; max-width: 320px; }

.stats-panel {
  background: rgba(12, 26, 20, 0.5);
  border: 1px solid rgba(232, 168, 64, 0.12);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
}

.stats-panel h3 {
  font-family: 'Fraunces', Georgia, serif;
  color: var(--amber);
  margin-bottom: var(--sp-3);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid rgba(232, 168, 64, 0.12);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: var(--sp-2) 0;
  font-size: 0.9rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.stat-row:last-child { border-bottom: none; }
.stat-row span:first-child { color: var(--text-secondary); }
.stat-row span:last-child { color: var(--amber); font-weight: 600; }

/* ===== Game Screen ===== */
#game-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-2) var(--sp-5);
  background: rgba(19, 40, 32, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(232, 168, 64, 0.1);
  flex-shrink: 0;
  z-index: 10;
}

#username-display {
  font-family: 'Fraunces', Georgia, serif;
  color: var(--cream);
  font-weight: 600;
  font-size: 0.95rem;
}

#phase-indicator {
  padding: var(--sp-1) var(--sp-3);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--amber);
  background: rgba(232, 168, 64, 0.1);
  border: 1px solid rgba(232, 168, 64, 0.2);
}

#turn-indicator {
  color: var(--amber);
  font-family: 'Fraunces', Georgia, serif;
  font-size: 0.9rem;
  font-weight: 500;
  animation: pulse 2.5s ease-in-out infinite;
}

/* ===== Main Layout ===== */
main {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: var(--sp-4);
  padding: var(--sp-4);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ===== Play Area ===== */
#play-area {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-height: 0;
}

/* Shared Table Centerpiece */
#center-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #2d1a0b; /* Wooden base */
  border: 12px solid #1a1007;
  border-radius: var(--r-xl);
  padding: var(--sp-2);
  box-shadow: 
    0 20px 50px rgba(0,0,0,0.7),
    inset 0 0 60px rgba(0,0,0,0.5);
  position: relative;
  min-height: 500px;
  gap: var(--sp-2);
}

/* Green Felt Inset */
#table-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  background: radial-gradient(circle at center, var(--felt-light) 0%, var(--felt) 100%);
  border: 4px solid #1a1007;
  border-radius: var(--r-lg);
  box-shadow: inset 0 4px 20px rgba(0,0,0,0.6);
  min-height: 240px;
}

/* Integrated Board Area */
#board-area {
  background: rgba(0,0,0,0.15);
  border-radius: var(--r-lg);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
}

#board-svg {
  width: 100%;
  height: 220px;
}

#starter-card {
  width: 70px;
  height: 98px;
  box-shadow: var(--shadow-md);
  border-radius: var(--r-card);
  flex-shrink: 0;
}

#pegging-count {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 800;
  font-size: 1.8rem;
  color: var(--amber);
  background: rgba(12, 26, 20, 0.85);
  padding: var(--sp-1) var(--sp-4);
  border-radius: var(--r-md);
  border: 1.5px solid rgba(232, 168, 64, 0.25);
  position: relative;
  min-width: 60px;
  text-align: center;
}

#pegging-count::before {
  content: 'COUNT';
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.5rem;
  letter-spacing: 1.5px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  background: var(--amber);
  color: var(--bg-deep);
  padding: 1px 7px;
  border-radius: 999px;
}

#played-cards-container {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
}

.played-pile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  flex: 1;
}

.pile-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  color: rgba(255,255,255,0.6);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.pile-cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 62px;
  align-items: center;
  width: 100%;
}


/* ===== Hands & Actions ===== */
.hand {
  display: flex;
  gap: var(--sp-2);
  justify-content: center;
  flex-wrap: wrap;
  padding: var(--sp-2) var(--sp-2) calc(var(--sp-2) + 28px);
  min-height: 148px;
  align-items: center;
  width: 100%;
  flex-shrink: 0;
}

#ai-hand {
  transform: scale(0.85);
  opacity: 0.8;
  min-height: 120px;
}

#action-buttons {
  display: flex;
  gap: var(--sp-3);
  justify-content: center;
  width: 100%;
  flex-shrink: 0;
  padding: var(--sp-2) 0;
}

#go-btn,
#continue-btn {
  padding: var(--sp-2) var(--sp-5);
  border-radius: var(--r-md);
  cursor: pointer;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.5px;
  transition: all 0.25s var(--ease-out);
  border: 1.5px solid;
}

#go-btn { color: var(--green-accent); border-color: var(--green-accent); background: transparent; }
#continue-btn { color: var(--amber); border-color: var(--amber); background: transparent; }

#go-btn:hover {
  background: var(--green-accent);
  color: var(--bg-deep);
  box-shadow: 0 0 16px rgba(60, 184, 104, 0.3);
  transform: translateY(-2px);
}

#continue-btn:hover {
  background: var(--amber);
  color: var(--bg-deep);
  box-shadow: var(--shadow-glow);
  transform: translateY(-2px);
}


/* ===== Sidebar ===== */
#sidebar-area {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-height: 0;
  overflow: hidden;
}

#game-log { flex: 1; }

#game-log, #cheat-sheet {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: rgba(250, 243, 227, 0.95);
  border: 1px solid rgba(232, 168, 64, 0.15);
  border-radius: var(--r-lg);
  padding: var(--sp-3);
  box-shadow: var(--shadow-sm);
}

#cheat-sheet { flex-shrink: 0; }

#game-log h3, #cheat-sheet h3 {
  flex-shrink: 0;
  font-family: 'Fraunces', Georgia, serif;
  color: var(--text-dark);
  margin-bottom: var(--sp-2);
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  border-bottom: 1px solid rgba(42, 30, 16, 0.12);
  padding-bottom: var(--sp-2);
}

.cheat-entries {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.72rem;
  color: var(--text-dark);
}

.cheat-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dotted rgba(42, 30, 16, 0.1);
  padding: 3px 0;
}

.cheat-row:last-child { border-bottom: none; }
.cheat-row span:first-child { font-weight: 500; }
.cheat-row span:last-child { color: var(--red-deep); font-weight: 700; }

#log-entries {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  font-size: 0.8rem;
  color: var(--text-dark);
}

.crib-area {
  padding: var(--sp-2);
  background: rgba(0,0,0,0.1);
  border-radius: var(--r-md);
}
.crib-area .crib-label { font-size: 0.7rem; font-weight: 600; color: var(--text-muted); }
.crib-area .crib-cards { min-height: 40px; display: flex; gap: var(--sp-1); }


/* ===== Cards & Overlays (mostly unchanged) ===== */
.card {
  width: 80px;
  height: 112px;
  background: linear-gradient(160deg, #ffffff 0%, var(--ivory) 100%);
  border-radius: var(--r-card);
  box-shadow:
    0 2px 6px rgba(0,0,0,0.25),
    0 1px 2px rgba(0,0,0,0.15),
    inset 0 1px 0 rgba(255,255,255,0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: all 0.3s var(--ease-spring);
  border: 1.5px solid rgba(42, 30, 16, 0.12);
  user-select: none;
  font-family: 'Fraunces', Georgia, serif;
  flex-shrink: 0;
}
.card:hover:not(.disabled):not(.face-down) {
  box-shadow: 0 12px 24px rgba(0,0,0,0.3), 0 0 12px var(--amber-glow);
  transform: translateY(-14px) scale(1.05);
  z-index: 10;
  border-color: var(--amber);
}
.card .rank { 
  font-size: 2.2rem; 
  font-weight: 800; 
  color: var(--text-dark); 
  line-height: 1;
  margin-top: -5px;
}
.card .suit { 
  font-size: 1.8rem; 
  margin-top: -2px; 
  line-height: 1;
}
.card.red { color: var(--suit-red); }
.card.black { color: var(--suit-black); }
.card.face-down {
  background: var(--bg-card);
  border: 2px solid var(--wood);
}
.card.face-down::after {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(232, 168, 64, 0.2);
  border-radius: calc(var(--r-card) - 3px);
  background: radial-gradient(circle at center, rgba(232, 168, 64, 0.06) 0%, transparent 70%);
}
.card.selected {
  border-color: var(--amber);
  box-shadow: var(--shadow-glow), 0 8px 16px rgba(0,0,0,0.3);
  transform: translateY(-10px) scale(1.03);
}
.card.card-playable { border-color: var(--green-accent); }
.card.card-blocked, .card.disabled {
  cursor: not-allowed;
  border-color: var(--red);
  opacity: 0.5;
}
.mini-card {
  width: 38px;
  height: 54px;
}

.key-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--amber);
  color: var(--bg-deep);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  border: 1.5px solid var(--bg-surface);
  z-index: 20;
  pointer-events: none;
  font-family: 'DM Sans', sans-serif;
}

.card:hover .key-badge {
  transform: scale(1.1);
  background: var(--gold);
}

/* ===== Overlays ===== */
#scoring-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 26, 20, 0.75); /* Darken without blurring */
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeUp 0.3s forwards;
}

#scoring-modal {
  background: var(--bg-surface);
  border: 1.5px solid rgba(232, 168, 64, 0.2);
  border-radius: var(--r-xl);
  padding: var(--sp-5) var(--sp-6);
  max-width: 90vw;
  width: 440px;
  text-align: center;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.score-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
}

.score-option-btn {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 2rem;
  padding: var(--sp-3) var(--sp-5);
  margin: var(--sp-1);
  border: 1.5px solid rgba(60, 184, 104, 0.4);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-card) 100%);
  color: var(--cream);
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  min-width: 120px;
  box-shadow: 0 4px 0 0 #10251c, var(--shadow-sm);
}

.score-option-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #30644d 0%, #224a38 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 0 #10251c, var(--shadow-md);
}

.score-option-btn:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 2px 0 0 #10251c, inset 0 1px 2px rgba(0,0,0,0.4);
}

.score-option-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.6);
  transform: none;
  box-shadow: 0 4px 0 0 #10251c, var(--shadow-sm);
}

#score-explainer {
  position: fixed;
  z-index: 1200;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: clamp(320px, 90vw, 500px);
  max-height: 80vh;
  overflow-y: auto;
  background: rgba(19, 40, 32, 0.95);
  backdrop-filter: blur(20px);
  padding: var(--sp-5);
  border-radius: var(--r-xl);
  border: 1px solid rgba(232, 168, 64, 0.2);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  animation: fadeUp 0.3s var(--ease-out);
}
.score-breakdown-row { background: rgba(255,255,255,0.04); border: 1px solid rgba(232, 168, 64, 0.1); border-radius: var(--r-sm); padding: var(--sp-2); }
.score-breakdown-header { color: var(--amber); font-weight: 700; }
.score-breakdown-details { color: var(--text-secondary); font-size: 0.82rem; }

/* etc... */
