:root {
  --ink: #18231d;
  --muted: #68736c;
  --paper: #f6f3ec;
  --panel: #fffdf8;
  --forest: #174a35;
  --forest-2: #2d6a4d;
  --gold: #c6a15b;
  --line: #ddd9ce;
  --cover: #315d47;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(420px, 1fr) 390px; }
.library, .tutor { position: sticky; top: 0; height: 100vh; background: var(--panel); }
.library { border-right: 1px solid var(--line); padding: 28px 20px; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark, .avatar { display: grid; place-items: center; background: var(--forest); color: white; font-family: Georgia, serif; }
.brand-mark { width: 42px; height: 42px; border-radius: 50% 50% 50% 12%; font-size: 24px; }
.brand span:last-child { display: grid; }
.brand strong { font-family: Georgia, serif; font-size: 20px; line-height: 1; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.library-heading { display: flex; justify-content: space-between; align-items: center; margin: 46px 4px 12px; }
.library-heading p { margin: 0; color: var(--muted); font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: .12em; }
.library-heading span { color: var(--muted); font-size: 12px; }
.work-list { display: grid; gap: 8px; }
.work-item { width: 100%; border: 1px solid transparent; border-radius: 14px; background: transparent; padding: 10px; display: flex; align-items: center; gap: 11px; color: inherit; text-align: left; }
.work-item:hover { background: #f2efe6; }
.work-item.active { background: #edf2ed; border-color: #d1dfd5; }
.work-item > span:last-child { display: grid; min-width: 0; }
.work-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: Georgia, serif; font-size: 14px; }
.work-item small { color: var(--muted); margin-top: 3px; }
.mini-cover { --cover: #315d47; flex: 0 0 32px; height: 44px; display: grid; place-items: center; border-radius: 2px 6px 6px 2px; color: #f8efda; background: var(--cover); box-shadow: inset 3px 0 rgba(255,255,255,.14); font-family: Georgia, serif; }
.library-foot { margin-top: auto; border-top: 1px solid var(--line); padding: 18px 4px 0; display: flex; align-items: center; gap: 10px; }
.library-foot div { display: grid; }
.library-foot strong { font-size: 12px; }
.library-foot small { color: var(--muted); font-size: 11px; margin-top: 2px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #4d9d70; box-shadow: 0 0 0 4px #e3f0e8; }

.reader { padding: 0 clamp(28px, 5vw, 82px) 72px; min-width: 0; }
.topbar { height: 82px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.topbar-actions{display:flex;align-items:center;gap:13px}.topbar-actions>a{color:var(--muted);font-size:11px;text-decoration:none}.topbar-actions>a:hover{color:var(--forest)}
.eyebrow { color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .14em; text-transform: uppercase; }
.settings-button { border: 1px solid var(--line); background: rgba(255,255,255,.55); color: var(--ink); border-radius: 999px; padding: 9px 14px; font-size: 12px; }
.settings-button:hover { border-color: var(--forest-2); }
.work-hero { display: grid; grid-template-columns: 118px 1fr; gap: 30px; align-items: center; padding: 55px 0 42px; }
.book-glyph { width: 108px; height: 150px; display: grid; place-items: center; position: relative; border-radius: 3px 10px 10px 3px; background: var(--cover); color: #f4e9ce; box-shadow: inset 7px 0 rgba(0,0,0,.12), 0 18px 28px rgba(45,59,49,.16); }
.book-glyph::before, .book-glyph::after { content: ""; position: absolute; border: 1px solid rgba(238,220,176,.35); border-radius: 50%; }
.book-glyph::before { width: 64px; height: 64px; }
.book-glyph::after { width: 42px; height: 92px; }
.book-glyph span { position: relative; z-index: 1; font: 42px Georgia, serif; }
.work-meta { margin: 0 0 12px; color: var(--forest-2); font-size: 12px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.work-hero h1 { margin: 0; font: 600 clamp(38px, 5vw, 64px)/.98 Georgia, "Times New Roman", serif; letter-spacing: -.035em; }
.work-tagline { max-width: 680px; margin: 17px 0 0; color: var(--muted); font: 17px/1.65 Georgia, serif; }
.tabs { display: flex; gap: 28px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { white-space: nowrap; padding: 0 2px 15px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 13px; font-weight: 700; }
.tabs button[aria-selected="true"] { color: var(--forest); border-bottom-color: var(--forest); }
.section-list { display: grid; }
.empty-sections { margin: 0; padding: 42px 4px; color: var(--muted); font: 15px/1.6 Georgia, serif; }
.reading-section { display: grid; grid-template-columns: 42px 1fr; gap: 19px; padding: 32px 0; border-bottom: 1px solid var(--line); }
.section-number { padding-top: 3px; color: var(--gold); font: 15px Georgia, serif; }
.section-heading { display: flex; justify-content: space-between; gap: 16px; align-items: baseline; }
.section-heading h2 { margin: 0; font: 600 24px/1.2 Georgia, serif; }
.section-heading span { flex: 0 0 auto; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.reading-section p { margin: 15px 0 0; color: #3e4842; font: 16px/1.8 Georgia, serif; }
.theme-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 18px; }
.theme-row span { border: 1px solid #d7ded8; border-radius: 999px; padding: 4px 9px; color: var(--forest-2); font-size: 10px; }

.tutor { border-left: 1px solid var(--line); display: grid; grid-template-rows: auto auto 1fr auto; min-width: 0; }
.tutor-header { padding: 26px 24px 18px; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.tutor-kicker { color: var(--forest-2); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .13em; }
.tutor h2 { margin: 4px 0 0; font: 600 21px Georgia, serif; }
.provider-badge { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 5px 8px; border-radius: 999px; background: #eaf1eb; color: var(--forest); font-size: 9px; }
.privacy-note { margin: 0 24px; padding: 10px 12px; border-radius: 10px; background: #f5f2e9; color: var(--muted); font-size: 11px; }
.messages { min-height: 0; overflow-y: auto; padding: 22px 24px; display: flex; flex-direction: column; gap: 22px; }
.message { display: flex; gap: 10px; align-items: flex-start; }
.message.user { justify-content: flex-end; }
.message.user > div { max-width: 85%; background: var(--forest); color: white; border-radius: 16px 16px 4px 16px; padding: 11px 14px; }
.message.assistant > div { min-width: 0; }
.message p { margin: 0; font-size: 13px; line-height: 1.65; }
.message p + p { margin-top: 10px; }
.avatar { flex: 0 0 28px; height: 28px; border-radius: 50% 50% 50% 7px; font: 15px Georgia, serif; }
.suggestions { display: grid; gap: 7px; margin-top: 14px; }
.suggestions button { border: 1px solid var(--line); background: white; color: #435048; border-radius: 10px; padding: 9px 11px; text-align: left; font-size: 11px; }
.suggestions button:hover { border-color: var(--forest-2); color: var(--forest); }
.citation { color: var(--forest-2); font-weight: 800; }
.source-details { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 9px; color: var(--muted); font-size: 10px; }
.source-details summary { cursor: pointer; font-weight: 700; }
.source-details ol { margin: 8px 0 0; padding-left: 17px; }
.source-details li { margin: 6px 0; }
.source-details li span { display: block; }
.loading i { display: inline-block; width: 5px; height: 5px; margin: 9px 2px; border-radius: 50%; background: var(--forest-2); animation: pulse 1s infinite alternate; }
.loading i:nth-child(2) { animation-delay: .2s; }.loading i:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { to { opacity: .2; transform: translateY(-2px); } }
.chat-form { margin: 0 20px 20px; border: 1px solid #cfd5cf; border-radius: 16px; background: white; padding: 12px; box-shadow: 0 8px 28px rgba(37,53,43,.08); }
.chat-form textarea { width: 100%; resize: none; border: 0; outline: 0; color: var(--ink); }
.chat-form textarea::placeholder { color: #929b95; }
.chat-actions { margin-top: 8px; display: flex; justify-content: space-between; align-items: center; }
.spoiler-control { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.spoiler-control select { margin-left: 4px; border: 0; color: var(--forest); font-size: 10px; font-weight: 700; outline: 0; }
.send-button { width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--forest); color: white; font-size: 20px; }

.settings-dialog { width: min(520px, calc(100vw - 28px)); border: 0; border-radius: 22px; padding: 0; color: var(--ink); box-shadow: 0 30px 100px rgba(12,24,17,.35); }
.settings-dialog::backdrop { background: rgba(12,24,17,.55); backdrop-filter: blur(3px); }
.dialog-card { padding: 28px; display: grid; gap: 17px; }
.dialog-header { display: flex; justify-content: space-between; align-items: start; }
.dialog-header p { margin: 0 0 3px; color: var(--forest-2); font-size: 10px; font-weight: 800; letter-spacing: .12em; }
.dialog-header h2 { margin: 0; font: 600 28px Georgia, serif; }
.close-button { border: 0; background: transparent; color: var(--muted); font-size: 28px; }
.dialog-copy { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.dialog-card > label:not(.check-row) { display: grid; gap: 7px; color: #455048; font-size: 12px; font-weight: 700; }
.dialog-card input, .dialog-card select { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 11px 12px; outline: none; }
.dialog-card input:focus, .dialog-card select:focus { border-color: var(--forest-2); box-shadow: 0 0 0 3px #e7efe9; }
.dialog-card small { color: var(--muted); font-weight: 400; }
.check-row { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 11px; }
.check-row input { width: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 4px; }
.primary-button, .secondary-button { border-radius: 999px; padding: 10px 16px; font-size: 12px; font-weight: 750; }
.primary-button { border: 1px solid var(--forest); background: var(--forest); color: white; }
.secondary-button { border: 1px solid var(--line); background: white; color: var(--ink); }
.sr-only, .sr-only:focus:not(:focus-visible) { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 210px 1fr; }
  .tutor { position: fixed; z-index: 10; right: 18px; bottom: 18px; top: auto; width: min(390px, calc(100vw - 36px)); height: min(680px, calc(100vh - 36px)); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; box-shadow: 0 24px 70px rgba(24,35,29,.22); }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .library { position: static; width: auto; height: auto; padding: 18px; border: 0; border-bottom: 1px solid var(--line); }
  .library-heading, .library-foot { display: none; }
  .work-list { margin-top: 16px; }
  .reader { padding: 0 20px 620px; }
  .topbar { height: 66px; }
  .topbar-actions>a{display:none}
  .work-hero { grid-template-columns: 72px 1fr; gap: 18px; padding: 34px 0; }
  .book-glyph { width: 66px; height: 94px; }.book-glyph::before { width: 40px; height: 40px; }.book-glyph::after { width: 30px; height: 60px; }.book-glyph span { font-size: 26px; }
  .work-hero h1 { font-size: 39px; }
  .tutor { right: 12px; bottom: 12px; width: calc(100vw - 24px); height: 560px; }
  .reading-section { grid-template-columns: 28px 1fr; gap: 10px; }
  .section-heading { display: block; }.section-heading span { display: inline-block; margin-top: 7px; }
}
