*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
  padding-top: 34px;
}

/* ── Language switcher ──────────────────────────── */
#lang-switcher {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  background: #12122a;
  border-bottom: 1px solid #222;
}
#lang-switcher button {
  background: transparent;
  color: #555;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.7rem;
  cursor: pointer;
  letter-spacing: 0.5px;
}
#lang-switcher button:hover { color: #eee; border-color: #556; }
#lang-switcher button.lang-active { color: #7ec8e3; border-color: #7ec8e3; }

/* ── Views ─────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }
#view-lobby, #view-waiting, #view-gameover {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 30px 20px;
  gap: 20px;
}
#view-lobby.active, #view-waiting.active, #view-gameover.active { display: flex; }

/* ── Lobby / Waiting shared ─────────────────────── */
.panel { width: 100%; max-width: 480px; }
h1 { font-size: 2.4rem; letter-spacing: 2px; text-align: center; }
h2 { font-size: 1.2rem; color: #aaa; font-weight: 400; text-align: center; }

.card {
  background: #16213e;
  border-radius: 14px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
label { font-size: 0.85rem; color: #aaa; display: block; margin-bottom: 3px; }
input[type="text"], select {
  width: 100%; padding: 10px 14px; border-radius: 8px;
  border: 1px solid #334; background: #0f3460; color: #eee;
  font-size: 1rem; outline: none;
}
input[type="text"]:focus, select:focus { border-color: #e94560; }
.btn { padding: 12px 20px; border-radius: 8px; border: none; font-size: 1rem; font-weight: 600; cursor: pointer; transition: opacity 0.15s; width: 100%; }
.btn:hover { opacity: 0.85; }
.btn-primary { background: #e94560; color: #fff; }
.btn-secondary { background: #0f3460; color: #eee; border: 1px solid #334; }
.separator { display: flex; align-items: center; gap: 10px; color: #555; font-size: 0.85rem; }
.separator::before, .separator::after { content: ''; flex: 1; height: 1px; background: #334; }
.error { color: #e94560; font-size: 0.9rem; min-height: 1.2em; text-align: center; }

/* ── Waiting room ───────────────────────────────── */
.game-id-box { background: #0f3460; border-radius: 10px; padding: 18px; text-align: center; }
.game-id-box .code { font-size: 2.6rem; font-weight: 700; letter-spacing: 10px; color: #e94560; font-family: monospace; margin: 6px 0; }
.copy-btn { background: none; border: 1px solid #334; color: #aaa; border-radius: 6px; padding: 4px 12px; cursor: pointer; font-size: 0.8rem; margin-top: 6px; }
.copy-btn:hover { color: #eee; border-color: #888; }
.lan-url { font-size: 0.8rem; color: #666; text-align: center; }
.lan-url a { color: #7ec8e3; text-decoration: none; }
.player-item { background: #0f3460; border-radius: 8px; padding: 10px 14px; display: flex; align-items: center; gap: 10px; }
.player-item .dot { width: 10px; height: 10px; border-radius: 50%; background: #4caf50; flex-shrink: 0; }
.player-item.waiting .dot { background: #555; }
.waiting-text { color: #888; font-size: 0.9rem; text-align: center; }
.dice-mode-badge { background: #0f3460; border-radius: 20px; padding: 4px 14px; font-size: 0.8rem; color: #7ec8e3; }

/* ── Game view ──────────────────────────────────── */
#view-game { display: none; flex-direction: column; height: 100vh; height: 100dvh; }
#view-game.active { display: flex; }

#game-header {
  background: #16213e;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #222;
  flex-wrap: wrap;
}
#game-title { font-size: 1.3rem; font-weight: 700; letter-spacing: 2px; color: #e94560; flex-shrink: 0; }
#turn-banner { font-size: 0.95rem; color: #aaa; }
#turn-banner strong { color: #eee; }
#player-dots { display: flex; gap: 8px; flex-wrap: wrap; }
.pdot {
  display: flex; align-items: center; gap: 6px;
  background: #0f3460; border-radius: 20px; padding: 4px 10px;
  font-size: 0.8rem; color: #aaa; border: 2px solid transparent;
  transition: all 0.3s;
}
.pdot.active-player { border-color: #7ec8e3; color: #eee; background: #0f3460; }
.pdot .dot { width: 8px; height: 8px; border-radius: 50%; background: #555; }
.pdot.active-player .dot { background: #7ec8e3; }
.pdot .dot.online  { background: #4caf50; }
.pdot .dot.offline-turn {
  background: linear-gradient(45deg,#7a00ff,#ff003c);
  animation: offline-pulse 0.7s ease-in-out infinite;
}
@keyframes offline-pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

#game-body {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 0;
  overflow: hidden;
}

/* Left: dice zone */
#dice-zone {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  gap: 20px;
  min-width: 0;
}
#dice-group {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  justify-content: center;
  align-items: center;
  width: 100%;
}

/* 3D Dice */
.scene { perspective: 500px; width: 60px; height: 60px; flex-shrink: 0; }
.cube {
  width: 60px; height: 60px;
  position: relative; transform-style: preserve-3d;
  transition: transform 0.8s ease-in-out;
  cursor: pointer;
}
.cube.kept .face { border-color: #4caf50 !important; box-shadow: 0 0 10px 3px rgba(76,175,80,0.5) inset !important; }
.cube.disabled { cursor: default; }
.face {
  position: absolute; width: 60px; height: 60px;
  background: radial-gradient(circle at 35% 35%, #fff 0%, #ddd 100%);
  border-radius: 10px; border: 2px solid #aaa;
  box-shadow: inset 0 0 6px rgba(0,0,0,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: bold; color: #222;
  user-select: none; backface-visibility: hidden;
}
.face1 { transform: rotateY(0deg)   translateZ(30px); }
.face2 { transform: rotateY(180deg) translateZ(30px); }
.face3 { transform: rotateY(90deg)  translateZ(30px); }
.face4 { transform: rotateY(-90deg) translateZ(30px); }
.face5 { transform: rotateX(-90deg) translateZ(30px); }
.face6 { transform: rotateX(90deg)  translateZ(30px); }

#turn-timer { font-size: 0.82rem; color: #4caf50; text-align: center; font-variant-numeric: tabular-nums; transition: color 0.4s; }
#turn-timer.warn  { color: #f0a500; }
#turn-timer.alert { color: #e94560; animation: timer-pulse 0.6s ease-in-out infinite; }
@keyframes timer-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
#dice-hint { font-size: 0.8rem; color: #555; text-align: center; }
#dice-group.spectating .cube { cursor: default; pointer-events: none; }
#dice-group.spectating .face { opacity: 0.6; filter: grayscale(0.35); }

#rerolls-bar { display: flex; align-items: center; gap: 10px; }
.reroll-pip { width: 12px; height: 12px; border-radius: 50%; background: #334; transition: background 0.2s; }
.reroll-pip.available { background: #e94560; }

#reroll-btn {
  padding: 10px 24px; border-radius: 8px; border: none;
  background: #e94560; color: #fff; font-size: 0.95rem; font-weight: 600;
  cursor: pointer; transition: opacity 0.15s;
}
#reroll-btn:hover:not(:disabled) { opacity: 0.85; }
#reroll-btn:disabled { opacity: 0.35; cursor: default; }

#waiting-msg { font-size: 0.9rem; color: #666; font-style: italic; text-align: center; }

/* ── Suggestion ─────────────────────────────────── */
.scene:has(.cube.suggested) {
  filter: drop-shadow(0 0 8px rgba(240,165,0,0.9)) drop-shadow(0 0 16px rgba(240,165,0,0.4));
  animation: suggest-pulse 1.4s ease-in-out infinite;
}
@keyframes suggest-pulse {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(240,165,0,1)) drop-shadow(0 0 14px rgba(240,165,0,0.5)); }
  50%       { filter: drop-shadow(0 0 14px rgba(240,165,0,0.3)) drop-shadow(0 0 28px rgba(240,165,0,0.1)); }
}
#suggestion-area { display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 48px; }
#suggestion-text { font-size: 0.82rem; color: #f0a500; font-style: italic; text-align: center; }
#suggestion-follow {
  padding: 4px 14px; border-radius: 6px; border: 1px solid #f0a500;
  background: none; color: #f0a500; font-size: 0.8rem; cursor: pointer;
  transition: background 0.12s;
}
#suggestion-follow:hover { background: rgba(240,165,0,0.15); }
#suggest-toggle {
  padding: 4px 12px; border-radius: 6px; border: 1px solid #f0a500;
  background: none; color: #f0a500; font-size: 0.78rem; cursor: pointer;
  transition: all 0.15s; flex-shrink: 0;
}
#suggest-toggle.off { border-color: #334; color: #555; }

/* Right: score panel */
#score-panel {
  width: 280px;
  flex-shrink: 0;
  background: #16213e;
  border-left: 1px solid #222;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#score-options-section {
  padding: 16px;
  border-bottom: 1px solid #222;
}
#score-options-section h3 { font-size: 0.8rem; color: #aaa; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; }
.score-opt {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 6px; margin-bottom: 4px;
  cursor: pointer; background: #0f3460; border: 1px solid #334;
  transition: background 0.12s, border-color 0.12s; font-size: 0.88rem;
}
.score-opt:hover { background: #1a4a80; border-color: #e94560; }
.score-opt .pts { font-weight: 700; color: #7ec8e3; }
.score-opt.zero-pts { opacity: 0.45; }
.score-opt.zero-pts:hover { opacity: 0.7; }
.score-opt.score-opt-primary {
  background: #1a3a4a;
  border-color: #f0b429;
  box-shadow: 0 0 6px rgba(240,180,41,0.3);
}
.score-opt.score-opt-primary:hover { background: #1e4a60; }
.score-opt.score-opt-good {
  background: #1a2a3a;
  border-color: #7c6af0;
}
.score-opt.score-opt-good:hover { background: #1a3a50; }
.score-opt-badge {
  font-size: 0.7rem; margin-right: 4px; color: #f0b429; vertical-align: middle;
}
.score-opt-badge.secondary { color: #7c6af0; }
#no-options-msg { font-size: 0.8rem; color: #555; font-style: italic; padding: 4px 0; }
#score-chosen-banner { background: #0f3460; border: 1px solid #4caf50; border-radius: 8px; padding: 10px 12px; text-align: center; font-size: 0.85rem; }
#score-chosen-banner .sc-label { color: #aaa; font-size: 0.75rem; margin-bottom: 4px; }
#score-chosen-banner .sc-combo { color: #eee; font-weight: 600; }
#score-chosen-banner .sc-pts { color: #4caf50; font-size: 1.1rem; font-weight: 700; }
.opt-section-label { font-size: 0.68rem; color: #555; text-transform: uppercase; letter-spacing: 0.8px; margin: 10px 0 4px 2px; }
.opt-section-label:first-child { margin-top: 0; }

#scores-section { padding: 16px; flex: 1; }
#scores-section h3 { font-size: 0.8rem; color: #aaa; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; }

.player-scorecard { margin-bottom: 16px; }
.player-scorecard .pname {
  font-size: 0.85rem; font-weight: 700; color: #7ec8e3;
  margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center;
}
.player-scorecard .pname.active-pname { color: #e94560; }
.scorecard-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.scorecard-table td { padding: 2px 4px; }
.scorecard-table td:last-child { text-align: right; font-weight: 600; color: #7ec8e3; }
.scorecard-table tr.section-label td { color: #555; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px; padding-top: 6px; }
.scorecard-table tr.bonus-row td { color: #f0a500; }
.scorecard-table tr.total-row td { color: #eee; font-weight: 700; border-top: 1px solid #334; padding-top: 4px; }
.scored-val { color: #4caf50; }
.crossed-val { color: #555; text-decoration: line-through; }
.empty-val { color: #333; }
.scorecard-table tr.last-scored { background: rgba(255, 200, 0, 0.08); }
.scorecard-table tr.last-scored td:first-child { border-left: 2px solid #f0a500; padding-left: 4px; }

/* ── Leaderboard ────────────────────────────────── */
.leaderboard-card { padding: 14px 16px; gap: 8px; }
.leaderboard-title { font-size: 0.85rem; font-weight: 700; color: #f0a500; margin-bottom: 6px; }
.leaderboard-cols { display: flex; gap: 12px; }
.leaderboard-col  { flex: 1; min-width: 0; }
.leaderboard-col-title { font-size: 0.75rem; color: #aaa; text-align: center; margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid #222; }
.leaderboard-row {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 0; border-bottom: 1px solid #1e1e3a;
}
.leaderboard-row:last-of-type { border-bottom: none; }
.lb-medal { font-size: 1rem; width: 20px; }
.lb-name  { flex: 1; font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; color: #7ec8e3; font-size: 0.8rem; white-space: nowrap; }
.leaderboard-note { font-size: 0.68rem; color: #444; margin-top: 8px; text-align: center; }

/* ── Game Over ──────────────────────────────────── */
.result-row {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: #0f3460; border-radius: 8px; margin-bottom: 8px;
  user-select: none;
}
.result-row.winner { background: #1a4a20; border: 1px solid #4caf50; }
.result-row .rank { font-size: 1.4rem; width: 30px; }
.result-row .pname { flex: 1; font-size: 1rem; }
.result-row .total { font-size: 1.2rem; font-weight: 700; color: #7ec8e3; }
.result-row .breakdown-toggle { font-size: 0.7rem; color: #666; margin-left: 8px; }
.score-breakdown { width: 100%; margin-top: 10px; }
.breakdown-table { font-size: 0.8rem; }
.breakdown-table td { padding: 2px 6px; }

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 600px) {
  #view-lobby, #view-waiting, #view-gameover { min-height: 100dvh; padding: 20px 14px; }
  #game-header { padding: 8px 12px; gap: 6px; }
  #game-title { font-size: 1rem; letter-spacing: 1px; }
  #turn-banner { font-size: 0.82rem; }
  #suggest-toggle { font-size: 0.72rem; padding: 3px 8px; }
  #game-body { flex-direction: column; }
  #dice-zone { flex: 0 0 auto; padding: 14px 12px; gap: 12px; justify-content: flex-start; }
  #dice-group { flex-wrap: nowrap; gap: 4px; justify-content: center; width: 100%; }
  .scene { width: 44px; height: 44px; }
  .cube { width: 44px; height: 44px; }
  .face { width: 44px; height: 44px; font-size: 18px; }
  .face1 { transform: rotateY(0deg)   translateZ(22px); }
  .face2 { transform: rotateY(180deg) translateZ(22px); }
  .face3 { transform: rotateY(90deg)  translateZ(22px); }
  .face4 { transform: rotateY(-90deg) translateZ(22px); }
  .face5 { transform: rotateX(-90deg) translateZ(22px); }
  .face6 { transform: rotateX(90deg)  translateZ(22px); }
  #score-panel { width: 100%; border-left: none; border-top: 1px solid #222; flex: 1; min-height: 0; }
  .score-opt { padding: 10px 12px; font-size: 0.9rem; margin-bottom: 6px; }
  .scorecard-table { font-size: 0.82rem; }
}

/* ── Auth ───────────────────────────────────────────────── */
.btn-google {
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 500;
}
.btn-google:hover { background: #f8f9fa; opacity: 1; }

.btn-passkey {
  background: #2d2d44;
  color: #e0e0ff;
  border: 1px solid #4444aa;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  width: 100%;
}
.btn-passkey:hover { background: #3a3a5c; opacity: 1; }

.btn-microsoft {
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 500;
}
.btn-microsoft:hover { background: #f8f9fa; opacity: 1; }

.auth-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #0f3460;
  border-radius: 8px;
  padding: 8px 12px;
}
.auth-chip img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: #334;
}
.auth-chip .auth-name {
  flex: 1;
  font-size: 0.88rem;
  color: #eee;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.auth-chip .auth-logout {
  background: none;
  border: 1px solid #334;
  color: #888;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.75rem;
  cursor: pointer;
  width: auto;
  flex-shrink: 0;
}
.auth-chip .auth-logout:hover { color: #e94560; border-color: #e94560; opacity: 1; }

#auth-history details summary { list-style: none; }
#auth-history details summary::-webkit-details-marker { display: none; }
.history-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 0.73rem; color: #aaa; }
.history-table th { color: #666; font-weight: 400; padding: 2px 6px; border-bottom: 1px solid #222; text-align: left; }
.history-table td { padding: 3px 6px; }
.history-table tbody tr:nth-child(odd) { background: rgba(255,255,255,0.03); }

.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.auth-hint {
  font-size: 0.78rem;
  color: #555;
  text-align: center;
  margin-top: 8px;
}

@media (max-width: 380px) {
  #game-header { flex-wrap: nowrap; overflow-x: auto; }
  #player-dots { display: none; }
  .scene, .cube, .face { width: 48px; height: 48px; }
  .face1 { transform: rotateY(0deg)   translateZ(24px); }
  .face2 { transform: rotateY(180deg) translateZ(24px); }
  .face3 { transform: rotateY(90deg)  translateZ(24px); }
  .face4 { transform: rotateY(-90deg) translateZ(24px); }
  .face5 { transform: rotateX(-90deg) translateZ(24px); }
  .face6 { transform: rotateX(90deg)  translateZ(24px); }
}

/* ── Solo / Advisor ──────────────────────────────── */
.btn-create {
  background: linear-gradient(135deg, #1a6b3c, #2ecc71);
  color: #fff;
  border: none;
  transition: opacity 0.15s;
}
.btn-create:hover { opacity: 0.85; }
.btn-create:disabled { background: #2a2a3a; color: #555; cursor: not-allowed; }

.btn-solo {
  background: linear-gradient(135deg, #3a6cf0, #7c6af0);
  color: #fff;
  border: none;
  transition: opacity 0.15s;
}
.btn-solo:hover { opacity: 0.85; }
.btn-solo:disabled { background: #2a2a3a; color: #555; cursor: not-allowed; }
.btn-back {
  background: none; border: 1px solid #444; color: #aaa;
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
}
.btn-back:hover { background: #2a2a3a; color: #eee; }

#view-solo { display: none; }
#view-solo.active { display: flex; align-items: flex-start; justify-content: center; padding: 12px; min-height: calc(100vh - 34px); }
#view-solo-gameover { display: none; }
#view-solo-gameover.active { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 34px); }

.solo-layout { width: 100%; max-width: 900px; }
.solo-header {
  display: flex; align-items: center; gap: 16px; margin-bottom: 16px;
}
.solo-header h1 { flex: 1; font-size: 1.3rem; }
.solo-roll-counter { font-size: 0.9rem; color: #aaa; white-space: nowrap; }

.solo-main { display: flex; gap: 16px; flex-wrap: wrap; }
.solo-left { flex: 1; min-width: 280px; }
.solo-right { width: 220px; flex-shrink: 0; }

.solo-instruction { font-size: 0.85rem; color: #aaa; margin-bottom: 10px; min-height: 1.2em; }

.solo-dice-zone {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.solo-die {
  width: 64px; height: 64px;
  background: #2a2a3a; border: 2px solid #444; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; user-select: none; transition: border-color 0.15s, background 0.15s;
  position: relative;
}
.solo-die:hover { border-color: #7c6af0; }
.solo-die.kept { background: #1a3a1a; border-color: #2ecc71; }
.solo-die-face { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.solo-die-hint { font-size: 0.6rem; color: #888; position: absolute; bottom: 3px; }
.solo-die-lock { font-size: 0.7rem; position: absolute; bottom: 3px; }

.solo-suggestion {
  font-size: 0.85rem; color: #a78bfa; min-height: 1.4em;
  margin-bottom: 10px; font-style: italic;
}
.solo-controls { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.solo-scorecard-title { font-size: 0.8rem; color: #aaa; margin-bottom: 6px; }
.solo-scorecard { font-size: 0.82rem; }
.scorecard-row {
  display: flex; justify-content: space-between;
  padding: 2px 4px; border-bottom: 1px solid #222;
}
.scorecard-row.bonus-row { color: #f0b429; }
.scorecard-row.total-row { font-weight: 700; font-size: 0.9rem; border-top: 1px solid #555; border-bottom: none; margin-top: 4px; }

@media (max-width: 600px) {
  .solo-right { width: 100%; }
  .solo-die { width: 52px; height: 52px; }
  .solo-die-face { font-size: 1.4rem; }
}
