:root {
  color-scheme: dark;
  /* Yarnfray palette */
  --night: #0d1b2a; --arcane: #6c3bbf; --tech: #00c2d4; --story: #f4a261; --ember: #c4633a; --paper: #f7eedb;
  --bg: #0d1b2a; --panel: #152538; --ink: #f7eedb; --muted: #9db2c9;
  --line: #263a52; --brand: #f4a261; --brand-ink: #0d1b2a;
  --ok: #34c98a; --warn: #f4a261; --err: #e0684f; --shadow: 0 2px 10px rgba(0,0,0,.35);
  --radius: 12px; --maxw: 1040px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1b2a; --panel: #152538; --ink: #f7eedb; --muted: #9db2c9;
    --line: #263a52; --shadow: 0 2px 10px rgba(0,0,0,.5);
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

/* nav */
nav {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
nav .wrap { display: flex; align-items: center; gap: 20px; height: 60px; }
nav .brand { font-weight: 800; font-size: 18px; letter-spacing: -.02em; color: var(--story); }
nav .brand span { color: var(--tech); }
nav .links { margin-left: auto; display: flex; gap: 18px; align-items: center; }
nav .links a { color: var(--muted); font-weight: 600; font-size: 15px; }
nav .links a:hover { color: var(--ink); text-decoration: none; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 10px 16px; border-radius: 10px; font-weight: 650; font-size: 15px;
}
.btn:hover { border-color: var(--brand); text-decoration: none; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.big { padding: 13px 22px; font-size: 16px; }

/* hero */
.hero { padding: 72px 0 40px; text-align: center; }
.hero h1 { font-size: clamp(32px, 5vw, 52px); line-height: 1.08; letter-spacing: -.03em; margin: 0 0 16px; }
.hero .lead { font-size: clamp(17px, 2.4vw, 21px); color: var(--muted); max-width: 660px; margin: 0 auto 28px; }
.hero .cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.kicker { display:inline-block; font-weight:700; font-size:13px; letter-spacing:.08em; text-transform:uppercase;
  color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, transparent);
  padding: 5px 12px; border-radius: 999px; margin-bottom: 18px; }

/* sections */
section { padding: 44px 0; }
section h2 { font-size: clamp(24px, 3.4vw, 34px); letter-spacing: -.02em; margin: 0 0 8px; }
section .sub { color: var(--muted); margin: 0 0 28px; font-size: 17px; }
.center { text-align: center; }

/* cards / steps */
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); }
.card .n { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  font-weight: 800; background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); margin-bottom: 12px; }
.card h3 { margin: 0 0 6px; font-size: 18px; }
.card p { margin: 0; color: var(--muted); }

/* chat mock */
.mock { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; max-width: 460px; margin: 28px auto 0; text-align: left; }
.bubble { background: color-mix(in srgb, var(--brand) 8%, var(--panel)); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 13px; margin: 8px 0; font-size: 14.5px; }
.bubble .who { font-weight: 700; color: var(--brand); font-size: 12px; text-transform: uppercase; letter-spacing:.04em; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.chip { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 600; }

/* tool */
.tool { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .tool { grid-template-columns: 1fr 1fr; } }
textarea, .code {
  width: 100%; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; resize: vertical;
}
textarea { min-height: 300px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.report { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px;
  white-space: pre-wrap; font: 13.5px/1.55 ui-monospace, Menlo, Consolas, monospace; }
.status { font-weight: 700; padding: 8px 12px; border-radius: 8px; display: inline-block; }
.status.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.status.err { color: var(--err); background: color-mix(in srgb, var(--err) 12%, transparent); }
.status.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.muted { color: var(--muted); }
details { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: var(--panel); }
details summary { cursor: pointer; font-weight: 650; }
svg.map { width: 100%; height: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.hidden { display: none; }
footer { border-top: 1px solid var(--line); color: var(--muted); padding: 30px 0; font-size: 14px; margin-top: 40px; }
.spinner { display:inline-block; width:14px; height:14px; border:2px solid var(--line);
  border-top-color: var(--brand); border-radius:50%; animation: spin .7s linear infinite; vertical-align:-2px; }
@keyframes spin { to { transform: rotate(360deg); } }
ol.steps { padding-left: 0; list-style: none; counter-reset: s; display: grid; gap: 14px; }
ol.steps li { counter-increment: s; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 16px 18px 16px 56px; position: relative; }
ol.steps li::before { content: counter(s); position: absolute; left: 16px; top: 16px; width: 26px; height: 26px;
  border-radius: 7px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; }
code.inline { background: color-mix(in srgb, var(--brand) 10%, transparent); padding: 1px 6px; border-radius: 5px;
  font: 13px ui-monospace, Menlo, Consolas, monospace; }
.statline { color: var(--muted); font-size: 14px; margin: 4px 0 14px; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .02em; padding: 2px 7px;
  border-radius: 999px; background: color-mix(in srgb, var(--brand) 13%, transparent); color: var(--brand);
  vertical-align: 1px; }
.tag.mv { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
ul.abil { list-style: none; padding: 0; margin: 4px 0 6px; display: grid; gap: 8px; }
ul.abil li { padding-left: 2px; font-size: 14.5px; }
ul.abil.tree li { padding-left: 16px; position: relative; color: var(--ink); }
ul.abil.tree li::before { content: "↳"; position: absolute; left: 0; color: var(--brand); font-weight: 700; }
h4.sub2 { margin: 14px 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

/* campaign builder hub */
.startbar { display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .startbar { grid-template-columns: 1fr 1fr; } }
.startcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); }
.startcard h3 { margin: 0 0 6px; font-size: 17px; }
.startcard p { margin: 0 0 12px; }
.field { font: 14px inherit; background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; }
.field:focus { outline: none; border-color: var(--brand); }
.snips .btn { padding: 7px 12px; font-size: 14px; }

/* live feedback column */
.feedback { position: sticky; top: 76px; align-self: start; }
@media (max-width: 899px) { .feedback { position: static; } }
.outgroup { margin-top: 12px; }
.outhead { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }
.outlist { display: flex; flex-wrap: wrap; gap: 6px; }
.outrow { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px;
  padding: 5px 10px; font-size: 13px; font-weight: 600; cursor: pointer; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.outrow:hover { border-color: var(--brand); }
.outrow.static { cursor: default; color: var(--muted); font-weight: 500; }
.outrow.static:hover { border-color: var(--line); }

/* rules checklist */
.rule { border-top: 1px solid var(--line); padding: 9px 0; font-size: 13.5px; }
.rule:first-child { border-top: none; }
.rule .muted { font-size: 13px; }
.sev { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  padding: 1px 7px; border-radius: 999px; vertical-align: 1px; }
.sev-error { background: color-mix(in srgb, var(--err) 15%, transparent); color: var(--err); }
.sev-warning { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.sev-map { background: color-mix(in srgb, var(--brand) 15%, transparent); color: var(--brand); }
.sev-profile { background: color-mix(in srgb, var(--muted) 22%, transparent); color: var(--muted); }

/* chapters panel */
.chapters-panel summary { font-size: 15px; }
.chapters-panel textarea { min-height: 150px; }

/* editor tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs .tab { appearance: none; border: 1px solid transparent; border-bottom: none; background: transparent;
  color: var(--muted); font: inherit; font-weight: 650; font-size: 14px; padding: 8px 14px; cursor: pointer;
  border-radius: 8px 8px 0 0; margin-bottom: -1px; }
.tabs .tab:hover { color: var(--ink); }
.tabs .tab.active { color: var(--ink); background: var(--panel); border-color: var(--line); }

/* form editor */
.fcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.fhead { margin: 0 0 10px; font-size: 15px; }
.fentity { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-top: 10px; background: color-mix(in srgb, var(--brand) 3%, var(--panel)); }
.frow { display: block; margin: 8px 0; }
.frow .flabel, .fsub .flabel { display: block; font-size: 12px; font-weight: 700; letter-spacing: .02em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
.fsub { margin: 8px 0; }
.field { font: 14px inherit; width: auto; background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; }
.field:focus { outline: none; border-color: var(--brand); }
select.field { min-width: 120px; }
.fcheck { display: inline-flex; align-items: center; gap: 5px; font-size: 14px; cursor: pointer; }
.advnote { margin: 8px 0 0; font-size: 12.5px; color: var(--warn); }

/* store card map thumbnail */
.thumb { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); max-height: 150px; }
.thumb svg.map { border: none; border-radius: 0; max-height: 150px; display: block; }
.thumb .muted { display: none; }  /* hide per-level titles in the compact thumbnail */

/* rules builder */
.knob { border-top: 1px solid var(--line); padding: 12px 0; display: grid; gap: 6px; }
.knob:first-child { border-top: none; }
.knob .kpath { font: 12.5px ui-monospace, Menlo, Consolas, monospace; color: var(--brand); font-weight: 700; }
.knob .kmean { font-size: 13px; color: var(--muted); }
.knob .krow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.knob .kbase { font-size: 12px; color: var(--muted); }
.knob.changed { background: color-mix(in srgb, var(--brand) 5%, transparent); border-radius: 8px; padding-left: 8px; padding-right: 8px; }
.rgroup { margin: 16px 0; }
.rgroup > h3 { margin: 0 0 2px; font-size: 15px; }
.difftable { width: 100%; border-collapse: collapse; font: 13px ui-monospace, Menlo, Consolas, monospace; }
.difftable th, .difftable td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); }
.difftable th { color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.difftable .was { color: var(--muted); }
.difftable .now { color: var(--ok); font-weight: 700; }

/* landing "try a turn" demo */
.demo { max-width: 520px; margin: 8px auto 0; }
.democard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; text-align: left; }
.demoroom { font-weight: 800; font-size: 18px; letter-spacing: -.01em; }
.demolog { background: color-mix(in srgb, var(--brand) 8%, var(--panel)); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 14px; white-space: pre-wrap; }
.demoacts { display: flex; flex-wrap: wrap; gap: 8px; }
.demo-btn { cursor: pointer; background: var(--panel); }
.demo-btn:hover { border-color: var(--brand); }

/* playable fight board */
.fightboard { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-top: 10px; background: var(--panel); }
.roster { display: grid; gap: 6px; margin-bottom: 10px; }
.cmb { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2, var(--bg)); font-size: 13.5px; }
.cmb.active { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.cmb.dead { opacity: .5; }
.cmb.dead .cmb-name { text-decoration: line-through; }
.cmb.downed { border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }
.cmb-name { font-weight: 600; }
.cmb-sub { font-weight: 400; font-size: 11px; color: var(--muted); margin-left: 6px; }
.cmbtok { position: relative; display: inline-grid; place-items: center; width: 30px; height: 30px;
  border-radius: 50%; vertical-align: middle; overflow: hidden; }
.cmbtok img { image-rendering: pixelated; display: block; }
.cmbtok.ally { background: color-mix(in srgb, #5a96dc 30%, var(--panel)); }
.cmbtok.foe { background: color-mix(in srgb, #c85a5a 30%, var(--panel)); }
.cmbtok.dead { filter: grayscale(1); opacity: .6; }
.cmbtok.boss { width: 34px; height: 34px; box-shadow: 0 0 0 2px #f5cd46; overflow: visible; }
.cmbtok .crown { position: absolute; top: -9px; left: 50%; transform: translateX(-50%); font-size: 11px; line-height: 1; }
.dialoguecard { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); box-shadow: 0 0 0 1px color-mix(in srgb, var(--brand) 20%, transparent) inset; }
.cmb-hp { display: flex; align-items: center; gap: 8px; }
.cmb-num { font: 12px ui-monospace, Menlo, Consolas, monospace; color: var(--muted); min-width: 46px; text-align: right; }
.hpbar { display: inline-block; width: 84px; height: 8px; border-radius: 999px; overflow: hidden;
  background: color-mix(in srgb, var(--muted) 25%, transparent); }
.hpbar > span { display: block; height: 100%; border-radius: 999px; }
.fightlog { margin: 6px 0 10px; max-height: 220px; overflow-y: auto; font-size: 13px; }

/* combat sim bar */
.simbar { height: 12px; border-radius: 999px; background: color-mix(in srgb, var(--muted) 25%, transparent); overflow: hidden; }
.simbar > span { display: block; height: 100%; border-radius: 999px; }

/* playtest board */
.pt-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.pt-actions .flabel { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-right: 2px; }
.pt-btn { padding: 6px 11px; font-size: 13.5px; }
.pt-btn.locked { opacity: .55; cursor: not-allowed; }
.pt-enc { background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 13.5px; }

/* ───────────────────── responsive / mobile ───────────────────── */
/* Keep media and wide content from forcing a page-level horizontal scroll.
   (We deliberately don't set overflow-x:hidden on html/body — that would break
   the sticky nav — so wide widgets scroll inside their own boxes instead.) */
img, svg, video, canvas { max-width: 100%; height: auto; }
/* Wide content scrolls inside its own box, not the page. */
.report, pre.code { overflow-x: auto; }
#rules-diff, .difftable-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.difftable { min-width: 340px; }

/* Hamburger button (injected by nav.js) — hidden until the nav collapses. */
.navburger { display: none; margin-left: auto; background: transparent; border: 1px solid var(--line);
  color: var(--ink); border-radius: 9px; padding: 5px 12px; font-size: 18px; line-height: 1; cursor: pointer; }
.navburger:hover { border-color: var(--brand); }

@media (max-width: 720px) {
  /* Nav collapses to a hamburger: the links become a dropdown panel. */
  nav .wrap { gap: 12px; height: 54px; padding: 0 14px; }
  nav .brand { font-size: 16px; flex: 0 0 auto; }
  .navburger { display: inline-flex; align-items: center; }
  nav .links { display: none; position: absolute; top: 100%; left: 10px; right: 10px;
    flex-direction: column; align-items: stretch; gap: 2px; margin: 6px 0 0;
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
    box-shadow: var(--shadow); padding: 8px; z-index: 20; }
  nav .links.open { display: flex; }
  nav .links a { font-size: 15px; padding: 11px 12px; border-radius: 8px; }
  nav .links a:hover { background: color-mix(in srgb, var(--brand) 10%, transparent); text-decoration: none; }
  nav .links a.btn.primary { justify-content: center; margin-top: 4px; }

  section { padding: 32px 0; }
  .hero { padding: 48px 0 30px; }
  .wrap { padding: 0 16px; }

  /* Editor toolbars & action rows wrap cleanly and stay tappable. */
  .row { gap: 8px; }
  .btn { padding: 10px 14px; }              /* ~44px tap target */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs .tab { flex: 0 0 auto; }
  textarea { min-height: 220px; }

  /* Sticky feedback column shouldn't pin on small screens (also set below 900px). */
  .feedback { position: static; }
  /* Form field inputs go full-width so they're easy to tap and read. */
  select.field, .frow .field, .fsub .field { width: 100%; }
  .knob .krow { gap: 8px; }
}

@media (max-width: 480px) {
  .hero h1 { font-size: 30px; }
  .cta .btn.big, .hero .cta .btn { width: 100%; justify-content: center; }
  .grid { grid-template-columns: 1fr; }
}
