/* Cleo — sci-fi minimal.
 *
 * The brief is restraint, not decoration. Three rules do most of the work:
 *
 *   One accent, one job.  Cyan marks machine state — connected, listening,
 *   measuring. Her voice gets the warm violet and nothing else does, so the
 *   eye learns instantly which half of the screen is her and which is the
 *   instrument around her.
 *
 *   Monospace belongs to the instrument.  Status, latency, keys, counts —
 *   anything the machine reports about itself. Her words and his are set in a
 *   humanist sans. A companion whose speech renders in a terminal font reads
 *   as a readout rather than a person.
 *
 *   Hairlines, not boxes.  1px dividers at low contrast instead of filled
 *   panels. Structure comes from alignment and space, which is what makes it
 *   feel engineered rather than decorated.
 */

:root {
  --bg: #07090c;
  --bg-lift: #0b0e13;
  --panel: #0a0d12;
  --line: #18202b;
  --line-bright: #243040;

  --text: #dde6f0;
  --muted: #6c7c90;
  --dim: #44515f;

  --accent: #4fd6e0;          /* machine state */
  --accent-dim: #1d4f57;
  --her: #c9a2e8;             /* her voice, and only ever her voice */
  --me: #7fb8e0;
  --warn: #e8847f;
  --ok: #68d6a0;

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

/* Must out-rank the display rules below. The `hidden` attribute only sets
   display:none at user-agent level, so any `display:` on .gate or .app wins
   over it and the signed-out card keeps occupying space above the app. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* One very faint wash, so the black does not read as flat. Far short of a
   texture — a visible grid or scanline would fight her face. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 0%, rgba(79,214,224,0.045), transparent 62%);
  z-index: 0;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--warn); font-size: 12px; font-family: var(--mono); }

/* --- sign in --------------------------------------------------------- */

.gate {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(180deg, var(--bg-lift), var(--panel));
  border: 1px solid var(--line);
  padding: 34px 30px;
  position: relative;
}

/* Corner ticks. Cheap, and they set the register better than a heavier border
   would. */
.gate-card::before,
.gate-card::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  border: 1px solid var(--accent-dim);
}
.gate-card::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.gate-card::after { bottom: -1px; right: -1px; border-left: none; border-top: none; }

.gate-card h1 {
  margin: 0 0 6px;
  font: 500 15px/1 var(--mono);
  letter-spacing: 0.34em;
  text-transform: uppercase;
}

.gate-card > p { margin: 0 0 24px; font-size: 13px; line-height: 1.6; }

form label {
  display: block;
  font: 10px/1 var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 16px;
}

input {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 10px 12px;
  background: #06080b;
  border: 1px solid var(--line);
  color: var(--text);
  font: 14px/1.4 var(--sans);
  letter-spacing: normal;
  text-transform: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder { color: var(--dim); }

input:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: inset 0 0 0 1px rgba(79,214,224,0.1);
}

button {
  font: 11px/1 var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--accent-dim);
  padding: 11px 16px;
  background: rgba(79,214,224,0.07);
  color: var(--accent);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

button:hover:not(:disabled) { background: rgba(79,214,224,0.14); border-color: var(--accent); }
button:disabled { opacity: 0.35; cursor: default; }

button.ghost {
  border-color: var(--line-bright);
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
}

button.ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--muted);
  background: rgba(255,255,255,0.03);
}

button.ghost.on {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: rgba(79,214,224,0.1);
}

button.ghost.quiet { color: var(--dim); border-color: transparent; }
button.ghost.quiet:hover { color: var(--warn); border-color: var(--line-bright); }

#auth-form button { width: 100%; margin-top: 8px; }

a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-dim); }
a:hover { border-bottom-color: var(--accent); }

#auth-toggle-wrap { margin: 18px 0 0; font-size: 12px; }

/* --- app ------------------------------------------------------------- */

.app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

header, footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(7,9,12,0.85);
  backdrop-filter: blur(8px);
}

footer {
  border-bottom: none;
  border-top: 1px solid var(--line);
  min-height: 38px;
  font: 11px/1.4 var(--mono);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
}

.who { display: flex; align-items: center; gap: 11px; }

.who strong {
  font: 500 12px/1 var(--mono);
  letter-spacing: 0.26em;
  text-transform: uppercase;
}

#state-text {
  font: 10px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}

.actions { display: flex; gap: 7px; }

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--dim);
  transition: background 0.25s, box-shadow 0.25s;
  flex: none;
}

.dot.listening { background: var(--accent); box-shadow: 0 0 0 3px rgba(79,214,224,0.14); }
.dot.hearing   { background: var(--ok);     box-shadow: 0 0 0 3px rgba(104,214,160,0.16); animation: pulse 1.6s ease-in-out infinite; }
.dot.speaking  { background: var(--her);    box-shadow: 0 0 0 3px rgba(201,162,232,0.18); animation: pulse 1.1s ease-in-out infinite; }
.dot.error     { background: var(--warn); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

@media (prefers-reduced-motion: reduce) { .dot { animation: none !important; } }

main {
  position: relative;   /* the memory sheet is positioned against this */
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  min-height: 0;
}

.transcript {
  overflow-y: auto;
  padding: 26px 24px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;   /* the conversation is a centred column */
  gap: 18px;
  min-height: 0;
}

/* Centred rather than left-aligned in a very wide area. Empty space on both
   sides reads as a deliberate measure; the same amount of space only on the
   right reads as a broken layout, which is exactly how it looked. */
.line {
  width: 100%;
  max-width: 680px;
}

.line .speaker {
  font: 10px/1 var(--mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 5px;
}

.line.me .speaker { color: var(--me); }
.line.her .speaker { color: var(--her); }

.line .text {
  white-space: pre-wrap;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

.line.her .text { border-left-color: rgba(201,162,232,0.3); }
.line.me  .text { border-left-color: rgba(127,184,224,0.26); }

.line.her.cut .text::after {
  content: " \2039 cut \203A";
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11px;
}

.line .tone {
  font: 10px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  margin-top: 6px;
  padding-left: 12px;
}

.line.system {
  color: var(--dim);
  font: 11px/1.5 var(--mono);
  letter-spacing: 0.06em;
  text-align: center;
  max-width: none;
  padding: 2px 0;
}

/* --- memory ---------------------------------------------------------- */

/* An overlay sheet, not a grid column.
 *
 * As a column it took its width out of `main`, which shrank the stage, which
 * squashed her portrait every time the panel opened. Floating it over the
 * transcript means opening and closing it reflows nothing behind it. */
#settings-panel,
.memory {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 86vw);
  z-index: 3;
  border-left: 1px solid var(--line-bright);
  background: rgba(10, 13, 18, 0.97);
  backdrop-filter: blur(14px);
  box-shadow: -24px 0 48px -24px rgba(0, 0, 0, 0.9);
  overflow-y: auto;
  padding: 18px;
  animation: sheet-in 0.18s ease-out;
}

@keyframes sheet-in {
  from { transform: translateX(14px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .memory { animation: none; }
}

.memory-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.memory-head strong {
  font: 500 10px/1 var(--mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

#memory-count { font-family: var(--mono); color: var(--accent); }

.memory > p { margin: 12px 0 0; font-size: 12px; line-height: 1.6; color: var(--dim); }

.memory ul { list-style: none; margin: 14px 0 0; padding: 0; }

.memory li {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.memory .k {
  display: block;
  font: 9px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 4px;
}

.memory .passing {
  font: 9px/1 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #c9a06a;
  margin-left: 6px;
}

.memory .forget {
  background: none;
  border: none;
  color: var(--dim);
  padding: 2px 5px;
  font-size: 14px;
  line-height: 1;
  letter-spacing: 0;
  flex: none;
}

.memory .forget:hover { color: var(--warn); background: none; }

/* --- avatar ---------------------------------------------------------- */

.stage {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  min-height: 0;
}

/* A column, not a banner. The portrait is 3:4, and a full-width strip crops it
   to a letterbox showing her chin — a tall narrow frame matches the source and
   shows her face at a sensible size. Stacks back to a strip when there is not
   enough width for both. */
.stage:has(.avatar:not([hidden])) {
  grid-template-rows: 1fr;
  grid-template-columns: clamp(280px, 32%, 540px) 1fr;
}

.avatar {
  width: 100%;
  height: 100%;
  display: block;
  background: #04060a;
  border-right: 1px solid var(--line);
}

/* The video layers inside are position:absolute, so this has to establish a
   containing block for them. Without it they resolve against <main> — which
   is itself positioned for the memory sheet — and her face covers the entire
   conversation. */
.avatar-stage {
  position: relative;
  overflow: hidden;
}

@media (max-width: 880px) {
  .stage:has(.avatar:not([hidden])) {
    grid-template-columns: 1fr;
    grid-template-rows: clamp(200px, 38vh, 340px) 1fr;
  }
  .avatar { border-right: none; border-bottom: 1px solid var(--line); }
}

/* --- chrome ---------------------------------------------------------- */

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-bright); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

::selection { background: rgba(79,214,224,0.22); }

@media (max-width: 760px) {
  header { flex-wrap: wrap; }
  .memory { width: 100%; border-left: none; }
}

/* --- settings -------------------------------------------------------- */

.set {
  display: block;
  margin: 18px 0 0;
  font: 10px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}

.set select,
.set input {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 9px 10px;
  background: #06080b;
  border: 1px solid var(--line);
  color: var(--text);
  font: 13px/1.4 var(--sans);
  letter-spacing: normal;
  text-transform: none;
}

.set select:focus,
.set input:focus { outline: none; border-color: var(--accent-dim); }

#settings-panel button { width: 100%; margin-top: 18px; }
#settings-panel > p { margin: 10px 0 0; }
#set-voice-name { margin-top: 8px; }


/* The camera button. `active` is a steady state, `looked` is a one-off pulse
   when a frame actually reached her — without it there is no way to tell
   "she looked and said nothing" from "she never saw it". */
#eyes-toggle.active {
  color: var(--accent, #7fd4e8);
  border-color: currentColor;
}

#eyes-toggle.looked {
  animation: eyes-pulse 0.9s ease-out;
}

@keyframes eyes-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(127, 212, 232, 0.55); }
  100% { box-shadow: 0 0 0 14px rgba(127, 212, 232, 0); }
}


/* His own picture, bottom-right of her stage.

   Mirrored, because an unmirrored self-view is the thing everyone finds subtly
   wrong about video calls — you have spent your life looking at yourself in a
   mirror and the real orientation reads as someone else's face.

   It sits over her rather than beside her: the stage is already narrow on a
   phone, and splitting it would shrink the thing worth looking at. */
.selfview {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 22%;
  max-width: 180px;
  min-width: 96px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  transform: scaleX(-1);
  border-radius: 10px;
  border: 1px solid rgba(127, 212, 232, 0.28);
  background: #06080d;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.55);
  z-index: 3;
  opacity: 0.92;
  transition: opacity 0.25s ease, box-shadow 0.4s ease;
}

.selfview:hover {
  opacity: 1;
}

/* Pulses in step with the Eyes button when a frame actually reaches her, so
   it is visible which frame she was given. */
.selfview.looked {
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.55),
              0 0 0 2px rgba(127, 212, 232, 0.75);
}

@media (max-width: 640px) {
  .selfview {
    width: 28%;
    right: 10px;
    bottom: 10px;
  }
}
