:root {
  --paper: #f5f2ea;
  --paper-2: #ede8dc;
  --field: #fbfaf6;
  --ink: #22201c;
  --ink-2: #5d584e;
  --ink-3: #8a8476;
  --line: #d9d2c2;
  --accent: #a3401f;
  --accent-soft: #f1ddd2;
  --ok: #3f6b47;
  --ok-soft: #dfe9dc;
  --bad: #a3361f;
  --bad-soft: #f3dcd4;
  --serif: "Newsreader", "Noto Serif KR", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1c1b18; --paper-2: #24221e; --field: #201f1b;
    --ink: #e9e4d8; --ink-2: #b3ac9d; --ink-3: #847e70; --line: #3a372f;
    --accent: #d9774f; --accent-soft: #3b2a21;
    --ok: #8fbf8f; --ok-soft: #26321f; --bad: #e0876b; --bad-soft: #3d2620;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { word-break: keep-all; margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.55 var(--sans); }
a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--accent); color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
p { margin: 0 0 0.6em; }
[hidden] { display: none !important; }
kbd { font: 11px var(--mono); border: 1px solid currentColor; border-radius: 3px; padding: 0 4px; opacity: 0.6; margin-left: 6px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
::selection { background: var(--accent-soft); }

.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.pad { padding: 12px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line); padding: 26px 18px; display: flex; flex-direction: column; gap: 28px; background: var(--paper); }
.brand { font: 600 30px/1 var(--serif); text-decoration: none; padding-left: 8px; }
.brand span { color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a { display: flex; gap: 12px; align-items: baseline; padding: 7px 8px; text-decoration: none; border-radius: 3px; color: var(--ink-2); }
.nav a i { font: normal 11px var(--mono); color: var(--ink-3); }
.nav a:hover { color: var(--ink); background: var(--paper-2); }
.nav a.on { color: var(--ink); background: var(--paper-2); font-weight: 500; }
.nav a.on i { color: var(--accent); }
.side-foot { margin-top: auto; }
.who { display: flex; align-items: center; gap: 8px; font-size: 13px; text-decoration: none; padding: 6px 8px; overflow: hidden; }
.who span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who img, .who .initial { width: 24px; height: 24px; border-radius: 50%; flex: none; }
.who .initial { display: grid; place-items: center; background: var(--ink); color: var(--paper); font: 600 12px var(--sans); text-transform: uppercase; }

.view { padding: 44px 56px 80px; max-width: 1080px; width: 100%; }
.view.wide { max-width: none; padding: 0; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 30px; flex-wrap: wrap; }
.page-head h1 { font-size: 38px; line-height: 1.1; }
.eyebrow, .label { font: 500 12px/1.4 var(--sans); letter-spacing: 0.02em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 8px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.section-title { font-size: 22px; margin-bottom: 14px; }

/* ---------- controls ---------- */
.btn { font: 500 14px/1 var(--sans); color: var(--ink); background: transparent; border: 1px solid var(--ink); border-radius: 3px; padding: 9px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.btn:hover { background: var(--paper-2); color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { display: flex; justify-content: center; }
.btn.wide { min-width: 220px; justify-content: center; }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.google { background: var(--field); border-color: var(--line); padding: 10px 16px; }
.link-btn { font: 13px var(--sans); color: var(--ink-2); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.link-btn:hover { color: var(--accent); }
.link-btn.danger:hover { color: var(--bad); }

input[type=text], input[type=password], input[type=url], input[type=search], textarea, select {
  font: 15px/1.5 var(--sans); color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 3px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; }
select { width: auto; max-width: 100%; padding-right: 28px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=radio] { accent-color: var(--accent); }
.search { max-width: 260px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 160px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 16px 0 6px; }
.field > span:first-child { font-weight: 500; font-size: 14px; }
.inline-field { display: flex; gap: 8px; align-items: center; }
.inline-field select { padding: 4px 26px 4px 8px; font-size: 13px; }

/* ---------- layout bits ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 36px; }
.grid-2.tight { gap: 20px; margin-bottom: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border: 1px solid var(--line); margin-bottom: 40px; }
.panel { padding: 22px; }
.grid-3 .panel + .panel { border-left: 1px solid var(--line); }
.stat { font: 600 40px/1.1 var(--serif); margin: 4px 0 12px; }
.stat span { font: 400 15px var(--sans); color: var(--ink-2); }
.timer-mode { font-size: 13px; color: var(--accent); font-weight: 500; }
.timer-time { font: 500 40px/1.1 var(--mono); margin: 4px 0 12px; letter-spacing: -0.02em; }

.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.plain-list li:first-child { border-top: 1px solid var(--line); }

.empty { border: 1px dashed var(--line); padding: 40px 28px; text-align: center; color: var(--ink-2); max-width: 560px; margin: 20px auto; }
.empty-title { font: 600 22px var(--serif); color: var(--ink); }
.empty .btn { margin-top: 10px; }
.notice { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }

.rows { border-top: 1px solid var(--line); }
.group + .group { margin-top: 26px; }
.group > .label { margin-top: 10px; }
.row-item { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.row-main { display: flex; gap: 14px; align-items: center; text-decoration: none; min-width: 0; flex: 1; }
.row-main > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 14px; align-items: center; flex: none; }
.doc-icon { font: 500 10px var(--mono); border: 1px solid var(--ink-3); color: var(--ink-2); padding: 10px 5px; border-radius: 2px; flex: none; }

.drop { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; border: 1px dashed var(--ink-3); padding: 22px 24px; margin-bottom: 28px; cursor: pointer; }
.drop strong { font: 600 18px var(--serif); }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- reader ---------- */
.reader { display: grid; grid-template-columns: 1fr 400px; height: 100vh; }
.reader-doc { display: flex; flex-direction: column; min-width: 0; }
.reader-bar { display: flex; gap: 16px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.reader-title { font: 600 16px var(--serif); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-frame { flex: 1; border: 0; width: 100%; background: var(--paper-2); }
.reader-side { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; padding: 13px 0 11px; font: 500 14px var(--sans); color: var(--ink-2); cursor: pointer; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.pane { flex: 1; min-height: 0; display: flex; }
.pane-body { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 14px 16px; gap: 10px; }
.pane-body.scroll { overflow-y: auto; display: block; }
.pane-foot { display: flex; justify-content: space-between; align-items: center; }
.note-area { flex: 1; resize: none; font: 15px/1.6 var(--sans); }
.make-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.make-row p { margin: 2px 0 0; }
.make-row select { padding: 7px 24px 7px 8px; }
.make-out { padding-top: 14px; }

/* ---------- chat ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-log { flex: 1; overflow-y: auto; min-height: 0; padding: 4px 2px 12px; }
.chat-hint { color: var(--ink-2); font-size: 14px; border-left: 2px solid var(--line); padding-left: 12px; margin: 8px 0; }
.msg { padding: 12px 0; border-bottom: 1px solid var(--line); position: relative; }
.msg-who { font: 600 12px var(--sans); color: var(--ink-3); margin-bottom: 4px; }
.msg.model .msg-who { color: var(--accent); }
.msg.pending .msg-body { color: var(--ink-2); }
.msg.error .msg-body { color: var(--bad); }
.msg-copy { position: absolute; top: 12px; right: 0; font-size: 12px; opacity: 0; }
.msg:hover .msg-copy { opacity: 1; }
.composer { border-top: 1px solid var(--line); padding-top: 10px; }
.composer textarea { resize: none; }
.composer-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.composer-actions .muted { margin-right: auto; }

.msg-body, .prose { overflow-wrap: anywhere; }
.msg-body > :last-child, .prose > :last-child { margin-bottom: 0; }
.msg-body h2, .msg-body h3, .msg-body h4, .prose h2, .prose h3, .prose h4 { font-size: 17px; margin: 14px 0 6px; }
.prose h2 { font-size: 22px; }
.msg-body ul, .msg-body ol, .prose ul, .prose ol { padding-left: 22px; margin: 0 0 0.6em; }
.msg-body li, .prose li { margin: 2px 0; }
code { font: 13px var(--mono); background: var(--paper-2); padding: 1px 4px; border-radius: 2px; }
pre { background: var(--paper-2); padding: 12px; overflow-x: auto; border-radius: 3px; }
pre code { background: none; padding: 0; }
blockquote { border-left: 2px solid var(--line); margin: 0 0 0.6em; padding-left: 12px; color: var(--ink-2); }

.tutor-layout { display: grid; grid-template-columns: 230px 1fr; gap: 32px; height: calc(100vh - 124px); }
.tutor-layout aside { overflow-y: auto; }
.conv-list { display: flex; flex-direction: column; gap: 2px; }
.conv-list .btn { margin-bottom: 10px; }
.conv-main { display: flex; flex-direction: column; min-height: 0; }
.conv-head { display: flex; gap: 16px; align-items: center; justify-content: space-between; padding-bottom: 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }

/* ---------- notes ---------- */
.notes-layout { display: grid; grid-template-columns: 260px 1fr; gap: 32px; min-height: calc(100vh - 124px); }
.notes-side .row { flex-wrap: nowrap; margin-bottom: 10px; }
.notes-side .search { max-width: none; }
.note-list { display: flex; flex-direction: column; }
.note-link { display: flex; flex-direction: column; padding: 10px; text-decoration: none; border-radius: 3px; border-bottom: 1px solid var(--line); }
.note-link:hover { background: var(--paper-2); color: inherit; }
.note-link.on { background: var(--paper-2); box-shadow: inset 2px 0 var(--accent); }
.note-snip { font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-editor { display: flex; flex-direction: column; min-width: 0; }
.note-bar { display: flex; gap: 16px; align-items: center; justify-content: flex-end; margin-bottom: 8px; }
.note-bar > :first-child { margin-right: auto; }
.note-title { font: 600 30px/1.2 var(--serif) !important; border: 0 !important; background: transparent !important; padding: 4px 0 !important; outline: none !important; }
.note-body { flex: 1; min-height: 60vh; border: 0 !important; background: transparent !important; padding: 8px 0 !important; outline: none !important; font: 16px/1.7 var(--sans); resize: none; }
.note-preview { padding: 8px 0; font-size: 16px; line-height: 1.7; }

/* ---------- cards ---------- */
.add-card { display: grid; gap: 8px; border: 1px solid var(--line); padding: 16px; margin-bottom: 28px; background: var(--field); }
.card-list { border-top: 1px solid var(--line); }
.card-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 20px; padding: 12px 4px; border-bottom: 1px solid var(--line); align-items: start; }
.card-row textarea { grid-column: span 1; }
.card-side { white-space: pre-wrap; }
.muted-ink { color: var(--ink-2); }
.card-meta { display: flex; gap: 12px; align-items: center; }

.review { max-width: 680px; margin: 0 auto; }
.review-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.progress { height: 3px; background: var(--line); margin-bottom: 30px; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.25s; }
.flash { border: 1px solid var(--ink); background: var(--field); padding: 36px 40px; min-height: 260px; cursor: pointer; box-shadow: 4px 4px 0 var(--line); }
.flash-label { font: 600 12px var(--sans); color: var(--ink-3); margin-bottom: 10px; }
.flash-text { font: 400 24px/1.4 var(--serif); white-space: pre-wrap; }
.flash-text.answer { font-size: 20px; color: var(--ink-2); }
.review-actions { display: flex; gap: 10px; justify-content: center; margin: 24px 0; flex-wrap: wrap; }
.grade-again { border-color: var(--bad); color: var(--bad); }

/* ---------- quiz ---------- */
.quiz { display: flex; flex-direction: column; gap: 18px; margin-bottom: 24px; }
.q { border: 1px solid var(--line); padding: 16px 20px 12px; margin: 0; }
.q legend { font: 500 17px/1.4 var(--serif); padding: 0 6px; margin-left: -6px; }
.q-num { font: 500 13px var(--mono); color: var(--accent); }
.q.right { border-color: var(--ok); }
.q.wrong { border-color: var(--bad); }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 7px 8px; border-radius: 3px; cursor: pointer; }
.opt:hover { background: var(--paper-2); }
.opt input { margin-top: 5px; }
.opt.correct { background: var(--ok-soft); }
.opt.picked-wrong { background: var(--bad-soft); text-decoration: line-through; text-decoration-color: var(--bad); }
.why { font-size: 14px; color: var(--ink-2); border-left: 2px solid var(--line); padding-left: 10px; margin: 10px 0 4px; }
.quiz-result { margin-top: 20px; }

/* ---------- settings ---------- */
.settings-block { border-top: 1px solid var(--line); padding: 26px 0 30px; max-width: 720px; }
.persona-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.persona { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); padding: 10px 12px; cursor: pointer; border-radius: 3px; }
.persona:has(input:checked) { border-color: var(--ink); background: var(--field); }
.persona input { margin-top: 4px; }
.persona > span { display: flex; flex-direction: column; }
.persona strong { font-weight: 500; }
.persona-grid + div textarea { margin-top: 10px; }
details.cfg { margin-top: 22px; border: 1px solid var(--line); padding: 10px 14px; }
details.cfg summary { cursor: pointer; font-weight: 500; }

/* ---------- toast ---------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 3px; font-size: 14px; opacity: 0; pointer-events: none; transition: 0.2s; max-width: 90vw; z-index: 10; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--bad); color: #fff; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .shell { display: block; }
  .side { position: sticky; z-index: 5; height: auto; flex-direction: row; align-items: center; padding: 10px 14px; gap: 14px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .brand { font-size: 24px; padding: 0; }
  .nav { flex-direction: row; }
  .nav a { white-space: nowrap; padding: 6px 8px; }
  .nav a i { display: none; }
  .side-foot { margin: 0 0 0 auto; }
  .who span:last-child { display: none; }
  .view { padding: 26px 18px 60px; }
  .page-head h1 { font-size: 30px; }
  .grid-2, .grid-3, .persona-grid { grid-template-columns: 1fr; }
  .grid-3 .panel + .panel { border-left: 0; border-top: 1px solid var(--line); }
  .reader { grid-template-columns: 1fr; height: auto; }
  .pdf-frame { height: 70vh; flex: none; }
  .reader-side { border-left: 0; border-top: 1px solid var(--line); height: 80vh; }
  .notes-layout, .tutor-layout { grid-template-columns: 1fr; height: auto; min-height: 0; gap: 20px; }
  .tutor-layout aside { max-height: 200px; }
  .conv-main { height: 75vh; }
  .card-row { grid-template-columns: 1fr; gap: 6px; }
  .flash { padding: 24px; }
  .row-actions { gap: 10px; }
}
