/* Dice Ladder — UI. Mobile-first; the banner band is reserved with
   --banner-h by ads.js (an AdMob banner is a native overlay and fires no
   resize, so the layout must already own that space). */
:root {
  --bg: #0e1118;
  --bg-2: #151a24;
  --card: #1a2030;
  --line: #2a3244;
  --ink: #eef1f7;
  --muted: #8d96ab;
  --accent: #f2b544;
  --accent-ink: #23190a;
  --good: #4ecb8d;
  --bad: #e8685d;
  --banner-h: 0px;
  --radius: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none; touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
}
.app {
  display: flex; flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           calc(var(--banner-h) + env(safe-area-inset-bottom)) env(safe-area-inset-left);
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 4px; flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
  gap: 3px; padding: 5px; transform: rotate(-6deg);
}
.brand-mark .pip { background: var(--accent-ink); border-radius: 50%; }
.brand-name { font-weight: 700; letter-spacing: .2px; font-size: 16px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--muted); font-size: 15px; font-weight: 700;
}
.icon-btn:active { transform: scale(.94); }

/* ---------- modes ---------- */
.modes {
  display: flex; gap: 6px; margin: 6px 16px 0; padding: 4px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  flex: 0 0 auto;
}
.mode {
  flex: 1; padding: 8px 0; border: 0; border-radius: 9px; background: transparent;
  color: var(--muted); font: inherit; font-size: 13px; font-weight: 600;
}
.mode.is-on { background: var(--card); color: var(--ink); box-shadow: 0 1px 0 rgba(255,255,255,.05) inset; }

/* ---------- hud ---------- */
.hud {
  display: grid; grid-template-columns: 1.2fr 1fr 0.8fr; gap: 8px;
  margin: 10px 16px 0; flex: 0 0 auto;
}
.hud-cell {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 13px;
  padding: 9px 11px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.hud-label { font-size: 10px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.hud-value { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.15; }
.hud-turn { color: var(--accent); }
.goal-line { margin: 8px 16px 0; font-size: 12px; color: var(--muted); flex: 0 0 auto; }

/* ---------- board ---------- */
.board {
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
  justify-content: center; gap: 14px; padding: 6px 16px;
}
.dice {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px; max-width: 420px; width: 100%; margin: 0 auto;
  position: relative;
}
.die {
  position: relative; aspect-ratio: 1 / 1; border-radius: 18px;
  background: linear-gradient(160deg, #f7f8fb, #dfe3ec 68%, #ccd2df);
  box-shadow: 0 6px 0 #a7aec0, 0 10px 18px rgba(0,0,0,.35);
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  padding: 14%; gap: 4%; border: 0; transition: transform .12s ease, box-shadow .12s ease;
}
.die i { border-radius: 50%; background: transparent; }
.die i.on { background: #18202e; }
.die.st-empty { background: linear-gradient(160deg, #1d2434, #171d29); box-shadow: 0 6px 0 #10151f, 0 8px 14px rgba(0,0,0,.3); }
.die.st-empty i.on { background: transparent; }
.die.st-empty::after {
  content: "·"; position: absolute; inset: 0; display: grid; place-items: center;
  color: #333d52; font-size: 26px;
}
.die.st-spent { opacity: .28; transform: scale(.9); box-shadow: none; }
.die.st-live:active { transform: translateY(2px) scale(.98); box-shadow: 0 4px 0 #a7aec0; }
.die.st-sel {
  background: linear-gradient(160deg, #ffe3a6, #f2b544 70%, #e0a233);
  box-shadow: 0 6px 0 #a9761c, 0 0 0 3px rgba(242,181,68,.35), 0 10px 18px rgba(0,0,0,.35);
  transform: translateY(-4px);
}
.die.st-sel i.on { background: #23190a; }
.die.rolling { animation: shake .38s ease; }
@keyframes shake {
  0% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-6px) rotate(-5deg); }
  55% { transform: translateY(1px) rotate(4deg); }
  100% { transform: translateY(0) rotate(0); }
}

/* ---------- 3D dice (three.js canvas over the same slots) ----------
   The buttons stay exactly where they were: they are the hit areas and the
   accessible names. Everything visible is drawn on the canvas, so the CSS
   dice are blanked — but the WebGL canvas can fail on an old WebView, and
   then .is-3d is never set and the CSS dice below remain the renderer. */
.dice.is-3d .die {
  background: none; box-shadow: none; border: 0;
  transform: none; transition: none; animation: none;
}
.dice.is-3d .die i { display: none; }
.dice.is-3d .die.st-empty::after { display: none; }
.dice.is-3d .die.st-spent { opacity: 1; transform: none; }
.dice.is-3d .die.st-sel { background: none; box-shadow: none; transform: none; }
.dice.is-3d .die.st-live:active { transform: none; box-shadow: none; }
.dice.is-3d .die:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 16px;
}
.status {
  margin: 0; text-align: center; font-size: 13px; color: var(--muted);
  min-height: 18px; font-variant-numeric: tabular-nums;
}
.status.is-good { color: var(--good); }
.status.is-bad { color: var(--bad); }

/* ---------- actions ---------- */
.actions {
  display: grid; grid-template-columns: 76px 1fr 96px; gap: 10px;
  padding: 8px 16px 14px; flex: 0 0 auto;
}
.btn {
  border: 0; border-radius: 14px; font: inherit; font-weight: 700; font-size: 15px;
  padding: 15px 10px; color: var(--ink); background: var(--card);
  transition: transform .1s ease, opacity .15s ease;
}
.btn:active:not(:disabled) { transform: translateY(2px); }
.btn:disabled { opacity: .38; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-bank { background: var(--card); border: 1px solid var(--line); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.btn.wide { width: 100%; margin-top: 14px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--banner-h) + 96px);
  transform: translateX(-50%); background: #232b3d; color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px; padding: 10px 18px;
  font-size: 13px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  z-index: 50; white-space: nowrap;
}
.toast.is-bad { background: #3a1f1f; border-color: #5b2d2d; color: #ffc9c3; }
.toast.is-good { background: #16342a; border-color: #24503f; color: #b9f3d3; }

/* ---------- sheets ---------- */
.sheet {
  position: fixed; inset: 0; background: rgba(6, 9, 14, .72);
  display: flex; align-items: flex-end; justify-content: center; z-index: 60;
  padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom));
  backdrop-filter: blur(3px);
}
.sheet[hidden] { display: none; }
.sheet-card {
  width: 100%; max-width: 460px; max-height: 86vh; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 22px;
  padding: 20px; animation: rise .22s ease;
  overscroll-behavior: contain;
}
/* The rules are taller than a 640 px viewport; the only way out must stay on
   screen, so the primary button is a sticky footer inside the scroll box. */
.sheet-card > .btn-primary:last-child {
  position: sticky; bottom: calc(-20px + env(safe-area-inset-bottom));
  margin: 14px -20px calc(-20px + env(safe-area-inset-bottom));
  width: calc(100% + 40px); border-radius: 0 0 21px 21px;
  padding: 15px 20px 17px;
  border-top: 1px solid var(--line);
}
@keyframes rise { from { transform: translateY(18px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-card h2 { margin: 0 0 8px; font-size: 20px; }
.sheet-card h3 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.sheet-card p { margin: 0 0 10px; font-size: 14px; line-height: 1.5; color: #c6cddb; }
.rules { width: 100%; border-collapse: collapse; font-size: 13px; }
.rules td { padding: 7px 0; border-bottom: 1px solid var(--line); color: #c6cddb; }
.rules td:last-child { text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.stats { color: var(--muted) !important; font-size: 12.5px !important; }
.fine { color: var(--muted) !important; font-size: 11.5px !important; }
.fine a { color: var(--accent); }
.over-score {
  font-size: 46px; font-weight: 800; text-align: center; color: var(--accent);
  margin: 6px 0 2px !important; font-variant-numeric: tabular-nums;
}
.over-sub { text-align: center; color: var(--muted) !important; margin-bottom: 4px !important; }

@media (min-height: 760px) { .dice { gap: 14px; } }
@media (max-width: 360px) { .hud-value { font-size: 19px; } .actions { grid-template-columns: 64px 1fr 84px; } }
