/* David on the web. Same dark brown and orange amber as the phone and David Desktop.
   Phone width first: a bottom tab bar and a slide-out chat list. Wide screens: a side column. */
:root {
  --bg: #16100B;
  --surface: #1E1610;
  --surface2: #2A1F16;
  --raised: #33261B;
  --line: #3A2B1E;
  --accent: #D97A1A;
  --accent-text: #F29A4E;
  --on-accent: #16100B;
  --text: #F6EFE6;
  --muted: #C4B5A3;
  --faint: #9A8875;
  --good: #7FB685;
  --danger: #EF6B66;
  --ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "Cascadia Code", Consolas, ui-monospace, monospace;
  --tabbar: 62px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.55 var(--ui); -webkit-font-smoothing: antialiased; overflow: hidden; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0; text-wrap: balance; }
h1 { font-size: 26px; letter-spacing: -0.01em; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--faint); margin: 28px 0 10px; }
p { margin: 0; }
a { color: var(--accent-text); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.hint { color: var(--faint); font-size: 13px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.primary { background: var(--accent); color: var(--on-accent); font-weight: 600; padding: 12px 18px; border-radius: 12px; min-height: 48px; }
.primary:hover { filter: brightness(1.08); }
.ghost { border: 1px solid var(--line); padding: 9px 14px; border-radius: 12px; color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; }
.ghost:hover { background: var(--surface2); }
.ghost.on { border-color: var(--accent); color: var(--accent-text); }
.wide { width: 100%; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface2); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--accent-text); background: var(--surface2); }

input[type=text], input[type=search], textarea {
  width: 100%; background: var(--surface2); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 13px; font: inherit; font-size: 16px;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
label { display: block; color: var(--muted); font-size: 14px; margin: 16px 0 6px; }
.switch { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 15px; margin: 12px 0; cursor: pointer; }
.switch input { accent-color: var(--accent); width: 20px; height: 20px; }
.row-input { display: flex; gap: 8px; }
.row-input > input { flex: 1; min-width: 0; }

.boot { height: 100%; display: grid; place-items: center; color: var(--muted); }

/* ----- sign in ----- */
.signin { height: 100%; overflow-y: auto; display: grid; place-items: center; padding: 24px 16px; }
.signin-card { width: min(400px, 100%); }
.logo { width: 56px; height: 56px; margin-bottom: 14px; }
.signin-card h1 { margin-bottom: 6px; }
.signin-card #code { font-family: var(--mono); letter-spacing: 0.18em; text-transform: uppercase; font-size: 20px; text-align: center; }
.signin-card .primary { margin-top: 18px; }
.signin-card .hint { margin-top: 10px; }

/* ----- frame ----- */
.app { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.top { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--bg); position: relative; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 600; font-size: 18px; }
.brand img { width: 28px; height: 28px; }
.top-gap { flex: 1; }
.brain-note { color: var(--faint); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.me-btn { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 4px; border-radius: 999px; min-height: 44px; }
.me-btn:hover { background: var(--surface2); }
.avatar-dot { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-weight: 700; }
.popover { position: absolute; right: 12px; top: calc(100% + 6px); width: min(300px, calc(100vw - 24px)); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: grid; gap: 8px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); }

.layout { min-height: 0; display: grid; grid-template-columns: 280px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "tabs main" "side main"; }
.layout > .view { grid-area: main; }
.side { grid-area: side; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { grid-area: tabs; display: flex; gap: 4px; padding: 10px; background: var(--surface); border-right: 1px solid var(--line); }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border-radius: 12px; color: var(--faint); font-size: 12.5px; min-height: 52px; }
.tab:hover { color: var(--text); background: var(--surface2); }
.tab.on { color: var(--accent-text); background: var(--surface2); }
.side-chats { display: flex; flex-direction: column; min-height: 0; flex: 1; padding: 4px 10px 12px; }
.list-label { color: var(--faint); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; padding: 16px 8px 6px; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-item { display: flex; align-items: center; border-radius: 10px; }
.chat-item:hover, .chat-item.on { background: var(--surface2); }
.chat-item .open { flex: 1; min-width: 0; text-align: left; padding: 10px; min-height: 44px; color: var(--muted); font-size: 14.5px; }
.chat-item .open span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .open small { color: var(--faint); font-size: 12px; }
.chat-item.on .open { color: var(--text); }
.chat-item .del { width: 40px; height: 40px; color: var(--faint); border-radius: 10px; display: grid; place-items: center; opacity: 0; }
.chat-item:hover .del, .chat-item .del:focus-visible, .chat-item.on .del { opacity: 1; }
.chat-item .del:hover { color: var(--danger); }
.chat-item .del svg { width: 18px; height: 18px; }
.scrim { display: none; }
.only-narrow { display: none; }

.view { min-height: 0; min-width: 0; }

/* ----- chat ----- */
.chat { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: 100%; }
.messages { overflow-y: auto; padding: 20px 16px 24px; }
.empty { max-width: 560px; margin: 8vh auto 0; text-align: center; }
.empty h1 { margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 9px 14px; color: var(--muted); font-size: 14.5px; min-height: 44px; }
.chip:hover { color: var(--text); background: var(--surface2); }
.msg { max-width: 760px; margin: 0 auto 20px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--surface2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 18px 18px 4px 18px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .files-note { color: var(--faint); font-size: 12.5px; margin-top: 4px; }
.msg.david { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; }
.msg.david .av { width: 28px; height: 28px; margin-top: 2px; }
.msg.david .body { min-width: 0; overflow-wrap: anywhere; }
.body p { margin: 0 0 10px; }
.body ul, .body ol { margin: 0 0 10px; padding-left: 22px; }
.body li { margin: 3px 0; }
.body h4 { font-size: 16px; margin: 14px 0 6px; }
.body code { font-family: var(--mono); font-size: 13.5px; background: var(--surface2); padding: 1px 5px; border-radius: 5px; }
.body pre { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow-x: auto; }
.body pre code { background: none; padding: 0; }
.tool-note { color: var(--faint); font-size: 13px; margin-bottom: 6px; }
.thinking { display: inline-flex; gap: 5px; padding: 8px 0; }
.thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-text); opacity: 0.35; animation: pulse 1.2s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: 0.15s; }
.thinking i:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 50% { opacity: 1; } }
.msg .fail { color: var(--danger); }

.composer { border-top: 1px solid var(--line); padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--bg); }
.composer-row { max-width: 800px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px; background: var(--surface2); border: 1px solid var(--line); border-radius: 18px; padding: 4px; }
.composer-row:focus-within { border-color: var(--accent); }
.composer textarea { border: 0; background: transparent; resize: none; max-height: 200px; padding: 10px 6px; outline: none; }
.composer textarea:focus-visible { outline: none; }
.send { width: 44px; height: 44px; border-radius: 14px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: 0.4; cursor: default; }
.composer .hint { max-width: 800px; margin: 6px auto 0; min-height: 18px; }
.files { max-width: 800px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.files:empty { display: none; }
.file-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 4px 2px 12px; font-size: 13.5px; color: var(--muted); max-width: 100%; }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; }
.file-chip svg { width: 16px; height: 16px; }

/* ----- pages: home and memory ----- */
.page { overflow-y: auto; height: 100%; }
.page-inner { max-width: 760px; margin: 0 auto; padding: 22px 16px 40px; }
.page-inner > .muted { margin-top: 6px; }
.rows { display: grid; gap: 8px; }
.row { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row .grow { flex: 1; min-width: 160px; }
.row .name { font-weight: 600; }
.row .sub { color: var(--faint); font-size: 13.5px; }
.row .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.row input[type=range] { width: 140px; accent-color: var(--accent); }
.state-on { color: var(--good); }
.journal { display: grid; gap: 4px; }
.day { color: var(--faint); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.08em; margin: 14px 0 4px; }
.entry { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.entry time { color: var(--faint); font-size: 13px; }
.entry .where { color: var(--faint); font-size: 12px; margin-left: 6px; }

/* ----- phone width ----- */
@media (max-width: 860px) {
  .only-wide { display: none; }
  .only-narrow { display: grid; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "main"; padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: min(320px, 86vw); z-index: 50; transform: translateX(-105%); transition: transform 0.2s ease; padding-top: env(safe-area-inset-top); }
  .side.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 40; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding: 4px 8px env(safe-area-inset-bottom); border-right: 0; border-top: 1px solid var(--line); z-index: 35; }
  .messages { padding: 16px 12px 20px; }
  .msg.david { grid-template-columns: minmax(0, 1fr); }
  .msg.david .av { display: none; }
  .brain-note { max-width: 32vw; }
}
@media (prefers-reduced-motion: reduce) {
  .side { transition: none; }
  .thinking i { animation: none; opacity: 0.8; }
}

/* Stage 18: accounts */
.link { color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px; padding: 4px 0; font-size: 13px; }
a.ghost { text-decoration: none; }
input[type=email], input[type=password] {
  width: 100%; background: var(--surface2); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 13px; font: inherit; font-size: 16px;
}

/* thumbs on David's answers (Stage 20) */
.vote { display: flex; align-items: center; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg:hover .vote, .vote.voted, .vote:focus-within { opacity: 1; }
.vote button { color: var(--faint); padding: 4px 7px; border-radius: 6px; line-height: 0; background: none; border: 0; cursor: pointer; }
.vote button:hover { color: var(--text); background: var(--surface2); }
.vote button[aria-pressed="true"] { color: var(--accent); }
.vote button.down svg { transform: scaleY(-1); }
.vote svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.vote-note { color: var(--faint); font-size: 12.5px; margin-left: 6px; }
@media (hover: none) { .vote { opacity: 1; } }

/* Stage 23: install David as a desktop app */
.install-card { position: fixed; z-index: 60; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(560px, calc(100% - 32px)); display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 4px 14px; align-items: start;
  background: var(--surface); border: 1px solid var(--accent); border-radius: 16px; padding: 16px 18px; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45); }
.install-card img { width: 44px; height: 44px; }
.install-card h2 { font-size: 17px; margin: 0 0 4px; }
.install-card p { margin: 0; color: var(--muted); font-size: 14px; }
.install-acts { grid-column: 2; display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
