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

:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --surface2: #21262d;
  --border:   #30363d;
  --text:     #e6edf3;
  --muted:    #8b949e;
  --accent:   #f59e0b;
  --red:      #ef4444;
  --blue:     #3b82f6;
  --yellow:   #eab308;
  --green:    #22c55e;
  --shadow:   0 4px 24px rgba(0,0,0,.5);
  --radius:   12px;
}

[data-theme="light"] {
  --bg:       #f1f5f9;
  --surface:  #ffffff;
  --surface2: #f8fafc;
  --border:   #e2e8f0;
  --text:     #0f172a;
  --muted:    #64748b;
  --shadow:   0 4px 24px rgba(0,0,0,.12);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

/* No screen rotation */
@media screen and (orientation: landscape) and (max-height: 600px) {
  body { overflow-y: scroll; }
}

a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select { font-family: inherit; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== UTILITY ===== */
.hidden   { display: none !important; }
.flex     { display: flex; }
.flex-col { flex-direction: column; }
.gap-1    { gap: .5rem; }
.gap-2    { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-center { text-align: center; }
.w-full   { width: 100%; }
.mt-1     { margin-top: .5rem; }
.mt-2     { margin-top: 1rem; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .4rem; padding: .65rem 1.4rem;
  border: none; border-radius: var(--radius); font-size: .95rem;
  font-weight: 600; transition: all .2s; white-space: nowrap;
}
.btn-primary   { background: var(--accent); color: #000; }
.btn-primary:hover { background: #d97706; transform: translateY(-1px); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger    { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-success   { background: var(--green); color: #000; }
.btn-lg        { padding: .9rem 2rem; font-size: 1.05rem; border-radius: 14px; }
.btn-sm        { padding: .45rem .9rem; font-size: .85rem; border-radius: 8px; }
.btn:active    { transform: scale(.97); }
.btn:disabled  { opacity: .5; pointer-events: none; }

/* ===== INPUTS ===== */
.inp {
  width: 100%; padding: .7rem 1rem;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .95rem; transition: border-color .2s; outline: none;
}
.inp:focus { border-color: var(--accent); }
.inp::placeholder { color: var(--muted); }

/* ===== LAYOUT ===== */
#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ===== NAV ===== */
#nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
}
.nav-logo { font-size: 1.3rem; font-weight: 800; color: var(--accent); letter-spacing: -0.5px; }
.nav-actions { display: flex; gap: .5rem; align-items: center; }
#theme-toggle { background: none; border: none; font-size: 1.3rem; padding: .3rem; }
.nav-user { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.nav-avatar { font-size: 1.3rem; }

/* ===== VIEWS ===== */
.view { display: none; flex: 1; flex-direction: column; }
.view.active { display: flex; }

/* ===== HOME VIEW ===== */
#view-home {
  align-items: center; justify-content: center;
  padding: 2rem 1rem; min-height: calc(100vh - 60px);
}
.home-hero { text-align: center; margin-bottom: 2.5rem; }
.home-hero h1 { font-size: 2.8rem; font-weight: 800; color: var(--accent); margin-bottom: .5rem; }
.home-hero p  { color: var(--muted); font-size: 1.1rem; }
.home-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; max-width: 900px; width: 100%; }
.mode-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 1.5rem; cursor: pointer;
  transition: all .25s; text-align: center;
}
.mode-card:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: var(--shadow); }
.mode-card .icon { font-size: 2.8rem; margin-bottom: .75rem; }
.mode-card h3 { font-size: 1.1rem; margin-bottom: .3rem; }
.mode-card p  { font-size: .85rem; color: var(--muted); }

/* ===== LOBBY VIEW ===== */
#view-lobby { padding: 1.5rem; max-width: 600px; margin: 0 auto; width: 100%; }
.lobby-section { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem; border: 1px solid var(--border); }
.lobby-section h2 { margin-bottom: 1rem; font-size: 1.1rem; }
.invite-link { background: var(--surface2); border: 1px dashed var(--border); border-radius: 8px; padding: .6rem 1rem; font-size: .85rem; color: var(--muted); word-break: break-all; }
.room-list { display: flex; flex-direction: column; gap: .5rem; max-height: 280px; overflow-y: auto; }
.room-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem; background: var(--surface2);
  border-radius: 8px; border: 1px solid var(--border);
}
.room-item:hover { border-color: var(--accent); }

/* ===== GAME VIEW ===== */
#view-game { padding: 0; min-height: calc(100vh - 60px); flex-direction: column; }
#game-container {
  display: flex; flex-direction: column; align-items: center;
  padding: 1rem; gap: 1rem; min-height: calc(100vh - 60px);
}

/* ===== PLAYER STATUS BAR ===== */
#players-bar {
  display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center;
  width: 100%; max-width: 700px;
}
.player-status {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .9rem; border-radius: 10px;
  border: 2px solid transparent; font-size: .9rem; flex: 1; min-width: 130px;
  background: var(--surface); transition: all .3s;
}
.player-status.active-turn { border-color: var(--accent); box-shadow: 0 0 12px rgba(245,158,11,.3); }
.player-status.done { opacity: .5; }
.player-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.player-dot.red    { background: #ef4444; }
.player-dot.blue   { background: #3b82f6; }
.player-dot.yellow { background: #eab308; }
.player-dot.green  { background: #22c55e; }
.player-info { flex: 1; }
.player-name { font-weight: 600; font-size: .85rem; }
.player-tokens-count { font-size: .75rem; color: var(--muted); }

/* ===== BOARD WRAPPER ===== */
#board-wrap {
  position: relative; display: inline-block;
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
}

/* ===== LUDO BOARD ===== */
#ludo-board {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  width: min(90vw, 480px);
  height: min(90vw, 480px);
  background: #fff;
  border: 3px solid #888;
}

.cell {
  border: .5px solid rgba(0,0,0,.15);
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: visible;
  font-size: calc(min(90vw, 480px) / 15 * 0.38);
  cursor: default; transition: background .2s;
}

/* Color zones */
.cell.zone-red    { background: #ffcdd2; }
.cell.zone-blue   { background: #bbdefb; }
.cell.zone-yellow { background: #fff9c4; }
.cell.zone-green  { background: #c8e6c9; }
.cell.zone-white  { background: #ffffff; }
.cell.zone-center { background: #e8f5e9; }

/* Home areas (colored quadrants) */
.cell.home-red    { background: #ef4444; }
.cell.home-blue   { background: #3b82f6; }
.cell.home-yellow { background: #eab308; }
.cell.home-green  { background: #22c55e; }

/* Home inner circles */
.home-inner {
  position: absolute; inset: 8%;
  border-radius: 50%; background: rgba(255,255,255,.35);
  pointer-events: none;
}

/* Home column (colored stretch) */
.cell.home-col-red    { background: #ffcdd2; }
.cell.home-col-blue   { background: #bbdefb; }
.cell.home-col-yellow { background: #fff9c4; }
.cell.home-col-green  { background: #c8e6c9; }

/* Center triangle pieces */
.cell.center-tri {
  background: transparent;
  clip-path: none;
}
.cell.center { background: transparent; }

/* Safe square star */
.cell.safe::after {
  content: '★';
  position: absolute;
  font-size: .6em;
  color: rgba(0,0,0,.25);
  pointer-events: none;
}

/* Starting squares (bigger star) */
.cell.start-red::after    { content: '⬤'; color: rgba(239,68,68,.3); font-size: .8em; }
.cell.start-blue::after   { content: '⬤'; color: rgba(59,130,246,.3); font-size: .8em; }
.cell.start-yellow::after { content: '⬤'; color: rgba(234,179,8,.3); font-size: .8em; }
.cell.start-green::after  { content: '⬤'; color: rgba(34,197,94,.3); font-size: .8em; }

/* ===== TOKENS ===== */
.token-slot {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}

.token {
  width: 60%; height: 60%;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,.3);
  display: flex; align-items: center; justify-content: center;
  font-size: .55em; font-weight: 700; color: white;
  cursor: pointer; position: relative;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  pointer-events: all;
  z-index: 5;
  user-select: none;
  -webkit-user-select: none;
}
.token:hover { transform: scale(1.2); box-shadow: 0 4px 12px rgba(0,0,0,.4); }
.token.movable { animation: pulse 1s infinite alternate; cursor: pointer; }
.token.red    { background: linear-gradient(135deg, #f87171, #b91c1c); }
.token.blue   { background: linear-gradient(135deg, #60a5fa, #1d4ed8); }
.token.yellow { background: linear-gradient(135deg, #fde047, #a16207); }
.token.green  { background: linear-gradient(135deg, #4ade80, #15803d); }
.token.home   { opacity: .85; border-style: dashed; cursor: default; }
.token.won    { transform: scale(.7); opacity: .7; }

/* Multiple tokens on same square */
.cell[data-count="2"] .token { width: 44%; height: 44%; }
.cell[data-count="3"] .token { width: 36%; height: 36%; }
.cell[data-count="4"] .token { width: 32%; height: 32%; }

@keyframes pulse {
  from { box-shadow: 0 0 0 0 rgba(245,158,11,.5); }
  to   { box-shadow: 0 0 0 8px rgba(245,158,11,0); }
}

@keyframes hop {
  0%   { transform: scale(1) translateY(0); }
  50%  { transform: scale(1.3) translateY(-8px); }
  100% { transform: scale(1) translateY(0); }
}
.token.hopping { animation: hop .35s ease; }

/* Center star */
.center-star {
  font-size: 1.8em; pointer-events: none;
  background: linear-gradient(135deg, #ef4444 25%, #3b82f6 25% 50%, #22c55e 50% 75%, #eab308 75%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

/* ===== DICE AREA ===== */
#dice-area {
  display: flex; flex-direction: column; align-items: center; gap: .75rem;
  padding: 1rem;
}
#turn-indicator {
  font-size: 1rem; font-weight: 600; color: var(--muted);
  text-align: center; min-height: 1.4em;
}
#dice-wrap {
  display: flex; align-items: center; gap: 1rem;
}

#dice-face {
  width: 70px; height: 70px;
  background: #fff; border-radius: 12px;
  border: 2px solid #ddd;
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  padding: 8px; gap: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  transition: transform .1s;
}
#dice-face.rolling { animation: diceRoll .5s ease; }

.dot {
  width: 100%; height: 100%;
  background: #1a1a2e; border-radius: 50%;
  display: none;
}
.dot.show { display: block; }

/* Dot positions for each number */
[data-dice="1"] .d5 { display: block; }
[data-dice="2"] .d1,.d9 { display: block; }
[data-dice="3"] .d1,.d5,.d9 { display: block; }
[data-dice="4"] .d1,.d3,.d7,.d9 { display: block; }
[data-dice="5"] .d1,.d3,.d5,.d7,.d9 { display: block; }
[data-dice="6"] .d1,.d3,.d4,.d6,.d7,.d9 { display: block; }

@keyframes diceRoll {
  0%   { transform: rotate(0deg) scale(1); }
  25%  { transform: rotate(180deg) scale(1.1); }
  50%  { transform: rotate(360deg) scale(1); }
  75%  { transform: rotate(540deg) scale(1.1); }
  100% { transform: rotate(720deg) scale(1); }
}

#btn-roll {
  padding: .7rem 1.8rem; font-size: 1rem; border-radius: 12px;
}
#cheat-badge {
  background: #ef4444; color: #fff;
  padding: .3rem .8rem; border-radius: 9999px;
  font-size: .8rem; font-weight: 700;
  display: none; animation: blink 1s infinite;
}
@keyframes blink {
  0%,100% { opacity:1; } 50% { opacity:.4; }
}

/* ===== GAME LOG ===== */
#game-log {
  max-width: 700px; width: 100%;
  background: var(--surface); border-radius: var(--radius);
  padding: 1rem; border: 1px solid var(--border);
  max-height: 120px; overflow-y: auto;
}
.log-entry { font-size: .82rem; color: var(--muted); padding: .2rem 0; }
.log-entry .color { font-weight: 700; }
.log-entry .color.red    { color: #f87171; }
.log-entry .color.blue   { color: #60a5fa; }
.log-entry .color.yellow { color: #fde047; }
.log-entry .color.green  { color: #4ade80; }

/* ===== CHEAT MODE BANNER ===== */
#cheat-banner {
  background: #7f1d1d; border: 1px solid #ef4444;
  border-radius: 8px; padding: .5rem 1rem;
  font-size: .85rem; color: #fca5a5;
  font-weight: 600; display: none;
  text-align: center;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 999; padding: 1rem;
}
.modal {
  background: var(--surface); border-radius: 20px;
  padding: 2rem; max-width: 420px; width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: modalIn .3s ease;
}
@keyframes modalIn {
  from { transform: scale(.85); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.modal h2 { margin-bottom: 1.2rem; font-size: 1.3rem; }
.modal-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1.5rem; }

/* ===== WIN SCREEN ===== */
#win-screen {
  position: fixed; inset: 0; background: rgba(0,0,0,.85);
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 1000; text-align: center; padding: 2rem;
}
#win-screen.show { display: flex; }
.win-trophy { font-size: 5rem; animation: bounce 1s infinite alternate; }
@keyframes bounce {
  from { transform: translateY(0); }
  to   { transform: translateY(-20px); }
}
.win-title { font-size: 2rem; font-weight: 800; color: var(--accent); margin: 1rem 0 .5rem; }
.win-subtitle { color: var(--muted); margin-bottom: 2rem; }

/* ===== LEADERBOARD VIEW ===== */
#view-leaderboard { padding: 1.5rem; max-width: 600px; margin: 0 auto; width: 100%; }
.lb-row {
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1rem; background: var(--surface);
  border-radius: 10px; margin-bottom: .5rem; border: 1px solid var(--border);
}
.lb-rank { font-size: 1.2rem; font-weight: 800; min-width: 2rem; text-align: center; color: var(--muted); }
.lb-rank.gold   { color: #f59e0b; }
.lb-rank.silver { color: #94a3b8; }
.lb-rank.bronze { color: #b45309; }
.lb-name { flex: 1; }
.lb-score { font-weight: 700; color: var(--accent); }

/* ===== LOCAL MODE ===== */
.local-turn-banner {
  background: var(--surface); border: 2px solid var(--accent);
  border-radius: 12px; padding: 1rem 1.5rem;
  text-align: center; font-size: 1.1rem; font-weight: 700;
  margin-bottom: .5rem;
}
.local-turn-banner .turn-color { text-transform: capitalize; }

/* ===== PRACTICE MODE ===== */
.difficulty-btns { display: flex; gap: .5rem; }
.diff-btn {
  flex: 1; padding: .6rem;
  border: 2px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text); font-weight: 600;
  transition: .2s;
}
.diff-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(245,158,11,.1); }
.diff-btn:hover  { border-color: var(--accent); }

/* ===== TOAST ===== */
#toast {
  position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%);
  background: var(--surface2); color: var(--text);
  padding: .75rem 1.5rem; border-radius: 9999px;
  box-shadow: var(--shadow); z-index: 9999;
  font-size: .9rem; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .3s;
  max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }

/* ===== OFFLINE INDICATOR ===== */
#offline-bar {
  background: #854d0e; color: #fef08a;
  text-align: center; font-size: .85rem;
  padding: .4rem; display: none;
}
#offline-bar.show { display: block; }

/* ===== HISTORY VIEW ===== */
#view-history { padding: 1.5rem; max-width: 600px; margin: 0 auto; width: 100%; }
.history-item {
  background: var(--surface); border-radius: 10px;
  padding: 1rem 1.2rem; margin-bottom: .75rem;
  border: 1px solid var(--border); border-left: 4px solid;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 700px) {
  #game-container { flex-direction: row; align-items: flex-start; flex-wrap: wrap; justify-content: center; }
  #game-right { display: flex; flex-direction: column; gap: 1rem; max-width: 260px; }
  #players-bar { flex-direction: column; max-width: 240px; }
  #dice-area { align-items: flex-start; }
}

@media (max-width: 699px) {
  #ludo-board { width: min(97vw, 420px); height: min(97vw, 420px); }
  .home-hero h1 { font-size: 2rem; }
  .home-cards { grid-template-columns: 1fr; }
  #game-container { padding: .5rem; gap: .5rem; }
  #game-right { width: 100%; max-width: 97vw; flex-direction: row; flex-wrap: wrap; justify-content: center; }
  #players-bar { flex-direction: row; flex-wrap: wrap; justify-content: center; width: 100%; }
  .player-status { min-width: 110px; flex: 0 1 auto; }
  #game-log { display: none; }
  #dice-area { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: center; padding: .5rem; gap: .5rem; }
  #turn-indicator { width: 100%; text-align: center; font-size: .9rem; }
}

/* Dice dots light theme fix */
[data-theme="light"] .dot { background: #111; }
[data-theme="light"] #dice-face { border-color: #ccc; }

