:root {
  color-scheme: light;
  --bg: #f3f1eb;
  --panel: #fffefa;
  --line: #dedbd2;
  --text: #262a26;
  --muted: #76796f;
  --accent: #ac4d31;
  --accent-soft: #f4e9df;
  --green: #48634d;
  --radius: 16px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, textarea, select { font: inherit; }
button, .button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 9px 14px; border-radius: 8px; transition: background .15s, border-color .15s; text-align: center; }
button:hover:not(:disabled), .button:hover { background: #edece4; border-color: #b9b9aa; }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, .button:focus-within, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 550; }
.primary:hover:not(:disabled) { background: #903f27; border-color: #903f27; }
.primary.big { margin-left: auto; padding: 12px 20px; }
.primary.big span { margin-left: 20px; }
.ghost { background: transparent; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 68px; padding: 14px 36px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-family: Georgia, serif; font-size: 25px; letter-spacing: -.8px; }
.brand img { filter: saturate(.5); }
.status { color: var(--muted); font-size: 11px; text-align: right; max-width: 65%; }
.status.bad { color: var(--accent); }
main { max-width: 1180px; margin: 0 auto; padding: 40px 32px 64px; }
.intro { padding: 12px 0 34px; }
.eyebrow { font-size: 10px; font-weight: 650; letter-spacing: 1.5px; color: var(--muted); }
.intro h1 { font: 54px/1.05 Georgia, "Times New Roman", serif; letter-spacing: -2px; margin: 18px 0; }
.intro h1 span { color: var(--accent); }
.intro p { color: var(--muted); margin-bottom: 0; max-width: 460px; font-size: 15px; }
.setup-grid { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 24px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
.panel-head h2 { font-size: 16px; font-weight: 600; margin: 0; }
.step-number { display: inline-flex; color: var(--accent); font: 12px ui-monospace, monospace; margin-right: 10px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 20px; }
.pill { display: inline-block; font-size: 11px; padding: 4px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 550; }
.pill.neutral { background: #eeeee6; color: var(--muted); }
.pill.good { background: #e8eee4; color: var(--green); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; min-width: 0; }
.row.presets { gap: 6px; margin: 8px 0 22px; }
.chip { padding: 4px 10px; font-size: 11px; border-radius: 5px; color: var(--muted); background: transparent; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.subjects-label { margin-top: 4px; }
.subjects-count { font-weight: 400; color: var(--muted); margin-left: 6px; }
.handwriting-panel > .small-note.subjects-note { margin: 2px 0 0; }
.row.subjects { margin: 8px 0 4px; }
input[type="text"], textarea, select { color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 10px 12px; background: var(--panel); }
input[type="text"] { flex: 1 1 150px; min-width: 0; width: 100%; font-size: 12px; }
textarea { width: 100%; resize: vertical; min-height: 112px; margin-top: 8px; font-size: 13px; }
textarea::placeholder, input::placeholder { color: #94978b; }
.field-label { display: block; font-size: 12px; font-weight: 600; margin-top: 22px; }
.select { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.select select { padding: 7px; font-size: 12px; }
.dropzone { display: flex; flex-direction: column; justify-content: center; gap: 12px; border: 1px dashed #b9bcad; border-radius: 10px; padding: 28px 18px; color: var(--muted); text-align: center; font-size: 12px; background: #f8f8f2; transition: background .15s; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.sources { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.sources li { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); padding: 8px 0; font-size: 12px; }
.sources canvas { width: 32px; height: 42px; object-fit: cover; border: 1px solid var(--line); border-radius: 3px; background: white; }
.sources li > div { min-width: 0; overflow-wrap: anywhere; }
.sources .meta { color: var(--muted); font-size: 10px; }
.sources .drop { margin-left: auto; border: 0; background: none; color: var(--muted); font-size: 18px; padding: 2px 6px; }
.character-details { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 14px; }
.character-details summary { color: var(--muted); cursor: pointer; font-size: 12px; }
.glyph-preview { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 14px; max-height: 260px; overflow: auto; }
.glyph-preview figure { margin: 0; width: 38px; text-align: center; }
.glyph-preview canvas { width: 100%; height: 38px; object-fit: contain; background: white; border: 1px solid var(--line); border-radius: 5px; }
.glyph-preview figcaption { font: 10px ui-monospace, monospace; color: var(--muted); }
.small-note { font-size: 11px; color: var(--muted); line-height: 1.7; }
.handwriting-panel > .small-note { margin: 22px 0 0; }
kbd { font: inherit; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 4px; }

/* The writing desk: a continuous paper stack, with progress kept in view. */
.writing-view { max-width: 1480px; padding-top: 0; }
.workspace-toolbar { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; align-items: center; gap: 24px; min-height: 100px; border-bottom: 1px solid var(--line); margin-bottom: 28px; }
.workspace-toolbar > .ghost { border: 0; padding-left: 0; font-size: 12px; }
.document-heading { min-width: 0; }
.document-heading h1 { font: 22px Georgia, serif; margin: 4px 0 0; overflow-wrap: anywhere; }
.workspace-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-shrink: 0; }
.workspace-actions button { font-size: 12px; }
.workspace-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 42px; align-items: start; }
.paper-stage { min-width: 0; max-width: 820px; width: 100%; justify-self: center; }
.paper-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 10px; color: var(--muted); padding: 0 3px 14px; }
.paper-meta span:last-child { font-size: 9px; letter-spacing: 1px; }
.page-stack { position: relative; }
.pages { display: grid; gap: 28px; }
.pages canvas { width: 100%; height: auto; display: block; background: white; scroll-margin-top: 120px; box-shadow: 0 5px 22px #242a2410, 0 1px 3px #242a2418; }
.page-waiting { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; padding: 24% 24px 24px; text-align: center; pointer-events: none; }
.waiting-mark { font-size: 30px; color: #b7b9a7; animation: breathe 2s ease-in-out infinite; }
.page-waiting h2 { font: 23px Georgia, serif; color: #737764; margin: 20px 0 8px; }
.page-waiting p { font-size: 12px; color: #939788; max-width: 240px; }
.page-footnote { text-align: center; color: var(--muted); font-size: 10px; margin-top: 24px; }
.session-panel { position: sticky; top: 124px; max-height: calc(100dvh - 148px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; min-width: 0; }
.session-heading { display: flex; justify-content: space-between; align-items: center; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.current-problem { padding-top: 26px; }
.current-problem .eyebrow { color: var(--accent); font-size: 9px; }
.current-problem h2 { font: 28px/1.2 Georgia, serif; margin: 12px 0; overflow-wrap: anywhere; }
.current-problem p { color: var(--muted); font-size: 12px; margin: 0; min-height: 54px; overflow-wrap: anywhere; }
.session-progress { margin: 24px 0; }
.progress-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; margin-bottom: 9px; }
progress { display: block; width: 100%; height: 4px; border: 0; border-radius: 8px; overflow: hidden; background: #e8e9df; accent-color: var(--green); }
progress::-webkit-progress-bar { background: #e8e9df; }
progress::-webkit-progress-value { background: var(--green); transition: width .2s; }
progress::-moz-progress-bar { background: var(--green); }
progress:indeterminate { opacity: .45; animation: breathe 2s ease-in-out infinite; }
.playback-controls { display: flex; gap: 8px; margin-bottom: 24px; }
.playback-controls button { flex: 1; font-size: 11px; padding: 7px; }
.queue-heading { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 22px; }
.queue-heading h3 { margin: 0; font-size: 11px; font-weight: 600; }
.queue-heading > span { font: 10px ui-monospace, monospace; color: var(--muted); }
.problem-queue { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 5px; max-height: 32vh; overflow-y: auto; }
.problem-queue li { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 6px; color: var(--muted); font-size: 12px; }
.problem-queue li.active { background: #f0f2e9; color: var(--text); }
.problem-queue li.done { color: var(--green); }
.queue-dot { width: 20px; height: 20px; display: grid; place-items: center; flex-shrink: 0; border: 1px solid var(--line); border-radius: 50%; font-size: 9px; }
.active .queue-dot { color: white; background: var(--green); border-color: var(--green); }
.done .queue-dot { border-color: transparent; background: #e8eee4; }
.queue-name { overflow-wrap: anywhere; }
.queue-state { margin-left: auto; font-size: 9px; white-space: nowrap; }
.session-footer { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 16px; }
.session-footer > div { display: flex; justify-content: space-between; gap: 12px; margin: 7px 0; color: var(--muted); font-size: 10px; }
.session-footer strong { color: var(--text); font-weight: 500; text-align: right; }
.engine-note { font-size: 10px; color: var(--muted); margin: 18px 0 0; overflow-wrap: anywhere; }
.failure { padding: 12px; border: 1px solid #e2c4b6; border-radius: 7px; color: #963e28; background: #fbefe8; font-size: 12px; overflow-wrap: anywhere; margin-bottom: 12px; }
#retryGenerate { width: 100%; margin-bottom: 22px; font-size: 12px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); max-width: min(70ch, calc(100vw - 32px)); padding: 12px 18px; background: var(--text); color: white; border-radius: 9px; box-shadow: 0 6px 24px #242a2420; font-size: 12px; z-index: 50; }
.toast.bad { background: #903f27; }
@keyframes breathe { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
@media (min-width: 1600px) { .writing-view { max-width: 1550px; } .workspace-grid { gap: 64px; grid-template-columns: minmax(0, 1fr) 320px; } }
@media (max-width: 1000px) {
  .setup-grid { grid-template-columns: 270px minmax(0, 1fr); gap: 16px; }
  .panel { padding: 20px; }
  .workspace-grid { grid-template-columns: minmax(0, 1fr) 260px; gap: 24px; }
  .session-panel { padding: 18px; }
  main { padding-left: 24px; padding-right: 24px; }
  .workspace-toolbar { gap: 16px; }
}
@media (max-width: 740px) {
  .topbar { padding: 12px 20px; min-height: 60px; }
  .status { max-width: 58%; font-size: 10px; }
  main { padding: 24px 18px 40px; }
  .intro { padding: 0 0 24px; }
  .intro h1 { font-size: 44px; }
  .setup-grid { grid-template-columns: 1fr; }
  .handwriting-panel .row { margin-top: 8px; }
  .workspace-toolbar { flex-wrap: wrap; padding: 16px 0; margin-bottom: 20px; gap: 12px; }
  .document-heading { flex: 1; }
  .document-heading h1 { font-size: 18px; }
  .workspace-toolbar > .ghost { font-size: 11px; }
  .workspace-actions { width: 100%; justify-content: flex-end; }
  .workspace-grid { display: flex; flex-direction: column; gap: 24px; }
  .session-panel { position: static; max-height: none; width: 100%; order: -1; }
  .session-heading { padding-bottom: 12px; }
  .current-problem { padding-top: 14px; }
  .current-problem h2 { margin: 6px 0; font-size: 24px; }
  .current-problem p { min-height: 0; }
  .session-progress { margin: 16px 0; }
  .queue-heading { padding-top: 14px; }
  .problem-queue { max-height: 110px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .queue-state { display: none; }
  .session-footer { margin-top: 14px; padding-top: 10px; }
  .session-footer > div { display: inline-flex; margin-right: 12px; }
  .engine-note { margin-top: 8px; }
  .page-waiting h2 { font-size: 20px; }
  .paper-meta span:last-child { font-size: 8px; }
}
