*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg); color: var(--fg);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  line-height: 1.5;
}

/* ── Error screen (invalid / expired link) ── */
#error-screen {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; padding: 2rem; gap: 1rem; text-align: center;
}
#error-screen h1 {
  font-family: var(--font-serif); font-size: 1.75rem; font-weight: 700;
  color: var(--primary);
}
#error-screen p { color: var(--muted); max-width: 400px; }

/* ── Chat shell ── */
#chat-screen { display: none; flex-direction: column; flex: 1; height: 100%; min-height: 0; }

/* Header — Ledger pattern: serif "Sconce setup" + muted caption */
#chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: var(--bg);
  flex-shrink: 0;
}
#chat-header img { width: 24px; height: 24px; flex-shrink: 0; }
#chat-header .title-block { display: flex; flex-direction: column; line-height: 1.1; }
#chat-header .coach-title {
  font-family: var(--font-serif); font-size: 18px; font-weight: 700;
  color: var(--primary); letter-spacing: 0.1px;
}
#chat-header .sconce-caption {
  font-size: 11px; color: var(--muted); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.6px; margin-top: 2px;
}

/* Messages scroller */
#messages {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  -webkit-overflow-scrolling: touch;
}

/* ── Turn types ── */

/* Day divider — inline serif rule (onboard rarely crosses days, but supported) */
.day-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 4px 0 14px;
}
.day-divider .rule { flex: 1; height: 1px; background: var(--border); }
.day-divider .label {
  font-family: var(--font-serif); font-size: 13.5px; font-weight: 600;
  color: var(--primary); letter-spacing: 0.1px;
}

/* Kid/user turn — right-aligned navy-soft bubble */
.turn-kid { display: flex; justify-content: flex-end; margin: 8px 0; }
.turn-kid .kid-wrap { max-width: 82%; }
.turn-kid .bubble {
  background: var(--primary-soft); color: #faf8f4;
  padding: 9px 13px; border-radius: 10px 10px 4px 10px;
  font-size: 14.5px; line-height: 1.45;
  white-space: pre-wrap; word-wrap: break-word;
  -webkit-user-select: text; user-select: text;
}
.turn-kid .ts {
  font-size: 10.5px; color: var(--muted-2); margin-top: 3px;
  text-align: right; font-variant-numeric: tabular-nums;
}

/* Coach + tool turns share the copper-rail shell */
.turn-coach, .turn-tool, .turn-stream, .turn-error {
  display: flex; gap: 10px; margin: 8px 0; align-items: stretch;
}
.turn-coach .rail, .turn-tool .rail, .turn-error .rail {
  width: 3px; background: var(--copper); border-radius: 2px;
  flex-shrink: 0; align-self: stretch;
}
.turn-stream .rail {
  width: 3px; background: var(--copper); border-radius: 2px;
  flex-shrink: 0; height: 20px; align-self: flex-start;
}
.turn-coach .body, .turn-tool .body, .turn-stream .body, .turn-error .body {
  flex: 1; min-width: 0; padding: 2px 0 2px 2px;
}
.turn-coach .prose {
  font-size: 15px; line-height: 1.5; color: var(--fg);
  white-space: pre-wrap; word-wrap: break-word;
  -webkit-user-select: text; user-select: text;
}
/* OAuth "Connect …" links rendered as full-width tap targets (≥44px). The
   authorize URL itself never shows — labelForUrl swaps in a friendly label. */
.turn-coach .prose a.oauth-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 18px; margin: 8px 0;
  background: var(--primary); color: #faf8f4;
  border-radius: var(--r-sm); text-decoration: none;
  font-size: 15px; font-weight: 600;
}
.turn-coach .ts, .turn-tool .ts {
  font-size: 10.5px; color: var(--muted-2); margin-top: 5px;
  font-variant-numeric: tabular-nums;
}

/* Tool turn — label chip + body */
.turn-tool .tool-label {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted);
  margin-bottom: 6px;
}
.turn-tool .tool-body {
  font-size: 14.5px; line-height: 1.5; color: var(--fg);
  white-space: pre-wrap; word-wrap: break-word;
}

/* Streaming pulse — three copper dots */
.turn-stream .body {
  display: flex; align-items: center; padding: 2px 0 2px 2px;
}
.stream-pulse { display: inline-flex; gap: 4px; align-items: center; }
.stream-pulse .dot {
  width: 6px; height: 6px; border-radius: 99px; background: var(--copper);
  animation: sconce-breathe 2.4s ease-in-out infinite;
}
.stream-pulse .dot:nth-child(2) { animation-delay: 0.2s; }
.stream-pulse .dot:nth-child(3) { animation-delay: 0.4s; }

/* Error turn — copper-soft, never red */
.turn-error { background: transparent; }
.turn-error .rail { background: var(--copper-deep); }
.turn-error .body {
  background: var(--copper-soft);
  border: 1px solid rgba(196, 125, 60, 0.3);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  display: flex; gap: 10px; align-items: flex-start;
}
.turn-error .warn-icon { color: var(--copper-deep); flex-shrink: 0; padding-top: 1px; }
.turn-error .err-text { flex: 1; font-size: 14px; line-height: 1.45; color: var(--fg); }

/* System line — centered muted */
.turn-system {
  text-align: center; color: var(--muted); font-size: 12.5px;
  margin: 8px 0; padding: 4px 12px;
}

/* Completion card — setup done handoff */
.turn-complete {
  margin: 14px 0 8px;
  padding: 14px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--copper);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-card);
}
.turn-complete .complete-heading {
  font-family: var(--font-serif); font-size: 15.5px; font-weight: 700;
  color: var(--primary); margin-bottom: 10px;
}
.turn-complete .complete-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 14px; margin: 4px 6px 4px 0;
  background: var(--primary); color: #faf8f4;
  border-radius: var(--r-sm);
  font-size: 14.5px; font-weight: 500;
  text-decoration: none;
}
.turn-complete .complete-link.secondary {
  background: transparent; color: var(--primary);
  border: 1px solid var(--primary);
}

/* ── Input rail ── */
#input-area {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border); background: var(--bg);
  flex-shrink: 0;
}
#input-area .textarea-wrap {
  flex: 1; min-height: 44px; max-height: 120px;
  display: flex; align-items: center;
  border: 1px solid var(--border); border-radius: 22px;
  padding: 0 14px; background: var(--card-bg);
}
#msg-input {
  flex: 1; border: none; outline: none; background: transparent;
  resize: none; font-size: 16px; line-height: 1.4; color: var(--fg);
  font-family: inherit; padding: 8px 0;
  min-height: 44px; max-height: 120px;
}
#send-btn {
  width: 44px; height: 44px; min-width: 44px; min-height: 44px;
  border: none; border-radius: 22px;
  background: var(--primary); color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-family: inherit; padding: 0;
}
#send-btn:disabled {
  background: var(--border); color: var(--muted-2); cursor: not-allowed;
}
#char-count {
  font-size: 11px; color: var(--muted); text-align: right;
  padding: 0 16px;
}

/* ── Extracted inline style="" attribute (CSP: style-src 'self'). */
.auth-logo { margin-bottom: 0.5rem; }
