/* Roll Anything — dice roller
   Palette: night table surface, bone dice, resin jade accent */

:root {
  --ink: #12141c;
  --felt: #191d29;
  --raise: #212636;
  --edge: #2e3548;
  --chalk: #eceae3;
  --muted: #8d94ab;
  --jade: #45c9a0;
  --jade-dim: #2a7a63;
  --crit: #ff5c5c;
  --gold: #e0a83c;

  --display: 'Space Grotesk', system-ui, sans-serif;
  --body: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;

  --gut: clamp(1rem, 4vw, 2.5rem);
  --max: 940px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--ink);
  color: var(--chalk);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.6;
  /* faint graph paper, the surface these games are played on */
  background-image:
    linear-gradient(rgba(69, 201, 160, .028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(69, 201, 160, .028) 1px, transparent 1px);
  background-size: 26px 26px;
}

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 var(--gut); }

/* ---------- masthead ---------- */
.masthead {
  border-bottom: 1px solid var(--edge);
  padding: 1.1rem 0;
  margin-bottom: 2.5rem;
}
.masthead .wrap { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.brand {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -.02em;
  color: var(--chalk);
  text-decoration: none;
}
.brand span { color: var(--jade); }
.masthead nav { margin-left: auto; display: flex; gap: 1.1rem; flex-wrap: wrap; }
.masthead nav a {
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--muted);
  text-decoration: none;
  padding-bottom: 2px;
  border-bottom: 1px solid transparent;
}
.masthead nav a:hover, .masthead nav a:focus-visible { color: var(--jade); border-bottom-color: var(--jade); }

/* ---------- page head ---------- */
.eyebrow {
  font-family: var(--mono);
  font-size: .74rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--jade);
  margin: 0 0 .7rem;
}
h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(2rem, 6vw, 3.1rem);
  line-height: 1.03;
  letter-spacing: -.035em;
  margin: 0 0 .8rem;
}
.standfirst {
  font-size: 1.06rem;
  color: var(--muted);
  max-width: 56ch;
  margin: 0 0 2.2rem;
}

/* ---------- roller ---------- */
.roller {
  background: var(--felt);
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: clamp(1.2rem, 4vw, 2rem);
  margin-bottom: 2.5rem;
}

.readout {
  text-align: center;
  padding: 1.4rem 0 1.6rem;
  border-bottom: 1px solid var(--edge);
  margin-bottom: 1.4rem;
}
/* ---------- the dice themselves: signature element ---------- */
.stage {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
  justify-content: center;
  align-items: center;
  /* No fixed height needed: the resting state renders the same dice a roll
     does, so there is no layout shift to reserve space for. */
  min-height: 0;
  padding: .6rem 0 1.1rem;
  margin-bottom: .2rem;
}

.die-slot {
  animation: tumble .52s cubic-bezier(.18,.86,.28,1.06) backwards;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.5));
}
.die-slot.solo { width: clamp(122px, 30vw, 158px); height: clamp(122px, 30vw, 158px); }
.die-slot.many { width: 62px; height: 62px; }
.die-slot.dropped { opacity: .28; }

@keyframes tumble {
  0%   { transform: rotate(-155deg) scale(.35); opacity: 0; }
  55%  { transform: rotate(14deg) scale(1.09); opacity: 1; }
  78%  { transform: rotate(-5deg) scale(.97); }
  100% { transform: rotate(0) scale(1); }
}

.die { width: 100%; height: 100%; display: block; overflow: visible; }
.die-body {
  fill: var(--raise);
  stroke: var(--jade);
  stroke-width: 2.4;
  stroke-linejoin: round;
  transition: stroke .2s ease;
}
/* the front face: a touch lighter than the body so it reads as facing you */
.die-face {
  fill: rgba(255,255,255,.07);
  stroke: var(--jade);
  stroke-width: 1.6;
  stroke-linejoin: round;
  opacity: .9;
  transition: stroke .2s ease;
}
[data-style] .die-face { stroke: var(--d-edge, var(--jade)); fill: var(--d-face, rgba(255,255,255,.07)); }
[data-style] .die.hi .die-face { stroke: var(--gold); }
[data-style] .die.lo .die-face { stroke: var(--crit); }
.die.hi .die-face { stroke: var(--gold); }
.die.lo .die-face { stroke: var(--crit); }
.die-facet {
  fill: none;
  stroke: var(--jade);
  stroke-width: 1;
  stroke-linejoin: round;
  opacity: .32;
}
/* side faces darken towards the edge, front face lifts a touch */
.die-side { fill: #000; pointer-events: none; }
.die-front { fill: #fff; opacity: .05; pointer-events: none; }
.stage.idle .die-side, .stage.idle .die-front { display: none; }
.die-num {
  fill: var(--chalk);
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: -.03em;
}
.die.many .die-num { font-size: 38px; }

.die.hi .die-body { stroke: var(--gold); }
.die.hi .die-facet { stroke: var(--gold); }
.die.hi .die-num { fill: var(--gold); }
.die.lo .die-body { stroke: var(--crit); }
.die.lo .die-facet { stroke: var(--crit); }
.die.lo .die-num { fill: var(--crit); }

/* resting state before the first roll */
.stage.idle .die-slot { animation: none; filter: none; opacity: .3; }
.stage.idle .die-num { fill: var(--muted); }

.total-line { min-height: 1.1em; }
.total {
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(1.9rem, 6vw, 2.6rem);
  line-height: 1;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  transition: color .18s ease;
}
.total.is-max { color: var(--gold); }
.total.is-min { color: var(--crit); }
.total.hidden { display: none; }
.total-label {
  font-family: var(--mono);
  font-size: .7rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  display: block;
  margin-bottom: .3rem;
}
.total-label.hidden { display: none; }

.breakdown {
  font-family: var(--mono);
  font-size: .88rem;
  color: var(--muted);
  margin-top: .75rem;
  min-height: 1.4em;
  word-break: break-word;
}
.breakdown b { color: var(--chalk); font-weight: 500; }
.breakdown .hi { color: var(--gold); }
.breakdown .lo { color: var(--crit); }
.verdict {
  font-family: var(--display);
  font-weight: 500;
  font-size: .82rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  min-height: 1.2em;
  margin-top: .5rem;
}
.verdict.hi { color: var(--gold); }
.verdict.lo { color: var(--crit); }


/* controls */
.controls { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: .32rem; }
.field label {
  font-family: var(--mono);
  font-size: .7rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.field input, .field select {
  font-family: var(--mono);
  font-size: .95rem;
  background: var(--ink);
  color: var(--chalk);
  border: 1px solid var(--edge);
  border-radius: 7px;
  padding: .55rem .65rem;
  width: 5.2rem;
}
.field input:focus-visible, .field select:focus-visible { outline: 2px solid var(--jade); outline-offset: 1px; }

.roll-btn {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .02em;
  background: var(--jade);
  color: var(--ink);
  border: 0;
  border-radius: 8px;
  padding: .72rem 1.9rem;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 140px;
  transition: transform .1s ease, background .15s ease;
}
.roll-btn:hover { background: #55dcb1; }
.roll-btn:active { transform: translateY(1px); }
.roll-btn:focus-visible { outline: 2px solid var(--chalk); outline-offset: 2px; }

.toggles { display: flex; gap: .45rem; flex-wrap: wrap; margin-top: 1rem; }
.toggle {
  font-family: var(--mono);
  font-size: .76rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: .35rem .8rem;
  cursor: pointer;
}
.toggle[aria-pressed="true"] { background: var(--jade-dim); border-color: var(--jade); color: var(--chalk); }
.toggle:focus-visible { outline: 2px solid var(--jade); outline-offset: 1px; }

/* ---------- sections ---------- */
section { margin-bottom: 2.8rem; }
h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: -.02em;
  margin: 0 0 .3rem;
}
h3 {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.05rem;
  margin: 1.6rem 0 .5rem;
}
.sub { color: var(--muted); font-size: .93rem; margin: 0 0 1.2rem; max-width: 62ch; }
p { max-width: 68ch; }

/* ---------- histogram: the signature ---------- */
.histo {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 190px;
  padding: 0 0 1.9rem;
  border-bottom: 1px solid var(--edge);
  position: relative;
  overflow-x: auto;
}
.bar { flex: 1 1 0; min-width: 5px; position: relative; height: 100%; display: flex; align-items: flex-end; }
.bar i {
  display: block; width: 100%;
  background: var(--jade-dim);
  border-radius: 2px 2px 0 0;
  transition: background .18s ease;
}
.bar.mode i { background: var(--jade); }
.bar.hit i { background: var(--chalk); }
.bar[data-tick]::after {
  content: attr(data-tick);
  position: absolute;
  bottom: -1.55rem; left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: .68rem;
  color: var(--muted);
}
.histo-key {
  font-family: var(--mono);
  font-size: .74rem;
  color: var(--muted);
  margin-top: .9rem;
  display: flex; gap: 1.2rem; flex-wrap: wrap;
}
.histo-key b { font-weight: 500; color: var(--chalk); }

/* ---------- stat strip ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1px;
  background: var(--edge);
  border: 1px solid var(--edge);
  border-radius: 10px;
  overflow: hidden;
}
.stats div { background: var(--felt); padding: .95rem 1rem; }
.stats dt {
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .3rem;
}
.stats dd {
  font-family: var(--mono);
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -.02em;
}

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .86rem; }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--edge); }
th { color: var(--muted); font-weight: 500; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; }

/* ---------- link grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: .55rem;
}
.card {
  display: block;
  background: var(--felt);
  border: 1px solid var(--edge);
  border-radius: 9px;
  padding: .8rem .9rem;
  text-decoration: none;
  color: var(--chalk);
  transition: border-color .15s ease, transform .15s ease;
}
.card:hover, .card:focus-visible { border-color: var(--jade); transform: translateY(-2px); }
.card b { font-family: var(--mono); font-weight: 600; font-size: .98rem; display: block; }
.card span { font-size: .76rem; color: var(--muted); }

/* ---------- footer ---------- */
footer {
  border-top: 1px solid var(--edge);
  margin-top: 3.5rem;
  padding: 1.8rem 0 3rem;
  font-size: .82rem;
  color: var(--muted);
}
footer a { color: var(--muted); }
footer p { max-width: 70ch; }
.footlinks {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  margin-top: 1.1rem;
  font-family: var(--mono);
  font-size: .78rem;
}
.footlinks a { text-decoration: none; }
.footlinks a:hover, .footlinks a:focus-visible { color: var(--jade); }

a { color: var(--jade); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---------- pickers: die type and dice style ---------- */
.pickers { display: flex; flex-direction: column; gap: .7rem; margin-bottom: 1.1rem; }
.picker { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; }
.die-pick, .style-pick {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: .3rem;
  cursor: pointer;
  line-height: 0;
  transition: border-color .15s ease, transform .15s ease, background .15s ease;
}
/* The rows never wrap. Each icon takes an equal share of whatever width the
   card actually has, capped so desktop stays tidy. aspect-ratio keeps them
   square at any share, so a phone gets seven small dice in one row and a
   desktop gets seven large ones, with no breakpoint to maintain. */
.picker { flex-wrap: nowrap; }
.die-pick { flex: 1 1 0; max-width: 84px; aspect-ratio: 1; height: auto; }
.style-pick { flex: 1 1 0; max-width: 42px; aspect-ratio: 1; height: auto; }
.picker-die { gap: clamp(.2rem, 1vw, .6rem); }
.style-pick { border-radius: 999px; padding: .25rem; }
.die-pick:hover, .style-pick:hover { transform: translateY(-2px); border-color: var(--edge); }
.die-pick[aria-pressed="true"] { background: var(--raise); border-color: var(--jade); }
.style-pick[aria-pressed="true"] { border-color: var(--chalk); background: var(--raise); }
.die-pick:focus-visible, .style-pick:focus-visible { outline: 2px solid var(--jade); outline-offset: 1px; }
.die.icon .die-num { font-family: var(--mono); font-weight: 600; }

/* ---------- dice styles ----------
   Each style sets four things: body fill, overlay fill, edge colour, and
   number colour. The default (jade wire) is the original look. Swatches in
   the style picker carry their own data-style so they preview themselves. */
.die-skin { fill: none; pointer-events: none; }

[data-style] .die-body { fill: var(--d-body, var(--raise)); stroke: var(--d-edge, var(--jade)); }
[data-style] .die-facet { stroke: var(--d-edge, var(--jade)); opacity: var(--d-facet, .32); }
[data-style] .die-num { fill: var(--d-num, var(--chalk)); }
[data-style] .die-skin { fill: var(--d-skin, none); opacity: var(--d-skin-o, 1); }

[data-style="jade"]     { --d-body: var(--raise); --d-edge: var(--jade); --d-num: var(--chalk); }
[data-style="jade"] .die-side { opacity: 0 !important; }
[data-style="jade"] .die-front { fill: var(--jade); opacity: .06; }
[data-style="obsidian"] { --d-body: url(#dc-obsidian); --d-edge: #4a4a58; --d-num: #ff5a5a; --d-facet: .55; }
[data-style="galaxy"]   { --d-body: url(#dc-galaxy);   --d-edge: #9db4ff; --d-num: #ffd66e; --d-skin: url(#dc-galaxy-ov); --d-facet: .28; }
[data-style="ember"]    { --d-body: url(#dc-ember);    --d-edge: #ffb26b; --d-num: #ffe6a8; --d-skin: url(#dc-ember-ov); --d-skin-o: .6; --d-facet: .35; }
[data-style="seaglass"] { --d-face: rgba(255,255,255,.12); --d-body: url(#dc-seaglass); --d-edge: #d9fff5; --d-num: #073530; --d-facet: .45; }
[data-style="bone"]     { --d-face: rgba(0,0,0,.05); --d-body: url(#dc-bone);     --d-edge: #7d6844; --d-num: #2a2116; --d-facet: .5; }
[data-style="brass"]    { --d-body: url(#dc-brass);    --d-edge: #fff0b8; --d-num: #3a2606; --d-facet: .4; }
[data-style="candy"]    { --d-body: url(#dc-candy);    --d-edge: #ffe1f1; --d-num: #ffffff; --d-facet: .4; }
[data-style="frost"]    { --d-face: rgba(0,0,0,.05); --d-body: url(#dc-frost);    --d-edge: #6fa9dc; --d-num: #174b7a; --d-skin: url(#dc-frost-ov); --d-skin-o: .5; --d-facet: .35; }

/* natural max and natural 1 still read through any style */
[data-style] .die.hi .die-body, [data-style] .die.hi .die-facet { stroke: var(--gold); }
[data-style] .die.hi .die-num { fill: var(--gold); paint-order: stroke; stroke: rgba(0,0,0,.45); stroke-width: 1.2px; }
[data-style] .die.lo .die-body, [data-style] .die.lo .die-facet { stroke: var(--crit); }
[data-style] .die.lo .die-num { fill: var(--crit); paint-order: stroke; stroke: rgba(0,0,0,.45); stroke-width: 1.2px; }

/* resting dice stay dimmed regardless of style */
.stage.idle .die-num { fill: var(--muted) !important; }
.stage.idle .die-skin { display: none; }

@media (max-width: 480px) {
  .die-pick { padding: .15rem; }
}
.style-pick .die-num { display: none; }

/* ---------- live distribution notice ----------
   Shown only when the visitor has rolled a different notation from the one
   this page is about, so the chart above and the prose below cannot silently
   disagree with each other. */
.shape-live {
  font-family: var(--mono);
  font-size: .78rem;
  line-height: 1.5;
  color: var(--muted);
  background: var(--raise);
  border: 1px solid var(--edge);
  border-left: 2px solid var(--jade);
  border-radius: 8px;
  padding: .6rem .8rem;
  margin: 0 0 1.1rem;
  max-width: 62ch;
}
.shape-live[hidden] { display: none; }
.shape-live b { color: var(--chalk); font-weight: 500; }
.shape-live a { color: var(--jade); }

.histo-oversize {
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--muted);
  margin: 0;
  align-self: center;
  max-width: 60ch;
}

/* ---------- share link ----------
   Appears after a roll. The roll itself goes in the URL fragment, so the
   link works with no server and creates no crawlable URL variants. */
.share { margin-top: .7rem; }
.share[hidden] { display: none; }
.share-btn {
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .04em;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: .3rem .8rem;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease;
}
.share-btn:hover { color: var(--chalk); border-color: var(--jade-dim); }
.share-btn:focus-visible { outline: 2px solid var(--jade); outline-offset: 1px; }

/* ---------- stat roller ----------
   Six rows of four dice. The dropped die stays visible but dimmed, because
   seeing what you lost is half the fun of the method. */
.stat-grid {
  display: grid;
  gap: .45rem;
  margin: .4rem 0 1rem;
}
.stat-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: .5rem .8rem;
  background: var(--raise);
  border: 1px solid var(--edge);
  border-radius: 10px;
  color: var(--chalk);
  font: inherit;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s ease, transform .15s ease;
  animation: tumble .45s cubic-bezier(.18,.86,.28,1.06) backwards;
}
.stat-row:hover { border-color: var(--jade-dim); }
.stat-row:active { transform: translateY(1px); }
.stat-row:focus-visible { outline: 2px solid var(--jade); outline-offset: 1px; }
.stat-dice { display: flex; gap: .4rem; align-items: center; }
.stat-die { width: 34px; height: 34px; display: inline-block; }
.stat-die .die { width: 100%; height: 100%; }
.stat-die.dropped { opacity: .28; }
.stat-face {
  display: inline-grid; place-items: center; width: 100%; height: 100%;
  font-family: var(--mono); font-weight: 600; background: var(--felt);
  border: 1px solid var(--edge); border-radius: 6px;
}
.stat-score {
  font-family: var(--mono);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -.02em;
  min-width: 2ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.stat-mod {
  font-family: var(--mono);
  font-size: .82rem;
  color: var(--muted);
  min-width: 2.4ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.stat-summary {
  font-family: var(--mono);
  font-size: .82rem;
  line-height: 1.6;
  color: var(--muted);
  margin: 0 0 1.1rem;
}
.stat-summary b { color: var(--chalk); font-weight: 500; }
.stat-summary .stat-total b { color: var(--jade); font-size: 1.05em; }
.stat-roller .controls { justify-content: stretch; }
.stat-roller .roll-btn { flex: 1 1 auto; }
.stat-roller .share { margin: 0 0 1rem; }
@media (max-width: 480px) {
  .stat-die { width: 26px; height: 26px; }
  .stat-row { gap: .6rem; padding: .4rem .6rem; }
}

/* ---------- calculator ----------
   Inputs only, no stage. The chart below is the output. */
.calc .controls { align-items: flex-end; }
.calc-answer {
  font-family: var(--mono);
  font-size: .86rem;
  line-height: 1.6;
  color: var(--muted);
  margin: 1rem 0 0;
  max-width: none;
  min-height: 1.4em;
}
.calc-answer b { color: var(--chalk); font-weight: 500; }
.calc-answer b:last-of-type { color: var(--jade); }

/* Plain fallback face, used only if shapes.js is unavailable. */
.die.plain { width: 100%; height: 100%; display: block; }
.stage.idle .die.plain { opacity: .5; }
