:root {
  --paper: #f4f0e7;
  --paper-deep: #e9e1d2;
  --paper-light: #fbf9f4;
  --ink: #24211d;
  --ink-soft: #625c52;
  --rule: #cec3b2;
  --accent: #9d332b;
  --ochre: #b48238;
  --display: "Iowan Old Style", "Baskerville", "Palatino Linotype", Georgia, serif;
  --body: "Aptos", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--body);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background-color: var(--paper);
  background-image: radial-gradient(rgba(69, 54, 36, .055) .7px, transparent .8px), linear-gradient(115deg, rgba(255,255,255,.38), transparent 42%);
  background-size: 6px 6px, 100% 100%;
}
button, input, textarea { font: inherit; }
button { color: inherit; }
button:not(:disabled) { cursor: pointer; }
:focus-visible { outline: 3px solid var(--ochre); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.mobile-only { display: none; }
.icon-button, .quiet-button, .text-button { border: 0; background: transparent; }
.icon-button { min-width: 40px; min-height: 40px; border-radius: 50%; font-size: 1.15rem; }
.icon-button:hover { background: rgba(36,33,29,.08); }
.section-label, .eyebrow, .chapter-number, .topbar__kicker { margin: 0; color: var(--accent); font-size: .68rem; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; }

.app-shell { height: 100%; display: grid; grid-template-columns: 270px minmax(420px, 1fr); }
.sidebar { display: flex; min-width: 0; flex-direction: column; background: #292722; color: #f4efe5; border-right: 1px solid #151410; }
.brand { height: 88px; padding: 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand__monogram { display: grid; width: 43px; aspect-ratio: 1; place-items: center; border: 1px solid #a99475; color: #d7bd91; font: 700 .9rem var(--display); transform: rotate(-2deg); }
.brand strong { display: block; font: 700 1.25rem var(--display); letter-spacing: .04em; }
.brand span { display: block; margin-top: 2px; color: #bdb5a7; font-size: .67rem; letter-spacing: .13em; text-transform: uppercase; }
.new-conversation { margin: 20px; padding: 12px 14px; border: 1px solid #776e61; background: transparent; color: #fff9ee; text-align: left; font: italic 1rem var(--display); transition: border-color .2s, background .2s; }
.new-conversation:hover { border-color: #d7bd91; background: rgba(255,255,255,.06); }
.new-conversation span { color: #d3a85e; margin-right: 9px; }
.history { min-height: 0; flex: 1; overflow: auto; }
.history .section-label { padding: 5px 22px 12px; color: #9f9689; }
.conversation-list, .document-list { list-style: none; margin: 0; padding: 0; }
.conversation-item { display: flex; align-items: center; margin: 2px 10px; border-left: 2px solid transparent; }
.conversation-item[data-active="true"] { background: rgba(255,255,255,.08); border-left-color: #cc9156; }
.conversation-item__open { flex: 1; min-width: 0; padding: 12px 10px; border: 0; background: transparent; color: #e9e2d7; overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; font: .94rem var(--display); }
.conversation-item__actions { display: none; padding-right: 4px; }
.conversation-item:hover .conversation-item__actions, .conversation-item:focus-within .conversation-item__actions { display: flex; }
.conversation-item__actions .icon-button { min-width: 30px; min-height: 30px; color: #c9c0b2; font-size: .85rem; }
.conversation-item__actions .icon-button:hover { background: rgba(255,255,255,.1); }
.sidebar__footer { padding: 14px 20px 20px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar__footer { display: grid; gap: 10px; }
.quiet-button { color: #bdb5a7; font-size: .78rem; letter-spacing: .06em; }
.quiet-button:hover { color: white; }
.password-panel { position: fixed; z-index: 30; left: 18px; bottom: 18px; width: 234px; padding: 17px; background: #f8f4eb; color: var(--ink); border: 1px solid var(--rule); box-shadow: 0 16px 38px rgba(0,0,0,.35); }
.password-panel h2 { margin: 0 0 12px; font: 600 1.2rem var(--display); }
.password-panel label { display: block; margin-top: 9px; font-size: .7rem; }
.password-panel input { width: 100%; margin-top: 4px; padding: 7px; border: 1px solid var(--rule); background: white; }
.password-panel [role="status"] { min-height: 2.4em; color: var(--accent); font-size: .7rem; }
.password-panel form > div { display: flex; align-items: center; gap: 10px; }

.writing-room { min-width: 0; display: grid; grid-template-areas: "topbar" "notice" "messages" "composer"; grid-template-rows: auto auto minmax(0, 1fr) auto; }
.topbar { grid-area: topbar; height: 82px; display: flex; align-items: center; gap: 18px; padding: 14px 30px; border-bottom: 1px solid var(--rule); background: rgba(244,240,231,.82); backdrop-filter: blur(10px); }
.topbar > div { flex: 1; min-width: 0; }
.topbar h1 { margin: 3px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 600 1.45rem var(--display); }
.documents-trigger { display: flex; align-items: center; gap: 8px; padding: 9px 14px; border: 1px solid var(--rule); background: var(--paper-light); font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; }
.notice { grid-area: notice; margin: 12px auto 0; max-width: 760px; width: calc(100% - 48px); padding: 11px 14px; background: #f4ddd8; border-left: 3px solid var(--accent); color: #71261f; font-size: .86rem; }
.notice-action { grid-area: notice; align-self: center; justify-self: end; z-index: 1; margin-right: max(32px, calc((100% - 730px)/2)); border: 0; background: transparent; color: var(--accent); text-decoration: underline; }
.context-usage { grid-area: notice; justify-self: center; width: calc(100% - 48px); max-width: 760px; margin: 10px auto 0; padding: 8px 12px; border-left: 3px solid var(--ochre); background: #efe3c9; color: #675020; font-size: .78rem; }
.context-usage[data-level="warning"] { border-left-color: var(--accent); background: #f4ddd8; color: #71261f; font-weight: 700; }
.messages { grid-area: messages; overflow-y: auto; padding: 44px max(28px, calc((100% - 780px)/2)) 20px; scroll-behavior: smooth; }
.empty-state { min-height: 100%; display: grid; place-content: center; max-width: 500px; margin: auto; text-align: center; animation: reveal .65s ease-out both; }
.empty-state__number { margin: 0; color: var(--ochre); font: italic 1rem var(--display); }
.empty-state h2 { margin: 10px 0 8px; font: 500 clamp(2.2rem, 5vw, 4rem)/1 var(--display); }
.empty-state > p:not(.empty-state__number) { max-width: 430px; margin: 0 auto; color: var(--ink-soft); font: italic 1.08rem/1.6 var(--display); }
.prompt-lines { margin: 32px auto; width: 80px; display: grid; gap: 6px; }
.prompt-lines span { height: 1px; background: var(--rule); }
.prompt-lines span:nth-child(2) { width: 55px; margin: auto; }
.message { position: relative; max-width: 760px; margin: 0 auto 38px; padding-left: 84px; animation: reveal .32s ease-out both; }
.message__label { position: absolute; left: 0; top: 2px; color: var(--accent); font: 700 .67rem var(--body); letter-spacing: .12em; text-transform: uppercase; }
.message--user .message__body { color: #4b463f; font: italic 1.06rem/1.65 var(--display); white-space: pre-wrap; }
.message--assistant { border-left: 1px solid var(--rule); padding-left: 31px; margin-left: max(0px, calc((100% - 760px)/2 + 53px)); }
.message--assistant .message__label { left: -84px; }
.message__body { overflow-wrap: anywhere; line-height: 1.68; }
.message__body > :first-child { margin-top: 0; }
.message__body > :last-child { margin-bottom: 0; }
.message__body h1, .message__body h2, .message__body h3 { font-family: var(--display); line-height: 1.2; }
.message__body pre { overflow: auto; padding: 16px; background: #292722; color: #f1eadf; border-radius: 2px; }
.message__body code { font-family: "Cascadia Mono", Consolas, monospace; font-size: .88em; }
.message__body :not(pre) > code { padding: 2px 5px; background: var(--paper-deep); }
.message__body blockquote { margin-left: 0; padding-left: 18px; border-left: 3px solid var(--ochre); color: var(--ink-soft); font-family: var(--display); font-style: italic; }
.message__body a { color: var(--accent); text-underline-offset: 3px; }
.typing { display: inline-flex; margin-top: 9px; color: var(--ink-soft); font: italic .8rem var(--display); }
.typing::after { content: "…"; animation: pulse 1.1s infinite; }
.message__state { margin-top: 12px; color: var(--accent); font-size: .8rem; }
.text-button { padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

.composer-wrap { grid-area: composer; padding: 12px 28px 25px; background: linear-gradient(transparent, var(--paper) 30%); }
.composer { max-width: 800px; margin: auto; padding: 15px 16px 10px; background: var(--paper-light); border: 1px solid #bbb09f; box-shadow: 0 13px 30px rgba(49,39,25,.1); }
.composer textarea { display: block; width: 100%; min-height: 58px; max-height: 180px; padding: 4px; resize: vertical; border: 0; outline: 0; background: transparent; color: var(--ink); font: 1rem/1.5 var(--body); }
.composer textarea::placeholder { color: #8b8377; font-family: var(--display); font-style: italic; }
.composer__footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #8b8377; font-size: .68rem; }
.send-button { width: 38px; aspect-ratio: 1; border: 0; border-radius: 50%; background: var(--accent); color: white; font-size: 1.25rem; }
.send-button:disabled { opacity: .45; }
.stop-button { margin-right: 10px; padding: 7px 10px; border: 1px solid var(--rule); background: transparent; color: var(--accent); font-size: .75rem; }

.documents-panel { position: fixed; visibility: hidden; z-index: 20; top: 0; right: 0; height: 100%; width: min(390px, 100%); padding: 26px; overflow-y: auto; background: #f8f4eb; border-left: 1px solid var(--rule); box-shadow: -20px 0 50px rgba(45,36,23,.16); transform: translateX(102%); transition: transform .3s cubic-bezier(.2,.8,.2,1), visibility 0s linear .3s; }
.app-shell[data-documents-open="true"] .documents-panel { visibility: visible; transform: translateX(0); transition-delay: 0s; }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; padding-bottom: 20px; border-bottom: 1px solid var(--rule); }
.panel-header h2 { margin: 4px 0 0; font: 500 2.2rem var(--display); }
.panel-deck { color: var(--ink-soft); font: italic .98rem/1.55 var(--display); }
.dropzone { margin: 24px 0 10px; padding: 28px 18px; display: grid; place-items: center; gap: 7px; border: 1px dashed #a99b86; background: rgba(255,255,255,.35); text-align: center; transition: background .2s, border-color .2s; }
.dropzone[data-dragging="true"] { border-color: var(--accent); background: #f3e2d9; }
.dropzone__glyph { color: var(--accent); font-size: 2rem; }
.dropzone > span:not(.dropzone__glyph) { color: var(--ink-soft); font-size: .75rem; }
.outline-button { margin-top: 10px; padding: 9px 14px; border: 1px solid var(--ink); background: transparent; }
.document-status { min-height: 1.3em; color: var(--ink-soft); font-size: .78rem; }
.document-status[data-kind="error"] { color: var(--accent); }
.document-status[data-kind="success"] { color: #52683d; }
.document-item { display: flex; justify-content: space-between; gap: 14px; padding: 16px 0; border-bottom: 1px solid var(--rule); }
.document-item strong { display: block; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: .95rem var(--display); }
.document-item span { display: block; margin-top: 4px; color: var(--ink-soft); font-size: .7rem; }
.document-actions { display: flex; align-items: center; gap: 4px; }
.switch { position: relative; width: 37px; height: 21px; border: 0; border-radius: 20px; background: #a69e92; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: white; transition: transform .2s; }
.switch[aria-checked="true"] { background: #697c4e; }
.switch[aria-checked="true"]::after { transform: translateX(16px); }
.context-note { margin-top: 25px; padding: 14px; background: var(--paper-deep); color: var(--ink-soft); font: italic .8rem/1.45 var(--display); }
.scrim { display: none; position: fixed; inset: 0; z-index: 15; border: 0; background: rgba(24,22,18,.46); }
.app-shell[data-documents-open="true"] .scrim, .app-shell[data-sidebar-open="true"] .scrim { display: block; }

.login-page { overflow: auto; }
.login-shell { min-height: 100%; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, .75fr); }
.login-intro { position: relative; padding: clamp(46px, 9vw, 130px); overflow: hidden; display: flex; flex-direction: column; justify-content: center; border-right: 1px solid var(--rule); }
.login-intro::before { content: "“"; position: absolute; top: -9rem; right: -1rem; color: rgba(157,51,43,.075); font: 34rem/1 var(--display); }
.login-intro h1 { position: relative; margin: 22px 0; font: 500 clamp(3.5rem, 7vw, 7.4rem)/.9 var(--display); letter-spacing: -.045em; }
.login-intro h1 em { color: var(--accent); font-weight: 400; }
.login-deck { max-width: 560px; margin: 0; color: var(--ink-soft); font: 1.2rem/1.6 var(--display); }
.folio-mark { position: absolute; right: 7%; bottom: 8%; width: 72px; aspect-ratio: 1; display: grid; place-items: center; border: 1px solid var(--ochre); transform: rotate(4deg); color: var(--ochre); font: 600 1.25rem var(--display); }
.login-card { display: flex; flex-direction: column; justify-content: center; padding: clamp(38px, 7vw, 90px); background: rgba(251,249,244,.67); }
.login-card form { margin: 32px 0 25px; }
.login-card label { display: block; margin-bottom: 9px; font: .82rem var(--body); letter-spacing: .07em; }
.password-field { position: relative; border-bottom: 1px solid var(--ink); }
.password-field input { width: 100%; padding: 13px 70px 13px 0; border: 0; outline: 0; background: transparent; font: 1.2rem var(--display); }
.password-field .text-button { position: absolute; right: 0; top: 15px; font-size: .72rem; }
.primary-button { width: 100%; margin-top: 31px; padding: 15px 17px; display: flex; justify-content: space-between; border: 1px solid var(--accent); background: var(--accent); color: white; font-family: var(--display); }
.primary-button:hover { background: #7f2822; }
.primary-button:disabled { opacity: .6; }
.form-error { padding: 11px; background: #f4ddd8; color: #79271f; font-size: .8rem; }
.privacy-note { padding-top: 22px; border-top: 1px solid var(--rule); color: var(--ink-soft); font: italic .78rem var(--display); }

@keyframes reveal { from { opacity: 0; transform: translateY(8px); } }
@keyframes pulse { 50% { opacity: .25; } }
@media (max-width: 820px) {
  .mobile-only { display: inline-grid; place-items: center; }
  .app-shell { display: block; }
  .sidebar { position: fixed; visibility: hidden; z-index: 20; top: 0; bottom: 0; left: 0; width: min(310px, 88vw); transform: translateX(-102%); transition: transform .3s cubic-bezier(.2,.8,.2,1), visibility 0s linear .3s; }
  .app-shell[data-sidebar-open="true"] .sidebar { visibility: visible; transform: translateX(0); transition-delay: 0s; }
  .brand .mobile-only { margin-left: auto; color: white; }
  .writing-room { height: 100vh; height: 100dvh; }
  .topbar { height: 70px; padding: 10px 15px; }
  .topbar h1 { font-size: 1.1rem; }
  .desktop-label { display: none; }
  .documents-trigger { padding: 9px 11px; }
  .messages { padding: 28px 20px 12px; }
  .message { padding-left: 0; margin-bottom: 30px; }
  .message__label { position: static; display: block; margin-bottom: 7px; }
  .message--assistant { margin-left: 0; padding: 18px 0 0 16px; }
  .message--assistant .message__label { margin-left: -1px; }
  .composer-wrap { padding: 9px 12px 14px; }
  .composer__footer > span { display: none; }
  .composer__footer { justify-content: flex-end; }
  .login-shell { display: block; }
  .login-intro { min-height: 53vh; padding: 48px 28px; border-right: 0; border-bottom: 1px solid var(--rule); }
  .login-intro h1 { font-size: clamp(3.2rem, 15vw, 5rem); }
  .login-deck { font-size: 1rem; }
  .folio-mark { right: 28px; bottom: 28px; width: 52px; }
  .login-card { min-height: 47vh; padding: 42px 28px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
