:root {
  --bg: #f6f3ec;
  --card: #fffdf8;
  --ink: #1d2230;
  --muted: #5d6475;
  --line: #e2dccd;
  --accent: #1f2a6b;
  --accent-ink: #fff;
  --ok: #1d6b3a;
  --warn: #8a5a00;
  --err: #a32121;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #14161d;
    --card: #1c1f29;
    --ink: #eceef5;
    --muted: #a3a9ba;
    --line: #303546;
    --accent: #8d9bff;
    --accent-ink: #10131f;
    --ok: #6fd391;
    --warn: #f0b95a;
    --err: #ff8a8a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }
.top { padding: 40px 0 8px; }
.top h1 { margin: 0 0 8px; font-size: clamp(28px, 5vw, 40px); letter-spacing: -0.02em; }
.top p { margin: 0; color: var(--muted); max-width: 62ch; }

.status {
  margin: 18px 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  overflow-wrap: anywhere;
}
.status[data-kind='ok'] { border-left-color: var(--ok); }
.status[data-kind='warn'] { border-left-color: var(--warn); }
.status[data-kind='error'] { border-left-color: var(--err); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin: 0 0 18px;
}
.card h2 { margin: 0 0 12px; font-size: 20px; display: flex; align-items: center; gap: 10px; }
.n {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
}
.how { margin: 0 0 14px; padding-left: 22px; color: var(--muted); }
.how li { margin: 3px 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0; }
.row.small { margin-top: 0; }
.muted { color: var(--muted); font-size: 14px; }

button, .btn {
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  min-height: 40px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
button:hover:not(:disabled), .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.ghost, .btn.ghost { font-weight: 500; color: var(--muted); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.link { border: 0; background: none; color: var(--accent); min-height: 0; padding: 2px 4px; text-decoration: underline; font-weight: 500; }
:focus-visible, .btn:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

.field { display: block; font-weight: 600; margin: 10px 0 6px; }
textarea {
  width: 100%;
  font: 15px/1.5 ui-monospace, Consolas, monospace;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  resize: vertical;
}

.glyphs { display: flex; flex-wrap: wrap; gap: 4px; max-height: 260px; overflow: auto; }
.tile { padding: 0; min-height: 0; width: 48px; height: 48px; background: #fdfcf6; border-radius: 6px; justify-content: center; }
.tile canvas { display: block; }
.tile:hover { border-color: var(--err); }

.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 22px; }
.controls label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; position: relative; }
.controls label.check { flex-direction: row; align-items: center; gap: 8px; align-self: end; }
.controls output { position: absolute; right: 0; top: 0; font-weight: 400; color: var(--muted); }
.controls input[type='color'] { width: 100%; height: 38px; padding: 2px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); }
.controls select { font: inherit; padding: 8px; min-height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.controls input[type='range'] { width: 100%; min-height: 28px; accent-color: var(--accent); }

.warn { color: var(--warn); margin: 6px 0; min-height: 0; }
.pages { display: grid; gap: 18px; }
.pages figure { margin: 0; }
.pages canvas { width: 100%; height: auto; display: block; border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12); }
.pages figcaption { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-top: 6px; }
.empty { color: var(--muted); margin: 0; }
.foot { padding: 8px 16px 40px; color: var(--muted); font-size: 14px; }
.foot a { color: var(--accent); }

@media (max-width: 520px) {
  .card { padding: 16px; }
  .row > * { flex: 1 1 100%; justify-content: center; }
}
@media (prefers-reduced-motion: no-preference) {
  button, .btn { transition: border-color 0.12s; }
}

/* Write-on-screen dialog */
.sub { font-size: 16px; margin: 16px 0 4px; }
.dlg {
  width: min(680px, calc(100vw - 16px));
  max-width: none;
  max-height: calc(100dvh - 16px);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
}
.dlg::backdrop { background: rgba(0, 0, 0, 0.5); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.dlg-head h2 { margin: 0; font-size: 20px; }
.select { font: inherit; width: 100%; padding: 8px; min-height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.prompt { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin: 4px 0 10px; min-height: 48px; }
.prompt .big { font: 600 40px/1.1 Georgia, 'Times New Roman', serif; overflow-wrap: anywhere; }
.prompt .progress { margin-left: auto; }
#pad { display: block; width: 100%; margin: 0 auto; touch-action: none; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: crosshair; }
.pad-actions { justify-content: flex-end; }
.pad-actions #drawBack { margin-right: auto; }
@media (max-width: 520px) {
  .dlg { padding: 12px; }
  .prompt .big { font-size: 30px; }
  .pad-actions > * { flex: 1 1 auto; }
  .pad-actions #drawNext { flex: 1 1 100%; }
}

.syntax { margin-top: 10px; font-size: 14px; color: var(--muted); }
.syntax summary { cursor: pointer; font-weight: 600; color: var(--ink); min-height: 32px; display: list-item; }
.syntax ul { margin: 6px 0 0; padding-left: 20px; }
.syntax li { margin: 4px 0; }
.syntax code, .card p code { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 13px; }

/* Learn-from-a-photo */
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 7px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); vertical-align: middle; margin-left: 6px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.dlg .status:empty { display: none; }
.dlg .status { margin: 10px 0 0; }

.select.grow { flex: 1 1 220px; width: auto; }
.inline { font-weight: 600; }
.controls input[type='number'] { font: inherit; padding: 8px; min-height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); width: 100%; }

/* Sample checker */
.tile.flagged { border: 2px solid var(--err); background: #fff1f1; }
.flag-note { border-left: 4px solid var(--err); background: var(--card); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.flag-note p { margin: 0 0 4px; }
.check-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }

/* Pen colours */
.ink-tools { grid-column: 1 / -1; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { min-height: 36px; padding: 4px 12px 4px 6px; font-size: 14px; font-weight: 500; gap: 8px; }
.swatch .dot { width: 22px; height: 22px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.2); display: inline-block; }
.swatch[aria-pressed='true'] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.select.narrow { width: auto; min-height: 36px; padding: 4px 8px; }
#inkHint { margin: 8px 0 0; }

.foot .disclaimer { border-left: 3px solid var(--line); padding-left: 10px; }
