:root {
  --card-width: 44px;
  --card-height: 64px;
  --table-size: min(92vw, 680px);

  /* Default (Light Theme) */
  --page-bg: #102216;
  --panel: #fff8df;
  --panel-strong: #f4e7bb;
  --panel-soft: #fffdf4;
  --text: #1d2118;
  --muted: #596048;
  --line: #6f5c25;
  --button-bg: #f7ebc7;
  --button-hover: #fff4d4;
  --button-text: #20190a;
  --accent: #a36d08;
  --accent-2: #23683f;
  --board-text: #fff1bc;
  --board-muted: #ffe39a;
  --board-line: #ffd76f;
  --timer-glow: #ffcf57;
  --win: #27683c;
  --lose: #9d3c22;
  --shadow: rgba(0, 0, 0, 0.4);
  --card: #fffaf0;
  --card-ink: #24190c;
  --card-back: #263e28;
  --card-back-line: #f5d779;
}

/* Dark Theme Overrides */
body.theme-dark {
  --page-bg: #090e0a;
  --panel: #1a241c;
  --panel-strong: #253328;
  --panel-soft: #121a14;
  --text: #e2ebd8;
  --muted: #8b997c;
  --line: #3a4f3e;
  --button-bg: #2a3a2d;
  --button-hover: #374b3a;
  --button-text: #f0f7e8;
  --accent: #d4af37;
  --board-text: #e0eadd;
  --board-muted: #a3b59f;
  --board-line: #425c46;
  --card: #202b22;
  --card-ink: #f0f5eb;
}

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

body {
  background-color: var(--page-bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Base Layout */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

/* Tracker Sidebar */
.tracker {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  height: max-content;
  max-height: 85vh;
  box-shadow: 0 4px 12px var(--shadow);
}

.tracker-time {
  font-weight: bold;
  font-size: 1.1rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}

.move-list {
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text);
}

.move-list li {
  padding: 0.25rem 0;
  border-bottom: 1px dashed var(--line);
}

/* Game Stage */
.game-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hero-copy {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  color: var(--board-text);
}

.title-block h1 {
  font-size: 1.8rem;
  color: var(--accent);
  text-shadow: 0 2px 4px var(--shadow);
}

.settings {
  display: flex;
  gap: 0.75rem;
}

.settings label {
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  color: var(--board-muted);
}

.settings select {
  background: var(--button-bg);
  color: var(--button-text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
}

/* Round Table */
.round-table {
  position: relative;
  width: var(--table-size);
  height: var(--table-size);
  margin: 1rem auto;
  border-radius: 50%;
  background: radial-gradient(circle, #2e4a33 60%, #16281a 100%);
  border: 8px solid #3d2a18;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.6), 0 10px 30px var(--shadow);
}

.table-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.deck-zone {
  display: flex;
  gap: 16px;
}

.deck {
  width: var(--card-width);
  height: var(--card-height);
  border-radius: 6px;
  border: 2px solid var(--board-line);
  background: var(--button-bg);
  color: var(--button-text);
  font-weight: bold;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 8px var(--shadow);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.deck:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.deck:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#discardCardPreview {
  font-size: 0.9rem;
}

.turn-hint {
  font-size: 0.85rem;
  color: var(--board-text);
  background: rgba(0, 0, 0, 0.4);
  padding: 0.3rem 0.75rem;
  border-radius: 12px;
  text-align: center;
  white-space: nowrap;
}

/* Player Slots & Hands */
.player-slot {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 3;
}

.player-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid var(--board-line);
  object-fit: cover;
  background-color: #1a1a1a;
  box-shadow: 0 2px 6px var(--shadow);
}

.hand, .cpu-hand-wrap {
  margin-top: 4px;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Absolute Seat Coordinates around the circle */
/* Absolute Seat Positions around Table */
#player1 { bottom: 12px; left: 50%; transform: translateX(-50%); }

/* Middle right player (CPU 1) – push down slightly */
#player2 { top: 65%; right: -10px; transform: translateY(-50%); }

/* Top right player */
/* Top right player */
#player3 { top: 15%; right: 15%; }

/* Top left player – move lower than player3 */
#player4 { top: 12%; left: 5%; }


/* Middle left player (CPU 4) – push down slightly */
#player5 { top: 70%; left: -10px; transform: translateY(-50%); }

/* Cards */
.card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px;
  width: var(--card-width);
  height: var(--card-height);
  background-color: var(--card);
  color: var(--card-ink);
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 4px var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.hand .card:not(:first-child),
.cpu-hand-wrap .card:not(:first-child) {
  margin-left: -18px;
}

.card:hover:not(:disabled),
.card.is-selected {
  transform: translateY(-8px);
  z-index: 10;
  border-color: #0077ff;
  box-shadow: 0 0 8px rgba(0, 119, 255, 0.8);
}

/* Meld Highlight Borders */
.card.meld-set { border: 2px solid #28a745; }
.card.meld-run { border: 2px solid #ffc107; }

.card.dragging { opacity: 0.4; transform: scale(1.05); }
.card.drop-target { outline: 2px dashed #0077ff; }

.card-rank { font-size: 0.8rem; align-self: flex-start; }
.card-suit { font-size: 1rem; }
.card-suit-small { font-size: 0.65rem; align-self: flex-end; }

/* Wizard/Back Card Visuals */
.wizard-card-back, .card-back {
  background: linear-gradient(135deg, #2b1b4d 0%, #1a1030 100%);
  color: #d4af37;
  border: 1px solid #d4af37;
  justify-content: center;
}

.wizard-sigil, .back-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.65rem;
}

/* Controls & Actions */
.duel-controls {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-top: 1rem;
}

.timer {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--timer-glow);
  text-shadow: 0 0 6px var(--timer-glow);
}

.duel-buttons, .finish-buttons, .modal-buttons {
  display: flex;
  gap: 0.5rem;
}

button {
  background: var(--button-bg);
  color: var(--button-text);
  border: 1px solid var(--line);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

button:hover:not(:disabled) {
  background: var(--button-hover);
}

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

.action-panel {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-top: 0.75rem;
  background: var(--panel);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  border: 1px solid var(--line);
}

.deadwood-score {
  font-weight: bold;
  color: var(--accent);
}

/* Result Modal */
.result-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 100;
}

.result-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.result-card {
  background: var(--panel);
  padding: 2rem;
  border-radius: 12px;
  border: 2px solid var(--line);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 280px;
  box-shadow: 0 10px 25px var(--shadow);
}

.result-card.win h2 { color: var(--win); }
.result-card.lose h2 { color: var(--lose); }

/* Responsive Overrides */
/* Responsive Overrides & 13-Card Hand Formatting */
@media (max-width: 800px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .tracker {
    max-height: 140px;
  }

  :root {
    --card-width: 32px;
    --card-height: 48px;
  }

  /* Tighter card overlap for mobile screens to fit 13 cards */
  .hand .card:not(:first-child),
  .cpu-hand-wrap .card:not(:first-child) {
    margin-left: -18px;
  }

  #player2 { right: -5px; }
  #player5 { left: -5px; }
}