:root {
  --bg: #f4eee2; --paper: #fdf8ee; --ink: #211f2b; --muted: #6f6a76; --accent: #2b4294; --gold: #c8942f;
  --card: rgba(33,31,43,.05); --line: rgba(33,31,43,.12); --ok: #1f9d55; --warn: #e08a1e; --bad: #c0392b;
  --serif: ui-serif, "New York", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #131419; --paper: #1b1b1d; --ink: #f0ebde; --muted: #a09aa6; --accent: #9eb8ff; --gold: #e0b050;
    --card: rgba(240,235,222,.07); --line: rgba(240,235,222,.14); --ok: #4cc27f; --warn: #f0a640; --bad: #ff7b6b; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { font-family: var(--serif); margin: 0; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.top { display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); z-index: 5; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 22px; color: var(--ink); }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 14px; font-weight: 600; font-size: 14px; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.btn:hover { background: var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #10131f; } }
.btn:disabled { opacity: .5; cursor: default; }
.crumbs { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.crumbs h1 { font-size: 34px; }

/* auth */
.auth { max-width: 380px; margin: 12vh auto 0; padding: 0 20px; }
.auth h1 { font-size: 38px; margin-bottom: 4px; }
.auth form { display: grid; gap: 12px; margin-top: 22px; }
input, textarea { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.msg { font-size: 14px; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 16%, transparent); }
.msg.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); }
.link { background: none; border: 0; color: var(--accent); padding: 0; font-size: 14px; text-align: left; }

/* notebooks */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 26px; }
.cover { aspect-ratio: 3 / 4; border-radius: 14px; padding: 18px 14px 14px 26px; position: relative; display: flex; flex-direction: column; justify-content: space-between; color: #fff; box-shadow: 0 8px 22px rgba(0,0,0,.22); transition: transform .15s; overflow: hidden; }
.cover:hover { transform: translateY(-3px); }
.cover::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 14px; background: rgba(0,0,0,.25); }
.cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(135deg, rgba(255,255,255,.14), rgba(0,0,0,.18)); pointer-events: none; }
.plate { background: #fdf8ee; color: #211f2b; border-radius: 6px; padding: 10px 8px; text-align: center; font-family: var(--serif); font-weight: 700; font-size: 20px; line-height: 1.2; box-shadow: 0 2px 6px rgba(0,0,0,.25); position: relative; z-index: 1; word-break: break-word; }
.count { text-align: center; letter-spacing: .14em; font-size: 12px; font-weight: 600; text-transform: uppercase; opacity: .85; position: relative; z-index: 1; }
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 24px; }
.pagecard .thumb { aspect-ratio: 4 / 3; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: grid; place-items: center; }
.pagecard .thumb img { width: 100%; height: 100%; object-fit: contain; background: var(--paper); }
.pagecard h3 { font-size: 18px; margin-top: 8px; color: var(--ink); }
.pagecard small { color: var(--muted); }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 8px; }

/* page viewer */
.viewer { display: grid; grid-template-columns: 1fr; gap: 18px; }
.viewer.withpanel { grid-template-columns: 1fr 380px; }
@media (max-width: 900px) { .viewer.withpanel { grid-template-columns: 1fr; } }
.stage { position: relative; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; line-height: 0; touch-action: pan-y; }
.stage img { width: 100%; height: auto; display: block; user-select: none; -webkit-user-drag: none; }
.stage.asking { cursor: crosshair; touch-action: none; }
.sel { position: absolute; border: 2px dashed var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); pointer-events: none; }
.pager { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; flex-wrap: wrap; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; align-self: start; position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
.panel h3 { font-size: 20px; margin-bottom: 10px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.crop { border: 2px dashed var(--accent); border-radius: 10px; background: #fff; max-width: 100%; display: block; }
.turn { margin: 14px 0; }
.turn.user { background: var(--accent); color: #fff; border-radius: 14px; padding: 9px 13px; margin-left: 36px; }
@media (prefers-color-scheme: dark) { .turn.user { color: #10131f; } }
.turn.ai { display: flex; gap: 10px; }
.turn.ai > span { color: var(--gold); line-height: 1.6; }
.rich { min-width: 0; flex: 1; }
.rich p, .rich ul, .rich ol { margin: 0 0 .7em; }
.rich ul, .rich ol { padding-left: 1.4em; }
.rich code { background: var(--card); padding: .1em .35em; border-radius: 5px; font-size: .9em; }
.rich h4 { margin: .9em 0 .35em; }
.rich .katex-display { overflow-x: auto; overflow-y: hidden; }
.composer { display: flex; gap: 8px; margin-top: 10px; }
.note { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; margin: 8px 0; }

/* review */
.card { background: var(--card); border-radius: 12px; padding: 14px 16px; margin: 10px 0; border-left: 4px solid var(--accent); }
.card.warn { border-color: var(--warn); } .card.ok { border-color: var(--ok); }
.card h4 { margin: 0 0 4px; font-size: 17px; }
.group-title { font-family: var(--serif); font-size: 21px; font-weight: 600; margin: 26px 0 8px; }
.group-title.warn { color: var(--warn); } .group-title.ok { color: var(--ok); } .group-title.gold { color: var(--gold); } .group-title.acc { color: var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { background: var(--line); border: 0; border-radius: 999px; padding: 3px 10px; font-size: 12.5px; font-weight: 600; }
.seg { display: inline-flex; background: var(--card); border-radius: 10px; padding: 3px; margin: 8px 0 14px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: 8px; font-size: 14px; }
.seg button.on { background: var(--paper); box-shadow: 0 1px 3px rgba(0,0,0,.18); font-weight: 600; }
.qrow { display: flex; gap: 14px; background: var(--card); border-radius: 12px; padding: 12px; margin: 10px 0; cursor: pointer; text-align: left; width: 100%; border: 0; }
.qrow img { width: 96px; height: 72px; object-fit: contain; background: #fff; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.qrow .tag { color: var(--accent); font-weight: 700; font-size: 12.5px; }
.qrow .snip { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; font-size: 14.5px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; padding: 20px; z-index: 20; }
.modal[hidden] { display: none; }
.sheet { background: var(--bg); border-radius: 16px; max-width: 640px; width: 100%; max-height: 88vh; overflow: auto; padding: 20px; }
.sheet img.pic { max-width: 100%; max-height: 240px; background: #fff; border-radius: 10px; display: block; margin: 0 auto 10px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: 14px; z-index: 30; }
