/* Layout: wizard on the left, live paper preview on the right; stacks on phones.
   Look: classroom desk — cool grey-blue paper, ink-blue type, highlighter-yellow selection. */
:root {
  --bg: #e9eef2;
  --surface: #ffffff;
  --sunk: #f3f6f8;
  --ink: #14212b;
  --muted: #586773;
  --line: #d3dbe2;
  --accent: #ffd23f;     /* highlighter */
  --accent-ink: #14212b;
  --primary: #1d3f5e;    /* ink blue */
  --primary-ink: #ffffff;
  --warn-bg: #fff3d1;
  --warn-ink: #6b4b00;
  --desk: #cfd8df;
  --font-display: "Lexend", "Segoe UI", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10171d; --surface: #18222b; --sunk: #131c23; --ink: #e7edf2; --muted: #9babb8; --line: #2b3a46;
    --accent: #ffd23f; --accent-ink: #14212b; --primary: #8fc1ec; --primary-ink: #0d1820;
    --warn-bg: #3a2f10; --warn-ink: #ffe08a; --desk: #0b1116; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #10171d; --surface: #18222b; --sunk: #131c23; --ink: #e7edf2; --muted: #9babb8; --line: #2b3a46;
  --accent: #ffd23f; --accent-ink: #14212b; --primary: #8fc1ec; --primary-ink: #0d1820;
  --warn-bg: #3a2f10; --warn-ink: #ffe08a; --desk: #0b1116; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font-body); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.wrap { max-width: 1440px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

/* Header */
.top { background: var(--surface); border-bottom: 1px solid var(--line); }
.top-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 28px; padding-block: 14px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font: 700 1.35rem/1 var(--font-display); letter-spacing: -0.01em; }
.brand-mark { width: 34px; height: 34px; }
.mk-sheet { fill: var(--sunk); stroke: var(--ink); stroke-width: 1.6; }
.mk-sheet2 { fill: var(--surface); stroke: var(--ink); stroke-width: 1.6; }
.mk-cut { stroke: var(--ink); stroke-width: 1.6; stroke-dasharray: 2.5 2; }
.mk-line { stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }
.tagline { margin: 0; color: var(--muted); font-size: 0.95rem; max-width: 60ch; }

/* App layout */
.app { display: grid; grid-template-columns: minmax(0, 480px) minmax(0, 1fr); gap: 24px; padding-block: 24px 40px; align-items: start; }
@media (max-width: 900px) { .app { grid-template-columns: minmax(0, 1fr); } }

.wizard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); display: flex; flex-direction: column; min-width: 0; }
.stepper { display: flex; flex-wrap: wrap; gap: 6px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.stepper button { font: 600 0.82rem/1 var(--font-display); color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px 7px 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.stepper button .n { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--sunk); color: var(--muted); font-size: 0.72rem; }
.stepper button[aria-current="step"] { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.stepper button[aria-current="step"] .n { background: var(--accent-ink); color: var(--accent); }
.stepper button.done .n { background: var(--primary); color: var(--primary-ink); }
.stepper button:disabled { opacity: 0.45; cursor: default; }

.step-body { padding: 18px 20px 8px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.step-title { font: 700 1.25rem/1.2 var(--font-display); margin: 0; text-wrap: balance; }
.step-intro { margin: -10px 0 0; color: var(--muted); font-size: 0.95rem; }
.step-nav { display: flex; justify-content: space-between; gap: 12px; padding: 14px 20px 18px; border-top: 1px solid var(--line); margin-top: 10px; }

/* Buttons */
.btn { font: 600 0.95rem/1 var(--font-display); border-radius: 8px; padding: 12px 18px; cursor: pointer; border: 1px solid transparent; }
.btn.small { padding: 9px 14px; font-size: 0.88rem; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.12); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--sunk); }
.btn.big { padding: 15px 22px; font-size: 1.05rem; width: 100%; }
.btn:disabled { opacity: 0.4; cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Format gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.fmt { text-align: left; background: var(--surface); border: 2px solid var(--line); border-radius: var(--r); padding: 10px; cursor: pointer; color: var(--ink); display: flex; flex-direction: column; gap: 8px; font: inherit; }
.fmt:hover { border-color: var(--muted); }
.fmt[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 4px var(--accent); }
.fmt-thumb { background: var(--desk); border-radius: 6px; height: 132px; display: grid; place-items: center; overflow: hidden; padding: 8px; }
.fmt-thumb svg { max-height: 116px; max-width: 100%; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.fmt-name { font: 700 1rem/1.2 var(--font-display); }
.fmt-tag { font-size: 0.85rem; color: var(--muted); line-height: 1.35; }
.chip { display: inline-block; font: 600 0.72rem/1 var(--font-display); letter-spacing: 0.04em; text-transform: uppercase; padding: 5px 7px; border-radius: 5px; background: var(--sunk); color: var(--muted); border: 1px solid var(--line); align-self: flex-start; }
.fmt.soon { cursor: default; opacity: 0.62; border-style: dashed; }
.fmt.soon:hover { border-color: var(--line); }
.soon-thumb { height: 132px; border-radius: 6px; border: 2px dashed var(--line); display: grid; place-items: center; color: var(--muted); }
.soon-thumb svg { width: 56px; height: 56px; }

/* Form fields */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .label { font: 600 0.92rem/1.3 var(--font-display); }
.help { font-size: 0.85rem; color: var(--muted); margin: 0; }
input[type="text"], textarea, select {
  width: 100%; font: 1rem/1.45 var(--font-body); color: var(--ink); background: var(--sunk);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
}
textarea { resize: vertical; min-height: 64px; }
input[type="text"]:focus, textarea:focus, select:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent); background: var(--surface); }
.count { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.count.bad { color: var(--warn-ink); background: var(--warn-bg); padding: 1px 6px; border-radius: 4px; align-self: flex-start; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span { display: inline-block; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 0.92rem; background: var(--surface); cursor: pointer; }
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.seg input:focus-visible + span { outline: 3px solid var(--primary); outline-offset: 2px; }

.toggle { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.toggle input { appearance: none; flex: none; width: 42px; height: 24px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; margin: 0; transition: background .15s; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.toggle input:checked { background: var(--primary); }
.toggle input:checked::after { transform: translateX(18px); }
.toggle .t-text { display: flex; flex-direction: column; gap: 2px; font-size: 0.95rem; }

/* Activity block editor */
.blocks { display: flex; flex-direction: column; gap: 10px; }
.blk { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.blk-head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 12px; }
.blk-num { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: var(--surface); display: grid; place-items: center; font: 700 0.8rem/1 var(--font-display); }
.blk-name { flex: 1; min-width: 0; background: none; border: 0; padding: 0; text-align: left; font: 600 0.95rem/1.25 var(--font-display); color: var(--ink); cursor: pointer; }
.blk-name small { display: block; font: 400 0.8rem/1.3 var(--font-body); color: var(--muted); }
.icon-btn { flex: none; width: 32px; height: 32px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--sunk); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn svg { width: 16px; height: 16px; }
.blk-body { border-top: 1px dashed var(--line); padding: 14px 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; }
.add-row select { flex: 1 1 200px; }

/* Finish step */
.out-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.out-choice label { position: relative; border: 2px solid var(--line); border-radius: var(--r); padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.out-choice input { position: absolute; opacity: 0; }
.out-choice label:has(input:checked) { border-color: var(--ink); box-shadow: 0 0 0 4px var(--accent); }
.out-choice label:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }
.out-choice b { font: 700 1rem/1.2 var(--font-display); }
.out-choice span { font-size: 0.84rem; color: var(--muted); }
.reset { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; font-size: 0.88rem; padding: 0; align-self: flex-start; }

/* Preview */
.preview { position: sticky; top: 12px; min-width: 0; background: var(--desk); border-radius: var(--r); display: flex; flex-direction: column; max-height: calc(100vh - 24px); }
@media (max-width: 900px) { .preview { position: static; max-height: none; } }
.preview-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r) var(--r) 0 0; }
.pv-name { font: 700 1rem/1.2 var(--font-display); }
.pv-meta { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.warnings { list-style: none; margin: 0; padding: 10px 14px; background: var(--warn-bg); color: var(--warn-ink); font-size: 0.9rem; display: flex; flex-direction: column; gap: 4px; }
.warnings li::before { content: "! "; font-weight: 700; }
.pages { overflow: auto; padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.page { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.page svg { width: 100%; height: auto; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.22); border-radius: 2px; }
.page.p-a4p svg { max-width: 620px; }
.page.p-a3l svg { max-width: 1100px; }
.page-label { font: 600 0.78rem/1 var(--font-display); color: var(--muted); letter-spacing: 0.05em; text-transform: uppercase; }

.foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding-block: 0 28px; color: var(--muted); font-size: 0.85rem; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 12px 18px; border-radius: 8px; font-weight: 700; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: calc(100% - 32px); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
