:root {
  --blue: #1E64B4;
  --red: #D9383A;
  --green: #2E9E5B;
  --orange: #F58220;
  --bg: #1b120c;
  --panel: #2a1c13;
  --cream: #fbefd9;
  --gold: #e9b53b;
  --ink: #2b1a10;
  --cur: var(--gold);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(circle at 50% 0%, #4a2c17 0%, var(--bg) 60%) fixed var(--bg);
  color: var(--cream);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#app { height: 100dvh; display: flex; justify-content: center; overflow: hidden; }
.screen {
  width: 100%;
  max-width: 780px;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.logo { margin: 0; font-size: 2.8rem; font-weight: 900; letter-spacing: 0.02em; }
.logo span { color: var(--gold); }
.logo.small { font-size: 1.3rem; white-space: nowrap; }
.tagline { margin: 0; opacity: 0.8; text-align: center; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 700; color: var(--cream);
  background: var(--panel); border: 2px solid #5a3d27; border-radius: 12px;
  padding: 12px 22px; min-width: 220px; cursor: pointer;
}
.btn:hover { border-color: var(--gold); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn.small { min-width: 0; padding: 8px 10px; font-size: 0.8rem; white-space: nowrap; }
.icon-btn {
  font: inherit; font-size: 1.05rem; font-weight: 800; color: var(--cream);
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
  background: var(--panel); border: 2px solid #5a3d27;
}
.icon-btn[aria-pressed="false"] { opacity: 0.45; }
#view[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); }
button:focus-visible { outline: 3px solid var(--cream); outline-offset: 2px; }

/* ---------- setup ---------- */
#setup { justify-content: center; overflow-y: auto; }
.seats { width: 100%; max-width: 420px; display: grid; gap: 10px; margin: 8px 0; }
.seat {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border-radius: 14px; padding: 10px 12px;
  border-left: 8px solid var(--c);
}
.seat-name { font-weight: 800; flex: 1; }
.seg { display: flex; border-radius: 10px; overflow: hidden; border: 2px solid #5a3d27; }
.seg button {
  font: inherit; font-size: 0.85rem; font-weight: 700; color: var(--cream);
  background: transparent; border: 0; padding: 9px 11px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--c); color: #fff; }
.setup-error { margin: 0; min-height: 1.2em; color: #ff9d8a; font-weight: 600; }

/* ---------- game chrome ---------- */
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }

.chips { width: 100%; display: flex; gap: 6px; }
.chip {
  flex: 1; min-width: 0; padding: 6px 8px; border-radius: 10px;
  background: var(--panel); border: 2px solid transparent; border-top: 5px solid var(--c);
  opacity: 0.6; transition: opacity 0.2s, transform 0.2s;
}
.chip.active { opacity: 1; border-color: var(--c); transform: translateY(-2px); }
.chip-name { font-weight: 800; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-name small { font-weight: 600; opacity: 0.7; }
.chip-meta { display: flex; align-items: center; gap: 4px; font-size: 0.78rem; font-weight: 800; color: var(--gold); margin-top: 2px; }
.coin-ico {
  width: 12px; height: 12px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 35%, #fff3b0, #c9961a); border: 1px solid #7a5608;
}
.chip-meta .toks { margin-left: auto; display: flex; gap: 3px; }
.toks i { width: 9px; height: 9px; border-radius: 2px; border: 2px solid var(--c); }
.toks i.out { background: color-mix(in srgb, var(--c) 45%, transparent); }
.toks i.home { background: var(--c); }
.count-row { display: flex; align-items: center; gap: 12px; font-weight: 800; margin-bottom: 4px; }
.count-row .seg button[aria-pressed="true"] { background: var(--gold); color: var(--ink); }
.bar { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.12); margin-top: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--c); transition: width 0.4s; }

/* ---------- 3D scene: fills whatever space is left; view3d.js fits the board into it ---------- */
.scene { flex: 1; min-height: 0; width: 100%; position: relative; }
.scene canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; cursor: pointer; }

.controls { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.msg { margin: 0; min-height: 1.3em; font-weight: 700; text-align: center; }
.btn.roll {
  font-size: 1.1rem; padding: 14px 22px; min-width: 240px;
  background: var(--cur); border-color: var(--cur); color: #fff;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.45);
  transition: background 0.3s, border-color 0.3s, opacity 0.2s;
}
.btn.roll:disabled { opacity: 0.35; cursor: default; box-shadow: none; }
.btn.roll:not(:disabled) { animation: bob 0.9s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px); } }

/* ---------- dialogs ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7);
  display: grid; place-items: center; padding: 16px; z-index: 20;
}
.dialog {
  background: var(--panel); border: 3px solid var(--gold); border-radius: 18px;
  padding: 22px; width: 100%; max-width: 360px; max-height: 90dvh;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.dialog.rules { max-width: 480px; }
.rules-body { overflow-y: auto; font-size: 0.92rem; line-height: 1.45; user-select: text; }
.rules-body p { margin: 0 0 8px; }
.dialog h2 { margin: 0; font-size: 1.6rem; }
.ranks { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; gap: 6px; }
.ranks li {
  display: flex; gap: 10px; align-items: center; font-weight: 700;
  padding: 8px 12px; border-radius: 10px; background: rgba(0, 0, 0, 0.25); border-left: 8px solid var(--c);
}
.ranks .grow { flex: 1; }

@media (max-width: 520px) {
  .logo.small { font-size: 1.05rem; }
  #view { display: none; }
  .chip { padding: 5px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn.roll:not(:disabled) { animation: none; }
}
