  /* ---- palette ----
     Dark is the base. Light is a designed counterpart, not an inversion: warm
     paper instead of white, warm dark ink instead of black, and an accent moved
     from lamplit gold to bronze because #c8a45c disappears on paper (it needs a
     darker, more saturated shade to hold contrast on a light ground).
     Theme selection is the data-theme attribute on <html>, written before first
     paint by the boot script in index.html:
       data-theme="dark"  → the base block below
       data-theme="light" → the explicit light block
       data-theme="auto"  → prefers-color-scheme decides
     The two light blocks are duplicates BY NECESSITY (CSS has no mixins) —
     change one, change the other. */
  :root {
    color-scheme: dark;
    --bg: #14120f; --panel: #1d1a16; --panel2: #232019; --ink: #e8e0d0; --dim: #9a8f7a;
    --accent: #c8a45c; --accent2: #8c2f22; --line: #3a352c; --good: #6a9955; --bad: #b5534a;
    --shadow: rgba(0, 0, 0, .5);
    /* reading settings — the settings popover writes these on <html> */
    --prose: 17px; --col: 38em;
  }
  @media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
      color-scheme: light;
      --bg: #f4ede0; --panel: #ece2d0; --panel2: #e2d6c0; --ink: #2a251e; --dim: #6b6050;
      --accent: #8a5a1a; --accent2: #8c2f22; --line: #d5c8ae; --good: #4d7a3c; --bad: #a3352a;
      --shadow: rgba(60, 45, 20, .22);
    }
  }
  :root[data-theme="light"] {
    color-scheme: light;
    --bg: #f4ede0; --panel: #ece2d0; --panel2: #e2d6c0; --ink: #2a251e; --dim: #6b6050;
    --accent: #8a5a1a; --accent2: #8c2f22; --line: #d5c8ae; --good: #4d7a3c; --bad: #a3352a;
    --shadow: rgba(60, 45, 20, .22);
  }
  * { box-sizing: border-box; margin: 0; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  /* Nothing here is load-bearing motion — a reader who asked for stillness gets it. */
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: .01ms !important; animation-iteration-count: 1 !important;
      transition-duration: .01ms !important; scroll-behavior: auto !important;
    }
  }
  [hidden] { display: none !important; }
  body {
    background: var(--bg); color: var(--ink); height: 100dvh; display: flex; flex-direction: column;
    font-family: "Songti TC", "Noto Serif TC", "PMingLiU", serif; font-size: 17px; line-height: 1.85;
  }
  header {
    display: flex; align-items: baseline; gap: 14px; padding: 10px 18px; border-bottom: 1px solid var(--line);
    background: var(--panel); flex-wrap: wrap;
  }
  header h1 { font-size: 18px; letter-spacing: 4px; color: var(--accent); font-weight: 600; }
  header .meta { color: var(--dim); font-size: 13px; letter-spacing: 1px; }
  header .spacer { flex: 1; }
  header button { font-size: 12px; }
  #layout { flex: 1; display: flex; min-height: 0; }
  #story { flex: 1; overflow-y: auto; padding: 26px 8%; font-size: var(--prose); }
  /* The reading column: prose is measured in characters per line, not in screen
     width. Everything in the flow — turns, the options block, the status line —
     shares the one column so the eye never has to re-find the left margin. */
  #story > * { max-width: var(--col); margin-left: auto; margin-right: auto; }
  #story .turn { margin-bottom: 30px; }
  #story .action {
    color: var(--accent); font-size: 14px; letter-spacing: 1px; margin-bottom: 8px;
  }
  #story .action::before { content: "➤ "; }
  #story .prose { white-space: pre-wrap; text-align: justify; }
  #story .sys { color: var(--dim); font-size: 13px; margin: 14px 0; }
  /* 序幕 — the world's 前提, sitting above the first turn. Deliberately QUIETER than
     narration: it is what the player already knows walking in, not something that just
     happened. Colour comes from --dim/--line, so both themes follow the palette. */
  #story .prologue { border-left: 2px solid var(--line); padding-left: 16px; margin-bottom: 36px; }
  #story .prologuehead { color: var(--dim); font-size: 12px; letter-spacing: 4px; margin-bottom: 8px; }
  #story .prologuebody {
    color: var(--ink); opacity: .92; white-space: pre-wrap; text-align: justify;
    font-size: inherit; line-height: 1.85;
  }
  /* The status line: one dim line closing the latest turn. Each item is an
     inline-block so a phone breaks BETWEEN items, never inside "氣血 20/20". */
  .statusline { color: var(--dim); font-size: 12.5px; line-height: 1.9; letter-spacing: .5px; margin-top: 16px; }
  .statusline::before { content: "［"; }
  .statusline::after { content: "］"; }
  .statusline .sl { display: inline-block; }
  /* separator is real text in app.js (copy-paste must keep it) */
  #side {
    width: 250px; border-left: 1px solid var(--line); background: var(--panel); padding: 16px;
    overflow-y: auto; font-size: 13px; flex-shrink: 0;
  }
  #side h3 { color: var(--dim); font-size: 12px; letter-spacing: 3px; margin: 14px 0 8px; font-weight: normal; }
  #side h3:first-child { margin-top: 0; }
  .stat { margin-bottom: 8px; }
  .stat .label { display: flex; justify-content: space-between; color: var(--ink); margin-bottom: 2px; }
  .stat .bar { height: 4px; background: var(--panel2); border-radius: 2px; overflow: hidden; }
  .stat .bar i { display: block; height: 100%; background: var(--good); }
  .stat .bar i.warn { background: var(--bad); }
  .stat.art .label { color: var(--ink); }
  .stat.art .artaffords { color: var(--dim); font-size: 12px; line-height: 1.65; margin: 2px 0 8px; }
  .stat.art .statdetail { white-space: normal; }
  .tierchip {
    font-style: normal; color: var(--accent); font-size: 10px; letter-spacing: 1px;
    border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 5px; vertical-align: 1px;
  }
  /* 階為事: the band is NEW. The mark is the chip's own border and ground, not a badge or an
     animation — the row must read as the same row, standing somewhere it did not stand before. */
  .tierchip.fresh { border-color: var(--accent); background: var(--panel2); }
  /* 本回得失: one dim line under the prose, above the status line. Same column, same restraint —
     it says what MOVED; the status line says where things stand. */
  .gainloss { color: var(--dim); font-size: 12.5px; line-height: 1.9; letter-spacing: .5px; margin-top: 14px; }
  .statname.expandable { cursor: pointer; border-bottom: 1px dotted var(--dim); }
  .statdetail { color: var(--dim); font-size: 12px; line-height: 1.7; margin: 4px 0 2px; }
  .tokens { color: var(--dim); line-height: 1.7; }
  /* 未了: one row per open question; the turn it opened sits dim beside it. */
  #openQuestions { color: var(--accent); line-height: 1.6; }
  #openQuestions .openq { margin-bottom: 6px; }
  #openQuestions .since { color: var(--dim); font-size: 11px; margin-left: 6px; white-space: nowrap; }
  #controls { border-top: 1px solid var(--line); background: var(--panel); padding: 12px 8% 16px; }
  /* The control bar aligns to the same reading column as the prose above it. */
  #controls > * { max-width: var(--col); margin-left: auto; margin-right: auto; }
  #options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
  /* The options box lives INSIDE the story flow whenever there are options — on
     every viewport now, so they read as the choices ending the latest turn. Keep
     the auto margins: this rule outranks the #story > * column rule. */
  #story > #options { margin: -8px auto 30px; }
  #options button {
    text-align: left; padding: 10px 14px; background: var(--panel2); border: 1px solid var(--line);
    color: var(--ink); font: inherit; font-size: 15px; border-radius: 6px; cursor: pointer; line-height: 1.6;
  }
  #options button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
  #options button .n { color: var(--accent); margin-right: 10px; }
  /* Confirmation beat: the tapped option lights up, the others recede, THEN the
     block becomes the turn's ➤ action line — the chosen text never just vanishes. */
  #options button.chosen { border-color: var(--accent); color: var(--accent); opacity: 1; }
  #options button.dim { opacity: .25; transition: opacity .35s ease; }
  /* QUEUED: tapped while the turn was still committing. The tap is held, not lost — the
     option fills in (the accent the page already uses for a live choice, over the raised
     panel tone) and says 等待中…, then submits itself the moment the turn lands. Every
     colour is a palette variable, so both themes are covered by construction. */
  #options button.queued {
    border-color: var(--accent); color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, var(--panel2));
  }
  #options button .qwait { font-style: normal; font-size: 12px; letter-spacing: 2px; color: var(--dim); margin-left: 10px; }
  #options button.queued .qwait { color: var(--accent); }
  /* The free-text submit during a turn: waiting, not merely dead (button:disabled dims it). */
  #btnGo.waiting { letter-spacing: 1px; }

  #freeform { display: flex; gap: 8px; }
  #freeform input {
    flex: 1; background: var(--panel2); border: 1px solid var(--line); color: var(--ink);
    font: inherit; font-size: 15px; padding: 10px 14px; border-radius: 6px; outline: none;
  }
  #freeform input:focus { border-color: var(--accent); }
  #freeform input::placeholder { color: var(--dim); }
  button.primary, #side button, header button {
    background: var(--panel2); color: var(--accent); border: 1px solid var(--accent);
    font: inherit; padding: 10px 18px; border-radius: 6px; cursor: pointer;
  }
  button:disabled { opacity: .4; cursor: default; }
  /* ---- 設定 popover (字級 / 主題 / 版面寬度) ---- */
  .popwrap { position: relative; display: inline-block; }
  #settings {
    position: absolute; top: calc(100% + 10px); right: 0; z-index: 30; width: 236px; text-align: left;
    background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
    padding: 13px 15px 15px; box-shadow: 0 12px 30px var(--shadow);
  }
  #settings h4 { color: var(--dim); font-size: 11px; letter-spacing: 2px; font-weight: normal; margin: 14px 0 6px; }
  #settings h4:first-child { margin-top: 0; }
  #settings .seg { display: flex; gap: 6px; }
  #settings .seg button {
    flex: 1; background: var(--panel2); border: 1px solid var(--line); color: var(--dim);
    font: inherit; font-size: 13px; letter-spacing: 1px; padding: 7px 0; border-radius: 6px; cursor: pointer;
  }
  #settings .seg button:hover { color: var(--ink); }
  #settings .seg button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
  #status { color: var(--dim); font-size: 13px; min-height: 20px; margin-bottom: 6px; letter-spacing: 1px; }
  .pending { color: var(--dim); animation: breathe 1.6s ease-in-out infinite; }
  @keyframes breathe { 0%,100% { opacity: .35; } 50% { opacity: .9; } }
  /* landing */
  #landing { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 24px; }
  #landing h1 { font-size: 42px; letter-spacing: 16px; color: var(--accent); font-weight: 600; }
  #landing p { color: var(--dim); letter-spacing: 2px; }
  #landing .card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 22px 26px; width: min(430px, 92vw); }
  #landing .card h3 { color: var(--dim); font-size: 13px; letter-spacing: 3px; margin-bottom: 12px; font-weight: normal; }
  #landing .save { display: flex; justify-content: space-between; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
  #landing .save:hover .name { color: var(--accent); }
  #landing .save .sub { color: var(--dim); font-size: 12px; }
  .savedel { background: none; border: none; color: var(--dim); cursor: pointer; font: inherit; font-size: 12px; padding: 2px 6px; }
  .savedel:hover { color: var(--bad); }
  #landing input, #landing select {
    width: 100%; background: var(--panel2); border: 1px solid var(--line); color: var(--ink);
    font: inherit; padding: 9px 12px; border-radius: 6px; margin-bottom: 10px; outline: none;
  }
  .wcard {
    border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 8px;
    cursor: pointer; background: var(--panel2);
  }
  .wcard.sel { border-color: var(--accent); }
  .wcard .wtitle { color: var(--ink); font-size: 16px; }
  .wcard.sel .wtitle { color: var(--accent); }
  .wcard .wgenre { color: var(--dim); font-size: 11px; letter-spacing: 2px; margin-left: 8px; }
  .wcard .wtag { color: var(--dim); font-size: 13px; line-height: 1.6; margin-top: 4px; }
  /* 起點 — one card per authored origin, indented under the world cards it belongs to. */
  #originWrap { margin: 2px 0 10px 12px; padding-left: 10px; border-left: 1px solid var(--line); }
  #originWrap .ohead { color: var(--dim); font-size: 11px; letter-spacing: 2px; margin-bottom: 6px; }
  .ocard {
    border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; margin-bottom: 6px;
    cursor: pointer; background: var(--panel2);
  }
  .ocard.sel { border-color: var(--accent); }
  .ocard .otitle { color: var(--ink); font-size: 14px; }
  .ocard.sel .otitle { color: var(--accent); }
  .ocard .oregion { color: var(--dim); font-size: 11px; letter-spacing: 2px; margin-left: 8px; }
  .ocard .ohook { color: var(--dim); font-size: 12px; line-height: 1.6; margin-top: 4px; }
  .styleseg { display: flex; gap: 8px; margin-bottom: 10px; }
  .styleseg button {
    flex: 1; background: var(--panel2); border: 1px solid var(--line); color: var(--dim);
    font: inherit; font-size: 14px; padding: 9px 0; border-radius: 6px; cursor: pointer;
  }
  .styleseg button.sel { border-color: var(--accent); color: var(--accent); }
  /* ---- 書卷 reader (read-only overlay over the game) ---- */
  #reader {
    position: fixed; inset: 0; z-index: 40; background: var(--bg);
    display: flex; flex-direction: column;
  }
  #readerBar {
    display: flex; align-items: center; gap: 12px; padding: 10px 18px;
    padding-top: calc(10px + env(safe-area-inset-top));
    border-bottom: 1px solid var(--line); background: var(--panel); flex-shrink: 0;
  }
  #readerBar .spacer { flex: 1; }
  #readerBar button {
    background: none; border: none; color: var(--dim); font: inherit; font-size: 14px;
    cursor: pointer; padding: 4px 6px;
  }
  #readerBar button:hover { color: var(--accent); }
  #readerTitle { color: var(--accent); font-size: 15px; letter-spacing: 3px; }
  /* The text column, and nothing else: no chrome lives inside it. */
  #readerBody {
    flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 26px 8% calc(40px + env(safe-area-inset-bottom));
    font-size: var(--prose);
  }
  #readerBody > * { max-width: var(--col); margin-left: auto; margin-right: auto; }
  .rvol {
    color: var(--dim); font-size: 12px; letter-spacing: 4px; margin: 26px 0 10px;
    border-bottom: 1px solid var(--line); padding-bottom: 6px;
  }
  .rvol:first-child { margin-top: 0; }
  .rchap { padding: 12px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
  .rchap:hover .rchaptitle { color: var(--accent); }
  .rchaptitle { font-size: 16px; line-height: 1.6; }
  .rchap.open .rchaptitle { color: var(--accent); }
  .rchapbadge {
    color: var(--accent); font-size: 10px; letter-spacing: 1px; border: 1px solid var(--line);
    border-radius: 4px; padding: 0 4px; margin-left: 8px; vertical-align: 2px;
  }
  .rchapsnip { color: var(--dim); font-size: 13px; line-height: 1.7; margin-top: 4px; }
  .rhead { margin-bottom: 26px; }
  .rhead .t { color: var(--accent); font-size: 19px; letter-spacing: 2px; line-height: 1.6; }
  .rhead .s { color: var(--dim); font-size: 12px; letter-spacing: 2px; margin-top: 4px; }
  .raction { color: var(--dim); font-size: 13px; letter-spacing: 1px; margin: 24px 0 8px; }
  .raction::before { content: "➤ "; }
  .rprose { white-space: pre-wrap; text-align: justify; margin-bottom: 4px; }
  .rclosing {
    white-space: pre-wrap; color: var(--dim); font-size: 14px; line-height: 1.9;
    border-top: 1px solid var(--line); margin-top: 30px; padding-top: 16px;
  }
  /* LEGACY — a 回憶 day in the book (the feature was removed 2026-07-30; old saves keep
     their entries). Set apart and dim, so a remembered day never passes for a played one. */
  .rrecall {
    border-left: 2px solid var(--line); padding-left: 14px; margin: 20px 0 24px;
    color: var(--dim); font-size: 14.5px; line-height: 1.9; white-space: pre-wrap; text-align: justify;
  }
  .rrecallhead { color: var(--accent); font-size: 12px; letter-spacing: 3px; margin-bottom: 6px; white-space: normal; }
  .rrecallpromise { font-size: 12.5px; margin-bottom: 5px; white-space: normal; }
  .rrecallchosen { font-size: 13px; margin-top: 7px; white-space: normal; }
  .rempty { color: var(--dim); font-size: 14px; padding: 20px 0; }
  /* ---- 畫像 / 輿圖 — world assets. Only ever visible when the world ships the image. ---- */
  #castList {
    display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px;
    border-top: 1px solid var(--line); padding-top: 12px;
  }
  .portrait { margin: 0; width: 56px; text-align: center; }
  .portrait img {
    width: 56px; height: 56px; object-fit: cover; border-radius: 6px;
    border: 1px solid var(--line); display: block; background: var(--panel2);
  }
  .portrait figcaption { color: var(--dim); font-size: 11px; margin-top: 4px; line-height: 1.4; word-break: break-all; }
  /* ---- 武學 — overlay drawer, same bones as 書卷 / 輿圖. One panel, not a modal per art. ---- */
  #artsView { position: fixed; inset: 0; z-index: 42; background: var(--bg); display: flex; flex-direction: column; }
  #artsBar {
    display: flex; align-items: center; gap: 12px; padding: 10px 18px;
    padding-top: calc(10px + env(safe-area-inset-top));
    border-bottom: 1px solid var(--line); background: var(--panel); flex-shrink: 0;
  }
  #artsBar .spacer { flex: 1; }
  #artsBar button { background: none; border: none; color: var(--dim); font: inherit; font-size: 14px; cursor: pointer; padding: 4px 6px; }
  #artsBar button:hover { color: var(--accent); }
  #artsTitle { color: var(--accent); font-size: 15px; letter-spacing: 3px; }
  #artsBody {
    flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 18px 8% calc(36px + env(safe-area-inset-bottom));
    max-width: var(--col); margin: 0 auto; width: 100%; box-sizing: border-box;
  }
  #mapView { position: fixed; inset: 0; z-index: 45; background: var(--bg); display: flex; flex-direction: column; }
  #mapBar {
    display: flex; align-items: center; gap: 12px; padding: 10px 18px;
    padding-top: calc(10px + env(safe-area-inset-top));
    border-bottom: 1px solid var(--line); background: var(--panel); flex-shrink: 0;
  }
  #mapBar .spacer { flex: 1; }
  #mapBar button { background: none; border: none; color: var(--dim); font: inherit; font-size: 14px; cursor: pointer; padding: 4px 6px; }
  #mapBar button:hover { color: var(--accent); }
  #mapTitle { color: var(--accent); font-size: 15px; letter-spacing: 3px; }
  #mapBody {
    flex: 1; overflow: auto; -webkit-overflow-scrolling: touch;
    display: flex; align-items: center; justify-content: center;
    padding: 16px 4% calc(24px + env(safe-area-inset-bottom));
  }
  #mapImage { max-width: 100%; max-height: 100%; object-fit: contain; }
  #btnSide { display: none; }
  @media (max-width: 760px) {
    body { font-size: 16px; }
    header { padding: 8px 12px; gap: 10px; }
    header .meta { font-size: 12px; }
    #btnSide { display: inline-block; }
    /* stats become a toggleable sheet instead of disappearing */
    #side { position: fixed; top: 0; right: 0; bottom: 0; width: min(78vw, 300px); z-index: 20;
            transform: translateX(105%); transition: transform .22s ease; box-shadow: -12px 0 30px var(--shadow); }
    #side.open { transform: none; }
    #story { padding: 18px 5%; }
    #readerBar { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); gap: 10px; }
    #readerBody { padding: 18px 5% calc(36px + env(safe-area-inset-bottom)); }
    #artsBar { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); gap: 10px; }
    #artsBody { padding: 16px 5% calc(28px + env(safe-area-inset-bottom)); }
    #mapBar { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); gap: 10px; }
    #mapBody { padding: 12px 3% calc(20px + env(safe-area-inset-bottom)); }
    #controls { padding: 10px 4% calc(12px + env(safe-area-inset-bottom)); }
    #options button { padding: 7px 10px; font-size: 16px; }
    #options { gap: 6px; }
    #freeform input, #landing input, #landing select, #login input { font-size: 16px; } /* prevents iOS focus zoom */
  }
