:root {
  --bg: #f6f4f1;
  --bg-elev: #ffffff;
  --ink: #1c1b1a;
  --ink-soft: #5c5955;
  --ink-faint: #8a857e;
  --line: #e6e2dc;
  --line-strong: #d4cfc6;
  --accent: #2f5d50;
  --accent-hover: #264a40;
  --accent-soft: #e7efec;
  --tutor-bubble: #ffffff;
  --kid-bubble: #2f5d50;
  --kid-ink: #f7f5f2;
  --warn: #8a5a2b;
  --danger: #a63d3d;
  --radius: 20px;
  --radius-sm: 12px;
  --radius-pill: 999px;
  --shadow: 0 1px 2px rgba(28, 27, 26, 0.04), 0 8px 24px rgba(28, 27, 26, 0.04);
  --font: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-ui: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --topbar-h: 56px;
  --composer-h: 88px;
  --chat-max: 720px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, white);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-family: var(--font);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.brand span {
  color: var(--accent);
}

.topbar-meta {
  font-size: 13px;
  color: var(--ink-soft);
}

.topbar-link {
  font-size: 13px;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
}

.topbar-link:hover {
  color: var(--ink);
}

.chat-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--chat-max);
  margin: 0 auto;
  min-height: 0;
}

.chat-stream {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px 16px;
  scroll-behavior: smooth;
}

.msg-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
  max-width: 85%;
  animation: rise 280ms ease;
}

.msg-row.tutor {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.system {
  align-self: center;
  max-width: 90%;
  margin: 8px 0 18px;
}

.msg-label {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 4px 6px;
}

.bubble {
  border-radius: var(--radius);
  padding: 14px 16px;
  line-height: 1.45;
  box-shadow: var(--shadow);
  position: relative;
}

.msg-row.tutor .bubble {
  background: var(--tutor-bubble);
  border: 1px solid var(--line);
  color: var(--ink);
  border-bottom-left-radius: 6px;
  font-family: var(--font);
  font-size: 17px;
}

.msg-row.user .bubble {
  background: var(--kid-bubble);
  color: var(--kid-ink);
  border-bottom-right-radius: 6px;
  font-size: 16px;
}

.msg-row.system .bubble {
  background: transparent;
  box-shadow: none;
  color: var(--ink-faint);
  font-size: 13px;
  padding: 0;
  text-align: center;
}

.bubble p {
  margin: 0 0 0.65em;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--ink);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.chip:hover,
.chip:focus-visible {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line-strong));
  outline: none;
}

.chip.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.chip.primary:hover {
  background: var(--accent-hover);
}

.tts-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 12px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.composer {
  flex-shrink: 0;
  padding: 12px 20px 20px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, white);
}

.composer-inner {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  padding: 10px 10px 10px 16px;
  box-shadow: var(--shadow);
}

.composer textarea {
  flex: 1;
  border: none;
  resize: none;
  min-height: 24px;
  max-height: 120px;
  background: transparent;
  outline: none;
  line-height: 1.4;
  padding: 6px 0;
}

.composer .send {
  appearance: none;
  border: none;
  background: var(--accent);
  color: white;
  border-radius: 14px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.composer .send:hover {
  background: var(--accent-hover);
}

.composer .send:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Kid session voice dock */
.voice-dock {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, white);
  padding: 18px 20px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.hold-talk {
  appearance: none;
  width: min(240px, 70vw);
  height: 76px;
  border-radius: var(--radius-pill);
  border: none;
  background: var(--accent);
  color: white;
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 560;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(47, 93, 80, 0.28);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.hold-talk:hover {
  background: var(--accent-hover);
}

.hold-talk.recording {
  transform: scale(1.04);
  background: var(--ink);
  box-shadow: 0 0 0 6px rgba(28, 27, 26, 0.08), 0 12px 32px rgba(28, 27, 26, 0.2);
}

.voice-links {
  display: flex;
  gap: 18px;
  font-size: 13px;
}

.voice-links button {
  appearance: none;
  border: none;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 4px;
}

.voice-links button:hover {
  color: var(--ink);
  text-decoration: underline;
}

.objective-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

.objective-bar strong {
  font-family: var(--font);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.session .msg-row.tutor .bubble {
  font-size: 20px;
  padding: 16px 18px;
  padding-right: 42px;
}

.session .msg-row.user .bubble {
  font-size: 18px;
}

/* Parent home */
.home {
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 36px 20px 64px;
}

.home h1 {
  font-family: var(--font);
  font-weight: 600;
  font-size: 32px;
  letter-spacing: -0.03em;
  margin: 0 0 6px;
}

.home .lede {
  color: var(--ink-soft);
  margin: 0 0 28px;
  font-size: 15px;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.card .title {
  font-family: var(--font);
  font-size: 22px;
  margin: 0 0 4px;
}

.card .sub {
  color: var(--ink-soft);
  margin: 0 0 18px;
  font-size: 14px;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  font-weight: 520;
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
  text-decoration: none;
  color: white;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line-strong);
}

.week-dots {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 8px 0 0;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line-strong);
}

.dot.on {
  background: var(--accent);
}

.home-links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 10px;
  font-size: 14px;
}

.contract-card {
  border: 1px solid var(--line-strong);
  background: var(--bg);
  border-radius: 16px;
  padding: 14px;
  margin-top: 10px;
}

.contract-card dl {
  margin: 0;
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px 12px;
  font-size: 14px;
}

.contract-card dt {
  color: var(--ink-faint);
}

.contract-card dd {
  margin: 0;
}

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  width: min(400px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px;
  box-shadow: var(--shadow);
  text-align: center;
}

.gate-card h1 {
  font-family: var(--font);
  font-size: 28px;
  margin: 0 0 8px;
  letter-spacing: -0.03em;
}

.gate-card p {
  color: var(--ink-soft);
  margin: 0 0 22px;
  line-height: 1.5;
}

.nav-demo {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 50;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 90vw;
  opacity: 0.55;
}

.nav-demo:hover {
  opacity: 1;
}

.nav-demo a {
  font-size: 11px;
  background: var(--ink);
  color: white;
  padding: 6px 8px;
  border-radius: 8px;
  text-decoration: none;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── Problem board session (Aristotle-style staged math) ─── */
.board-session .session-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  width: min(640px, 100%);
  margin: 0 auto;
  padding: 24px 20px 12px;
  min-height: 0;
}

.problem-board {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 28px 28px 32px;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.board-kicker {
  margin: 0 0 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.board-body.board-enter {
  animation: rise 0.35s ease both;
}

.board-prompt {
  margin: 0 0 12px;
  font-family: var(--font);
  font-size: clamp(22px, 3.2vw, 28px);
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.board-math {
  margin: 8px 0 0;
  font-family: var(--font);
  font-size: clamp(48px, 9vw, 72px);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.board-math[data-kind="status"] {
  font-size: clamp(36px, 6vw, 52px);
  color: var(--ink-soft);
  font-weight: 500;
}

.board-hint {
  margin: 20px 0 0;
  font-size: 15px;
  color: var(--warn);
  line-height: 1.4;
}

.coach-strip {
  width: 100%;
  max-width: 36rem;
  text-align: center;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink-soft);
  min-height: 1.45em;
  padding: 0 8px;
}

.coach-strip.empty {
  opacity: 0;
}

.answer-echo {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 16px;
  font-weight: 500;
}

.answer-echo-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.75;
}

.board-session .voice-dock {
  flex-shrink: 0;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.board-session .composer {
  width: min(640px, 100%);
  margin: 0 auto;
  padding: 0 20px 20px;
}

@media (max-width: 640px) {
  .session .msg-row.tutor .bubble {
    font-size: 18px;
  }

  .home h1 {
    font-size: 28px;
  }

  .problem-board {
    padding: 22px 18px 26px;
    min-height: 200px;
    border-radius: 20px;
  }

  .board-prompt {
    font-size: 20px;
  }

  .board-math {
    font-size: 44px;
  }
}
