:root {
  /* The same palette as Leslie's console on the Mac. */
  --bg: #0e1013;
  --surface: #16191e;
  --raise: #1c2026;
  --ink: #e9e4d9;
  --muted: #8b8f97;
  --line: #262a31;
  --accent: #d98e4a;
  --accent-ink: #1b1712;
  --cream: #f4e1b5;
  --you: #1c2026;
  --you-ink: #e9e4d9;
  --good: #7fb58f;
  --danger: #c3674d;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.35);
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --sans: "Figtree", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(120% 70% at 50% 0%, #171a1f 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
}

/* Header */
.bar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(14, 16, 19, 0.92);
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
/* His face in the bar: glows while he's thinking, and moves his mouth while a reply is read aloud. */
.mark { position: relative; flex: none; width: 40px; height: 40px; border-radius: 50%; box-shadow: 0 0 0 1px rgb(217 142 74 / 0.35); transition: box-shadow 0.4s ease; }
.mark img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; display: block; }
.mark .talk { opacity: 0; transition: opacity 0.08s linear; }
.mark.talking .talk { opacity: 1; }
.mark.busy { animation: mark-glow 1.6s ease-in-out infinite; }
.mark.speaking { box-shadow: 0 0 0 1px rgb(217 142 74 / 0.6), 0 0 16px rgb(217 142 74 / 0.45); }
@keyframes mark-glow { 50% { box-shadow: 0 0 0 1px rgb(217 142 74 / 0.6), 0 0 18px rgb(217 142 74 / 0.5); } }
@media (prefers-reduced-motion: reduce) { .mark.busy { animation: none; box-shadow: 0 0 0 1px rgb(217 142 74 / 0.6), 0 0 12px rgb(217 142 74 / 0.4); } }
/* A new conversation: his face, waiting. */
.chat:has(#log:empty) { display: flex; flex-direction: column; }
#log:empty { display: grid; place-items: center; flex: 1; }
#log:empty::before { content: ""; width: min(56vw, 240px); aspect-ratio: 1; background: url("/face/neutral.webp") center / contain no-repeat; opacity: 0.85; }
.bar .title { font-family: var(--serif); font-weight: 600; font-size: 21px; line-height: 1.1; letter-spacing: 0.18em; text-transform: uppercase; color: var(--cream); }
.status { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.bad { color: var(--danger); }
/* A photo you asked Leslie to look at (shown here only; it isn't kept). */
.msg.you .snap { display: block; width: 100%; max-width: 220px; border-radius: 10px; margin-bottom: 6px; }
/* Running AI cost: small and quiet. */
.spend { font-size: 10.5px; line-height: 1.2; color: var(--muted); opacity: 0.8; font-variant-numeric: tabular-nums; white-space: nowrap; }
.spend.warn { color: #e0a43a; opacity: 1; }
.spend.over { color: var(--danger); opacity: 1; }
.actions { display: flex; gap: 4px; }

.icon-btn {
  width: 40px; height: 40px;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 12px;
  background: transparent; cursor: pointer;
}
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.icon-btn:focus-visible, .send:focus-visible, .primary:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn svg, .send svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#speak-toggle svg path:first-child { fill: currentColor; stroke: none; }
#speak-toggle[aria-pressed="false"] .waves { opacity: 0.25; }
#speak-toggle[aria-pressed="true"] { color: var(--accent); }

.menu {
  position: absolute; right: 12px; top: calc(100% + 6px); z-index: 5;
  min-width: 220px; max-width: calc(100vw - 24px);
  padding: 12px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow);
}
.menu-who { font-weight: 600; overflow-wrap: anywhere; color: var(--cream); }
.menu-note { font-size: 13px; color: var(--muted); margin: 2px 0 10px; }
.menu button { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: transparent; cursor: pointer; }
.menu button + button, .menu .menu-note + button { margin-top: 8px; }
.menu button:disabled { opacity: 0.6; cursor: default; }

/* Screens */
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.screen { margin: auto; padding: 32px 24px; text-align: center; max-width: 420px; }
.screen h1 { font-family: var(--serif); font-size: 32px; line-height: 1.15; margin: 16px 0 8px; font-weight: 600; color: var(--cream); text-wrap: balance; }
.screen p { color: var(--muted); margin: 0 0 24px; }
.screen ul { text-align: left; color: var(--muted); }
.hero-mark { width: min(56vw, 200px); height: auto; filter: drop-shadow(0 0 24px rgb(217 142 74 / 0.3)); }
.primary {
  padding: 12px 22px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer;
}
.primary:disabled { opacity: 0.6; cursor: default; }
.fine { font-size: 14px; color: var(--danger); margin-top: 16px !important; min-height: 1.5em; }

/* Chat */
.chat { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
/* Missions: background jobs from the Mac, shown above the chat */
.missions { display: grid; gap: 10px; padding: 12px 16px 0; }
.missions:empty { display: none; }
.mission { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); padding: 12px 14px; display: grid; gap: 7px; }
.mission.working, .mission.planning { border-color: var(--accent, #d98e4a); }
.mission .mh { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent, #d98e4a); font-weight: 600; }
.mission .mt { font-family: var(--serif); font-size: 18px; color: var(--cream); }
.mission ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; font-size: 14px; }
.mission li { display: grid; grid-template-columns: 18px 1fr; gap: 6px; }
.mission li .ic { color: var(--muted); text-align: center; }
.mission li.done .ic { color: #7fb58f; }
.mission li .n { display: block; font-size: 12px; color: var(--muted); }
.mission .mr { font-size: 14px; white-space: pre-wrap; }
.log { display: flex; flex-direction: column; gap: 14px; padding: 20px 16px 12px; }
.msg { max-width: 85%; overflow-wrap: anywhere; }
.msg p { margin: 0 0 0.6em; }
.msg p:last-child, .msg ul:last-child { margin-bottom: 0; }
.msg ul { margin: 0 0 0.6em; padding-left: 1.2em; }
.msg code { font: 0.9em ui-monospace, SFMono-Regular, Menlo, monospace; background: color-mix(in srgb, var(--ink) 8%, transparent); padding: 0.1em 0.3em; border-radius: 5px; }
.msg a { color: inherit; }
.msg.you {
  align-self: flex-end;
  background: var(--you); color: var(--you-ink); border: 1px solid var(--line);
  padding: 9px 14px; border-radius: 18px 18px 6px 18px;
  white-space: pre-wrap;
}
.msg.leslie { align-self: flex-start; padding: 2px 2px; }
.msg.leslie::before { content: "Leslie"; display: block; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.msg.leslie.thinking::after { content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 2px; border-radius: 50%; background: var(--muted); animation: pulse 1s ease-in-out infinite; }
.msg.error { align-self: center; color: var(--danger); font-size: 14px; text-align: center; }
.hello { margin: auto; text-align: center; color: var(--muted); padding: 40px 24px; }
.hello strong { display: block; color: var(--cream); font-family: var(--serif); font-size: 26px; margin-bottom: 4px; font-weight: 600; }
@keyframes pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .msg.leslie.thinking::after { animation: none; } }

/* Composer */
.composer {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: rgba(14, 16, 19, 0.92);
}
.composer textarea {
  flex: 1; resize: none; max-height: 160px;
  padding: 9px 14px; border: 1px solid var(--line); border-radius: 20px;
  background: var(--raise); color: var(--ink);
  font: inherit; font-size: 16px; line-height: 1.4;
}
.send {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
}
.send:disabled { opacity: 0.35; cursor: default; }
.mic.listening { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* Requests handed to the Mac (Phase 6) */
.task {
  align-self: stretch;
  border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); padding: 12px 14px;
  box-shadow: var(--shadow);
}
.task-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0.01em; }
.task-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.task.working .dot, .task.queued .dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.task.needs_approval { border-color: var(--accent); }
.task-head { text-transform: uppercase; letter-spacing: 0.1em; font-size: 12px; }
.task.needs_approval .dot { background: var(--cream); }
.task.sent .dot, .task.done .dot { background: var(--good); }
.task.failed .dot, .task.expired .dot { background: var(--danger); }
.task-body { margin-top: 8px; overflow-wrap: anywhere; }
.task-body p { margin: 0 0 0.5em; }
.task-body p:last-child { margin-bottom: 0; }
.task-note { font-size: 14px; color: var(--muted); margin-top: 6px; }
.task-bad { color: var(--danger); }
.draft-warning { margin-top: 10px; border-radius: 12px; padding: 8px 12px; font-size: 14px; color: var(--danger); border: 1px solid var(--danger); }
.draft { margin-top: 10px; border-radius: 12px; background: var(--raise); padding: 10px 12px; font-size: 15px; }
.draft dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0 0 8px; font-size: 14px; }
.draft dt { color: var(--muted); }
.draft dd { margin: 0; overflow-wrap: anywhere; }
.draft .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.task-actions { display: flex; gap: 8px; margin-top: 10px; }
.task-actions button { flex: 1; padding: 10px 14px; border-radius: 999px; font-weight: 600; cursor: pointer; border: 1px solid var(--line); background: transparent; }
.task-actions .approve { background: var(--cream); color: var(--accent-ink); border-color: var(--cream); }
.task-actions button:disabled { opacity: 0.55; cursor: default; }
.task.highlight { outline: 2px solid var(--accent); outline-offset: 2px; }
.pending-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 6px 2px -4px; }
@media (prefers-reduced-motion: reduce) { .task .dot { animation: none !important; } }

/* Kill switch banner (Phase 7) */
.banner {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  margin: 10px 16px 0; padding: 10px 12px 10px 14px; border-radius: 14px;
  background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); font-size: 14px;
}
.banner button { flex: none; padding: 7px 14px; border-radius: 999px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; }

/* Activity screen (Phase 7) */
.screen-full { flex: 1; min-height: 0; overflow-y: auto; }
.activity-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px 0; }
.activity-head h2 { font-family: var(--serif); font-size: 26px; margin: 0; font-weight: 600; color: var(--cream); }
.activity-list { padding: 8px 16px 24px; }
.activity-day { font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 2px 6px; }
.activity-item { display: grid; grid-template-columns: 22px 1fr auto; gap: 4px 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); align-items: start; }
.activity-item .icon { font-size: 15px; line-height: 1.4; text-align: center; }
.activity-item .title { font-weight: 550; overflow-wrap: anywhere; }
.activity-item .detail { grid-column: 2 / 4; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.activity-item .time { color: var(--muted); font-size: 13px; white-space: nowrap; }
.activity-empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* Brain map (read-only copy of the Mac's; drawn by brain.js) */
.brain { position: relative; flex: 1; min-height: 0; overflow: hidden; background: radial-gradient(90% 80% at 50% 45%, #171a1f 0%, var(--bg) 100%); }
.brain canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.pill { cursor: pointer; font-size: 13px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); }
.pill.open { border-color: var(--accent); color: var(--ink); }
.x { cursor: pointer; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; width: 32px; height: 32px; color: var(--muted); font-size: 18px; line-height: 1; }
.bm-top { position: absolute; top: 10px; left: 12px; right: 12px; display: flex; gap: 8px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; pointer-events: none; }
.bm-top > * { pointer-events: auto; }
.bm-search { position: relative; width: min(340px, 100%); }
.bm-search input { width: 100%; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: rgba(22, 25, 30, 0.92); color: var(--ink); font: inherit; font-size: 16px; }
.bm-search input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.bm-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 2; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; display: grid; max-height: 50vh; overflow-y: auto; }
.bm-results button { display: flex; align-items: center; gap: 8px; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--ink); }
.bm-results button:hover, .bm-results button:focus-visible { background: var(--raise); }
.bm-results i, .bm-legend i { flex: none; width: 8px; height: 8px; border-radius: 50%; }
.bm-none { padding: 8px 10px; color: var(--muted); font-size: 14px; }
.bm-tools { display: flex; gap: 6px; align-items: center; }
/* Hint and legend share one footer and stack, so a legend that wraps to two lines never runs into the hint. */
.bm-foot { position: absolute; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.bm-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.bm-legend span { display: inline-flex; align-items: center; gap: 6px; }
.bm-when { position: absolute; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); font-family: var(--serif); font-size: 22px; font-style: italic; color: var(--cream); pointer-events: none; white-space: nowrap; }
.bm-hint { font-size: 12px; color: var(--muted); opacity: 0.8; }
.bm-empty { position: absolute; left: 50%; top: 60%; transform: translateX(-50%); width: min(420px, 100% - 32px); text-align: center; color: var(--muted); font-size: 15px; }
.bm-card { z-index: 2; position: absolute; left: 12px; right: 12px; bottom: 56px; margin-left: auto; max-width: 360px; background: rgba(22, 25, 30, 0.96); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: grid; gap: 6px; }
.bm-kind { font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; }
.bm-text { font-family: var(--serif); font-size: 19px; line-height: 1.35; color: var(--cream); overflow-wrap: anywhere; }
.bm-meta { font-size: 12px; color: var(--muted); }
.bm-acts { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 2px; }
.bm-chain { margin: 2px 0 0; padding-left: 20px; font-size: 14px; display: grid; gap: 2px; }

/* Files from the phone */
.uploads { padding-top: 0; }
.uploads:empty { display: none; }
.task.upload .facts { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.task.upload .facts label { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; cursor: pointer; padding: 3px 0; }
.task.upload .facts input { accent-color: var(--accent); margin-top: 4px; flex: none; width: 18px; height: 18px; }
.task-head .fname { text-transform: none; letter-spacing: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
