/* Juno — Daybreak theme. Dawn-sky light / indigo-dusk dark. Same tokens as
   the approved Phase 2 visual pitch, applied across every screen. */

:root {
  --bg: #eef6fb; --card: #ffffff; --card2: #f6fafd; --border: #dbe7ee;
  --ink: #23313d; --muted: #6c8090;
  --accent: #e69a2e; --accent-dark: #b97a17; --accent-ink: #3a2604;
  --tint: #fdecd3; --tint-ink: #8a5a10;
  --coral: #ef7d6a; --teal: #0a9d90; --danger: #d64545;
  --shadow: 0 10px 26px rgba(35, 49, 61, .10);
  --radius: 15px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161a2d; --card: #1f2340; --card2: #232748; --border: #2c3156;
    --ink: #eef0fb; --muted: #98a0c4;
    --accent: #f0b04d; --accent-dark: #f6c877; --accent-ink: #2a1a04;
    --tint: #33291c; --tint-ink: #f6c877;
    --coral: #ff9585; --teal: #2fd4c4; --danger: #ff6b78;
    --shadow: 0 10px 26px rgba(0, 0, 0, .38);
  }
}
:root[data-theme="light"] {
  --bg: #eef6fb; --card: #ffffff; --card2: #f6fafd; --border: #dbe7ee;
  --ink: #23313d; --muted: #6c8090;
  --accent: #e69a2e; --accent-dark: #b97a17; --accent-ink: #3a2604;
  --tint: #fdecd3; --tint-ink: #8a5a10;
  --coral: #ef7d6a; --teal: #0a9d90; --danger: #d64545;
  --shadow: 0 10px 26px rgba(35, 49, 61, .10);
}
:root[data-theme="dark"] {
  --bg: #161a2d; --card: #1f2340; --card2: #232748; --border: #2c3156;
  --ink: #eef0fb; --muted: #98a0c4;
  --accent: #f0b04d; --accent-dark: #f6c877; --accent-ink: #2a1a04;
  --tint: #33291c; --tint-ink: #f6c877;
  --coral: #ff9585; --teal: #2fd4c4; --danger: #ff6b78;
  --shadow: 0 10px 26px rgba(0, 0, 0, .38);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Text", "Nunito", system-ui, sans-serif;
  overflow: hidden; /* app-shell pattern — only #content scrolls */
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font-family: inherit; }
a { color: var(--accent-dark); }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

header.topbar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) max(16px, var(--safe-r)) 10px max(16px, var(--safe-l));
  background: var(--card); border-bottom: 1px solid var(--border);
}
header.topbar .brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px; }
header.topbar .brand img { width: 26px; height: 26px; border-radius: 8px; }

.lda { display: flex; background: var(--card2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.lda button {
  border: none; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700;
  padding: 5px 10px; border-radius: 999px; cursor: pointer; letter-spacing: .02em;
}
.lda button.active { background: var(--accent); color: var(--accent-ink); }

#content { flex: 1 1 auto; min-height: 0; position: relative; }
.panel {
  position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px max(16px, var(--safe-r)) 16px max(16px, var(--safe-l));
  display: none;
}
.panel.active { display: block; }

nav.tabbar {
  flex: 0 0 auto; display: flex; background: var(--card); border-top: 1px solid var(--border);
  padding: 6px max(8px, var(--safe-r)) calc(6px + var(--safe-b)) max(8px, var(--safe-l));
}
nav.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: none; background: transparent; color: var(--muted); font-size: 10.5px; font-weight: 700;
  padding: 6px 2px 4px; cursor: pointer; border-radius: 12px;
}
nav.tabbar button .ic { font-size: 19px; line-height: 1; }
nav.tabbar button.active { color: var(--accent-dark); }
nav.tabbar button.active .ic { transform: translateY(-1px); }

h1.page-title { font-size: 21px; font-weight: 800; margin: 4px 0 14px; letter-spacing: -.01em; }
h2.section-title { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 10px; }
h2.section-title:first-child { margin-top: 0; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- Talk ----------
   Native-app layout (house §3): Juno's face and her controls stay put; only
   the conversation scrolls. The panel becomes a flex column and overrides the
   generic .panel scrolling, so nothing but .transcript can move. */
#panel-talk.active { display: flex; flex-direction: column; overflow: hidden; }
.talk-fixed {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 2px;
}
/* Once a call is live the wake-word chip is dead weight — she's already
   listening — so reclaim its row for the conversation. */
#avatar-pane.live ~ .wake-chip { display: none; }
#panel-talk .transcript {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  width: 100%; max-width: 420px; margin: 14px auto 0; padding-bottom: 4px;
}
.avatar-pane {
  width: 100%; max-width: 360px; aspect-ratio: 4/3; border-radius: 18px;
  /* Cap by viewport height too, so on a short phone screen she can't crowd out
     the conversation below her. */
  max-height: min(30vh, 240px);
  background: linear-gradient(160deg, var(--tint), var(--card2) 70%);
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 20px; color: var(--muted); font-size: 12.5px; line-height: 1.5;
  overflow: hidden;
}
/* Idle pane is a call-to-action: it's tappable and says so. */
.avatar-pane:not(.live) { cursor: pointer; }
.avatar-pane:not(.live):hover { border-color: var(--accent); }
.avatar-cta {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 700; color: var(--tint-ink);
  background: var(--tint); border-radius: 999px; padding: 9px 18px;
}
.avatar-cta::before { content: "🎙️"; font-size: 15px; }

/* Her portrait fills the idle pane; the CTA sits over it on a scrim so the
   label stays legible against the photograph in both themes. */
.avatar-pane:not(.live) { position: relative; padding: 0; }
.avatar-still {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 22%;
}
.avatar-pane:not(.live) .avatar-cta {
  position: relative; z-index: 1; margin-top: auto; margin-bottom: 14px;
  background: rgba(12, 14, 26, 0.72); color: #f4f6ff;
  backdrop-filter: blur(6px);
}
.avatar-pane:not(.live) { align-items: flex-end; }

/* Once the stream is up the pane holds the keyed canvas. The Daybreak gradient
   stays as her backdrop — the raw feed is chroma-key green and is composited
   out in app.js, so the <video> is only a frame source and audio sink. */
.avatar-pane.live { padding: 0; position: relative; }
.avatar-pane video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; pointer-events: none;   /* NOT display:none — that can pause audio */
}
.avatar-pane canvas { width: 100%; height: 100%; object-fit: contain; display: block; position: relative; }
.wake-chip {
  display: inline-flex; align-items: center; gap: 8px; background: var(--tint); color: var(--tint-ink);
  border-radius: 999px; padding: 7px 16px; font-size: 12.5px; font-weight: 700; cursor: pointer; border: none;
}
.wake-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.wake-chip.on .dot { background: var(--coral); }
.mic-btn {
  width: 68px; height: 68px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  border: none; display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .15s ease;
}
.mic-btn:active { transform: scale(.94); }
.mic-btn svg { width: 26px; height: 26px; }
.mic-btn.live { animation: pulse 1.8s ease-out infinite; }
@media (prefers-reduced-motion: no-preference) {
  @keyframes pulse {
    0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); }
    70% { box-shadow: 0 0 0 18px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
  }
}
.talk-status { font-size: 13.5px; font-weight: 700; color: var(--coral); min-height: 18px; text-align: center; }
.transcript { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 8px; }
.bubble { border-radius: 14px; padding: 10px 13px; font-size: 13.5px; line-height: 1.5; max-width: 88%; }
.bubble.me { align-self: flex-end; background: var(--tint); color: var(--tint-ink); }
.bubble.juno { align-self: flex-start; background: var(--card); border: 1px solid var(--border); }
.talk-controls { display: flex; gap: 10px; }
.talk-controls button {
  border: 1px solid var(--border); background: var(--card); color: var(--ink); border-radius: 12px;
  padding: 9px 16px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.talk-controls button#sound-btn {
  /* The fix action, so it carries the accent rather than sitting flat beside Mute.
     Contrast on #e69a2e / #3a2604 is 6.2:1 light, 9.5:1 dark (#f0b04d / #2a1a04). */
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
}
.talk-controls button.end { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.setup-note { max-width: 420px; text-align: center; }
.vol-wrap { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.vol-wrap input[type="range"] { width: 88px; accent-color: var(--accent); }
.sound-panel {
  max-width: 420px; width: 100%; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px; font-size: 13px; text-align: left;
}
.sound-row { margin: 4px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sound-row select, .sound-row button {
  font: inherit; border: 1px solid var(--border); background: var(--bg); color: var(--ink);
  border-radius: 9px; padding: 6px 10px; max-width: 100%;
}
.sound-row button { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; cursor: pointer; }

/* ---------- Briefing ---------- */
.ep-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.ep-row:last-child { border-bottom: none; }
.ep-play {
  width: 40px; height: 40px; border-radius: 50%; background: var(--tint); color: var(--tint-ink); border: none;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer;
}
.ep-meta { flex: 1; min-width: 0; }
.ep-date { font-weight: 700; font-size: 14px; }
.ep-sub { font-size: 12px; color: var(--muted); }
.big-btn {
  width: 100%; background: var(--accent); color: var(--accent-ink); border: none; border-radius: 13px;
  padding: 13px; font-size: 15px; font-weight: 800; cursor: pointer; margin-top: 4px;
}
.big-btn:disabled { opacity: .5; cursor: default; }
audio.player-el { width: 100%; margin-top: 10px; }

/* ---------- History ---------- */
.hist-row { padding: 12px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.hist-row:last-child { border-bottom: none; }
.hist-date { font-weight: 700; font-size: 14px; }
.hist-sub { font-size: 12px; color: var(--muted); }
.hist-turns { display: none; flex-direction: column; gap: 6px; margin-top: 10px; }
.hist-turns.open { display: flex; }

/* ---------- Settings ---------- */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 13.5px; }
.kv .k { color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; background: var(--tint); color: var(--tint-ink);
}
.pill.ok { background: color-mix(in srgb, var(--teal) 18%, var(--card)); color: var(--teal); }
.pill.bad { background: color-mix(in srgb, var(--danger) 16%, var(--card)); color: var(--danger); }
details.settings-group { margin-bottom: 12px; }
details.settings-group summary {
  cursor: pointer; font-weight: 800; font-size: 13.5px; padding: 12px 4px; list-style: none;
  display: flex; align-items: center; justify-content: space-between;
}
details.settings-group summary::-webkit-details-marker { display: none; }
details.settings-group summary::after { content: "\\2304"; color: var(--muted); font-size: 16px; }
details.settings-group[open] summary::after { content: "\\2303"; }
.appearance-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; }
.time-input { background: var(--card2); border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; color: var(--ink); font-size: 13px; }
select.time-input { min-width: 0; }
.signout-btn {
  width: 100%; background: var(--card2); color: var(--danger); border: 1px solid var(--border);
  border-radius: 12px; padding: 11px; font-size: 13.5px; font-weight: 700; cursor: pointer; margin-top: 6px;
}
.applink { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; font-size: 13.5px; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--border); }
.applink:last-child { border-bottom: none; }

/* ---------- PIN gate ---------- */
#pin-gate {
  position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex;
  align-items: center; justify-content: center; flex-direction: column; gap: 18px; padding: 24px;
}
#pin-gate[hidden] { display: none !important; }
#pin-gate .pin-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; text-align: center; width: 100%; max-width: 320px; }
#pin-gate h1 { font-size: 19px; margin: 0 0 4px; }
/* PIN keypad (house standard 2026-10-20). Colors come from --pk-* set per app on .pin-gate. */
.pin-gate{--pk-size:clamp(64px,min(20vw,10vh),84px);display:flex;flex-direction:column;align-items:center;gap:clamp(8px,1.6vh,16px);touch-action:manipulation;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent;color:var(--pk-ink)}
.pin-dots{display:flex;gap:10px}
.pin-dots span{width:14px;height:14px;border-radius:50%;border:2px solid var(--pk-ink);box-sizing:border-box}
.pin-dots span.on{background:var(--pk-ink)}
.pin-gate.busy .pin-dots span.on{animation:pkpulse .9s ease-in-out infinite}
@keyframes pkpulse{50%{opacity:.35}}
.pin-gate.bad .pin-dots{animation:pkshake .35s}
@keyframes pkshake{20%,60%{transform:translateX(-8px)}40%,80%{transform:translateX(8px)}}
.pin-msg{min-height:1.3em;font-size:16px;line-height:1.3;color:var(--pk-muted);text-align:center}
.pin-pad{display:grid;grid-template-columns:repeat(3,var(--pk-size));gap:clamp(8px,1.6vh,16px)}
.pin-pad button{height:var(--pk-size);border-radius:50%;border:1px solid var(--pk-line);background:var(--pk-surface);color:var(--pk-ink);font-family:inherit;font-weight:600;font-size:clamp(26px,4vh,32px);line-height:1;padding:0;touch-action:manipulation;-webkit-tap-highlight-color:transparent;cursor:pointer}
.pin-pad button:active{background:var(--pk-accent);color:var(--pk-accent-ink)}
.pin-pad button:disabled{opacity:.5}
.pin-pad .pin-del{border:none;background:transparent;font-size:24px}
@media (prefers-reduced-motion:reduce){.pin-gate.busy .pin-dots span.on,.pin-gate.bad .pin-dots{animation:none}}
#pin-gate .pin-gate { --pk-ink: var(--ink); --pk-muted: var(--muted); --pk-line: var(--border); --pk-surface: var(--card2); --pk-accent: var(--accent); --pk-accent-ink: var(--accent-ink); margin-top: 14px; }
#pin-gate .pin-card { padding: 20px 16px; }

@media (min-width: 720px) {
  .panel { padding-left: max(28px, var(--safe-l)); padding-right: max(28px, var(--safe-r)); }
  header.topbar { padding-left: max(20px, var(--safe-l)); padding-right: max(20px, var(--safe-r)); }
}

/* ---------- version badge (index.html, filled from version.js) ----------
   Top-left inside the safe area, in the header's top padding above the brand, clear of the
   L/D/A toggle on the right. The light --muted is too faint for 9px text (3.75:1 on the page,
   4.10:1 on the header card), so the badge mixes it 60/40 toward the ink. Measured: light
   #4f606f 6.49:1 on the header (#ffffff), 5.94:1 on the PIN gate (#eef6fb); dark #bac0da
   8.48:1 on the header (#1f2340), 9.54:1 on the gate (#161a2d). Failure: --danger mixed 75/25
   toward the ink, #a94043 6.00:1 / 5.49:1 light, #fb8c99 6.78:1 / 7.64:1 dark. */
.app-version {
  position: fixed; z-index: 60; pointer-events: none;   /* above the PIN gate (50) */
  top: var(--safe-t);
  left: calc(var(--safe-l) + 16px);
  font: 500 9px/9px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .2px; white-space: nowrap;
  color: color-mix(in srgb, var(--muted) 60%, var(--ink));
}
.app-version.fail { color: color-mix(in srgb, var(--danger) 75%, var(--ink)); font-weight: 700; }
