@font-face {
  font-family: 'Cinzel';
  src: url('fonts/cinzel-600.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #eceff1;
  --panel: #ffffff;
  --ink: #1b1d21;
  --muted: #474c54;
  --line: #c5cbd2;
  --ctl: #7a828c;
  --hope: #f0c33c;
  --hope-ink: #6b4d00;
  --hope-on: #261b00;
  --hope-soft: #f6e2a4;
  --fear: #4e2d84;
  --fear-ink: #4e2d84;
  --fear-on: #ffffff;
  --fear-soft: #cdbde8;
  --crit: #0b6a5e;
  --crit-on: #ffffff;
  --ok: #3b4656;
  --btn: #1b1d21;
  --btn-on: #ffffff;
  --focus: #0b5fcc;
  --bad: #9b1c1c;
  --display: 'Cinzel', 'Trajan Pro', Georgia, serif;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --r: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --panel: #1c1f25;
    --ink: #eceef1;
    --muted: #b6bcc5;
    --line: #3a3f48;
    --ctl: #7d8592;
    --hope: #e9b93a;
    --hope-ink: #f2c94c;
    --hope-on: #221800;
    --hope-soft: #6b5521;
    --fear: #7a57c4;
    --fear-ink: #c7b2f3;
    --fear-on: #ffffff;
    --fear-soft: #43336a;
    --crit: #3cb6a3;
    --crit-on: #06221e;
    --ok: #a7b2c2;
    --btn: #eceef1;
    --btn-on: #121418;
    --focus: #79b3ff;
    --bad: #ff9b9b;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 var(--body);
}
a { color: inherit; text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--panel); padding: 8px 12px; z-index: 5; }
.skip:focus { left: 8px; }

.top, main, .foot-in { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; padding-bottom: 6px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font: 600 19px/1 var(--display); letter-spacing: .02em; min-height: 44px; }
.brand-mark { width: 40px; height: 24px; }
.bm-hope { fill: var(--hope); }
.bm-fear { fill: var(--fear); }
.top nav a { white-space: nowrap; display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; font-weight: 600; }

h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.2; letter-spacing: .01em; }
h1 { font-size: clamp(26px, 5.6vw, 40px); margin: 8px 0 4px; max-width: 22ch; }
.lede { margin: 0 0 16px; color: var(--muted); max-width: 60ch; }
h2 { font-size: 23px; margin: 0 0 10px; }
h3 { font-size: 18px; margin: 20px 0 4px; }

.tool { display: grid; gap: 20px; align-items: start; }
@media (min-width: 880px) {
  .tool { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 40px; }
}

/* ---------- form ---------- */
.setup { display: grid; gap: 14px; }
.setup .player-only, .setup .gm-only, .more-body { display: grid; gap: 14px; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 2px solid var(--line); }
.modes label { position: relative; }
.modes input, .seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.modes span { display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 4px 6px; font-weight: 600; color: var(--muted); border-bottom: 4px solid transparent; margin-bottom: -2px; text-align: center; line-height: 1.15; }
.modes input:checked + span { color: var(--ink); border-bottom-color: var(--ink); }
.modes input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: -3px; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.num label, .seg legend { display: block; font-weight: 600; margin-bottom: 4px; padding: 0; }
.unit { font-weight: 400; color: var(--muted); }
.unit.short { color: var(--bad); font-weight: 600; }
.step { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; border: 1px solid var(--ctl); border-radius: var(--r); background: var(--panel); overflow: hidden; }
.step input { width: 100%; min-width: 0; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); text-align: center; font: 600 20px/1 var(--body); font-variant-numeric: tabular-nums; color: var(--ink); background: transparent; height: 46px; }
.sbtn { appearance: none; border: 0; background: transparent; color: var(--ink); font: 600 22px/1 var(--body); min-width: 44px; min-height: 44px; cursor: pointer; }
.sbtn:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.sbtn:disabled { color: var(--ctl); cursor: default; background: transparent; }
select { width: 100%; height: 48px; font: 17px var(--body); color: var(--ink); background: var(--panel); border: 1px solid var(--ctl); border-radius: var(--r); padding: 0 10px; }
.step input:focus-visible { outline-offset: -3px; }

.seg { border: 0; margin: 0; padding: 0; min-width: 0; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.seg legend { grid-column: 1 / -1; float: left; width: 100%; }
.seg label { position: relative; }
.seg label span { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 46px; padding: 6px 6px; border: 1px solid var(--ctl); margin-left: -1px; background: var(--panel); line-height: 1.15; }
.seg label:first-of-type span { border-radius: var(--r) 0 0 var(--r); margin-left: 0; }
.seg label:last-of-type span { border-radius: 0 var(--r) var(--r) 0; }
.seg input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; position: relative; z-index: 1; }
.seg-2 { grid-template-columns: 1fr 1fr; }
.hint { margin: -6px 0 0; color: var(--muted); font-size: 16px; }
.more { border-top: 1px solid var(--line); padding-top: 4px; }
.more summary { min-height: 44px; display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; list-style: none; }
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: ''; width: 0; height: 0; border-left: 7px solid currentColor; border-top: 6px solid transparent; border-bottom: 6px solid transparent; transition: transform .15s; }
.more[open] summary::before { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) { .more summary::before { transition: none; } }

.xps { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: center; }
.xps legend { float: left; font-weight: 600; padding: 0; line-height: 1.2; }
.xps legend .unit { display: block; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.xps .warn { grid-column: 1 / -1; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span { display: flex; align-items: center; justify-content: center; gap: 7px; min-width: 62px; min-height: 44px; padding: 0 10px; border: 1px solid var(--ctl); border-radius: var(--r); background: var(--panel); font: 600 19px/1 var(--body); font-variant-numeric: tabular-nums; }
.chip span::before { content: ''; width: 14px; height: 14px; border: 2px solid var(--ctl); border-radius: 3px; flex: none; }
.chip input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip input:checked + span::before { width: 5px; height: 11px; border-width: 0 3px 3px 0; border-color: var(--bg); border-radius: 0; transform: translate(2px, -2px) rotate(45deg); margin: 0 3px 0 2px; }
.chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }
.warn { margin: 8px 0 0; color: var(--bad); font-weight: 600; }
select.on { border: 2px solid var(--ink); font-weight: 600; }
.xedit { border: 0; margin: 0; padding: 0; min-width: 0; }
.xedit legend { font-weight: 600; margin-bottom: 4px; padding: 0; }
.xrows { margin: 0 0 10px; padding: 0; list-style: none; display: grid; gap: 8px; }
.xrows li { display: grid; grid-template-columns: minmax(118px, 170px) auto; justify-content: start; gap: 10px; align-items: center; }
.more-body { padding: 8px 0 4px; }
.share-row { margin: 0; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn { appearance: none; font: 600 16px var(--body); color: var(--ink); background: var(--panel); border: 1px solid var(--ctl); border-radius: var(--r); min-height: 44px; padding: 0 16px; cursor: pointer; }
.btn:hover { border-color: var(--ink); }

/* ---------- odds ---------- */
.play { display: grid; gap: 16px; }
.odds-head { font: 600 18px/1.3 var(--body); margin: 0 0 8px; }
.odds-head .big { font: 700 34px/1 var(--body); margin-right: 4px; font-variant-numeric: lining-nums tabular-nums; }
.bar { display: flex; height: 22px; border-radius: 6px; overflow: hidden; background: var(--line); gap: 2px; }
.bar i { display: block; height: 100%; min-width: 0; }
.bar i.gap { flex: 0 0 4px; background: var(--bg); }
.k-crit { background: var(--crit); }
.k-sHope { background: var(--hope); }
.k-sFear { background: var(--fear); }
.k-fHope { background: var(--hope-soft); }
.k-fFear { background: var(--fear-soft); }
.k-fail, .k-miss { background: var(--line); }
.k-success, .k-hit { background: var(--ok); }
.odds-list { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.odds-list td { padding: 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.odds-list td:last-child { text-align: right; font-weight: 600; white-space: nowrap; padding-left: 12px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; margin-right: 10px; vertical-align: -2px; }
.odds-list tr.sub td { color: var(--muted); font-weight: 400; }
.odds-list tr.sub td:last-child { font-weight: 400; }

.roll { appearance: none; width: 100%; min-height: 60px; border: 0; border-radius: var(--r); background: var(--btn); color: var(--btn-on); font: 600 24px/1 var(--display); letter-spacing: .08em; cursor: pointer; }
.roll:active { transform: translateY(1px); }

/* ---------- result ---------- */
.result { background: var(--panel); border-radius: var(--r); padding: 18px 16px 16px; box-shadow: 0 1px 0 var(--line), 0 6px 20px -12px rgba(0,0,0,.35); }
.result:focus { outline: none; }
.result.none { padding: 12px 16px; }
.result.none .dice { min-height: 0; }
.result.none .verdict { margin: 0; }
@media (max-width: 879px) {
  .odds { display: contents; }
  .odds-head { order: 1; margin: 0 0 -8px; }
  .bar { order: 2; }
  .roll { order: 3; }
  .result { order: 4; }
  .odds-list { order: 5; margin-top: 0; }
  .track { order: 6; }
  .savenote { order: 7; }
  h1 { font-size: 25px; }
  .lede { margin-bottom: 12px; }
  .setup, .setup .player-only, .setup .gm-only { gap: 10px; }
  .tool { gap: 14px; }
  .modes span { min-height: 44px; }
}
.dice { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; min-height: 108px; }
.die { position: relative; display: grid; justify-items: center; gap: 4px; }
.die svg { display: block; }
.die .face { position: absolute; inset: 0 0 auto 0; display: grid; place-items: center; font: 600 32px/1 var(--display); font-variant-numeric: lining-nums; }
.die .dl { font-size: 16px; font-weight: 600; }
.d12 svg { width: 84px; height: 84px; }
.d12 .face { height: 84px; }
.d12.hope path.body { fill: var(--hope); }
.d12.hope .face { color: var(--hope-on); }
.d12.fear path.body { fill: var(--fear); }
.d12.fear .face { color: var(--fear-on); }
.die path.edge { fill: none; stroke: rgba(0,0,0,.28); stroke-width: 1.5; }
.d12.fear path.edge { stroke: rgba(255,255,255,.35); }
.d12.hope .dl { color: var(--hope-ink); }
.d12.fear .dl { color: var(--fear-ink); }
.small svg { width: 50px; height: 50px; }
.small .face { height: 50px; font-size: 22px; }
.small path.body { fill: var(--panel); stroke: var(--ink); stroke-width: 2.5; }
.small.drop path.body { stroke-dasharray: 5 4; stroke: var(--ctl); }
.die.drop svg { opacity: .45; }
.small.drop .face, .gm20.drop .face { color: var(--muted); }
.die.drop .dl { max-width: 64px; text-align: center; line-height: 1.1; }
.small .dl { color: var(--muted); font-weight: 600; }
.small.minus .face::before { content: '\2212'; }
.gm20 svg { width: 84px; height: 84px; }
.gm20 .face { height: 84px; }
.gm20 path.body { fill: var(--ink); }
.gm20 .face { color: var(--bg); font-size: 30px; }
.gm20.drop path.body { fill: none; stroke: var(--ctl); stroke-width: 2.5; stroke-dasharray: 6 5; }

.gm20 path.edge { stroke: color-mix(in srgb, var(--bg) 45%, transparent); }
.gm20.drop path.edge { stroke: var(--line); }
.plus { align-self: center; padding-bottom: 26px; font: 600 22px var(--body); color: var(--muted); }
.total { margin: 12px 0 0; font: 600 22px/1.2 var(--body); }
.total b { font: 700 46px/1 var(--body); font-variant-numeric: lining-nums; margin-right: 8px; }
.total .with-hope { color: var(--hope-ink); }
.total .with-fear { color: var(--fear-ink); }
.verdict { margin: 6px 0 0; font-size: 20px; font-weight: 600; }
.verdict.empty { font-weight: 400; color: var(--muted); font-size: 17px; }
.effect { margin: 4px 0 0; color: var(--muted); }

/* ---------- motion ---------- */
@keyframes tumble {
  0% { transform: translate(-30px, -26px) rotate(-260deg) scale(.55); }
  60% { transform: translate(4px, 4px) rotate(18deg) scale(1.06); }
  80% { transform: translate(-1px, -1px) rotate(-6deg) scale(.98); }
  100% { transform: none; }
}
@keyframes tumble-r {
  0% { transform: translate(30px, -26px) rotate(240deg) scale(.55); }
  60% { transform: translate(-4px, 4px) rotate(-16deg) scale(1.06); }
  80% { transform: translate(1px, -1px) rotate(5deg) scale(.98); }
  100% { transform: none; }
}
.rolling .die svg, .rolling .die .face { animation: tumble .62s cubic-bezier(.2, .7, .3, 1) both; }
.rolling .die.fear svg, .rolling .die.fear .face, .rolling .die:nth-child(even) svg, .rolling .die:nth-child(even) .face { animation-name: tumble-r; }
.rolling .total, .rolling .verdict, .rolling .effect { animation: settle .25s ease-out .5s both; }
@keyframes settle { from { opacity: .25; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .rolling .die svg, .rolling .die .face, .rolling .total, .rolling .verdict, .rolling .effect { animation: none !important; }
}

/* ---------- trackers ---------- */
.track { display: grid; gap: 8px; }
.tk { display: grid; grid-template-columns: 76px 44px 2.4ch 44px 1fr; align-items: center; gap: 6px; }
.tk-name { font-weight: 600; }
.tk-hope .tk-name { color: var(--hope-ink); }
.tk-fear .tk-name { color: var(--fear-ink); }
.tk-val { font: 700 22px/1 var(--body); font-variant-numeric: lining-nums tabular-nums; text-align: center; }
.tk .sbtn { border: 1px solid var(--ctl); border-radius: var(--r); background: var(--panel); }
.pips { display: flex; flex-wrap: wrap; gap: 4px; padding-left: 6px; }
.pips i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ctl); }
.tk-hope .pips i.on { background: var(--hope); border-color: var(--hope); }
.tk-fear .pips { display: grid; grid-template-columns: repeat(6, 11px); }
.tk-fear .pips i { width: 11px; height: 11px; }
.tk-fear .pips i.on { background: var(--fear); border-color: var(--fear); }
.savenote, .linknote { margin: 0; padding: 10px 12px; border-radius: var(--r); background: var(--panel); border: 1px solid var(--line); }
.linknote p { margin: 0 0 8px; }
.linknote .btn + .btn { margin-left: 8px; }

/* ---------- log ---------- */
.log { margin-top: 36px; }
.log-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.log-top h2 { margin: 0; }
.entries { list-style: none; margin: 10px 0 0; padding: 0; }
.entries li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.entries .what { font-weight: 600; }
.entries .when { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.entries .how { grid-column: 1 / -1; color: var(--muted); font-variant-numeric: tabular-nums; }
.o-hope { color: var(--hope-ink); }
.o-fear { color: var(--fear-ink); }
.o-crit { color: var(--crit); }
.empty { color: var(--muted); }
.confirm { margin-top: 10px; padding: 10px 12px; background: var(--panel); border-radius: var(--r); border: 1px solid var(--line); }
.confirm p { margin: 0 0 8px; }
.confirm .btn + .btn { margin-left: 8px; }
.bins { margin-top: 12px; }
.bins summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
.bins ul { list-style: none; padding: 0; margin: 0; }
.bins li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }

/* ---------- article ---------- */
.about { max-width: 70ch; margin: 44px 0 0; }
.about h2 { margin-top: 32px; }
.about p { margin: 0 0 12px; }
.faq h3 { font-family: var(--body); font-weight: 700; font-size: 18px; letter-spacing: 0; }
.credit { margin-top: 28px !important; color: var(--muted); }

/* ---------- odds page ---------- */
.crumbs { margin: 6px 0 0; color: var(--muted); }
.crumbs a { color: var(--ink); }
.otable-wrap { margin: 12px 0 28px; }
.otable { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.otable caption { text-align: left; font: 600 20px/1.3 var(--display); padding: 0 0 6px; }
.otable th, .otable td { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.otable th:first-child, .otable td:first-child { text-align: left; }
.otable thead th { font-size: 16px; vertical-align: bottom; border-bottom: 2px solid var(--ink); }
.otable thead tr.grp th, .otable thead tr.grp td { border-bottom: 1px solid var(--line); text-align: center; font-weight: 600; }
.about.first { margin-top: 12px; }
.otable td.main { font-weight: 700; }
.otable-note { margin: 8px 0 0; max-width: 70ch; }
.otable .h { color: var(--hope-ink); }
.otable .f { color: var(--fear-ink); }
.picker { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 8px 0 0; }
@media (max-width: 560px) {
  .otable .opt { display: none; }
  .otable th, .otable td { padding: 6px 3px; }
}
@media (max-width: 340px) {
  .otable th, .otable td { padding: 6px 1px; }
  .otable td:first-child, .otable th:first-child { padding-right: 0; }
}

/* ---------- footer ---------- */
.foot { margin-top: 56px; border-top: 1px solid var(--line); padding: 20px 0 32px; color: var(--muted); }
.sb-footer p { margin: 0 0 10px; }
.sb-more { font-size: 16px; line-height: 1.7; }
.sb-more a { color: var(--ink); }
.sb-credit a { color: var(--ink); }

@media (max-width: 400px) {
  body { font-size: 16px; }
  .brand { font-size: 16px; gap: 8px; }
  .brand-mark { width: 32px; height: 20px; }
  .d12 svg, .gm20 svg { width: 72px; height: 72px; }
  .d12 .face, .gm20 .face { height: 72px; font-size: 28px; }
  .seg label span { font-size: 16px; padding: 6px 2px; letter-spacing: -.01em; }
  .seg:not(.seg-2) { grid-template-columns: 1.4fr .75fr 1.15fr; }
  .tk { grid-template-columns: 70px 44px 2.4ch 44px 1fr; }
}

@media print {
  body { background: #fff; color: #000; font-size: 11pt; }
  .top nav, .skip, .setup, .play, .about, .foot, .log-actions, .bins, .confirm, .empty { display: none !important; }
  .tool { display: block; }
  h1 { font-size: 18pt; margin: 0; }
  .lede { display: none; }
  .log { margin-top: 8pt; }
  .entries li { break-inside: avoid; border-color: #999; padding: 4pt 0; }
  .entries .when, .entries .how { color: #333; }
  .o-hope, .o-fear, .o-crit { color: #000; }
  .print-head { display: block !important; margin: 0 0 6pt; }
  .otable-page .top, .otable-page .crumbs, .otable-page .about { display: none !important; }
  .otable-page .about.setup-note { display: block !important; max-width: none; margin: 0 0 8pt; font-size: 10pt; }
  .otable-page .setup-note p { margin: 0 0 4pt; }
  .otable-page h1 { font-size: 16pt; max-width: none; }
  .otable { font-size: 10pt; }
  .otable caption { font-size: 13pt; }
  .otable th, .otable td { border-color: #999; padding: 1.5pt 4pt; }
  .otable thead th { font-size: 10pt; }
  .otable .h, .otable .f { color: #000; }
  .otable-wrap { break-inside: avoid; margin: 0 0 10pt; }
  .otable-wrap + .otable-wrap { break-before: page; }
  #gm { break-before: auto; margin-top: 18pt; }
  .otable-note { font-size: 10pt; margin-top: 6pt; }
  .otable .opt { display: table-cell !important; }
  /* With an empty log, print the odds of the current setup instead of a blank page. */
  .log-empty .play { display: block !important; }
  .log-empty .play > :not(#odds), .log-empty .log, .log-empty #bar, .log-empty .sw { display: none !important; }
  .log-empty .odds { margin-top: 10pt; border: 0; padding: 0; background: none; box-shadow: none; }
  .log-empty .odds-head { margin: 0 0 4pt; }
  .log-empty .print-setup { display: block !important; margin: 0 0 8pt; }
  .log-empty .odds-list { width: auto; min-width: 60%; }
  .log-empty .odds-list td { border-color: #999; padding: 3pt 12pt 3pt 0; }
  .log-empty .odds-list tr.sub td { color: #333; }
}
.print-head, .print-setup { display: none; }
