:root {
  --bg: #efe6d6; --panel: #fbf6ec; --ink: #2a2230; --muted: #7d7286; --line: #e0d4c2;
  --accent: #7c3aed; --accent-ink: #fff; --soft: #e9dfcf; --gold: #b7791f; --good: #2f9e44; --bad: #e03131;
  --atk: #e8590c; --def: #1c7ed6; --heal: #2f9e44; --dice: #9c36b5; --util: #e0a100;
  --stone: #3b3346; --stone2: #2a2433;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15121b; --panel: #221d2b; --ink: #f1ecf7; --muted: #a59bb3; --line: #382f45; --accent: #a78bfa; --accent-ink: #160e26; --soft: #2f2839; --gold: #f2b84b; }
}
* { 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, p { margin: 0; }
h2 { font-size: 22px; }

/* ---------- 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; }
.title { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 10px; }
.logo { width: 64px; height: 64px; border-radius: 15px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.title h1 { font-size: 34px; font-weight: 900; }
.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; }
.bestiary { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.beast { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.beast .face { font-size: 30px; }
.beast.unknown { opacity: .4; }

/* ---------- 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; }

/* ---------- run header ---------- */
.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: max(4px, env(safe-area-inset-top)) max(10px, 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; }
.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; }
.hpmini, .coins { display: flex; align-items: center; gap: 4px; font-size: 17px; font-variant-numeric: tabular-nums; }
.hpmini b { font-weight: 800; }
.coins b { font-weight: 900; color: var(--gold); }
.coins.pop { animation: pop .45s; }
@keyframes pop { 30% { transform: scale(1.3); } }

/* ---------- map ---------- */
.lvl { display: flex; align-items: center; gap: 10px; }
.lvl b { font-size: 16px; white-space: nowrap; }
.xpbar { flex: 1; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.xpbar i { display: block; height: 100%; background: var(--accent); }
.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: 80px;
  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.boss { box-shadow: inset 0 0 0 3px var(--bad); }
.choice .face { font-size: 40px; width: 52px; text-align: center; flex: none; }
.choice b { display: block; font-size: 18px; }
.choice span { display: block; font-size: 14px; color: var(--muted); }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }

/* ---------- cards ---------- */
.cards-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.gcard {
  --k: var(--atk); position: relative; border: 0; border-radius: 13px; padding: 6px 6px 5px; min-height: 96px; text-align: center;
  display: grid; grid-template-rows: auto 1fr auto; justify-items: center; gap: 3px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--k) 22%, var(--panel)), var(--panel) 70%);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--k) 70%, transparent), 0 2px 0 rgba(0,0,0,.15);
  transition: transform .15s, opacity .15s, box-shadow .15s;
}
.gcard.k-def { --k: var(--def); } .gcard.k-heal { --k: var(--heal); } .gcard.k-dice { --k: var(--dice); } .gcard.k-util { --k: var(--util); }
.gcard .cname { font-size: 13px; font-weight: 800; line-height: 1.1; }
.gcard .plus { color: var(--good); margin-left: 2px; }
.gcard .slots { display: flex; gap: 4px; align-items: center; }
.gcard .slot {
  width: 34px; height: 34px; border-radius: 9px; border: 2px dashed color-mix(in srgb, var(--k) 75%, transparent);
  display: grid; place-items: center; font-size: 12px; font-weight: 900; color: var(--k); background: rgba(255,255,255,.35);
}
@media (prefers-color-scheme: dark) { .gcard .slot { background: rgba(0,0,0,.2); } }
.gcard .slot .die { --s: 30px; }
.gcard .cfx { font-size: 12.5px; line-height: 1.2; font-weight: 600; }
.gcard .cuses { position: absolute; top: 4px; right: 6px; font-size: 11px; font-weight: 800; color: var(--muted); }
.gcard.spent { opacity: .35; }
.gcard.off { opacity: .4; filter: grayscale(.8); }
.gcard.off::after { content: '⚡'; position: absolute; top: 2px; left: 6px; font-size: 16px; }
.gcard.fit { transform: translateY(-3px); box-shadow: inset 0 0 0 3px #ffd43b, 0 0 14px rgba(255, 212, 59, .7); }
.gcard.nofit { opacity: .4; }
.gcard.flash { animation: cardflash .45s; }
@keyframes cardflash { 30% { transform: scale(1.08); box-shadow: inset 0 0 0 3px #fff, 0 0 22px var(--k); } }
.cards-grid.small .gcard { min-height: 84px; }
.cards-grid.small .gcard .slot { width: 28px; height: 28px; }
.cards-row { display: flex; gap: 6px; justify-content: center; }
.cards-row .gcard { width: 96px; min-height: 84px; }
.cards-row .gcard .slot { width: 28px; height: 28px; }

/* ---------- fight ---------- */
.fight { display: flex; flex-direction: column; overflow: hidden; background: radial-gradient(ellipse at 50% 35%, var(--stone), var(--stone2)); color: #f1ecf7; }
.fight .muted { color: #b9aec8; }
.foe { padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 4px max(10px, env(safe-area-inset-left)); display: grid; gap: 6px; }
.foe-head { display: flex; align-items: center; gap: 8px; }
.foe-head .icon-btn { color: #b9aec8; margin-left: -6px; }
.foe-head .face { font-size: 48px; width: 60px; text-align: center; }
.foe-head .face.hurt { animation: hurt .35s; }
@keyframes hurt { 20% { transform: translateX(-6px) rotate(-6deg); filter: brightness(2) saturate(0); } 50% { transform: translateX(5px) rotate(4deg); } }
.who { flex: 1; display: grid; gap: 4px; }
.who b { font-size: 17px; }
.hpbar { position: relative; height: 18px; border-radius: 9px; background: rgba(0,0,0,.4); overflow: hidden; }
.hpbar i { position: absolute; inset: 0 auto 0 0; width: 100%; background: linear-gradient(90deg, #e03131, #ff6b6b); transition: width .35s ease-out; }
.you .hpbar i { background: linear-gradient(90deg, #2f9e44, #69db7c); }
.hpbar span { position: relative; display: block; text-align: center; font-size: 12px; font-weight: 800; line-height: 18px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.status { display: flex; gap: 4px; flex-wrap: wrap; min-height: 22px; }
.chip { display: inline-flex; align-items: center; gap: 3px; border-radius: 10px; padding: 1px 8px; font-size: 13px; font-weight: 800; background: rgba(255,255,255,.12); }
.chip.shield { background: rgba(28, 126, 214, .35); } .chip.poison { background: rgba(47, 158, 68, .4); } .chip.weak { background: rgba(232, 89, 12, .4); }
.chip.frozen { background: rgba(116, 192, 252, .4); } .chip.shocked { background: rgba(250, 176, 5, .4); }
.chip.bump { animation: pop .4s; }
.foe-dice { display: flex; gap: 8px; justify-content: center; min-height: 40px; perspective: 600px; }
.foe-dice .cube3, .foe-dice .bigdie { --s: 36px; }
.fight .gcard { color: #f1ecf7; background: linear-gradient(180deg, color-mix(in srgb, var(--k) 35%, #2a2433), #2a2433 75%); }
.fight .gcard .slot { background: rgba(0,0,0,.25); }
.arena { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; }
.tray { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-content: center; perspective: 900px; padding: 8px; max-width: 420px; }
.tray .cube3, .tray .bigdie { --s: min(15vw, 62px); }
.turnbanner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3; pointer-events: none;
  font-size: 30px; font-weight: 900; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.4), 0 0 20px rgba(0,0,0,.5); animation: banner 1.1s ease-out forwards; white-space: nowrap;
}
.turnbanner.foe { color: #ff8787; } .turnbanner.win { color: #8ce99a; font-size: 40px; } .turnbanner.lose { color: #ff6b6b; font-size: 40px; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.6); } 18% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); } 30% { transform: translate(-50%, -50%) scale(1); } 75% { opacity: 1; } 100% { opacity: 0; } }
.you { padding: 6px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); display: grid; gap: 7px; background: rgba(0,0,0,.18); }
.you-head { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.you-foot { display: flex; gap: 10px; align-items: center; }
.you-foot .info { flex: 1; font-size: 14px; color: #b9aec8; line-height: 1.25; }
.you-foot .btn { min-width: 128px; }
.you.hurt { animation: flashred .4s; }
@keyframes flashred { 30% { background: rgba(224, 49, 49, .45); } }

/* dice: tap one, it lifts; big merged dice are flat gold tiles with their number */
.cube3.picked { transform: translateY(-10px); }
.cube3.picked .face { box-shadow: inset 0 0 0 4px #ffd43b, 0 0 14px #ffd43b; }
.bigdie {
  --s: 56px; width: var(--s); height: var(--s); border: 0; border-radius: 22%; display: grid; place-items: center;
  font-size: calc(var(--s) * .5); font-weight: 900; color: #5c3d00; background: linear-gradient(160deg, #fff3bf, #f2b84b);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.12), 0 3px 0 rgba(0,0,0,.3); transition: transform .15s;
}
.bigdie.picked { transform: translateY(-10px); box-shadow: 0 0 0 4px #ffd43b, 0 0 14px #ffd43b; }
.dragging { position: fixed; z-index: 40; pointer-events: none; transform: translate(-50%, -50%) scale(1.1); opacity: .95; }
.newdie { animation: popin .35s ease-out; }
@keyframes popin { from { transform: scale(.2); opacity: 0; } }
.float-fixed {
  position: fixed; z-index: 31; transform: translate(-50%, -50%); pointer-events: none; white-space: nowrap;
  font-weight: 900; font-size: 30px; color: #ffe066; text-shadow: 0 2px 0 rgba(0,0,0,.6), 0 0 12px rgba(0,0,0,.4);
  animation: popfloat 1s ease-out forwards;
}
.float-fixed.dmg { color: #ff6b6b; font-size: 34px; } .float-fixed.heal { color: #69db7c; } .float-fixed.block { color: #74c0fc; font-size: 24px; }
.float-fixed.poison { color: #8ce99a; font-size: 24px; } .float-fixed.small { font-size: 18px; color: #fff; }
@keyframes popfloat { 0% { transform: translate(-50%, -50%) scale(.4); opacity: 0; } 14% { transform: translate(-50%, -62%) scale(1.2); opacity: 1; } 28% { transform: translate(-50%, -68%) scale(1); } 75% { opacity: 1; } 100% { transform: translate(-50%, -160%); opacity: 0; } }
.die.flying, .bigdie.flying { position: fixed; z-index: 30; margin: 0; pointer-events: none; transition: transform .3s cubic-bezier(.45, 0, .25, 1.2); }

/* ---------- reward, rooms, end ---------- */
.face.big { font-size: 80px; }
.levelup { font-weight: 900; color: var(--accent); font-size: 18px; }
.room-head { display: flex; gap: 14px; align-items: center; }
.room-head .face { font-size: 54px; }
.room-body { display: grid; gap: 10px; }
.offer { display: flex; align-items: center; gap: 12px; border: 0; border-radius: 14px; padding: 10px 12px; background: var(--panel); text-align: left; }
.offer .gcard { width: 104px; flex: none; }
.offer > div { flex: 1; display: grid; gap: 4px; }
.offer .price { font-weight: 900; color: var(--gold); font-size: 18px; }
.offer.sold { opacity: .4; }
.offer.no .price { color: var(--bad); }
.d-card { display: flex; gap: 14px; align-items: center; }
.d-card .gcard { width: 120px; min-height: 110px; flex: none; }
.d-card p { color: var(--muted); font-size: 15px; }
.d-actions { display: grid; gap: 8px; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 10; }
.sheet-wrap { background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; }
.sheet {
  width: 100%; max-width: 560px; margin: 0 auto; background: var(--panel); color: var(--ink); 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; max-height: 85vh; overflow-y: auto;
}
.toast {
  position: fixed; left: 50%; bottom: calc(120px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; max-width: calc(100% - 32px);
  background: rgba(20, 16, 26, .95); color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 15px; text-align: center; pointer-events: none;
}

/* ---------- 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.steady { background: linear-gradient(160deg, #e6fcf5, #96f2d7); --pip: #087f5b; }
.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; }

.cube3.fresh { cursor: pointer; }
.cube3.sel { transform: translateY(-12px); }
.cube3.sel .face { box-shadow: inset 0 0 0 4px #ffd43b, 0 0 14px #ffd43b; }
.cube3.idle { opacity: .5; }
.cube3.glow .face { box-shadow: inset 0 0 0 4px #cc5de8, 0 0 20px #cc5de8; }
.cube3.busted .face { filter: grayscale(.7) brightness(.75); }
.cube3.busted { animation: shake .4s; }
.cube3.hot .face { box-shadow: inset 0 0 0 3px #ffd43b, 0 0 22px #ff922b; }
.die.flying { position: fixed; z-index: 30; margin: 0; pointer-events: none; transition: transform .38s cubic-bezier(.45, 0, .25, 1.25); }
.float-fixed {
  position: fixed; z-index: 31; transform: translate(-50%, -50%); pointer-events: none; white-space: nowrap;
  font-weight: 900; font-size: 28px; color: #ffe066; text-shadow: 0 2px 0 rgba(0,0,0,.5), 0 0 12px rgba(0,0,0,.35);
  animation: popfloat 1.05s ease-out forwards;
}
.float-fixed.big { font-size: 40px; color: #ffa94d; }
.float-fixed.tag { font-size: 13px; color: #fff; background: #be4bdb; padding: 3px 9px; border-radius: 10px; text-shadow: none; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
@keyframes popfloat {
  0% { transform: translate(-50%, -50%) scale(.4); opacity: 0; }
  14% { transform: translate(-50%, -62%) scale(1.2); opacity: 1; }
  28% { transform: translate(-50%, -68%) scale(1); }
  75% { opacity: 1; }
  100% { transform: translate(-50%, -170%); opacity: 0; }
}
.flytext {
  position: fixed; z-index: 31; transform: translate(-50%, -50%); pointer-events: none; white-space: nowrap;
  font-weight: 900; font-size: 26px; color: #ffe066; text-shadow: 0 2px 0 rgba(0,0,0,.5);
  transition: transform .5s cubic-bezier(.5, 0, .25, 1), opacity .5s ease-in;
}
.helped-line { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 10px; align-items: center; color: var(--muted); font-size: 15px; }
.helped { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; color: var(--ink); }
.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); } }


/* a die on the table is a real 3D cube: six faces, turned so the rolled face points up at you */
.cube3 { --s: min(17vw, 76px); position: relative; width: var(--s); height: var(--s); border: 0; padding: 0; background: none; transition: transform .15s; }
.cube3 .shadow { position: absolute; left: 6%; right: 6%; bottom: -7%; height: 26%; border-radius: 50%; background: rgba(0, 0, 0, .38); filter: blur(5px); }
.cube3 .cube { position: absolute; inset: 0; transform-style: preserve-3d; }
.cube3 .face { position: absolute; left: -0.5px; top: -0.5px; width: calc(var(--s) + 1px); height: calc(var(--s) + 1px); --s: inherit; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 14%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1), inset 0 -4px 6px rgba(0,0,0,.08); }
.cube3 .f0 { transform: translateZ(calc(var(--s) / 2)); }
.cube3 .f1 { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.cube3 .f2 { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.cube3 .f3 { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.cube3 .f4 { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.cube3 .f5 { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
/* a solid inner cube, a little smaller and darker: what shows through the rounded corners and the
   seams between faces is the die's own colour (it reads as a bevel), never the table behind */
.cube3 .inner { position: absolute; left: 4%; top: 4%; width: 92%; height: 92%; padding: 0; border-radius: 0; box-shadow: none; filter: brightness(.82); }
.cube3 .inner i { display: none; }
.cube3 .i0 { transform: translateZ(calc(var(--s) * .46)); }
.cube3 .i1 { transform: rotateY(180deg) translateZ(calc(var(--s) * .46)); }
.cube3 .i2 { transform: rotateY(90deg) translateZ(calc(var(--s) * .46)); }
.cube3 .i3 { transform: rotateY(-90deg) translateZ(calc(var(--s) * .46)); }
.cube3 .i4 { transform: rotateX(90deg) translateZ(calc(var(--s) * .46)); }
.cube3 .i5 { transform: rotateX(-90deg) translateZ(calc(var(--s) * .46)); }
.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.steady { background: linear-gradient(160deg, #e6fcf5, #96f2d7); --pip: #087f5b; }
.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; }

.cube3.fresh { cursor: pointer; }
.cube3.sel { transform: translateY(-12px); }
.cube3.sel .face { box-shadow: inset 0 0 0 4px #ffd43b, 0 0 14px #ffd43b; }
.cube3.idle { opacity: .5; }
.cube3.glow .face { box-shadow: inset 0 0 0 4px #cc5de8, 0 0 20px #cc5de8; }
.cube3.busted .face { filter: grayscale(.7) brightness(.75); }
.cube3.busted { animation: shake .4s; }
.cube3.hot .face { box-shadow: inset 0 0 0 3px #ffd43b, 0 0 22px #ff922b; }
