:root {
  --bg: #FAFAF7;
  --ink: #1A1D1A;
  --ink-soft: #55594F;
  --label: #8A8A82;
  --line: #E7E7E0;
  --green: #1E4D36;
  --green-hover: #173D2B;
  --green-tint: #EEF3EF;
  --red: #B23A2F;
  --red-tint: #FBEAE8;
  --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

/* ---------- Header ---------- */
header {
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 36px;
}

.wordmark {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 26px;
  letter-spacing: 0.2px;
  color: var(--green);
}

.wordmark span {
  color: var(--ink);
  font-weight: 500;
}

/* ---------- Sections ---------- */
.section { padding: 28px 0; border-bottom: 1px solid var(--line); }
.section:last-of-type { border-bottom: none; }

.label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--label);
  margin-bottom: 14px;
}

/* ---------- Select ---------- */
.select-wrap { position: relative; max-width: 320px; }

select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  padding: 10px 40px 10px 14px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s ease;
}

select:hover { border-color: #CFCFC6; }

.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 9px;
  height: 9px;
  border-right: 1.5px solid var(--ink-soft);
  border-bottom: 1.5px solid var(--ink-soft);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.email-wrap { margin-top: 16px; max-width: 320px; }

.email-input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color .15s ease;
}

.email-input:hover { border-color: #CFCFC6; }
.email-input:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

button {
  font: inherit;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 10px 20px;
  transition: background .15s ease, color .15s ease, border-color .15s ease, opacity .15s ease;
}

.btn-primary {
  background: var(--green);
  color: #fff;
  border: 1px solid var(--green);
}
.btn-primary:hover { background: var(--green-hover); }

.btn-secondary {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.btn-secondary:hover { border-color: #CFCFC6; color: var(--ink); }

.btn-secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button:focus-visible, select:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

/* Recording state */
.btn-recording {
  background: #fff;
  color: var(--red);
  border: 1px solid var(--red);
}

.rec-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  margin-right: 8px;
  vertical-align: 1px;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.audio-status {
  font-size: 13px;
  color: var(--label);
}

.audio-status.ready { color: var(--green); }
.audio-status.error { color: var(--red); }

/* ---------- Processing stepper ---------- */
#processing { display: none; }
#processing.active { display: block; }

.step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  font-size: 14px;
  color: var(--label);
  transition: color .3s ease;
}

.step.current { color: var(--ink); }
.step.done { color: var(--ink-soft); }
.step.failed { color: var(--red); }

.step-marker {
  width: 18px;
  height: 18px;
  flex: none;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  display: grid;
  place-items: center;
  transition: border-color .3s ease, background .3s ease;
}

.step.current .step-marker {
  border-color: var(--green);
  border-top-color: transparent;
  animation: spin 0.9s linear infinite;
}

.step.done .step-marker {
  background: var(--green);
  border-color: var(--green);
}

.step.done .step-marker::after {
  content: "";
  width: 5px;
  height: 9px;
  border-right: 1.5px solid #fff;
  border-bottom: 1.5px solid #fff;
  transform: rotate(45deg) translate(-1px, -1px);
}

.step.failed .step-marker {
  border-color: var(--red);
}

.step.failed .step-marker::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
}

@keyframes spin { to { transform: rotate(360deg); } }

.done-note {
  display: none;
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--green-tint);
  border-radius: var(--radius);
  color: var(--green);
  font-size: 14px;
}

.done-note.show { display: block; }
.done-note.error { background: var(--red-tint); color: var(--red); }

#new-lesson-btn { margin-top: 20px; }

/* ---------- Student profile ---------- */
.profile-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.profile-name {
  font-family: 'Fraunces', serif;
  font-weight: 500;
  font-size: 20px;
}

.profile-facts {
  font-size: 13px;
  color: var(--label);
}

details.cat { border-bottom: 1px solid var(--line); }
details.cat:last-of-type { border-bottom: none; }

details.cat > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  font-weight: 500;
  font-size: 15px;
}

details.cat > summary::-webkit-details-marker,
details.topic > summary::-webkit-details-marker { display: none; }

.cat-chevron {
  width: 8px;
  height: 8px;
  flex: none;
  border-right: 1.5px solid var(--label);
  border-bottom: 1.5px solid var(--label);
  transform: rotate(45deg);
  transition: transform .2s ease;
  margin-right: 3px;
}

details.cat[open] > summary .cat-chevron { transform: rotate(225deg); }

.cat-body { padding: 0 0 8px; }

details.topic > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
  color: var(--ink-soft);
}

details.topic > summary::after {
  content: "+";
  color: var(--label);
  font-size: 15px;
}

details.topic[open] > summary { color: var(--ink); }
details.topic[open] > summary::after { content: "\2212"; }

.topic-body {
  padding: 0 0 14px;
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.6;
  max-width: 480px;
}

.topic-body p, .topic-body ul { margin: 0; }
.topic-body p + p, .topic-body ul + p, .topic-body p + ul { margin-top: 8px; }
.topic-body ul { padding-left: 18px; }

.topic-date {
  display: block;
  font-size: 12px;
  color: var(--green);
  font-weight: 600;
  margin-bottom: 4px;
}

/* Flat groups: everything visible on one click */
.flat-group { padding: 4px 0 14px; max-width: 480px; }

.flat-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 3px;
}

.flat-group p, .flat-group ul {
  margin: 0;
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.6;
}

.flat-group p + p, .flat-group ul + p, .flat-group p + ul { margin-top: 6px; }
.flat-group ul { padding-left: 18px; }

@media (prefers-reduced-motion: reduce) {
  .rec-dot, .step.current .step-marker { animation: none; }
  .step.current .step-marker { border-top-color: var(--green); }
}

/* ---------- Chat ---------- */
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
  margin-bottom: 14px;
}

.chat-messages:empty { display: none; }

.chat-msg {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--green);
  color: #fff;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
}

.chat-msg.pending {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--label);
  font-style: italic;
}

.chat-msg.error {
  align-self: flex-start;
  background: var(--red-tint);
  color: var(--red);
}

.chat-form { display: flex; }

.chat-input-wrap {
  position: relative;
  flex: 1;
  display: flex;
}

.chat-input {
  flex: 1;
  padding: 12px 46px 12px 16px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  transition: border-color .15s ease;
}

.chat-input:hover { border-color: #CFCFC6; }
.chat-input:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.chat-send-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: none;
  background: var(--green);
  color: #fff;
  transition: background .15s ease, opacity .15s ease;
}

.chat-send-btn:hover { background: var(--green-hover); }

.chat-send-btn:disabled {
  background: var(--line);
  color: var(--label);
  cursor: not-allowed;
}

@media (max-width: 480px) {
  .page { padding: 32px 20px 60px; }
  .actions button { width: 100%; }
  .select-wrap { max-width: none; }
  .email-wrap { max-width: none; }
}
