@import url('https://fonts.googleapis.com/css2?family=Cinzel+Decorative:wght@700;900&family=Cinzel:wght@400;600;700&family=Rajdhani:wght@400;600;700&display=swap');

/* ── Design canvas ── */
:root {
  --pw: 390px;
  --canvas-h: 490px;   /* fixed canvas height — preserves aspect ratio 390:490 */
  --ph: 672px;         /* HUD(70) + divider(1) + canvas(490) + status(26) + action(85) */

  --bg:       #04060e;
  --baize:    #06091a;
  --panel:    rgba(8, 12, 28, 0.96);
  --border:   rgba(180, 140, 60, 0.18);
  --border-h: rgba(220, 180, 80, 0.45);

  --gold:     #d4a017;
  --gold-hi:  #f5c842;
  --gold-dim: #8a6510;

  --red:      #c0392b;
  --red-hi:   #e74c3c;

  --text:     #e8ecf5;
  --muted:    #6b7a9c;

  --win-color:  #22c55e;
  --lose-color: #ef4444;
  --draw-color: #f59e0b;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Rajdhani', 'Segoe UI', sans-serif;
  color: var(--text);
}

/* ── Shell (viewport fill, no scroll) ── */
.shell-stage {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(180,120,30,0.07), transparent 55%),
    radial-gradient(ellipse 60% 80% at 20% 100%, rgba(100,30,30,0.09), transparent 50%),
    radial-gradient(ellipse 70% 70% at 80% 50%, rgba(20,30,80,0.12), transparent 60%),
    #04060e;
}

/* ── Phone container ── */
.shell-fit {
  position: relative;
  width: var(--pw);
  height: var(--ph);
  flex: 0 0 auto;
}

.phone {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--pw);
  height: var(--ph);
  margin-left: calc(var(--pw) / -2);
  margin-top: calc(var(--ph) / -2);
  transform-origin: center center;
  border-radius: 28px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(180, 140, 60, 0.22),
    0 0 0 3px rgba(0,0,0,0.9),
    0 24px 80px rgba(0,0,0,0.95),
    inset 0 1px 0 rgba(255,255,255,0.04);
}

/* ── Baize background ── */
.baize {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 90% 70% at 50% 30%, #0c1232 0%, #060918 55%, #03050f 100%),
    repeating-linear-gradient(45deg, transparent 0, transparent 7px, rgba(255,255,255,0.007) 7px, rgba(255,255,255,0.007) 8px),
    repeating-linear-gradient(-45deg, transparent 0, transparent 7px, rgba(255,255,255,0.007) 7px, rgba(255,255,255,0.007) 8px);
}

.baize::after {
  content: '';
  position: absolute;
  top: 0; left: 10%; right: 10%; height: 280px;
  background: radial-gradient(ellipse 60% 100% at 50% 0%, rgba(212,160,23,0.08), transparent 70%);
  pointer-events: none;
}

/* ── Main game UI ── */
.game-ui {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

/* ── HUD ── */
.hud {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  background: linear-gradient(180deg, rgba(0,0,0,0.75) 0%, transparent 100%);
}

.hud-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(8, 14, 34, 0.9);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px 5px 5px;
}

.hud-av {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-dim), var(--gold));
  border: 1px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cinzel', serif;
  font-size: 9px;
  font-weight: 700;
  color: #060910;
  flex-shrink: 0;
  box-shadow: 0 0 8px rgba(212,160,23,0.35);
}

.hud-chip-info { display: flex; flex-direction: column; gap: 1px; }

.hud-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud-name {
  font-family: 'Cinzel', serif;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-timer-wrap,
.hud-count-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: rgba(8,14,34,0.82);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 14px;
}

.hud-timer {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--gold-hi);
  letter-spacing: 0.04em;
  min-width: 44px;
  text-align: center;
}

.hud-count {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.hud-divider {
  flex-shrink: 0;
  height: 1px;
  margin: 0 16px;
  background: linear-gradient(90deg, transparent, var(--gold-dim), var(--gold), var(--gold-dim), transparent);
  opacity: 0.5;
}

/* ── 3-D canvas — fixed height so aspect ratio 390:490 is always preserved ── */
.canvas-area {
  height: var(--canvas-h);
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  contain: layout;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
}

#canvasLoader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-family: 'Cinzel', serif;
  font-size: 13px;
  letter-spacing: 0.12em;
  pointer-events: none;
}

/* ── Status bar ── */
.status-bar {
  flex-shrink: 0;
  padding: 4px 16px;
  text-align: center;
  min-height: 22px;
}

.status-text {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.status-text.status-important {
  color: var(--gold-hi);
  font-weight: 700;
}

/* ── Action bar ── */
.action-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px 20px;
  background: linear-gradient(0deg, rgba(0,0,0,0.88) 55%, transparent);
}

.score-chip {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(8,14,34,0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 16px;
}

.score-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.score-value {
  font-family: 'Cinzel', serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--gold-hi);
  line-height: 1.1;
}

#rollBtn {
  flex: 1;
  border: none;
  border-radius: 16px;
  padding: 16px 18px;
  font-family: 'Cinzel', serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #060910;
  background: linear-gradient(135deg, var(--gold-dim) 0%, var(--gold) 40%, var(--gold-hi) 55%, var(--gold) 75%, var(--gold-dim) 100%);
  background-size: 200%;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.18s ease, box-shadow 0.18s ease;
  box-shadow: 0 4px 20px rgba(212,160,23,0.4), 0 0 0 1px rgba(212,160,23,0.2);
  position: relative;
  overflow: hidden;
  animation: shimmer 2.8s linear infinite;
}

#rollBtn::after {
  content: '';
  position: absolute;
  top: 0; left: -80%; width: 55%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
  animation: sweep 2.6s ease-in-out infinite;
}

#rollBtn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  animation: none;
  box-shadow: none;
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.2);
}

#rollBtn:disabled::after { display: none; }

#rollBtn:not(:disabled):active { transform: translateY(1px); }

/* ── Overlays ── */
.ol {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.38s ease;
  z-index: 50;
}

.ol.on {
  opacity: 1;
  pointer-events: all;
}

/* ── Ready lobby overlay ── */
.ol-ready {
  background: radial-gradient(ellipse 95% 95% at 50% 50%, rgba(6,9,22,0.97), rgba(3,5,12,1) 100%);
  justify-content: center;
  padding: 24px;
}

.ready-card {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px 24px;
  border-radius: 20px;
  background: linear-gradient(160deg, rgba(10,16,38,0.98), rgba(6,10,24,0.99));
  border: 1px solid var(--border-h);
  box-shadow: 0 0 0 1px rgba(212,160,23,0.08), 0 20px 60px rgba(0,0,0,0.6);
  text-align: center;
}

.ready-card::before {
  content: '';
  display: block;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: -28px -24px 0;
  border-radius: 20px 20px 0 0;
}

.ready-eyebrow {
  font-family: 'Cinzel', serif;
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold-dim);
}

.ready-title {
  font-family: 'Cinzel Decorative', cursive;
  font-size: 22px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--gold-hi), var(--gold), var(--gold-dim));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.06em;
}

.ready-subtitle {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

#readyBtn {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 14px;
  font-family: 'Cinzel', serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #060910;
  background: linear-gradient(135deg, var(--gold-dim), var(--gold-hi));
  cursor: pointer;
  transition: transform 0.12s, opacity 0.18s;
  box-shadow: 0 4px 16px rgba(212,160,23,0.35);
}

#readyBtn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.2);
  box-shadow: none;
}

#readyBtn:not(:disabled):active { transform: translateY(1px); }

.ready-hint {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* ── Leaderboard overlay ── */
.ol-lb {
  background:
    radial-gradient(ellipse 90% 60% at 50% 0%, rgba(212,160,23,0.06), transparent 50%),
    linear-gradient(170deg, #060b1c 0%, #040810 55%, #050a18 100%);
  justify-content: flex-start;
  overflow: hidden;
}

.lb-header {
  flex-shrink: 0;
  width: 100%;
  padding: 28px 20px 0;
  text-align: center;
}

.lb-eyebrow {
  font-family: 'Cinzel', serif;
  font-size: 9px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin-bottom: 6px;
}

.lb-title {
  font-family: 'Cinzel Decorative', cursive;
  font-size: 20px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--gold-hi), var(--gold), var(--gold-dim));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.1em;
  margin-bottom: 14px;
}

.lb-divider {
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dim), var(--gold-hi), var(--gold-dim), transparent);
}

/* lb-list: fills remaining space, no overflow on Y (fits 2-6 players easily) */
.lb-list {
  flex: 1;
  width: 100%;
  padding: 12px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

/* ── Leaderboard rows ── */
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  opacity: 0;
  animation: rowUp 0.35s ease forwards;
}

@keyframes rowUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* WIN row */
.lb-row.result-win {
  background: linear-gradient(135deg, rgba(22,60,14,0.97), rgba(12,38,8,0.97));
  border: 1px solid rgba(34,197,94,0.28);
  box-shadow: 0 0 14px rgba(34,197,94,0.06);
}

/* LOSE row */
.lb-row.result-lose {
  background: rgba(255,255,255,0.025);
  border: 1px solid rgba(255,255,255,0.055);
}

/* DRAW row */
.lb-row.result-draw {
  background: linear-gradient(135deg, rgba(60,44,8,0.97), rgba(38,28,5,0.97));
  border: 1px solid rgba(245,158,11,0.28);
  box-shadow: 0 0 14px rgba(245,158,11,0.06);
}

/* highlight yourself */
.lb-row.you-row {
  box-shadow: 0 0 0 1px var(--gold), 0 0 16px rgba(212,160,23,0.18) !important;
}

/* rank number */
.lb-rank {
  font-family: 'Cinzel', serif;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  width: 20px;
  flex-shrink: 0;
  text-align: center;
}

.lb-rank.rank-1 { color: var(--gold-hi); }

/* avatar circle */
.lb-av {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cinzel', serif;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

.result-win .lb-av {
  background: linear-gradient(135deg, #14532d, #16a34a);
  border: 1px solid #22c55e;
  color: #f0fdf4;
}

.result-lose .lb-av {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.28);
}

.result-draw .lb-av {
  background: linear-gradient(135deg, #713f12, #d97706);
  border: 1px solid #f59e0b;
  color: #fefce8;
}

/* player info */
.lb-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lb-name {
  font-family: 'Cinzel', serif;
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-win .lb-name  { color: var(--text); }
.result-lose .lb-name { color: rgba(255,255,255,0.28); }
.result-draw .lb-name { color: var(--text); }

.lb-you-tag {
  font-size: 9px;
  color: var(--gold);
  letter-spacing: 0.1em;
  font-weight: 700;
}

.lb-score {
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* result badge */
.lb-badge {
  flex-shrink: 0;
  padding: 3px 10px;
  border-radius: 999px;
  font-family: 'Cinzel', serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.result-win  .lb-badge { background: rgba(34,197,94,0.15);  color: var(--win-color);  border: 1px solid rgba(34,197,94,0.3); }
.result-lose .lb-badge { background: rgba(239,68,68,0.1);   color: var(--lose-color); border: 1px solid rgba(239,68,68,0.2); }
.result-draw .lb-badge { background: rgba(245,158,11,0.12); color: var(--draw-color); border: 1px solid rgba(245,158,11,0.25); }

/* prize amount */
.lb-prize {
  flex-shrink: 0;
  font-family: 'Cinzel', serif;
  font-size: 13px;
  font-weight: 700;
  text-align: right;
  min-width: 72px;
}

.result-win  .lb-prize { color: var(--gold-hi); }
.result-lose .lb-prize { color: rgba(255,255,255,0.15); }
.result-draw .lb-prize { color: var(--draw-color); }

/* ── Leaderboard footer ── */
.lb-footer {
  flex-shrink: 0;
  width: 100%;
  padding: 10px 20px 28px;
  border-top: 1px solid rgba(255,255,255,0.05);
  background: linear-gradient(0deg, rgba(0,0,0,0.5), transparent);
  display: flex;
  justify-content: center;
  align-items: center;
}

.lb-pool-block { text-align: center; }

.lb-pool-label {
  font-family: 'Cinzel', serif;
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.lb-pool-value {
  font-family: 'Cinzel Decorative', cursive;
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--gold-hi), var(--gold), var(--gold-dim));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.04em;
}

/* ── Utilities ── */
.hidden { display: none !important; }

/* ── Animations ── */
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

@keyframes sweep {
  0%   { left: -80%; }
  100% { left: 160%; }
}
