/* The game page's styles (index.html links this file). */
  :root {
    --bg: #14110f; --panel: #1d1916; --panel-2: #26211c; --panel-3: #2f2822; --line: #3a322a; --line-2: #5a4d3e;
    --text: #ece4d6; --soft: #d8ccb8; --muted: #a39683; --accent: #d9a441; --accent-ink: #1a1408;
    --you: #2b3a33; --bad: #c8553d; --good: #6fae7a; --warn: #d9a441;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --display: "IM Fell English", "Iowan Old Style", "Palatino Linotype", Georgia, serif;   /* places and titles, used sparingly */
    --display-sc: "IM Fell English SC", "IM Fell English", Georgia, serif;
    --prose: Spectral, "Iowan Old Style", "Palatino Linotype", Georgia, serif;                 /* what the DM says */
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 .9 0 0 0 0 .75 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px; line-height: 1.5; }
  body.playing { overflow: hidden; }            /* the game screen scrolls inside its panes, never the page */
  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .hidden { display: none !important; }
  .muted { color: var(--muted); }
  /* the SRD's attribution statement (CC-BY-4.0, INF-102): required on the work, kept small */
  .legal { color: var(--muted); font-size: 11px; line-height: 1.45; max-width: 640px; margin: 40px 0 12px; }
  .legal a { color: inherit; }
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-thumb { background: #3a322a; border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
  ::-webkit-scrollbar-thumb:hover { background-color: #4e4337; }
  ::-webkit-scrollbar-track { background: transparent; }

  h2 { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 30px 0 10px; font-weight: 600; }
  .primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 11px 20px; font-weight: 650; }
  .primary:disabled { opacity: .45; cursor: default; }
  .ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px; color: var(--soft); font-size: 13px; }
  .ghost:hover { border-color: var(--line-2); background: #221d19; }
  .notice { background: #3a2a14; border: 1px solid #6b4d1c; color: #f0d9a8; border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 18px; }
  .hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
  .badge { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; background: #332b23; color: var(--soft); white-space: nowrap; font-weight: 600; }
  .badge.combat { background: #4a2a22; color: #f6c9bd; }
  .badges { display: inline-flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
  .badge.clock { background: #22303a; color: #bcd3e2; }
  .badge.clock.late { background: #2a3f52; color: #e4f1fb; }
  .badge.ended { background: #24322a; color: #bfe0c6; }

  /* ---------- setup ---------- */
  #setup { max-width: 1200px; margin: 0 auto; padding: 40px 24px 64px; }
  #setup h1 { font-family: var(--display); font-weight: 400; font-size: 40px; margin: 0 0 4px; letter-spacing: .2px; }
  #setup .lede { color: var(--muted); margin: 0 0 8px; max-width: 64ch; }
  .setup-grid { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 32px; align-items: start; }
  .setup-grid > div:first-child > h2:first-child { margin-top: 18px; }
  .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
  .card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; text-align: left; position: relative; }
  .card:hover, .card.viewing { border-color: var(--line-2); background: #221d19; }
  .card b { display: block; font-family: var(--serif); font-size: 17px; font-weight: 600; padding-right: 76px; }
  .card small { color: var(--muted); display: block; }
  .card p { margin: 8px 0 0; font-size: 13px; color: #cdbfa9; }
  .card.you { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
  .card.companion { border-color: var(--good); }
  .card .tag { position: absolute; top: 10px; right: 10px; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; }
  .card.you .tag { background: var(--accent); color: var(--accent-ink); }
  .card.companion .tag { background: var(--good); color: #0e1a11; }
  .row { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
  label.opt { display: flex; gap: 8px; align-items: center; color: var(--soft); }
  #sheetPane { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; overscroll-behavior: contain;
               background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-top: 18px; }
  #sheetPane .empty { color: var(--muted); font-size: 14px; padding: 30px 6px; text-align: center; }

  .saves { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
  .save { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; text-align: left; display: flex; flex-direction: column; gap: 4px; }
  .save:hover { border-color: var(--line-2); background: #221d19; }
  .saveitem { position: relative; display: flex; flex-direction: column; }
  .saveitem .save { flex: 1; padding-right: 40px; }
  .saveitem .del { position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; padding: 0; border-radius: 6px; border: 1px solid transparent;
                   background: transparent; color: var(--muted); font-size: 13px; line-height: 1; cursor: pointer; }
  .saveitem .del:hover, .saveitem .del:focus-visible { color: #e0846f; border-color: var(--line-2); background: #221d19; }
  .save.latest { border-color: #6b5328; }
  .save .who { display: flex; align-items: baseline; gap: 8px; }
  .save .who b { font-family: var(--serif); font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .save .who .badge { margin-left: auto; }
  .save .party { color: var(--muted); font-size: 13px; }
  .save .where { font-size: 13px; color: var(--soft); }
  .save .last { font-family: var(--serif); font-style: italic; color: #cdbfa9; font-size: 14px; line-height: 1.45; margin: 4px 0 2px;
                display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .save .when { color: var(--muted); font-size: 12px; display: flex; gap: 10px; font-variant-numeric: tabular-nums; }
  .save .when span:last-child { margin-left: auto; }
  /* a story on the start screen: who, where in the campaign, and what comes next */
  .save .s-top { display: flex; gap: 12px; align-items: center; min-width: 0; }
  .save .s-top .por { width: 48px; height: 48px; border-radius: 10px; }
  .save.latest .s-top .por { border-color: var(--accent); }
  .save .s-id { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 1px; }
  .save .s-id b { font-family: var(--serif); font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .save .s-advrow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .save .s-advrow .badge { margin-left: auto; }
  .save .s-camp { margin-top: 8px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.06); display: flex; flex-direction: column; gap: 3px; }
  .save .s-camp .kind { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); font-weight: 650; }
  .save .s-adv { font-family: var(--serif); font-size: 16px; color: var(--text); }
  .save .s-earlier { color: var(--muted); font-size: 12.5px; }
  .trail { display: flex; gap: 4px; list-style: none; margin: 6px 0 2px; padding: 0; }
  .trail li { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
  .trail li.done { background: var(--accent); }
  .trail li.now { background: linear-gradient(90deg, var(--accent) 50%, var(--line) 50%); }
  .save .s-next { margin-top: 6px; align-self: flex-start; background: var(--accent); color: var(--accent-ink); border-radius: 8px; padding: 8px 14px; font-weight: 650; font-size: 14px; }
  .badge.done { background: #3a2f1a; color: var(--accent); }
  .badge.fallen { background: #3a2220; color: #e0a090; }

  #endBar { flex: none; display: flex; align-items: center; gap: 12px; padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
            background: linear-gradient(180deg, #2a2117, var(--panel)); }
  #endBar span { flex: 1; min-width: 0; font-family: var(--serif); font-size: 16px; color: var(--soft); }
  #endBar span b { display: block; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); font-family: var(--sans); font-weight: 650; }
  #endBar .primary { white-space: nowrap; animation: beckon 2.4s ease-out 3; }
  @keyframes beckon { 0% { box-shadow: 0 0 0 0 rgba(217,164,65,.5); } 100% { box-shadow: 0 0 0 14px rgba(217,164,65,0); } }
  @media (prefers-reduced-motion: reduce) { #endBar .primary { animation: none; } }

  /* the end of a chapter: a card at the end of the log (what happened folded, who comes along, the way on) */
  .msg.chapter-card { align-self: stretch; max-width: none; border: 1px solid var(--line-2); border-radius: 14px; background: var(--panel-2); padding: 16px 16px 14px;
                      display: flex; flex-direction: column; gap: 10px; color: var(--text); }
  .chapter-card .kind { display: block; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); font-weight: 650; }
  .chapter-card .cc-head { display: flex; gap: 14px; align-items: center; }
  .chapter-card .end-seal { width: 48px; height: 48px; flex: none; border-radius: 50%; display: grid; place-items: center; font: 400 19px var(--display); background: #8d2f22; color: #f3d9a8; }
  .chapter-card .end-seal.grey { background: radial-gradient(circle at 35% 30%, #8a7f70, #5a5046); color: #1a1714; box-shadow: none; animation: none; }
  .chapter-card h2 { font-family: var(--display); font-size: 25px; font-weight: 400; line-height: 1.15; margin: 2px 0 0; color: var(--text); text-transform: none; letter-spacing: 0; }
  .chapter-card .cc-out { margin: 0; font-family: var(--prose); font-style: italic; font-size: 16px; line-height: 1.5; color: var(--soft); }
  .chapter-card .end-trail { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; }
  .chapter-card .end-trail li { flex: 1; display: flex; flex-direction: column; gap: 6px; font-size: 11px; color: var(--muted); line-height: 1.25; }
  .chapter-card .end-trail li::before { content: ""; height: 5px; border-radius: 3px; background: var(--line); }
  .chapter-card .end-trail li.done::before { background: var(--accent); }
  .chapter-card .end-trail li.done { color: var(--soft); }
  .chapter-card .end-trail li.next::before { background: repeating-linear-gradient(90deg, var(--accent) 0 6px, transparent 6px 10px); opacity: .7; }
  .chapter-card .rule { border: 0; border-top: 1px solid var(--line); margin: 2px 0; width: 100%; }
  .chapter-card .next-l { margin: 0; }
  .chapter-card h3 { font-family: var(--display); font-weight: 400; font-size: 21px; margin: 0; color: var(--text); }
  .chapter-card .meta { margin: 0; color: var(--muted); font-size: 13px; }
  .chapter-card details > summary { cursor: pointer; color: var(--accent); font-size: 13.5px; padding: 4px 0; }
  .chapter-card details > p { font-family: var(--prose); font-size: 15.5px; line-height: 1.55; color: var(--soft); margin: 6px 0 4px; }
  .chapter-card .who-comes { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0 4px; }
  .chapter-card .who-comes > span { color: var(--muted); font-size: 13px; width: 100%; }
  .chapter-card .chip-pc { position: relative; display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-size: 14px; color: var(--muted); }
  .chapter-card .chip-pc .por { width: 28px; height: 28px; border-radius: 50%; opacity: .5; }
  .chapter-card .chip-pc input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
  .chapter-card .chip-pc:has(input:checked) { border-color: var(--good); color: var(--text); background: rgba(111,174,122,.08); }
  .chapter-card .chip-pc:has(input:checked) .por { opacity: 1; }
  .chapter-card .chip-pc:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
  .chapter-card .who-comes select { background: #120f0d; color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; font: inherit; font-size: 14px; }
  .chapter-card .go { width: 100%; padding: 14px 18px; font-size: 16px; border-radius: 10px; display: flex; justify-content: center; align-items: center; gap: 10px; }
  .chapter-card .cc-save { margin: 0; text-align: center; color: var(--muted); font-size: 12.5px; }
  .chapter-card .opt { padding: 12px 0; border-top: 1px solid rgba(255,255,255,.06); display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: start; }
  .chapter-card .opt b { font-family: var(--serif); font-size: 16px; font-weight: 600; }
  .chapter-card .opt .meta { grid-column: 1; }
  .chapter-card .opt p { grid-column: 1 / -1; margin: 2px 0 0; font-size: 14px; color: #cdbfa9; line-height: 1.5; font-family: var(--serif); }
  .chapter-card .opt button { grid-row: 1 / 3; grid-column: 2; align-self: center; }
  .chapter-card .end-adv { font-family: var(--serif); color: var(--soft); margin: 0; }
  .chapter-card .wait-line { display: flex; gap: 10px; align-items: center; justify-content: center; color: var(--muted); font-style: italic; font-family: var(--serif); }
  .chapter-card .nexterr { color: #f1c4ba; font-size: 14px; margin: 0; }
  .chapter-card .cc-home { align-self: center; background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 4px 8px; }
  .chapter-card .end-more { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
  .chapter-card .end-more p { margin: 0; font-size: 14px; color: var(--soft); }
  /* once the next chapter begins, the card shrinks to a marker and a divider starts the new one in the same log */
  .msg.chapter-mark { align-self: stretch; max-width: none; display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); padding: 8px 12px; font-size: 13.5px; color: var(--soft); }
  .chapter-mark .end-seal { width: 28px; height: 28px; font-size: 12px; border-radius: 50%; display: grid; place-items: center; background: #8d2f22; color: #f3d9a8; font-family: var(--display); flex: none; }
  .chapter-mark small { display: block; color: var(--muted); font-size: 12px; }
  .msg.chapter-divider { align-self: stretch; max-width: none; text-align: center; padding: 10px 0 2px; background: none; border: 0; }
  .chapter-divider .kind { display: block; font-size: 11.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 650; }
  .chapter-divider .t { display: block; font-family: var(--display); font-size: 27px; line-height: 1.15; margin-top: 2px; color: var(--text); text-wrap: balance; }
  .chapter-divider::after { content: ""; display: block; width: 60px; height: 1px; background: var(--line-2); margin: 12px auto 0; }
  details.more { margin-top: 10px; }
  details.more > summary { color: var(--muted); font-size: 13px; cursor: pointer; }
  details.more .saves { margin-top: 10px; }
  .chips { display: flex; flex-wrap: wrap; gap: 8px; }

  /* ---------- new game: two steps ---------- */
  .steps { display: flex; align-items: center; gap: 10px; margin: 34px 0 6px; }
  .step { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 4px 2px; color: var(--muted); font-weight: 600; font-size: 14px; }
  .step i { font-style: normal; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--line-2); font-size: 13px; }
  .step.on { color: var(--text); } .step.on i { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  .step.done i { background: #3a2f1a; color: var(--accent); border-color: #6b5328; }
  .step:disabled { cursor: default; }
  .step-line { flex: 0 1 60px; height: 1px; background: var(--line-2); }
  .advs { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
  .adv { position: relative; text-align: left; background: linear-gradient(160deg, #2a2119, #1b1714 60%); border: 1px solid var(--line); border-radius: 14px;
         padding: 16px 18px 14px; display: flex; flex-direction: column; gap: 8px; min-height: 150px; }
  .adv:hover { border-color: var(--line-2); }
  .adv.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
  .adv.camp { background: linear-gradient(160deg, #2b2416, #1d1813 60%); }
  .adv .kind, .msg.next .kind { display: block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); font-weight: 650; }
  .campstart { margin-top: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
  .campstart > b { font-size: 14px; }
  .campstart .seg { display: flex; flex-wrap: wrap; flex: 1 1 100%; min-width: 0; }
  .campstart .seg label { flex: 1 1 200px; min-width: 0; }
  .campstart .seg span { white-space: normal; text-align: left; line-height: 1.25; }
  .campstart .seg small { display: block; color: var(--muted); font-size: 12px; }
  .msg.next .party-swap { margin: 4px 0 10px; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 14px; }
  .msg.next .party-swap select { background: #120f0d; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; font: inherit; }
  .adv b { font-family: var(--display); font-size: 23px; font-weight: 400; line-height: 1.2; padding-right: 28px; }
  .adv p { margin: 0; color: #cdbfa9; font-size: 13.5px; line-height: 1.5; }
  .adv p em { font-family: var(--serif); font-size: 15px; color: #e3d6bf; }
  .adv .tags { display: flex; gap: 6px; flex-wrap: wrap; }
  .adv .tag { font-size: 12px; color: var(--accent); border: 1px solid #6b5328; border-radius: 999px; padding: 2px 9px; }
  .adv .facts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
  .adv .check { position: absolute; top: 14px; right: 14px; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line-2); display: grid; place-items: center; font-size: 13px; color: transparent; }
  .adv.on .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
  .settings { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
  .setting { display: flex; gap: 18px; align-items: center; justify-content: space-between; padding: 14px 18px; }
  .setting + .setting { border-top: 1px solid var(--line); }
  .setting .txt { min-width: 0; }
  .setting .txt b { display: block; font-weight: 600; }
  .setting .txt small { display: block; color: var(--muted); font-size: 13px; line-height: 1.4; margin-top: 2px; }
  .seg { display: inline-flex; flex: none; background: #120f0d; border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
  .seg label { position: relative; flex: 1; }
  .seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
  .seg span { display: block; text-align: center; padding: 7px 14px; border-radius: 7px; color: var(--muted); font-size: 14px; white-space: nowrap; transition: background .15s, color .15s; }
  .seg input:checked + span { background: var(--panel-3); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.04), 0 1px 3px rgba(0,0,0,.4); }
  .seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
  .switch { position: relative; flex: none; width: 48px; height: 28px; }
  .switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
  .switch span { position: absolute; inset: 0; border-radius: 999px; background: #3a322a; transition: background .2s; }
  .switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--soft); transition: transform .2s, background .2s; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
  .switch input:checked + span { background: var(--accent); }
  .switch input:checked + span::after { transform: translateX(20px); background: var(--accent-ink); }
  .switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
  .stepbar { display: flex; gap: 14px; align-items: center; justify-content: flex-end; margin-top: 22px; }
  .stepbar .hint { margin: 0; margin-right: auto; }
  .lvpicks { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: flex-end; font-size: 13px; color: var(--soft); }
  .lvpicks label { display: inline-flex; align-items: center; gap: 6px; }
  .lvpicks select { background: #120f0d; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; font: inherit; }
  .lvpicks .catch { flex-basis: 100%; justify-content: flex-end; color: var(--muted); }
  .keepbtn { background: transparent; color: var(--accent); border: 1px solid var(--accent); border-radius: 6px; padding: 2px 9px; font-weight: 650; font-size: 12px; margin-left: 6px; }
  .stepbar.sticky { position: sticky; bottom: 0; z-index: 3; background: linear-gradient(transparent, var(--bg) 28%); padding: 26px 0 calc(14px + env(safe-area-inset-bottom)); margin-top: 6px; }
  .crumb { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin: 18px 0 0; color: var(--muted); font-size: 14px; }
  .crumb #advChosen { color: var(--soft); }

  /* ---------- character cards with portraits ---------- */
  .cards { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .card.ch { display: flex; gap: 12px; align-items: flex-start; padding: 12px; }
  .card.ch .cbody { min-width: 0; flex: 1; }
  .card.ch b { padding-right: 0; }
  .card.ch small { margin-top: 1px; }
  .card.ch p { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin-top: 6px; }
  .card.ch .tag { position: static; display: inline-block; margin-top: 8px; }
  .card.ch .tag:empty { display: none; }
  .card.locked { opacity: .55; cursor: not-allowed; }
  .card.locked .tag { background: #4a2a22; color: #f6c9bd; }
  .card .peek { display: inline-block; }
  .por { flex: none; width: 72px; height: 72px; border-radius: 12px; overflow: hidden; background: var(--panel-3); border: 1px solid var(--line-2); position: relative; }
  .por img, .por svg { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 22%; }
  .por.sm { width: 40px; height: 40px; border-radius: 9px; }
  .por.lg { width: 84px; height: 84px; border-radius: 14px; }
  .card.you .por { border-color: var(--accent); } .card.companion .por { border-color: var(--good); }
  .sheet-head .por img { cursor: zoom-in; }
  dialog#picDlg.portrait { width: min(520px, calc(100vw - 16px)); }
  dialog#picDlg.portrait img { max-height: calc(100dvh - 120px); object-fit: contain; }
  .porbtns { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
  .porbtns .ghost { font-size: 12px; padding: 3px 9px; }

  /* ---------- character sheet (setup pane and in-game dialog) ---------- */
  .sheet h3 { font-family: var(--serif); font-size: 24px; font-weight: 600; margin: 0; line-height: 1.2; }
  .sheet .line { color: var(--muted); font-size: 13px; margin: 2px 0 10px; }
  .sheet .persona { font-size: 13.5px; color: #cdbfa9; margin: 0 0 12px; }
  .sheet .persona b { color: var(--soft); font-weight: 600; }
  .sheet h4 { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 16px 0 6px; font-weight: 600; }
  .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; text-align: center; }
  .stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
  .stat small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
  .abils { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
  .abil { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 2px 5px; text-align: center; }
  .abil small { display: block; font-size: 10.5px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
  .abil b { display: block; font-size: 19px; line-height: 1.2; font-variant-numeric: tabular-nums; }
  .abil .score { font-size: 12px; color: var(--muted); }
  .abil .sv { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 3px; }
  .abil .sv.prof { color: var(--accent); }
  .skills { columns: 2; column-gap: 14px; font-size: 13px; }
  .skills div { display: flex; justify-content: space-between; break-inside: avoid; padding: 1px 0; color: var(--muted); }
  .skills div.prof { color: var(--text); }
  .skills div.prof::before { content: "●"; color: var(--accent); font-size: 8px; margin-right: 5px; align-self: center; }
  .skills div.exp::before { content: "●●"; }
  .skills div span:first-child { flex: 1; }
  .skills div span:last-child { font-variant-numeric: tabular-nums; }
  table.atk { width: 100%; border-collapse: collapse; font-size: 13px; }
  table.atk th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; padding: 2px 6px 4px 0; }
  table.atk td { padding: 4px 6px 4px 0; border-top: 1px solid var(--line); vertical-align: top; }
  table.atk td.n { font-variant-numeric: tabular-nums; white-space: nowrap; }
  table.atk .props { color: var(--muted); font-size: 11.5px; display: block; }
  .kv { font-size: 13px; margin: 3px 0; }
  .kv b { color: var(--muted); font-weight: 500; }
  .feat { border-top: 1px solid var(--line); padding: 5px 0; font-size: 13px; }
  .feat summary { cursor: pointer; list-style: none; display: flex; gap: 8px; }
  .feat summary::-webkit-details-marker { display: none; }
  .feat summary::before { content: "▸"; color: var(--muted); }
  .feat[open] summary::before { content: "▾"; }
  .feat summary small { color: var(--muted); margin-left: auto; }
  .inv { list-style: none; margin: 0; padding: 0; font-size: 13px; }
  .inv li { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; border-top: 1px solid var(--line); }
  .inv li:first-child { border-top: 0; }
  .inv .q { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 26px; }
  .inv .tagx { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
  .inv .tagx.eq { color: var(--good); }
  .inv-group { font-size: 11px; color: var(--muted); margin: 8px 0 2px; }
  .coins { display: inline-block; margin-top: 6px; font-size: 13px; background: #3a2f1a; color: #f0d9a8; border-radius: 6px; padding: 2px 8px; }
  .feat p { margin: 5px 0 3px 16px; color: #cdbfa9; white-space: pre-line; }

  /* ---------- the sheet's head and tabs ---------- */
  .sheet-head { display: flex; gap: 14px; align-items: flex-start; }
  .sheet-head .who { min-width: 0; flex: 1; }
  .sheet-head .line { margin-bottom: 0; line-height: 1.45; }
  .sheet .stats { margin-top: 14px; }
  .stats.stats3 { margin-top: 4px; }
  .sheet-tabs { display: flex; gap: 0; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); margin: 14px -2px 2px;
                position: sticky; top: -16px; z-index: 2; background: var(--panel); }
  .sheet-tabs::-webkit-scrollbar { display: none; }
  .sheet-tabs button { flex: 1 0 auto; background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 7px 8px; color: var(--muted);
                       font-size: 11.5px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
  .sheet-tabs button:hover { color: var(--soft); }
  .sheet-tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
  .sheet .pane { display: none; } .sheet .pane.on { display: block; animation: tickin .18s ease; }
  .sheet .pane > h4:first-child { margin-top: 12px; }
  .slots { display: flex; flex-wrap: wrap; gap: 6px; }
  .slot { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px 9px; font-size: 13px; color: var(--muted); }
  .slot b { color: var(--text); font-variant-numeric: tabular-nums; }
  .pchead { display: flex; gap: 10px; align-items: center; }
  .pchead .pcwho { min-width: 0; flex: 1; }
  .card .cacts { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 6px; }
  .card.ch .cdel { position: static; display: inline-grid; place-items: center; }
  .card .peek { font-size: 12px; padding: 3px 10px; }

  /* ---------- the whole sheet at once (desktop) ---------- */
  #sheetPane { position: sticky; }
  #sheetPane .panefull { position: absolute; top: 14px; right: 14px; font-size: 12px; padding: 4px 10px; z-index: 3; }
  #sheetPane .sheet-head { padding-right: 84px; }
  dialog#sheetDlg.wide { width: min(1180px, calc(100vw - 32px)); }
  .sheet.all .panes { column-width: 320px; column-gap: 26px; margin-top: 6px; }
  .sheet.all .pane { break-inside: avoid; padding-bottom: 4px; animation: none; }
  .sheet.all .pane[data-pane="features"] { break-inside: auto; }
  .sheet.all .stats { grid-template-columns: repeat(6, 1fr); max-width: 760px; }
  .sheet.all .sheet-head { max-width: 760px; }

  /* ---------- game ---------- */
  #game { display: grid; grid-template-columns: minmax(0, 1fr) 340px; grid-template-rows: minmax(0, 1fr); height: 100vh; height: 100dvh; }
  #chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--line); }
  header.bar { display: flex; align-items: center; gap: 10px; padding: 9px 16px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
  header.bar .where { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
  header.bar .where small { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  header.bar .where span { font-family: var(--display); font-size: 20px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  header.bar .meta { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
  .logwrap { position: relative; flex: 1; min-height: 0; }
  #log { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; padding: 22px 16px 8px; }
  .msg { max-width: 68ch; margin: 0 auto 18px; }
  .msg.dm { font-family: var(--prose); font-size: 17.5px; line-height: 1.66; }
  .msg.dm p { margin: 0 0 .8em; }
  .msg.dm.lead { margin-bottom: .8em; }   /* the instant first line runs on into the DM's answer like one more paragraph */
  /* The DM's words come up a sentence at a time through an SVG grain filter (game.js, reveal): wet amber ink that
     dries to the text colour. Before its turn a sentence is laid out but hidden. Not scoped to .msg.dm: the
     "Previously on" recap card is written out the same way. */
  .ink.wait { opacity: 0; }
  .ink.wet { color: #e6a54c; }
  .ink.wet.dry { color: inherit; transition: color 2.2s ease-out; }
  .inking { cursor: pointer; }
  @media (prefers-reduced-motion: reduce) { .ink { opacity: 1 !important; filter: none !important; } }
  .msg.player { background: var(--you); border-radius: 10px; padding: 9px 13px; width: fit-content; max-width: min(68ch, 85%); margin-left: auto; margin-right: max(0px, calc((100% - 68ch) / 2)); white-space: pre-wrap; }
  .msg.error { background: #3a1b15; border: 1px solid #6b2c22; color: #f1c4ba; border-radius: 8px; padding: 9px 13px; font-size: 14px; }
  .msg.note { color: var(--muted); font-size: 12px; text-align: center; letter-spacing: .04em; }
  .ticks { max-width: 68ch; margin: 0 auto 14px; padding: 8px 12px; border-left: 2px solid var(--line); color: var(--muted); font-size: 13px; line-height: 1.55; font-variant-numeric: tabular-nums; }
  .ticks > div { animation: tickin .25s ease; }
  @keyframes tickin { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
  .msg.wait { color: var(--muted); font-style: italic; font-family: var(--serif); display: flex; align-items: center; gap: 10px; }
  .msg.wait .label::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.4s steps(4, end) infinite; }
  @keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
  @media (prefers-reduced-motion: reduce) { .ticks div { animation: none; } .msg.wait .label::after { animation: none; content: "..."; } }

  /* ---------- the d20 spinner: loading, and while the DM thinks ---------- */
  .d20 { width: 26px; height: 26px; flex: none; display: inline-block; vertical-align: middle; animation: d20roll 1.6s cubic-bezier(.45,.05,.55,.95) infinite; }
  .d20 { --d20-face: #3a2f1a; --d20-edge: var(--accent); font: 700 22px var(--sans); }
  .d20.big { width: 64px; height: 64px; }
  @keyframes d20roll { 0% { transform: rotate(0) scale(1); } 40% { transform: rotate(200deg) scale(.9); } 70% { transform: rotate(340deg) scale(1.05); } 100% { transform: rotate(360deg) scale(1); } }
  #loading { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 40; transition: opacity .25s ease; }
  #loading.gone { opacity: 0; pointer-events: none; }
  #loading div { display: flex; flex-direction: column; align-items: center; gap: 14px; color: var(--muted); font-family: var(--serif); font-style: italic; }
  button .d20 { width: 18px; height: 18px; margin: -3px 8px 0 0; }
  button .d20 { --d20-face: rgba(0,0,0,.12); --d20-edge: currentColor; }
  @media (prefers-reduced-motion: reduce) { .d20 { animation-duration: 4s; } }

  /* ---------- previously on ---------- */
  .msg.recap { border: 1px solid #5a4424; background: linear-gradient(180deg, #241c13, #1b1611); border-radius: 12px; padding: 14px 18px;
               font-family: var(--prose); font-size: 16.5px; line-height: 1.6; color: var(--soft); }
  .msg.recap h3 { font-family: var(--serif); font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin: 0 0 8px; font-weight: 600; }
  .msg.recap p { margin: 0 0 .6em; } .msg.recap p:last-child { margin-bottom: 0; }
  .msg.recap .wait-line { display: flex; gap: 10px; align-items: center; color: var(--muted); font-style: italic; }

  /* ---------- your own characters ---------- */
  .card.add { border-style: dashed; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; min-height: 110px; color: var(--soft); }
  .card.add b { padding-right: 0; }
  .card .mine { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin-left: 6px; }
  .card .cdel { position: absolute; bottom: 8px; right: 8px; width: 24px; height: 24px; padding: 0; border-radius: 6px; border: 1px solid transparent;
                background: transparent; color: var(--muted); font-size: 12px; line-height: 1; }
  .card .cdel:hover { color: #e0846f; border-color: var(--line-2); }
  dialog#impDlg { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 14px; padding: 0;
                  width: min(640px, calc(100vw - 16px)); max-height: calc(100dvh - 24px); }
  dialog#impDlg::backdrop { background: rgba(8, 6, 5, .7); }
  #impDlg .imp-body { padding: 18px 20px 8px; overflow-y: auto; max-height: calc(100dvh - 110px); overscroll-behavior: contain; }
  #impDlg h3 { font-family: var(--serif); font-size: 24px; font-weight: 600; margin: 0 0 4px; }
  #impDlg textarea { width: 100%; min-height: 150px; background: #120f0d; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; resize: vertical; }
  #impDlg .changes { background: #2a2116; border: 1px solid #5a4424; border-radius: 8px; padding: 8px 12px; font-size: 13px; margin: 10px 0; }
  #impDlg .changes li { margin: 2px 0; }
  .imp-foot { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); flex-wrap: wrap; }

  /* ---------- levelling up ---------- */
  .xpline { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
  .lvlbtn { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 6px; padding: 3px 10px; font-weight: 650; font-size: 12px; animation: glow 2.4s ease-in-out infinite; }
  @keyframes glow { 0%,100% { box-shadow: 0 0 0 0 rgba(217,164,65,.0); } 50% { box-shadow: 0 0 0 4px rgba(217,164,65,.25); } }
  /* the level-up screen: the character rising on the left, the choices as sealed steps on the right */
  dialog#lvlDlg { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 16px; padding: 0; overflow: hidden;
                  width: min(1040px, calc(100vw - 16px)); max-height: calc(100dvh - 24px); }
  dialog#lvlDlg[open] { animation: lvIn .45s cubic-bezier(.2, .8, .2, 1); }
  @keyframes lvIn { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }
  dialog#lvlDlg::backdrop { background: radial-gradient(ellipse at 30% 20%, rgba(217,164,65,.10), rgba(8,6,5,.86) 60%); }
  #lvlDlg form { display: flex; flex-direction: column; height: min(820px, calc(100dvh - 26px)); }
  #lvlBody { flex: 1; min-height: 0; overflow: hidden; }
  .lv { display: grid; grid-template-columns: 300px minmax(0, 1fr); height: 100%; }

  .lv-hero { position: relative; overflow: hidden auto; padding: 26px 22px 20px; text-align: center; border-right: 1px solid var(--line);
             background: radial-gradient(120% 70% at 50% 0%, #3a2c18 0%, #241c15 46%, #191512 100%), var(--grain); }
  .lv-ray { position: absolute; inset: -40% -30% auto; height: 360px; pointer-events: none;
            background: conic-gradient(from 180deg at 50% 0%, transparent 0 155deg, rgba(240,200,120,.13) 170deg, transparent 185deg,
                        rgba(240,200,120,.08) 195deg, transparent 210deg 360deg); animation: lvRay 9s ease-in-out infinite alternate; }
  @keyframes lvRay { from { transform: rotate(-6deg); } to { transform: rotate(6deg); } }
  .lv-por { position: relative; width: 112px; height: 112px; margin: 4px auto 10px; border-radius: 50%; padding: 4px;
            background: conic-gradient(from 0deg, #f3d58c, #a8792c, #f3d58c, #7a5520, #f3d58c);
            box-shadow: 0 0 0 1px #00000080, 0 0 34px rgba(217,164,65,.35); animation: lvHalo 3.2s ease-in-out infinite; }
  @keyframes lvHalo { 50% { box-shadow: 0 0 0 1px #00000080, 0 0 48px rgba(217,164,65,.55); } }
  .lv-por .por { display: block; width: 100%; height: 100%; border-radius: 50%; border: 2px solid #1b1510; }
  .lv-who { position: relative; font-family: var(--display); font-size: 26px; line-height: 1.1; color: #f3e6c9; }
  .lv-cls { position: relative; color: var(--muted); font-size: 13px; margin-top: 3px; }
  .lv-num { position: relative; display: flex; justify-content: center; align-items: center; gap: 14px; margin: 14px 0 0; font-family: var(--display); line-height: 1; }
  .lv-num .from { font-size: 38px; color: #6f604c; }
  .lv-num .from::after { content: "›"; margin-left: 14px; color: #8a7350; font-size: 30px; vertical-align: 4px; }
  .lv-num .to { font-size: 84px; background: linear-gradient(180deg, #fff1c8 0%, #f0c86a 45%, #a8792c 100%); -webkit-background-clip: text; background-clip: text;
                color: transparent; filter: drop-shadow(0 4px 18px rgba(217,164,65,.45)); animation: lvRise .9s .15s cubic-bezier(.2, .9, .25, 1.2) both; }
  @keyframes lvRise { from { opacity: 0; transform: translateY(26px) scale(.7); } to { opacity: 1; transform: none; } }
  .lv-cap { position: relative; font-family: var(--display-sc); letter-spacing: .14em; color: #c9a45c; font-size: 13px; margin-top: 2px; }
  .lv-gains { position: relative; list-style: none; margin: 20px 0 0; padding: 0; text-align: left; font-size: 13px; }
  .lv-gains li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 2px; border-top: 1px solid rgba(255,255,255,.06);
                 animation: tickin .4s both; }
  .lv-gains li:nth-child(2) { animation-delay: .08s; } .lv-gains li:nth-child(3) { animation-delay: .16s; } .lv-gains li:nth-child(n+4) { animation-delay: .24s; }
  .lv-gains b { font-weight: 500; color: var(--soft); }
  .lv-gains span { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
  .lv-gains i { font-style: normal; color: #6f604c; margin: 0 2px; }
  .lv-gains em { font-style: normal; color: #f0c86a; font-weight: 650; }
  .lv-prog { position: relative; margin-top: 18px; font-size: 12px; color: var(--muted); }
  .lv-prog .seals { display: flex; justify-content: center; gap: 7px; margin-bottom: 7px; flex-wrap: wrap; }
  .lv-prog .seal { width: 14px; height: 14px; }

  .seal { flex: none; display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-family: var(--display); font-size: 14px;
          color: #c9a45c; border: 1.5px solid #6b5432; background: #1d1813; transition: background .25s, border-color .25s, transform .25s; }
  .seal.done { background: radial-gradient(circle at 35% 30%, #f6d98f, #b8832f 60%, #7a5520); border-color: #f0c86a; color: var(--accent-ink); }
  .seal.fresh { animation: stamp .45s both; }
  .lv.settled .lv-num .to, .lv.settled .lv-gains li { animation: none; }
  .seal.done::before { content: "✓"; font-family: var(--sans); font-size: 13px; font-weight: 800; }
  .lv-prog .seal.done::before { font-size: 0; }
  .seal.star::before { content: "✦"; font-size: 13px; }

  .lv-main { overflow-y: auto; padding: 8px 26px 26px; overscroll-behavior: contain; scroll-behavior: smooth; }
  .lv-sec { padding: 18px 0 6px; border-bottom: 1px solid var(--line); scroll-margin-top: 8px; }
  .lv-sec:last-child { border-bottom: 0; }
  .lv-sec > header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
  .lv-sec h4 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 21px; letter-spacing: .2px; color: #f1e5cb; }
  .lv-sec .count { margin-left: auto; color: var(--accent); font-size: 13px; font-variant-numeric: tabular-nums; }
  .lv-sec.done .count { color: var(--good); }
  .lv-sec .hint { margin: -2px 0 10px; }

  .lv-feats { display: grid; gap: 8px; }
  .lv-feat { border: 1px solid #4a3c2a; border-radius: 12px; padding: 11px 14px; background: linear-gradient(180deg, #2a221a, #211b16);
             box-shadow: inset 0 1px 0 rgba(255,230,180,.06); }
  .lv-feat summary { cursor: pointer; list-style: none; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
  .lv-feat summary::-webkit-details-marker { display: none; }
  .lv-feat b { font-family: var(--serif); font-size: 16.5px; font-weight: 600; color: #f3e6c9; }
  .lv-feat small { color: #c9a45c; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; align-self: center; }
  .lv-feat .lede { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
  .lv-feat[open] .lede { display: none; }
  .lv-feat p { margin: 8px 0 0; font-size: 14px; color: #d6c8b0; white-space: pre-line; line-height: 1.55; }

  .lv-tiles { display: grid; gap: 10px; }
  .lv-tiles.two { grid-template-columns: 1fr 1fr; }
  .lv-tile, .lv-card, .lv-chip { position: relative; cursor: pointer; border: 1px solid var(--line); border-radius: 12px; background: #1a1612;
                                 transition: border-color .18s, background .18s, box-shadow .18s, transform .18s; }
  .lv-tile:hover, .lv-card:hover, .lv-chip:hover { border-color: var(--line-2); background: #211b16; }
  .lv-tile.on, .lv-card.on, .lv-chip.on { border-color: #d9a441; background: linear-gradient(180deg, #33281a, #251e16);
                                          box-shadow: 0 0 0 1px rgba(217,164,65,.5), 0 8px 26px -12px rgba(217,164,65,.45); }
  .lv-tile input[type=radio], .lv-card input, .lv-chip input { position: absolute; opacity: 0; pointer-events: none; }
  .lv-tile { display: grid; gap: 2px; padding: 14px 16px; }
  .lv-tile b { font-family: var(--display); font-size: 26px; font-weight: 400; color: #f3e6c9; line-height: 1.1; }
  .lv-tile span { color: var(--soft); font-size: 14px; }
  .lv-tile small { color: var(--muted); font-size: 12.5px; }
  .lv-tile input[type=number] { margin-top: 6px; width: 90px; background: #120f0d; border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 9px; }

  .lv-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
  .lv-cards.feats { max-height: 420px; overflow-y: auto; padding: 3px; margin: 0 -3px; }
  .lv-card { display: block; padding: 12px 14px; }
  .lv-card b { display: block; font-family: var(--serif); font-size: 16px; font-weight: 600; color: #f3e6c9; }
  .lv-card small { display: block; color: #c9a45c; font-size: 12px; margin-top: 1px; }
  .lv-card p { margin: 6px 0 0; font-size: 13px; color: #c9bba4; line-height: 1.5; }
  .lv-card.on p { color: #e2d5bd; }
  .lv-card.asi { border-style: dashed; }
  .lv-card.asi.on { border-style: solid; }
  .lv-card .more { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(217,164,65,.25); grid-column: 1 / -1; }
  .lv-card .more p { font-size: 13.5px; }
  .lv-card:has(.more) { grid-column: 1 / -1; }
  .lv-cards.subs { align-items: start; }
  .lv-card.compact { padding: 9px 12px; opacity: .8; }
  .lv-card.compact b { font-size: 14.5px; }
  .lv-card.compact p { font-size: 12.5px; margin-top: 3px; }
  .lv-card.compact:hover { opacity: 1; }
  .lv-card.on .more { animation: lvMore .35s ease both; }
  @keyframes lvMore { from { opacity: 0; } to { opacity: 1; } }
  .lv-main { overflow-anchor: none; }
  @media (prefers-reduced-motion: reduce) { .lv-card.on .more { animation: none; } }
  .tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
  .tags span { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #2e2519; color: #e0c48a; border: 1px solid #4a3a22; }

  .lv-abs { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
  .lv-ab { text-align: center; padding: 9px 4px 7px; border-radius: 12px; border: 1px solid var(--line); background: #1a1612; transition: all .2s; }
  .lv-ab .k { display: block; font-size: 11px; letter-spacing: .12em; color: var(--muted); font-weight: 600; }
  .lv-ab b { display: block; font-family: var(--display); font-size: 28px; font-weight: 400; line-height: 1.15; color: #efe3c9; }
  .lv-ab small { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
  .lv-ab small i { font-style: normal; color: var(--good); }
  .lv-ab.up { border-color: #d9a441; background: linear-gradient(180deg, #3a2d18, #221b14); box-shadow: 0 0 22px -6px rgba(217,164,65,.5); }
  .lv-ab.up b { color: #f6d27c; animation: land .35s both; }
  .lv-ab.off { opacity: .38; }
  .lv-ab .pm { display: flex; justify-content: center; gap: 6px; margin-top: 6px; }
  .lv-ab .pm button { width: 28px; height: 26px; border-radius: 7px; border: 1px solid var(--line-2); background: #241e18; color: var(--soft); line-height: 1; font-size: 16px; padding: 0; }
  .lv-ab .pm button:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
  .lv-ab .pm button:disabled { opacity: .3; cursor: default; }
  .lv-search input { width: 100%; margin: 4px 0 10px; background: #120f0d; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
  .lv-search input:focus { border-color: var(--line-2); outline: none; }

  .lv-group { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 10px 0 6px; font-weight: 600; }
  .lv-chips { display: flex; flex-wrap: wrap; gap: 7px; }
  .lv-chip { display: inline-flex; align-items: baseline; gap: 7px; padding: 7px 12px; border-radius: 999px; font-size: 13.5px; }
  .lv-chip b { font-weight: 550; color: var(--soft); }
  .lv-chip small { color: var(--muted); font-size: 11.5px; }
  .lv-chip.on b { color: #f6d27c; }
  .lv-chip:has(input:disabled) { opacity: .4; cursor: default; }
  .lv-chip.wide { display: block; flex: 1 1 240px; border-radius: 12px; padding: 10px 13px; }
  .lv-chip.wide p { margin: 4px 0 0; font-size: 12.5px; color: #bfb19a; }
  .lv-text { width: 100%; margin: 3px 0; background: #120f0d; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }

  .lvl-foot { display: flex; gap: 8px; justify-content: space-between; align-items: center; padding: 12px 22px calc(12px + env(safe-area-inset-bottom));
              border-top: 1px solid var(--line); flex-wrap: wrap; background: #191512; }
  .lvl-foot .msg { margin: 0; flex-basis: 100%; max-width: none; }
  .lvl-acts { display: flex; gap: 10px; align-items: center; }
  #lvlLeft { font-size: 13px; }
  #lvlGo.ready { animation: beckon 1.6s ease-out infinite; }

  .lv-done { position: absolute; inset: 0; z-index: 5; display: grid; place-content: center; justify-items: center; gap: 6px; text-align: center; padding: 30px;
             background: radial-gradient(60% 50% at 50% 42%, rgba(70,50,20,.96), rgba(20,16,12,.98)); animation: tickin .35s both; }
  .lv-done .medal { width: 150px; height: 150px; border-radius: 50%; display: grid; place-items: center; position: relative;
                    background: radial-gradient(circle at 35% 30%, #fbe3a0, #c8902f 55%, #6e4a18); box-shadow: 0 0 0 6px #2a2013, 0 0 0 8px #b8832f, 0 0 80px rgba(240,190,90,.5);
                    animation: stamp .7s .1s both; }
  .lv-done .medal span { font-family: var(--display); font-size: 78px; color: #3a2408; text-shadow: 0 1px 0 rgba(255,240,200,.6); }
  .lv-done h3 { font-family: var(--display); font-weight: 400; font-size: 32px; margin: 18px 0 0; color: #f6e7c4; animation: scenein .9s .35s both; }
  .lv-done p { color: var(--soft); max-width: 52ch; margin: 2px 0 16px; animation: tickin .5s .6s both; }
  .lv-done .burst { position: absolute; left: 50%; top: calc(50% - 70px); width: 0; height: 0; }
  .lv-done .burst i { position: absolute; width: 3px; height: 26px; border-radius: 3px; background: linear-gradient(#ffe7a6, transparent);
                      transform: rotate(var(--a)) translateY(calc(-1 * var(--d))); opacity: 0; animation: lvBurst 1.1s .25s ease-out both; }
  @keyframes lvBurst { 0% { opacity: 0; transform: rotate(var(--a)) translateY(-40px) scaleY(.4); } 30% { opacity: 1; }
                       100% { opacity: 0; transform: rotate(var(--a)) translateY(calc(-1 * var(--d) - 60px)) scaleY(1); } }

  @media (max-width: 760px) {
    dialog#lvlDlg { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; }
    #lvlDlg form { height: 100dvh; }
    #lvlBody { overflow-y: auto; }
    .lv { display: block; height: auto; }
    .lv-hero { border-right: 0; border-bottom: 1px solid var(--line); padding: 18px 16px 14px; display: grid; grid-template-columns: 72px 1fr auto; gap: 0 12px; text-align: left; align-items: center; }
    .lv-ray { display: none; }
    .lv-por { width: 72px; height: 72px; margin: 0; grid-row: 1 / 3; }
    .lv-who { font-size: 21px; } .lv-cls { margin: 0; grid-column: 2; }
    .lv-num { grid-column: 3; grid-row: 1 / 3; margin: 0; gap: 8px; }
    .lv-num .from { font-size: 24px; } .lv-num .from::after { margin-left: 8px; font-size: 20px; }
    .lv-num .to { font-size: 52px; }
    .lv-cap { display: none; }
    .lv-gains, .lv-prog { grid-column: 1 / -1; }
    .lv-gains { margin-top: 12px; }
    .lv-main { overflow: visible; padding: 4px 16px 18px; }
    .lv-tiles.two { grid-template-columns: 1fr; }
    .lv-abs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .lv-cards.feats { max-height: none; overflow: visible; }
    .lvl-foot { padding-left: 16px; padding-right: 16px; }
    .lvl-acts { order: 1; flex-basis: 100%; }
    .lvl-acts button { white-space: nowrap; }
    .lvl-acts #lvlGo { flex: 1; }
    #lvlAuto { order: 2; flex-basis: 100%; border: 0; padding: 2px; text-decoration: underline; text-underline-offset: 3px; color: var(--muted); }
    #lvlLeft { display: none; }
  }
  @media (prefers-reduced-motion: reduce) {
    .lv-ray, .lv-por, #lvlGo.ready { animation: none; }
    .lv-done .burst { display: none; }
  }

  /* ---------- session zero and the table's agreements ---------- */
  #zeroBar { display: flex; gap: 10px; align-items: center; justify-content: space-between;
             padding: 8px 16px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); background: #1a1613; flex: none; }
  #zeroBar .ghost { white-space: nowrap; }
  .table-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
  .table-card .kv { margin: 4px 0; }
  .table-card .actions { display: flex; justify-content: flex-end; margin-top: 6px; }
  .table-card .actions .ghost { font-size: 12px; padding: 3px 9px; }
  #jump { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); background: var(--panel-3); border: 1px solid var(--line-2);
          border-radius: 999px; padding: 5px 14px; font-size: 13px; color: var(--soft); box-shadow: 0 4px 14px rgba(0,0,0,.4); }
  #jump:hover { background: #3a3129; }
  form#say { display: flex; gap: 8px; padding: 12px 16px 14px; border-top: 1px solid var(--line); background: var(--panel); flex: none; align-items: flex-end; }
  #input { flex: 1; resize: none; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; max-height: 160px; overflow-y: auto; scrollbar-width: thin; line-height: 1.45; }
  #input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
  #send { min-width: 78px; height: 44px; }
  .sayhint { color: var(--muted); font-size: 11.5px; padding: 0 16px 10px; background: var(--panel); margin-top: -8px; flex: none; }

  aside { overflow-y: auto; overscroll-behavior: contain; min-height: 0; padding: 14px 14px 0; background: var(--panel);
          display: flex; flex-direction: column; gap: 16px; }
  aside > * { flex: none; }
  aside > div:empty { display: none; }
  aside h2:first-child { margin-top: 2px; }
  aside.fight .side-head { order: -3; }
  aside.fight #map { order: -2; } aside.fight #combat { order: -1; }   /* in a fight the map and the turn order come first */
  .side-head { display: none; }
  .side-actions { margin-top: auto; position: sticky; bottom: 0; display: flex; gap: 8px; padding: 10px 0 calc(12px + env(safe-area-inset-bottom));
                  background: var(--panel); border-top: 1px solid var(--line); }
  .side-actions .ghost { flex: 1; padding: 9px 11px; font-size: 14px; }
  #leave:hover { border-color: #6b2c22; color: #f1c4ba; }
  .pc { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; margin-bottom: 10px; }
  .pc.turn { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
  .pc .top { display: flex; align-items: baseline; gap: 8px; }
  .pc .name { font-family: var(--serif); font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .pc .sub { color: var(--muted); font-size: 12px; }
  .pc .ac { margin-left: auto; font-size: 12px; color: var(--soft); white-space: nowrap; background: #332b23; border-radius: 6px; padding: 0 6px; }
  .bar-hp { height: 8px; background: #120f0d; border-radius: 5px; margin: 8px 0 4px; overflow: hidden; }
  .bar-hp > i { display: block; height: 100%; background: var(--good); border-radius: 5px; transition: width .35s ease; }
  .bar-hp.low > i { background: var(--warn); } .bar-hp.crit > i { background: var(--bad); }
  .hpline { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
  .pills { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
  .pill { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: #332b23; color: #dccfb9; }
  .pill.cond { background: #4a2a22; color: #f0c2b6; } .pill.res { background: #24322a; color: #bfe0c6; }
  .pc details { margin-top: 8px; font-size: 13px; }
  .pc summary { cursor: pointer; color: var(--muted); font-size: 12px; }
  .pc details table { width: 100%; border-collapse: collapse; margin-top: 6px; }
  .pc details td { padding: 2px 0; vertical-align: top; }
  .pc details td:last-child { text-align: right; color: var(--soft); font-variant-numeric: tabular-nums; padding-left: 8px; }
  .pc .actions { display: flex; justify-content: flex-end; margin-top: 6px; }
  .pc .actions .ghost { font-size: 12px; padding: 3px 9px; }
  .order { list-style: none; margin: 0; padding: 0; font-size: 13px; }
  .order li { display: flex; gap: 8px; padding: 4px 6px; border-radius: 6px; align-items: baseline; }
  .order li.now { background: #3a2f1a; }
  .order li.out { opacity: .45; text-decoration: line-through; }
  .order .h { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
  .order .enemy { color: #f0c2b6; }
  #map svg { width: 100%; height: auto; display: block; border-radius: 8px; border: 1px solid var(--line);
             background: linear-gradient(rgba(14,11,9,.62), rgba(14,11,9,.62)), var(--floor, none) center / cover, #120f0d; }   /* the place's own ground */
  #game[data-setting="forest"] #map .t-pillar { fill: #2c3a26; stroke: #46593a; }   /* in a wood, what blocks is trees */
  #map .cell { fill: none; stroke: #2e2720; stroke-width: 1; }
  #map .t-wall { fill: #40372e; stroke: #4c4237; stroke-width: 1; }
  #map .t-barrel { fill: #5e4128; stroke: #8a6440; stroke-width: 2; }
  #map .t-hoop { fill: none; stroke: #8a6440; stroke-width: 1.5; }
  #map .t-diff { fill: url(#hatch); }
  #map .t-water { fill: #17303c; }
  #map .t-table { fill: #4e3a28; stroke: #6d5238; stroke-width: 2; }
  #map .t-low { fill: #3a322a; }
  #map .t-pillar { fill: #4c4237; stroke: #5f5345; stroke-width: 2; }
  #map .t-shelf { fill: #3b2a1c; stroke: #6d5238; stroke-width: 2; }
  #map .t-pit { fill: #050403; stroke: #2e2720; }
  #map .t-stairs { stroke: #5a4d3e; stroke-width: 2; }
  /* walls a spell made (INF-38) */
  #map .sw { stroke-width: 2; }
  #map .sw-stone { fill: #6b6156; stroke: #8a7f71; }
  #map .sw-ice { fill: #9cc7d8; stroke: #d4eef7; fill-opacity: .8; }
  #map .sw-force { fill: rgba(170, 200, 255, .12); stroke: rgba(190, 215, 255, .75); stroke-dasharray: 5 3; }
  #map .sw-fire { fill: rgba(230, 110, 40, .6); stroke: #f3a35a; }
  #map .sw-blades { fill: rgba(190, 190, 200, .25); stroke: #c9c9d4; }
  #map .sw-thorns { fill: rgba(70, 95, 45, .75); stroke: #8aa063; }
  #map .sw-prism { fill: rgba(200, 160, 255, .45); stroke: #f5d2ff; }
  #map .sw-wind { fill: rgba(200, 220, 230, .12); stroke: rgba(210, 230, 240, .5); }
  #map .sw-mark { fill: none; stroke: rgba(240, 240, 240, .65); stroke-width: 1.5; stroke-linecap: round; pointer-events: none; }
  #map .fog-dim { fill: rgba(8, 6, 5, .55); } #map .fog-dark { fill: #0b0908; }
/* spells that stay on the map: harm (damage), hold (restrain, knock down, blind), help (an ally's aura) */
#map .zone rect { stroke-width: 1; pointer-events: none; }
#map .zone-harm rect { fill: rgba(214, 92, 60, .3); stroke: rgba(240, 130, 90, .45); }
#map .zone-hold rect { fill: rgba(150, 110, 210, .22); stroke: rgba(180, 150, 235, .35); }
#map .zone-help rect { fill: rgba(232, 196, 96, .18); stroke: rgba(240, 214, 130, .35); }
  #map .mv { fill: rgba(111, 174, 122, .22); stroke: rgba(150, 214, 160, .6); stroke-width: 1.5; cursor: pointer; }
  #map .mv.oa { fill: rgba(200, 85, 61, .12); stroke: rgba(230, 120, 95, .45); stroke-dasharray: 4 3; }
  #map .mv.sel { fill: rgba(217, 164, 65, .35); stroke: var(--accent); stroke-width: 2; }
  #map .movehint { font-size: 12.5px; color: var(--soft); margin: 6px 0 0; min-height: 1.4em; }
  #map .movehint.bad { color: #f1c4ba; }
  #map svg.picking { cursor: pointer; }
  #map .door { fill: #a8743a; } #map .door.open { fill: #7a5a34; } #map .door .lock { fill: var(--accent); }
  #map .tok { stroke: #120f0d; stroke-width: 2; }
  #map .tok.party { fill: #6fae7a; } #map .tok.enemy { fill: #c8553d; } #map .tok.neutral { fill: #a39683; }
  #map .tok.down { opacity: .3; }
  /* an enemy's picture (tokens.js) and its initiative number in a badge on the rim */
  #map .ico, #ribbon .foe.pic .ico { color: #f3dcc4; pointer-events: none; filter: url(#icoShadow); }
  #map .ico .f, #ribbon .foe.pic .ico .f { fill: url(#icoFill); } #map .ico .k, #ribbon .foe.pic .ico .k { fill: #5a1f16; }
  #map .ico .s, #ribbon .foe.pic .ico .s { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  #map .tokg.haspic .tok.enemy { fill: url(#tokShade); }
  #ribbon .ini .foe.pic { background: radial-gradient(circle at 38% 30%, #d9684e, #b8472f 70%, #8e3322); }
  #map circle.badge { fill: #14110f; stroke: #c8553d; stroke-width: 1.5; }
  #map text.badge { font: 700 8.5px var(--sans); fill: #fff1e6; }
  /* the same picture in the turn order, with its number */
  #ribbon .foe.pic { position: relative; }
  #ribbon .foe.pic .ico { width: 64%; height: 64%; }
  #ribbon .foe.pic b { position: absolute; right: -3px; top: -3px; min-width: 16px; height: 16px; border-radius: 8px; padding: 0 3px;
                       background: #14110f; border: 1px solid #c8553d; font: 700 10px/14px var(--sans); color: #fff1e6; text-align: center; }
  #map .tokg.down .ico, #map .tokg.down .badge { opacity: .35; }
  #map .ring { fill: none; stroke: var(--accent); stroke-width: 3; }
  #map text { font: 600 13px var(--sans); fill: #14110f; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
  #pics h2 { margin-top: 18px; }
  .end-more .write-status { margin-top: 10px; }
  .msg.next .nextopt { border-top: 1px solid rgba(255,255,255,.08); padding: 12px 0 4px; }
  .msg.next .nextopt b { font-family: var(--serif); font-size: 17px; display: block; }
  .msg.next .nextopt p { margin: 6px 0 10px; }
  #journal h2, #people h2 { margin-top: 18px; }
  /* People: everyone in the story, with how they stand and what happened between them and the party */
  #people .person { border-bottom: 1px solid rgba(255,255,255,.06); }
  #people .person summary { list-style: none; display: grid; grid-template-columns: 34px 1fr auto; gap: 2px 10px; align-items: center; padding: 8px 0; cursor: pointer; }
  #people .person summary::-webkit-details-marker { display: none; }
  #people .person .por { width: 34px; height: 34px; border-radius: 50%; grid-row: 1 / 3; }
  #people .person .init { width: 34px; height: 34px; border-radius: 50%; grid-row: 1 / 3; display: grid; place-items: center; font-size: 13px; font-weight: 650;
                          background: var(--panel-3); color: var(--soft); border: 1px solid var(--line-2); }
  #people .person b { font-family: var(--serif); font-size: 15px; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #people .person .role { grid-column: 2 / 4; font-size: 12px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #people .feel { font-size: 11px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--soft); white-space: nowrap; }
  #people .feel.friendly { border-color: #3f6b48; color: #a8d5b0; } #people .feel.hostile { border-color: #7a3a2e; color: #f1b5a6; }
  #people .feel.dead, #people .feel.missing, #people .feel.gone { border-color: var(--line); color: var(--muted); font-style: italic; }
  #people .person.out { opacity: .6; }
  #people .person .mood { font-family: var(--serif); font-style: italic; font-size: 13.5px; color: #cdbfa9; margin: 0 0 6px 44px; }
  #people .person ol { list-style: none; margin: 0 0 10px 44px; padding: 0; border-left: 1px solid var(--line); }
  #people .person li { font-size: 13px; line-height: 1.45; color: var(--soft); padding: 2px 0 6px 10px; position: relative; }
  #people .person li::before { content: ""; position: absolute; left: -3px; top: 8px; width: 5px; height: 5px; border-radius: 50%; background: var(--line-2); }
  #people .person li small { display: block; color: var(--muted); font-size: 11px; }
  #journal .quest { padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,.06); font-size: 14px; }
  #journal .quest b { font-weight: 600; }
  #journal h3 { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; opacity: .6; margin: 14px 0 2px; font-weight: 600; }
  #journal .quest small { display: block; opacity: .7; margin-top: 2px; }
  #journal .quest.done b { text-decoration: line-through; opacity: .6; }
  #journal .quest.failed b { text-decoration: line-through; opacity: .45; }
  #journal .quest.known small { opacity: .85; font-size: 13.5px; line-height: 1.45; }
  #journal .known-earlier { margin: 10px 0 2px; }
  #journal .known-earlier summary { cursor: pointer; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; opacity: .6; font-weight: 600; }
  .msg.chapter { text-align: center; font-family: var(--display-sc); color: var(--accent); letter-spacing: .08em; font-size: 19px; opacity: .9; margin: 18px auto; }
  #map .legend { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
  .foot { color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
  #panelToggle, #scrim { display: none; }
  #panelToggle { position: relative; width: 42px; height: 38px; padding: 0; flex: none; }
  .burger { display: inline-flex; flex-direction: column; gap: 4px; vertical-align: middle; }
  .burger i { display: block; width: 18px; height: 2px; border-radius: 2px; background: var(--soft); }
  #panelToggle .dot { display: none; position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
  #panelToggle.alert .dot { display: block; }

  dialog#sheetDlg { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 14px; padding: 0;
                    width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); }
  dialog#sheetDlg::backdrop { background: rgba(8, 6, 5, .65); }
  dialog#sheetDlg .dlg-body { padding: 16px 20px 20px; overflow-y: auto; max-height: calc(100dvh - 42px); overscroll-behavior: contain; }
  dialog#sheetDlg .close { position: absolute; top: 12px; right: 12px; z-index: 3; }
  dialog#sheetDlg .sheet-head { padding-right: 64px; }
  @media (max-width: 820px) {                /* a phone: the sheet takes the whole screen, tabs under the headline numbers */
    dialog#sheetDlg { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
    dialog#sheetDlg .dlg-body { max-height: 100dvh; height: 100dvh; padding: calc(14px + env(safe-area-inset-top)) 14px calc(20px + env(safe-area-inset-bottom)); }
    dialog#sheetDlg .close { top: calc(10px + env(safe-area-inset-top)); right: 10px; }
    dialog#sheetDlg .sheet-tabs { top: calc(-14px - env(safe-area-inset-top)); margin: 14px -14px 2px; padding: 0 6px; }
    .sheet .stats { grid-template-columns: repeat(3, 1fr); gap: 5px; }
    .sheet .stat b { font-size: 17px; }
    .sheet .skills { columns: 1; font-size: 14.5px; }
    .sheet .skills div { padding: 5px 2px; border-bottom: 1px solid var(--line); }
    .sheet .feat { font-size: 14px; padding: 9px 0; }
    .sheet .inv { font-size: 14px; } .sheet .inv li { padding: 7px 0; }
    .sheet table.atk { font-size: 13.5px; }
    .sheet .kv { font-size: 14px; }
  }


  /* ---------- rules terms and their tooltip ---------- */
  .term { text-decoration: underline dotted var(--line-2); text-underline-offset: 3px; cursor: help; }
  .term:hover, .term:focus-visible { text-decoration-color: var(--accent); }
  .pill.term, .stat .term, .ac.term { text-decoration: none; }
  .pill.term:hover, .ac.term:hover { outline: 1px solid var(--line-2); }
  #tip { position: fixed; z-index: 30; inset: auto; margin: 0; max-width: min(360px, calc(100vw - 16px)); background: #0f0d0b; color: var(--text);
         border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; font: 13px/1.45 var(--sans);
         box-shadow: 0 8px 28px rgba(0,0,0,.55); outline: none; }
  #tip b { display: block; font-family: var(--serif); font-size: 15px; margin-bottom: 2px; }
  #tip .line { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
  #tip p { margin: 0; white-space: pre-line; max-height: 40vh; overflow-y: auto; overscroll-behavior: contain; }
  #tip .term { cursor: pointer; }
  #tip .tipback { background: none; border: 0; padding: 0 0 6px; color: var(--accent); font: inherit; font-size: 12px; cursor: pointer; }
  #tip small { display: block; color: var(--muted); margin-top: 6px; font-size: 11px; }

  /* ---------- dice in the ticker ---------- */
  .ticks div { display: flex; gap: 8px; align-items: flex-start; }
  .ticks div + div { margin-top: 3px; }
  .ticks.undone > div:not(.note) { text-decoration: line-through; text-decoration-color: var(--line-2); opacity: .6; }
  .ticks .note { font-style: italic; color: var(--soft); }
  .ticks .aside { font-style: italic; color: var(--soft); font-family: var(--serif); font-size: 14.5px; }
  .ticks .aside::before { content: "❝"; color: var(--good); font-style: normal; width: 24px; text-align: center; flex: none; }
  .die { flex: none; width: 24px; height: 24px; margin-top: -1px; display: inline-grid; place-items: center; font: 700 11.5px var(--sans);
         font-variant-numeric: tabular-nums; color: var(--text); background: #3a322a;
         clip-path: polygon(50% 0, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%); }
  .die.rolling { animation: tumble .5s linear infinite; color: var(--muted); }
  .die.hit, .die.success { background: #2f5a3a; color: #dff3e3; }
  .die.miss, .die.failure { background: #4a3a34; color: #cdbfb3; }
  .die.crit { background: var(--accent); color: var(--accent-ink); }
  .die.foe.hit, .die.foe.crit { background: #7a2e22; color: #ffd9cf; }
  .die.foe.miss { background: #33402f; color: #cfe3c9; }
  .die.landed { animation: land .28s ease-out; }
  @keyframes tumble { from { transform: rotate(0); } to { transform: rotate(360deg); } }
  @keyframes land { from { transform: scale(1.5); } to { transform: scale(1); } }

  /* ---------- hits and misses on the map ---------- */
  #map .tokg { transition: transform .45s ease; }
  #map .tokg .ring { display: none; } #map .tokg.current .ring { display: inline; }
  #map .inner.hit { animation: shake .45s ease; } #map .inner.hit .tok { stroke: #ffb4a2; stroke-width: 4; }
  #map .inner.crit { animation: shake .6s ease; } #map .inner.crit .tok { stroke: var(--accent); stroke-width: 5; }
  #map .inner.miss { animation: sidestep .45s ease; }
  #map .inner.heal .tok { stroke: #bfe0c6; stroke-width: 4; }
  #map .swing { stroke: #f0d9a8; stroke-width: 3; stroke-linecap: round; animation: swing .45s ease-out forwards; }
  #map .swing.miss { stroke: #a39683; stroke-dasharray: 5 6; }
  #map text.float { font: 700 17px var(--sans); fill: #ffb4a2; stroke: #120f0d; stroke-width: 3; paint-order: stroke; animation: floatup 1s ease-out forwards; }
  #map text.float.miss { fill: #d8ccb8; font-size: 13px; } #map text.float.heal { fill: #bfe0c6; } #map text.float.crit { fill: var(--accent); font-size: 21px; }
  @keyframes shake { 0%,100% { transform: translate(0); } 20% { transform: translate(-4px, 1px); } 40% { transform: translate(4px, -1px); } 60% { transform: translate(-3px, 0); } 80% { transform: translate(2px, 0); } }
  @keyframes sidestep { 0%,100% { transform: translate(0); } 50% { transform: translate(6px, -3px); } }
  @keyframes swing { from { opacity: 1; } to { opacity: 0; } }
  @keyframes floatup { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-26px); } }

  /* ---------- handouts (pictures from the adventure) ---------- */
  .handout { margin: 0; cursor: zoom-in; background: #120f0d; border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: block; width: 100%; text-align: left; }
  .handout:hover { border-color: var(--line-2); }
  .handout img { display: block; width: 100%; height: auto; border-radius: 6px; }
  .handout span { display: block; color: var(--muted); font-size: 12.5px; margin-top: 6px; line-height: 1.4; }
  .msg.pic { max-width: 68ch; }
  dialog#picDlg { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 14px; padding: 14px;
                  width: min(980px, calc(100vw - 16px)); max-height: calc(100dvh - 24px); }
  dialog#picDlg::backdrop { background: rgba(8, 6, 5, .8); }
  dialog#picDlg img { width: 100%; height: auto; display: block; border-radius: 8px; }
  dialog#picDlg p { color: var(--soft); font-size: 14px; margin: 10px 2px 0; }
  dialog#picDlg .close { float: right; margin-bottom: 8px; }
  @media (prefers-reduced-motion: reduce) {
    .die.rolling, .die.landed, #map .inner.hit, #map .inner.crit, #map .inner.miss, #map .swing { animation: none; }
    #map .tokg { transition: none; } #map text.float { animation-duration: 2s; }
  }

  @media (max-width: 980px) {
    .setup-grid { grid-template-columns: 1fr; gap: 0; }
    #sheetPane { display: none; }            /* on a narrow screen a card's Sheet button opens it full screen */
    .card .cacts:not(:has(*)) { display: none; }
  }
  @media (max-width: 600px) {
    .setting { flex-wrap: wrap; gap: 10px; padding: 14px; }
    .setting .seg { width: 100%; }
    .campstart .seg { flex-direction: column; }   /* chapters stack on a phone */
    .campstart .seg label { flex: none; }
    .setting .switch { margin-left: auto; }
    .setting:has(.switch) { flex-wrap: nowrap; }
    .steps { margin-top: 24px; }
    .cards { grid-template-columns: 1fr; }
    .por { width: 64px; height: 64px; }
    .stepbar { flex-wrap: wrap; }
    .stepbar .primary { flex: 1 1 100%; }
    .stepbar .hint { flex-basis: 100%; }
  }
  @media (max-width: 820px) {
    #setup { padding: 28px 16px 48px; }
    #game { grid-template-columns: 1fr; }
    #chat { border-right: 0; }
    aside { position: fixed; inset: 0 0 0 auto; width: min(92vw, 360px); transform: translateX(100%); transition: transform .2s ease; border-left: 1px solid var(--line); z-index: 6; }
    aside.open { transform: none; }
    #scrim.on { display: block; position: fixed; inset: 0; background: rgba(8, 6, 5, .55); z-index: 5; }
    #panelToggle { display: inline-block; }
    header.bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "badge menu" "where menu"; column-gap: 10px; row-gap: 3px;
                 padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
    header.bar .where { grid-area: where; }
    header.bar .where small { display: none; }
    header.bar .where span { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.2; }
    header.bar .badges { grid-area: badge; justify-self: start; }
    #modeBadge:empty { display: none; }
    #panelToggle { grid-area: menu; align-self: center; }
    header.bar .meta { display: none; }
    .side-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: calc(-14px - env(safe-area-inset-top));
                 margin: calc(-14px - env(safe-area-inset-top)) -14px 0; padding: calc(12px + env(safe-area-inset-top)) 14px 10px;
                 background: var(--panel); border-bottom: 1px solid var(--line); z-index: 1; }
    .side-head span { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
    .side-head .ghost { width: 36px; height: 34px; padding: 0; }
    #party h2:first-child { display: none; }        /* the panel's own heading says Party */
    aside { padding-top: calc(14px + env(safe-area-inset-top)); }
    .abils { grid-template-columns: repeat(3, 1fr); }
    .sayhint { display: none; }
    #log { padding: 16px 12px 8px; }
    .msg.dm { font-size: 17px; line-height: 1.58; }
    .msg.player { max-width: 90%; }
    .ticks { padding: 6px 10px; }
    form#say { padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
    #input { font-size: 16px; }                    /* 16px stops phones zooming in on focus */
    #send { min-width: 68px; }
    #map svg { max-height: 46vh; }
  }

  /* ---------- sign-in (hosted version only) ---------- */
  #login { max-width: 420px; margin: 0 auto; padding: 64px 24px; }
  #login h1 { font-family: var(--display); font-weight: 400; font-size: 40px; margin: 0 0 4px; }
  #login .lede { color: var(--muted); margin: 0 0 22px; }
  .logincard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
  .logincard h2 { margin: 0 0 2px; }
  .logincard label { display: flex; flex-direction: column; gap: 4px; color: var(--soft); font-size: 13px; }
  .logincard input { background: #120f0d; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font-size: 15px; }
  .logincard .ghost { padding: 10px 12px; font-size: 14px; }
  .logincard #googleBtn { display: flex; align-items: center; justify-content: center; gap: 10px; }
  .logincard #googleBtn svg { width: 17px; height: 17px; flex: none; color: var(--accent); }
  .logincard .or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
  .logincard .or::before, .logincard .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
  .logincard .links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
  button.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 13px; text-decoration: underline; text-underline-offset: 2px; }
  .logincard .msg { max-width: none; margin: 0; }
  .logincard .msg.ok { background: #1f3326; border-color: #2f5a3b; color: #cfe9d4; }
  .logincard.joinbeta { margin-top: 14px; align-items: center; text-align: center; gap: 10px; }
  .logincard.joinbeta p { margin: 0; color: var(--soft); }
  .logincard.joinbeta a.ghost { text-decoration: none; display: block; width: 100%; box-sizing: border-box; text-align: center; color: var(--accent); border-color: var(--accent); font-weight: 650; }
  .acct { position: relative; display: flex; justify-content: flex-end; margin: -16px 0 8px; font-size: 13px; }
  .acct summary { list-style: none; display: inline-flex; gap: 10px; align-items: center; cursor: pointer; padding: 3px 3px 3px 10px; border-radius: 999px; border: 1px solid var(--line); }
  .acct summary::-webkit-details-marker { display: none; }
  .acct summary:hover, .acct[open] summary { border-color: var(--line-2); }
  .acct .ini { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-3); color: var(--soft); font: 400 15px var(--display); }
  .acct .credit { color: var(--soft); font-variant-numeric: tabular-nums; }
  .acct .credit:empty { display: none; }
  .acct .credit.low { color: var(--warn); }
  .acctmenu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 230px; display: grid; gap: 2px; padding: 10px; border-radius: 12px;
              background: var(--panel); border: 1px solid var(--line-2); box-shadow: 0 16px 40px rgba(0,0,0,.55); }
  .acctmenu > span { padding: 2px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .acctmenu > span:first-child { color: var(--text); font-weight: 600; }
  .acctmenu > span.muted { font-size: 12px; margin-bottom: 6px; }
  .acctmenu a, .acctmenu button { display: block; text-align: left; padding: 7px 8px; border-radius: 7px; border: 0; background: none; color: var(--soft); text-decoration: none; }
  .acctmenu a:hover, .acctmenu button:hover { background: var(--panel-2); color: var(--text); }

  /* ---------- atmosphere: light, type and motion that follow the story (phase 1 of docs/ui-overhaul.md) ---------- */
  /* The mood light sits behind the story. The place sets the scene (.scape: its setting's colours and texture, its
     light); on top, moon-blue while a clock nears its end, ember in a fight, and a red rim when you are badly hurt. */
  #mood { position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
  #mood i { position: absolute; inset: 0; opacity: 0; transition: opacity 2s ease; }
  #mood .moon { background: radial-gradient(90% 50% at 50% -8%, rgba(120,170,225,.18), transparent 72%); }
  #mood .ember { background: radial-gradient(90% 55% at 50% -8%, rgba(224,85,58,.22), transparent 72%), radial-gradient(120% 70% at 50% 125%, rgba(224,85,58,.10), transparent 70%); }
  #mood::before { content: ""; position: absolute; inset: 0; z-index: 2; background: radial-gradient(130% 100% at 50% 45%, transparent 55%, rgba(0,0,0,.5)); }
  #mood::after { content: ""; position: absolute; inset: 0; z-index: 2; opacity: .6; background-image: var(--grain); }
  #game.m-tense #mood .moon { opacity: 1; }
  #game.m-fight #mood .ember { opacity: 1; }
  #mood .moon, #mood .ember, #mood .rim { z-index: 3; }

  /* ---- the place: a soft light from above, tinted by the time of day, and the ground underfoot laid in perspective
          (painted by static/scenery.js). One .scape per place; a new one fades in over the old. ---- */
  .scape { position: absolute; inset: 0; transition: opacity 2.2s ease; }
  .scape.out { opacity: 0; }
  .scape .lite { position: absolute; inset: 0; background: radial-gradient(95% 50% at 50% -10%, var(--lite), transparent 72%); }
  .scape { --lite: rgba(255,179,92,.17); }
  .scape[data-light="day"] { --lite: rgba(255,238,205,.14); }
  .scape[data-light="dawn"] { --lite: rgba(255,200,170,.15); }
  .scape[data-light="dusk"] { --lite: rgba(255,165,95,.18); }
  .scape[data-light="night"] { --lite: rgba(150,180,220,.15); }
  .scape[data-light="fire"] { --lite: rgba(255,170,90,.19); }
  .scape[data-light="dark"] { --lite: rgba(255,179,92,.10); }
  .scape[data-light="dim"] { --lite: rgba(255,179,92,.12); }
  .scape[data-light="fire"] .lite { animation: hearth 3.2s ease-in-out infinite; }
  @keyframes hearth { 0%, 100% { opacity: .9; } 30% { opacity: .75; } 55% { opacity: 1; } 80% { opacity: .82; } }
  .scape .ground { position: absolute; left: -45%; right: -45%; top: 46%; bottom: 0; background-size: cover; background-position: center;
                   transform: perspective(560px) rotateX(58deg); transform-origin: 50% 100%; opacity: .6; filter: brightness(1.3);
                   -webkit-mask-image: linear-gradient(transparent, rgba(0,0,0,.45) 30%, #000 80%); mask-image: linear-gradient(transparent, rgba(0,0,0,.45) 30%, #000 80%); }
  /* on a phone (owner, 2026-11-18: "too subtle"): the light twice as strong, reaching further down and glowing up from
     the ground too; the ground higher and clearer; night bluer and a dark place darker. A shadow keeps the story readable. */
  @media (max-width: 820px) {
    .scape .lite { background: radial-gradient(150% 62% at 50% -10%, var(--lite), transparent 80%),
                                radial-gradient(150% 62% at 50% -10%, var(--lite), transparent 80%),
                                radial-gradient(130% 40% at 50% 108%, var(--lite), transparent 72%); }
    .scape .ground { top: 50%; opacity: .72; filter: brightness(1.6) contrast(1.08);
                     -webkit-mask-image: linear-gradient(transparent, rgba(0,0,0,.5) 22%, #000 65%); mask-image: linear-gradient(transparent, rgba(0,0,0,.5) 22%, #000 65%); }
    .scape::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
    .scape[data-light="night"]::after { background: rgba(20,40,80,.22); }
    .scape[data-light="dark"]::after { background: rgba(0,0,0,.30); }
    .scape[data-light="dark"] .ground, .scape[data-light="dim"] .ground { filter: brightness(1.2); }
    .msg.dm, .msg.scene b { text-shadow: 0 1px 2px rgba(0,0,0,.85), 0 0 12px rgba(0,0,0,.55); }
  }

  /* the picture of a place, above its name when the party arrives */
  .msg.scene .art { display: block; width: 100%; max-width: 760px; height: auto; aspect-ratio: 2.6 / 1; border-radius: 6px; margin-bottom: -46px;
                    -webkit-mask-image: linear-gradient(transparent, #000 12%, #000 70%, transparent), linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent);
                    -webkit-mask-composite: source-in; mask-image: linear-gradient(transparent, #000 12%, #000 70%, transparent), linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent);
                    mask-composite: intersect; }
  .msg.scene .art + small { position: relative; }
  .msg.scene .art ~ b { position: relative; text-shadow: 0 2px 18px #000, 0 0 2px #000; }
  .msg.scene.in .art { animation: tickin 1.2s ease-out both; }
  @media (max-width: 820px) { .msg.scene .art { aspect-ratio: 2.2 / 1; margin-bottom: -36px; } }
  /* your own character at a quarter of their Hit Points or less: a red rim, with three beats when it first happens */
  #mood .rim { box-shadow: inset 0 0 80px 8px rgba(200,40,30,.26); transition-duration: .8s; }
  #game.bloodied #mood .rim { opacity: 1; }
  #game.bloodied.fresh #mood .rim { animation: heartbeat 1.1s ease-in-out 3; }
  @keyframes heartbeat { 0%, 100% { opacity: .55; } 14% { opacity: 1; } 28% { opacity: .65; } 42% { opacity: 1; } }

  /* a new place: its name, set like a chapter heading, before the narration that opens it */
  .msg.scene { display: flex; flex-direction: column; align-items: center; gap: 5px; text-align: center; margin: 34px auto 20px; }
  .msg.scene small { font: 600 10.5px var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
  .msg.scene b { font: 400 32px/1.1 var(--display); letter-spacing: .2px; text-wrap: balance; text-shadow: 0 0 30px rgba(255,179,92,.12); }
  .msg.scene .orn { display: flex; align-items: center; gap: 10px; width: min(260px, 70%); color: var(--accent); margin-top: 2px; }
  .msg.scene .orn::before, .msg.scene .orn::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--accent)); }
  .msg.scene .orn::after { transform: scaleX(-1); }
  .msg.scene .orn svg { width: 12px; height: 12px; flex: none; }
  .msg.scene.in b { animation: scenein 1.5s ease-out both; }
  .msg.scene.in small, .msg.scene.in .orn { animation: tickin .8s ease-out .5s both; }
  @keyframes scenein { from { opacity: 0; letter-spacing: .2em; filter: blur(3px); } to { opacity: 1; letter-spacing: .2px; filter: none; } }
  .msg.dm.first > p:first-child::first-letter { font: 400 3.4em/.8 var(--display); float: left; color: #f3cd78; padding: .1em .1em 0 0;
                                                 text-shadow: 0 0 18px rgba(243,205,120,.3); }

  /* a fight begins: a band across the story */
  #banner { position: absolute; left: 0; right: 0; top: 36%; z-index: 3; pointer-events: none; text-align: center; padding: 14px 16px;
            background: linear-gradient(90deg, transparent, rgba(58,20,14,.92) 18%, rgba(58,20,14,.92) 82%, transparent);
            border-top: 1px solid rgba(224,85,58,.45); border-bottom: 1px solid rgba(224,85,58,.45); animation: banner 2.8s ease-in-out forwards; }
  #banner b { display: block; font: 400 clamp(22px, 5vw, 32px)/1.1 var(--display-sc); letter-spacing: .1em; color: #ffd9cf; text-shadow: 0 0 20px rgba(224,85,58,.8); }
  #banner small { display: block; margin-top: 4px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: #f0c2b6; }
  @keyframes banner { 0% { clip-path: inset(0 50% 0 50%); } 18%, 78% { clip-path: inset(0 0 0 0); opacity: 1; } 100% { clip-path: inset(0 0 0 0); opacity: 0; } }

  /* people in the story, named in brass; a tap opens them */
  .who { color: #f3cd78; cursor: pointer; border-radius: 3px; }
  .who:hover, .who:focus-visible { text-decoration: underline dotted rgba(243,205,120,.6); text-underline-offset: 3px; }
  #people .person.flash summary { animation: flash 1.6s ease-out; }
  @keyframes flash { 0%, 30% { background: rgba(217,164,65,.22); } 100% { background: transparent; } }

  /* a natural 20 lands with a flash and sparks; a natural 1 sinks */
  .ticks > div { position: relative; }
  .die.nat20 { animation: nat20 .9s ease-out; }
  .die.nat1 { animation: nat1 .9s ease-out; }
  @keyframes nat20 { 0% { transform: scale(1.9) rotate(-30deg); filter: brightness(2.2); } 55% { transform: scale(1); filter: brightness(1.4); } 100% { filter: none; } }
  @keyframes nat1 { 0% { transform: scale(1.3); } 45% { transform: translateY(2px); filter: brightness(.45); } 100% { filter: none; } }
  .spark { position: absolute; left: 12px; top: 11px; width: 4px; height: 4px; margin: -2px; border-radius: 50%; background: #f3cd78; box-shadow: 0 0 6px #f3cd78;
           pointer-events: none; animation: spark .8s ease-out forwards; }
  @keyframes spark { from { transform: translate(0, 0) scale(1); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(.3); opacity: 0; } }

  /* while the DM works: a step for each stage the stream reports */
  .msg.wait .steps { display: inline-flex; gap: 4px; }
  .msg.wait .steps i { width: 16px; height: 3px; border-radius: 2px; background: var(--line-2); transition: background .4s; }
  .msg.wait .steps i.on { background: var(--accent); }

  @media (max-width: 820px) { .msg.scene b { font-size: 27px; } .msg.scene { margin-top: 26px; } }
  @media (prefers-reduced-motion: reduce) {
    #mood i, .scape { transition: none; } .scape .lite, .msg.scene.in .art { animation: none !important; }
    #game.bloodied.fresh #mood .rim, .msg.scene.in b, .msg.scene.in small, .msg.scene.in .orn, .die.nat20, .die.nat1 { animation: none; }
    .spark, #banner { display: none; }
  }

/* ---------- settings on this device, and "calm" ---------- */
#prefs { display: grid; gap: 4px; }
#prefs h2 { margin-bottom: 2px; }
.pref { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 6px 0; }
.helppref { flex-direction: column; align-items: stretch; }
.helppref .seg { display: flex; }
.helppref .seg span { padding: 7px 4px; }
.pref b { display: block; font-weight: 600; font-size: 13.5px; }
.pref small { display: block; color: var(--muted); font-size: 12px; line-height: 1.35; }
.pref input.pace { flex: none; width: 120px; accent-color: var(--accent); }
.pref output { color: var(--soft); font-variant-numeric: tabular-nums; }
.pref-error { color: #f1c4ba; font-size: 12.5px; margin: 0 0 4px; }
html.calm *, html.calm *::before, html.calm *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important;
                                                        transition-duration: .001ms !important; scroll-behavior: auto !important; }
html.calm #banner, html.calm .spark { display: none; }

/* ---------- the fight layout (fight.js): the board leads ---------- */
#board { display: none; position: relative; min-width: 0; min-height: 0; background: #0d0b09; }
#game.fight #board { display: flex; flex-direction: column; }
#game.fight #combat { display: none; }                                  /* the ribbon shows the turn order */
#ribbon { display: flex; gap: 4px; align-items: flex-end; padding: 8px 10px 6px; overflow-x: auto; scrollbar-width: none; flex: none;
          border-bottom: 1px solid var(--line); background: linear-gradient(#1a1512, #120f0d); }
#ribbon::-webkit-scrollbar { display: none; }
#ribbon .rd { font: 400 14px var(--display-sc); color: var(--accent); margin-right: 6px; white-space: nowrap; align-self: center; }
#ribbon .ini { flex: none; width: 56px; display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: 0; padding: 3px 0 0; opacity: .75; color: inherit; }
#ribbon .ini .por, #ribbon .ini .foe { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--good); }
#ribbon .ini .foe { display: grid; place-items: center; font: 650 14px var(--sans); background: #3b1d17; color: #ffd9cf; border-color: var(--bad); }
#ribbon .foe.some { box-shadow: inset 0 -6px 0 rgba(224,85,58,.35); }
#ribbon .foe.bad { box-shadow: inset 0 -14px 0 rgba(224,85,58,.55); }
#ribbon .foe.down { opacity: .5; }
#ribbon .ini small { font-size: 10.5px; color: var(--muted); max-width: 56px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#ribbon .ini.now { opacity: 1; }
#ribbon .ini.now .por, #ribbon .ini.now .foe { box-shadow: 0 0 0 3px var(--accent), 0 0 16px rgba(217,164,65,.55); }
#ribbon .ini.now small { color: #f3cd78; font-weight: 600; }
#ribbon .ini.out { opacity: .3; }
#boardMap { flex: 1; min-height: 0; overflow: auto; padding: 12px; }
#boardMap #map h2 { display: none; }
#boardMap #map svg { max-height: none; }
#tokcard { position: absolute; z-index: 5; min-width: 170px; max-width: 250px; background: #0f0d0b; border: 1px solid var(--line-2); border-radius: 10px;
           padding: 9px 11px; box-shadow: 0 10px 30px rgba(0,0,0,.6); display: grid; gap: 3px; font-size: 13px; }
#tokcard b { font: 400 17px var(--display); }
#tokcard span { color: var(--soft); }
#tokcard small { color: var(--muted); font-size: 12px; }
#tokcard .ghost { justify-self: start; margin-top: 4px; font-size: 12px; padding: 3px 9px; }
#boardHandle { display: none; }
#map .tokg { cursor: pointer; }
#map .face { pointer-events: none; }
#map .tokg:not(.hasface) .face { display: none; }
#map .tokg.hasface text { display: none; }
#map .tokg.down .face { opacity: .3; filter: grayscale(1); }
.por.xs { width: 26px; height: 26px; border-radius: 50%; }

/* what the player has left this turn, over the message box */
#eco { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 16px 0; background: var(--panel); flex: none; border-top: 1px solid var(--line); }
#eco + form#say { border-top: 0; }
.eco { font: 650 11.5px var(--sans); letter-spacing: .03em; padding: 4px 9px; border-radius: 6px; border: 1px solid; display: inline-flex; gap: 6px; align-items: center; }
.eco.on { border-color: #4f7d58; color: #cfe9d4; background: rgba(111,174,122,.12); }
.eco.used { border-color: var(--line); color: var(--muted); text-decoration: line-through; opacity: .7; }
.eco .mv { width: 46px; height: 4px; background: #0b0908; border-radius: 2px; overflow: hidden; }
.eco .mv i { display: block; height: 100%; background: var(--good); }

#hpstrip { display: none; }                                             /* the health strip is for phones */
@media (min-width: 821px) {                                            /* a desktop: three columns in a fight */
  #game.fight { grid-template-columns: minmax(0, 1fr) minmax(360px, 1.05fr) 300px; }
  #game.fight #board { border-right: 1px solid var(--line); }
}
@media (max-width: 820px) {
  #hpstrip { display: flex; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
  .hpm { flex: 1 1 0; min-width: 0; display: flex; gap: 6px; align-items: center; background: rgba(0,0,0,.3); border: 1px solid var(--line);
         border-radius: 999px; padding: 3px 9px 3px 3px; color: var(--soft); }
  .hpm.me { border-color: rgba(217,164,65,.55); }
  .hpm.turn { box-shadow: 0 0 0 2px var(--accent); }
  .hpm .hb { flex: 1; height: 5px; border-radius: 3px; background: #0b0908; overflow: hidden; }
  .hpm .hb i { display: block; height: 100%; background: var(--good); }
  .hpm .hb.low i { background: var(--warn); } .hpm .hb.crit i { background: var(--bad); }
  .hpm small { font-size: 11px; font-variant-numeric: tabular-nums; }
  .hpm:only-child { flex: 0 1 auto; }                                    /* alone (owner, 2026-11-19): a short pill, not a full-width bar */
  .hpm:only-child .hb { flex: none; width: 72px; }
  #game.fight #board { flex: none; height: var(--boardh, 42vh); border-bottom: 1px solid var(--line); }
  #game.fight #board.folded { height: auto; }
  #board.folded #boardMap, #board.folded #tokcard { display: none; }
  #boardMap { padding: 6px 8px 20px; }
  #boardMap #map .legend { display: none; }
  /* the drawer bar (owner, 2026-11-18): a real target, tap to fold or open, drag to resize */
  #boardHandle { display: flex; align-items: center; justify-content: center; gap: 10px; position: absolute; left: 0; right: 0; bottom: 0;
                 height: 30px; z-index: 6; padding: 0; border: 0; color: var(--soft); font: 600 12px var(--sans); letter-spacing: .02em;
                 background: linear-gradient(transparent, #0d0b09 45%); touch-action: none; cursor: ns-resize; }
  #board.folded #boardHandle { position: static; height: 34px; background: #0d0b09; color: var(--text); }
  #boardHandle i { width: 36px; height: 4px; border-radius: 2px; background: var(--line-2); }
  #game.typing #hpstrip, #game.typing #ribbon, #game.typing #eco { display: none; }   /* the keyboard is up */
  #boardMap { padding-bottom: 32px; }
  #eco { padding: 6px 10px 0; }
}

/* ---------- the end of a chapter: the place behind the heading, and a wax seal ---------- */
.chapter-card .end-seal:not(.grey) { width: 48px; height: 48px; border-radius: 47% 53% 50% 50% / 52% 48% 52% 48%; font: 400 19px var(--display); color: #f8dcc0;
  background: radial-gradient(circle at 38% 32%, #d0644a, #9a2c1c 55%, #5e170d); text-shadow: 0 1px 0 rgba(0,0,0,.45);
  box-shadow: 0 3px 0 #4a120a, 0 8px 22px rgba(0,0,0,.55), inset 0 0 0 5px rgba(0,0,0,.16), inset 0 0 0 7px rgba(255,200,170,.12);
  animation: stamp .9s cubic-bezier(.2,.8,.3,1.2) both; }
@keyframes stamp { 0% { transform: scale(1.7) rotate(-12deg); opacity: 0; } 60% { transform: scale(.94) rotate(2deg); opacity: 1; } 100% { transform: none; } }

/* ---------- the side panel as tabs (rail.js) ---------- */
#sideTabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); margin: -4px -14px 0; padding: 0 8px; position: sticky; top: -14px; z-index: 2; background: var(--panel); flex: none; }
#sideTabs button { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 4px 8px; color: var(--muted);
                   font: 650 11.5px var(--sans); letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; }
#sideTabs button:hover { color: var(--soft); }
#sideTabs button.on { color: var(--text); border-bottom-color: var(--accent); }
#sideTabs i { font-style: normal; font-size: 10px; background: var(--panel-3); color: var(--soft); border-radius: 999px; padding: 0 6px; margin-left: 3px; letter-spacing: 0; }
.tabhide { display: none !important; }
#party > h2:first-child, #journal > h2:first-child, #people > h2:first-child { display: none; }   /* the tab says it */
@media (max-width: 820px) { #sideTabs { top: calc(42px + env(safe-area-inset-top)); margin: 0 -14px; } }

/* health as a ring round the face */
.ringed { flex: none; display: inline-grid; place-items: center; padding: 3px; border-radius: 50%;
          background: conic-gradient(var(--ring, var(--good)) calc(var(--pct) * 1%), #2a2420 0); }
.ringed.low { --ring: var(--warn); } .ringed.crit { --ring: var(--bad); }
.ringed .por { border-radius: 50%; border: 2px solid var(--panel-2); }
.pc .hpline { margin-top: 6px; }

/* one look for every dialog */
dialog.shell { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
dialog.shell::backdrop { background: rgba(8, 6, 5, .74); }
#fbDlg, #rateDlg { padding: 18px; width: min(480px, calc(100vw - 32px)); }
#rateDlg .rate button { flex: 1; font-size: 15px; padding: 10px; }
#rateDlg .rate button.on { border-color: var(--accent); color: var(--accent); background: rgba(217, 164, 65, .12); }
/* under the DM's latest answer (INF-107): quiet until wanted */
.offflag { display: block; margin: 8px 0 0 auto; padding: 2px 6px; background: none; border: 0; color: var(--muted); font: inherit; font-size: 12px; opacity: .7; cursor: pointer; }
.offflag:hover, .offflag:focus-visible { opacity: 1; color: var(--text, inherit); text-decoration: underline; }

/* ---------- the start screen: the story you are in, as a cover ---------- */
.heroitem { display: block; }
.save.hero { position: relative; display: block; width: 100%; min-height: 300px; padding: 0; overflow: hidden; border-radius: 16px;
             border: 1px solid rgba(217,164,65,.45); background: #0c0a09; }
.save.hero:hover { border-color: var(--accent); }
.hero-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.save.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(10,8,7,.88) 0%, rgba(10,8,7,.55) 45%, rgba(10,8,7,0) 75%),
                    linear-gradient(transparent 40%, rgba(10,8,7,.75)); }
.hero-txt { position: relative; z-index: 1; display: grid; gap: 7px; justify-items: start; padding: 28px 30px 26px; max-width: 560px; text-align: left; }
.hero-txt .kind { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 650; }
.hero-txt .kind em { font-style: normal; color: #f6c9bd; }
.hero-txt b { font: 400 clamp(28px, 4vw, 40px)/1.05 var(--display); color: var(--text); text-wrap: balance; }
.hero-where { display: inline-flex; gap: 8px; align-items: center; color: var(--soft); font-size: 14px; }
.hero-txt q { font: italic 16px/1.55 var(--prose); color: #e3d9c7; max-width: 52ch; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.hero-txt .trail { width: min(320px, 100%); }
.hero-txt .go { margin-top: 6px; background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 11px 18px; font-weight: 650; font-size: 15px; }
.heroitem .del { z-index: 2; color: var(--soft); background: rgba(10,8,7,.6); }
.newstory { display: block; width: 100%; margin: 26px 0 0; padding: 14px; border: 1px dashed var(--line-2); border-radius: 12px; background: transparent;
            color: var(--soft); font-size: 15px; }
.newstory:hover { border-color: var(--accent); color: var(--text); }
@media (max-width: 600px) {
  .save.hero { min-height: 340px; }
  .save.hero::after { background: linear-gradient(transparent 15%, rgba(10,8,7,.92) 70%); }
  .hero-txt { padding: 150px 18px 20px; }
}

/* quick actions: a row of buttons that fill the message box */
#quick { display: flex; gap: 6px; padding: 8px 16px 0; background: var(--panel); flex: none; overflow-x: auto; scrollbar-width: none; }
#quick::-webkit-scrollbar { display: none; }
#quick .qa { flex: none; font-size: 12.5px; color: var(--soft); background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; }
#quick .qa:hover { border-color: var(--accent); color: var(--text); }
#eco:not(.hidden) + #quick { padding-top: 6px; }
#quick .qa.sp { border-color: rgba(140,170,230,.35); }                 /* a spell */
#quick .qa.own { border-style: dashed; }                                /* one of the player's own shortcuts */
#quick .qa.add { padding: 5px 10px; color: var(--accent); }
#scDlg { max-width: 520px; }
#scDlg input:not([type]), #scDlg textarea { background: #120f0d; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; color: var(--text); font: inherit; }
.sc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 34vh; overflow: auto; }
.sc-list li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; }
.sc-list li span { grid-column: 1; color: var(--soft); font-size: 13px; }
.sc-list li small { font-weight: 400; color: var(--muted, var(--soft)); margin-left: 6px; }
.sc-list li button { grid-row: 1 / span 2; grid-column: 2; }
.sc-list li.hint { display: block; border-style: dashed; }
@media (max-width: 820px) { #quick { padding: 6px 10px 0; } }
.pill.fx { border-color: rgba(140,170,230,.45); color: #c9d6f2; }   /* a spell in force */
