/* =====================================================================
   Focus Agent — Nocturne / Tide design system
   Ported from the focus-presence + focus-design prototypes.

   Tokens live here (kept in sync with the tailwind.config in index.html)
   so the CSS the utilities can't express — the capsule-eye glow keyframes
   and the frosted BlurPanel — theme-switch off the same variables.

   Default theme is Nocturne (dark): <html class="dark">.
   Tide (light) applies when the .dark class is absent.
   ===================================================================== */

/* ---- Tide (light) — the default :root values ---- */
:root {
  --ground: #e7ecef;
  --surface: #fbfdfe;
  --text: #1d2a31;
  --muted: #4c5a62;
  --faint: #93a2ab;
  --line: #d6dee2;
  --accent: #3b7c8a;
  --accent-bright: #6fb1bd;

  /* capsule-eye gradient + glow (teal in Tide) */
  --eye-top: #8fd0da;
  --eye-mid: #3b7c8a;
  --eye-bot: #2f6572;
  --glow-rgb: 59, 124, 138;

  /* page background wash */
  --bg-grad: radial-gradient(120% 90% at 50% 38%, #f2f6f8 0%, var(--ground) 58%, #d9e1e5 100%);
  --panel-bg: rgba(251, 253, 254, 0.66);
  --panel-border: rgba(59, 124, 138, 0.20);
  --panel-shadow: 0 20px 60px rgba(20, 40, 48, 0.14);

  --sans: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --glow: 0.55;      /* driven by [data-state] */
  --eye-h: 108px;    /* driven by [data-state] */
}

/* ---- Nocturne (dark, default) ---- */
html.dark {
  --ground: #14181d;
  --surface: #1d232b;
  --text: #cad2d9;
  --muted: #97a1aa;
  --faint: #6c757e;
  --line: #2a323b;
  --accent: #8fbba3;
  --accent-bright: #cdeeda;

  --eye-top: #cdeeda;
  --eye-mid: #8fbba3;
  --eye-bot: #6fa088;
  --glow-rgb: 143, 187, 163;

  --bg-grad: radial-gradient(120% 90% at 50% 38%, #1a2129 0%, var(--ground) 55%, #0f1216 100%);
  --panel-bg: rgba(29, 35, 43, 0.62);
  --panel-border: rgba(143, 187, 163, 0.18);
  --panel-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-grad);
  color: var(--text);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background 0.5s ease, color 0.4s ease;
}

/* ============ Ambient breathing halo behind the face ============ */
.ambient {
  position: absolute; left: 50%; top: 40%; width: 640px; height: 640px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(var(--glow-rgb), calc(0.16 * var(--glow))) 0%, transparent 62%);
  filter: blur(12px); pointer-events: none;
  transition: opacity 0.6s ease; animation: haloBreath 7s ease-in-out infinite;
}
@keyframes haloBreath {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50%      { transform: translate(-50%, -50%) scale(1.08); }
}

/* ============ The face — capsule eyes (form is locked) ============ */
.face {
  position: relative; display: flex; flex-direction: column; align-items: center;
  gap: 46px; animation: breathe 6s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-7px); }
}

.eyes { display: flex; gap: 46px; }
/* .eye is the fixed LAYOUT box; it owns per-state transforms (listening
   scale, speaking talk). Height never animates, so nothing reflows. */
.eye {
  position: relative; width: 74px; height: 108px;
  transform-origin: center;
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
/* .eye-shape is the glowing body; it owns the BLINK (fast scaleY) and the
   thinking SQUINT on its own transform channel — never colliding with the
   breathing (on .face) or the state transforms (on .eye). This is the fix
   for the glitchy blink: no height animation, no shared transform. */
.eye-shape {
  position: absolute; inset: 0; border-radius: 40px;
  background: linear-gradient(180deg, var(--eye-top), var(--eye-mid) 55%, var(--eye-bot));
  box-shadow:
    0 0 calc(30px * var(--glow)) rgba(var(--glow-rgb), 0.75),
    0 0 calc(70px * var(--glow)) rgba(var(--glow-rgb), 0.4),
    inset 0 -10px 22px rgba(0, 0, 0, 0.28),
    inset 0 8px 14px rgba(255, 255, 255, 0.28);
  transform-origin: center;
  transition: transform 0.12s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.4s ease, filter 0.4s ease;
}
.eye .glint {
  position: absolute; top: 16px; left: 16px; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.85); filter: blur(1px);
  transition: transform 0.6s ease, opacity 0.4s ease;
}
.eye.blink .eye-shape { transform: scaleY(0.06); }

/* ============ Agent states — one signal drives the whole face ============ */
[data-state="idle"]      { --glow: 0.5; }
[data-state="listening"] { --glow: 1; }
[data-state="thinking"]  { --glow: 0.8; }
[data-state="speaking"]  { --glow: 0.9; }
[data-state="asking"]    { --glow: 0.85; }

/* listening: wide, alert, halo ring */
[data-state="listening"] .eye { transform: scale(1.06); }
[data-state="listening"] .eye .glint { transform: translate(2px, -3px); }
[data-state="listening"] .face::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 280px; height: 150px;
  transform: translate(-50%, -50%); pointer-events: none;
  border-radius: 90px; border: 2px solid rgba(var(--glow-rgb), 0.35);
  animation: ring 1.9s ease-out infinite;
}
@keyframes ring {
  0%   { opacity: 0.5; transform: translate(-50%, -50%) scale(0.82); }
  100% { opacity: 0;   transform: translate(-50%, -50%) scale(1.5); }
}

/* thinking: squint + look around + shimmer (squint on the shape's own channel) */
[data-state="thinking"] .eyes { animation: lookAround 2.4s ease-in-out infinite; }
[data-state="thinking"] .eye-shape { transform: scaleY(0.56); filter: brightness(1.02); animation: shimmer 1.3s ease-in-out infinite; }
[data-state="thinking"] .glint { opacity: 0.3; }
@keyframes lookAround {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-10px); }
  55%      { transform: translateX(8px); }
  80%      { transform: translateX(-3px); }
}
@keyframes shimmer {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.22); }
}

/* speaking: gentle pulse in time with the words */
[data-state="speaking"] .eye { animation: talk 1.4s ease-in-out infinite; }
@keyframes talk {
  0%, 100% { transform: scaleY(1); }
  50%      { transform: scaleY(0.92); }
}

/* asking: curious, one soft look up */
[data-state="asking"] .glint { transform: translate(0, -5px); }

/* ============ Mic ============ */
.mic {
  width: 68px; height: 68px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--accent); cursor: pointer;
  display: grid; place-items: center;
  transition: transform 0.18s ease, border-color 0.2s ease, box-shadow 0.3s ease, background 0.3s ease, color 0.3s ease;
}
.mic:hover { transform: translateY(-2px); border-color: var(--accent); }
.mic svg { width: 26px; height: 26px; }
[data-state="listening"] .mic {
  border-color: var(--accent); color: var(--ground); background: var(--accent);
  box-shadow: 0 0 0 0 rgba(var(--glow-rgb), 0.5); animation: micPulse 1.6s ease-out infinite;
}
@keyframes micPulse {
  0%   { box-shadow: 0 0 0 0 rgba(var(--glow-rgb), 0.45); }
  100% { box-shadow: 0 0 0 22px rgba(var(--glow-rgb), 0); }
}

/* ============ BlurPanel — the frosted conversation surface ============ */
.panel {
  position: absolute; left: 50%; bottom: 132px; transform: translate(-50%, 24px);
  width: min(560px, 90vw);
  background: var(--panel-bg);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border: 1px solid var(--panel-border); border-radius: 20px;
  padding: 20px 22px; box-shadow: var(--panel-shadow);
  opacity: 0; pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 40;
}
.panel.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.panel .role {
  font: 500 10px/1 var(--sans); letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 10px;
}
.panel .said {
  font-family: var(--serif); font-size: 20px; line-height: 1.4; color: var(--text);
  margin: 0; min-height: 28px; white-space: pre-wrap;
}
.panel .said .caret { color: var(--accent); animation: caret 1s step-end infinite; }
@keyframes caret { 50% { opacity: 0; } }
.panel .why { font-size: 12px; color: var(--faint); margin: 8px 0 0; }

/* text field inside the panel (compose message) */
.field {
  width: 100%; font: 400 15px/1.4 var(--sans); color: var(--text);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease; resize: none;
}
.field:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--glow-rgb), 0.18);
}
.field::placeholder { color: var(--faint); }

.panel .send { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 14px; }
.btn {
  font: 600 14px/1 var(--sans); border-radius: 11px; padding: 10px 18px; cursor: pointer;
  border: 1px solid var(--line); background: transparent; color: var(--text);
  transition: all 0.16s;
}
.btn.go { background: var(--accent); color: var(--ground); border-color: var(--accent); }
.btn.go:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn.ghost:hover { border-color: var(--accent); }

/* ============ Chrome: brand / hint / theme toggle / week affordance ============ */
.chip-btn {
  font: 500 12px/1 var(--sans); letter-spacing: 0.04em;
  color: var(--muted); background: var(--panel-bg);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 999px; padding: 9px 14px; cursor: pointer;
  transition: all 0.16s ease; display: inline-flex; align-items: center; gap: 8px;
}
.chip-btn:hover { color: var(--text); border-color: var(--accent); transform: translateY(-1px); }
.chip-btn svg { width: 15px; height: 15px; }

/* ============ Schedule panel — slides up from behind the eyes ============ */
.schedule {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg-grad);
  transform: translateY(100%);
  transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
  overflow-y: auto;
}
.schedule.show { transform: translateY(0); }

.energy-deep   { --tag: var(--accent); }
.energy-light  { --tag: var(--accent-bright); }
.energy-admin  { --tag: var(--faint); }

.day-track { position: relative; }

/* sleeping: after a stretch of no interaction the presence rests — eyes
   lower and dim to a soft sliver. Any interaction (or the agent speaking)
   wakes them with a blink. Slow easing in, quick open on wake. */
#app.sleeping { --glow: 0.16; }
#app.sleeping .eye-shape {
  transform: scaleY(0.11);
  transition: transform 0.9s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.9s ease, filter 0.9s ease;
}
#app.sleeping .glint { opacity: 0; }
#app.sleeping .ambient { opacity: 0.32; }
#app.sleeping .face { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  .face, .ambient,
  [data-state="thinking"] .eyes, [data-state="thinking"] .eye-shape,
  [data-state="speaking"] .eye, [data-state="listening"] .mic,
  [data-state="listening"] .face::after { animation: none !important; }
}

/* =====================================================================
   Response-component library (P3-02)
   Ported from the focus-design study into the app tokens, so every control
   themes with Nocturne/Tide off the same variables. Consumed by
   components.js via renderClarifyQuestion(). Selected controls use
   var(--ground) for on-accent text — the same trick as .btn.go — which
   stays legible in both themes (light ground on dark teal, dark ground on
   light sage).
   ===================================================================== */

.clarify { display: flex; flex-direction: column; gap: 12px; }
.clarify-ask {
  font-family: var(--serif); font-size: 18px; line-height: 1.35;
  color: var(--text); margin: 0;
}
.clarify-why { font-size: 12px; color: var(--faint); margin: -4px 0 2px; }
.clarify-control { display: flex; flex-direction: column; gap: 14px; }
.clarify-readout {
  font: 500 12px/1.5 var(--mono); color: var(--muted); min-height: 17px;
  padding-top: 12px; border-top: 1px dashed var(--line);
}
.clarify-readout b { color: var(--accent); font-weight: 600; }

/* ---- chips (single / multi / duration / time_bucket) ---- */
.clarify .chips { display: flex; gap: 8px; flex-wrap: wrap; }
.clarify .chip {
  font: 500 13px/1 var(--sans); padding: 9px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--ground); color: var(--text);
  cursor: pointer; user-select: none;
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}
.clarify .chip:hover { border-color: var(--accent); transform: translateY(-1px); }
.clarify .chip:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--glow-rgb), 0.20); }
.clarify .chip.on { background: var(--accent); color: var(--ground); border-color: var(--accent); }
.clarify .chip .chk { display: none; margin-right: 5px; }
.clarify .chip.on .chk { display: inline; }

/* ---- rows + connectors ---- */
.clarify .rowflex { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.clarify .conj { color: var(--faint); font-size: 13px; }

/* ---- stepper (duration + duration_range) ---- */
.clarify .stepper {
  display: inline-flex; align-items: center; border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; background: var(--ground);
}
.clarify .stepper button {
  border: 0; background: transparent; color: var(--text);
  width: 40px; height: 42px; font-size: 20px; cursor: pointer; transition: background 0.15s;
}
.clarify .stepper button:hover { background: rgba(var(--glow-rgb), 0.14); }
.clarify .stepper .val { min-width: 92px; text-align: center; font: 500 15px/1 var(--mono); color: var(--text); }

/* ---- scale dots (scale_1_5) ---- */
.clarify .scale { display: flex; gap: 10px; align-items: center; }
.clarify .dot {
  width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--line);
  cursor: pointer; display: grid; place-items: center; background: transparent;
  font: 600 12px/1 var(--sans); color: var(--faint); transition: all 0.14s;
}
.clarify .dot:hover { border-color: var(--accent); }
.clarify .dot:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--glow-rgb), 0.20); }
.clarify .dot.on { background: var(--accent); border-color: var(--accent); color: var(--ground); }

/* ---- weekday pills (recurrence) ---- */
.clarify .week { display: flex; gap: 6px; }
.clarify .day {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--ground); cursor: pointer; font: 600 12px/1 var(--sans);
  color: var(--muted); transition: all 0.14s;
}
.clarify .day:hover { border-color: var(--accent); }
.clarify .day:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--glow-rgb), 0.20); }
.clarify .day.on { background: var(--accent); border-color: var(--accent); color: var(--ground); }

/* ---- native date/time fields ---- */
.clarify .nat {
  font: 400 14px/1 var(--sans); color: var(--text); background: var(--ground);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.clarify .nat:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--glow-rgb), 0.18); }
:root .clarify .nat { color-scheme: light; }
html.dark .clarify .nat { color-scheme: dark; }

/* ---- range slider (number) ---- */
.clarify input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  border-radius: 4px; background: var(--line); outline: none;
}
.clarify input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 3px solid var(--surface);
  box-shadow: var(--panel-shadow); transition: transform 0.12s;
}
.clarify input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.12); }
.clarify input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%; background: var(--accent);
  cursor: pointer; border: 3px solid var(--surface);
}

/* ---- confirm buttons: reuse .btn / .btn.go / .btn.ghost from above ---- */
.clarify .confirm { display: flex; gap: 10px; }

/* ---- reveal (exact-time / opens_free_text) ---- */
.clarify .reveal { display: none; margin-top: 2px; }
.clarify .reveal.show { display: flex; gap: 10px; align-items: center; }
.clarify .reveal .field { flex: 1; }

@media (prefers-reduced-motion: reduce) {
  .clarify .chip, .clarify .dot, .clarify .day,
  .clarify input[type="range"]::-webkit-slider-thumb { transition: none !important; }
}
