@layer theme, base, components, utilities;

/* Component styles. Layout utilities come from Tailwind (CDN);
   colours are semantic tokens so light/dark mode is automatic. */

@font-face {
  font-family: "Jakarta";
  src: url("fonts/plus-jakarta-sans-latin-wght-normal.woff2") format("woff2-variations");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Caveat";
  src: url("fonts/caveat-latin-wght-normal.woff2") format("woff2-variations");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --tn-bg: #f5f1e8;
  --tn-surface: #fffdf8;
  --tn-surface-2: #faf6ee;
  --tn-ink: #1d2130;
  --tn-ink-2: #474b58;
  --tn-muted: #847e70;
  --tn-line: #e8e1d2;
  --tn-line-2: #d6ccb8;
  --tn-pen: #2b45c4;
  --tn-pen-hover: #2138a6;
  --tn-pen-soft: #e7ebfb;
  --tn-on-pen: #ffffff;
  --tn-marker: #ffd84a;
  --tn-marker-soft: #fff2bd;
  --tn-marker-stroke: #ffd84a;
  --tn-ok: #1b7f50;
  --tn-ok-soft: #dcf2e5;
  --tn-warn: #a86200;
  --tn-warn-soft: #fcefd2;
  --tn-bad: #c0392b;
  --tn-bad-soft: #fbe2dd;
  --tn-shadow: 60 45 20;
  --tn-rule: rgba(43, 69, 196, 0.10);
  --tn-margin: rgba(214, 70, 70, 0.28);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tn-bg: #121210;
    --tn-surface: #1b1a17;
    --tn-surface-2: #22211d;
    --tn-ink: #eeeae0;
    --tn-ink-2: #c4bfb3;
    --tn-muted: #8f8a7e;
    --tn-line: #2f2d28;
    --tn-line-2: #3d3a33;
    --tn-pen: #93a6ff;
    --tn-pen-hover: #aebcff;
    --tn-pen-soft: #252b47;
    --tn-on-pen: #0f1220;
    --tn-marker: #e6c13b;
    --tn-marker-soft: #3a3218;
    --tn-marker-stroke: rgba(230, 193, 59, 0.42);
    --tn-ok: #52c58f;
    --tn-ok-soft: #16302a;
    --tn-warn: #e5a444;
    --tn-warn-soft: #33270f;
    --tn-bad: #f07b6b;
    --tn-bad-soft: #3a1d19;
    --tn-shadow: 0 0 0;
    --tn-rule: rgba(147, 166, 255, 0.10);
    --tn-margin: rgba(240, 123, 107, 0.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --tn-bg: #121210;
  --tn-surface: #1b1a17;
  --tn-surface-2: #22211d;
  --tn-ink: #eeeae0;
  --tn-ink-2: #c4bfb3;
  --tn-muted: #8f8a7e;
  --tn-line: #2f2d28;
  --tn-line-2: #3d3a33;
  --tn-pen: #93a6ff;
  --tn-pen-hover: #aebcff;
  --tn-pen-soft: #252b47;
  --tn-on-pen: #0f1220;
  --tn-marker: #e6c13b;
  --tn-marker-soft: #3a3218;
  --tn-marker-stroke: rgba(230, 193, 59, 0.42);
  --tn-ok: #52c58f;
  --tn-ok-soft: #16302a;
  --tn-warn: #e5a444;
  --tn-warn-soft: #33270f;
  --tn-bad: #f07b6b;
  --tn-bad-soft: #3a1d19;
  --tn-shadow: 0 0 0;
  --tn-rule: rgba(147, 166, 255, 0.10);
  --tn-margin: rgba(240, 123, 107, 0.25);
  color-scheme: dark;
}

/* ------------------------------------------------------------- base --- */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--tn-bg);
  color: var(--tn-ink);
  font-family: "Jakarta", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
::selection { background: var(--tn-marker-soft); color: var(--tn-ink); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--tn-pen); outline-offset: 2px; border-radius: 10px; }

/* Faint paper grain behind everything */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: radial-gradient(rgb(var(--tn-shadow) / 0.035) 1px, transparent 1px);
  background-size: 18px 18px;
}

@layer components {
.hand { font-family: "Caveat", "Comic Sans MS", cursive; }
.tnum { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ brand --- */
.wordmark {
  font-family: "Caveat", cursive;
  font-weight: 700;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
/* Longer app names ("Maggie's Note") get a little smaller in the phone header so the icons fit. */
@media (max-width: 420px) { .topbar .wordmark.is-long { font-size: 26px; } }
.marker {
  background: linear-gradient(100deg, transparent 0 2%, var(--tn-marker-stroke) 3% 96%, transparent 97%) no-repeat;
  background-size: 100% 42%;
  background-position: 0 88%;
  padding: 0 0.12em;
  border-radius: 2px;
}
.marker-full {
  background: linear-gradient(100deg, transparent 0 1%, var(--tn-marker-soft) 2% 97%, transparent 98%);
  padding: 0 0.2em;
  border-radius: 3px;
}

/* ------------------------------------------------------------ chrome --- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--tn-bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--tn-line) 70%, transparent);
}
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px;
  color: var(--tn-ink-2);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--tn-surface); border-color: var(--tn-line); color: var(--tn-ink); }
.worker-dot { width: 8px; height: 8px; border-radius: 99px; background: var(--tn-muted); display: inline-block; }
.worker-dot.on { background: var(--tn-ok); box-shadow: 0 0 0 3px var(--tn-ok-soft); }

.crumbs { display: flex; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none; white-space: nowrap; }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs.fade-l { -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 28px); mask-image: linear-gradient(90deg, transparent 0, #000 28px); }
.crumbs a { padding: 4px 8px; border-radius: 8px; color: var(--tn-muted); font-size: 13px; font-weight: 500; }
.crumbs a:hover { background: var(--tn-surface); color: var(--tn-ink); }
.crumbs a[aria-current] { color: var(--tn-ink); font-weight: 600; }
.crumbs svg { color: var(--tn-line-2); flex: none; }

/* ----------------------------------------------------------- buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: 12px;
  font-weight: 600; font-size: 14px; letter-spacing: .1px;
  border: 1px solid var(--tn-line); background: var(--tn-surface); color: var(--tn-ink);
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: background .15s, border-color .15s, transform .08s, box-shadow .15s, color .15s;
  box-shadow: 0 1px 0 rgb(var(--tn-shadow) / .04);
}
.btn:hover { border-color: var(--tn-line-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-busy { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--tn-pen); border-color: var(--tn-pen); color: var(--tn-on-pen); box-shadow: 0 6px 16px -8px var(--tn-pen); }
.btn-primary:hover { background: var(--tn-pen-hover); border-color: var(--tn-pen-hover); }
.btn-soft { background: var(--tn-pen-soft); border-color: transparent; color: var(--tn-pen); }
.btn-soft:hover { border-color: color-mix(in srgb, var(--tn-pen) 30%, transparent); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--tn-ink-2); }
.btn-ghost:hover { background: var(--tn-surface); border-color: var(--tn-line); }
.btn-danger { background: var(--tn-bad); border-color: var(--tn-bad); color: #fff; }
.btn-sm { height: 34px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
.btn-lg { height: 50px; padding: 0 22px; border-radius: 14px; font-size: 15px; }
.btn .spin { display: none; }
.btn.is-busy .spin { display: inline-block; }
.spin { width: 16px; height: 16px; border-radius: 99px; border: 2px solid currentColor; border-right-color: transparent; animation: tn-spin .7s linear infinite; }
@keyframes tn-spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- cards --- */
.card {
  background: var(--tn-surface);
  border: 1px solid var(--tn-line);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgb(var(--tn-shadow) / .04), 0 8px 24px -18px rgb(var(--tn-shadow) / .25);
}
.card-inset { background: var(--tn-surface-2); border: 1px solid var(--tn-line); border-radius: 14px; }
.section-title { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--tn-muted); }

/* Lined notebook paper */
.lined {
  background-color: var(--tn-surface);
  background-image:
    linear-gradient(90deg, transparent 38px, var(--tn-margin) 38px, var(--tn-margin) 39.5px, transparent 39.5px),
    repeating-linear-gradient(transparent 0 27px, var(--tn-rule) 27px 28px);
  background-position: 0 0, 0 14px;
}

/* ------------------------------------------------------ folder cards --- */
.folder-card {
  --c: #3f6fe0;
  position: relative; display: block;
  padding-top: 11px;
  transition: transform .18s cubic-bezier(.2,.8,.2,1);
  -webkit-user-select: none; user-select: none;
}
.folder-card:hover { transform: translateY(-2px); }
.folder-card:active { transform: translateY(0) scale(.99); }
.folder-card .tab {
  position: absolute; top: 0; left: 14px;
  width: 42%; height: 18px;
  background: color-mix(in srgb, var(--c) 78%, var(--tn-surface));
  border-radius: 10px 12px 0 0;
  clip-path: polygon(0 0, 82% 0, 100% 100%, 0 100%);
}
.folder-card .body {
  position: relative;
  min-height: 118px;
  border-radius: 6px 18px 18px 18px;
  padding: 16px 16px 14px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--c) 16%, var(--tn-surface)) 0%, color-mix(in srgb, var(--c) 9%, var(--tn-surface)) 100%);
  border: 1px solid color-mix(in srgb, var(--c) 26%, var(--tn-line));
  box-shadow: 0 1px 0 rgb(255 255 255 / .5) inset, 0 10px 22px -18px color-mix(in srgb, var(--c) 70%, #000);
  display: flex; flex-direction: column; justify-content: space-between; gap: 12px;
}
.folder-card .code {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .06em;
  color: color-mix(in srgb, var(--c) 80%, var(--tn-ink));
  background: color-mix(in srgb, var(--c) 16%, transparent);
  padding: 2px 7px; border-radius: 6px;
}
.folder-card .name { font-weight: 700; font-size: 15.5px; line-height: 1.25; color: var(--tn-ink); overflow-wrap: anywhere; }
.folder-card .meta { font-size: 12.5px; color: var(--tn-ink-2); opacity: .85; }
.folder-swatch { width: 12px; height: 12px; border-radius: 4px; background: var(--c); flex: none; }

/* -------------------------------------------------------- note rows --- */
.note-row {
  --c: #3f6fe0;
  position: relative; display: flex; gap: 14px; align-items: center;
  padding: 14px 14px 14px 18px;
  background: var(--tn-surface);
  border: 1px solid var(--tn-line);
  border-radius: 16px;
  transition: border-color .15s, transform .15s, box-shadow .15s;
  overflow: hidden;
}
.note-row::before {
  content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--c);
}
.note-row:hover { border-color: var(--tn-line-2); box-shadow: 0 8px 22px -16px rgb(var(--tn-shadow) / .4); }
.note-row > .flex-none { align-self: flex-start; }
.note-row .title { font-weight: 650; font-size: 15px; line-height: 1.3; overflow-wrap: anywhere; }
.note-row .meta { font-size: 12.5px; color: var(--tn-muted); }
.src-icons { display: inline-flex; gap: 8px; color: var(--tn-muted); font-size: 12px; align-items: center; }
.src-icons span { display: inline-flex; align-items: center; gap: 3px; }
.src-icons .on { color: var(--tn-ink-2); }

/* ------------------------------------------------------------- pills --- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px; border-radius: 99px;
  font-size: 12px; font-weight: 650; white-space: nowrap;
  background: var(--tn-surface-2); color: var(--tn-ink-2); border: 1px solid var(--tn-line);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 99px; background: currentColor; opacity: .9; }
.pill-draft { color: var(--tn-muted); }
.pill-queued { color: var(--tn-warn); background: var(--tn-warn-soft); border-color: transparent; }
.pill-processing { color: var(--tn-pen); background: var(--tn-pen-soft); border-color: transparent; }
.pill-processing::before { animation: tn-pulse 1.2s ease-in-out infinite; }
.pill-ready { color: var(--tn-ok); background: var(--tn-ok-soft); border-color: transparent; }
.pill-failed { color: var(--tn-bad); background: var(--tn-bad-soft); border-color: transparent; }
.pill-processed { color: #0f7d74; background: color-mix(in srgb, #159a8c 14%, var(--tn-surface)); border-color: transparent; }
:root[data-theme="dark"] .pill-processed { color: #5fd3c6; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill-processed { color: #5fd3c6; } }
@keyframes tn-pulse { 50% { opacity: .25; } }

/* ------------------------------------------------------------- forms --- */
.field { display: block; }
.field > .label { display: block; font-size: 13px; font-weight: 650; margin-bottom: 6px; color: var(--tn-ink); }
.field > .help { display: block; font-size: 12.5px; color: var(--tn-muted); margin-top: 6px; }
.input, .textarea, .select {
  width: 100%; box-sizing: border-box;
  background: var(--tn-surface); color: var(--tn-ink);
  border: 1px solid var(--tn-line-2); border-radius: 12px;
  padding: 11px 13px; font: inherit; font-size: 16px; /* 16px stops iOS zoom */
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--tn-muted); opacity: .8; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--tn-pen); box-shadow: 0 0 0 4px var(--tn-pen-soft); }
.select { appearance: none; -webkit-appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23847e70' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatches label { position: relative; cursor: pointer; }
.swatches input { position: absolute; opacity: 0; pointer-events: none; }
.swatches span {
  display: block; width: 32px; height: 32px; border-radius: 10px; background: var(--c);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / .08);
  transition: transform .12s;
}
.swatches input:checked + span { box-shadow: 0 0 0 2px var(--tn-surface), 0 0 0 4px var(--c); transform: scale(1.04); }
.swatches input:focus-visible + span { outline: 2px solid var(--tn-pen); outline-offset: 4px; }

.alert { border-radius: 12px; padding: 11px 13px; font-size: 14px; border: 1px solid transparent; }
.alert-bad { background: var(--tn-bad-soft); color: var(--tn-bad); }
.alert-ok { background: var(--tn-ok-soft); color: var(--tn-ok); }
.alert-warn { background: var(--tn-warn-soft); color: var(--tn-warn); }
.alert-info { background: var(--tn-pen-soft); color: var(--tn-pen); }

/* ------------------------------------------- sheets (native <dialog>) --- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; max-width: 100%; width: 100%;
  max-height: 92dvh;
  background: var(--tn-surface); color: var(--tn-ink);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -20px 60px -20px rgb(0 0 0 / .35);
  overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: tn-sheet-up .28s cubic-bezier(.2,.9,.25,1); }
dialog.sheet::backdrop { background: rgb(18 16 12 / .42); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: tn-fade .2s ease; }
dialog.sheet .sheet-head { padding: 10px 20px 12px; border-bottom: 1px solid var(--tn-line); position: relative; }
dialog.sheet .sheet-head::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 9px; background: var(--tn-line-2); margin: 0 auto 12px; }
dialog.sheet .sheet-body { padding: 18px 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
dialog.sheet .sheet-foot { padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--tn-line); display: flex; gap: 10px; justify-content: flex-end; background: var(--tn-surface-2); }
@media (min-width: 640px) {
  dialog.sheet { margin: auto; width: min(560px, calc(100% - 32px)); border-radius: 22px; max-height: 86dvh; box-shadow: 0 30px 80px -30px rgb(0 0 0 / .45); }
  dialog.sheet[open] { animation: tn-pop .22s cubic-bezier(.2,.9,.25,1); }
  dialog.sheet .sheet-head::before { display: none; }
  dialog.sheet .sheet-head { padding-top: 18px; }
}
@keyframes tn-sheet-up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes tn-pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tn-fade { from { opacity: 0; } }

dialog.sheet.sheet-tall { height: 92dvh; }
dialog.sheet.sheet-tall .sheet-body { flex: 1 1 auto; min-height: 0; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
[data-ex-search] { padding-right: 84px !important; }
@media (min-width: 640px) { dialog.sheet.sheet-tall { width: min(760px, calc(100% - 32px)); height: 86dvh; } }

/* Transcript / extracted text viewer */
.ex-block { display: grid; grid-template-columns: 58px 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--tn-line); font-size: 15px; line-height: 1.6; }
.ex-block:last-child { border-bottom: 0; }
.ex-ts { align-self: start; font-size: 12px; font-weight: 700; color: var(--tn-pen); background: var(--tn-pen-soft); border: 0; border-radius: 8px; padding: 3px 0; cursor: pointer; font-variant-numeric: tabular-nums; text-align: center; margin-top: 2px; }
.ex-ts:hover { filter: brightness(.96); }
.ex-ts.static { cursor: default; color: var(--tn-muted); background: var(--tn-surface-2); }
.ex-page { padding: 14px 0; border-bottom: 1px solid var(--tn-line); }
.ex-page:last-child { border-bottom: 0; }
.ex-page h4 { font-size: 13px; font-weight: 700; color: var(--tn-muted); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 4px; display: flex; gap: 8px; align-items: center; }
.ex-page .ptitle { font-weight: 700; font-size: 16px; margin-bottom: 6px; }
.ex-page .ptext { white-space: pre-wrap; font-size: 14.5px; line-height: 1.6; overflow-wrap: anywhere; }
.ex-page .pnotes { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--tn-marker-soft); font-size: 14px; white-space: pre-wrap; }
.ex-page .pnotes b { display: block; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 2px; }
.tag { display: inline-flex; align-items: center; height: 19px; padding: 0 7px; border-radius: 6px; font-size: 10.5px; font-weight: 800; letter-spacing: .05em; background: var(--tn-warn-soft); color: var(--tn-warn); }
mark { background: var(--tn-marker); color: #1d2130; border-radius: 3px; padding: 0 1px; }
.ex-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.ex-row .fname { font-size: 14px; }
.file-done { color: var(--tn-ok); font-weight: 650; }

/* ------------------------------------------------------ the notes --- */
.notes-paper { padding: 22px 18px 28px; }
@media (min-width: 640px) { .notes-paper { padding: 34px 40px 40px; } }
.notes-title { font-size: 26px; line-height: 1.15; font-weight: 800; letter-spacing: -.01em; margin: 0; overflow-wrap: anywhere; }
.notes-meta { font-size: 13px; color: var(--tn-muted); margin: 6px 0 4px; padding-bottom: 14px; border-bottom: 2px solid var(--tn-line); }
.notes { font-size: 15.5px; line-height: 1.72; color: var(--tn-ink); overflow-wrap: break-word; }
.notes > :first-child { margin-top: 18px; }
.notes h2 { font-size: 21px; line-height: 1.35; font-weight: 800; margin: 34px 0 10px; scroll-margin-top: 84px; }
.notes h2 > span { background: linear-gradient(transparent 58%, var(--tn-marker-soft) 58%); padding: 0 4px; margin-left: -4px;
  -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.notes h3 { font-size: 17px; font-weight: 750; margin: 22px 0 6px; color: var(--tn-ink); scroll-margin-top: 84px; }
.notes h4, .notes h5, .notes h6 { font-size: 15.5px; font-weight: 700; margin: 16px 0 4px; }
.notes p { margin: 8px 0; }
.notes ul, .notes ol { margin: 8px 0; padding-left: 22px; }
.notes ul { list-style: none; }
.notes ul > li { position: relative; }
.notes ul > li::before { content: ""; position: absolute; left: -15px; top: .72em; width: 6px; height: 6px; border-radius: 99px; background: var(--tn-pen); }
.notes ul ul > li::before { background: transparent; border: 1.5px solid var(--tn-pen); width: 5px; height: 5px; }
.notes ol { list-style: decimal; }
.notes ol ol { list-style: lower-alpha; }
.notes ol > li { padding-left: 2px; }
.notes ol > li::marker { color: var(--tn-pen); font-weight: 700; }
.notes li { margin: 3px 0; }
.notes strong { font-weight: 750; }
.notes mark { background: linear-gradient(100deg, transparent 0 1%, var(--tn-marker) 2% 98%, transparent 99%); color: inherit; padding: 0 .12em; border-radius: 3px; }
:root[data-theme="dark"] .notes mark { background: var(--tn-marker-soft); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .notes mark { background: var(--tn-marker-soft); } }
.notes code { font-family: ui-monospace, Menlo, monospace; font-size: .88em; background: var(--tn-surface-2); padding: 1px 5px; border-radius: 5px; }
.notes hr { border: 0; border-top: 2px dashed var(--tn-line); margin: 26px 0; }
.notes blockquote { margin: 12px 0; padding: 4px 14px; border-left: 3px solid var(--tn-line-2); color: var(--tn-ink-2); }
.notes .table-wrap { overflow-x: auto; margin: 12px 0; border: 1px solid var(--tn-line); border-radius: 12px; }
.notes table { border-collapse: collapse; width: 100%; font-size: 14px; line-height: 1.45; }
.notes th { background: var(--tn-surface-2); text-align: left; font-weight: 700; }
.notes th, .notes td { padding: 8px 10px; border-bottom: 1px solid var(--tn-line); vertical-align: top; }
.notes tr:last-child td { border-bottom: 0; }
.notes td + td, .notes th + th { border-left: 1px solid var(--tn-line); }
.notes .callout { --cc: #667085; margin: 14px 0; padding: 10px 14px 10px 14px; border-radius: 14px;
  background: color-mix(in srgb, var(--cc) 9%, var(--tn-surface)); border: 1px solid color-mix(in srgb, var(--cc) 28%, var(--tn-line)); border-left-width: 4px; }
.notes .callout > :last-child { margin-bottom: 2px; }
.notes .callout-label { font-size: 11.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: color-mix(in srgb, var(--cc) 85%, var(--tn-ink)); margin-bottom: 2px; }
.notes .callout-highyield { --cc: #d69e00; background: color-mix(in srgb, var(--tn-marker) 22%, var(--tn-surface)); }
.notes .callout-clinical { --cc: #159a8c; }
.notes .callout-example { --cc: #3f6fe0; }
.notes .callout-mnemonic { --cc: #8260d8; }
.notes .callout-note { --cc: #667085; }
.notes .callout-warning { --cc: #da4b42; }
.notes .callout-summary { --cc: var(--tn-pen); }
.notes .callout-definition { --cc: #3e9b4f; }
.notes .callout-quiz { --cc: #ea7a2e; }
.notes .callout-tip { --cc: #159a8c; }
.toc { display: grid; gap: 2px; }
.toc a { display: block; padding: 6px 8px; border-radius: 8px; font-size: 13.5px; color: var(--tn-ink-2); line-height: 1.35; }
.toc a:hover { background: var(--tn-surface-2); color: var(--tn-ink); }

/* Action menu items inside sheets */
.menu-item {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 13px 12px; border-radius: 12px; border: 0; background: transparent;
  text-align: left; cursor: pointer; font-size: 15px; font-weight: 550;
}
.menu-item:hover { background: var(--tn-surface-2); }
.menu-item .mi-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--tn-surface-2); border: 1px solid var(--tn-line); color: var(--tn-ink-2); flex: none; }
.menu-item.danger { color: var(--tn-bad); }
.menu-item.danger .mi-icon { color: var(--tn-bad); background: var(--tn-bad-soft); border-color: transparent; }
.menu-item small { display: block; font-size: 12.5px; color: var(--tn-muted); font-weight: 450; }

/* Folder picker tree */
.tree-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 10px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; text-align: left; font-size: 14.5px; }
.tree-item:hover:not([disabled]) { background: var(--tn-surface-2); }
.tree-item[aria-selected="true"] { background: var(--tn-pen-soft); color: var(--tn-pen); font-weight: 650; }
.tree-item[disabled] { opacity: .38; cursor: not-allowed; }

/* ------------------------------------------------------------- toast --- */
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(18px + env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 8px; z-index: 80; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; max-width: 440px;
  background: var(--tn-ink); color: var(--tn-bg);
  padding: 11px 16px; border-radius: 14px; font-size: 14px; font-weight: 550;
  box-shadow: 0 16px 40px -14px rgb(0 0 0 / .5);
  display: flex; gap: 10px; align-items: center;
  animation: tn-pop .2s ease;
}
.toast.bad { background: var(--tn-bad); color: #fff; }

/* --------------------------------------------------------------- FAB --- */
.fab {
  position: fixed; right: 18px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 40;
  width: 58px; height: 58px; border-radius: 20px; border: 0;
  background: var(--tn-pen); color: var(--tn-on-pen);
  display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 14px 30px -10px var(--tn-pen), 0 2px 6px rgb(0 0 0 / .15);
  transition: transform .15s;
}
.fab:active { transform: scale(.94); }
@media (min-width: 768px) { .fab { display: none; } }

/* ------------------------------------------------------- uploads etc --- */
.dropzone {
  border: 1.5px dashed var(--tn-line-2); border-radius: 16px;
  background: var(--tn-surface-2);
  transition: border-color .15s, background .15s;
}
.dropzone.is-over { border-color: var(--tn-pen); background: var(--tn-pen-soft); }
.file-row { display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 10px; border-radius: 12px; background: var(--tn-surface); border: 1px solid var(--tn-line); }
.file-row .icon-btn { width: 34px; height: 34px; border-radius: 10px; }
.file-row .fname { font-weight: 600; font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.file-badge { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; font-size: 10.5px; font-weight: 800; letter-spacing: .04em; flex: none; text-transform: uppercase; }
.file-badge.recording { background: color-mix(in srgb, #d6589a 16%, var(--tn-surface)); color: #b8407e; }
.file-badge.slides { background: color-mix(in srgb, #ea7a2e 16%, var(--tn-surface)); color: #c75f17; }
.file-badge.document { background: color-mix(in srgb, #3f6fe0 14%, var(--tn-surface)); color: #2f5bc6; }
:root[data-theme="dark"] .file-badge.recording { color: #f08cbf; }
:root[data-theme="dark"] .file-badge.slides { color: #f5a36a; }
:root[data-theme="dark"] .file-badge.document { color: #93a6ff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .file-badge.recording { color: #f08cbf; }
  :root:not([data-theme="light"]) .file-badge.slides { color: #f5a36a; }
  :root:not([data-theme="light"]) .file-badge.document { color: #93a6ff; }
}
.bar { height: 6px; border-radius: 99px; background: var(--tn-line); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--tn-pen); transition: width .3s ease; }
.bar.ok > i { background: var(--tn-ok); }
.bar.bad > i { background: var(--tn-bad); }
.bar.indeterminate > i { width: 35% !important; animation: tn-indet 1.3s ease-in-out infinite; }
@keyframes tn-indet { 0% { transform: translateX(-110%); } 100% { transform: translateX(300%); } }
audio { width: 100%; height: 40px; }

/* Pipeline stepper */
.steps { display: grid; gap: 2px; }
.step { display: flex; align-items: center; gap: 12px; padding: 7px 0; font-size: 14px; color: var(--tn-muted); }
.step .dot { width: 22px; height: 22px; border-radius: 99px; border: 1.5px solid var(--tn-line-2); display: grid; place-items: center; flex: none; background: var(--tn-surface); }
.step.done { color: var(--tn-ink-2); }
.step.done .dot { background: var(--tn-ok); border-color: var(--tn-ok); color: #fff; }
.step.active { color: var(--tn-ink); font-weight: 650; }
.step.active .dot { border-color: var(--tn-pen); box-shadow: 0 0 0 4px var(--tn-pen-soft); }
.step.active .dot::after { content: ""; width: 8px; height: 8px; border-radius: 99px; background: var(--tn-pen); animation: tn-pulse 1.2s ease-in-out infinite; }
.step.failed .dot { background: var(--tn-bad); border-color: var(--tn-bad); color: #fff; }

.log { font-size: 12.5px; line-height: 1.55; max-height: 220px; overflow-y: auto; }
.log .ev { display: grid; grid-template-columns: 64px 1fr; gap: 8px; padding: 3px 0; }
.log .ev time { color: var(--tn-muted); font-variant-numeric: tabular-nums; }
.log .ev.warn { color: var(--tn-warn); }
.log .ev.error { color: var(--tn-bad); }
.log .ev.success { color: var(--tn-ok); font-weight: 600; }

/* Context inheritance list */
.ctx-row { display: grid; grid-template-columns: 1fr; gap: 2px; padding: 10px 0; border-bottom: 1px dashed var(--tn-line); }
.ctx-row:last-child { border-bottom: 0; }
.ctx-row dt { font-size: 12px; font-weight: 650; color: var(--tn-muted); text-transform: uppercase; letter-spacing: .06em; }
.ctx-row dd { margin: 0; font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.ctx-from { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--tn-muted); font-weight: 500; }
.ctx-empty { color: var(--tn-muted); font-style: italic; }

/* Collapsible cards */
details.fold > summary { list-style: none; cursor: pointer; -webkit-user-select: none; user-select: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary .chev { transition: transform .2s; color: var(--tn-muted); }
details.fold[open] > summary .chev { transform: rotate(180deg); }

/* Empty states */
.empty { text-align: center; padding: 36px 20px; }
.empty .hand { font-size: 26px; color: var(--tn-ink-2); line-height: 1.1; }

/* Code/token display */
.token { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; background: var(--tn-surface-2); border: 1px solid var(--tn-line); border-radius: 10px; padding: 10px 12px; }
} /* end components */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ------------------------------------------------- handwritten view (Phase 4) --- */
@layer components {
  .seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--tn-surface-2); border: 1px solid var(--tn-line); }
  .seg button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 9px; font-size: 13.5px; font-weight: 650;
    color: var(--tn-ink-2); transition: background .15s, color .15s, box-shadow .15s; }
  .seg button[aria-selected="true"] { background: var(--tn-surface); color: var(--tn-ink); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--tn-line); }

  .pdf-bar { padding: 12px 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
  .pdf-bar .pdf-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none;
    background: color-mix(in srgb, #d63b3b 12%, var(--tn-surface)); color: #c43535; }
  .pdf-bar .pdf-ico.muted { background: var(--tn-surface-2); color: var(--tn-muted); }
  .pdf-bar .pdf-text { min-width: 0; flex: 1 1 180px; }
  .pdf-bar .pdf-title { font-weight: 700; font-size: 14.5px; line-height: 1.3; }
  .pdf-bar .pdf-sub { font-size: 12.5px; color: var(--tn-muted); line-height: 1.35; overflow-wrap: anywhere; }
  .pdf-bar .pdf-actions { display: flex; gap: 6px; flex-wrap: wrap; }
  .pdf-bar .bar { margin-top: 6px; }

  .hw-frame-wrap { position: relative; margin: 0 -16px; background: #fffcf1; min-height: 320px; }
  @media (min-width: 640px) { .hw-frame-wrap { margin: 0; border-radius: 18px; overflow: hidden; border: 1px solid var(--tn-line);
    box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 18px 40px -26px rgba(40,30,10,.45); } }
  .hw-frame { display: block; width: 100%; border: 0; height: 70vh; background: transparent; }
  .hw-frame-loading { position: absolute; inset: 0; display: flex; align-items: flex-start; justify-content: center; gap: 10px; padding-top: 70px;
    font: 500 14px/1.4 inherit; color: #6b6557; pointer-events: none; }
  .hw-frame-loading[hidden] { display: none; }

  .look { position: relative; cursor: pointer; display: block; }
  .look input { position: absolute; opacity: 0; pointer-events: none; }
  .look-card { display: block; border-radius: 14px; border: 1.5px solid var(--tn-line); overflow: hidden; background: var(--tn-surface);
    transition: border-color .15s, box-shadow .15s; }
  .look input:checked + .look-card { border-color: var(--tn-pen); box-shadow: 0 0 0 3px var(--tn-pen-soft); }
  .look input:focus-visible + .look-card { outline: 2px solid var(--tn-pen); outline-offset: 2px; }
  .look-name { display: block; padding: 7px 10px; font-size: 13px; font-weight: 650; color: var(--tn-ink); border-top: 1px solid var(--tn-line); }
  .hw-mini { display: block; height: 76px; padding: 12px 12px 0; background-color: var(--paper); color: var(--ink); line-height: 26px; font-size: 16px; overflow: hidden; }
  .hw-mini b { display: block; font-weight: 700; white-space: nowrap; }
  .hw-mini i { font-style: normal; background: linear-gradient(transparent 20%, color-mix(in srgb, var(--hl) 85%, transparent) 20% 85%, transparent 85%); padding: 0 3px; }
  .hw-mini > span { display: block; font-size: 14px; opacity: .8; white-space: nowrap; }
  .paper-ruled { background-image: repeating-linear-gradient(to bottom, transparent 0 25px, #bdd0e8 25px 26px); background-position: 0 12px; }
  .paper-dotted { background-image: radial-gradient(circle, #b6b5ad 0 1px, transparent 1.4px); background-size: 13px 13px; }
  .paper-grid { background-image: linear-gradient(#cfdfd0 1px, transparent 1px), linear-gradient(90deg, #cfdfd0 1px, transparent 1px); background-size: 13px 13px; }

  .chips { display: flex; flex-wrap: wrap; gap: 6px; }
  .chip-opt { position: relative; cursor: pointer; }
  .chip-opt input { position: absolute; opacity: 0; pointer-events: none; }
  .chip-opt > span { display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 5px 13px; border-radius: 999px; border: 1.5px solid var(--tn-line);
    background: var(--tn-surface); font-size: 13.5px; font-weight: 600; color: var(--tn-ink-2); transition: border-color .15s, background .15s; }
  .chip-opt input:checked + span { border-color: var(--tn-pen); background: var(--tn-pen-soft); color: var(--tn-ink); }
  .chip-opt input:focus-visible + span { outline: 2px solid var(--tn-pen); outline-offset: 2px; }
  .paper-dot, .tone-dot { display: inline-block; width: 16px; height: 16px; border-radius: 5px; border: 1px solid var(--tn-line-2); background-color: #fffcf1; }
  .paper-dot.paper-ruled { background-size: auto; background-image: repeating-linear-gradient(to bottom, transparent 0 4px, #9fb9dc 4px 5px); background-position: 0 0; }
  .paper-dot.paper-dotted { background-size: 5px 5px; background-image: radial-gradient(circle, #8f8e87 0 .8px, transparent 1.1px); }
  .paper-dot.paper-grid { background-size: 5px 5px; }
}

/* The style picker leaves the page visible, so changes can be seen as they happen. */
dialog.sheet.sheet-preview { max-height: 58dvh; }
dialog.sheet.sheet-preview::backdrop { background: rgb(18 16 12 / .1); -webkit-backdrop-filter: none; backdrop-filter: none; }
@media (min-width: 1024px) {
  dialog.sheet.sheet-preview { margin: auto 24px auto auto; width: 420px; max-height: calc(100dvh - 48px); }
}

/* ------------------------------------------------------ search (Phase 5) --- */
@layer components {
  .search-hit { align-items: flex-start; }
  .snippet { display: block; margin-top: 6px; font-size: 13.5px; line-height: 1.5; color: var(--tn-ink-2); overflow-wrap: anywhere; }
  .snippet mark, .search-hit .title mark { background: var(--tn-marker-soft); color: inherit; border-radius: 3px; padding: 0 2px; box-shadow: inset 0 -2px 0 var(--tn-marker); }
  .chip-link { --c: var(--tn-pen); display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--tn-line);
    background: var(--tn-surface); font-size: 13px; font-weight: 600; color: var(--tn-ink-2); max-width: 100%; }
  .chip-link svg { color: var(--c); flex: none; }
  .chip-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mat-hit { display: grid; grid-template-columns: 58px 1fr; gap: 8px; padding: 7px 8px; border-radius: 10px; }
  .mat-hit:hover { background: var(--tn-surface-2); }
  .mat-at { font-size: 12px; font-weight: 700; color: var(--tn-pen); padding-top: 2px; font-variant-numeric: tabular-nums; }
  .due-badge { position: absolute; top: 3px; right: 1px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 99px; background: var(--tn-bad);
    color: #fff; font-size: 10.5px; font-weight: 800; line-height: 17px; text-align: center; box-shadow: 0 0 0 2px var(--tn-bg); }
}
@layer components {
  .find-bar { position: sticky; top: 72px; z-index: 15; display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 12px; margin-bottom: 10px;
    border-radius: 14px; background: var(--tn-surface); border: 1px solid var(--tn-line); box-shadow: 0 8px 24px -16px rgb(var(--tn-shadow) / .45); font-size: 13.5px; }
  .notes mark.find-hit { background: color-mix(in srgb, #ff9f1c 35%, transparent); border-radius: 3px; }
  .notes mark.find-hit.current { background: #ff9f1c; color: #1b1300; }
}

/* ------------------------------------------- figures & flow charts (Phase 5) --- */
@layer components {
  .notes figure.fig { margin: 18px 0; text-align: center; }
  .notes figure.fig img { display: inline-block; max-width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--tn-line); background: #fff; }
  .notes figure.fig figcaption { font-size: 13.5px; color: var(--tn-ink-2); margin-top: 6px; line-height: 1.45; }
  .notes figure.fig .fig-src { display: block; font-size: 11.5px; color: var(--tn-muted); margin-top: 2px; }
  .notes .fig-missing { color: var(--tn-muted); font-style: italic; }
  .notes .flow { margin: 16px 0; padding: 14px; border-radius: 14px; background: var(--tn-surface-2); border: 1px solid var(--tn-line); }
  .notes .flow-title { font-size: 11.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--tn-pen); margin-bottom: 10px; text-align: center; }
  .notes ol.flow-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 24px; }
  .notes ol.flow-steps > li { position: relative; margin: 0; padding: 7px 14px; max-width: 94%; text-align: center; font-weight: 560; line-height: 1.4;
    background: var(--tn-surface); border: 1.5px solid color-mix(in srgb, var(--tn-pen) 45%, var(--tn-line)); border-radius: 11px; }
  .notes ol.flow-steps > li::marker { content: none; }
  .notes ol.flow-steps > li + li::before { content: ""; position: absolute; left: 50%; top: -21px; width: 2px; height: 13px; background: var(--tn-pen); transform: translateX(-50%); }
  .notes ol.flow-steps > li + li::after { content: ""; position: absolute; left: 50%; top: -10px; transform: translateX(-50%);
    border: 5px solid transparent; border-top: 6px solid var(--tn-pen); }
}

/* ------------------------------------------------ editing & flashcards (Phase 5) --- */
@layer components {
  .ed-toolbar { display: flex; gap: 4px; padding: 8px 14px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--tn-line);
    background: var(--tn-surface-2); flex: none; }
  .ed-toolbar::-webkit-scrollbar { display: none; }
  .ed-toolbar[hidden] { display: none; }
  .ed-toolbar button { flex: none; min-width: 34px; height: 34px; padding: 0 9px; border-radius: 9px; border: 1px solid transparent;
    display: inline-grid; place-items: center; font-size: 13.5px; font-weight: 650; color: var(--tn-ink-2); white-space: nowrap; }
  .ed-toolbar button:hover { background: var(--tn-surface); border-color: var(--tn-line); color: var(--tn-ink); }
  .ed-toolbar button:active { transform: translateY(1px); }
  .ed-toolbar .sym { min-width: 30px; padding: 0 4px; font-size: 15px; font-weight: 500; }
  .ed-hl { background: linear-gradient(transparent 18%, var(--tn-marker) 18% 88%, transparent 88%); padding: 0 3px; color: var(--tn-ink); }
  .ed-boxes { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 10px; border-bottom: 1px solid var(--tn-line); background: var(--tn-surface-2); flex: none; }
  .ed-boxes[hidden] { display: none; }
  .ed-boxes button { height: 30px; padding: 0 11px; border-radius: 99px; border: 1px solid var(--tn-line); background: var(--tn-surface);
    font-size: 12.5px; font-weight: 650; color: var(--tn-ink-2); }
  .ed-boxes button:hover { border-color: var(--tn-pen); color: var(--tn-pen); }
  .ed-ai { padding: 12px 16px; border-bottom: 1px solid var(--tn-line); background: color-mix(in srgb, var(--tn-pen-soft) 55%, var(--tn-surface)); flex: none; }
  .ed-ai[hidden] { display: none; }
  .ed-ai-status { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; padding: 8px 11px; border-radius: 10px;
    font-size: 13px; line-height: 1.4; background: var(--tn-surface); border: 1px solid var(--tn-line); color: var(--tn-ink-2); }
  .ed-ai-status[hidden] { display: none; }
  .ed-ai-status.ok { background: var(--tn-ok-soft); border-color: transparent; color: var(--tn-ok); }
  .ed-ai-status.bad { background: var(--tn-bad-soft); border-color: transparent; color: var(--tn-bad); }
  .ed-ai-status.warn { background: var(--tn-warn-soft); border-color: transparent; color: var(--tn-warn); }
  .chip-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 5px 13px; border-radius: 999px; border: 1.5px solid var(--tn-line);
    background: var(--tn-surface); font-size: 13px; font-weight: 600; color: var(--tn-ink-2); transition: border-color .15s, color .15s; }
  .chip-btn:hover { border-color: var(--tn-pen); color: var(--tn-pen); }
  .chip-btn:active { transform: translateY(1px); }
  /* 16px stops phones zooming in when the box gets focus */
  .ed-text { flex: 1 1 auto; min-height: 0; width: 100%; resize: none; border: 0; outline: none; background: var(--tn-surface); color: var(--tn-ink);
    padding: 14px 18px 40px; font: 400 16px/1.62 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 2; }
  @media (min-width: 640px) { .ed-text { font-size: 14px; padding: 16px 22px 40px; } }
  .ed-text[hidden], .ed-preview[hidden] { display: none; }
  .ed-preview { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 2px 20px 32px; }
  .ed-preview > :first-child { margin-top: 12px; }
  .notes h2 .h2-edit { display: inline-grid; place-items: center; width: 30px; height: 30px; margin: -4px 0 0 6px; vertical-align: middle; border-radius: 9px;
    color: var(--tn-muted); opacity: .55; transition: opacity .15s, background .15s, color .15s; }
  .notes h2 .h2-edit:hover, .notes h2 .h2-edit:focus-visible { opacity: 1; background: var(--tn-surface-2); color: var(--tn-pen); }
  @media (hover: hover) { .notes h2 .h2-edit { opacity: 0; } .notes h2:hover .h2-edit, .notes h2 .h2-edit:focus-visible { opacity: 1; } }
  @media print { .h2-edit { display: none !important; } }

  .card-row { display: flex; gap: 10px; padding: 12px 10px 12px 14px; margin: 8px 0; border-radius: 14px; border: 1px solid var(--tn-line); background: var(--tn-surface); }
  .card-row.is-off { opacity: .5; }
  .card-row.is-off .cr-front { text-decoration: line-through; text-decoration-color: var(--tn-muted); }
  .cr-front { font-weight: 650; font-size: 14.5px; line-height: 1.4; overflow-wrap: anywhere; }
  .cr-back { margin-top: 4px; font-size: 13.5px; line-height: 1.45; color: var(--tn-ink-2); overflow-wrap: anywhere; }
  .cr-front mark, .cr-back mark { background: var(--tn-marker-soft); color: inherit; border-radius: 3px; padding: 0 2px; }
  .cr-meta { margin-top: 6px; font-size: 11.5px; color: var(--tn-muted); font-weight: 600; letter-spacing: .01em; }
}

/* ------------------------------------------------------------- study (Phase 5) --- */
@layer components {
  .study-hero { background: linear-gradient(135deg, var(--tn-surface) 0 60%, color-mix(in srgb, var(--tn-pen-soft) 70%, var(--tn-surface)) 100%); }
  .study-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--tn-line); }
  .study-stats > div { text-align: center; }
  .study-stats b { display: block; font-size: 20px; font-weight: 800; line-height: 1.1; }
  .study-stats span { display: block; font-size: 12px; color: var(--tn-muted); margin-top: 2px; }

  .study-page main.study { padding-bottom: calc(170px + env(safe-area-inset-bottom)); }
  .study-counts { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
  .study-counts > span { padding: 1px 2px; border-bottom: 2px solid transparent; }
  .study-counts .c-due { color: var(--tn-pen); }
  .study-counts .c-again { color: var(--tn-bad); }
  .study-counts .c-new { color: var(--tn-ok); }
  .study-counts .is-cur { border-bottom-color: currentColor; }
  .study-stage { margin-top: 18px; }

  .flash { position: relative; display: flex; flex-direction: column; min-height: min(52vh, 460px); padding: 46px 22px 22px 22px; border-radius: 18px; cursor: pointer;
    background-color: var(--tn-surface); border: 1px solid var(--tn-line);
    background-image: linear-gradient(to bottom, transparent 34px, var(--tn-margin) 34px 35.5px, transparent 35.5px),
      repeating-linear-gradient(to bottom, transparent 0 29px, var(--tn-rule) 29px 30px);
    background-position: 0 0, 0 36px; background-repeat: no-repeat;
    box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 22px 44px -28px rgb(var(--tn-shadow) / .55);
    animation: tn-card-in .26s cubic-bezier(.2,.9,.25,1); outline: none; }
  .flash:focus-visible { box-shadow: 0 0 0 3px var(--tn-pen-soft), 0 22px 44px -28px rgb(var(--tn-shadow) / .55); }
  .flash.is-open { cursor: default; }
  @keyframes tn-card-in { from { transform: translateY(10px) scale(.985); opacity: 0; } to { transform: none; opacity: 1; } }
  .flash-tag { position: absolute; top: 9px; left: 22px; right: 22px; display: flex; gap: 8px; align-items: center; font-size: 11.5px; font-weight: 700; color: var(--tn-muted); min-width: 0; }
  .flash-tag > span:first-child { flex: none; padding: 1px 8px; border-radius: 99px; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; }
  .flash-tag .k-due { background: var(--tn-pen-soft); color: var(--tn-pen); }
  .flash-tag .k-new { background: var(--tn-ok-soft); color: var(--tn-ok); }
  .flash-tag .k-again { background: var(--tn-bad-soft); color: var(--tn-bad); }
  .flash-front { font-size: 21px; line-height: 1.45; font-weight: 700; overflow-wrap: anywhere; margin: auto 0; padding: 14px 0; text-align: center; }
  .flash.is-open .flash-front { margin: 0; font-size: 18px; text-align: left; padding: 6px 0 12px; }
  .flash-answer { border-top: 2px dashed var(--tn-line-2); padding-top: 14px; animation: tn-fade .25s ease; }
  .flash-back { font-size: 17.5px; line-height: 1.6; overflow-wrap: anywhere; }
  .flash-front mark, .flash-back mark { background: linear-gradient(100deg, transparent 0 1%, var(--tn-marker) 2% 98%, transparent 99%); color: inherit; padding: 0 .12em; border-radius: 3px; }
  .flash-front strong, .flash-back strong { font-weight: 780; }
  .flash-hint { text-align: center; font-size: 12.5px; color: var(--tn-muted); margin-top: auto; padding-top: 10px; }
  .cloze-gap { display: inline-block; min-width: 3.2em; border-bottom: 2.5px solid var(--tn-pen); color: var(--tn-pen); padding: 0 4px; line-height: 1.2; }
  .cloze-ans { color: var(--tn-pen); border-bottom: 2.5px solid var(--tn-pen); padding: 0 3px; background: var(--tn-pen-soft); border-radius: 4px 4px 0 0; }
  .flash-src { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 12px; font-size: 12.5px; color: var(--tn-muted); font-weight: 600; min-width: 0; }
  .flash-src span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .flash-src:hover { color: var(--tn-ink); }

  .study-dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--tn-bg) 88%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-top: 1px solid var(--tn-line); }
  .study-dock[hidden], .rate-row[hidden], .study-dock .btn[hidden] { display: none; }
  .rate-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .rate { --rc: var(--tn-ink-2); --rs: var(--tn-surface-2); position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    height: 58px; border-radius: 14px; background: var(--rs); color: var(--rc); border: 1px solid color-mix(in srgb, var(--rc) 22%, transparent);
    transition: transform .08s, filter .15s; }
  .rate:hover { filter: brightness(.97); }
  .rate:active { transform: translateY(1px) scale(.98); }
  .rate b { font-size: 15px; font-weight: 800; }
  .rate span { font-size: 12px; font-weight: 650; opacity: .85; font-variant-numeric: tabular-nums; }
  .rate-1 { --rc: var(--tn-bad); --rs: var(--tn-bad-soft); }
  .rate-2 { --rc: var(--tn-warn); --rs: var(--tn-warn-soft); }
  .rate-3 { --rc: var(--tn-ok); --rs: var(--tn-ok-soft); }
  .rate-4 { --rc: var(--tn-pen); --rs: var(--tn-pen-soft); }
  .kbd { display: inline-block; margin-left: 8px; padding: 0 6px; min-width: 20px; border-radius: 6px; font: 700 11px/18px ui-monospace, Menlo, monospace;
    border: 1px solid currentColor; opacity: .55; text-transform: lowercase; }
  .rate .kbd { position: absolute; top: 5px; right: 6px; margin: 0; min-width: 0; padding: 0 4px; font-size: 10px; line-height: 15px; }
  @media (hover: none), (max-width: 639px) { .kbd { display: none; } }

  .study-done { text-align: center; padding: 48px 12px 24px; }
  .done-mark { width: 64px; height: 64px; margin: 0 auto; border-radius: 22px; display: grid; place-items: center; background: var(--tn-ok-soft); color: var(--tn-ok);
    animation: tn-pop .35s cubic-bezier(.2,.9,.25,1.4); }
}
@layer components {
  .provider-opt { position: relative; display: block; cursor: pointer; }
  .provider-opt input { position: absolute; opacity: 0; pointer-events: none; }
  .provider-opt > span { display: block; height: 100%; padding: 11px 13px; border-radius: 14px; border: 1.5px solid var(--tn-line); background: var(--tn-surface-2);
    font-size: 14.5px; transition: border-color .15s, background .15s, box-shadow .15s; }
  .provider-opt input:checked + span { border-color: var(--tn-pen); background: var(--tn-pen-soft); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tn-pen-soft) 60%, transparent); }
  .provider-opt input:focus-visible + span { outline: 2px solid var(--tn-pen); outline-offset: 2px; }
}
:root[data-theme="dark"] .flash mark { background: var(--tn-marker-soft); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .flash mark { background: var(--tn-marker-soft); } }
