:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --ink: #18201c;
  --muted: #5b6660;
  --line: #dfe4df;
  --accent: #0f7b5f;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3ec;
  --felt: #0f5a46;
  --felt-2: #0b4637;
  --die: #ffffff;
  --die-edge: #d5dad6;
  --pip: #1b1f1d;
  --hot: #d6452f;
  --gold: #e7b23a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513; --surface: #1a201d; --ink: #e8ece9; --muted: #a3ada7; --line: #2c3430;
    --accent: #3fbf93; --accent-ink: #0b1511; --accent-soft: #1d3029;
    --felt: #0d3f32; --felt-2: #092e25;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.5rem); margin: 0 0 .4rem; }
h2 { font-size: 1.45rem; margin: 2rem 0 .6rem; }
.wrap { max-width: 1060px; margin: 0 auto; padding: 0 16px; }

/* Header */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top .wrap { max-width: 1240px; }
.top-in { display: flex; align-items: center; gap: 16px; min-height: 58px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 8px; margin: 0; }
.brand b { color: var(--accent); }
.brand-die { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; box-shadow: inset 0 0 0 2px rgba(255,255,255,.15); }
.brand-die::before, .brand-die::after { content: ""; position: absolute; width: 5px; height: 5px; border-radius: 50%; background: #fff; }
.brand-die::before { top: 4px; left: 4px; box-shadow: 9px 9px 0 #fff; }
.brand-die::after { bottom: 4px; left: 4px; box-shadow: 9px -9px 0 #fff; }
.menu-btn { display: none; margin-left: auto; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; margin-left: auto; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 9px; border-radius: 8px; font-size: .92rem; }
.nav a:hover, .nav a[aria-current] { color: var(--ink); background: var(--accent-soft); }
@media (max-width: 1180px) {
  .menu-btn { display: inline-flex; }
  .nav { display: none; width: 100%; padding-bottom: 10px; }
  .nav.open { display: flex; }
}

/* Hero + play area */
.hero { padding: 24px 0 8px; }
.hero p.lede { color: var(--muted); margin: 0 0 16px; max-width: 760px; }
.table {
  background: radial-gradient(ellipse at 50% 30%, var(--felt), var(--felt-2));
  border-radius: 20px; padding: 22px 16px; color: #fff; box-shadow: var(--shadow);
}
.tray { min-height: 150px; display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; align-items: center; padding: 10px 0 6px; }
.readout { text-align: center; font-size: 1.1rem; min-height: 1.8em; }
.readout strong { font-size: 2rem; vertical-align: -3px; margin-left: 6px; }
.readout .sub { display: block; font-size: .9rem; opacity: .8; }
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 14px; align-items: center; }
.controls label { display: flex; align-items: center; gap: 6px; font-size: .95rem; }
.hint { text-align: center; font-size: .82rem; opacity: .75; margin: 10px 0 0; }

button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 8px 14px; min-height: 40px;
}
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn-roll { background: var(--gold); color: #231a02; border: 0; font-weight: 700; font-size: 1.15rem; padding: 12px 34px; border-radius: 999px; box-shadow: 0 3px 0 #a87b17; }
.btn-roll:active { transform: translateY(2px); box-shadow: 0 1px 0 #a87b17; }
.btn-roll:disabled { opacity: .5; cursor: default; }
.table button:not(.btn-roll):not(.die), .table select, .table input { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25); }
.table select option { color: #000; }
select, input[type=number], input[type=text], textarea { font: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; background: var(--surface); color: var(--ink); min-height: 40px; }
input[type=number] { width: 5.5em; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { width: 40px; padding: 0; font-size: 1.2rem; }
.stepper output { min-width: 2ch; text-align: center; font-weight: 700; font-size: 1.15rem; }

/* Dice */
.die {
  --s: 76px; width: var(--s); height: var(--s); background: var(--die); border-radius: 18%;
  box-shadow: inset 0 -5px 0 var(--die-edge), 0 6px 14px rgba(0,0,0,.35);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: calc(var(--s) * .14); min-height: 0; position: relative;
  border: 0; color: var(--pip); cursor: default;
}
.die.clickable { cursor: pointer; }
.die .pip { width: 72%; height: 72%; margin: auto; border-radius: 50%; background: var(--pip); box-shadow: inset 0 2px 2px rgba(0,0,0,.5); }
.die.v1 .pip, .die.red .pip { background: var(--hot); }
.die.held { box-shadow: inset 0 -5px 0 var(--die-edge), 0 0 0 4px var(--gold), 0 6px 14px rgba(0,0,0,.35); transform: translateY(-4px); }
.die.held::after { content: "HELD"; position: absolute; bottom: -24px; left: 0; right: 0; text-align: center; font: 700 .7rem system-ui; color: var(--gold); letter-spacing: .08em; }
.die.num { display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: calc(var(--s) * .4); padding: 0; }
.die.num small { position: absolute; top: 4px; right: 8px; font-size: .62rem; font-weight: 600; opacity: .5; }
.die.crit { box-shadow: inset 0 -5px 0 var(--die-edge), 0 0 0 4px var(--gold), 0 6px 14px rgba(0,0,0,.35); }
.die.fail { box-shadow: inset 0 -5px 0 var(--die-edge), 0 0 0 4px var(--hot), 0 6px 14px rgba(0,0,0,.35); }
.die.dim { opacity: .4; }
.die.rolling { animation: tumble .55s cubic-bezier(.3,.7,.4,1); }
@keyframes tumble {
  0% { transform: translate(-40px, -30px) rotate(-200deg) scale(.8); }
  60% { transform: translate(6px, 4px) rotate(20deg) scale(1.05); }
  100% { transform: none; }
}
@media (prefers-reduced-motion: reduce) { .die.rolling, .coin.flipping { animation: none !important; } }
.die.sm { --s: 44px; border-radius: 10px; box-shadow: inset 0 -3px 0 var(--die-edge), 0 3px 6px rgba(0,0,0,.25); }
.die.sm.held::after { bottom: -18px; font-size: .6rem; }
/* pip positions: grid areas 1..9 */
.p1 { grid-area: 1/1; } .p2 { grid-area: 1/2; } .p3 { grid-area: 1/3; }
.p4 { grid-area: 2/1; } .p5 { grid-area: 2/2; } .p6 { grid-area: 2/3; }
.p7 { grid-area: 3/1; } .p8 { grid-area: 3/2; } .p9 { grid-area: 3/3; }

/* History */
.history { margin-top: 14px; font-size: .88rem; max-height: 140px; overflow: auto; background: rgba(0,0,0,.18); border-radius: 10px; padding: 8px 12px; }
.history:empty { display: none; }
.history div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid rgba(255,255,255,.1); padding: 3px 0; }
.history div:last-child { border: 0; }

/* Coin */
.coin-stage { perspective: 800px; height: 170px; display: flex; align-items: center; justify-content: center; }
.coin { width: 150px; height: 150px; position: relative; transform-style: preserve-3d; transition: transform .1s; }
.coin .face { position: absolute; inset: 0; border-radius: 50%; backface-visibility: hidden; display: flex; align-items: center; justify-content: center; flex-direction: column;
  background: radial-gradient(circle at 35% 30%, #f5f5f2, #b9bcc0 60%, #8d9196); color: #3b3f44; font-weight: 800; letter-spacing: .06em;
  box-shadow: inset 0 0 0 7px #a7abb0, inset 0 0 0 9px #d8dadd, 0 8px 18px rgba(0,0,0,.35); }
.coin .face span { font-size: 2.6rem; line-height: 1; }
.coin .face small { font-size: .8rem; }
.coin .tails { transform: rotateY(180deg); }
.coin.flipping { animation: flip 1s cubic-bezier(.2,.6,.3,1); }
@keyframes flip { 0% { transform: translateY(0) rotateY(0); } 50% { transform: translateY(-70px) rotateY(var(--spin-half)); } 100% { transform: translateY(0) rotateY(var(--spin)); } }
.stats { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.stat { background: rgba(0,0,0,.2); border-radius: 10px; padding: 6px 14px; text-align: center; min-width: 90px; }
.stat b { display: block; font-size: 1.3rem; }

/* Polyhedral picker */
.poly { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.poly button { min-width: 64px; font-weight: 700; }
.poly button[aria-pressed=true] { background: var(--gold) !important; color: #231a02 !important; border-color: var(--gold) !important; }
.big-num { font-size: clamp(3rem, 12vw, 6rem); font-weight: 800; text-align: center; line-height: 1.1; min-height: 1.1em; word-break: break-word; }
.big-num.many { font-size: 1.6rem; line-height: 1.6; }

/* Spinner */
.spin-wrap { position: relative; width: min(420px, 100%); margin: 0 auto; aspect-ratio: 1; }
.spin-wrap canvas { width: 100%; height: 100%; display: block; }
.spin-wrap .pointer { position: absolute; top: -6px; left: 50%; transform: translateX(-50%); width: 0; height: 0; border-left: 16px solid transparent; border-right: 16px solid transparent; border-top: 30px solid var(--gold); filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
textarea { width: 100%; min-height: 220px; resize: vertical; }

/* Scorecard */
.score { width: 100%; border-collapse: collapse; background: var(--surface); color: var(--ink); border-radius: 12px; overflow: hidden; font-size: .93rem; }
.score th, .score td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.score td:last-child { text-align: right; width: 90px; }
.score tr.sum td { font-weight: 700; background: var(--accent-soft); }
.score button { min-height: 32px; padding: 2px 10px; width: 100%; font-weight: 700; color: var(--accent); border-style: dashed; }
.score .done { font-weight: 700; }

/* Beetle */
.beetle-svg { width: 220px; height: 240px; display: block; margin: 0 auto; }
.beetle-svg .part { opacity: .1; transition: opacity .3s; }
.beetle-svg .part.on { opacity: 1; }
.parts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 6px; font-size: .88rem; margin-top: 8px; }
.parts span { background: rgba(0,0,0,.2); border-radius: 8px; padding: 4px 8px; }

/* Content */
.content { padding-top: 10px; }
.content p, .content li { max-width: 760px; }
.content table { border-collapse: collapse; margin: 10px 0; background: var(--surface); }
.content th, .content td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.faq details { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 8px 0; max-width: 820px; }
.faq summary { font-weight: 600; cursor: pointer; }
.faq p { margin: 8px 0 0; color: var(--muted); }
.more { padding-bottom: 30px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; gap: 4px; transition: transform .15s, box-shadow .15s; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card span:last-child { color: var(--muted); font-size: .9rem; }
.card-icon { font-size: 1.6rem; }

.foot { background: var(--surface); border-top: 1px solid var(--line); margin-top: 20px; padding: 26px 0 12px; font-size: .92rem; }
.foot-in { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 20px; }
.foot h3 { font-size: .95rem; margin: 0 0 8px; }
.foot a { display: block; color: var(--muted); text-decoration: none; padding: 2px 0; }
.foot a:hover { color: var(--accent); }
.foot p { color: var(--muted); margin: 0 0 8px; }
.copy { color: var(--muted); font-size: .82rem; margin-top: 16px; }
@media (max-width: 700px) { .foot-in { grid-template-columns: 1fr 1fr; } .foot-in > div:first-child { grid-column: 1 / -1; } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
