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

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;700&family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

: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;
}
.die-facet {
  fill: none;
  stroke: var(--jade);
  stroke-width: 1.1;
  stroke-linejoin: round;
  opacity: .32;
}
.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; }

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

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