/*
  Glyph — brief
  Product: a personal Goodnotes replacement. Audience: Quan, on iPad + iPhone Duo + Apple Pencil.
  Job: make writing by hand feel instant, and finding it later effortless.
  Direction: warm paper desk, cobalt ink accent, one black floating "ink bar" that carries every tool.
  Boldness lives in two places only: the ink bar and the big Bricolage library headings. Everything else stays quiet — the notes are the design.
  Mode: Operate (quiet), Read for text docs.
*/
:root {
  --bg: #F3EEE4; --bg-2: #EAE3D5; --surface: #FFFDF8; --desk: #E4DCCC;
  --ink: #17150F; --ink-2: #4B463C; --muted: #776F61; --line: #DCD3C2;
  --cobalt: #2346E0; --cobalt-2: #1B37B8; --cobalt-soft: #E1E6FF; --on-cobalt: #fff;
  --bar: #141310; --bar-2: #2A2822; --bar-ink: #F4EFE6; --bar-muted: #9C9486;
  --danger: #C8392B; --ok: #1E8A5A;
  --shadow: 0 10px 30px -12px rgba(40, 28, 8, .35), 0 2px 6px -2px rgba(40, 28, 8, .18);
  --r-s: 8px; --r-m: 14px; --r-l: 22px;
  --f-display: "Bricolage Grotesque", Figtree, system-ui, sans-serif;
  --f-body: Figtree, system-ui, -apple-system, sans-serif;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #12110E; --bg-2: #1A1814; --surface: #201E19; --desk: #0C0B09;
  --ink: #F1EBDF; --ink-2: #CFC7B8; --muted: #958D7F; --line: #322E27;
  --cobalt: #6E86FF; --cobalt-2: #8C9FFF; --cobalt-soft: #1D244A; --on-cobalt: #0B0E22;
  --bar: #050504; --bar-2: #24221D; --shadow: 0 12px 32px -10px rgba(0, 0, 0, .7), 0 2px 8px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 400 16px/1.45 var(--f-body); overscroll-behavior: none; }
body { overflow: hidden; -webkit-font-smoothing: antialiased; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
::selection { background: var(--cobalt); color: var(--on-cobalt); }
input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; caret-color: var(--cobalt); }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }
input, select, textarea { font: inherit; color: var(--ink); accent-color: var(--cobalt); }
.ic { display: block; flex: none; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- app frame ---------- */
#app { position: fixed; inset: 0; display: flex; }
.screen { position: absolute; inset: 0; display: flex; }

/* ---------- library ---------- */
.lib { background: var(--bg); }
.side { width: 248px; flex: none; padding: calc(18px + var(--sat)) 14px calc(16px + var(--sab)) calc(14px + var(--sal)); display: flex; flex-direction: column; gap: 4px; border-right: 1px solid var(--line); background: var(--bg-2); }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; font: 700 26px/1 var(--f-display); letter-spacing: -.03em; }
.brand svg { color: var(--cobalt); }
.nav-btn { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; font-weight: 500; color: var(--ink-2); min-height: 44px; text-align: left; }
.nav-btn:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.nav-btn[aria-current="true"] { background: var(--ink); color: var(--bg); }
.nav-btn .count { margin-left: auto; font-size: 13px; color: var(--muted); }
.nav-btn[aria-current="true"] .count { color: color-mix(in srgb, var(--bg) 70%, transparent); }
.side .spacer { flex: 1; }
.lib-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lib-head { padding: calc(22px + var(--sat)) calc(28px + var(--sar)) 14px 28px; display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.lib-title { font: 700 40px/1 var(--f-display); letter-spacing: -.035em; margin: 0; min-width: 0; flex: 1 1 auto; text-wrap: balance; }
.crumbs { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 14px; margin-bottom: 8px; flex-basis: 100%; }
.crumbs button { color: var(--muted); } .crumbs button:hover { color: var(--ink); }
.head-actions { display: flex; gap: 8px; align-items: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 999px; font-weight: 600; font-size: 15px; background: var(--surface); border: 1px solid var(--line); white-space: nowrap; }
.btn:hover { border-color: color-mix(in srgb, var(--ink) 30%, var(--line)); }
.btn.primary { background: var(--cobalt); color: var(--on-cobalt); border-color: var(--cobalt); }
.btn.primary:hover { background: var(--cobalt-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 999px; flex: none; }
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.lib-tools { display: flex; gap: 8px; padding: 0 28px 10px; align-items: center; flex-wrap: wrap; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); font-size: 14px; font-weight: 500; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.lib-scroll { flex: 1; overflow-y: auto; padding: 8px 28px calc(110px + var(--sab)); -webkit-overflow-scrolling: touch; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 30px 22px; }
.card { display: flex; flex-direction: column; gap: 8px; text-align: left; min-width: 0; position: relative; }
.thumb { aspect-ratio: 3 / 4; border-radius: 4px 12px 12px 4px; position: relative; overflow: hidden; box-shadow: var(--shadow); transition: transform .15s cubic-bezier(.2, .8, .2, 1); background: var(--surface); }
.card:active .thumb { transform: scale(.97); }
.thumb.page { border-radius: 6px; }
.thumb img, .thumb canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .cover-title { position: absolute; left: 16%; right: 10%; top: 16%; font: 700 17px/1.08 var(--f-display); letter-spacing: -.02em; color: rgba(255, 255, 255, .94); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; }
.thumb .cover-title.dark { color: rgba(20, 18, 14, .85); }
.thumb.folder { aspect-ratio: 4 / 3; border-radius: var(--r-m); background: color-mix(in srgb, var(--fc, var(--cobalt)) 16%, var(--surface)); box-shadow: none; border: 1px solid var(--line); display: grid; place-items: center; color: var(--fc, var(--cobalt)); }
.thumb.type-badge::after { content: attr(data-badge); position: absolute; left: 8px; bottom: 8px; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: rgba(20, 19, 16, .78); color: #F4EFE6; }
.card-meta { display: flex; gap: 6px; align-items: flex-start; min-width: 0; }
.card-meta > div { min-width: 0; flex: 1; }
.card-name { font-weight: 600; font-size: 15px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-date { font-size: 13px; color: var(--muted); }
.card .more { width: 32px; height: 32px; margin: -4px -6px 0 0; display: grid; place-items: center; border-radius: 999px; color: var(--muted); }
.card .fav { position: absolute; top: 8px; right: 8px; color: #FFD166; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .4)); }
.is-list .grid { grid-template-columns: 1fr; gap: 2px; }
.is-list .card { flex-direction: row; align-items: center; gap: 14px; padding: 8px; border-radius: 12px; }
.is-list .card:hover { background: var(--bg-2); }
.is-list .thumb { width: 44px; flex: none; box-shadow: none; border: 1px solid var(--line); }
.is-list .thumb.folder { width: 56px; }
.is-list .thumb .cover-title, .is-list .thumb::after { display: none; }
.is-list .card-meta { flex: 1; align-items: center; }
.section-h { font: 700 22px/1.2 var(--f-display); letter-spacing: -.02em; margin: 26px 0 14px; }
.section-h:first-child { margin-top: 4px; }
.empty { max-width: 420px; margin: 8vh auto; text-align: center; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty h3 { font: 700 26px/1.1 var(--f-display); letter-spacing: -.02em; margin: 0; color: var(--ink); }
.empty p { margin: 0; }
.empty .art { width: 150px; height: 110px; }
.tabbar { display: none; }
.fab { position: absolute; right: calc(24px + var(--sar)); bottom: calc(24px + var(--sab)); width: 60px; height: 60px; border-radius: 999px; background: var(--bar); color: var(--bar-ink); display: grid; place-items: center; box-shadow: var(--shadow); z-index: 20; }
.search-box { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0 16px; min-height: 48px; margin: 0 28px 14px; }
.search-box input { flex: 1; border: 0; background: transparent; outline: none; font-size: 17px; min-width: 0; }
.result { display: flex; gap: 14px; padding: 12px; border-radius: 12px; text-align: left; width: 100%; align-items: flex-start; }
.result:hover { background: var(--bg-2); }
.result .r-title { font-weight: 600; }
.result .r-snip { color: var(--ink-2); font-size: 14px; }
.result mark { background: var(--cobalt-soft); color: var(--ink); border-radius: 3px; padding: 0 2px; }
.result .r-kind { font-size: 12px; color: var(--muted); }

/* ---------- editor ---------- */
.ed { flex-direction: column; background: var(--desk); }
.ed-top { flex: none; display: flex; align-items: center; gap: 4px; padding: calc(6px + var(--sat)) calc(10px + var(--sar)) 6px calc(8px + var(--sal)); background: var(--bg); border-bottom: 1px solid var(--line); min-height: 56px; z-index: 30; }
.ed-title { font: 600 16px/1.2 var(--f-body); padding: 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; text-align: center; }
.ed-title button { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: flex; align-items: center; gap: 6px; padding: 0 6px 0 12px; height: 34px; border-radius: 10px; font-size: 14px; font-weight: 500; color: var(--muted); max-width: 200px; flex: none; }
.tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab[aria-current="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.tab .x { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; opacity: .7; }
.tab .x:hover { background: var(--bg-2); opacity: 1; }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.canvas-host canvas { position: absolute; left: 0; top: 0; }
.cv-ui { z-index: 2; } .cv-ink { z-index: 1; pointer-events: none; }
.text-layer { position: absolute; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.text-edit { position: absolute; pointer-events: auto; border: 1.5px dashed var(--cobalt); outline: none; resize: none; overflow: hidden; margin: 0; border-radius: 3px; white-space: pre-wrap; word-wrap: break-word; transform-origin: center; box-sizing: border-box; }
.text-edit.note { border: 0; box-shadow: 0 6px 18px rgba(40, 30, 10, .25); border-radius: 0; }

/* the ink bar */
.inkbar { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 25; display: flex; align-items: center; gap: 2px; padding: 6px; background: var(--bar); color: var(--bar-ink); border-radius: 999px; box-shadow: var(--shadow); max-width: calc(100% - 20px); overflow-x: auto; scrollbar-width: none; }
.inkbar::-webkit-scrollbar { display: none; }
.inkbar .tb { width: 44px; height: 44px; border-radius: 999px; display: grid; place-items: center; color: var(--bar-muted); flex: none; position: relative; transition: background .12s, color .12s; }
.inkbar .tb:hover { color: var(--bar-ink); }
.inkbar .tb[aria-pressed="true"] { background: var(--bar-ink); color: var(--bar); }
.inkbar .tb[aria-pressed="true"]::after { content: ""; position: absolute; bottom: 3px; width: 4px; height: 4px; border-radius: 9px; background: var(--cobalt); }
.inkbar .tb:disabled { opacity: .35; }
.inkbar .sep { width: 1px; height: 24px; background: var(--bar-2); margin: 0 6px; flex: none; }
.swatch { width: 30px; height: 30px; border-radius: 999px; flex: none; margin: 0 3px; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .14); position: relative; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bar), 0 0 0 4px var(--bar-ink); }
.sizebtn { width: 34px; height: 44px; display: grid; place-items: center; flex: none; }
.sizebtn i { display: block; border-radius: 99px; background: var(--bar-muted); }
.sizebtn[aria-pressed="true"] i { background: var(--bar-ink); }
.pageind { position: absolute; right: calc(14px + var(--sar)); bottom: calc(14px + var(--sab)); z-index: 20; display: flex; gap: 6px; align-items: center; }
.pill { height: 38px; padding: 0 14px; border-radius: 999px; background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--line); font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; box-shadow: 0 2px 8px rgba(0, 0, 0, .08); }
.pill.icon { width: 38px; padding: 0; justify-content: center; }
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--sab)); transform: translateX(-50%); background: var(--bar); color: var(--bar-ink); padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 500; z-index: 1000; box-shadow: var(--shadow); pointer-events: none; animation: toast .2s cubic-bezier(.2, .8, .2, 1); max-width: calc(100% - 32px); text-align: center; }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 8px); } }

/* popovers, menus, sheets */
.scrim { position: fixed; inset: 0; z-index: 90; }
.scrim.dim { background: rgba(15, 12, 6, .38); animation: fade .16s ease-out; }
@keyframes fade { from { opacity: 0; } }
.pop { position: fixed; z-index: 100; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow); padding: 14px; width: min(340px, calc(100vw - 20px)); max-height: min(72vh, 640px); overflow-y: auto; animation: pop .16s cubic-bezier(.2, .8, .2, 1); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.pop h4 { margin: 2px 0 10px; font: 600 13px/1.2 var(--f-body); color: var(--muted); }
.pop h4:not(:first-child) { margin-top: 16px; }
.seg { display: flex; background: var(--bg-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; min-height: 38px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--ink-2); display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 6px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.swatches { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.swatches button { aspect-ratio: 1; border-radius: 999px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
.swatches button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--cobalt); }
.row { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.row label { flex: 1; font-size: 15px; }
.row input[type="range"] { flex: 1.4; }
.row .val { min-width: 42px; text-align: right; font-size: 14px; color: var(--muted); }
.menu { padding: 6px; width: auto; min-width: 220px; }
.menu button, .menu a { display: flex; align-items: center; gap: 12px; width: 100%; padding: 0 12px; min-height: 44px; border-radius: 10px; font-size: 15px; text-align: left; color: var(--ink); text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--bg-2); }
.menu .danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
.selmenu { position: fixed; z-index: 40; display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; padding: 5px; background: var(--bar); color: var(--bar-ink); border-radius: 14px; box-shadow: var(--shadow); max-width: min(560px, calc(100vw - 16px)); }
.selmenu button { min-height: 44px; padding: 0 11px; border-radius: 10px; font-size: 14px; font-weight: 500; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.selmenu button:hover { background: var(--bar-2); }
.selmenu .sw { width: 28px; height: 28px; padding: 0; border-radius: 99px; min-height: 0; margin: 8px 4px; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .25); }
.sheet { position: fixed; z-index: 100; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 48px - var(--sat) - var(--sab)); background: var(--surface); border-radius: var(--r-l); box-shadow: var(--shadow); display: flex; flex-direction: column; animation: sheet .2s cubic-bezier(.2, .8, .2, 1); }
.sheet.wide { width: min(900px, calc(100vw - 24px)); height: min(760px, calc(100vh - 48px)); }
@keyframes sheet { from { opacity: 0; transform: translate(-50%, -48%); } }
.sheet-h { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px 22px; border-bottom: 1px solid var(--line); }
.sheet-h h3 { margin: 0; flex: 1; font: 700 22px/1.15 var(--f-display); letter-spacing: -.02em; min-width: 0; }
.sheet-b { padding: 18px 22px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-f { padding: 12px 22px calc(14px + var(--sab)); display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.input { min-height: 46px; border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; background: var(--bg); font-size: 16px; outline: none; width: 100%; }
.input:focus { border-color: var(--cobalt); }
textarea.input { padding: 12px 14px; min-height: 90px; resize: vertical; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 12px; }
.pick { display: flex; flex-direction: column; gap: 6px; align-items: center; font-size: 13px; color: var(--ink-2); text-align: center; }
.pick .pv { width: 100%; aspect-ratio: 3 / 4; border-radius: 6px; overflow: hidden; box-shadow: 0 1px 4px rgba(0, 0, 0, .15); outline: 2px solid transparent; outline-offset: 2px; }
.pick[aria-pressed="true"] .pv { outline-color: var(--cobalt); }
.pick[aria-pressed="true"] { color: var(--ink); font-weight: 600; }
.pick canvas { width: 100%; height: 100%; display: block; }
.sorter { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 18px; }
.sorter .pg { display: flex; flex-direction: column; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); position: relative; }
.sorter .pg canvas { width: 100%; border-radius: 4px; box-shadow: 0 2px 8px rgba(0, 0, 0, .14); outline: 2.5px solid transparent; outline-offset: 2px; background: #fff; }
.sorter .pg[aria-selected="true"] canvas { outline-color: var(--cobalt); }
.sorter .pg.current span { color: var(--cobalt); font-weight: 700; }
.sorter .pg .bm { position: absolute; top: -4px; right: 10px; color: var(--danger); }
.dock { position: absolute; left: 50%; bottom: calc(16px + var(--sab)); transform: translateX(-50%); z-index: 26; background: var(--bar); color: var(--bar-ink); border-radius: 18px; padding: 8px 10px; display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow); max-width: calc(100% - 20px); }
.dock .tb { width: 40px; height: 40px; border-radius: 999px; display: grid; place-items: center; flex: none; }
.dock .tb:hover { background: var(--bar-2); }
.dock input[type="range"] { width: min(260px, 40vw); accent-color: var(--cobalt); }
.dock .time { font-size: 13px; color: var(--bar-muted); min-width: 84px; font-variant-numeric: tabular-nums; }
.rec-dot { width: 10px; height: 10px; border-radius: 99px; background: #FF453A; animation: blink 1.2s infinite; flex: none; }
@keyframes blink { 50% { opacity: .3; } }
.zoomwin { position: absolute; left: 0; right: 0; bottom: 0; height: 34%; min-height: 190px; z-index: 24; background: var(--bar); display: flex; flex-direction: column; padding: 8px 10px calc(10px + var(--sab)); gap: 8px; box-shadow: 0 -10px 30px rgba(0, 0, 0, .25); }
.zoomwin .zw-bar { display: flex; gap: 4px; color: var(--bar-ink); align-items: center; }
.zoomwin .zw-bar .tb { width: 40px; height: 36px; border-radius: 10px; display: grid; place-items: center; }
.zoomwin .zw-bar .tb:hover { background: var(--bar-2); }
.zoomwin .zw-bar span { flex: 1; font-size: 13px; color: var(--bar-muted); padding-left: 6px; }
.zoomwin canvas { flex: 1; min-height: 0; width: 100%; border-radius: 10px; touch-action: none; background: #fff; }
.present .ed-top, .present .inkbar, .present .pageind { display: none; }
.present-ctl { position: absolute; z-index: 30; left: 50%; bottom: calc(14px + var(--sab)); transform: translateX(-50%); display: flex; gap: 6px; }
.lock { position: fixed; inset: 0; z-index: 2000; background: var(--bar); color: var(--bar-ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; }
.lock h2 { font: 700 32px/1 var(--f-display); margin: 0; letter-spacing: -.03em; }
.dots { display: flex; gap: 14px; }
.dots i { width: 14px; height: 14px; border-radius: 99px; border: 2px solid var(--bar-ink); }
.dots i.on { background: var(--bar-ink); }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; }
.keypad button { height: 76px; border-radius: 99px; background: var(--bar-2); font: 600 26px/1 var(--f-display); }
.keypad button:active { background: #3a372f; }
.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* tour */
.tour-ring { position: fixed; z-index: 1500; pointer-events: none; border: 3px solid var(--cobalt); box-shadow: 0 0 0 6px color-mix(in srgb, var(--cobalt) 25%, transparent); transition: all .3s cubic-bezier(.2, .8, .2, 1); animation: ringpulse 1.6s ease-in-out infinite; }
@keyframes ringpulse { 50% { box-shadow: 0 0 0 12px color-mix(in srgb, var(--cobalt) 10%, transparent); } }
.tour-card { position: fixed; z-index: 1501; width: min(360px, calc(100vw - 24px)); background: var(--bar); color: var(--bar-ink); border-radius: var(--r-l); box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 10px; animation: pop .2s cubic-bezier(.2, .8, .2, 1); }
.tour-card[data-pos="center"] { left: 50%; top: 50%; transform: translate(-50%, -50%); }
.tour-card[data-pos="corner"] { right: calc(16px + var(--sar)); bottom: calc(70px + var(--sab)); }
.tour-card[data-pos="top"] { left: 50%; transform: translateX(-50%); top: calc(64px + var(--sat)); }
.tour-card[data-pos="top-low"] { left: 50%; transform: translateX(-50%); top: calc(64px + var(--sat)); }
.tour-anim { width: 100%; height: auto; display: block; border-radius: 14px; }
.tour-text h3 { margin: 2px 0 2px; font: 700 22px/1.15 var(--f-display); letter-spacing: -.02em; }
.tour-text p { margin: 0; color: var(--bar-muted); font-size: 15px; }
.tour-step { font-size: 12px; color: var(--bar-muted); font-weight: 600; }
.tour-actions { display: flex; align-items: center; gap: 8px; }
.tour-actions .btn { background: var(--bar-2); border-color: var(--bar-2); color: var(--bar-ink); min-height: 40px; }
.tour-actions .btn.primary { background: var(--cobalt); border-color: var(--cobalt); color: #fff; }
.tour-actions .btn.ghost { background: transparent; border-color: transparent; color: var(--bar-muted); }
.tour-try { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; color: #8FA2FF; }
.tour-ok .tour-try { color: #55C98A; }
.tour-ok { box-shadow: 0 0 0 2px #55C98A, var(--shadow); }
@media (max-width: 600px) { .tour-anim-wrap { max-width: 220px; align-self: center; } .tour-card[data-pos="corner"] { left: 12px; right: 12px; width: auto; } }

/* text documents */
.tdoc { flex: 1; overflow-y: auto; background: var(--surface); }
.tdoc-in { max-width: 760px; margin: 0 auto; padding: 40px 28px 160px; }
.tdoc-title { font: 700 40px/1.05 var(--f-display); letter-spacing: -.035em; border: 0; outline: 0; width: 100%; background: transparent; padding: 0; margin-bottom: 18px; }
.tdoc-body { outline: none; font: 400 18px/1.65 Literata, Georgia, serif; min-height: 50vh; -webkit-user-select: text; user-select: text; }
.tdoc-body h1 { font: 700 30px/1.15 var(--f-display); letter-spacing: -.025em; margin: 1.2em 0 .4em; }
.tdoc-body h2 { font: 700 23px/1.2 var(--f-display); letter-spacing: -.02em; margin: 1.1em 0 .3em; }
.tdoc-body blockquote { margin: 1em 0; padding: 2px 0 2px 18px; border-left: 3px solid var(--cobalt); color: var(--ink-2); }
.tdoc-body pre, .tdoc-body code { font: 15px/1.5 "JetBrains Mono", monospace; background: var(--bg-2); border-radius: 6px; }
.tdoc-body pre { padding: 12px 14px; white-space: pre-wrap; }
.tdoc-body ul.check { list-style: none; padding-left: 4px; }
.tdoc-body ul.check li { display: flex; gap: 10px; align-items: baseline; }
.tdoc-body ul.check li::before { content: ""; width: 16px; height: 16px; border: 1.5px solid var(--muted); border-radius: 5px; flex: none; transform: translateY(2px); cursor: pointer; }
.tdoc-body ul.check li.done { color: var(--muted); text-decoration: line-through; }
.tdoc-body ul.check li.done::before { background: var(--cobalt) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="3.2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>') center/12px no-repeat; border-color: var(--cobalt); }
.tdoc-body mark { background: #FFE58F; color: inherit; border-radius: 2px; }
.tdoc-body hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.tdoc-body table { border-collapse: collapse; width: 100%; } .tdoc-body td { border: 1px solid var(--line); padding: 6px 10px; }
.fmtbar { position: absolute; left: 50%; transform: translateX(-50%); top: auto; bottom: calc(16px + var(--sab)); z-index: 25; }
.fmtbar .tb { color: var(--bar-ink); }

/* study */
.study { flex: 1; overflow-y: auto; }
.study-in { max-width: 860px; margin: 0 auto; padding: 28px 24px 140px; }
.study-stats { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 22px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: 12px 16px; min-width: 120px; }
.stat b { display: block; font: 700 28px/1 var(--f-display); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.cards-list { display: grid; gap: 10px; }
.fc-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: 10px; align-items: start; }
.fc-row img { max-width: 100%; max-height: 120px; border-radius: 6px; display: block; }
.fc-row .side-t { font-size: 15px; min-height: 44px; border: 0; background: var(--bg); border-radius: 10px; padding: 10px 12px; width: 100%; resize: vertical; outline: none; }
.flash-wrap { max-width: 620px; margin: 4vh auto 0; display: flex; flex-direction: column; gap: 18px; align-items: stretch; padding: 0 18px; }
.flash { perspective: 1400px; height: min(58vh, 420px); cursor: pointer; }
.flash-in { position: relative; width: 100%; height: 100%; transition: transform .45s cubic-bezier(.2, .8, .2, 1); transform-style: preserve-3d; }
.flash.flipped .flash-in { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px; text-align: center; font: 600 24px/1.3 var(--f-display); letter-spacing: -.01em; overflow: auto; }
.face img { max-width: 100%; max-height: 80%; border-radius: 8px; }
.face.back { transform: rotateY(180deg); }
.face small { position: absolute; top: 14px; left: 18px; font: 600 12px var(--f-body); color: var(--muted); }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grades button { min-height: 56px; border-radius: 14px; font-weight: 600; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.grades button small { font-weight: 400; color: var(--muted); font-size: 12px; }
.grades .g-again { color: var(--danger); }

:root[data-theme="dark"] .inkbar, :root[data-theme="dark"] .selmenu, :root[data-theme="dark"] .dock, :root[data-theme="dark"] .zoomwin { box-shadow: 0 0 0 1px #34312A, var(--shadow); }
.inkbar .swatch.cur { display: block; width: 28px; height: 28px; margin: 0; box-shadow: 0 0 0 2px var(--bar), 0 0 0 4px var(--bar-ink); }

/* ---------- compact: iPhone / folded Duo ---------- */
@media (max-width: 760px) {
  .side { display: none; }
  .lib-head { padding: calc(14px + var(--sat)) 18px 10px; }
  .lib-title { font-size: 34px; }
  .lib-tools, .search-box { margin-left: 0; margin-right: 0; padding-left: 18px; padding-right: 18px; }
  .search-box { margin: 0 18px 12px; padding: 0 14px; }
  .lib-scroll { padding: 6px 18px calc(110px + var(--sab)); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 24px 16px; }
  .head-actions .btn span { display: none; }
  .head-actions .btn { padding: 0 12px; }
  .tabbar { display: flex; position: absolute; left: 0; right: 0; bottom: 0; z-index: 30; background: color-mix(in srgb, var(--bg-2) 94%, transparent); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--sab)); justify-content: space-around; -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
  .tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); min-width: 56px; min-height: 48px; justify-content: center; }
  .tabbar button[aria-current="true"] { color: var(--cobalt); }
  .tabbar .mid { width: 52px; height: 52px; min-width: 52px; border-radius: 999px; background: var(--bar); color: var(--bar-ink); margin-top: -18px; box-shadow: var(--shadow); }
  .fab { display: none; }
  .tabs { display: none; }
  .ed-top .wide-only { display: none; }
  .inkbar { top: auto; bottom: calc(10px + var(--sab)); }
  .pageind { bottom: calc(76px + var(--sab)); }
  .dock { bottom: calc(76px + var(--sab)); }
  .pop.anchored-bottom { left: 10px !important; right: 10px; width: auto !important; }
  .sheet { left: 0; right: 0; top: auto; bottom: 0; transform: none; width: 100%; border-radius: var(--r-l) var(--r-l) 0 0; max-height: calc(100% - 30px - var(--sat)); animation: sheetup .22s cubic-bezier(.2, .8, .2, 1); }
  .sheet.wide { width: 100%; height: calc(100% - 30px - var(--sat)); }
  @keyframes sheetup { from { transform: translateY(40px); opacity: 0; } }
  .fc-row { grid-template-columns: 1fr; }
  .tdoc-in { padding: 24px 18px 160px; }
  .tdoc-title { font-size: 32px; }
  .zoomwin { height: 38%; }
  .fmtbar { bottom: calc(10px + var(--sab)); }
}
@media (max-width: 760px) { .toast { bottom: calc(150px + var(--sab)); } }
/* foldable: when the browser exposes two viewport segments, keep chrome off the fold */
@media (horizontal-viewport-segments: 2) {
  .inkbar { left: env(viewport-segment-left 1 0, 50%); transform: translateX(-50%); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--ink) 18%, transparent); border-radius: 99px; border: 3px solid transparent; background-clip: padding-box; }
