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

/* ===== THEMES ===== */
:root, [data-theme="dark"] {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface-2: #0f3460;
  --primary: #e94560;
  --primary-hover: #ff6b81;
  --text: #eee;
  --text-muted: #999;
  --success: #2ecc71;
  --warning: #f39c12;
  --border: #333;
  --dice-bg: #f5f5f0;
  --dice-border: #bbb;
  --dice-shadow: rgba(0,0,0,0.35);
  --dice-dot: #1a1a1a;
  --held-border: #e94560;
  --held-glow: rgba(233, 69, 96, 0.5);
  --score-available: rgba(233, 69, 96, 0.25);
  --score-hover: rgba(233, 69, 96, 0.5);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

[data-theme="light"] {
  --bg: #f0f2f5;
  --surface: #fff;
  --surface-2: #e8eaed;
  --primary: #d63031;
  --primary-hover: #e84343;
  --text: #222;
  --text-muted: #666;
  --success: #27ae60;
  --warning: #e67e22;
  --border: #d0d0d0;
  --dice-bg: #fff;
  --dice-border: #aaa;
  --dice-shadow: rgba(0,0,0,0.2);
  --dice-dot: #111;
  --held-border: #d63031;
  --held-glow: rgba(214, 48, 49, 0.35);
  --score-available: rgba(214, 48, 49, 0.15);
  --score-hover: rgba(214, 48, 49, 0.3);
}

[data-theme="casino"] {
  --bg: #1b5e20;
  --surface: #2e7d32;
  --surface-2: #388e3c;
  --primary: #fdd835;
  --primary-hover: #ffee58;
  --text: #fff;
  --text-muted: #c8e6c9;
  --success: #76ff03;
  --warning: #ff9800;
  --border: #1b5e20;
  --dice-bg: #fafafa;
  --dice-border: #999;
  --dice-shadow: rgba(0,0,0,0.4);
  --dice-dot: #111;
  --held-border: #fdd835;
  --held-glow: rgba(253, 216, 53, 0.5);
  --score-available: rgba(253, 216, 53, 0.2);
  --score-hover: rgba(253, 216, 53, 0.4);
}

[data-theme="ocean"] {
  --bg: #0a1628;
  --surface: #0d2137;
  --surface-2: #133a5c;
  --primary: #00bcd4;
  --primary-hover: #26c6da;
  --text: #e0f7fa;
  --text-muted: #80cbc4;
  --success: #00e676;
  --warning: #ffab40;
  --border: #1a3a5c;
  --dice-bg: #e0f7fa;
  --dice-border: #80cbc4;
  --dice-shadow: rgba(0,0,0,0.4);
  --dice-dot: #0a1628;
  --held-border: #00bcd4;
  --held-glow: rgba(0, 188, 212, 0.5);
  --score-available: rgba(0, 188, 212, 0.2);
  --score-hover: rgba(0, 188, 212, 0.4);
}

[data-theme="sunset"] {
  --bg: #2d1b00;
  --surface: #3e2723;
  --surface-2: #4e342e;
  --primary: #ff7043;
  --primary-hover: #ff8a65;
  --text: #ffecb3;
  --text-muted: #bcaaa4;
  --success: #aed581;
  --warning: #ffc107;
  --border: #5d4037;
  --dice-bg: #fff8e1;
  --dice-border: #a1887f;
  --dice-shadow: rgba(0,0,0,0.35);
  --dice-dot: #3e2723;
  --held-border: #ff7043;
  --held-glow: rgba(255, 112, 67, 0.5);
  --score-available: rgba(255, 112, 67, 0.2);
  --score-hover: rgba(255, 112, 67, 0.4);
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  transition: background 0.3s, color 0.3s;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
[data-theme="casino"] .btn-primary { color: #222; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-secondary:hover { opacity: 0.85; }
.btn-sm {
  padding: 5px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
}

/* Header controls (lang + theme) */
.header-controls {
  position: fixed;
  top: 12px;
  right: 16px;
  display: flex;
  gap: 6px;
  z-index: 100;
}
.header-controls .ctrl-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

input[type="text"] {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  width: 100%;
}
input[type="text"]:focus { border-color: var(--primary); }

/* ===== LANDING PAGE ===== */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.landing h1 {
  font-size: 2.5rem;
  margin-bottom: 40px;
  color: var(--primary);
}
.landing-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 400px;
}

/* ===== LOBBY ===== */
.lobby {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  max-width: 500px;
  margin: 0 auto;
}
.lobby h2 { margin-bottom: 16px; }
.lobby-link {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}
.lobby-link input {
  flex: 1;
  font-size: 0.85rem;
}
.player-list {
  list-style: none;
  margin: 16px 0;
}
.player-list li {
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 4px;
  background: var(--surface-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.player-list .host-badge {
  font-size: 0.75rem;
  background: var(--warning);
  color: #000;
  padding: 2px 8px;
  border-radius: 4px;
}
.mode-selector {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}
.mode-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  font-weight: 600;
  transition: border-color 0.2s;
}
.mode-btn.active {
  border-color: var(--primary);
  background: var(--score-available);
}

/* ===== GAME LAYOUT ===== */
.game-container {
  display: none;
  height: 100vh;
  flex-direction: column;
}
.game-container.active { display: flex; }

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  padding-right: 180px; /* space for fixed header-controls */
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.game-header h1 { font-size: 1.2rem; color: var(--primary); }

.game-boards {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.board-panel {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  scrollbar-width: none;
}
.board-panel::-webkit-scrollbar { width: 0; }
.board-panel:first-child {
  border-right: 1px solid var(--border);
}

/* ===== BOARD HEADERS (aligned) ===== */
.board-panel h3 {
  margin: 0 0 12px 0;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
  background: var(--surface-2);
  border: 2px solid var(--primary);
  border-radius: 6px;
  display: inline-block;
}

/* ===== PLAYER TABS ===== */
.player-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}
.player-tab {
  padding: 6px 14px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 2px solid transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: border-color 0.2s;
}
.player-tab.active { border-color: var(--primary); }
.player-tab.current-turn { background: var(--score-available); }

/* ===== SCORECARD ===== */
.scorecard {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.85rem;
}
.scorecard th, .scorecard td {
  padding: 3px 5px;
  border: 1px solid var(--border);
  text-align: center;
}
.scorecard th {
  background: var(--surface-2);
  font-weight: 600;
}
.scorecard .section-header {
  background: var(--surface);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}
.scorecard .cat-name { text-align: center; font-size: 0.8rem; width: 30%; }
.scorecard .score-cell {
  cursor: default;
}
.scorecard .score-cell.available {
  background: var(--score-available);
  cursor: pointer;
  font-style: italic;
  color: var(--text-muted);
}
.scorecard .score-cell.available:hover {
  background: var(--score-hover);
}
.scorecard .bonus-row { color: var(--warning); }
.scorecard .total-row {
  font-weight: 700;
  font-size: 1rem;
  background: var(--surface-2);
}
.scorecard tr.row-alt td {
  background: rgba(128, 128, 128, 0.07);
}
.scorecard tr.row-alt .score-cell.available {
  background: color-mix(in srgb, var(--score-available), rgba(128, 128, 128, 0.15));
}
.scorecard tr.row-alt .score-cell.available:hover {
  background: var(--score-hover);
}
.scorecard .score-cell.last-move {
  font-weight: 700;
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
.scorecard .score-cell.preview {
  font-style: italic;
  color: var(--text-muted);
  opacity: 0.6;
}
.scorecard .score-cell.unfilled {
  color: rgba(128, 128, 128, 0.2);
}

/* ===== DICE — CLASSIC STYLE ===== */
.dice-area {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px;
  flex-shrink: 0;
  text-align: center;
}
.dice-row {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}
.die {
  width: 72px;
  height: 72px;
  background: var(--dice-bg);
  border-radius: 12px;
  border: 2px solid var(--dice-border);
  box-shadow: 2px 3px 6px var(--dice-shadow), inset 0 1px 0 rgba(255,255,255,0.4);
  position: relative;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s;
  user-select: none;
}
.die:hover:not(.disabled) {
  box-shadow: 2px 4px 10px var(--dice-shadow);
}
.die.held {
  border: 3px dashed var(--held-border);
  transform: translateY(-8px);
  box-shadow: 0 8px 16px var(--held-glow), 2px 3px 6px var(--dice-shadow);
}
.die.disabled {
  cursor: default;
  opacity: 0.75;
}
.die.rolling {
  animation: roll 0.4s ease-out;
}
@keyframes roll {
  0% { transform: rotate(0deg) scale(0.8); }
  50% { transform: rotate(180deg) scale(1.1); }
  100% { transform: rotate(360deg) scale(1); }
}

.dot {
  position: absolute;
  width: 13px;
  height: 13px;
  background: var(--dice-dot);
  border-radius: 50%;
  display: none;
}

/* 9 dot positions — real die layout
   TL  TC  TR     (1  2  3)
   ML  MC  MR     (4  5  6)
   BL  BC  BR     (7  8  9)
*/
.dot:nth-child(1) { top: 14%; left: 14%; }     /* TL */
.dot:nth-child(2) { top: 14%; left: 50%; transform: translateX(-50%); }  /* TC */
.dot:nth-child(3) { top: 14%; right: 14%; }    /* TR */
.dot:nth-child(4) { top: 50%; left: 14%; transform: translateY(-50%); }  /* ML */
.dot:nth-child(5) { top: 50%; left: 50%; transform: translate(-50%, -50%); } /* MC */
.dot:nth-child(6) { top: 50%; right: 14%; transform: translateY(-50%); } /* MR */
.dot:nth-child(7) { bottom: 14%; left: 14%; }  /* BL */
.dot:nth-child(8) { bottom: 14%; left: 50%; transform: translateX(-50%); } /* BC */
.dot:nth-child(9) { bottom: 14%; right: 14%; } /* BR */

/* Die faces */
.die[data-value="1"] .dot:nth-child(5) { display: block; }

.die[data-value="2"] .dot:nth-child(3) { display: block; }
.die[data-value="2"] .dot:nth-child(7) { display: block; }

.die[data-value="3"] .dot:nth-child(3) { display: block; }
.die[data-value="3"] .dot:nth-child(5) { display: block; }
.die[data-value="3"] .dot:nth-child(7) { display: block; }

.die[data-value="4"] .dot:nth-child(1) { display: block; }
.die[data-value="4"] .dot:nth-child(3) { display: block; }
.die[data-value="4"] .dot:nth-child(7) { display: block; }
.die[data-value="4"] .dot:nth-child(9) { display: block; }

.die[data-value="5"] .dot:nth-child(1) { display: block; }
.die[data-value="5"] .dot:nth-child(3) { display: block; }
.die[data-value="5"] .dot:nth-child(5) { display: block; }
.die[data-value="5"] .dot:nth-child(7) { display: block; }
.die[data-value="5"] .dot:nth-child(9) { display: block; }

.die[data-value="6"] .dot:nth-child(1) { display: block; }
.die[data-value="6"] .dot:nth-child(3) { display: block; }
.die[data-value="6"] .dot:nth-child(4) { display: block; }
.die[data-value="6"] .dot:nth-child(6) { display: block; }
.die[data-value="6"] .dot:nth-child(7) { display: block; }
.die[data-value="6"] .dot:nth-child(9) { display: block; }

.dice-layout {
  display: flex;
  align-items: center;
}
.dice-layout::after {
  content: '';
  min-width: 150px;
}
.dice-main {
  flex: 1;
  text-align: center;
}
.dice-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  align-items: center;
}
.turn-info {
  min-width: 150px;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: left;
  padding-left: 8px;
}
.turn-info.your-turn {
  color: var(--success);
  font-weight: 700;
  font-size: 1.3rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  animation: pulse-turn 1.5s ease-in-out infinite;
}
@keyframes pulse-turn {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.dice-area.my-turn {
  border-top: 3px solid var(--success);
  background: linear-gradient(to bottom, rgba(46, 204, 113, 0.08), transparent 40%), var(--surface);
}

.bonus-toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--warning);
  color: #000;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1rem;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
.bonus-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== GAME OVER ===== */
.game-over-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.game-over-overlay.active { display: flex; }
.game-over-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  max-width: 500px;
  width: 90%;
}
.game-over-card h2 { color: var(--primary); margin-bottom: 16px; font-size: 1.8rem; }
.final-scores {
  list-style: none;
  margin: 16px 0;
}
.final-scores li {
  padding: 10px 16px;
  margin-bottom: 6px;
  background: var(--surface-2);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  font-size: 1.1rem;
}
.final-scores li:first-child {
  background: var(--score-available);
  border: 2px solid var(--primary);
  font-weight: 700;
}
.final-scores .rank { margin-right: 8px; }

/* Join screen */
.join-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

/* ===== MOBILE ===== */
@media (max-width: 767px) {
  .game-boards { flex-direction: column; }
  .board-panel:first-child { border-right: none; border-bottom: 1px solid var(--border); }
  .board-panel.right-panel { display: none; }
  .die { width: 54px; height: 54px; border-radius: 10px; }
  .dot { width: 10px; height: 10px; }
  .dice-row { gap: 10px; }
  .scorecard { font-size: 0.75rem; }
  .scorecard th, .scorecard td { padding: 3px 3px; }
  .dice-layout { flex-direction: column; }
  .dice-layout::after { display: none; }
  .turn-info { text-align: center; min-width: auto; padding-left: 0; }
  .game-header { padding-right: 140px; }
  .header-controls { top: 8px; right: 8px; }
}
