/* quire — a reading surface.
 *
 * House rules this file is written against (references/web-app-craft.md,
 * projects/toys/anti-slop-ui.md):
 *   - one spacing scale: 4 8 12 16 24 32 48. Nothing else.
 *   - no pure #000 on #fff. Warm off-tones throughout.
 *   - hairlines, not borders. Layered warm shadows, not one hard smudge.
 *   - 100svh shell, overflow hidden, scrolling in inner panes only.
 *   - density gates on (pointer: coarse), never on a width breakpoint.
 *   - theme blocks are :root[data-theme=...] so they outrank :root instead of
 *     racing it on source order.
 */

/* ══════════════════ tokens ══════════════════ */
/* The ink ramp is aimed at CONTRAST RATIOS, not at swatches that look nice in
 * the picker. Every --ink-3 below is solved to clear 4.5:1 on EVERY surface it is painted on
 * (--page, --ground and --hair-soft, the last being the segmented controls), and every --ink-2 at ~7:1, because --ink-3 carries the small text
 * (bylines, counts, hints, the reader's footer) and small text is exactly
 * where a tasteful-looking low-contrast ramp becomes unreadable on a bright
 * screen. Do not round these to friendlier values without re-running the
 * audit; sepia was the worst at 2.66:1 and looked perfectly fine on a laptop
 * in a dim room. */

:root {
  /* paper is the default and is declared on bare :root so every token has a
   * value before any theme attribute is read. */
  --ground:    #f3ede1;
  --page:      #faf6ec;
  --ink:       #262219;
  --ink-2:     #57503f;
  --ink-3:     #6a6255;
  --hair:      #ddd4c1;
  --hair-soft: #e8e0d0;
  --accent:    #a2482c;
  --accent-in: #fff8f2;
  --sel:       #e9c9a8;
  --shadow-1:  0 1px 2px rgba(72,56,32,.10);
  --shadow-2:  0 2px 4px rgba(72,56,32,.07), 0 8px 18px rgba(72,56,32,.09);
  --shadow-3:  0 1px 2px rgba(72,56,32,.10), 0 6px 14px rgba(72,56,32,.10), 0 22px 44px rgba(72,56,32,.11);
  --grain:     .035;
  --scrim:     rgba(250,246,236,.86);
  color-scheme: light;
}

:root[data-theme="sepia"] {
  --ground: #ece0c8; --page: #f4e9d4; --ink: #3a2e1d; --ink-2: #594b37; --ink-3: #695b48;
  --hair: #d9c9a9; --hair-soft: #e3d6ba; --accent: #97482a; --accent-in: #fdf6ec;
  --sel: #e3c294; --scrim: rgba(244,233,212,.87);
  --shadow-1: 0 1px 2px rgba(80,58,26,.11);
  --shadow-2: 0 2px 4px rgba(80,58,26,.08), 0 8px 18px rgba(80,58,26,.10);
  --shadow-3: 0 1px 2px rgba(80,58,26,.11), 0 6px 14px rgba(80,58,26,.11), 0 22px 44px rgba(80,58,26,.12);
  color-scheme: light;
}

:root[data-theme="grey"] {
  --ground: #e4e4e2; --page: #f0f0ee; --ink: #232324; --ink-2: #505055; --ink-3: #606065;
  --hair: #d0d0cf; --hair-soft: #dcdcda; --accent: #3f5a72; --accent-in: #f4f8fb;
  --sel: #c4d3e0; --grain: .022; --scrim: rgba(240,240,238,.87);
  --shadow-1: 0 1px 2px rgba(30,32,36,.10);
  --shadow-2: 0 2px 4px rgba(30,32,36,.07), 0 8px 18px rgba(30,32,36,.09);
  --shadow-3: 0 1px 2px rgba(30,32,36,.10), 0 6px 14px rgba(30,32,36,.10), 0 22px 44px rgba(30,32,36,.12);
  color-scheme: light;
}

/* Dark grounds sit at ~#16 rather than #000, and cards elevate by getting
 * LIGHTER — a shadow you cannot see is not elevation. */
:root[data-theme="night"] {
  --ground: #16150f; --page: #1d1b15; --ink: #ded6c6; --ink-2: #ada595; --ink-3: #908b7e;
  --hair: #2e2b23; --hair-soft: #26241d; --accent: #cf7d5c; --accent-in: #1d1b15;
  --sel: #4a3a28; --grain: .045; --scrim: rgba(29,27,21,.88);
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 2px 6px rgba(0,0,0,.45), 0 10px 24px rgba(0,0,0,.35);
  --shadow-3: 0 2px 6px rgba(0,0,0,.5), 0 10px 24px rgba(0,0,0,.4), 0 26px 52px rgba(0,0,0,.4);
  color-scheme: dark;
}

:root[data-theme="black"] {
  --ground: #000; --page: #000; --ink: #b9b3a9; --ink-2: #9a958d; --ink-3: #86817b;
  --hair: #222; --hair-soft: #191919; --accent: #c4785a; --accent-in: #000;
  --sel: #3a2c1e; --grain: 0; --scrim: rgba(0,0,0,.9);
  --shadow-1: none; --shadow-2: none; --shadow-3: none;
  color-scheme: dark;
}

/* ══════════════════ shell ══════════════════ */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%; margin: 0; padding: 0;
  overscroll-behavior: none;
}

body {
  background: var(--ground);
  color: var(--ink);
  font: 400 15px/1.5 'plexthai', ui-sans-serif, -apple-system, system-ui, sans-serif;
  overflow: hidden;                       /* the shell never scrolls; panes do */
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;             /* kill the 300ms double-tap zoom wait */
}

/* svh is the SMALL viewport, so the shell is never clipped behind a collapsed
 * URL bar and never reflows mid-scroll. dvh is a progressive upgrade only. */
.app {
  position: fixed; inset: 0;
  height: 100svh;
  display: grid;
  overflow: hidden;
}
@supports (height: 100dvh) { .app { height: 100dvh; } }

/* A faint tiled grain kills the banding that betrays a flat digital fill.
 * Fixed and tiled, never one full-viewport filter rect, and never inside a
 * scrolling container. */
.grain {
  position: fixed; inset: 0; z-index: 60; pointer-events: none;
  opacity: var(--grain);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3'/></filter><rect width='140' height='140' filter='url(%23n)'/></svg>");
  background-size: 140px 140px;
  mix-blend-mode: multiply;
}
:root[data-theme="night"] .grain,
:root[data-theme="black"] .grain { mix-blend-mode: screen; }

.screen { grid-area: 1 / 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.screen[hidden] { display: none !important; }

/* Safe areas return 0 unless viewport-fit=cover is set; always give env() a
 * 0px fallback or an unsupporting browser invalidates the whole calc(). */
.pad-t { padding-top:    env(safe-area-inset-top, 0px); }
.pad-b { padding-bottom: env(safe-area-inset-bottom, 0px); }

/* ══════════════════ type & controls ══════════════════ */

button, input, select { font: inherit; color: inherit; }
button {
  background: none; border: 0; padding: 0; cursor: pointer;
  transition: transform 140ms cubic-bezier(.22,.61,.36,1), opacity 140ms, background-color 140ms;
}
/* Press feedback scales DOWN. Growing under a finger reads as the button
 * escaping the press. */
button:active { transform: scale(.97); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}

.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 10px; color: var(--ink-2); position: relative;
}
.icon-btn::before {                        /* dense look, 44px touch target */
  content: ''; position: absolute; inset: -4px;
}
.icon-btn:hover { background: var(--hair-soft); color: var(--ink); }
.icon-btn.on { color: var(--accent); }
.icon-btn svg { width: 20px; height: 20px; display: block; }

/* Every control revealed only by :hover is unreachable on a touchscreen. */
@media (hover: none) {
  .icon-btn:hover { background: none; }
  .hover-only { opacity: 1 !important; }
}
@media (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
  /* iOS zooms the page when a focused input is under 16px. Fix the input. */
  input, select, textarea { font-size: 16px; }
}

.eyebrow {
  font: 600 11px/1 'plexthai', system-ui, sans-serif;
  letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3);
}

/* ══════════════════ shelf ══════════════════ */

.shelf-top {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px 12px; flex: 0 0 auto;
}
.shelf-top .wordmark {
  font: 500 19px/1 'notoserifthai', Georgia, serif;
  letter-spacing: .01em; color: var(--ink); margin-right: auto;
}
.shelf-top .wordmark i { font-style: normal; color: var(--accent); }

.shelf-scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 20px calc(32px + env(safe-area-inset-bottom, 0px));
}

/* the resume card — deliberately not a grid cell, so it leads */
.resume {
  display: grid; grid-template-columns: 76px 1fr; gap: 16px; align-items: center;
  width: 100%; text-align: left;
  padding: 16px; margin-bottom: 32px;
  background: var(--page); border-radius: 14px;
  box-shadow: var(--shadow-2);
  border: 1px solid var(--hair-soft);
}
.resume:active { transform: scale(.995); }
.resume .cover { width: 76px; aspect-ratio: 2/3; border-radius: 5px; }
.resume h3 {
  margin: 0 0 3px; font: 500 17px/1.3 'notoserifthai', Georgia, serif; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.resume .by { font-size: 13px; color: var(--ink-3); margin-bottom: 12px; }
.resume .meter { height: 3px; background: var(--hair); border-radius: 2px; overflow: hidden; }
.resume .meter i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.resume .pct { font: 500 11px/1 'plexthai', system-ui; color: var(--ink-3); margin-top: 8px; letter-spacing: .04em; }

.sect-head {
  display: flex; align-items: baseline; gap: 12px; margin: 0 0 16px;
}
.sect-head .count { font: 400 12px/1 'plexthai', system-ui; color: var(--ink-3); margin-left: auto; font-variant-numeric: tabular-nums; }

/* A wall of covers by 212 different designers cannot be made to agree, so the
 * FRAME does the agreeing: one aspect, one radius, one shadow, one gutter.
 * That is what makes it read as a shelf instead of a pile. */
.grid {
  display: grid; gap: 28px 20px;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  /* start, not the default stretch: a stretched <button> centres its own
   * content in Chrome, so a tile with a one-line title drops its cover ~9px
   * below its neighbours and the whole shelf loses its baseline. */
  align-items: start;
}
.tile {
  text-align: left; width: 100%;
  display: flex; flex-direction: column; align-items: stretch;
}
.tile .cover { width: 100%; aspect-ratio: 2/3; margin-bottom: 10px; }
.tile h4 {
  margin: 0 0 2px; font: 500 13px/1.35 'plexthai', system-ui, sans-serif; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tile .by {
  font: 400 11.5px/1.3 'plexthai', system-ui; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile .bar { height: 2px; background: var(--hair); border-radius: 1px; margin-top: 8px; overflow: hidden; }
.tile .bar i { display: block; height: 100%; background: var(--accent); }

/* the cover object itself: a spine edge and layered light, so even a plain
 * generated cover reads as a physical board rather than a coloured rectangle */
.cover {
  position: relative; overflow: hidden; border-radius: 3px 6px 6px 3px;
  background: var(--page);
  box-shadow: var(--shadow-2);
  transition: transform 220ms cubic-bezier(.22,.61,.36,1), box-shadow 220ms;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover::after {                            /* spine shading + top-lit edge */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(90deg, rgba(0,0,0,.20) 0, rgba(0,0,0,.05) 3px, rgba(0,0,0,0) 9px),
    linear-gradient(90deg, rgba(255,255,255,.13) 0, rgba(255,255,255,0) 14px);
  border-radius: inherit;
}
.tile:active .cover { transform: scale(.975); }
@media (hover: hover) {
  .tile:hover .cover { transform: translateY(-3px); box-shadow: var(--shadow-3); }
}

/* generated cover for books with no artwork: type IS the cover */
.cover.gen { display: grid; align-content: center; padding: 14px 12px; }
.cover.gen .t {
  font: 500 13px/1.28 'notoserifthai', Georgia, serif; color: var(--accent-in);
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
}
.cover.gen .a {
  font: 400 10px/1.3 'plexthai', system-ui; margin-top: 8px; opacity: .72; color: var(--accent-in);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* list view — a ledger, hairline-ruled and column-aligned */
.list { display: block; }
.row {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 14px; align-items: center;
  width: 100%; text-align: left;
  padding: 12px 4px; border-top: 1px solid var(--hair-soft);
}
.row:last-child { border-bottom: 1px solid var(--hair-soft); }
.row .cover { width: 34px; aspect-ratio: 2/3; border-radius: 2px 3px 3px 2px; }
.row .t { font: 500 14.5px/1.35 'plexthai', system-ui; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .a { font: 400 12px/1.3 'plexthai', system-ui; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .pct { font: 500 11px/1 'plexthai', system-ui; color: var(--ink-3);
  font-variant-numeric: tabular-nums; letter-spacing: .03em; }
@media (pointer: coarse) { .row { padding: 14px 4px; } }

.empty { text-align: center; padding: 72px 24px; color: var(--ink-3); }
.empty h2 { font: 400 21px/1.4 'notoserifthai', Georgia, serif; color: var(--ink-2); margin: 0 0 12px; }
.empty p { font-size: 14px; line-height: 1.7; max-width: 34ch; margin: 0 auto 24px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 18px; border-radius: 10px;
  background: var(--accent); color: var(--accent-in);
  font: 500 14px/1 'plexthai', system-ui; letter-spacing: .01em;
  box-shadow: var(--shadow-1);
}
.btn.ghost { background: none; color: var(--ink-2); box-shadow: none; border: 1px solid var(--hair); }
@media (pointer: coarse) { .btn { padding: 13px 20px; } }

/* ══════════════════ reader ══════════════════ */

.reader { position: relative; background: var(--page); }

.page-host {
  position: absolute; inset: 0;
  overflow: hidden;
  /* margins are set from JS so they can follow the measure control */
  padding: var(--m-t) var(--m-x) var(--m-b);
  contain: layout paint;
}

/* THE THAI CLIPPING FIX — do not remove this padding.
 *
 * Thai stacks a vowel above the consonant and a tone mark above that, and both
 * paint ABOVE the line box, outside the element. A multicol container clips to
 * its own box, so the first line of every column loses its entire upper
 * register: "สัมพันธ์ลับสิบปี" renders as "สมพนธลบสบป". It reads as a broken
 * font, which is what makes it hard to place — the font is fine, the glyphs
 * are being painted and then cut off.
 *
 * Padding on the multicol container is the fix rather than leading, because
 * padding shortens every column box, so column six is protected as well as
 * column one. (More line-height also works, by pushing the glyph down inside
 * its own box, but it is a big typographic change to buy a clipping fix.)
 * Set in em so it tracks the reading size. */
.flow {
  padding-top: .5em;
  padding-bottom: .3em;
  will-change: transform;
  color: var(--ink);
  font-family: var(--rf), 'plexthai', ui-serif, Georgia, serif;
  font-size: var(--rs);
  line-height: var(--rlh);
  text-align: var(--ralign);
  -webkit-hyphens: auto; hyphens: auto;
  word-break: normal;
  overflow-wrap: break-word;
}

/* Book content. Deliberately narrow rules: the book brings its own structure
 * and the app should set rhythm, not restyle every element it meets. */
.flow p { margin: 0; text-indent: var(--rindent); }
.flow p + p { margin-top: var(--rgap); }
/* Line-height on a heading is not a taste question in Thai, it is a
 * correctness one. Thai stacks a vowel above the consonant and a tone mark
 * above that, and both paint ABOVE the line box. The page container clips
 * (overflow:hidden + contain:paint), so a heading at the top of a page with
 * line-height 1.4 has its entire upper register sliced off — "สัมพันธ์ลับสิบปี"
 * renders as "สมพนธลบสบป" and reads as a broken font rather than a tight
 * leading. 1.55 is the floor the research gives; 1.62 for Thai buys margin. */
.flow h1, .flow h2, .flow h3, .flow h4, .flow h5, .flow h6 {
  font-family: var(--rf), Georgia, serif;
  font-weight: 700; line-height: 1.55;
  margin: 1.6em 0 .7em; text-indent: 0; text-align: start;
  break-after: avoid-column;
}
.flow[data-script="th"] h1, .flow[data-script="th"] h2, .flow[data-script="th"] h3,
.flow[data-script="th"] h4, .flow[data-script="th"] h5, .flow[data-script="th"] h6 {
  line-height: 1.62;
}
/* Same reasoning for anything else that sets its own tighter leading. */
.flow sub, .flow sup { line-height: 0; }
.flow h1 { font-size: 1.42em; } .flow h2 { font-size: 1.24em; }
.flow h3 { font-size: 1.1em; }  .flow h4, .flow h5, .flow h6 { font-size: 1em; }
.flow h1:first-child, .flow h2:first-child, .flow h3:first-child { margin-top: .2em; }
.flow blockquote {
  margin: 1.2em 0; padding-left: 1.1em; text-indent: 0;
  border-left: 2px solid var(--hair); color: var(--ink-2);
}
.flow ul, .flow ol { margin: 1em 0; padding-left: 1.4em; text-indent: 0; }
.flow li { margin: .35em 0; }
.flow hr { border: 0; border-top: 1px solid var(--hair); margin: 1.8em auto; width: 34%; }
.flow em, .flow i, .flow cite { font-style: italic; }
.flow strong, .flow b { font-weight: 700; }
.flow a { color: var(--accent); text-decoration: none; border-bottom: 1px solid color-mix(in oklab, var(--accent) 35%, transparent); }
.flow sup, .flow sub { font-size: .72em; line-height: 0; }
.flow code, .flow pre { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: .88em; }
.flow pre { white-space: pre-wrap; text-indent: 0; margin: 1.2em 0; }
.flow table { border-collapse: collapse; margin: 1.2em 0; font-size: .92em; text-indent: 0; }
.flow td, .flow th { border: 1px solid var(--hair); padding: 6px 9px; text-align: start; }

/* An image must fit inside one page or it pushes the column and every page
 * after it inherits the error. --page-h is published by the paginator. */
.flow img {
  display: block; max-width: 100%;
  max-height: calc(var(--page-h, 600px) - 2.5em);
  height: auto; margin: 1.1em auto; object-fit: contain;
  break-inside: avoid-column;
  border-radius: 2px;
}
.flow figure { margin: 1.2em 0; text-indent: 0; break-inside: avoid-column; }
.flow figcaption { font-size: .82em; color: var(--ink-3); text-align: center; margin-top: .5em; }

/* Thai wants a little more air between letters at reading size, and never
 * wants faux-bold: capped at 700, because Black clogs the counters. */
.flow[data-script="th"] { letter-spacing: var(--rls, .004em); }
.flow[data-script="th"] strong, .flow[data-script="th"] b { font-weight: 700; }

::selection { background: var(--sel); color: var(--ink); }

/* chrome: two bars that slide away, so the page is the whole screen by default.
 * Selector is the two modifiers, never bare `.bar`: the shelf tile's progress
 * bar is also `.bar`, and a bare rule made it `position:absolute; left:0;
 * right:0` — a full-width hairline laid across the covers. */
.bar-top, .bar-bot {
  position: absolute; left: 0; right: 0; z-index: 20;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(11px) saturate(150%);
  backdrop-filter: blur(11px) saturate(150%);
  transition: transform 260ms cubic-bezier(.22,.61,.36,1), opacity 200ms;
}
.bar-top {
  top: 0; padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
  border-bottom: 1px solid var(--hair-soft);
  display: flex; align-items: center; gap: 4px;
}
.bar-bot {
  bottom: 0; padding: 10px 20px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--hair-soft);
}
.chrome-off .bar-top { transform: translateY(-102%); opacity: 0; pointer-events: none; }
.chrome-off .bar-bot { transform: translateY(102%); opacity: 0; pointer-events: none; }

.bar-top .ttl {
  flex: 1 1 auto; min-width: 0; text-align: center;
  font: 500 13px/1.3 'plexthai', system-ui; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 4px;
}

.scrub { display: flex; align-items: center; gap: 12px; }
.scrub input[type=range] { flex: 1 1 auto; }
.scrub .n {
  font: 500 11px/1 'plexthai', system-ui; color: var(--ink-3);
  font-variant-numeric: tabular-nums; letter-spacing: .03em; white-space: nowrap;
}
.foot {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 7px;
  font: 400 10.5px/1 'plexthai', system-ui; color: var(--ink-3);
  letter-spacing: .05em; font-variant-numeric: tabular-nums;
}
.foot .ch { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 12px; }

/* tap zones: left third back, right third forward, middle toggles chrome */
.zones { position: absolute; inset: 0; z-index: 10; display: grid; grid-template-columns: 1fr 1fr 1fr; }
.zones > * { -webkit-tap-highlight-color: transparent; }

/* a page-edge hint that only appears while dragging */
.edge {
  position: absolute; top: 0; bottom: 0; width: 40px; z-index: 15; pointer-events: none;
  opacity: 0; transition: opacity 160ms;
}
.edge.l { left: 0;  background: linear-gradient(90deg, rgba(0,0,0,.07), transparent); }
.edge.r { right: 0; background: linear-gradient(270deg, rgba(0,0,0,.07), transparent); }
.dragging .edge { opacity: 1; }

/* the dim overlay for reading at night without touching system brightness */
.dim {
  position: absolute; inset: 0; z-index: 40; pointer-events: none;
  background: #000; opacity: 0; transition: opacity 200ms;
}

/* ══════════════════ range inputs ══════════════════ */
/* The visual track and the input share ONE centreline, both absolutely placed
 * in a fixed-height slot. A thumb sitting a pixel below its own track is the
 * loudest cheap-UI tell there is. */

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 28px; background: none; margin: 0; display: block;
}
/* The whole control is the touch target, not the thumb. The track stays 3px;
 * only the grabbable box grows. */
@media (pointer: coarse) { input[type=range] { height: 44px; } }
input[type=range]::-webkit-slider-runnable-track {
  height: 3px; border-radius: 2px; background: var(--hair);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--page); border: 1px solid var(--hair);
  box-shadow: var(--shadow-1);
  margin-top: -7.5px;                      /* (3 - 18) / 2 */
}
input[type=range]:active::-webkit-slider-thumb { background: var(--accent); border-color: var(--accent); }
input[type=range]::-moz-range-track { height: 3px; border-radius: 2px; background: var(--hair); }
input[type=range]::-moz-range-thumb {
  width: 17px; height: 17px; border-radius: 50%; border: 1px solid var(--hair);
  background: var(--page); box-shadow: var(--shadow-1);
}

/* ══════════════════ sheets ══════════════════ */

.sheet-wrap { position: fixed; inset: 0; z-index: 80; display: none; }
.sheet-wrap.on { display: block; }
.veil {
  position: absolute; inset: 0; background: rgba(20,16,10,.34);
  opacity: 0; transition: opacity 240ms;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.sheet-wrap.in .veil { opacity: 1; }

.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88svh; display: flex; flex-direction: column;
  background: var(--page); color: var(--ink);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -1px 0 var(--hair-soft), 0 -8px 40px rgba(40,30,16,.22);
  transform: translateY(100%);
  transition: transform 320ms cubic-bezier(.22,.61,.36,1);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet-wrap.in .sheet { transform: translateY(0); }
.sheet.dragging { transition: none; }

/* On a wide screen a full-width sheet is a waste; centre it as a panel. */
@media (min-width: 720px) {
  .sheet { left: 50%; right: auto; transform: translate(-50%, 100%); width: 560px; border-radius: 18px 18px 0 0; }
  .sheet-wrap.in .sheet { transform: translate(-50%, 0); }
}

.grip { padding: 10px 0 4px; display: grid; place-items: center; flex: 0 0 auto; cursor: grab; touch-action: none; }
.grip i { width: 38px; height: 4px; border-radius: 3px; background: var(--hair); display: block; }
.sheet-head {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 20px 12px; flex: 0 0 auto;
  border-bottom: 1px solid var(--hair-soft);
}
.sheet-head h3 { margin: 0; font: 500 15px/1 'plexthai', system-ui; color: var(--ink); }
.sheet-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch; padding: 4px 20px 24px;
}

/* tabs inside the type sheet */
.tabs { display: flex; gap: 4px; padding: 12px 20px 0; flex: 0 0 auto; }
.tab {
  padding: 7px 13px; border-radius: 8px; font: 500 12.5px/1 'plexthai', system-ui;
  color: var(--ink-3);
}
@media (pointer: coarse) { .tab { padding: 12px 15px; min-height: 44px; } }
.tab.on { background: var(--hair-soft); color: var(--ink); }

.field { padding: 16px 0; border-bottom: 1px solid var(--hair-soft); }
.field:last-child { border-bottom: 0; }
.field > label {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  font: 500 12px/1 'plexthai', system-ui; color: var(--ink-2);
  letter-spacing: .04em; text-transform: uppercase; margin-bottom: 12px;
}
.field > label .v {
  font: 400 12px/1 'plexthai', system-ui; color: var(--ink-3);
  text-transform: none; letter-spacing: .02em; font-variant-numeric: tabular-nums;
}
.hint { font: 400 11.5px/1.55 'plexthai', system-ui; color: var(--ink-3); margin: 10px 0 0; }

/* segmented control */
.seg { display: flex; gap: 3px; background: var(--hair-soft); padding: 3px; border-radius: 10px; }
.seg button {
  flex: 1 1 0; padding: 9px 4px; border-radius: 7px;
  font: 500 12.5px/1 'plexthai', system-ui; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.seg button.on { background: var(--page); color: var(--ink); box-shadow: var(--shadow-1); }
/* 44px is Apple's minimum, Material's 48dp and WCAG 2.5.8 all at once. Set a
 * min-height rather than more padding, so the label stays optically centred. */
@media (pointer: coarse) {
  .seg button { padding: 11px 4px; min-height: 44px; }
  .seg { padding: 4px; }
}

/* theme swatches show the real thing, not a label */
.themes { display: flex; gap: 10px; }
.sw {
  flex: 1 1 0; height: 58px; border-radius: 10px; position: relative;
  border: 1px solid var(--hair); display: grid; place-items: center;
  font: 500 11px/1 'plexthai', system-ui; letter-spacing: .04em;
  overflow: hidden;
}
.sw.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.sw .aa { font: 500 17px/1 'notoserifthai', Georgia, serif; }

/* ══════════════════ font picker ══════════════════ */

.fgroup { margin: 20px 0 0; }
.fgroup:first-child { margin-top: 8px; }
.fgroup > .gh {
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px;
}
.fgroup .gh b { font: 600 11px/1 'plexthai', system-ui; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-2); }
.fgroup .gh span { font: 400 11px/1 'plexthai', system-ui; color: var(--ink-3); }
.fgroup .gn { font: 400 11px/1.5 'plexthai', system-ui; color: var(--ink-3); margin: -4px 0 12px; }

.face {
  display: block; width: 100%; text-align: left;
  padding: 12px 14px; margin-bottom: 6px;
  border-radius: 10px; border: 1px solid transparent;
  background: color-mix(in oklab, var(--hair-soft) 55%, transparent);
}
.face.on { border-color: var(--accent); background: var(--page); box-shadow: var(--shadow-1); }
.face .fn {
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px;
  font: 500 12px/1 'plexthai', system-ui; color: var(--ink-2);
}
.face .fn .tag {
  font: 500 9.5px/1 'plexthai', system-ui; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-3); border: 1px solid var(--hair); border-radius: 4px; padding: 3px 5px;
}
.face.on .fn { color: var(--ink); }
.face.on .fn .tick { margin-left: auto; color: var(--accent); }
/* the preview must be set in ITS OWN face — the single easiest bug to ship
 * here is twenty previews that all render in one font */
.face .fp {
  font-size: 18px; line-height: 1.75; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.face .fp .lat { font-size: .82em; color: var(--ink-3); }

/* ══════════════════ contents ══════════════════ */

.toc-item {
  display: block; width: 100%; text-align: left;
  padding: 11px 8px; border-radius: 8px;
  font: 400 14px/1.45 'plexthai', system-ui; color: var(--ink-2);
  border-bottom: 1px solid var(--hair-soft);
}
.toc-item:last-child { border-bottom: 0; }
.toc-item.on { color: var(--accent); font-weight: 500; }
.toc-item .d1 { padding-left: 16px; display: block; }
.toc-item .d2 { padding-left: 32px; display: block; }
@media (pointer: coarse) { .toc-item { padding: 13px 8px; } }

/* ══════════════════ toast ══════════════════ */

.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 14px); z-index: 95;
  background: var(--ink); color: var(--page);
  padding: 11px 18px; border-radius: 10px;
  font: 500 13px/1 'plexthai', system-ui;
  box-shadow: var(--shadow-3); opacity: 0; pointer-events: none;
  transition: opacity 220ms, transform 220ms cubic-bezier(.22,.61,.36,1);
  max-width: min(90vw, 420px); text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ══════════════════ import progress ══════════════════ */

.sweep {
  position: absolute; left: 0; right: 0; top: 0; height: 2px; z-index: 30;
  overflow: hidden; opacity: 0; transition: opacity 200ms;
}
.sweep.on { opacity: 1; }
/* A sweep reads as WORKING. A pulse reads as stalled. */
.sweep i {
  display: block; height: 100%; width: 38%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: sweep 1.15s cubic-bezier(.45,0,.55,1) infinite;
}
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(363%); } }
