:root {
  color-scheme: light dark;
  --bg: #f5f4f1; --surface: #ffffff; --surface-2: #efede8; --line: #dcd9d1; --line-strong: #bdb8ac;
  --text: #24221e; --muted: #68645b; --accent: #4552c4; --accent-ink: #ffffff; --accent-soft: #e6e8fa;
  --good: #1d7a55; --good-soft: #dcf1e7; --warn: #8f5f00; --warn-soft: #fbedcd; --bad: #bb2d33; --bad-soft: #fbe2e2;
  --gold: #8f6c00; --gold-soft: #f8edc4; --dark-node: #e3e0d9; --shadow: 0 1px 2px rgb(0 0 0 / 8%);
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c; --surface: #202227; --surface-2: #2a2c33; --line: #363943; --line-strong: #4f5361;
    --text: #ece9e3; --muted: #a6a39b; --accent: #8c97f4; --accent-ink: #14161f; --accent-soft: #2c3058;
    --good: #5fcf9f; --good-soft: #1b3a2e; --warn: #eebb5c; --warn-soft: #3e3115; --bad: #f58a8c; --bad-soft: #4a2124;
    --gold: #e9c75b; --gold-soft: #3c3313; --dark-node: #2d2f36; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#app { min-height: 100%; display: flex; flex-direction: column; }
h1, h2, h3, h4, h5 { line-height: 1.25; margin: 0; }
h1 { font-size: 24px; } h2 { font-size: 18px; margin: 22px 0 10px; } h3 { font-size: 15px; margin: 18px 0 8px; } h4 { font-size: 15px; margin: 18px 0 8px; }
h5 { font-size: 13px; margin: 0 0 8px; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
code { font: 12px ui-monospace, Menlo, Consolas, monospace; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.brand span { color: var(--muted); font-weight: 400; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.topbar nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; }
.topbar nav a:hover { background: var(--surface-2); }
.topbar nav a.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.who { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.who img { border-radius: 50%; }
.count-pill { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; text-align: center; }
.count-pill.bad { background: var(--bad); color: var(--surface); } .count-pill.warn { background: var(--warn); color: var(--surface); }

.page { width: 100%; max-width: 1040px; margin: 0 auto; padding: 24px 20px 60px; }
.page.narrow { max-width: 640px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sub { color: var(--muted); }
.page-note { padding: 0 20px 40px; max-width: 1100px; margin: 0 auto; width: 100%; color: var(--muted); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.signin { max-width: 440px; margin: 12vh auto; padding: 0 20px; text-align: center; }
.signin h1 { font-size: 30px; margin-bottom: 10px; }
.signin .notice { text-align: left; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 13px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.1); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.btn.danger:hover:not(:disabled) { background: var(--bad); filter: brightness(1.1); }
.btn.good { background: var(--good); border-color: var(--good); color: var(--surface); }
.btn.good:hover:not(:disabled) { background: var(--good); filter: brightness(1.1); }
.btn.danger-quiet { color: var(--bad); border-color: transparent; background: transparent; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.big { padding: 11px 22px; font-size: 16px; margin-top: 8px; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; padding: 2px 4px; text-decoration: underline; }
.icon { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 6px; width: 32px; height: 34px; cursor: pointer; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 12px; min-width: 0; flex: 1; }
.field-label { font-size: 13px; font-weight: 600; }
.hint { color: var(--muted); font-size: 12.5px; }
.hint.bad { color: var(--bad); }
input[type=text], input[type=number], input[type=search], textarea, select { width: 100%; padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; min-width: 0; }
textarea { resize: vertical; }
fieldset:disabled input, fieldset:disabled textarea, fieldset:disabled select { background: var(--surface-2); color: var(--muted); }
.count { align-self: flex-end; font-size: 12px; color: var(--muted); } .count.over { color: var(--bad); font-weight: 600; }
.cols { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: flex-start; }
.cols > .field { flex: 1 1 180px; }
.cols.three > .field { flex: 1 1 150px; } .cols.six > .field { flex: 1 1 100px; }
.rows { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; gap: 6px; align-items: center; }
.row select { flex: 1; }
.emoji-input { display: flex; gap: 6px; }
.emoji-box { flex: 0 0 56px !important; width: 56px !important; text-align: center; font-size: 17px; padding: 4px !important; }
.emoji-input select { flex: 1; }
.meta-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 13px; }
.id { padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.green { background: var(--good-soft); color: var(--good); } .badge.amber { background: var(--warn-soft); color: var(--warn); } .badge.red { background: var(--bad-soft); color: var(--bad); }
.live-note { font-size: 12.5px; color: var(--good); }

.notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0; padding: 9px 13px; border-radius: var(--radius); background: var(--accent-soft); }
.notice.warn { background: var(--warn-soft); } .notice.error { background: var(--bad-soft); } .notice.good { background: var(--good-soft); }
body > #app > .notice { margin: 10px 20px; }
.empty { padding: 26px; border: 1px dashed var(--line-strong); border-radius: var(--radius); text-align: center; color: var(--muted); margin: 10px 0; }
.empty strong { color: var(--text); } .empty p { margin: 4px 0 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card { display: flex; flex-direction: column; gap: 6px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card p { margin: 0; color: var(--muted); }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card-title { font-weight: 650; font-size: 16px; color: var(--text); text-decoration: none; }
.card-title:hover { text-decoration: underline; }
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 12.5px; color: var(--muted); }
.card-actions { display: flex; gap: 6px; margin-top: auto; padding-top: 6px; }
.denied-note { color: var(--bad) !important; font-size: 13px; }

#app:has(.story) { height: 100vh; overflow: hidden; }
.workspace { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.scene-panel .cols > .field { flex-basis: 240px; }
.ws-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 20px; padding: 12px 20px 8px; }
.ws-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.ws-title h1 { font-size: 20px; }
.crumb { color: var(--muted); font-size: 14px; }
.ws-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.save-state { font-size: 12.5px; color: var(--muted); margin-right: 6px; }
.save-state.saved { color: var(--good); } .save-state.failed { color: var(--bad); font-weight: 600; }
.workspace > .notice { margin: 4px 20px; }
.tabs { display: flex; gap: 2px; padding: 0 20px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.form-page { width: 100%; max-width: 680px; margin: 0 auto; padding: 8px 20px 60px; }
.form-page.wide { max-width: 860px; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 24px; max-width: 1100px; margin: 0 auto; padding: 8px 20px; width: 100%; }

.story { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 500px); grid-template-rows: minmax(0, 1fr); flex: 1 1 0; min-height: 420px; }
.map-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.map-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-left: auto; font-size: 12px; color: var(--muted); }
.legend i.k { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--line-strong); margin-left: 8px; }
.legend i.pass { border-color: var(--good); } .legend i.fail { border-color: var(--bad); } .legend i.fight { border-top-style: dashed; border-color: var(--gold); }
.map { flex: 1; overflow: auto; background-color: var(--bg); background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 22px 22px; }
.map svg { display: block; touch-action: manipulation; }
.touch-hint { display: none; margin: 0; padding: 4px 12px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--line); }
@media (pointer: coarse) { .touch-hint { display: block; } }
.edge { fill: none; stroke: var(--line-strong); stroke-width: 1.8; }
.edge.pass { stroke: var(--good); } .edge.fail { stroke: var(--bad); } .edge.fight { stroke: var(--gold); stroke-dasharray: 6 4; }
.arrow { fill: var(--line-strong); } .arrow.pass { fill: var(--good); } .arrow.fail { fill: var(--bad); } .arrow.fight { fill: var(--gold); }
.node { cursor: grab; outline: none; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; } .node:active { cursor: grabbing; }
.node rect { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1.5; }
.node.start rect { stroke: var(--accent); stroke-width: 2; }
.node.win rect { fill: var(--gold-soft); stroke: var(--gold); } .node.lose rect { fill: var(--dark-node); }
.node.selected rect { stroke: var(--accent); stroke-width: 3; } .node:focus-visible rect { stroke: var(--accent); stroke-width: 3; }
.node-title { fill: var(--text); font-size: 13px; font-weight: 600; pointer-events: none; }
.node-sub { fill: var(--muted); font-size: 11.5px; pointer-events: none; }
.mark-error { fill: var(--bad); } .mark-warning { fill: var(--warn); }
.scene-panel { overflow-y: auto; padding: 12px 16px 40px; background: var(--surface); border-left: 1px solid var(--line); min-height: 0; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.panel-head h2, .panel-head h3 { margin: 0; font-size: 17px; }
.collapse { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; background: var(--surface); }
.collapse-head { display: flex; align-items: center; gap: 7px; width: 100%; padding: 8px 10px; border: 0; background: none; color: var(--text); font: inherit; font-weight: 600; text-align: left; cursor: pointer; border-radius: var(--radius); }
.collapse-head:hover { background: var(--surface-2); }
.collapse-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collapse-body { padding: 6px 10px 10px; border-top: 1px solid var(--line); }
.chev { color: var(--muted); width: 12px; }
.dot-mark { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot-mark.error { background: var(--bad); } .dot-mark.warning { background: var(--warn); }
.group { margin: 10px 0; padding: 10px; border-radius: var(--radius); background: var(--surface-2); }
.group .group { background: var(--surface); }
.group.pass { border-left: 3px solid var(--good); } .group.fail { border-left: 3px solid var(--bad); }
.subgroup { padding: 8px; border: 1px dashed var(--line-strong); border-radius: 6px; display: flex; flex-direction: column; gap: 6px; }
.plain { margin: 0; font-size: 13.5px; } .plain code { margin-left: 4px; padding: 1px 5px; border-radius: 4px; background: var(--surface); }
.effect, .effect-block { align-items: flex-end; }
.add-effect { margin-top: 4px; }
.choice-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.danger-zone { margin-top: 20px; padding-top: 10px; border-top: 1px solid var(--line); }

.problems { list-style: none; margin: 8px 0; padding: 0; }
.problem { display: flex; align-items: flex-start; gap: 9px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.problem > div { flex: 1; min-width: 0; }
.problem .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--muted); }
.problem.error .dot { background: var(--bad); } .problem.warning .dot { background: var(--warn); }
.problem .level { font-weight: 650; font-size: 12.5px; margin-right: 3px; }
.problems.compact { font-size: 13px; background: var(--surface-2); border-radius: 6px; }
.problems.compact .problem { border: 0; padding: 5px 8px; }
.stat-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.stat { flex: 1 1 110px; padding: 10px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.stat strong { display: block; font-size: 24px; line-height: 1.2; font-variant-numeric: tabular-nums; } .stat span { color: var(--muted); font-size: 13px; }
.stat.bad strong { color: var(--bad); } .stat.warn strong { color: var(--warn); } .stat.good strong { color: var(--good); }

.pick-list { list-style: none; padding: 0; margin: 10px 0; }
.pick-list li { display: flex; gap: 10px; align-items: flex-start; padding: 10px; margin-bottom: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.pick-list li > div { flex: 1; min-width: 0; } .pick-list p { margin: 2px 0 0; }
.pick-emoji { font-size: 20px; line-height: 1.3; flex: none; }
.checks { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.table-wrap { overflow-x: auto; margin: 10px 0; }
table { border-collapse: collapse; width: 100%; background: var(--surface); }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
thead th { font-size: 12.5px; color: var(--muted); }
tr.muted { opacity: .5; }
td input { min-width: 70px; }
.rate { display: flex; align-items: center; gap: 8px; min-width: 200px; font-variant-numeric: tabular-nums; }
.rate span { flex: 0 0 42px; text-align: right; }
.meter { flex: 1; height: 9px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); }
.meter i.brutal { background: var(--bad); } .meter i.hard { background: var(--warn); } .meter i.fair { background: var(--good); }
.run-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.run-row .field { flex: 0 0 180px; margin: 0; }
.bars { list-style: none; padding: 0; margin: 0; }
.bars li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }

.play { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 24px; max-width: 1020px; width: 100%; margin: 0 auto; padding: 12px 20px 60px; }
.play-main h2 { margin-top: 6px; }
.play-side { position: sticky; top: 10px; align-self: start; }
.news { padding: 8px 12px; margin: 8px 0; border-left: 3px solid var(--line-strong); background: var(--surface-2); border-radius: 0 6px 6px 0; font-size: 14px; }
.rich p { margin: 0 0 6px; } .rich blockquote { margin: 4px 0; padding-left: 10px; border-left: 3px solid var(--line-strong); color: var(--muted); }
.play-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.hero { padding: 7px 10px; margin-bottom: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.hero.down, .hero.dead, .hero.stable { opacity: .65; }
.hero-top { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin: 3px 0; }
.bar i { display: block; height: 100%; background: var(--good); }
.zones { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); margin: 8px 0; }
.zone { display: flex; gap: 10px; align-items: center; padding: 7px 10px; min-height: 40px; border-bottom: 1px solid var(--line); }
.zone:last-child { border: 0; }
.zone-name { flex: 0 0 76px; font-size: 12.5px; color: var(--muted); }
.token { display: inline-block; padding: 1px 8px; margin: 2px; border-radius: 12px; font-size: 13px; background: var(--surface-2); }
.token.enemy { background: var(--bad-soft); } .token.active { background: var(--accent-soft); font-weight: 650; }

.pool { display: grid; grid-template-columns: 320px minmax(0, 1fr); flex: 1; min-height: 0; }
.pool-list { padding: 16px; border-right: 1px solid var(--line); background: var(--surface); overflow-y: auto; height: calc(100vh - 53px); }
.pool-list h1 { font-size: 20px; }
.pool-list ul { list-style: none; padding: 0; margin: 10px 0 0; }
.pool-list li a { display: flex; gap: 9px; padding: 8px; border-radius: 6px; color: var(--text); text-decoration: none; }
.pool-list li a:hover { background: var(--surface-2); } .pool-list li a.active { background: var(--accent-soft); }
.pool-list li a span:last-child { min-width: 0; }
.pool-list .id { display: block; width: fit-content; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.pool-list small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pool-main { padding: 16px 24px 60px; overflow-y: auto; height: calc(100vh - 53px); }
.pool-form { max-width: 720px; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }

@media (max-width: 860px) {
  #app:has(.story) { height: auto; overflow: visible; }
  .story { grid-template-columns: 1fr; grid-template-rows: auto; flex: none; }
  .map { height: 300px; flex: none; }
  .scene-panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .pool { grid-template-columns: 1fr; }
  .pool-list { height: auto; max-height: 280px; border-right: 0; border-bottom: 1px solid var(--line); }
  .pool-main { height: auto; padding: 14px 16px 40px; }
  .play { grid-template-columns: 1fr; }
  .play-side { position: static; }
  .topbar nav { order: 3; flex-basis: 100%; }
  .who { margin-left: auto; }
  .topbar, .ws-head { padding-left: 16px; padding-right: 16px; }
  .page, .form-page { padding-left: 16px; padding-right: 16px; }
}
