:root {
  --bg: #181716;
  --panel: #211f1e;
  --panel-2: #292725;
  --ink: #f4efe8;
  --muted: #aaa39b;
  --line: #393634;
  --accent: #e98545;
  --accent-strong: #f39757;
  --green: #8aaa90;
  --error: #ffaaa0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, textarea, select { font: inherit; }
button { border: 0; color: inherit; cursor: pointer; }
button:disabled { cursor: wait; opacity: .5; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 400; }
code { color: #f4bc91; }
input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 12px;
  background: #242220;
  color: var(--ink);
}
label { display: block; margin: 17px 0 8px; font-size: 12px; font-weight: 600; }
label small { margin-left: 7px; color: var(--muted); font-weight: 400; }
.eyebrow { margin-bottom: 9px; color: var(--accent); font-size: 9px; font-weight: 700; letter-spacing: 1.7px; }
.fine { color: var(--muted); font-size: 11px; line-height: 1.6; }
.muted { color: var(--muted); }
.brand { display: flex; align-items: center; gap: 10px; font-family: Georgia, serif; font-size: 21px; letter-spacing: -.4px; }
.brand-mark {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: #211d1a;
  font-size: 23px;
  font-style: italic;
  font-weight: 700;
}
.primary {
  border-radius: 9px;
  background: var(--accent);
  color: #1d1917;
  padding: 12px 17px;
  font-weight: 700;
}
.primary:hover { background: var(--accent-strong); }

.welcome { min-height: 100dvh; display: grid; place-items: center; padding: 34px 20px; }
.welcome-card { width: min(100%, 470px); text-align: center; }
.welcome-brand { justify-content: center; margin-bottom: 76px; }
.welcome-copy h1 { margin: 15px 0 20px; font-size: clamp(42px, 6vw, 59px); line-height: 1.05; letter-spacing: -2px; }
.lead { margin-bottom: 34px; color: var(--muted); font-size: 14px; line-height: 1.75; }
.welcome-card > label { text-align: left; }
.guest-button { display: flex; width: 100%; justify-content: space-between; margin-top: 12px; }
.scope-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin-top: 30px; }
.scope-chips span { border: 1px solid var(--line); border-radius: 20px; padding: 6px 10px; color: #c3bcb5; font-size: 10px; }
.welcome-fine { margin: 19px 0 8px; }
.ai-note { color: #79736d; font-size: 10px; }

.workspace { height: 100dvh; display: grid; grid-template-columns: 210px minmax(0, 1fr) auto; overflow: hidden; }
.sidebar { display: flex; min-height: 0; flex-direction: column; padding: 23px 14px 15px; border-right: 1px solid var(--line); background: #1d1c1b; }
.sidebar > .brand { padding: 0 7px; }
.companion-state {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  margin: 29px 0 14px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #23211f;
}
.companion-state small { display: block; color: var(--muted); font-size: 7px; letter-spacing: 1px; }
.companion-state strong { display: block; margin-top: 3px; font-size: 10px; font-weight: 500; }
.companion-state em { color: var(--green); font-size: 7px; font-style: normal; letter-spacing: 1px; }
.status-orb { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px #8aaa901a; }
.new-chat { width: 100%; border-radius: 8px; padding: 10px 12px; background: var(--accent); color: #211d1a; font-size: 11px; font-weight: 700; text-align: left; }
.new-chat span { margin-right: 8px; font-size: 17px; }
.section-label { margin: 25px 8px 9px; color: #716c66; font-size: 8px; font-weight: 700; letter-spacing: 1.3px; }
#conversation-list { flex: 1; min-height: 40px; overflow-y: auto; }
#conversation-list button { display: block; width: 100%; overflow: hidden; margin: 2px 0; padding: 10px; border-radius: 7px; background: transparent; color: #97918a; font-size: 10px; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
#conversation-list button:hover, #conversation-list button.active { background: #2b2927; color: var(--ink); }
.sidebar-bottom { padding-top: 10px; border-top: 1px solid var(--line); }
.side-action { display: flex; width: 100%; align-items: center; gap: 9px; padding: 9px 8px; border-radius: 7px; background: transparent; color: #aaa49d; font-size: 10px; text-align: left; }
.side-action:hover { background: #292725; color: var(--ink); }
.side-action .count { margin-left: auto; }
.profile { display: flex; align-items: center; gap: 9px; margin-top: 8px; padding: 11px 7px 0; border-top: 1px solid var(--line); font-size: 10px; }
.profile small { display: block; margin-top: 2px; color: #77716b; font-size: 8px; }
.avatar { display: grid; width: 27px; height: 27px; place-items: center; border-radius: 50%; background: #3b3734; color: #d6cfc8; font-family: Georgia, serif; }

.main { display: flex; min-width: 0; min-height: 0; flex-direction: column; background: var(--bg); }
.topbar { display: flex; height: 58px; flex-shrink: 0; align-items: center; justify-content: space-between; padding: 0 24px; border-bottom: 1px solid var(--line); }
.session-title strong { display: block; max-width: 420px; overflow: hidden; font-size: 11px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.session-title span { color: #77716b; font-size: 8px; }
.top-actions { display: flex; align-items: center; gap: 7px; }
.quick-language {
  width: auto;
  min-width: 88px;
  border-radius: 20px;
  padding: 7px 28px 7px 11px;
  background-color: #211f1e;
  color: #c2bbb4;
  font-size: 10px;
}
.quiet, .memory-button { border: 1px solid var(--line); border-radius: 20px; background: #211f1e; color: #b5aea8; font-size: 10px; }
.quiet { display: none; width: 32px; height: 32px; }
.memory-button { padding: 7px 11px; }
.memory-button > span:first-child { margin-right: 4px; color: var(--accent); }
.count { border-radius: 12px; background: #3a3531; padding: 2px 6px; font-size: 8px; }
.chat-scroll { min-height: 0; flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.empty-chat { width: min(100%, 720px); margin: 0 auto; padding: clamp(54px, 11vh, 110px) 32px 25px; text-align: center; }
.spark { margin-bottom: 21px; color: var(--accent); font-size: 32px; }
.empty-chat h1 { margin: 11px 0 15px; font-size: clamp(34px, 5vw, 51px); line-height: 1.12; letter-spacing: -1.6px; }
.empty-chat > p:not(.eyebrow) { color: var(--muted); font-size: 12px; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; margin-top: 29px; }
.suggestions button { display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 20px; padding: 8px 12px; background: #201e1d; color: #b6afa8; font-size: 9px; }
.suggestions button:hover { border-color: #675243; color: var(--ink); }
.suggestions button span { color: var(--accent); }
.messages { display: flex; width: min(100%, 740px); flex-direction: column; gap: 19px; margin: auto; padding: 30px 28px; }
.bubble { max-width: 84%; overflow-wrap: anywhere; color: #ddd7d0; font-size: 13px; line-height: 1.7; white-space: pre-wrap; }
.bubble.user { align-self: flex-end; border-radius: 15px 15px 3px 15px; background: #302d2a; padding: 11px 15px; }
.bubble.assistant { align-self: flex-start; padding: 2px 5px 2px 0; }
.bubble.assistant::before { content: "MELEN"; display: block; margin-bottom: 6px; color: var(--accent); font-size: 7px; font-weight: 700; letter-spacing: 1.4px; }
.bubble.draft { opacity: .6; }
.bubble.failed { border-left: 2px solid #b7675e; padding-left: 10px; }
.bubble.searching { color: #c9a98f; }
.source-link { color: #e9a574; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.source-link:hover { color: #ffc49b; }
.turn-note { color: var(--muted); font-size: 10px; white-space: normal; }
.retry { display: block; margin-top: 7px; border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; background: #262321; color: #f2a36d; }
.composer-area { width: min(100%, 780px); flex-shrink: 0; margin: auto; padding: 9px 26px 17px; }
.composer { display: flex; align-items: center; gap: 7px; border: 1px solid #413d39; border-radius: 13px; background: #252321; padding: 8px; box-shadow: 0 8px 30px #0002; }
.composer textarea { min-width: 0; max-height: 105px; flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 12px; line-height: 1.5; }
.composer textarea::placeholder { color: #77716b; }
.round { display: grid; width: 33px; height: 33px; flex-shrink: 0; place-items: center; border-radius: 9px; background: #302d2a; color: #aaa39c; font-size: 16px; }
.mic.listening { background: #415846; color: #d8f3dc; box-shadow: 0 0 0 3px #8aaa901b; }
.speaker.active { color: var(--accent); }
.send { background: var(--accent); color: #211d1a; font-size: 19px; }
.stop { background: #51332d; color: #ffc1ae; }
.composer-meta { display: flex; justify-content: space-between; gap: 12px; padding: 9px 3px 0; color: #6f6964; font-size: 8px; }
.connection-note { padding: 8px 24px; background: #3a2d21; color: #e5b28c; font-size: 10px; line-height: 1.5; }
.due-banner { display: flex; align-items: center; justify-content: space-between; gap: 9px; padding: 8px 24px; background: #28332a; color: #b9d9bd; font-size: 10px; }
.due-banner button { background: transparent; color: inherit; text-decoration: underline; }
.error { margin: 0 0 8px; border: 1px solid #6b3d38; border-radius: 7px; background: #3d2825; color: var(--error); padding: 8px 11px; font-size: 10px; line-height: 1.5; }

.memory-drawer { width: 270px; min-height: 0; overflow-y: auto; padding: 20px 18px; border-left: 1px solid var(--line); background: #1e1c1b; }
.memory-drawer:not(.open) { display: none; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; }
.drawer-head h2 { margin: 0 0 18px; font-size: 24px; }
.memory-preview-list { margin: 18px 0; }
.outline-button { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: transparent; color: #c9c1ba; font-size: 10px; }
.close { background: transparent; color: var(--muted); font-size: 24px; line-height: 1; }

.panel { width: min(520px, calc(100% - 28px)); max-height: 88dvh; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; padding: 0; background: #211f1e; color: var(--ink); box-shadow: 0 24px 100px #0008; }
.panel::backdrop { background: #080706aa; backdrop-filter: blur(4px); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 22px 24px 15px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 26px; }
.panel-body { max-height: calc(88dvh - 85px); overflow-y: auto; padding: 19px 24px 25px; }
.panel .primary { width: 100%; margin: 13px 0; }
.panel h3 { font-size: 13px; font-weight: 600; }
.panel hr { margin: 24px 0; border: 0; border-top: 1px solid var(--line); }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.checkbox input { width: auto; }
.saved-item { display: flex; align-items: flex-start; gap: 8px; margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; padding: 11px; background: #252321; font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.saved-item .item-text { min-width: 0; flex: 1; }
.saved-item small { display: block; color: var(--muted); font-size: 9px; }
.saved-item button { padding: 4px; background: transparent; color: #efa06b; font-size: 9px; }
.saved-item.due { border-color: #627d67; background: #263027; }
.danger { padding: 9px 0; background: transparent; color: #e78a7e; font-size: 10px; }
.proposal { width: min(390px, 100%); align-self: flex-start; border: 1px solid #594b3e; border-radius: 11px; padding: 15px; background: #292621; font-size: 11px; }
.proposal h3 { margin-bottom: 7px; font-size: 12px; font-weight: 600; }
.proposal p { line-height: 1.6; }
.proposal small { color: var(--muted); }
.proposal label { margin-top: 9px; font-size: 9px; }
.proposal .actions { display: flex; gap: 8px; margin-top: 12px; }
.proposal .actions button { border-radius: 7px; padding: 8px 11px; background: #37322e; }
.proposal .actions button.primary { background: var(--accent); color: #211d1a; }
.memory-note { align-self: flex-start; border-radius: 18px; padding: 7px 10px; background: #263027; color: #add0b2; font-size: 9px; }
.toast { position: fixed; z-index: 20; bottom: 22px; left: 50%; max-width: 90%; transform: translateX(-50%); border: 1px solid #61584f; border-radius: 9px; padding: 10px 16px; background: #312e2b; color: var(--ink); box-shadow: 0 6px 25px #0006; font-size: 11px; }
#mobile-history { display: none; }

@media (max-width: 1040px) {
  .memory-drawer { position: fixed; z-index: 10; top: 0; right: 0; height: 100dvh; box-shadow: -16px 0 45px #0007; }
}
@media (max-width: 700px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 55px minmax(0, 1fr); }
  .sidebar { grid-row: 1; flex-direction: row; align-items: center; gap: 9px; padding: 9px 13px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar > .brand { padding: 0; }
  .sidebar .brand-mark { width: 27px; height: 27px; font-size: 19px; }
  .sidebar .brand { font-size: 17px; }
  .companion-state, .section-label, #conversation-list, .sidebar-bottom { display: none; }
  .new-chat { width: auto; margin-left: auto; padding: 7px 9px; font-size: 9px; }
  .main { grid-row: 2; }
  .topbar { height: 52px; padding: 0 14px; }
  .session-title strong { max-width: 180px; }
  .quiet { display: grid; place-items: center; }
  .memory-button { padding: 7px 9px; }
  .quick-language { min-width: 74px; max-width: 92px; padding-left: 8px; }
  #mobile-history { display: block; width: calc(100% - 28px); margin: 7px 14px 0; padding: 7px 9px; flex-shrink: 0; border: 1px solid var(--line); border-radius: 7px; background: #211f1e; color: var(--muted); font-size: 9px; }
  .empty-chat { padding: 43px 18px 18px; }
  .empty-chat h1 { font-size: 35px; }
  .suggestions { display: grid; grid-template-columns: 1fr; }
  .suggestions button { justify-content: space-between; }
  .messages { padding: 22px 17px; }
  .bubble { max-width: 92%; }
  .composer-area { padding: 7px 10px 11px; }
  .composer { gap: 5px; padding: 6px; }
  .round { width: 31px; height: 31px; }
  .composer-meta span:last-child { display: none; }
  .memory-drawer { width: min(88vw, 300px); }
  .connection-note, .due-banner { padding: 7px 14px; }
}
@media (max-height: 650px) and (min-width: 701px) {
  .empty-chat { padding-top: 35px; }
  .welcome-brand { margin-bottom: 35px; }
}
@media (prefers-reduced-motion: reduce) { .chat-scroll { scroll-behavior: auto; } }
