/* Every colour derives from one hue: the one the system chose for itself
   when it first woke up. Before that the page is grey. */
:root {
  --hue: 264;
  --chroma: 0;

  --bg: oklch(97.5% calc(var(--chroma) * 0.07) var(--hue));
  --surface: oklch(99.6% calc(var(--chroma) * 0.02) var(--hue));
  --raise: oklch(94.2% calc(var(--chroma) * 0.11) var(--hue));
  --ink: oklch(24% calc(var(--chroma) * 0.3) var(--hue));
  --muted: oklch(49% calc(var(--chroma) * 0.22) var(--hue));
  --faint: oklch(64% calc(var(--chroma) * 0.18) var(--hue));
  --line: oklch(89% calc(var(--chroma) * 0.14) var(--hue));
  --accent: oklch(54% var(--chroma) var(--hue));
  --on-accent: oklch(99% 0.01 var(--hue));
  --danger: oklch(52% 0.19 27);

  --bar: 52px;
  --panel: 420px;
  --gap: 16px;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: oklch(16% calc(var(--chroma) * 0.12) var(--hue));
  --surface: oklch(20.5% calc(var(--chroma) * 0.14) var(--hue));
  --raise: oklch(26% calc(var(--chroma) * 0.18) var(--hue));
  --ink: oklch(94% calc(var(--chroma) * 0.08) var(--hue));
  --muted: oklch(73% calc(var(--chroma) * 0.14) var(--hue));
  --faint: oklch(56% calc(var(--chroma) * 0.14) var(--hue));
  --line: oklch(31% calc(var(--chroma) * 0.2) var(--hue));
  --accent: oklch(77% calc(var(--chroma) * 0.9) var(--hue));
  --on-accent: oklch(18% 0.03 var(--hue));
  --danger: oklch(72% 0.16 27);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- the bar across the top ------------------------------------------------ */

.bar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  height: calc(var(--bar) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--gap), env(safe-area-inset-right)) 0 max(var(--gap), env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 12px;
  background: color-mix(in oklab, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex: none; }
.mark { width: 24px; height: 24px; color: var(--accent); flex: none; }
.name { font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }

.status {
  flex: 1 1 0;
  min-width: 0;
  color: var(--muted);
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--faint); vertical-align: 1px; }
.status[data-mode="listening"]::before, .status[data-mode="hearing"]::before { background: var(--accent); }
.status[data-mode="thinking"]::before, .status[data-mode="speaking"]::before { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.status[data-mode="offline"]::before { background: var(--danger); }
.status:empty::before { display: none; }
@keyframes pulse { 50% { opacity: 0.3; } }

.bar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  font-size: 0.875rem;
  font-weight: 550;
  white-space: nowrap;
}
.btn:hover { background: var(--raise); }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn.icon { width: 34px; padding: 0; }
.btn.small { height: 28px; padding: 0 9px; font-size: 0.8125rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn[aria-expanded="true"] { background: var(--raise); }

.seg { display: inline-flex; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.seg button { width: 30px; border: 0; border-radius: 6px; background: none; color: var(--muted); display: grid; place-items: center; padding: 0; }
.seg button svg { width: 16px; height: 16px; }
.seg button[aria-pressed="true"] { background: var(--raise); color: var(--ink); }

/* --- the stage: the face, what is being said, the controls ----------------- */

.stage {
  position: fixed;
  inset: calc(var(--bar) + env(safe-area-inset-top)) 0 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 max(var(--gap), env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(var(--gap), env(safe-area-inset-left));
  overflow: hidden;
}

.face {
  position: relative;
  flex: 1 1 0;
  min-height: 120px;
  width: 100%;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  border-radius: var(--radius);
}
#presence { position: absolute; inset: 0; margin: auto; width: min(100%, 560px); height: min(100%, 560px); color: var(--accent); display: block; }

.caption { width: min(100%, 720px); text-align: center; flex: none; min-height: 7.4rem; display: flex; flex-direction: column; justify-content: flex-end; }
.heard {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.9375rem;
  min-height: 1.5em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl; /* keep the end of a long line in view … */
}
.heard > span { direction: ltr; unicode-bidi: isolate; } /* … without changing its reading order */
.heard.live { color: var(--faint); }
.said-box { max-height: 4.2em; font-size: clamp(1.25rem, 0.9rem + 1.6vw, 1.75rem); line-height: 1.4; overflow: hidden; display: flex; flex-direction: column-reverse; }
.said { margin: 0; font-weight: 500; letter-spacing: -0.012em; text-wrap: pretty; }
.said .ahead { color: var(--faint); }

.cards { width: min(100%, 720px); flex: none; display: flex; flex-direction: column; gap: 8px; margin-top: 10px; max-height: 38vh; overflow-y: auto; }
.cards:empty { display: none; }

.type { width: min(100%, 720px); display: flex; gap: 8px; margin-top: 12px; flex: none; }
.type input { flex: 1; min-width: 0; height: 42px; padding: 0 14px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); font-size: 1rem; }
.type .btn { height: 42px; padding: 0 16px; }

.dock { display: flex; align-items: flex-end; justify-content: center; gap: 28px; margin-top: 14px; flex: none; }
.dock-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 64px;
  border: 0;
  padding: 0;
  background: none;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 550;
}
.dock-btn svg { width: 46px; height: 46px; padding: 11px; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--ink); }
.dock-btn:hover svg { background: var(--raise); }
.dock-btn[aria-pressed="true"] svg { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.dock-btn.mic svg { width: 64px; height: 64px; padding: 17px; }
.dock-btn.mic[aria-pressed="true"] svg { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.dock-btn.mic .i-stop { display: none; }
.dock-btn.mic[data-act="stop"] .i-stop { display: block; background: var(--ink); border-color: var(--ink); color: var(--bg); }
.dock-btn.mic[data-act="stop"] .i-mic { display: none; }
.dock-btn:disabled { opacity: 0.45; cursor: default; }

.finder { position: absolute; right: max(var(--gap), env(safe-area-inset-right)); top: 12px; display: flex; align-items: flex-start; gap: 6px; }
.finder video { width: 132px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: #000; }
/* Where the window is too narrow for the face and the camera's picture
   side by side, the face moves down to make room. */
@media (max-width: 860px) { body.cam-on .face { margin-top: 118px; } }
@media (min-width: 1000px) and (max-width: 1280px) { body.cam-on.panel-open .face { margin-top: 118px; } }

/* --- cards: what the system puts on screen --------------------------------- */

.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); text-align: left; }
.card-head { display: flex; align-items: center; gap: 8px; padding: 9px 9px 0 14px; }
.card-head h2 { flex: 1; min-width: 0; margin: 0; font-size: 0.9375rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-head time { color: var(--faint); font-size: 0.75rem; flex: none; }
.card-body { padding: 4px 14px 12px; overflow-wrap: anywhere; }

.prose { font-size: 0.9375rem; line-height: 1.55; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose ul, .prose ol, .prose pre, .prose blockquote, .prose .table { margin: 0.5em 0; }
.prose h3, .prose h4, .prose h5 { margin: 0.9em 0 0.3em; font-size: 0.9375rem; font-weight: 650; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li.task { list-style: none; margin-left: -1.3em; padding-left: 1.5em; position: relative; }
.prose li.task::before { content: ""; position: absolute; left: 0; top: 0.3em; width: 0.9em; height: 0.9em; border: 1.5px solid var(--faint); border-radius: 3px; }
.prose li.task.done { color: var(--muted); text-decoration: line-through; }
.prose li.task.done::before { background: var(--accent); border-color: var(--accent); }
.prose a { color: var(--accent); text-underline-offset: 2px; }
.prose code { font: 0.85em var(--mono); background: var(--raise); padding: 0.1em 0.35em; border-radius: 4px; }
.prose pre { background: var(--raise); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { padding: 8px 12px; background: var(--raise); border-radius: 8px; color: var(--muted); }
.prose .table { overflow-x: auto; }
.prose table { border-collapse: collapse; font-size: 0.875rem; }
.prose th, .prose td { padding: 4px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.prose th { font-weight: 650; }

/* --- the panel: everything that was said, shown, noted, remembered ---------- */

.panel {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
  padding-top: env(safe-area-inset-top);
}
body.panel-open .panel { display: flex; }

.panel-head { display: flex; align-items: center; gap: 8px; height: var(--bar); padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); border-bottom: 1px solid var(--line); flex: none; }
.panel-title { display: none; flex: 1; font-weight: 650; }
.tabs { flex: 1; min-width: 0; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { height: 34px; padding: 0 10px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: 0.875rem; font-weight: 550; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { background: var(--raise); color: var(--ink); }
.tabs button.gear { margin-left: auto; width: 34px; padding: 0; flex: none; display: grid; place-items: center; }
.tabs button.gear svg { width: 17px; height: 17px; }

.panel-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.tab { padding: 14px max(var(--gap), env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(var(--gap), env(safe-area-inset-left)); }
.empty { color: var(--muted); font-size: 0.9375rem; margin: 6px 0; }

.line { margin: 0 0 12px; }
.line .who { display: flex; align-items: baseline; gap: 8px; font-size: 0.75rem; color: var(--faint); }
.line .who b { font-weight: 650; color: var(--muted); }
.line.them .who b { color: var(--accent); }
.line p { margin: 1px 0 0; font-size: 0.9375rem; overflow-wrap: anywhere; white-space: pre-wrap; }
.line.you p { color: var(--muted); }
.line .cut { color: var(--faint); font-size: 0.8125rem; }
.day { margin: 16px 0 10px; font-size: 0.75rem; font-weight: 650; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; }
.day:first-child { margin-top: 0; }

.rows { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.rows > li { display: flex; align-items: center; gap: 10px; padding: 9px 9px 9px 14px; border-top: 1px solid var(--line); min-width: 0; }
.rows > li:first-child { border-top: 0; }
.rows .main { flex: 1; min-width: 0; }
.rows .main button.open { display: block; width: 100%; border: 0; padding: 0; background: none; text-align: left; font-weight: 550; font-size: 0.9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .main button.open:hover { color: var(--accent); }
.rows .title { font-weight: 550; font-size: 0.9375rem; overflow-wrap: anywhere; }
.rows .sub { color: var(--muted); font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows li.past .title { color: var(--muted); }

.doc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.doc-head h2 { flex: 1; min-width: 0; margin: 0; font-size: 1rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 12px 14px; }
.doc textarea { display: block; width: 100%; min-height: 46vh; border: 0; padding: 0; background: none; resize: vertical; font: 0.875rem/1.55 var(--mono); outline: none; }
.intro { color: var(--muted); font-size: 0.875rem; margin: 0 0 12px; }

.field { display: grid; grid-template-columns: 112px 1fr; align-items: center; gap: 6px 12px; margin-bottom: 10px; }
.field > label, .field > .label { font-size: 0.875rem; font-weight: 550; }
.field select, .field input[type="text"] { width: 100%; height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 0.875rem; min-width: 0; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.field .hint { grid-column: 2; margin: -2px 0 0; color: var(--muted); font-size: 0.8125rem; }
.field .inline { display: flex; align-items: center; gap: 8px; min-width: 0; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 0.875rem; }
.check input { margin-top: 3px; accent-color: var(--accent); }
.group { margin: 0 0 18px; padding: 0 0 8px; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group h3 { margin: 0 0 10px; font-size: 0.75rem; font-weight: 650; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; }
.facts { margin: 0; display: grid; grid-template-columns: 112px 1fr; gap: 4px 12px; font-size: 0.875rem; }
.facts dt { font-weight: 550; }
.facts dd { margin: 0; color: var(--muted); overflow-wrap: anywhere; }

/* --- the gate: passphrase, first wake, start -------------------------------- */

.gate { position: fixed; z-index: 60; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--bg); overflow-y: auto; }
.gate-box { width: min(100%, 400px); text-align: center; }
.mark.big { width: 72px; height: 72px; margin-bottom: 10px; }
.gate h1 { margin: 0 0 6px; font-size: 1.5rem; font-weight: 650; letter-spacing: -0.02em; }
.gate p { margin: 0 0 16px; color: var(--muted); }
.gate form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.gate label { font-size: 0.875rem; font-weight: 550; display: flex; flex-direction: column; gap: 5px; }
.gate label small { font-weight: 400; color: var(--muted); }
.gate input, .gate textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 1rem; }
.gate textarea { min-height: 84px; resize: vertical; }
.gate .btn { height: 44px; font-size: 1rem; }
.gate .note { margin: 14px 0 0; font-size: 0.8125rem; min-height: 1.3em; }
.gate .note.bad { color: var(--danger); }

.toast {
  position: fixed;
  z-index: 70;
  left: 50%;
  bottom: calc(150px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 520px);
  padding: 9px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.875rem;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.18);
}

/* --- room for more ----------------------------------------------------------- */

@media (min-width: 1000px) {
  /* Side by side: the stage keeps the left, the panel stays open on the
     right until it is closed. */
  .panel { inset: calc(var(--bar) + env(safe-area-inset-top)) 0 0 auto; width: var(--panel); padding-top: 0; border-left: 1px solid var(--line); z-index: 20; }
  body.panel-open .stage { right: var(--panel); }
  .panel-head { height: 46px; }
  #panel-close { display: none; }
}

@media (max-width: 999px) {
  .panel-open .bar { display: none; }
}

@media (max-width: 520px) {
  #panel-open span { display: none; }
  #panel-open { width: 34px; padding: 0; }
  .dock { gap: 18px; }
  .field, .facts { grid-template-columns: 96px 1fr; }
}

@media (max-width: 480px) {
  /* On a phone the tabs get a row of their own, under the title and the
     close button, so that all of them are in view. */
  .panel-head { flex-wrap: wrap; height: auto; padding-top: 9px; padding-bottom: 7px; row-gap: 7px; }
  .panel-title { display: block; }
  .tabs { order: 3; flex: 0 0 100%; justify-content: space-between; gap: 0; overflow: visible; }
  .tabs button { padding: 0 7px; font-size: 0.8125rem; }
  .tabs button.gear { margin-left: 0; width: 30px; }
}

@media (max-width: 380px) {
  .status { display: none; }
  .bar-actions { margin-left: auto; }
  .tabs button { padding: 0 3px; }
}

@media (max-height: 560px) {
  .caption { min-height: 4.6rem; }
  .said-box { max-height: 2.8em; }
  .dock-btn span { display: none; }
  .dock { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .status::before { animation: none !important; }
}
