/* Blades Dice Odds: Doskvol after dark. Lamp-black slate, brass, bone dice and oxblood for the bad news.
   Light mode is canal fog with ink. One heading face (Alegreya SC 700, self-hosted), system sans for reading. */
@font-face {
  font-family: 'Alegreya SC';
  src: url('fonts/alegreya-sc-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}
:root {
  --bg: #e7e5de;
  --surface: #f5f3ed;
  --ink: #181c20;
  --muted: #464c53;
  --line: #8d8f8c;
  --rule: #c9c5b8;
  --bar: #2b3640;
  --track: #d6d2c6;
  --bad: #9c2f1c;
  --brass: #7c530c;        /* brass as text on the fog */
  --plate: #1d262e;        /* header band and the Roll button */
  --plate-ink: #f2dc9e;
  --sel: #1d262e;
  --sel-ink: #f6ecd2;
  --frame: #a8761a;        /* the die that counts */
  --focus: #0a5f8f;
  --die: #f1e9d6;
  --die-edge: #a99a78;
  --pip: #1b1611;
  --box: #181c20;
  --head: 'Alegreya SC', 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --ds: 46px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171c;
    --surface: #1a2128;
    --ink: #ece4d3;
    --muted: #bdb5a4;
    --line: #6c7682;
    --rule: #2f3943;
    --bar: #d9c48f;
    --track: #2b343d;
    --bad: #f2937a;
    --brass: #e3b55a;
    --plate: #0b0f13;
    --plate-ink: #e8c46e;
    --sel: #e3b55a;
    --sel-ink: #12171c;
    --frame: #e3b55a;
    --focus: #7cc4ef;
    --die: #ece2cb;
    --die-edge: #8f8266;
    --pip: #17130f;
    --box: #ece4d3;
    color-scheme: dark;
  }
}

* { 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: var(--brass); text-underline-offset: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
[hidden] { display: none !important; }
h1, h2, .brand, .roll, .big, .tn { font-family: var(--head); font-weight: 700; }

/* header: a dark plate with a double brass rule, like a shop sign */
.top { background: var(--plate); color: var(--plate-ink); border-bottom: 4px double var(--plate-ink); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 4px 12px; min-height: 56px; flex-wrap: wrap; }
@media (max-width: 480px) {
  .top-in { flex-wrap: nowrap; }
  .brand { font-size: 17px; gap: 8px; white-space: nowrap; }
  .brand svg { flex: none; }
  .top nav a { padding: 8px 2px 8px 6px; font-size: 16px; white-space: nowrap; }
  .top nav a[aria-current] { display: none; }
}
@media (max-width: 350px) {
  .top-in { flex-wrap: wrap; }
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--plate-ink); text-decoration: none; font-size: 22px; letter-spacing: .02em; }
.top nav { display: flex; gap: 4px; }
.top nav a { color: var(--plate-ink); text-decoration: none; padding: 10px 10px; min-height: 44px; display: inline-flex; align-items: center; }
.top nav a[aria-current="page"] { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 6px; }

.hero { padding: 18px 0 6px; }
h1 { font-size: 34px; line-height: 1.1; margin: 0 0 6px; letter-spacing: .01em; }
.lede { margin: 0; color: var(--muted); max-width: 62ch; }

/* ---------- tool ---------- */
.tool { min-height: 560px; padding: 12px 0 8px; }
.tool-in { display: grid; gap: 20px; }
@media (min-width: 900px) {
  .tool-in { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 32px; align-items: start; }
  .tool-in > .right > .ask { margin: 0 0 16px; }
}
.controls { display: grid; gap: 16px; }
.ask { display: grid; gap: 16px; margin-top: 16px; }
.panel { display: grid; gap: 14px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend, .field > label { display: block; font-weight: 600; margin-bottom: 6px; padding: 0; }
.hint { margin: 4px 0 0; color: var(--muted); font-size: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: flex-start; }
.field { min-width: 0; }
.field.wide { flex: 1 1 100%; }

.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 3px; overflow: hidden; }
.seg label { position: relative; display: block; }
.seg label + label { border-left: 1px solid var(--line); }
.types .seg label:nth-child(4) { border-left: 0; }
.types .seg label:nth-child(n+4) { border-top: 1px solid var(--line); }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 6px 4px; text-align: center; line-height: 1.15; background: var(--surface); }
.seg input:checked + span { background: var(--sel); color: var(--sel-ink); font-weight: 700; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: -3px; }
.types legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
/* narrow phones: a wider first column so "Engagement" fits at 320 px */
@media (max-width: 380px) { .types .seg { grid-template-columns: 1.25fr 1fr 1fr; } }
/* phones: tighter spacing so the odds start on the first screen */
@media (max-width: 480px) {
  .hero { padding: 12px 0 2px; }
  .controls, .ask { gap: 12px; }
  .ask { margin-top: 12px; }
  .panel { gap: 10px; }
  legend, .field > label { margin-bottom: 4px; }
  .odds { gap: 2px; }
  .orow { min-height: 26px; line-height: 1.3; }
  .tool { padding-top: 6px; }
  /* each bonus button names its die ("Assist +1d"), so the heading can go on phones (kept for screen readers) */
  .bonus legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); }
.stepper input { width: 52px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); text-align: center; font: 700 20px/1 var(--body); color: var(--ink); background: transparent; min-height: 44px; }
.step { min-width: 44px; min-height: 44px; border: 0; background: transparent; color: var(--ink); font: 700 22px/1 var(--body); cursor: pointer; }
.step:disabled { color: var(--line); cursor: default; }
select, input[type=text] { font: 17px var(--body); color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 3px; min-height: 44px; padding: 6px 10px; max-width: 100%; }
.field.wide input { width: 100%; }

.check { display: flex; gap: 10px; align-items: flex-start; min-height: 44px; padding: 10px 0 4px; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--sel); flex: none; }
.seg input[type=checkbox]:checked + span { background: var(--sel); color: var(--sel-ink); font-weight: 700; }
.checks { display: grid; gap: 0 18px; }
@media (min-width: 560px) { .checks { grid-template-columns: 1fr 1fr; } .checks legend { grid-column: 1 / -1; } }
.pcs { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.pc-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.pool { margin: 0; }
.pool strong { font-size: 19px; }
.warn { color: var(--bad); font-weight: 600; }

/* odds: label, bar, number; bars are decoration, the numbers carry it */
.odds { display: grid; gap: 4px; }
.orow { display: grid; grid-template-columns: minmax(7.5em, auto) 1fr 4.6em; align-items: center; gap: 10px; min-height: 28px; }
.ol { white-space: nowrap; }
.ob { height: 10px; background: var(--track); display: block; }
.ob span { display: block; height: 100%; background: var(--bar); }
.orow.bad .ob span { background: var(--bad); }
.op { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.osub { margin: 8px 0 0; font-weight: 600; }
.osum { margin: 6px 0 0; }

.roll { width: 100%; min-height: 56px; border: 0; border-radius: 3px; background: var(--plate); color: var(--plate-ink); font-size: 24px; letter-spacing: .03em; cursor: pointer; scroll-margin-top: 8px; }
@media (prefers-color-scheme: dark) { .roll { background: var(--brass); color: #12171c; } }
.roll:active { transform: translateY(1px); }

.btn { font: 600 16px var(--body); min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); color: var(--ink); cursor: pointer; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.btn.act { border-color: var(--ink); border-width: 2px; }
.btn.danger { color: var(--bad); border-color: var(--bad); }

.more { border-top: 1px solid var(--rule); padding-top: 4px; margin-top: 14px; }
.more summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 600; }
.more-in { display: grid; gap: 14px; padding: 8px 0 12px; }
.more .seg { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 320px; }
.share { display: grid; gap: 8px; justify-items: start; }
.share input { width: 100%; }
.savenote { margin: 0 0 12px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); }
.linknote .btn { margin-top: 6px; }

/* ---------- result: the one card ---------- */
.result { background: var(--surface); border: 1px solid var(--rule); padding: 16px; scroll-margin-top: 8px; }
.result:focus { outline: none; }
.result .empty { color: var(--muted); margin: 0; }
.kind { margin: 0; font-weight: 600; }
.kind .sub { font-weight: 400; color: var(--muted); }
.big { margin: 4px 0 10px; display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 14px; line-height: 1; }
.big .num { font-size: 60px; }
.big .word { font-size: 30px; }
.result[data-band="bad"] .big { color: var(--bad); }
.dice { display: flex; flex-wrap: wrap; gap: 12px; padding: 6px 0 4px; }
.out p { margin: 8px 0 0; max-width: 60ch; }
.zero { margin: 4px 0 0; color: var(--muted); }
.ap { margin: 14px 0 0; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.pcs-out { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pcs-out li { display: grid; grid-template-columns: 3.4em 1fr auto; align-items: center; gap: 10px; }
.pcs-out .dice { padding: 0; gap: 8px; }
.pcs-out .pcb { font-weight: 700; font-variant-numeric: tabular-nums; }
.pcs-out li.lead .pcn::after { content: ' best'; font-weight: 600; color: var(--brass); }
.pcs-out .pcn { font-weight: 600; }

/* bone d6 cubes: transforms only. .die (slot, outline frame when it counts) > .cw (perspective) > .cube > 6 faces */
.die { display: inline-block; width: var(--ds); height: var(--ds); border-radius: 7px; outline: 3px solid transparent; outline-offset: 4px; }
.die.counts { outline-color: var(--frame); }
.cw { display: block; width: 100%; height: 100%; perspective: 260px; }
.cube { position: relative; display: block; width: 100%; height: 100%; transform-style: preserve-3d; }
.f { position: absolute; inset: 0; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 15%; background: var(--die); border: 1px solid var(--die-edge); border-radius: 7px; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.fF { transform: translateZ(calc(var(--ds) / 2)) scale(.94); }
.fB { transform: rotateY(180deg) translateZ(calc(var(--ds) / 2)); }
.fT { transform: rotateX(90deg) translateZ(calc(var(--ds) / 2)); }
.fD { transform: rotateX(-90deg) translateZ(calc(var(--ds) / 2)); }
.fR { transform: rotateY(90deg) translateZ(calc(var(--ds) / 2)); }
.fL { transform: rotateY(-90deg) translateZ(calc(var(--ds) / 2)); }
.f i { width: 78%; aspect-ratio: 1; border-radius: 50%; background: var(--pip); place-self: center; }
.f[data-v="1"] i { grid-area: 2 / 2; }
.f[data-v="2"] i:nth-child(1), .f[data-v="3"] i:nth-child(1) { grid-area: 1 / 3; }
.f[data-v="2"] i:nth-child(2), .f[data-v="3"] i:nth-child(3) { grid-area: 3 / 1; }
.f[data-v="3"] i:nth-child(2), .f[data-v="5"] i:nth-child(5) { grid-area: 2 / 2; }
.f[data-v="4"] i:nth-child(1), .f[data-v="5"] i:nth-child(1), .f[data-v="6"] i:nth-child(1) { grid-area: 1 / 1; }
.f[data-v="4"] i:nth-child(2), .f[data-v="5"] i:nth-child(2), .f[data-v="6"] i:nth-child(2) { grid-area: 1 / 3; }
.f[data-v="4"] i:nth-child(3), .f[data-v="5"] i:nth-child(3), .f[data-v="6"] i:nth-child(3) { grid-area: 3 / 1; }
.f[data-v="4"] i:nth-child(4), .f[data-v="5"] i:nth-child(4), .f[data-v="6"] i:nth-child(4) { grid-area: 3 / 3; }
.f[data-v="6"] i:nth-child(5) { grid-area: 2 / 1; }
.f[data-v="6"] i:nth-child(6) { grid-area: 2 / 3; }
.pcs-out .die { --ds: 38px; }
@media (min-width: 900px) { .result > .dice > .die { --ds: 54px; } }

/* ---------- stress tracker ---------- */
.stress { margin-top: 18px; }
.stress h2 { font-size: 24px; margin: 0 0 8px; }
.track { display: grid; grid-template-columns: 4.6em 1fr auto auto auto; align-items: center; gap: 6px 8px; min-height: 48px; }
.tn { font-size: 19px; }
.tv { font-variant-numeric: tabular-nums; white-space: nowrap; padding: 0 4px; }
.track .step { border: 1px solid var(--line); border-radius: 3px; background: var(--surface); }
/* one row of slanted boxes, as on the sheet: they narrow rather than wrap, and a filled face keeps them from reading
   as missing-character boxes */
.boxes { display: flex; flex-wrap: nowrap; gap: 4px; min-width: 0; }
.boxes span { flex: 0 1 18px; min-width: 10px; height: 24px; border: 3px solid var(--box); background: var(--surface); transform: skewX(-12deg); }
.boxes span.on { background: var(--box); }
.boxes.tb span { flex-basis: 24px; border-color: var(--muted); }
.boxes.tb span.on { background: var(--bad); border-color: var(--bad); }
.full { margin: 8px 0 0; font-weight: 600; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
@media (max-width: 420px) {
  .track { grid-template-columns: auto 1fr auto auto; }
  .track .tn { grid-column: 1; grid-row: 1; }
  .track .tv { grid-column: 2; grid-row: 1; }
  .track .step:nth-of-type(1) { grid-column: 3; grid-row: 1; }
  .track .step:nth-of-type(2) { grid-column: 4; grid-row: 1; }
  .track .boxes { grid-column: 1 / -1; grid-row: 2; padding: 0 0 6px 4px; }
}

/* ---------- log ---------- */
.logbox { margin: 28px 0 0; border-top: 4px double var(--rule); padding-top: 8px; }
.logbox h2 { font-size: 26px; margin: 4px 0 8px; }
.log { list-style: none; margin: 0; padding: 0; }
.log li { padding: 8px 0; border-bottom: 1px solid var(--rule); }
.lt { color: var(--muted); font-variant-numeric: tabular-nums; }
.lf { display: block; color: var(--muted); font-variant-numeric: tabular-nums; letter-spacing: .06em; }
.log-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.confirm { margin: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bins { margin-top: 12px; }
.bins summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; }
.empty { color: var(--muted); }
.print-only { display: none; }

/* ---------- content ---------- */
.content { max-width: 72ch; padding: 20px 0 32px; }
.content h2 { font-size: 26px; margin: 28px 0 8px; line-height: 1.2; }
.example { padding-left: 14px; border-left: 2px solid var(--line); }
.faq details { border-bottom: 1px solid var(--rule); }
.faq summary { cursor: pointer; padding: 12px 0; min-height: 44px; font-weight: 600; }
.faq details p { margin: 0 0 14px; }
.sources, .tm { color: var(--muted); }
.note { padding: 12px; background: var(--surface); }

/* odds tables page */
.crumb { margin: 12px 0 0; }
.crumb a { display: inline-flex; min-height: 44px; align-items: center; }
.tables h2 { font-size: 26px; margin: 30px 0 6px; line-height: 1.2; }
.tables p { max-width: 70ch; }
.table-wrap { overflow-x: auto; max-width: 100%; }
table.t { border-collapse: collapse; font-variant-numeric: tabular-nums; margin: 8px 0 4px; }
table.t caption { text-align: left; font-weight: 600; padding: 0 0 6px; }
table.t th, table.t td { padding: 7px 10px; border-bottom: 1px solid var(--rule); text-align: right; white-space: nowrap; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t thead th { border-bottom: 2px solid var(--ink); vertical-align: bottom; white-space: normal; }
table.t td.hi { font-weight: 700; }
.printbtn { margin-top: 12px; }
/* phones and narrow tablets: each row becomes a card (row label on the left, every number with its own label), so
   nothing scrolls sideways */
@media screen and (max-width: 820px) {
  table.t, table.t tbody, table.t caption { display: block; }
  table.t thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  table.t tbody tr { display: grid; grid-template-columns: 4.6em repeat(var(--c, 3), minmax(0, 1fr)); gap: 4px 8px; padding: 8px 0 10px; border-bottom: 1px solid var(--rule); }
  table.t tbody th, table.t td { border: 0; padding: 0; white-space: normal; text-align: left; line-height: 1.3; }
  table.t tbody th { grid-column: 1; grid-row: 1 / span var(--r, 2); }
  table.t tbody th[data-l] { font-size: 0; }
  table.t tbody th[data-l]::before { content: attr(data-l); font-size: 16px; }
  table.t td { display: flex; flex-direction: column; }
  table.t td::before { content: attr(data-l); color: var(--muted); font-weight: 400; }
}
/* the narrowest phones: the row label goes on its own line above the numbers */
@media screen and (max-width: 359px) {
  table.t tbody tr { grid-template-columns: repeat(var(--c, 3), minmax(0, 1fr)); }
  table.t tbody th { grid-column: 1 / -1; grid-row: auto; }
}

/* ---------- footer ---------- */
footer { border-top: 4px double var(--rule); padding: 18px 0 30px; color: var(--muted); }
.sb-footer p { margin: 0 0 10px; font-size: 16px; }
.sb-more a { color: var(--ink); }
.sb-credit a, .sb-privacy a { color: var(--brass); }

@media (max-width: 380px) {
  h1 { font-size: 29px; }
  .big .num { font-size: 52px; }
  .orow { grid-template-columns: minmax(6.6em, auto) 1fr 4.4em; gap: 8px; }
}

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

/* ---------- print: the roll log as a plain table, or the odds tables; never the controls ---------- */
@media print {
  :root { --bg: #fff; --surface: #fff; --ink: #000; --muted: #333; --rule: #999; --line: #666; color-scheme: light; }
  body { font: 11pt/1.4 Georgia, 'Times New Roman', serif; background: #fff; color: #000; }
  .top, .skip, .hero .lede, #tool, footer, .content, .log, .log-acts, .bins, .logbox > h2, .logbox > .empty, .printbtn, .crumb, nav { display: none !important; }
  .hero { padding: 0; }
  h1 { font-size: 18pt; margin: 0 0 6pt; }
  .print-only { display: table; }
  main:has(.logbox) .hero { display: none; }
  .plog caption { text-align: left; font: 700 14pt Georgia, serif; padding: 0 0 8pt; }
  .logbox { border: 0; margin: 0; padding: 0; }
  .plog { width: 100%; border-collapse: collapse; table-layout: fixed; }
  .plog th { text-align: left; font-size: 10.5pt; padding: 0 4pt 4pt; border-bottom: 1pt solid #000; }
  .plog td { font-size: 10pt; line-height: 1.3; padding: 3pt 4pt; border: .5pt solid #777; vertical-align: top; overflow-wrap: break-word; }
  .plog tr { break-inside: avoid; }
  /* the last page never holds a lone roll: the last three rows stay together */
  .plog:not(.blank) tbody tr:nth-last-child(-n+2) { break-before: avoid; }
  .plog th:nth-child(1) { width: 13%; } .plog th:nth-child(2) { width: 14%; } .plog th:nth-child(3) { width: 29%; }
  .plog th:nth-child(4) { width: 15%; } .plog th:nth-child(5) { width: 17%; } .plog th:nth-child(6) { width: 12%; }
  .plog.blank td { height: 26pt; }
  .plog .fill { display: inline-block; width: 45%; border-bottom: .75pt solid #000; height: 12pt; vertical-align: baseline; }
  .tables h2 { font-size: 13pt; margin: 12pt 0 4pt; break-after: avoid; }
  .tables p { margin: 0 0 4pt; font-size: 10pt; }
  .tables .table-wrap { overflow: visible; break-inside: avoid; }
  .tsec { break-inside: avoid; }
  table.t { font-size: 9.5pt; break-inside: avoid; }
  table.t th, table.t td { padding: 2.5pt 6pt; border-bottom: .5pt solid #999; }
  table.t thead th { border-bottom: 1pt solid #000; }
  .tables .print-note { display: block; }
  a { color: #000; text-decoration: none; }
}
@page { margin: 14mm; }
