/* One die — warm paper, ink, and a single oxblood accent taken from the pip on
   the one-face. Nothing here is a gradient mesh. */

:root {
  --paper: #f6f2e9;
  --paper-deep: #ece5d6;
  --ink: #23201c;
  --ink-soft: #5d564c;
  --oxblood: #8f2d1e;
  --rule: #d9d0bd;
  --measure: 34rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #191713;
    --paper-deep: #221f19;
    --ink: #ece5d6;
    --ink-soft: #a89d8b;
    --oxblood: #d4634c;
    --rule: #3a352c;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1.0625rem/1.65 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  padding: clamp(1.5rem, 5vw, 4rem) 1.25rem clamp(3rem, 8vw, 6rem);
}

main { max-width: var(--measure); margin: 0 auto; }

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

h1 {
  margin: 0 0 0.75rem;
  font: 400 clamp(2.4rem, 9vw, 3.6rem)/1.05 ui-serif, 'Iowan Old Style', Georgia, serif;
  letter-spacing: -0.01em;
}

.standfirst {
  margin: 0;
  max-width: 30rem;
  color: var(--ink-soft);
  font-size: 1.05rem;
}

/* ------------------------------------------------------------------- stage */

.stage {
  position: relative;
  margin: clamp(1.5rem, 5vw, 2.75rem) 0 0;
  aspect-ratio: 4 / 3;
  max-height: 56vh;
  display: grid;
  place-items: center;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: pan-y;          /* a touch drag scrolls the page, as it should */
  cursor: pointer;
}

/* The flat die: the fallback, and the only die on a page with no WebGL. */
.flat {
  display: none;
  width: min(58%, 13rem);
  aspect-ratio: 1;
  padding: 9%;
  border-radius: 22%;
  background:
    radial-gradient(120% 120% at 30% 24%, #fdfaf1 0%, var(--paper-deep) 62%, #ded4bf 100%);
  box-shadow: 0 1.4rem 2.4rem -1.2rem rgba(60, 48, 32, 0.55), inset 0 0 0 1px rgba(255,255,255,0.5);
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 6%;
}

.flat span { border-radius: 50%; visibility: hidden; background: #26221d; }

.flat[data-face="1"] span:nth-child(5),
.flat[data-face="2"] span:nth-child(1), .flat[data-face="2"] span:nth-child(9),
.flat[data-face="3"] span:nth-child(1), .flat[data-face="3"] span:nth-child(5), .flat[data-face="3"] span:nth-child(9),
.flat[data-face="4"] span:nth-child(1), .flat[data-face="4"] span:nth-child(3), .flat[data-face="4"] span:nth-child(7), .flat[data-face="4"] span:nth-child(9),
.flat[data-face="5"] span:nth-child(1), .flat[data-face="5"] span:nth-child(3), .flat[data-face="5"] span:nth-child(5), .flat[data-face="5"] span:nth-child(7), .flat[data-face="5"] span:nth-child(9),
.flat[data-face="6"] span:nth-child(1), .flat[data-face="6"] span:nth-child(3), .flat[data-face="6"] span:nth-child(4),
.flat[data-face="6"] span:nth-child(6), .flat[data-face="6"] span:nth-child(7), .flat[data-face="6"] span:nth-child(9) {
  visibility: visible;
}

.flat[data-face="1"] span:nth-child(5) { background: var(--oxblood); }

/* WebGL missing, refused or broken: swap them over. Set by scene-host.js. */
.no-webgl canvas { display: none; }
.no-webgl .flat { display: grid; }
html:not(.no-webgl) .flat { display: none; }

/* ---------------------------------------------------------------- controls */

.controls {
  margin-top: clamp(1.25rem, 4vw, 2rem);
  text-align: center;
}

.roll {
  appearance: none;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-weight: 600;
  padding: 0.7rem 1.6rem;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.12s ease;
}
.roll:hover { transform: translateY(-1px); }
.roll:active { transform: translateY(0); }
.roll:focus-visible { outline: 3px solid var(--oxblood); outline-offset: 3px; }
.roll[disabled] { opacity: 0.45; cursor: default; transform: none; }

.result { margin: 0.9rem 0 0.2rem; font-size: 1.1rem; }
.result strong { font-weight: 600; }

.hint { margin: 0; color: var(--ink-soft); font-size: 0.98rem; }

kbd {
  font: 0.92em ui-monospace, monospace;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.1em 0.4em;
}

/* ------------------------------------------------------------------- prose */

.prose {
  margin-top: clamp(2.5rem, 8vw, 4rem);
  border-top: 1px solid var(--rule);
  padding-top: 1.5rem;
}

h2 {
  margin: 0 0 0.6rem;
  font: 400 1.3rem/1.3 ui-serif, 'Iowan Old Style', Georgia, serif;
}

.prose p { margin: 0 0 1rem; color: var(--ink-soft); }

footer {
  margin-top: 2.5rem;
  border-top: 1px solid var(--rule);
  padding-top: 1rem;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

code { font: 0.9em ui-monospace, monospace; }

@media (prefers-reduced-motion: reduce) {
  .roll { transition: none; }
  .roll:hover { transform: none; }
}
