:root {
  --bg: #f4ecdf; --panel: #fffaf2; --ink: #2b211a; --muted: #85766a; --line: #e6d9c6;
  --accent: #c2410c; --accent-ink: #fff; --soft: #efe3d0; --gold: #b7791f; --good: #2f9e44; --bad: #e03131;
  --felt: #2f6b4a; --felt2: #275a3e; --wood: #7a4b2a;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15110d; --panel: #221b15; --ink: #f3ebe0; --muted: #a8988a; --line: #3a2f26; --accent: #fb7d3c; --accent-ink: #1b0d04; --soft: #33281f; --gold: #f2b84b; --felt: #245239; --felt2: #1d432f; --wood: #5a371f; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
body { font: 17px/1.4 -apple-system, system-ui, sans-serif; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
h1, h2 { margin: 0; }
h2 { font-size: 23px; }
p { margin: 0; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.screen.run { top: calc(54px + env(safe-area-inset-top)); }
.inner {
  max-width: 520px; margin: 0 auto; display: grid; gap: 14px; align-content: start;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.run .inner { padding-top: 14px; }
.menu .title { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 10px; }
.menu .logo { width: 64px; height: 64px; border-radius: 15px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.menu h1 { font-size: 40px; font-weight: 900; letter-spacing: -.01em; }
.tagline { text-align: center; color: var(--muted); margin-top: -4px; }
.stack { display: grid; gap: 10px; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats3 div { background: var(--panel); border-radius: 14px; padding: 10px 4px; text-align: center; }
.stats3 b { display: block; font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats3 span { font-size: 13px; color: var(--muted); }
.card { background: var(--panel); border-radius: 16px; padding: 12px 14px; display: grid; gap: 8px; }
.card summary { font-weight: 700; min-height: 28px; cursor: pointer; }
.card p { color: var(--muted); font-size: 15px; margin-top: 6px; }
.settings { padding: 4px 14px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.account { display: grid; gap: 6px; justify-items: center; }
.hint { display: flex; align-items: center; gap: 8px; background: var(--soft); border-radius: 14px; padding: 6px 4px 6px 14px; font-size: 15px; }
.hint span { flex: 1; }
.scoring { width: 100%; border-collapse: collapse; font-size: 15px; margin-top: 6px; }
.scoring td { padding: 6px 2px; border-top: 1px solid var(--line); }
.scoring td:last-child { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.scoring .dice-row { display: flex; gap: 3px; }
.codex { display: grid; gap: 8px; }
.codex .entry { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.codex .entry b { display: block; font-size: 15px; }
.codex .entry span { color: var(--muted); }
.codex .unknown { opacity: .45; }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: 14px; min-height: 48px; padding: 6px 14px; font-weight: 700; font-size: 16px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.soft { background: var(--soft); color: var(--ink); }
.btn.gold { background: #f59f00; color: #2b1a00; }
.btn:disabled { opacity: .4; }
.btn.big { min-height: 56px; font-size: 19px; width: 100%; }
.btn small { display: block; font-size: 13px; font-weight: 600; opacity: .8; }
.icon-btn { border: 0; background: none; min-width: 44px; min-height: 44px; font-size: 20px; color: var(--muted); }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; min-height: 44px; }
.center-btn { display: block; margin: 0 auto; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg); border-radius: 12px; padding: 3px; }
.seg button { border: 0; border-radius: 10px; background: none; min-height: 40px; padding: 0 12px; font-size: 15px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.round { width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--soft); font-size: 26px; font-weight: 700; }

/* ---------- run header ---------- */
.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: max(4px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 4px max(4px, env(safe-area-inset-left));
  min-height: calc(54px + env(safe-area-inset-top)); background: var(--panel); box-shadow: 0 1px 0 var(--line);
}
.where { flex: 1; display: grid; line-height: 1.15; min-width: 0; }
.where b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.steps { display: flex; gap: 4px; margin-top: 3px; }
.steps i { width: 14px; height: 6px; border-radius: 3px; background: var(--line); }
.steps i.done { background: var(--good); }
.steps i.now { background: var(--accent); }
.steps i.boss { width: 20px; }
.coins { display: flex; align-items: center; gap: 4px; font-size: 18px; }
.coins b { font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
.coins.pop { animation: pop .45s; }
@keyframes pop { 30% { transform: scale(1.3); } }
.mini-trinkets { display: flex; gap: 2px; font-size: 18px; }
.mini-trinkets button { border: 0; background: none; padding: 0 2px; font-size: 20px; min-width: 30px; min-height: 36px; }

/* ---------- road ---------- */
.choices { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: center; gap: 12px; text-align: left; border: 0; border-radius: 18px; padding: 12px 14px; min-height: 84px;
  background: var(--panel); box-shadow: inset 0 0 0 2px var(--line); animation: rise .3s ease-out backwards;
}
.choice:nth-child(2) { animation-delay: .05s; } .choice:nth-child(3) { animation-delay: .1s; }
.choice.champion { box-shadow: inset 0 0 0 3px #f59f00; background: linear-gradient(135deg, var(--panel), rgba(245, 159, 0, .15)); }
.choice .face { font-size: 40px; width: 56px; text-align: center; flex: none; }
.choice b { display: block; font-size: 18px; }
.choice span { display: block; font-size: 14px; color: var(--muted); }
.choice .tag { display: inline-block; font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 8px; margin-top: 4px; background: var(--soft); color: var(--ink); }
.choice .tag.t0 { background: #d3f9d8; color: #2b8a3e; } .choice .tag.t1 { background: #fff3bf; color: #8a6100; } .choice .tag.t2 { background: #ffe3e3; color: #c92a2a; }
@media (prefers-color-scheme: dark) { .choice .tag.t0 { background: #1f3b26; color: #8ce99a; } .choice .tag.t1 { background: #40350a; color: #ffe066; } .choice .tag.t2 { background: #4a1a1a; color: #ffa8a8; } }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }
.bag { display: flex; flex-wrap: wrap; gap: 8px; }
.bag.pick .die { --s: 46px; }
.bag.small-dice .die { --s: 32px; }

/* ---------- prep ---------- */
.opp-card { display: flex; gap: 14px; align-items: center; }
.face { font-size: 54px; line-height: 1; }
.face.big { font-size: 84px; }
.quote { font-style: italic; color: var(--muted); margin-top: 4px; }
.tr-list { display: flex; gap: 6px; flex-wrap: wrap; }
.tr-chip { display: inline-flex; gap: 4px; align-items: center; background: var(--soft); border: 0; border-radius: 10px; padding: 4px 9px; font-size: 13px; font-weight: 700; }
.bet { display: flex; align-items: center; justify-content: center; gap: 22px; }
.bet b { font-size: 34px; font-weight: 900; color: var(--gold); min-width: 90px; text-align: center; font-variant-numeric: tabular-nums; }
.champ-note { background: #fff3bf; color: #6b4e00; border-radius: 14px; padding: 10px 14px; font-weight: 600; text-align: center; }
@media (prefers-color-scheme: dark) { .champ-note { background: #40350a; color: #ffe066; } }
.die.picked { box-shadow: 0 0 0 3px var(--accent), 0 3px 0 rgba(0,0,0,.25); }
.die.unpicked { opacity: .45; }

/* ---------- duel ---------- */
.duel { display: flex; flex-direction: column; overflow: hidden; }
.players {
  display: grid; gap: 6px; background: var(--panel); box-shadow: 0 1px 0 var(--line);
  padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
}
.duelhead { display: flex; align-items: center; gap: 8px; margin: -4px 0 -2px -8px; }
.duelhead #d-where { flex: 1; }
.player { position: relative; display: flex; align-items: center; gap: 10px; border-radius: 14px; padding: 4px 6px; }
.player.active { background: var(--soft); }
.player .face { font-size: 34px; width: 44px; text-align: center; }
.pinfo { flex: 1; display: grid; gap: 4px; }
.pname { display: flex; gap: 8px; align-items: center; font-size: 15px; }
.pname .mini-trinkets { font-size: 14px; }
.meter { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; border-radius: 5px; transition: width .6s ease-out; }
.opp .meter i { background: #e8590c; } .you .meter i { background: var(--good); }
.pscore { font-size: 22px; font-weight: 900; min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
.pscore.bump { animation: pop .5s; }
.bubble {
  position: absolute; right: 70px; top: 100%; z-index: 3; margin-top: -2px; max-width: 70%;
  background: #fff; color: #222; border-radius: 14px; padding: 7px 12px; font-size: 15px; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.25);
  animation: rise .2s ease-out;
}
.bubble::before { content: ''; position: absolute; top: -6px; right: 22px; border: 7px solid transparent; border-top: 0; border-bottom-color: #fff; }

.table {
  position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 12px 14px;
  background: radial-gradient(ellipse at 50% 40%, var(--felt), var(--felt2)); box-shadow: inset 0 0 0 6px var(--wood), inset 0 0 40px rgba(0,0,0,.35);
  margin: 10px max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); border-radius: 22px;
}
.table.shake { animation: shake .4s; }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
.turnline { display: flex; justify-content: space-between; align-items: baseline; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.turnline span { font-weight: 700; font-size: 15px; opacity: .9; }
.turnline b { font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; }
.turnline b.bump { animation: pop .4s; }
.kept { display: flex; flex-wrap: wrap; gap: 6px; min-height: 40px; align-items: center; }
.kept .die { --s: 36px; }
.kept .group { display: flex; gap: 3px; padding: 3px; border-radius: 10px; background: rgba(0,0,0,.18); }
.tray { flex: 1; display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 14px; }
.tray .die { --s: min(17vw, 76px); }
.splash {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 2;
  font-size: 46px; font-weight: 900; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.35), 0 0 24px rgba(0,0,0,.4);
  animation: splash 1s ease-out forwards;
}
.splash.bust { color: #ff8787; } .splash.hot { color: #ffd43b; } .splash.win { color: #8ce99a; }
.splash small { display: block; font-size: 18px; text-align: center; }
@keyframes splash { 0% { transform: scale(.5); opacity: 0; } 15% { transform: scale(1.1); opacity: 1; } 25% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
.float { position: absolute; z-index: 2; color: #ffe066; font-weight: 900; font-size: 24px; text-shadow: 0 2px 0 rgba(0,0,0,.4); pointer-events: none; animation: floatup .9s ease-out forwards; }
@keyframes floatup { to { transform: translateY(-50px); opacity: 0; } }

.controls { display: grid; gap: 8px; padding: 10px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
.info { text-align: center; min-height: 22px; font-size: 15px; color: var(--muted); }
.info b { color: var(--ink); }
.info .bad { color: var(--bad); font-weight: 700; }
.tools { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.tools:empty { display: none; }
.tool { border: 0; border-radius: 12px; background: var(--soft); min-height: 40px; padding: 0 12px; font-size: 14px; font-weight: 700; }
.tool.on { background: var(--accent); color: var(--accent-ink); }
.controls .btn.big { min-height: 62px; }
.controls .btn small { font-size: 13px; }

/* ---------- dice ---------- */
.die {
  --s: 56px; --pip: #2b1d14; position: relative; width: var(--s); height: var(--s); border-radius: 22%; padding: calc(var(--s) * .13); border: 0;
  background: linear-gradient(160deg, #fffdf8, #efe6d6); box-shadow: inset 0 -4px 0 rgba(0,0,0,.1), 0 3px 0 rgba(0,0,0,.28);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); flex: none; transition: transform .15s, box-shadow .15s;
}
.die i { width: 72%; height: 72%; border-radius: 50%; background: var(--pip); place-self: center; visibility: hidden; }
.die i.on { visibility: visible; }
.die .star { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--s) * .55); color: #f08c00; }
.die.lucky { background: linear-gradient(160deg, #ebfbee, #c3fae8); --pip: #2b8a3e; }
.die.odd { background: linear-gradient(160deg, #e7f5ff, #c5e0fb); --pip: #1864ab; }
.die.even { background: linear-gradient(160deg, #f3f0ff, #ddd2fb); --pip: #5f3dc4; }
.die.lead { background: linear-gradient(160deg, #6c757d, #3f454a); --pip: #f8f9fa; }
.die.wobbly { background: linear-gradient(160deg, #fff0f6, #fcc2d7); --pip: #a61e4d; }
.die.devil { background: linear-gradient(160deg, #e03131, #9b1c1c); --pip: #fff5f5; }
.die.loaded { background: linear-gradient(160deg, #f4e6d4, #ddc3a3); --pip: #5c3a1e; }
.die.wild { background: conic-gradient(from 30deg, #ffc9c9, #ffec99, #b2f2bb, #a5d8ff, #d0bfff, #ffc9c9); --pip: #343a40; }
.die.gold { background: linear-gradient(160deg, #fff3bf, #f2b84b); --pip: #5c3d00; }
.die.glass { background: linear-gradient(160deg, rgba(231, 245, 255, .75), rgba(165, 216, 255, .45)); --pip: #1c7ed6; box-shadow: inset 0 0 0 2px rgba(255,255,255,.8), 0 3px 0 rgba(0,0,0,.2); }
.die.twin { background: linear-gradient(135deg, #fffdf8 50%, #ffd8a8 50%); --pip: #d9480f; }
.die.twin::after { content: '×2'; position: absolute; right: 4%; bottom: 2%; font-size: calc(var(--s) * .2); font-weight: 900; color: #d9480f; }
.die.blank i { visibility: hidden !important; }

.tray .die.fresh { cursor: pointer; }
.tray .die.sel { transform: translateY(-10px); box-shadow: 0 0 0 4px #ffd43b, 0 10px 14px rgba(0,0,0,.35); }
.tray .die.idle { opacity: .5; }
.tray .die.rolling { animation: tumble .5s ease-out; }
@keyframes tumble { 0% { transform: translate(var(--tx, 0), -40px) rotate(-200deg) scale(.7); opacity: .3; } 60% { transform: translate(0, 4px) rotate(15deg); opacity: 1; } 100% { transform: none; } }
.die.nudged { animation: pop .4s; }
.die.cracked { animation: crack .8s; }
@keyframes crack { 30% { transform: rotate(-8deg); filter: brightness(1.5); } 100% { opacity: .2; transform: scale(.6) rotate(25deg); } }

/* ---------- offers (result, events) ---------- */
.offers { display: grid; gap: 8px; }
.offer {
  display: flex; align-items: center; gap: 12px; text-align: left; border: 0; border-radius: 14px; padding: 10px 12px; min-height: 64px;
  background: var(--soft); animation: rise .3s ease-out backwards;
}
.offer .em { font-size: 30px; width: 46px; text-align: center; flex: none; }
.offer .die { --s: 42px; }
.offer > div { flex: 1; }
.offer b { display: block; font-size: 16px; }
.offer span { display: block; font-size: 14px; color: var(--muted); line-height: 1.3; }
.offer .price { font-weight: 900; color: var(--gold); flex: none; }
.offer.sold { opacity: .4; }
.offer.no .price { color: var(--bad); }
.coins-big { font-size: 28px; font-weight: 900; color: var(--gold); }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 10; }
.sheet-wrap { background: rgba(0, 0, 0, .4); display: flex; align-items: flex-end; }
.sheet {
  width: 100%; max-width: 560px; margin: 0 auto; background: var(--panel); border-radius: 22px 22px 0 0; display: grid; gap: 12px;
  padding: 18px max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  animation: rise .25s ease-out;
}
.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20; max-width: calc(100% - 32px);
  background: rgba(30, 22, 16, .94); color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 15px; text-align: center; pointer-events: none;
}
