:root {
  --paper: #fbf6ec;
  --card: #fffdf9;
  --ink: #221d2c;
  --muted: #776e7f;
  --line: #e9e0d1;
  --accent: #ff5a36;
  --accent-ink: #fff;
  --sun: #ffd23f;
  --lilac: #c9b8ff;
  --mint: #93e1c4;
  --guide: #e9dfcc;
  --ok: #2f7d4f;
  --radius: 16px;
  --w: 460px;
  --display: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, sans-serif;
  --pop: 0 3px 0 var(--ink);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
main {
  max-width: var(--w);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.15; margin: 0; font-family: var(--display); font-weight: 800; letter-spacing: -0.01em; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack > * + * { margin-top: var(--gap, 12px); }
.row { display: flex; gap: 8px; align-items: center; }
.spread { justify-content: space-between; }
.grow { flex: 1; }

/* ---------- top bar ---------- */
.bar { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-bottom: 12px; }
.logo { font: 800 26px/1 var(--display); letter-spacing: -0.03em; text-decoration: none; display: inline-flex; }
.logo b { color: var(--accent); font-weight: inherit; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--line); object-fit: cover; }

/* ---------- buttons & inputs ---------- */
/* Buttons draw their fill + outline on ::before, roughened by the #sketchy filter (index.html),
   so the line looks hand-drawn but the label stays crisp. Variants only change the variables. */
button, .btn {
  --bg: var(--card); --bd: var(--ink); --sh: var(--pop);
  --r: 22px 18px 24px 17px / 20px 24px 18px 22px;
  font: inherit; font-weight: 600; font-size: 15px;
  position: relative; isolation: isolate;
  border: 2px solid transparent; background: none; color: var(--ink);
  border-radius: 999px; padding: 10px 16px; min-height: 44px;
  transition: transform .08s;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none;
}
button::before, .btn::before {
  content: ''; position: absolute; inset: -2px; z-index: -1; pointer-events: none;
  background: var(--bg); border: 2px solid var(--bd); border-radius: var(--r); box-shadow: var(--sh);
  filter: url(#sketchy); transition: box-shadow .08s;
}
button:active, .btn:active { transform: translateY(3px); --sh: 0 0 0 transparent; }
button:disabled { opacity: .4; cursor: default; transform: none; --sh: none; }
.primary { --bg: var(--ink); --sh: 0 3px 0 var(--accent); color: var(--paper); }
.accent { --bg: var(--accent); --bd: var(--ink); color: var(--accent-ink); }
.ghost { --bg: transparent; --bd: transparent; --sh: none; }
.ghost:active { transform: scale(.96); }
.icon { padding: 0; width: 44px; --r: 23px 20px 22px 19px / 20px 23px 19px 22px; }
.danger { color: #b3261e; --bd: #b3261e; --sh: 0 3px 0 #b3261e; }
input[type=text], textarea {
  font: inherit; width: 100%; padding: 11px 14px; min-height: 44px;
  border: 2px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink);
}
input[type=text]:focus, textarea:focus { outline: none; border-color: var(--ink); }
input[type=range] { width: 100%; accent-color: var(--accent); }

.card { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: 0 3px 0 var(--line); }
.section-title { font: 800 13px/1.3 var(--display); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 24px 0 8px; }

/* ---------- landing ---------- */
.hero { padding: 32px 0 8px; }
.hero h1 { font: 800 46px/1.02 var(--display); letter-spacing: -0.035em; }
.hero h1 em {
  font-style: normal; padding: 0 .08em; margin: 0 -.04em;
  background: linear-gradient(100deg, transparent 2%, var(--sun) 4% 96%, transparent 98%) 0 72% / 100% 45% no-repeat;
}
.hero p { margin-top: 14px; font-size: 17px; color: var(--muted); }
.steps { list-style: none; padding: 0; margin: 24px 0; }
.steps li { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
/* Hand-drawn badge (SVG from stepNum() in app.js), vertically centred on the first line of text. */
.step-num { flex: none; width: 36px; height: 36px; margin: calc((1lh - 36px) / 2) 0; overflow: visible; }
.step-num path { fill: none; stroke: var(--ink); stroke-linecap: round; stroke-linejoin: round; }
.step-num .ring { fill: var(--accent); stroke-width: 2.4; filter: url(#sketchy); }
.step-num .digit { stroke-width: 3.4; }
.step-2 .ring { fill: var(--sun); }
.step-3 .ring { fill: var(--lilac); }
#gsi { min-height: 44px; }

/* ---------- font list ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 12px; }
.section-head .section-title { margin: 0; }
.section-head .new-font { padding: 6px 14px; }
.empty { text-align: center; padding: 40px 0 8px; --gap: 16px; }
.font-list { display: grid; gap: 10px; }
.font-item { display: block; text-decoration: none; transition: transform .12s, box-shadow .12s, border-color .12s; }
.font-item:hover { border-color: var(--ink); box-shadow: var(--pop); transform: translateY(-2px) rotate(-.4deg); }
.font-item .name { font-size: 34px; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > i {
  display: block; height: 100%; border-radius: 99px; transition: width .3s cubic-bezier(.3,1.4,.6,1);
  background: repeating-linear-gradient(-45deg, var(--accent) 0 6px, #ff7a5c 6px 12px);
}

/* ---------- editor ---------- */
.ed-head { display: flex; align-items: center; gap: 10px; }
.ed-char {
  font: 500 40px/1 Georgia, serif; min-width: 56px; height: 56px; padding: 0 10px;
  --bg: var(--sun); --r: 15px 11px 16px 12px / 12px 16px 11px 15px;
}
.ed-meta { flex: 1; min-width: 0; }
.ed-meta .progress { margin-top: 6px; }
.canvas-wrap { position: relative; margin: 12px 0; aspect-ratio: 1; width: 100%; }
canvas#pad {
  width: 100%; height: 100%; display: block; touch-action: none;
  background: var(--card); border: 2px solid var(--line); border-radius: 20px;
  cursor: crosshair;
}
.auto-note { position: absolute; left: 0; right: 0; bottom: 12px; text-align: center; pointer-events: none; }
.saved-dot { position: absolute; top: 10px; right: 12px; font-size: 12px; color: var(--muted); pointer-events: none; }
.ed-tools { display: grid; grid-template-columns: 44px 1fr 1fr 1.4fr; gap: 8px; }
.ed-tools .next { grid-column: 4; }
.drawn-line { font-size: 34px; line-height: 1.2; word-break: break-all; color: var(--ink); }
.try-box {
  margin-top: 10px; border: 1.5px dashed #cdbfa6; border-radius: var(--radius);
  background: var(--card); padding: 8px 12px 4px; cursor: text; transition: border-color .15s;
}
.try-box:focus-within { border-style: solid; border-color: var(--ink); }
.try-head { display: flex; justify-content: space-between; align-items: center; min-height: 28px; }
.try-head label { font-size: 13px; font-weight: 600; color: var(--muted); cursor: text; }
.try-box:focus-within .try-head label { color: var(--ink); }
.try-reset { min-height: 28px; padding: 2px 10px; font-size: 12px; --bd: var(--line); }
.try-input {
  display: block; width: 100%; font-size: 34px; line-height: 1.2; padding: 4px 0 6px;
  border: none; background: transparent; resize: none; color: var(--ink); overflow: hidden;
}
.try-input:focus { outline: none; }
.try-input::placeholder { color: #c9bba3; }

/* glyph picker sheet */
.sheet-bg { position: fixed; inset: 0; background: rgb(0 0 0 / .3); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet {
  background: var(--paper); border-top: 2px solid var(--ink); width: 100%; max-width: var(--w); max-height: 80dvh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.grid button { padding: 0; min-height: 44px; --r: 13px 9px 12px 10px / 10px 13px 9px 12px; --bd: var(--line); --sh: none; font: 500 20px/1 Georgia, serif; }
.grid button:nth-child(3n+1) { --r: 9px 13px 10px 12px / 13px 10px 12px 9px; }
.grid button.done { --bg: var(--ink); --bd: var(--ink); color: var(--paper); }
.grid button.current { --bd: var(--accent); --sh: 0 0 0 2px var(--accent); }

/* ---------- font page ---------- */
.specimen { font-size: 44px; line-height: 1.15; word-break: break-word; }
pre.code {
  margin: 0; padding: 12px 64px 12px 12px; border-radius: 14px; background: var(--ink); color: #f3ecdf;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-all;
}
.copy-row { position: relative; }
.copy-row button { position: absolute; top: 6px; right: 6px; min-height: 30px; padding: 4px 10px; font-size: 12px; --bg: var(--sun); --bd: var(--ink); --sh: none; color: var(--ink); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- help ---------- */
.help-btn { font: 800 17px/1 var(--display); --bg: var(--lilac); }
.help-section h4 { margin: 0 0 4px; font-size: 15px; }
.help-section p { color: var(--muted); font-size: 14.5px; }
.help-section p + p { margin-top: 6px; }
.settings label { display: block; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.small-btn { min-height: 36px; padding: 6px 4px; font-size: 14px; }
.danger.ghost { --bd: transparent; --sh: none; }

/* ---------- font page: specimen + tabs ---------- */
.font-title { font: 800 15px/1.3 var(--display); color: var(--muted); margin: 8px 0 6px; }
.specimen-static { font-size: 22px; line-height: 1.3; white-space: pre-line; word-break: break-word; margin: 0 0 22px; }

.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px;
  background: #efe6d6; border-radius: 999px; position: sticky; top: 8px; z-index: 5;
  box-shadow: 0 -8px 0 8px var(--paper);
}
.tab {
  --bg: transparent; --bd: transparent; --sh: none; --r: 21px 17px 22px 16px / 19px 22px 17px 21px;
  min-height: 40px; font: 800 15px/1 var(--display); color: var(--muted);
}
.tab:active { transform: none; }
.tab[aria-selected="true"] { --bg: var(--card); --bd: var(--ink); --sh: 0 2px 0 var(--ink); color: var(--ink); }
.tab-panel { padding-top: 20px; }
.tab-panel > * + * { margin-top: 10px; }

.field { display: block; }
.field + .field { margin-top: 22px; }
.field-label { display: flex; font-size: 13px; font-weight: 600; margin-bottom: 8px; }

.tab-footer { margin-top: 32px !important; padding-top: 12px; border-top: 1px solid var(--line); display: flex; justify-content: center; }
.help-link { font-size: 14px; color: var(--muted); font-weight: 500; min-height: 40px; }
.help-dot {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  border: 1.5px solid currentColor; font-size: 12px; font-weight: 700;
}

/* glyph grid */
.glyph-group .section-title { display: flex; justify-content: space-between; margin: 22px 0 8px; }
.glyph-group .count { font-weight: 500; letter-spacing: 0; }
.glyph-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
.glyph {
  aspect-ratio: 1; display: grid; place-items: center; border-radius: 10px;
  text-decoration: none; font-size: 26px; line-height: 1; -webkit-tap-highlight-color: transparent;
}
/* Drawn tiles get a hand-drawn box: uneven corners (varied per tile) + an ink-wobble SVG filter (#sketchy, in index.html).
   The border lives on ::before so the filter roughens the line, not the letter. */
.glyph.done { position: relative; color: var(--ink); --r: 7px 11px 6px 10px / 10px 6px 11px 7px; }
.glyph.done::before {
  content: ''; position: absolute; inset: 1px; z-index: -1; pointer-events: none;
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--r); filter: url(#sketchy);
}
.glyph-grid { isolation: isolate; }
.glyph.done:nth-child(3n+1) { --r: 11px 6px 9px 7px / 6px 10px 7px 11px; }
.glyph.done:nth-child(4n+2) { --r: 6px 10px 7px 9px / 9px 7px 11px 6px; }
.glyph.done:nth-child(5n+3) { --r: 10px 7px 11px 6px / 7px 11px 6px 10px; }
.glyph.done:nth-child(4n+1) { transform: rotate(-1.2deg); }
.glyph.done:nth-child(5n+3) { transform: rotate(1deg); }
/* Automatic accents: in the font already, so shown in it, with a dashed outline to tell them from drawn ones. */
.glyph.auto { border: 2px dashed #a8957a; color: var(--ink); }
.glyph.auto:hover, .glyph.auto:focus-visible { border-color: var(--accent); }
.grid button.auto { --bd: #a8957a; }
.grid button.auto::before { border-style: dashed; }
.group-note { margin: -2px 0 8px; }
.glyph.todo { border: 2px dashed #d8cbb3; color: #c9bba3; font-family: Georgia, serif; font-size: 20px; }
.glyph:active { transform: scale(.96); }
.glyph.todo:hover, .glyph.todo:focus-visible { border-color: var(--accent); color: var(--accent); }

/* toggle switch */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch {
  appearance: none; flex: none; width: 48px; height: 28px; border-radius: 999px; margin: 0;
  background: #d8cfbf; position: relative; cursor: pointer; transition: background .15s; border: 2px solid var(--ink); box-shadow: none; min-height: 0; padding: 0;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 2px solid var(--ink); box-sizing: border-box; transition: transform .2s cubic-bezier(.3,1.5,.6,1);
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }


/* ---------- a little playfulness (skipped when people ask for less motion) ---------- */
@media (prefers-reduced-motion: no-preference) {
  .glyph.done:hover, .glyph.done:focus-visible { animation: wiggle .4s ease-in-out; }
  #toast.show { animation: pop .3s cubic-bezier(.3,1.6,.6,1); }
  .ed-char { animation: pop .25s cubic-bezier(.3,1.6,.6,1); }
}
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-8deg); }
  75% { transform: rotate(8deg); }
}
@keyframes pop {
  from { transform: translate(var(--tx, 0), 0) scale(.85); }
  to { transform: translate(var(--tx, 0), 0) scale(1); }
}
#toast { --tx: -50%; }

/* ---------- legal pages ---------- */
.legal h1 { font-size: 34px; margin: 20px 0 4px; }
.legal h2 { font-size: 19px; margin: 26px 0 6px; }
.legal p, .legal li { font-size: 15.5px; }
.legal ul { padding-left: 20px; margin: 0; }
.legal li + li { margin-top: 6px; }
.legal > p:last-child { margin-top: 10px; }
.legal > p.muted.small { margin-top: 36px; padding-top: 12px; border-top: 1px solid var(--line); }
.site-foot { margin-top: 32px; text-align: center; }
.site-foot a, .site-foot .link-btn { color: var(--muted); }
.link-btn { all: unset; cursor: pointer; text-decoration: underline; }
.link-btn::before { content: none; }
.link-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
