/* ---- tokens and type (P10) ----
   Two materials: paper (cards, tiles, buttons, sheets) with ink on it, and the dark table with chalk on it.
   One typeface, Averia Serif Libre. One red, for damage only. */
@font-face {
  font-family: "Averia Serif Libre";
  src: url("assets/fonts/AveriaSerifLibre-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Averia Serif Libre";
  src: url("assets/fonts/AveriaSerifLibre-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --table: #111214; --rule: #2e3034;
  --chalk: #dcdddf; --chalk-dim: #a0a3a8; --chalk-faint: #6a6d73;
  --paper: #e0e0e0; --ink: #1b1c1e; --ink-dim: #55575c;
  --danger: #e5484d;
  --paper-tex: none; --table-tex: none;                 /* drawn by art.js at start (panels.dress) */
  --serif: "Averia Serif Libre", Georgia, serif;
  --r: 4px;
  --lift: 0 2px 0 rgba(0, 0, 0, .55), 0 10px 20px rgba(0, 0, 0, .45);
  --spring: cubic-bezier(.3, 1.5, .5, 1);
  --press: 90ms;
}

/* ---- page ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
h1, h2, h3, h4, p { margin: 0; }
body {
  background: var(--table) var(--table-tex);
  color: var(--chalk);
  font: 15px/1.45 var(--serif);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
:focus-visible { outline: 2px solid var(--chalk); outline-offset: 3px; }
.defs { position: absolute; width: 0; height: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.dim { color: var(--chalk-dim); }
.small { font-size: 13px; }
.label { font: 700 11px/1.2 var(--serif); letter-spacing: .16em; text-transform: uppercase; color: var(--chalk-faint); }
.portrait, .trait { filter: grayscale(1) contrast(1.05); }

/* Scrollbars: thin chalk on the table, thin ink on paper. Scrollers keep their gutter and never drag the page behind. */
* { scrollbar-width: thin; scrollbar-color: var(--chalk-faint) transparent; }
.sheet-card, .sheet-card * { scrollbar-color: rgba(27, 28, 30, .35) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 10px; background: var(--chalk-faint) padding-box; }
.sheet-card::-webkit-scrollbar-thumb, .sheet-card ::-webkit-scrollbar-thumb { background-color: rgba(27, 28, 30, .35); }
#ledger, .hand, .sheet-card { overscroll-behavior: contain; }
#ledger { scrollbar-gutter: stable; }
/* A soft fade at whichever edge still has more to scroll (where scroll-driven animation exists; elsewhere, no fade). */
@property --fade-top { syntax: "<length>"; inherits: false; initial-value: 0px; }
@property --fade-end { syntax: "<length>"; inherits: false; initial-value: 0px; }
@keyframes edge-fade { from { --fade-top: 0px; --fade-end: 22px; } 12% { --fade-top: 22px; } 88% { --fade-end: 22px; } to { --fade-top: 22px; --fade-end: 0px; } }
@supports (animation-timeline: scroll()) {
  .fades { mask-image: linear-gradient(#0000, #000 var(--fade-top), #000 calc(100% - var(--fade-end)), #0000);
    animation: edge-fade linear both; animation-timeline: scroll(self); }
  @media (min-width: 1024px) { .hand.fades { mask-image: none; animation: none; } }   /* one row that never scrolls */
}

/* Pen-drawn glyphs: the same stroke as the room emblems. */
.icon { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 4.5;
  stroke-linecap: round; stroke-linejoin: round; filter: url(#pen); }

/* ---- layout (P1): phone first, desktop from 1024px ---- */
body {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(150px, 1fr) auto;
  grid-template-areas: "hud" "routes" "board" "sheet";
}
@media (min-width: 1024px) {
  body {
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "hud hud" "board routes" "board ledger" "sheet sheet";
  }
}

/* ---- buttons: chalk outlines on the table, paper for the main action; all sink when pressed (P0) ---- */
.btn {
  position: relative; font: inherit; color: var(--chalk); background: transparent; border: 0; border-radius: var(--r);
  min-height: 44px; min-width: 44px; padding: 8px 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 220ms var(--spring), box-shadow 160ms, background 160ms;
}
.btn::before {
  content: ""; position: absolute; inset: 0; border: 1.5px solid var(--chalk-faint); border-radius: inherit;
  filter: url(#pen); pointer-events: none; transition: border-color 160ms;
}
.btn:hover:not(:disabled)::before { border-color: var(--chalk-dim); }
.btn:active:not(:disabled) { transform: translateY(2px); transition-duration: var(--press); }
.btn:disabled { cursor: default; opacity: .5; }
.btn.icon-btn { padding: 0; width: 44px; }
.btn.paper, .btn[aria-pressed="true"] { background: var(--paper) var(--paper-tex); color: var(--ink); box-shadow: var(--lift); }
.btn.paper::before, .btn[aria-pressed="true"]::before { inset: 3px; border-width: 1px; border-color: var(--ink); }
.btn.paper { font-weight: 700; }
.btn.paper:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 0 0 rgba(0, 0, 0, .55), 0 3px 8px rgba(0, 0, 0, .4); }
.btn.paper:disabled { opacity: 1; background: transparent; color: var(--chalk-dim); box-shadow: none; }
.btn.paper:disabled::before { inset: 0; border: 1.5px dashed var(--chalk-faint); }

/* ---- ui/panels.js: the HUD ---- */
#hud { grid-area: hud; display: flex; align-items: center; gap: 22px; padding: 8px 16px; min-height: 60px; border-bottom: 1px solid var(--rule); }
.wordmark { display: none; font: 700 19px/1 var(--serif); letter-spacing: .18em; color: var(--chalk); padding-right: 8px; }
.stat { display: grid; gap: 3px; white-space: nowrap; }
.stat > b { font: 700 18px/1 var(--serif); }
.stat small { color: var(--chalk-faint); font-size: 13px; font-weight: 400; }
.depth { display: inline-flex; gap: 3px; margin-left: 8px; vertical-align: middle; }
.depth i { width: 9px; height: 4px; border-radius: 1px; background: var(--chalk-faint); opacity: .5; }
.depth i.on { background: var(--chalk); opacity: 1; }
.hearts { display: inline-flex; gap: 3px; align-items: center; }
.hearts .icon { width: 20px; height: 20px; stroke-width: 5; }
.hearts .full { fill: var(--chalk); color: var(--chalk); }
.hearts .lost { color: var(--chalk-faint); }
.hearts .lost:is(b) { color: var(--danger); font-size: 15px; }
/* The selected route's descents: a diamond for each, filled once spent; the last one left turns red. */
.descents .notches { display: inline-flex; align-items: center; gap: 8px; height: 20px; padding-left: 2px; }
.descents .notches i { width: 9px; height: 9px; transform: rotate(45deg); border: 1.5px solid var(--chalk-dim); }
.descents .notches i.used { background: var(--chalk-dim); }
.descents.warn .notches i:not(.used) { border-color: var(--danger); }
.descents.solved .notches i { opacity: .4; }
.descents .tick { width: 17px; height: 17px; stroke-width: 7; filter: none; color: var(--chalk); }
.hud-buttons { margin-left: auto; display: flex; gap: 6px; }
@media (min-width: 1024px) {
  #hud { padding: 8px 24px; gap: 30px; }
  .wordmark { display: block; }
  .notes-btn { display: none; }
}
@media (max-width: 1023px) {
  #hud { gap: 16px; padding: 6px 12px; min-height: 56px; }
  #hud .label { letter-spacing: .1em; }
  .hud-buttons { gap: 4px; }
}
@media (max-width: 420px) { .depth { display: none; } }

/* ---- ui/panels.js: the route bar ---- */
#routes { grid-area: routes; display: flex; align-items: center; gap: 12px; padding: 10px 12px 0; min-width: 0; }
.tabs { display: flex; gap: 6px; flex: none; }
.btn.tab { width: 46px; padding: 0; font: 700 16px/1 var(--serif); letter-spacing: .04em; }
.btn.tab .tick { position: absolute; top: -7px; right: -7px; width: 19px; height: 19px; padding: 2px; border-radius: 50%;
  background: var(--chalk); color: var(--ink); stroke-width: 8; filter: none; }
.route-name { min-width: 0; font: 700 17px/1.2 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 1024px) {
  #routes { flex-direction: column; align-items: flex-start; gap: 14px; padding: 18px 24px 4px; border-left: 1px solid var(--rule); }
  .route-name { font-size: 21px; white-space: normal; }
}

/* ---- ui/board.js ---- */
#board {
  grid-area: board; display: block; width: 100%; height: 100%; min-width: 0; min-height: 0; touch-action: manipulation;
  background: radial-gradient(ellipse 55% 50% at 50% 52%, rgba(255, 255, 255, .07), transparent 72%);
  transition: opacity 200ms ease;
}
#board.dim { opacity: .35; }
.board-labels { position: fixed; pointer-events: none; overflow: hidden; display: none; z-index: 1; }
.board-labels span {
  position: absolute; transform: translate(-50%, -30%); width: max-content; max-width: var(--tile, 90px); padding: 3px 6px 2px; border-radius: 2px;
  font: 700 10px/1.15 var(--serif); letter-spacing: .08em; text-transform: uppercase; text-align: center;
  color: var(--ink); background: var(--paper) var(--paper-tex); box-shadow: 0 3px 8px rgba(0, 0, 0, .6);
  opacity: 0; transition: opacity 160ms;
}
.board-labels span.on { opacity: 1; }
@media (min-width: 1024px) { .board-labels { display: block; } }

/* ---- ui/hand.js: party bar, highlighter, hand ---- */
#sheet {
  grid-area: sheet; min-height: 0; display: grid; gap: 10px 16px;
  grid-template-columns: minmax(0, 1fr); grid-template-areas: "party" "filter" "hand";
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule); background: linear-gradient(rgba(0, 0, 0, .05), rgba(0, 0, 0, .4));
}
@media (min-width: 1024px) {
  #sheet { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "filter party" "hand hand"; align-items: end; padding: 12px 24px 18px; }
}

.filter { grid-area: filter; display: flex; align-items: center; gap: 2px; min-width: 0; }
.trait-btn .trait { width: 24px; height: 24px; filter: grayscale(1) brightness(1.5) contrast(1.1); }
.trait-btn[aria-pressed="true"] .trait { filter: grayscale(1) contrast(1.2); mix-blend-mode: multiply; }
@media (max-width: 1023px) {
  .filter { justify-content: space-between; }
  .filter .btn { flex: 1 1 0; min-width: 0; }
}

.party { grid-area: party; display: flex; align-items: center; gap: 12px; justify-content: flex-end; min-width: 0; }
.party > .label { margin-right: 2px; }
.slots { display: flex; gap: 8px; flex: none; }
.slot { position: relative; width: 56px; height: 66px; border-radius: var(--r); display: grid; place-items: center; color: var(--chalk-faint); padding: 0; border: 0; font: inherit; }
.slot::before { content: ""; position: absolute; inset: 0; border: 1.5px dashed var(--chalk-faint); border-radius: inherit; filter: url(#pen); pointer-events: none; }
.slot i { font: 700 15px/1 var(--serif); font-style: normal; opacity: .7; }
.slot.full { overflow: hidden; background: var(--paper) var(--paper-tex); color: var(--ink); box-shadow: var(--lift); cursor: pointer; transition: transform 220ms var(--spring); }
.slot.full::before { inset: 3px; border: 1px solid var(--ink); z-index: 1; }
.slot.full:active { transform: translateY(2px); transition-duration: var(--press); }
.slot .portrait { width: 100%; height: 100%; object-fit: cover; object-position: 50% 0; mix-blend-mode: multiply; }
.slot-name { position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 0 2px; font: 700 8px/1 var(--serif); letter-spacing: .03em;
  text-transform: uppercase; text-align: center; background: var(--ink); color: var(--paper); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.go-wrap { display: grid; gap: 4px; flex: 1 1 auto; min-width: 0; max-width: 300px; }
.btn.go { width: 100%; min-height: 52px; font: 700 17px/1.1 var(--serif); letter-spacing: .02em; }
.btn.go.last { box-shadow: 0 0 0 2px var(--danger), var(--lift); }
.btn.go.skip { letter-spacing: .14em; font-size: 14px; }
.btn.go.skip .icon { width: 18px; height: 18px; }
.warning { color: var(--danger); font-size: 13px; line-height: 1.25; }
.charted { display: flex; align-items: center; gap: 8px; min-height: 52px; color: var(--chalk-dim); }
@media (max-width: 1023px) { .party > .label { display: none; } .go-wrap { max-width: none; } .slots { gap: 6px; } .slot { width: 46px; height: 56px; } }

.hand { grid-area: hand; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 118px); justify-content: center; gap: 12px; padding-top: 18px; min-height: 0; }
@media (max-width: 1023px) {
  .hand { grid-auto-flow: row; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 8px; max-height: 40dvh; overflow-y: auto;
    padding: 16px 10px 8px; margin-inline: -10px; }
}

/* A hero card: a little tarot card of the guild, numbered like its catalog entry. */
.card.hero {
  position: relative; display: flex; flex-direction: column; min-width: 0; padding: 6px 6px 8px; border: 0; border-radius: 5px;
  font: inherit; color: var(--ink); cursor: pointer; text-align: center;
  background: var(--paper) var(--paper-tex); box-shadow: var(--lift);
  transition: transform 260ms var(--spring), box-shadow 200ms, opacity 160ms;
}
.card.hero::before { content: ""; position: absolute; inset: 3px; border: 1.5px solid var(--ink); border-radius: 3px; filter: url(#pen); pointer-events: none; }
.card.hero .num { font: 700 10px/1 var(--serif); letter-spacing: .1em; padding: 3px 0 4px; }
.card.hero .art { display: block; aspect-ratio: 1 / 1.08; overflow: hidden; border-block: 1px solid var(--ink); }
.card.hero .portrait { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 0; mix-blend-mode: multiply; }
.card.hero .name { padding: 6px 2px 3px; font: 700 11px/1.1 var(--serif); letter-spacing: .1em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.hero .traits { display: flex; justify-content: center; align-items: center; gap: 4px; }
.card.hero .trait { width: 15px; height: 15px; mix-blend-mode: multiply; filter: grayscale(1) contrast(1.25); }
.card.hero .trait.big { width: 19px; height: 19px; }
.card.hero .star { position: absolute; top: 6px; left: 9px; font-size: 11px; line-height: 1; }
.card.hero:hover:not(:disabled) { transform: translateY(-4px); }
.card.hero:active:not(:disabled) { transform: translateY(1px); transition-duration: var(--press); }
.card.hero.in-party { transform: translateY(-14px); box-shadow: 0 0 0 2px var(--chalk), 0 16px 28px rgba(0, 0, 0, .6); }
.card.hero.in-party:active:not(:disabled) { transform: translateY(-11px); }
.card.hero.in-party .name { background: var(--ink); color: var(--paper); margin: 4px -3px 2px; }
.card.hero .order { position: absolute; top: -10px; right: -10px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font: 700 14px/1 var(--serif); background: var(--ink); color: var(--paper); box-shadow: 0 0 0 2px var(--chalk); }
.card.hero.faded { opacity: .3; }
.card.hero:disabled { cursor: default; }
.card.hero.barred .art, .card.hero.barred .traits { opacity: .3; }
.card.hero .stamp { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) rotate(-12deg); padding: 5px 6px 4px; white-space: nowrap;
  font: 700 10px/1 var(--serif); letter-spacing: .12em; border: 2px solid var(--ink); background: var(--paper); filter: url(#pen); }
.shake { animation: shake 320ms ease-out; }
@keyframes shake { 20% { translate: -5px 0; } 40% { translate: 5px 0; } 60% { translate: -3px 0; } 80% { translate: 3px 0; } }
#sheet.playing .filter { visibility: hidden; }
/* Phones get a compact card: head and shoulders, no numeral, so the board keeps its room. */
@media (max-width: 1023px) {
  #sheet { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); gap: 8px; }
  .card.hero { padding: 4px 4px 6px; }
  .card.hero .num { display: none; }
  .card.hero .art { aspect-ratio: 1 / .8; border-top: 0; }
  .card.hero .name { font-size: 10px; letter-spacing: .05em; padding-top: 4px; }
  .card.hero.in-party { transform: translateY(-6px); }
  .card.hero.in-party .name { margin-inline: -1px; }
  .card.hero .star { top: 7px; left: 8px; background: var(--paper); border-radius: 2px; padding: 1px 2px; }
  .btn.go.skip { letter-spacing: .08em; }
}

/* ---- coins: a hero's head on a round of paper, used in notes, clues and the chooser ---- */
.coin { display: inline-block; flex: none; width: 24px; height: 24px; border-radius: 50%; overflow: hidden;
  background: var(--paper) var(--paper-tex); box-shadow: 0 0 0 1.5px var(--ink), 0 0 0 2.5px var(--chalk-faint); }
.coin .portrait { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 0;
  transform: scale(1.9); transform-origin: 50% 4%; mix-blend-mode: multiply; }
.coin.trait-coin { display: grid; place-items: center; }
.coin.trait-coin .trait { width: 70%; height: 70%; mix-blend-mode: multiply; filter: grayscale(1) contrast(1.25); }

/* ---- ui/panels.js: the Route Ledger ---- */
#ledger { display: none; }
#ledger h3 { font: 700 19px/1.2 var(--serif); margin-top: 4px; }
#ledger h4 { display: flex; align-items: center; gap: 10px; margin: 22px 0 10px; font: 700 11px/1 var(--serif); letter-spacing: .16em; color: var(--chalk-faint); }
#ledger h4::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.ledger-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.lg-grid { display: grid; grid-template-columns: 52px repeat(4, minmax(0, 1fr)); gap: 6px; align-items: center; }
.lg-room { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 11px; line-height: 1.1; text-align: center; color: var(--chalk-dim); hyphens: auto; }
.lg-room .emblem { width: 28px; height: 28px; color: var(--chalk); stroke-width: 5; }
.lg-room .coin.key { width: 28px; height: 28px; }
.lg-party { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; justify-items: center; }
.lg-party .coin { width: 20px; height: 20px; }
.lg-cell { height: 32px; display: grid; place-items: center; border-radius: 3px; font: 700 15px/1 var(--serif); color: var(--chalk-faint); position: relative; }
.lg-cell.ok { background: var(--paper) var(--paper-tex); color: var(--ink); box-shadow: 0 2px 0 rgba(0, 0, 0, .5); }
.lg-cell.stop { color: var(--chalk); }
.lg-cell.stop::before, .lg-cell.forced::before { content: ""; position: absolute; inset: 0; border: 1.5px solid var(--chalk-faint); border-radius: inherit; filter: url(#pen); }
.lg-cell.forced { color: var(--danger); }
.lg-cell.forced::before { border-color: var(--danger); }
.lg-descent { padding: 10px 0 4px; border-top: 1px dashed var(--rule); }
.lg-said { display: flex; gap: 10px; align-items: flex-start; margin: 8px 0; font-size: 14px; line-height: 1.4; }
.lg-said .coin { width: 28px; height: 28px; margin-top: 2px; }
.lg-said b { display: block; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--chalk-dim); }
.lg-said.opening { color: var(--chalk-dim); }
.lg-said.opening span:last-child { padding-top: 4px; }
.lg-ix { margin: 6px 0; font-size: 13px; color: var(--chalk-dim); }
.ledger-close { display: none; }
@media (min-width: 1024px) {
  #ledger { display: block; grid-area: ledger; min-height: 0; overflow: auto; padding: 0 24px 24px; border-left: 1px solid var(--rule); }
  .ledger-head { display: none; }
}
@media (max-width: 1023px) {
  #ledger {
    display: block; position: fixed; top: 0; right: 0; bottom: 0; width: min(88%, 380px); z-index: 15; overflow: auto;
    padding: 16px 18px calc(16px + env(safe-area-inset-bottom)); background: var(--table) var(--table-tex); border-left: 1px solid var(--rule);
    box-shadow: -20px 0 40px rgba(0, 0, 0, .6); transform: translateX(105%); visibility: hidden;
    transition: transform 220ms ease-out, visibility 0s 220ms;
  }
  body.notes-open #ledger { transform: none; visibility: visible; transition: transform 220ms ease-out; }
  .ledger-close { display: inline-flex; }
}

/* ---- paper sheets: screens, the Guild Book, the chooser; a double rule like an old book's border ---- */
.sheet-card {
  position: relative; width: min(100%, 460px); max-height: calc(100dvh - 32px); overflow: auto; border-radius: 5px;
  padding: 30px 28px 26px; background: var(--paper) var(--paper-tex); color: var(--ink); box-shadow: 0 24px 60px rgba(0, 0, 0, .7);
}
.sheet-card::before, .sheet-card::after { content: ""; position: absolute; border-radius: 3px; pointer-events: none; filter: url(#pen); }
.sheet-card::before { inset: 7px; border: 1.5px solid var(--ink); }
.sheet-card::after { inset: 11px; border: 1px solid var(--ink); opacity: .5; }
.sheet-card .label, .sheet-card .dim { color: var(--ink-dim); }
.sheet-card .btn:not(.paper) { color: var(--ink); }
.sheet-card .btn:not(.paper)::before { border-color: var(--ink-dim); }
.sheet-card .btn.paper, .sheet-card .btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.sheet-card .btn.paper::before, .sheet-card .btn[aria-pressed="true"]::before { border-color: var(--paper); }
.sheet-card :focus-visible { outline-color: var(--ink); }

.scrim { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(9, 10, 11, .72); }
.screen { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.screen h1 { font: 700 46px/1 var(--serif); letter-spacing: .12em; margin-top: 6px; }
.screen h2 { font: 700 20px/1.25 var(--serif); letter-spacing: .08em; }
.screen .blurb { max-width: 36ch; }
.howto { align-self: stretch; text-align: left; margin: 4px 0; padding: 12px 0 12px 24px; border-block: 1px solid rgba(27, 28, 30, .25); }
.howto li { margin: 3px 0; }
.actions { align-self: stretch; display: flex; gap: 10px; margin-top: 6px; }
.actions .btn { flex: 1; min-height: 50px; font-size: 16px; }

/* ---- the Guild Book: a small stitched book; two pages to a spread on desktop, one on a phone ----
   The chapters flow through CSS columns (one column, one page) and a spread slides into view (panels.js). */
#book { position: fixed; inset: 0; z-index: 25; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 66px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(9, 10, 11, .86);
  backdrop-filter: blur(3px); }
.book { position: relative; width: min(960px, 100%); height: min(620px, calc(100dvh - 150px)); padding: 14px; border-radius: 10px 12px 12px 10px;
  background: #27282b var(--table-tex); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .07), 0 30px 70px rgba(0, 0, 0, .75);
  animation: book-in 280ms var(--spring) both; }
.book::before { content: ""; position: absolute; inset: 6px; border: 1px dashed rgba(220, 221, 223, .18); border-radius: 7px; pointer-events: none; }
@keyframes book-in { from { transform: translateY(18px) scale(.98); opacity: 0; } }
.pages {
  position: relative; height: 100%; overflow: hidden; border-radius: 3px; color: var(--ink); touch-action: pan-y;
  background:
    linear-gradient(to right, rgba(0, 0, 0, .16), transparent 3%, transparent 45%, rgba(0, 0, 0, .2) 50%, transparent 55%, transparent 97%, rgba(0, 0, 0, .16)),
    var(--paper) var(--paper-tex);
  box-shadow: 0 1px 0 #cfcfcd, 0 2px 0 #8e8f91, 0 3px 0 #cfcfcd, 0 4px 0 #8e8f91, 0 5px 0 #c4c4c2;   /* the pages beneath */
}
.flow { position: absolute; inset: 54px 48px 50px; column-count: 2; column-gap: 96px; column-fill: auto;
  transition: transform 360ms cubic-bezier(.25, .8, .25, 1); }
.flow .chapter { break-before: column; margin: 0 0 16px; font: 700 28px/1.1 var(--serif); }
.flow .chapter:first-child { break-before: auto; }
.flow .chapter small { display: block; margin-bottom: 8px; font-size: 12px; letter-spacing: .24em; color: var(--ink-dim); }
.flow .chapter::after { content: ""; display: block; width: 56px; margin-top: 12px; border-top: 1.5px solid var(--ink); filter: url(#pen); }
.flow p { margin: 0 0 12px; font-size: 15px; line-height: 1.55; }
.flow p.lead::first-letter { float: left; margin: 5px 7px 0 0; font: 700 3.3em/.8 var(--serif); }
.flow .entry { break-inside: avoid; margin: 0 0 12px; padding-bottom: 10px; border-bottom: 1px dashed rgba(27, 28, 30, .28); }
.flow .entry p { margin: 4px 0 0; font-size: 14px; line-height: 1.45; color: var(--ink-dim); }
.entry-head { display: flex; align-items: center; gap: 8px; }
.entry-head b { font-size: 15px; }
.entry-head .trait { width: 22px; height: 22px; mix-blend-mode: multiply; filter: grayscale(1) contrast(1.25); }
.entry-mark { margin-left: auto; font-size: 10px; letter-spacing: .14em; text-transform: uppercase; text-align: right; color: var(--ink-dim); }
.running, .folio { position: absolute; font: 700 10px/1 var(--serif); letter-spacing: .22em; text-transform: uppercase; color: var(--ink-dim); }
.running { top: 22px; }
.folio { bottom: 20px; font-size: 12px; letter-spacing: .1em; }
.running.left, .folio.left { left: 48px; }
.running.right, .folio.right { right: 48px; }
.ribbons { position: absolute; left: 40px; bottom: 100%; display: flex; gap: 6px; }
.ribbon { min-height: 44px; padding: 12px 14px 10px; border: 0; border-radius: 6px 6px 0 0; cursor: pointer;
  font: 700 12px/1 var(--serif); letter-spacing: .12em; text-transform: uppercase; color: var(--ink);
  background: #a4a5a7 var(--paper-tex); background-blend-mode: multiply; box-shadow: inset 0 -9px 10px -8px rgba(0, 0, 0, .4);
  transform: translateY(8px); transition: transform 220ms var(--spring), background-color 160ms; }
.ribbon small { margin-right: 6px; font-size: 10px; opacity: .6; }
.ribbon:hover { transform: translateY(4px); }
.ribbon[aria-current="true"] { background-color: var(--paper); transform: translateY(3px); }
.ribbon:active { transform: translateY(7px); transition-duration: var(--press); }
.book-close { position: absolute; right: 0; bottom: calc(100% + 6px); }
.book-foot { display: flex; align-items: center; gap: 16px; font-size: 13px; color: var(--chalk-dim); }
.page-count { min-width: 120px; text-align: center; }
@media (max-width: 760px) {
  .book { height: min(680px, calc(100dvh - 146px)); padding: 9px; }
  .pages { background: linear-gradient(to right, rgba(0, 0, 0, .14), transparent 5%, transparent 95%, rgba(0, 0, 0, .1)), var(--paper) var(--paper-tex); }
  .flow { inset: 46px 24px 44px; column-count: 1; column-gap: 48px; }
  .running.left, .folio.right { display: none; }
  .running.right { left: 24px; right: auto; }
  .folio.left { left: 50%; transform: translateX(-50%); }
  .ribbons { left: 8px; }
  .ribbon { padding-inline: 12px; }
  .ribbon small { display: none; }
}

/* ---- ui/talk.js: Hades-style dialogue, and the chooser ---- */
#talk, #overlay { position: fixed; inset: 0; z-index: 20; }
body.talking #board { opacity: .6; }
.talk-scrim { position: absolute; inset: 0; display: flex; justify-content: center; background: linear-gradient(rgba(9, 10, 11, .1) 25%, rgba(9, 10, 11, .85)); }
.talk-scrim.choose { align-items: center; padding: 16px; background: rgba(9, 10, 11, .75); }
.talk-stage { position: relative; width: min(100%, 760px); height: 100%; cursor: pointer; }
.talk-portrait { position: absolute; bottom: calc(18vh + 30px); height: 40vh; display: flex; animation: slide-in 320ms ease-out both; pointer-events: none;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, .7)); }
.talk-portrait.left { left: 12px; --from: -60px; }
.talk-portrait.right { right: 12px; --from: 60px; }
.talk-portrait .portrait { height: 100%; width: auto; max-width: 70vw; }
@keyframes slide-in { from { transform: translateX(var(--from)); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }
.talk-box {
  position: absolute; left: 12px; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom)); min-height: 18vh; padding: 30px 24px 22px; border-radius: 5px;
  background: var(--paper) var(--paper-tex); color: var(--ink); box-shadow: 0 20px 50px rgba(0, 0, 0, .7);
}
.talk-box::before { content: ""; position: absolute; inset: 6px; border: 1.5px solid var(--ink); border-radius: 3px; filter: url(#pen); pointer-events: none; }
.plate { position: absolute; top: -15px; left: 22px; padding: 7px 14px 6px; border-radius: 3px; font: 700 13px/1 var(--serif); letter-spacing: .14em; text-transform: uppercase;
  background: var(--ink); color: var(--paper); box-shadow: 0 0 0 2px var(--paper), 0 4px 10px rgba(0, 0, 0, .5); }
.talk-box[data-side="right"] .plate { left: auto; right: 22px; }
.line { font: 20px/1.5 var(--serif); }
.rest { visibility: hidden; }
.caret { position: absolute; right: 20px; bottom: 12px; color: var(--ink); visibility: hidden; }
.talk-box.done .caret { visibility: visible; animation: bob 800ms ease-in-out infinite; }
@keyframes bob { 50% { transform: translateX(4px); } }
@media (min-width: 1024px) { .talk-portrait { height: 52vh; bottom: calc(18vh + 30px); } .talk-box { padding: 34px 32px 26px; } }
.ask-card { width: min(100%, 480px); }
.asks { align-self: stretch; display: grid; gap: 8px; }
.btn.ask { display: grid; grid-template-columns: 44px 1fr 24px; grid-template-areas: "p n t" "p d d"; align-items: center; justify-items: start;
  gap: 2px 12px; padding: 10px 14px; text-align: left; }
.btn.ask .coin { grid-area: p; width: 44px; height: 44px; }
.btn.ask b { grid-area: n; font: 700 17px/1.2 var(--serif); }
.btn.ask .trait { grid-area: t; width: 22px; height: 22px; mix-blend-mode: multiply; }
.btn.ask span:last-child { grid-area: d; color: var(--ink-dim); }

/* ---- toast: a slip of paper ---- */
#toast {
  position: fixed; left: 50%; top: 124px; z-index: 30; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px);
  padding: 9px 16px 8px; border-radius: 3px; font-size: 14px; background: var(--paper) var(--paper-tex); color: var(--ink); box-shadow: var(--lift);
}
#toast.in { animation: toast-in 220ms var(--spring); }
@media (min-width: 1024px) { #toast { left: calc((100vw - 340px) / 2); top: 84px; } }
@keyframes toast-in { from { transform: translate(-50%, -8px); opacity: 0; } }

/* ---- reduced motion: shakes and bounces stop, slides become fades (P10) ---- */
@media (prefers-reduced-motion: reduce) {
  .shake, .talk-box.done .caret, #toast.in { animation: none; }
  .talk-portrait { animation: fade-in 320ms ease-out both; }
  .btn, .card.hero, .slot.full, .flow, .ribbon { transition: none; }
  .book { animation: none; }
  .btn:active:not(:disabled), .card.hero:active:not(:disabled), .card.hero:hover:not(:disabled) { transform: none; }
}
@media (max-width: 1023px) and (prefers-reduced-motion: reduce) {
  #ledger { transform: none; opacity: 0; transition: opacity 200ms ease-out, visibility 0s 200ms; }
  body.notes-open #ledger { opacity: 1; transition: opacity 200ms ease-out; }
}
