:root {
  color-scheme: dark;
  --bg: #111114;
  --bg-raised: #18181d;
  --panel: rgba(28, 28, 34, .82);
  --panel-solid: #1b1b20;
  --panel-soft: #222229;
  --line: rgba(242, 238, 230, .12);
  --line-strong: rgba(242, 238, 230, .22);
  --text: #efebe5;
  --muted: #a29c98;
  --faint: #69646a;
  --copper: #d59a61;
  --copper-bright: #edb87b;
  --moon: #9bb4d1;
  --green: #92c39b;
  --danger: #db8c8c;
  --display: "Iowan Old Style", "Baskerville", Georgia, serif;
  --body: "Avenir Next", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", Consolas, monospace;
  --shadow: 0 20px 70px rgba(0, 0, 0, .24);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

html[data-theme="paper"] {
  color-scheme: light;
  --bg: #f1ece4;
  --bg-raised: #faf7f1;
  --panel: rgba(255, 252, 246, .9);
  --panel-solid: #fffdf8;
  --panel-soft: #e7ded3;
  --line: rgba(39, 33, 29, .13);
  --line-strong: rgba(39, 33, 29, .24);
  --text: #262128;
  --muted: #6c625b;
  --faint: #988d85;
  --copper: #a86338;
  --copper-bright: #854921;
  --moon: #55738f;
  --green: #527c5a;
  --danger: #a84d4d;
  --shadow: 0 20px 70px rgba(103, 76, 43, .12);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--body); font-size: 15px; line-height: 1.5; }
button, textarea, select { font: inherit; }
button { color: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--copper-bright); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 246px minmax(0, 1fr); background: radial-gradient(circle at 76% 0%, rgba(155, 180, 209, .06), transparent 30rem), var(--bg); }
.sidebar { padding: 28px 16px 18px; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 100vh; background: rgba(14, 14, 17, .35); }
html[data-theme="paper"] .sidebar { background: rgba(255,255,255,.25); }
.brand-lockup { display: flex; align-items: center; gap: 11px; padding: 0 12px 28px; letter-spacing: .16em; }
.brand-lockup strong { display: block; font-size: 13px; font-weight: 700; }
.brand-lockup small { display: block; color: var(--muted); font-size: 8px; letter-spacing: .25em; margin-top: 2px; }
.brand-orbit { width: 28px; height: 28px; border: 1px solid var(--copper); border-radius: 50%; position: relative; transform: rotate(-24deg); }
.brand-orbit:before { content: ""; position: absolute; inset: 5px -4px; border: 1px solid var(--moon); border-radius: 50%; }
.brand-orbit span { width: 4px; height: 4px; border-radius: 50%; background: var(--copper-bright); position: absolute; right: 2px; top: 2px; box-shadow: 0 0 9px var(--copper); }
.new-story { border: 1px solid rgba(213,154,97,.5); background: linear-gradient(135deg, rgba(213,154,97,.18), rgba(213,154,97,.05)); padding: 11px 13px; border-radius: 10px; display: flex; align-items: center; gap: 9px; font-weight: 650; margin-bottom: 25px; transition: transform .2s var(--ease), border-color .2s var(--ease); }
.new-story:hover { transform: translateY(-2px); border-color: var(--copper-bright); }
.plus { color: var(--copper-bright); font-size: 19px; line-height: 1; }
.primary-nav, .sidebar-bottom { display: grid; gap: 3px; }
.nav-item { border: 0; background: transparent; color: var(--muted); border-radius: 8px; padding: 9px 10px; display: flex; align-items: center; gap: 10px; text-align: left; transition: background .2s var(--ease), color .2s var(--ease); }
.nav-item span { width: 19px; color: var(--faint); text-align: center; }
.nav-item:hover, .nav-item.active { background: var(--panel-soft); color: var(--text); }
.nav-item.active span { color: var(--copper-bright); }
.nav-item i { font-style: normal; font-size: 10px; margin-left: auto; color: var(--copper-bright); border: 1px solid rgba(213,154,97,.4); border-radius: 20px; padding: 1px 6px; }
.sidebar-section { margin-top: 28px; }
.section-label, .eyebrow, .memory-label { letter-spacing: .14em; font-size: 10px; color: var(--faint); font-weight: 700; }
.section-label { padding: 0 10px 9px; display: flex; justify-content: space-between; }
.section-label button { border: 0; background: transparent; color: var(--muted); padding: 0; }
.story-row { width: 100%; display: flex; align-items: center; gap: 9px; text-align: left; border: 0; background: transparent; padding: 8px 9px; border-radius: 10px; color: var(--text); }
.story-row:hover, .story-row.selected { background: var(--panel-soft); }
.story-row > span:nth-child(2) { display: grid; min-width: 0; }
.story-row b { font-size: 12px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.story-row small { color: var(--faint); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.story-row em { margin-left: auto; color: var(--copper); font-size: 8px; font-style: normal; }
.story-avatar, .user-avatar, .message-avatar { flex: 0 0 auto; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-size: 17px; color: #f8efe4; border: 1px solid rgba(255,255,255,.24); box-shadow: inset 0 0 16px rgba(0,0,0,.18); }
.avatar-elara { background: linear-gradient(135deg, #58485a, #bf8b78); }
.avatar-riven { background: linear-gradient(135deg, #293d54, #8098ae); }
.avatar-moss { background: linear-gradient(135deg, #354738, #88916a); }
.sidebar-bottom { margin-top: auto; }
.user-mini { border-top: 1px solid var(--line); margin-top: 14px; padding: 14px 8px 0; display: grid; grid-template-columns: 32px 1fr 28px; align-items: center; gap: 9px; }
.user-mini > span:nth-child(2) { display: grid; }
.user-mini b { font-size: 12px; }
.user-mini small { font-size: 10px; color: var(--faint); }
.user-mini small strong { color: var(--copper-bright); font-weight: 600; }
.user-mini > button { border: 0; background: transparent; color: var(--muted); padding: 4px; }

.main-stage { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { min-height: 76px; display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(20px, 4vw, 58px); border-bottom: 1px solid var(--line); }
.breadcrumb { display: flex; align-items: center; gap: 9px; min-width: 0; font-size: 12px; }
.breadcrumb span { color: var(--faint); font-size: 10px; letter-spacing: .14em; font-weight: 700; }
.breadcrumb b { color: var(--line-strong); font-weight: 400; }
.breadcrumb strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.status-pill { color: var(--muted); font-size: 10px; border: 1px solid var(--line); border-radius: 30px; padding: 6px 9px; }
.status-pill i, .memory-live { color: var(--green); font-style: normal; }
.icon-button, .soft-button { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 8px; min-width: 32px; height: 32px; }
.icon-button:hover, .soft-button:hover { border-color: var(--line-strong); color: var(--text); background: var(--panel-soft); }
.view { display: none; flex: 1; }
.view.active { display: flex; }
.view-scene { flex-direction: column; padding: clamp(23px, 4vw, 52px) clamp(20px, 6vw, 92px) 32px; }
.scene-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; max-width: 1160px; width: 100%; margin: 0 auto 31px; }
.scene-header h1 { font-family: var(--display); font-size: clamp(29px, 4vw, 47px); font-weight: 500; line-height: 1.05; margin: 9px 0 11px; letter-spacing: -.035em; }
.scene-header h1 span { color: var(--muted); font-family: var(--body); font-size: .37em; letter-spacing: 0; vertical-align: middle; font-weight: 450; }
.scene-header p { max-width: 620px; margin: 0; color: var(--muted); font-size: 13px; }
.scene-controls { display: flex; gap: 9px; align-items: center; }
.select-wrap select { appearance: none; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 31px 8px 10px; font-size: 11px; }
.chat-layout { max-width: 1160px; width: 100%; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 50px; flex: 1; min-height: 0; }
.chat-column { min-width: 0; display: flex; flex-direction: column; }
.chapter-marker { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; margin: 0 0 25px; }
.chapter-marker i { height: 1px; flex: 1; background: var(--line); }
.messages { display: grid; gap: 25px; padding: 0 0 24px; overflow: auto; scrollbar-width: thin; }
.message { display: flex; align-items: flex-start; gap: 11px; animation: rise .35s var(--ease) both; }
.message-user { justify-content: flex-end; }
.message-user .message-body { max-width: min(75%, 560px); }
.message-assistant .message-body { max-width: min(85%, 650px); }
.message-meta { display: flex; align-items: center; gap: 9px; color: var(--faint); font-size: 10px; margin: 0 0 6px; }
.message-meta b { color: var(--copper-bright); font-weight: 650; }
.message-user .message-meta { justify-content: flex-end; }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 3px 16px 16px 16px; padding: 13px 16px; box-shadow: var(--shadow); }
.message-user .bubble { background: rgba(155,180,209,.11); border-color: rgba(155,180,209,.2); border-radius: 16px 3px 16px 16px; }
.bubble p { margin: 0; font-size: 14px; line-height: 1.75; white-space: pre-wrap; }
.bubble em { color: var(--muted); font-family: var(--display); font-size: 1.05em; }
.message-tools { opacity: 0; transition: opacity .2s ease; display: flex; gap: 7px; padding: 6px 3px 0; }
.message:hover .message-tools, .message-tools:focus-within { opacity: 1; }
.message-tools button { border: 0; color: var(--faint); background: transparent; padding: 2px 5px; font-size: 10px; }
.message-tools button:hover { color: var(--copper-bright); }
.composer { margin-top: auto; border: 1px solid var(--line-strong); background: var(--panel); border-radius: 15px; padding: 10px 12px 9px; box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.composer-tools, .composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 9px; }
.composer-tools > button { border: 0; background: transparent; color: var(--muted); padding: 2px 4px; }
.composer-hint { color: var(--faint); font-size: 10px; margin-right: auto; }
.composer textarea { width: 100%; resize: none; border: 0; background: transparent; color: var(--text); padding: 11px 0 12px; min-height: 63px; max-height: 180px; outline: none; }
.composer textarea::placeholder { color: var(--faint); }
.presence-picker { display: flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--muted); font-size: 11px; padding: 4px 0; }
.presence-picker b { color: var(--faint); }
.presence-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--copper); box-shadow: 0 0 9px var(--copper); }
.composer-right { display: flex; align-items: center; gap: 11px; }
.counter { color: var(--faint); font-family: var(--mono); font-size: 9px; }
.send-button { background: var(--copper); color: #1a1511; border: 0; width: 32px; height: 32px; border-radius: 10px; font-size: 18px; line-height: 1; transition: transform .2s var(--ease), background .2s var(--ease); }
.send-button:hover { background: var(--copper-bright); transform: translateY(-2px); }
.send-button:disabled { opacity: .45; cursor: wait; transform: none; }
.memory-panel { border-left: 1px solid var(--line); padding: 2px 0 0 24px; min-width: 0; }
.panel-heading { display: flex; justify-content: space-between; gap: 9px; }
.panel-heading h2 { font-family: var(--display); font-size: 22px; font-weight: 500; line-height: 1.1; margin: 9px 0 0; }
.close-panel { display: none; border: 0; background: transparent; color: var(--muted); font-size: 22px; }
.panel-note { color: var(--muted); font-size: 11px; line-height: 1.55; margin: 12px 0 24px; }
.memory-block { padding: 14px 0; border-top: 1px solid var(--line); }
.memory-label { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.memory-label button { border: 0; background: transparent; color: var(--copper-bright); font-size: 17px; padding: 0; }
.fact-card { display: flex; gap: 8px; align-items: flex-start; background: rgba(213,154,97,.08); border: 1px solid rgba(213,154,97,.18); border-radius: 9px; padding: 10px; }
.fact-card > span { color: var(--copper-bright); }
.fact-card p { margin: 0; font-size: 11px; line-height: 1.5; flex: 1; }
.fact-card button { border: 0; background: transparent; color: var(--faint); padding: 0; }
.scene-state { margin: 0; display: grid; gap: 9px; }
.scene-state div { display: flex; justify-content: space-between; gap: 9px; }
.scene-state dt, .scene-state dd { margin: 0; font-size: 11px; }
.scene-state dt { color: var(--faint); }
.scene-state dd { color: var(--muted); text-align: right; }
.scene-state dd.warm { color: var(--copper-bright); }
.summary-copy { color: var(--muted); font-family: var(--display); font-size: 14px; line-height: 1.55; margin: 0; }
.outline-button { border: 1px solid var(--line-strong); border-radius: 8px; background: transparent; color: var(--muted); padding: 9px 12px; font-size: 11px; }
.outline-button:hover { color: var(--text); border-color: var(--copper); }
.full { width: 100%; }

.empty-view, .settings-view, .profile-view { width: min(900px, calc(100% - 48px)); margin: auto; }
.empty-view { padding: 50px 0; text-align: center; }
.big-symbol { color: var(--copper); font-size: 34px; display: block; margin-bottom: 22px; }
.empty-view h2, .settings-view h2 { font-family: var(--display); font-size: clamp(32px, 5vw, 54px); font-weight: 500; letter-spacing: -.04em; margin: 10px 0 12px; }
.empty-view p { max-width: 480px; margin: 0 auto 25px; color: var(--muted); }
.primary-button { border: 0; color: #1d1611; background: var(--copper); border-radius: 9px; padding: 11px 16px; font-weight: 650; }
.discover-chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.discover-chips button { border: 1px solid var(--line); background: var(--panel); border-radius: 30px; color: var(--muted); padding: 9px 13px; }
.settings-view { padding: 70px 0; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 34px; }
.setting-card { text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 17px; display: grid; gap: 5px; transition: transform .2s var(--ease), border-color .2s var(--ease); }
.setting-card:hover { transform: translateY(-2px); border-color: var(--copper); }
.setting-card span { color: var(--copper); font-size: 22px; margin-bottom: 10px; }
.setting-card b { font-size: 14px; }
.setting-card small { color: var(--muted); }
.profile-view { padding: 50px 0; }
.profile-cover { height: 180px; border: 1px solid var(--line); border-radius: 18px 18px 0 0; background: radial-gradient(circle at 70% 30%, rgba(213,154,97,.4), transparent 15%), radial-gradient(circle at 30% 80%, rgba(155,180,209,.32), transparent 25%), #242029; }
.profile-card { display: flex; align-items: center; gap: 15px; background: var(--panel); border: 1px solid var(--line); border-top: 0; padding: 20px; position: relative; }
.profile-avatar { width: 64px; height: 64px; font-size: 29px; border: 2px solid var(--copper); margin-top: -48px; }
.profile-card h2 { margin: 6px 0; font-family: var(--display); font-weight: 500; font-size: 27px; }
.profile-card h2 span { color: var(--copper-bright); font-size: 14px; }
.profile-card p { margin: 0; color: var(--muted); font-size: 12px; }
.apx-card { margin-left: auto; display: grid; gap: 2px; text-align: right; }
.apx-card span { color: var(--faint); font-size: 10px; }
.apx-card strong { color: var(--copper-bright); font-family: var(--mono); font-size: 16px; }
.apx-card small { font-size: 10px; font-family: var(--body); }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 34px; }
.profile-grid > div:first-child { grid-column: 1/-1; }
.profile-grid h3 { font-family: var(--display); font-weight: 500; font-size: 28px; margin: 8px 0; }
.cosmetic-preview { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 16px; display: grid; grid-template-columns: 40px 1fr; column-gap: 10px; align-items: center; }
.cosmetic-preview small { grid-column: 2; color: var(--muted); font-size: 11px; }
.cosmetic-preview.rose { background: linear-gradient(135deg, rgba(142,102,125,.35), var(--panel)); }
.frame-orbit { width: 38px; height: 38px; border: 1px solid var(--copper); border-radius: 50%; display: grid; place-items: center; font-family: var(--display); box-shadow: 0 0 0 4px rgba(213,154,97,.12), 0 0 0 7px rgba(213,154,97,.07); }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 14px; color: var(--text); font-size: 12px; box-shadow: var(--shadow); transition: opacity .2s ease, transform .2s ease; z-index: 10; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.auth-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(8, 8, 10, .72); backdrop-filter: blur(18px); }
.auth-backdrop[aria-hidden="true"] { display: none; }
.auth-card { width: min(430px, 100%); padding: 30px; border: 1px solid var(--line-strong); border-radius: 18px; background: var(--panel-solid); box-shadow: 0 30px 100px rgba(0,0,0,.38); }
.auth-mark { display: flex; align-items: center; gap: 10px; color: var(--copper-bright); font-size: 11px; font-weight: 700; letter-spacing: .17em; margin-bottom: 30px; }
.auth-mark .brand-orbit { width: 24px; height: 24px; }
.auth-card h2 { font-family: var(--display); font-size: 34px; line-height: 1.05; font-weight: 500; letter-spacing: -.04em; margin: 9px 0 11px; }
.auth-copy { color: var(--muted); font-size: 12px; margin: 0 0 22px; }
.auth-tabs { display: flex; gap: 5px; border-bottom: 1px solid var(--line); margin-bottom: 19px; }
.auth-tab { border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); padding: 9px 4px; margin-right: 16px; font-size: 12px; }
.auth-tab.active { color: var(--text); border-color: var(--copper); }
.auth-field { display: grid; gap: 6px; margin: 12px 0; }
.auth-field span { color: var(--muted); font-size: 11px; }
.auth-field input { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-raised); color: var(--text); padding: 11px 12px; outline: none; }
.auth-field input:focus { border-color: var(--copper); }
.auth-submit { width: 100%; margin-top: 9px; }
.auth-error { min-height: 18px; color: var(--danger); font-size: 11px; margin: 12px 0 0; }
.auth-footnote { color: var(--faint); font-size: 10px; line-height: 1.5; margin: 19px 0 0; }
.presence-menu { position: fixed; left: 272px; bottom: 82px; width: 210px; background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 11px; padding: 12px; box-shadow: var(--shadow); opacity: 0; visibility: hidden; transform: translateY(7px); transition: .2s var(--ease); z-index: 12; }
.presence-menu.open { opacity: 1; visibility: visible; transform: translateY(0); }
.presence-menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 4px; color: var(--muted); font-size: 12px; border-radius: 5px; }
.presence-menu button:hover { color: var(--text); background: var(--panel-soft); }

@keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 1020px) { .app-shell { grid-template-columns: 215px minmax(0,1fr); } .chat-layout { grid-template-columns: 1fr; } .memory-panel { display: none; } .memory-panel.open { display: block; position: fixed; top: 76px; right: 0; bottom: 0; width: min(360px, 92vw); background: var(--bg-raised); z-index: 8; padding: 24px; box-shadow: var(--shadow); overflow: auto; } .close-panel { display: block; } }
@media (max-width: 700px) { body { font-size: 14px; } .app-shell { display: block; } .sidebar { min-height: auto; height: auto; padding: 14px 14px 10px; border-right: 0; border-bottom: 1px solid var(--line); } .brand-lockup { padding: 0 3px 14px; } .new-story { position: absolute; top: 12px; right: 14px; padding: 8px 10px; font-size: 0; } .new-story .plus { font-size: 21px; } .primary-nav { display: flex; overflow-x: auto; gap: 2px; padding-bottom: 2px; } .primary-nav .nav-item { flex: 0 0 auto; padding: 8px; font-size: 11px; } .primary-nav .nav-item span { width: auto; } .sidebar-section, .sidebar-bottom > .nav-item { display: none; } .user-mini { position: absolute; top: 16px; right: 65px; border: 0; padding: 0; grid-template-columns: 27px; } .user-mini > span:nth-child(2), .user-mini > button { display: none; } .user-mini .user-avatar { width: 27px; height: 27px; font-size: 14px; } .topbar { min-height: 57px; padding: 0 16px; } .status-pill { display: none; } .top-actions { gap: 5px; } .view-scene { padding: 24px 14px 18px; } .scene-header { display: block; margin-bottom: 22px; } .scene-controls { margin-top: 15px; } .chat-layout { display: block; } .message-user .message-body, .message-assistant .message-body { max-width: 88%; } .composer { position: sticky; bottom: 8px; margin-top: 16px; } .composer-hint { display: none; } .empty-view, .settings-view, .profile-view { width: calc(100% - 28px); } .settings-view { padding: 40px 0; } .settings-grid, .profile-grid { grid-template-columns: 1fr; } .profile-card { align-items: flex-start; flex-wrap: wrap; } .apx-card { margin-left: 0; width: 100%; text-align: left; } .presence-menu { left: 14px; bottom: 98px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }
