:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-sunk: #f2f4f7;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #16191f;
  --text-soft: #5c6470;
  --text-faint: #8b929d;
  --accent: #2563eb;
  --accent-hover: #1d4fd7;
  --accent-soft: #eaf0fe;
  --accent-border: #c3d4fb;
  --danger: #b42318;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-sunk: #1e222b;
    --border: #2a2f3a;
    --border-strong: #3a404d;
    --text: #e8eaee;
    --text-soft: #a4abb8;
    --text-faint: #7b8391;
    --accent: #6f9bff;
    --accent-hover: #86adff;
    --accent-soft: #1b2637;
    --accent-border: #2f4470;
    --danger: #ff9a8f;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

/* Several things here are flex, and an author `display` beats the browser's
   own rule for [hidden]. Without this, hiding an element does nothing. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.011em;
}

p {
  margin: 0;
}

button {
  font: inherit;
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 20;
  text-decoration: none;
}
.skip:focus {
  left: 0;
}

/* ---------- masthead ---------- */

.masthead {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 22px 20px 0;
}

.masthead-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  align-items: flex-start;
  justify-content: space-between;
}

/* Below roughly 380px of text width the button drops to its own line
   rather than crushing the paragraph into a ribbon. */
.masthead-text {
  flex: 1 1 380px;
}

.masthead h1 {
  font-size: 1.5rem;
  font-weight: 650;
}

.masthead p {
  margin-top: 6px;
  color: var(--text-soft);
  max-width: 62ch;
  font-size: 0.95rem;
}

.progress {
  max-width: 1100px;
  margin: 16px auto 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
}

.progress-track {
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: var(--surface-sunk);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.35s ease;
}

.progress-label {
  font-size: 0.82rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- layout ---------- */

.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 24px;
  grid-template-columns: 1fr;
  align-items: start;
}

main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  outline: none;
}

/* ---------- section list ---------- */

.sections {
  min-width: 0;
}

.sections ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-padding: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.sections ol::-webkit-scrollbar {
  display: none;
}

.section-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  white-space: nowrap;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}

.section-button:hover {
  border-color: var(--border-strong);
}

.section-button[aria-current="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.section-button[aria-current="true"] .section-name {
  color: var(--accent);
  font-weight: 600;
}

.pip {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--border-strong);
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}

.section-button[aria-current="true"] .pip {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.section-button.is-done .pip {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.section-button.is-done[aria-current="true"] .pip {
  background: var(--accent);
  color: #fff;
}

.section-meta {
  display: none;
  font-size: 0.8rem;
  color: var(--text-faint);
}

.section-name {
  font-size: 0.92rem;
}

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.eyebrow {
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--text-faint);
  text-transform: none;
}

.section-card h2 {
  font-size: 1.3rem;
  font-weight: 650;
  margin-top: 4px;
}

.question {
  margin-top: 10px;
  color: var(--text-soft);
  max-width: 68ch;
}

.field-label {
  display: block;
  margin-top: 20px;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-soft);
}

textarea,
input[type="text"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  resize: vertical;
}

textarea {
  min-height: 150px;
  line-height: 1.6;
}

textarea:focus,
input[type="text"]:focus,
button:focus-visible,
.section-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* ---------- coach ---------- */

.coach-card h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.coach-body {
  margin-top: 12px;
}

.hint {
  color: var(--text-soft);
}

.feedback {
  border-left: 3px solid var(--accent-border);
  padding-left: 16px;
}

.feedback p {
  margin: 0 0 10px;
}

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

/* Only a bold run that opens a paragraph is treated as a heading — bold
   used mid-sentence stays inline. */
.feedback p > strong:first-child {
  display: block;
  margin-top: 14px;
  color: var(--text);
  font-weight: 650;
}

.feedback p:first-child > strong:first-child {
  margin-top: 0;
}

.thinking {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text-faint);
}

.thinking::before {
  content: "";
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .thinking::before {
    animation-duration: 2.4s;
  }
  .progress-fill {
    transition: none;
  }
}

.caret::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s steps(2) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.error-note {
  color: var(--danger);
}

/* ---------- chat ---------- */

.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat:not(:empty) {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.94rem;
}

.bubble.from-you {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble.from-coach {
  align-self: flex-start;
  background: var(--surface-sunk);
  border-bottom-left-radius: 4px;
}

.bubble.from-coach p {
  margin: 0 0 8px;
}
.bubble.from-coach p:last-child {
  margin-bottom: 0;
}

.chat-form {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.chat-form input {
  flex: 1;
  min-width: 0;
}

/* ---------- buttons ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.spacer {
  flex: 1;
}

.primary-button,
.secondary-button,
.ghost-button {
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 0.94rem;
  font-weight: 550;
  border: 1px solid transparent;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    opacity 0.15s ease;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}
.primary-button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.secondary-button {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.secondary-button:hover:not(:disabled) {
  border-color: var(--text-faint);
}

.ghost-button {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-soft);
  padding: 8px 14px;
  font-size: 0.88rem;
  white-space: nowrap;
}
.ghost-button:hover {
  color: var(--text);
  border-color: var(--text-faint);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

.link-button {
  background: none;
  border: none;
  color: var(--text-faint);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0;
  font-size: 0.85rem;
}
.link-button:hover {
  color: var(--danger);
}

/* ---------- review ---------- */

.review-card h2 {
  font-size: 1.3rem;
  font-weight: 650;
}

.review-entry {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 16px;
}

.review-entry h3 {
  font-size: 1rem;
  font-weight: 620;
}

.review-entry .eyebrow {
  margin-bottom: 2px;
}

.review-entry p.answer {
  margin-top: 8px;
  white-space: pre-wrap;
  color: var(--text-soft);
}

.review-entry p.answer.empty {
  color: var(--text-faint);
  font-style: italic;
}

.review-actions {
  margin-top: 22px;
}

/* ---------- footer & toast ---------- */

.footer {
  max-width: 1100px;
  margin: 8px auto 0;
  padding: 20px 20px 40px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  color: var(--text-faint);
  font-size: 0.85rem;
}

.footer p {
  max-width: 60ch;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 99px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgb(16 24 40 / 0.18);
  z-index: 30;
}

/* ---------- wider screens ---------- */

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 268px minmax(0, 1fr);
    gap: 28px;
    padding: 28px 20px;
  }

  .sections {
    position: sticky;
    top: 20px;
  }

  .sections ol {
    flex-direction: column;
    overflow: visible;
    gap: 6px;
  }

  .section-button {
    align-items: flex-start;
    white-space: normal;
    padding: 12px 14px;
  }

  .section-meta {
    display: block;
  }

  .card {
    padding: 26px;
  }

  .masthead {
    padding-inline: 20px;
  }
}
