/* Phone first. System fonts only: nothing is downloaded. */

:root {
  color-scheme: light dark;

  --page: #ffffff;
  --ink: #1f2a24;
  --muted: #4a554e;
  --line: #dde3de;
  --field: #ffffff;

  --teacher-surface: #d9eedf;
  --teacher-label: #2f5d46;
  --learner-surface: #ddeaf8;
  --learner-label: #1d4f86;

  /* AI learners: a bubble tint and a name colour, keyed by name. An unknown
     name falls back to the --ai-learner pair. Names are over 5.5:1 and text
     over 11:1 on their tint, in both themes. */
  --surface-ramesh: #f3e6cc;
  --name-ramesh: #7a4f08;
  --surface-priya: #e6e0f8;
  --name-priya: #4a3f9b;
  --surface-simran: #f6dde6;
  --name-simran: #9c2f57;
  --surface-sejal: #d3ecef;
  --name-sejal: #1d5f6b;
  --ai-learner-surface: #eceeed;
  --ai-learner-name: var(--muted);

  --primary: #2f5d46;
  --on-primary: #ffffff;
  /* The Home bot's pointer: a bright gold ring and its glow. */
  --pointer: #f0a000;
  --pointer-glow: rgb(240 160 0 / 0.4);
  --view-blue: #2e6fb5;
  --pause-orange: #ba7517;
  --sound-green: #3e8e5a;
  --sound-off-red: #c8423a;
  --mic-green: #3e8e5a;

  --resources-surface: #f3d3de;
  --resources-ink: #9c2f57;
  --roleplay-line: #bdb3f0;
  --roleplay-ink: #4a3f9b;
  --quiz-line: #e8c27a;
  --quiz-ink: #7a4b08;

  /* Roleplay: the counsellor's bubbles pink, Priya's green, each with a
     label colour and a dot for the header's legend. */
  --counsellor-surface: #fbe1df;
  --counsellor-label: #9b2f28;
  --counsellor-dot: #d9645c;
  --patient-surface: #dcefe2;
  --patient-label: #2f6b45;
  --patient-dot: #4e9a6a;
  --waiting-surface: #e4e8e5;

  --good: #2f7a4e;
  --warn: #b26a00;
  --bad: #c8423a;
  /* Quiz: a picked answer (blue), a right one (green), a wrong one (orange),
     and the score's dots. */
  --quiz-pick: #2e6fb5;
  --quiz-pick-surface: #e3edf9;
  --quiz-pick-ink: #173f6b;
  --quiz-right-surface: #e0f0e4;
  --quiz-right-ink: #1f5234;
  --quiz-right-dot: #4a8a5c;
  --quiz-wrong: #c46a2b;
  --quiz-wrong-surface: #fbece2;
  --quiz-wrong-ink: #8a4515;
  --quiz-amber: #d6a04c;
  --problem-surface: #fbebcb;
  --problem-ink: #7a4b08;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Gujarati", sans-serif;
}

/* The theme follows the phone unless Settings picked one (data-theme on
   <html>). The dark colours are written twice, once for each way in. */
:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #121614;
    --ink: #e6ece8;
    --muted: #9aa59e;
    --line: #2c3530;
    --field: #1b211e;

    --teacher-surface: #1e3529;
    --teacher-label: #8fcfa8;
    --learner-surface: #1b2c40;
    --learner-label: #9cc3ef;

    --surface-ramesh: #33291a;
    --name-ramesh: #e2be7c;
    --surface-priya: #2a2540;
    --name-priya: #c3b8f2;
    --surface-simran: #3a1f2a;
    --name-simran: #f0a6c1;
    --surface-sejal: #16313a;
    --name-sejal: #8fd0db;
    --ai-learner-surface: #232a26;

    --primary: #3e7a5a;
    --pointer: #ffc233;
    --pointer-glow: rgb(255 194 51 / 0.35);
    --resources-surface: #3a1f2a;
    --resources-ink: #f0a9c3;
    --roleplay-line: #5a4fa8;
    --roleplay-ink: #c4bbf5;
    --quiz-line: #8a6420;
    --quiz-ink: #f0cd8a;
    --counsellor-surface: #3b2220;
    --counsellor-label: #f2a59e;
    --counsellor-dot: #e07a72;
    --patient-surface: #1e3529;
    --patient-label: #8fcfa8;
    --patient-dot: #6fc993;
    --waiting-surface: #2a312d;

    --good: #6fc993;
    --warn: #e7a94a;
    --bad: #f07a72;
    --quiz-pick: #6fa3df;
    --quiz-pick-surface: #1d2b3c;
    --quiz-pick-ink: #cfe0f5;
    --quiz-right-surface: #1d3326;
    --quiz-right-ink: #bfe6cb;
    --quiz-right-dot: #5fae7b;
    --quiz-wrong: #e08b52;
    --quiz-wrong-surface: #3a271b;
    --quiz-wrong-ink: #f2c09c;
    --quiz-amber: #d9ad5c;
    --problem-surface: #3a2c12;
    --problem-ink: #f0cd8a;
  }
}

:root[data-theme="dark"] {
  --page: #121614;
  --ink: #e6ece8;
  --muted: #9aa59e;
  --line: #2c3530;
  --field: #1b211e;

  --teacher-surface: #1e3529;
  --teacher-label: #8fcfa8;
  --learner-surface: #1b2c40;
  --learner-label: #9cc3ef;

  --surface-ramesh: #33291a;
  --name-ramesh: #e2be7c;
  --surface-priya: #2a2540;
  --name-priya: #c3b8f2;
  --surface-simran: #3a1f2a;
  --name-simran: #f0a6c1;
  --surface-sejal: #16313a;
  --name-sejal: #8fd0db;
  --ai-learner-surface: #232a26;

  --primary: #3e7a5a;
  --pointer: #ffc233;
  --pointer-glow: rgb(255 194 51 / 0.35);
  --resources-surface: #3a1f2a;
  --resources-ink: #f0a9c3;
  --roleplay-line: #5a4fa8;
  --roleplay-ink: #c4bbf5;
  --quiz-line: #8a6420;
  --quiz-ink: #f0cd8a;
  --counsellor-surface: #3b2220;
  --counsellor-label: #f2a59e;
  --counsellor-dot: #e07a72;
  --patient-surface: #1e3529;
  --patient-label: #8fcfa8;
  --patient-dot: #6fc993;
  --waiting-surface: #2a312d;

  --good: #6fc993;
  --warn: #e7a94a;
  --bad: #f07a72;
  /* Quiz: a picked answer (blue), a right one (green), a wrong one (orange),
     and the score's dots. */
  --quiz-pick: #6fa3df;
  --quiz-pick-surface: #1d2b3c;
  --quiz-pick-ink: #cfe0f5;
  --quiz-right-surface: #1d3326;
  --quiz-right-ink: #bfe6cb;
  --quiz-right-dot: #5fae7b;
  --quiz-wrong: #e08b52;
  --quiz-wrong-surface: #3a271b;
  --quiz-wrong-ink: #f2c09c;
  --quiz-amber: #d9ad5c;
  --problem-surface: #3a2c12;
  --problem-ink: #f0cd8a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

h1,
p {
  margin: 0;
}

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

button {
  cursor: pointer;
}

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

[hidden] {
  display: none !important;
}

.icon {
  width: 1.5rem;
  height: 1.5rem;
  flex: none;
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
}

/* Each screen fills the phone's visible height, keyboard included. */
.screen {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  height: 100dvh;
  max-width: 30rem;
  margin: 0 auto;
  padding: max(0.75rem, env(safe-area-inset-top)) 1rem max(0.75rem, env(safe-area-inset-bottom));
}

/* --- Shared pieces -------------------------------------------------------- */

.speaker-name {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
}

.bubble {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: 1rem;
}

.teacher-bubble {
  background: var(--teacher-surface);
}

.teacher-bubble .speaker-name {
  color: var(--teacher-label);
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: none;
}

.input-row input {
  flex: 1;
  min-width: 0; /* lets the box shrink on a narrow phone */
  height: 3rem;
  padding: 0 min(1.125rem, 4vw);
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: var(--field);
  font-size: 1rem; /* 16px keeps iOS from zooming in on focus */
}

.input-row input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.mic-button,
.send-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: none;
  border: none;
  border-radius: 50%;
  background: var(--mic-green);
  color: #ffffff;
}

.send-button {
  background: var(--primary);
}

/* --- Login --------------------------------------------------------------- */

.login-screen {
  position: relative; /* holds the language pill */
  justify-content: center;
  padding-inline: 1.5rem;
}

/* English | ગુજરાતી, top right: two joined pills after a globe, the chosen
   one filled, like the theme picker. */
.language-choice {
  position: absolute;
  top: max(1.25rem, env(safe-area-inset-top));
  right: 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.125rem;
  max-width: calc(100% - 2rem);
  padding: 0.25rem 0.25rem 0.25rem 0.625rem;
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  font-size: 0.9375rem;
}

.language-choice[hidden] {
  display: none;
}

.language-choice .icon {
  width: 1.125rem;
  height: 1.125rem;
  margin-right: 0.25rem;
  color: var(--muted);
}

/* The radio stays in the page for keyboards and screen readers, unseen. */
.language-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.language-choice span {
  display: grid;
  place-items: center;
  min-height: 2.25rem;
  padding: 0 0.75rem;
  border-radius: 999px;
  cursor: pointer;
}

.language-choice input:checked + span {
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
}

.language-choice input:focus-visible + span {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.login-form {
  display: flex;
  flex-direction: column;
}

.login-form h1 {
  font-size: 1.625rem;
  line-height: 1.25;
}

.login-intro {
  margin-top: 0.75rem;
  color: var(--muted);
}

.login-code {
  margin: 2rem 0 0;
  padding: 0;
  border: none;
  min-width: 0;
}

.login-code legend {
  padding: 0;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.login-code-boxes {
  display: flex;
  gap: 0.5rem;
}

.login-code-boxes input {
  flex: 1;
  min-width: 0;
  max-width: 3rem;
  height: 3.75rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  background: var(--field);
  text-align: center;
  font-size: 1.5rem; /* over 16px, so iOS doesn't zoom in on focus */
  font-weight: 600;
}

.login-code-boxes input:focus {
  outline: 2px solid var(--good);
  outline-offset: -1px;
}

.login-code-boxes.wrong input {
  border: 2px solid var(--bad);
  background: color-mix(in srgb, var(--bad) 10%, var(--field));
}

.login-hint,
.login-error {
  margin-top: 0.5rem;
  font-size: 0.875rem;
}

.login-hint {
  color: var(--muted);
}

.login-error {
  display: flex;
  gap: 0.5rem;
  color: var(--bad);
}

.login-error .icon {
  width: 1.125rem;
  height: 1.125rem;
  margin-top: 0.125rem;
}

.login-button {
  height: 3.5rem;
  margin-top: 2rem;
  border: none;
  border-radius: 1rem;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 1.0625rem;
  font-weight: 600;
}

.keep-logged-in {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  font-size: 0.9375rem;
}

.keep-logged-in input {
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  accent-color: var(--sound-green);
}

/* The login button while the trainer wakes: a spinner before the words. */
.login-button.waking {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: color-mix(in srgb, var(--primary) 35%, var(--page));
  color: var(--ink);
}

/* Waiting on the trainer, not unavailable: full strength. */
.login-button.waking:disabled {
  opacity: 1;
}

.login-button.waking::before {
  content: "";
  width: 1.125rem;
  height: 1.125rem;
  border: 2.5px solid color-mix(in srgb, var(--good) 30%, transparent);
  border-top-color: var(--good);
  border-radius: 50%;
  animation: wake-spin 0.9s linear infinite;
}

/* --- Wake ------------------------------------------------------------------ */

.wake-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  max-width: 30rem;
  margin: 0 auto;
  padding: max(1.25rem, env(safe-area-inset-top)) 1.5rem max(1.25rem, env(safe-area-inset-bottom));
  background: var(--page);
}

/* Covers the full width, though the column above stays phone-sized. */
.wake-screen::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--page);
}

.wake-screen[hidden] {
  display: none;
}

.wake-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.wake-name {
  flex: 1 1 8rem;
  color: var(--teacher-label);
  font-size: 0.9375rem;
  font-weight: 700;
}

.wake-header .language-choice {
  position: static;
  flex: none;
}

.wake-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
}

.wake-body h1 {
  margin-top: 1.5rem;
  font-size: 1.75rem;
  line-height: 1.25;
}

.wake-text {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 1.0625rem;
  line-height: 1.55;
}

.wake-text strong {
  color: var(--ink);
}

.wake-mark {
  display: grid;
  place-items: center;
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 50%;
}

.wake-mark > * {
  display: none;
}

.wake-spinner {
  width: 4.5rem;
  height: 4.5rem;
  border: 0.4rem solid color-mix(in srgb, var(--good) 20%, transparent);
  border-top-color: var(--good);
  border-radius: 50%;
  animation: wake-spin 1.2s linear infinite;
}

.wake-mark .icon {
  width: 2rem;
  height: 2rem;
}

.wake-screen:is([data-step="waking"], [data-step="starting"], [data-step="getting_ready"]) .wake-spinner {
  display: block;
}

.wake-screen[data-step="ready"] .wake-mark {
  background: var(--sound-green);
  color: #ffffff;
}

.wake-screen[data-step="ready"] .wake-check {
  display: block;
}

.wake-screen[data-step="slow"] .wake-mark {
  background: var(--problem-surface);
  color: var(--warn);
}

.wake-screen[data-step="slow"] .wake-clock {
  display: block;
}

.wake-progress {
  height: 0.5rem;
  margin-top: 1.5rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--good) 15%, transparent);
  overflow: hidden;
}

.wake-bar {
  width: calc(var(--done, 0) * 100%);
  height: 100%;
  border-radius: inherit;
  background: var(--good);
  transition: width 0.6s ease;
}

.wake-since {
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.wake-steps {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
  padding: 0;
  list-style: none;
  font-size: 1.0625rem;
}

.wake-steps li {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  color: var(--muted);
}

.wake-step-dot {
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  flex: none;
  border: 2px solid var(--line);
  border-radius: 50%;
}

.wake-step-dot .icon {
  display: none;
  width: 0.875rem;
  height: 0.875rem;
}

.wake-steps li.done {
  color: var(--ink);
}

.wake-steps li.done .wake-step-dot {
  border-color: var(--sound-green);
  background: var(--sound-green);
  color: #ffffff;
}

.wake-steps li.done .wake-step-dot .icon {
  display: block;
}

.wake-steps li.active {
  color: var(--ink);
  font-weight: 600;
}

.wake-steps li.active .wake-step-dot {
  border-color: var(--good);
  background: radial-gradient(circle, var(--good) 0 0.3rem, transparent 0.32rem);
}

.wake-screen:is([data-step="ready"], [data-step="slow"]) :is(.wake-steps, .wake-since) {
  display: none;
}

.wake-screen[data-step="slow"] .wake-progress {
  display: none;
}

.wake-bottom {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.wake-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  height: 3.5rem;
  border: none;
  border-radius: 1rem;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 1.125rem;
  font-weight: 700;
}

.wake-button[hidden] {
  display: none;
}

.wake-button .icon {
  width: 1.25rem;
  height: 1.25rem;
}

.wake-screen:not([data-step="slow"]) .wake-retry-icon,
.wake-screen:not([data-step="ready"]) .wake-open-icon {
  display: none;
}

.wake-footnote {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
  text-align: center;
}

.wake-footnote:empty {
  display: none;
}

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

/* --- Home ---------------------------------------------------------------- */

.home-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.25rem;
}

.home-header > div {
  flex: 1 1 10rem;
}

.home-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.resources-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  border: none;
  border-radius: 999px;
  background: var(--resources-surface);
  color: var(--resources-ink);
  font-size: 0.9375rem;
}

.resources-pill .icon {
  width: 1rem;
  height: 1rem;
}

.home-body {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  gap: 1.5rem;
  /* Room inside the scrolling edge, so the bot's pointer glow around a
     button isn't cut off; the negative margin keeps the layout as it was. */
  padding: 0 1rem 0.75rem;
  margin: 0 -1rem -0.75rem;
}

/* The chat with the Home bot: its bubbles on the left, the learner's on the
   right, as in WhatsApp. Text only. */
.home-conversation {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.home-chat {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

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

.home-chat li {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: 1rem;
  white-space: pre-wrap; /* replies can contain line breaks */
  overflow-wrap: break-word;
}

.home-chat .bot {
  align-self: flex-start;
  background: var(--teacher-surface);
}

.home-chat .learner {
  align-self: flex-end;
  background: var(--learner-surface);
}

/* Until the first words of a reply arrive. app.js puts the word in
   data-typing-note. */
.home-chat .bot-typing::before {
  content: attr(data-typing-note);
  color: var(--muted);
  font-style: italic;
  animation: typing-fade 1.2s ease-in-out infinite alternate;
}

@keyframes typing-fade {
  to {
    opacity: 0.35;
  }
}

.reply-failed-note {
  display: block;
  color: var(--bad);
  font-size: 0.875rem;
}

.home-choices {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

.home-options {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  width: 80%;
}

.home-options:empty {
  display: none;
}

.settings-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--field);
}

/* --- Settings: a sheet from the bottom of Home ----------------------------- */

.settings-sheet {
  width: 100%;
  max-width: 30rem;
  max-height: 85dvh;
  margin: auto auto 0;
  padding: 0;
  border: none;
  border-radius: 1.25rem 1.25rem 0 0;
  background: var(--field);
  color: var(--ink);
}

.settings-sheet::backdrop {
  background: rgb(0 0 0 / 0.45);
}

.settings-sheet-body {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1rem 1rem max(1.25rem, env(safe-area-inset-bottom));
  outline: none;
}

.settings-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-sheet-header h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
}

.settings-close-button {
  min-height: 2.75rem;
  padding: 0 0.75rem;
  border: none;
  background: none;
  color: var(--primary);
  font-weight: 600;
}

.theme-picker {
  margin: 0;
  padding: 0;
  border: none;
}

.theme-picker legend {
  margin-bottom: 0.5rem;
  padding: 0;
  font-size: 0.875rem;
  color: var(--muted);
}

/* Three joined pills; the chosen one is filled. */
.theme-options {
  display: flex;
  padding: 0.25rem;
  border-radius: 999px;
  background: var(--page);
  border: 1px solid var(--line);
}

.theme-options label {
  flex: 1;
}

/* The radio stays in the page for keyboards and screen readers, unseen. */
.theme-options input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-options span {
  display: grid;
  place-items: center;
  min-height: 2.5rem;
  border-radius: 999px;
  cursor: pointer;
}

.theme-options input:checked + span {
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
}

.theme-options input:focus-visible + span {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* A row with the words on the left and an on/off switch on the right. */
.setting-switch {
  display: flex;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
}

.setting-switch-words {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.setting-switch-hint {
  color: var(--muted);
  font-size: 0.875rem;
}

/* The checkbox drawn as a switch: a pill track with a round knob. */
.setting-switch input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  position: relative;
  width: 3.25rem;
  height: 2rem;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background 0.2s;
}

.setting-switch input::before {
  content: "";
  position: absolute;
  top: 0.1875rem;
  left: 0.1875rem;
  width: 1.625rem;
  height: 1.625rem;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
  transition: transform 0.2s;
}

.setting-switch input:checked {
  background: var(--sound-green);
}

.setting-switch input:checked::before {
  transform: translateX(1.25rem);
}

.setting-switch input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.settings-actions,
.settings-confirm {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.settings-action {
  min-height: 3rem;
  padding: 0 1rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--page);
  text-align: left;
}

.settings-confirm-buttons {
  display: flex;
  gap: 0.625rem;
}

.settings-confirm-buttons .settings-action {
  flex: 1;
  text-align: center;
}

.settings-action.do-it-for-sure {
  border-color: var(--sound-off-red);
  background: var(--sound-off-red);
  color: #ffffff;
  font-weight: 600;
}

/* --- A popup in the middle of the screen: one message and OK --------------- */

.notice-popup {
  width: calc(100% - 2rem);
  max-width: 22rem;
  padding: 0;
  border: none;
  border-radius: 1rem;
  background: var(--field);
  color: var(--ink);
}

.notice-popup::backdrop {
  background: rgb(0 0 0 / 0.45);
}

.notice-popup-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem 1rem 1rem;
}

.notice-popup-body p {
  margin: 0;
  line-height: 1.5;
}

.notice-popup-button {
  min-height: 3rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--page);
  font-weight: 600;
}

.choice-button {
  min-height: 3rem;
  padding: 0.625rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--field);
  text-align: left;
  font-size: 1rem;
}

.choice-button[data-kind="continue"] {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
}

.choice-button[data-kind="roleplay"] {
  border-color: var(--roleplay-line);
  color: var(--roleplay-ink);
}

.choice-button[data-kind="quiz"] {
  border-color: var(--quiz-line);
  color: var(--quiz-ink);
}

/* --- Training: header and problems -------------------------------------- */

.training-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.training-header h1 {
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.25;
}

.home-button {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
}

.home-button .icon {
  width: 1.25rem;
  height: 1.25rem;
}

.training-heading {
  flex: 1;
  min-width: 0;
}

.end-call-button {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  flex: none;
  border: none;
  border-radius: 50%;
  background: var(--sound-off-red);
  color: #ffffff;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.9375rem;
}

.connection-status::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
}

.connection-status[data-tone="idle"] {
  color: var(--muted);
}

.connection-status[data-tone="good"] {
  color: var(--good);
}

.connection-status[data-tone="waiting"] {
  color: var(--warn);
}

.connection-status[data-tone="bad"] {
  color: var(--bad);
}

.problem-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  border-radius: 0.75rem;
  background: var(--problem-surface);
  color: var(--problem-ink);
  font-size: 0.9375rem;
}

/* --- Training: the stage ------------------------------------------------- */

/* Top to bottom: the conversation, any choices, the round buttons. Each has
   its own row, so text never runs under the options or the buttons. */
.training-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.conversation-area {
  position: relative; /* holds the "Back to latest" pill */
  flex: 1;
  min-height: 0;
  display: flex;
}

/* The edges fade, so lines slide in and out rather than being cut. */
.conversation-scroll {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  padding: 1.25rem 0 1rem;
  overflow-y: auto;
  mask-image: linear-gradient(to bottom, transparent 0, #000 1.25rem, #000 calc(100% - 1rem), transparent 100%);
}

/* Lines sit at the bottom, near the controls, as in a messaging app. */
.conversation {
  flex: 1 0 auto; /* fills an empty view, so its placeholder can centre */
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.625rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* app.js puts the words in data-empty-note and data-start-note. */
.conversation:empty::before {
  content: attr(data-empty-note);
  margin: auto;
  color: var(--muted);
}

/* Off a call, the microphone guide says what to do instead. */
.training-stage[data-call="off"] .conversation:empty::before {
  content: none;
}

/* --- Training: the microphone guide, before a call ------------------------ */

/* Centred where the conversation will be: a small picture of the two ways
   the call works, then what to do. */
.mic-guide {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  max-width: 20rem;
  margin: 0 auto;
  text-align: center;
}

.mic-guide:not([hidden]) ~ .conversation {
  flex: none;
}

.mic-guide-picture {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 0.5rem;
}

.mic-guide-picture figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.375rem;
  width: 6.5rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.3;
}

.mic-guide-badge {
  display: grid;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: var(--sound-green);
  color: #fff;
}

.mic-guide-badge .icon {
  width: 1.75rem;
  height: 1.75rem;
}

/* Waiting to be allowed: ringed in the pointer's gold. */
.mic-guide[data-mic="ask"] .mic-badge {
  box-shadow: 0 0 0 3px var(--pointer), 0 0 0 7px var(--pointer-glow);
}

.mic-guide[data-mic="off"] .mic-badge {
  background: var(--sound-off-red);
}

.mic-guide[data-mic="off"] .show-when-mic-usable,
.mic-guide:not([data-mic="off"]) .show-when-mic-off {
  display: none;
}

.mic-guide-title {
  margin: 0;
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
}

.mic-guide-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

/* Filled green like Start session and Back to home, so it reads as the way on. */
.mic-help-button {
  width: 100%;
  margin-top: 0.5rem;
  text-align: center;
}

/* Connected, and the Teacher waits for Start session. Large and bold, like
   the line being spoken, so it is clear what to do next. */
.training-stage[data-start="waiting"] .conversation:empty::before {
  content: attr(data-start-note);
  max-width: 18rem;
  color: var(--ink);
  font-size: 1.4375rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  white-space: pre-line;
}

/* The status line below says every session is finished. */
.training-stage[data-call="finished"] .conversation:empty::before {
  content: none;
}

/* Each line: the speaker's name, then the text. */
.conversation li {
  max-width: 85%;
  padding: 0.5rem 0.875rem;
  border-radius: 1rem;
  white-space: pre-wrap; /* model replies can contain line breaks */
  overflow-wrap: break-word;
}

.conversation .text {
  display: block;
}

.conversation .trainer {
  align-self: flex-start;
  background: var(--teacher-surface);
}

.conversation .trainer .speaker-name {
  color: var(--teacher-label);
}

.conversation .learner {
  align-self: flex-end;
  background: var(--learner-surface);
}

.conversation .learner .speaker-name {
  color: var(--learner-label);
}

/* An AI learner, as in a group chat: left side, in that learner's tint, with
   the name in the stronger shade (--ai-learner-tint and --name-color, set by
   app.js). */
.conversation .ai-learner {
  align-self: flex-start;
  background: var(--ai-learner-tint);
}

.conversation .ai-learner .speaker-name {
  color: var(--name-color);
}

/* "· AI learner" after the name, in immersive only. */
.speaker-role {
  display: none;
}

/* A line's paragraphs (app.js splits it at blank lines). Immersive shows
   them as paragraphs; chat as one bubble each, below. The name copied into
   the first is for chat only. */
.conversation .paragraph {
  display: block;
}

.conversation .paragraph + .paragraph {
  margin-top: 0.75em;
}

.first-bubble-name {
  display: none;
}

/* Chat: each paragraph is its own bubble, close under the one before, with
   the name inside the first only, as WhatsApp groups messages sent in a row.
   The line itself is only their column. */
.training-stage[data-view="chat"] .conversation li {
  padding: 0;
  background: none;
}

.training-stage[data-view="chat"] .conversation li > .speaker-name {
  display: none;
}

.training-stage[data-view="chat"] .conversation .first-bubble-name {
  display: block;
}

.training-stage[data-view="chat"] .conversation .text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
}

.training-stage[data-view="chat"] .conversation .learner .text {
  align-items: flex-end;
}

/* A bubble not shown yet (paceBubbles in app.js). */
.training-stage[data-view="chat"] .conversation .paragraph.waiting {
  display: none;
}

.training-stage[data-view="chat"] .conversation .paragraph {
  max-width: 100%;
  margin: 0;
  padding: 0.5rem 0.875rem;
  border-radius: 1rem;
}

.training-stage[data-view="chat"] .conversation .trainer .paragraph {
  background: var(--teacher-surface);
}

.training-stage[data-view="chat"] .conversation .learner .paragraph {
  background: var(--learner-surface);
}

.training-stage[data-view="chat"] .conversation .ai-learner .paragraph {
  background: var(--ai-learner-tint);
}

.training-stage[data-view="chat"] .interrupted-note {
  padding: 0 0.875rem;
}

/* A line the learner cut off: the part never spoken is dimmed. */
.unheard {
  opacity: 0.4;
}

.interrupted-note {
  display: block;
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.875rem;
}

/* --- Training: immersive, a calm feed ------------------------------------ */

/* No bubbles except the learner's own. What is being spoken now is large;
   everything else is ordinary text. Size alone marks what is live. */
.training-stage[data-view="immersive"] .conversation {
  gap: 1.125rem;
}

.training-stage[data-view="immersive"] .conversation li:not(.learner) {
  max-width: none;
  padding: 0;
  border-radius: 0;
  background: none;
}

.training-stage[data-view="immersive"] .conversation .text {
  margin-top: 0.25rem;
  font-size: 1.0625rem;
  line-height: 1.5;
}

.training-stage[data-view="immersive"] .speaker-name {
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Spacing pulls apart Gujarati's joined letters, and it has no capitals. */
:root:lang(gu) .training-stage[data-view="immersive"] .speaker-name {
  letter-spacing: 0;
}

.training-stage[data-view="immersive"] .speaker-role {
  display: inline;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

/* The learner's own bubble has no name: it is clearly theirs. */
.training-stage[data-view="immersive"] .learner .speaker-name {
  display: none;
}

.training-stage[data-view="immersive"] .learner .text {
  margin-top: 0;
}

/* The paragraph being spoken. */
.training-stage[data-view="immersive"] .live-paragraph {
  font-size: 1.4375rem;
  font-weight: 700;
  line-height: 1.35;
}

/* The question the open options answer: the reply's last sentence. */
.training-stage[data-view="immersive"] .question-sentence {
  font-size: 1.4375rem;
  font-weight: 700;
  line-height: 1.3;
}

/* A line with no voice to follow (the learner's own, or a short line from
   the Teacher) is large while it is the newest. A saved session being
   revised has nothing live, so it stays even. */
.training-stage[data-view="immersive"] .conversation > li:last-child:not(.voiced, .saved) .text {
  font-size: 1.4375rem;
  font-weight: 700;
  line-height: 1.35;
}

/* --- Training: the Trainer thinking --------------------------------------- */

/* Three soft dots under the Trainer's name: a Trainer bubble in chat, plain
   in immersive, like the Trainer's lines. */
.trainer-thinking {
  align-self: flex-start;
  padding: 0.5rem 0.875rem;
  border-radius: 1rem;
  background: var(--teacher-surface);
}

.trainer-thinking[hidden] {
  display: none;
}

.trainer-thinking .speaker-name {
  display: block;
  color: var(--teacher-label);
}

.training-stage[data-view="immersive"] .trainer-thinking {
  margin-top: 0.5rem; /* the immersive feed's wider gap */
  padding: 0;
  background: none;
}

.thinking-dots {
  display: flex;
  gap: 0.3125rem;
  padding: 0.5rem 0 0.25rem;
}

.thinking-dots span {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--teacher-label);
  opacity: 0.45;
  animation: thinking-dot 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes thinking-dot {
  0%,
  60%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  30% {
    opacity: 0.8;
    transform: translateY(-0.1875rem);
  }
}

/* --- Training: what the room is doing, and the way back down ------------- */

.room-state {
  color: var(--muted);
  font-size: 0.875rem;
}

.room-state:empty {
  display: none;
}

.room-state[data-state="ended"],
.room-state[data-state="allFinished"],
.room-state[data-state="revising"],
.room-state[data-state="nothingSaved"] {
  color: var(--ink);
  font-size: 1.0625rem;
  font-weight: 700;
}

.back-to-latest {
  position: absolute;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.625rem 1.125rem;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.2);
}

.back-to-latest .icon {
  width: 1.125rem;
  height: 1.125rem;
}

/* --- Training: choices ---------------------------------------------------- */

/* Full-width options in a tinted panel. On a small phone with the keyboard
   open it stops at 45% of the stage and scrolls inside itself. */
.choice-panel {
  flex: none;
  max-height: 45%;
  overflow-y: auto;
  margin-top: 0.5rem;
  padding: 0.625rem;
  border-radius: 1.25rem;
  background: var(--teacher-surface);
}

.choice-panel-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.choice-panel-options .choice-button {
  width: 100%;
  line-height: 1.3;
}

/* --- Training: the round buttons ----------------------------------------- */

.round-controls {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding-top: 0.75rem;
}

.round-button {
  display: grid;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  border: none;
  border-radius: 50%;
  color: #ffffff;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.15);
}

.view-button {
  background: var(--view-blue);
}

.call-button {
  width: 4.25rem;
  height: 4.25rem;
  background: var(--mic-green);
}

.call-button .icon {
  width: 1.75rem;
  height: 1.75rem;
}

.pause-button {
  width: 4.25rem;
  height: 4.25rem;
  background: var(--pause-orange);
}

.pause-button .icon {
  width: 1.75rem;
  height: 1.75rem;
}

.sound-button {
  background: var(--sound-green);
}

.sound-button.sound-off {
  background: var(--sound-off-red);
}

/* Each two-state button carries both icons; its state picks one. */
.training-stage[data-view="immersive"] .show-when-chat,
.training-stage[data-view="chat"] .show-when-immersive,
.pause-button:not(.paused) .show-when-paused,
.pause-button.paused .show-when-playing,
.sound-button:not(.sound-off) .show-when-sound-off,
.sound-button.sound-off .show-when-sound-on {
  display: none;
}

/* --- Roleplay: a counsellor and Priya ------------------------------------- */

.roleplay-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: none;
  margin: 0 -1rem;
  padding: 0 1rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.roleplay-header h1 {
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.25;
}

.roleplay-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.875rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.legend-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
}

.legend-dot[data-speaker="priya"] {
  background: var(--patient-dot);
}

.legend-dot[data-speaker="counsellor"] {
  background: var(--counsellor-dot);
}

/* The lines sit at the bottom while there are few, as in a chat. */
.roleplay-scroll {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.roleplay-lines {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: auto 0 0;
  padding: 0;
  list-style: none;
}

.roleplay-line {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: 1rem;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.roleplay-line .speaker-name {
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Spacing pulls Gujarati's joined letters apart, and it has no capitals. */
:root:lang(gu) .roleplay-line .speaker-name {
  letter-spacing: 0;
}

/* A later bubble of the same speaker's run, close beneath the one before. */
.roleplay-line.same-speaker {
  margin-top: -0.5rem;
}

.roleplay-line[data-speaker="counsellor"] {
  align-self: flex-end;
  background: var(--counsellor-surface);
}

.roleplay-line[data-speaker="counsellor"] .speaker-name {
  color: var(--counsellor-label);
}

/* The learner's own lines, in the counsellor's place, in the learner's blue. */
.roleplay-line[data-speaker="learner"] {
  align-self: flex-end;
  background: var(--learner-surface);
}

.roleplay-line[data-speaker="learner"] .speaker-name {
  color: var(--learner-label);
}

.roleplay-line[data-speaker="priya"] {
  align-self: flex-start;
  background: var(--patient-surface);
}

.roleplay-line[data-speaker="priya"] .speaker-name {
  color: var(--patient-label);
}

/* The caret while a line is being written. */
.roleplay-line.writing .text::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1.1em;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: var(--counsellor-label);
  animation: blink 1s steps(2) infinite;
}

.roleplay-priya-typing {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  align-self: flex-start;
  flex: none;
  padding: 0.375rem 0.875rem;
  border: 1px dashed var(--patient-dot);
  border-radius: 1rem;
  background: var(--patient-surface);
  color: var(--muted);
  font-size: 0.875rem;
}

.roleplay-priya-typing .thinking-dots {
  padding: 0;
}

.roleplay-priya-typing .thinking-dots span {
  width: 0.375rem;
  height: 0.375rem;
  background: var(--patient-label);
}

.roleplay-footer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: none;
  margin: 0 -1rem;
  padding: 0.75rem 1rem 0;
  border-top: 1px solid var(--line);
}

.roleplay-next-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3.5rem;
  padding: 0 1rem;
  border: none;
  border-radius: 1rem;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 1.0625rem;
  font-weight: 700;
  box-shadow: 0 3px 0 rgb(0 0 0 / 0.25);
}

.roleplay-next-button .icon {
  width: 1.25rem;
  height: 1.25rem;
}

/* Greyed while a step runs, with the dots, but not faded. */
.roleplay-next-button[data-state="waiting"] {
  background: var(--waiting-surface);
  color: var(--muted);
  box-shadow: none;
  opacity: 1;
}

.roleplay-next-button .thinking-dots {
  padding: 0;
}

.roleplay-next-button .thinking-dots span {
  background: currentColor;
}

.roleplay-next-button:not([data-state="waiting"]) .show-when-waiting,
.roleplay-next-button:not([data-state="ready"]) .show-when-ready {
  display: none;
}

.roleplay-caption {
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
}

.roleplay-caption[data-tone="bad"] {
  color: var(--bad);
}

/* --- Quiz: one question at a time, then the score --------------------------- */

.quiz-screen {
  padding-bottom: 0; /* the bottom sheet runs to the edge */
}

.quiz-header {
  padding-bottom: 0.25rem;
  border-bottom: none;
}

.quiz-title {
  flex: 1;
  min-width: 0;
  font-size: 1.0625rem;
  font-weight: 700;
}

.quiz-count {
  flex: none;
  color: var(--muted);
  font-weight: 700;
}

/* A thin bar per question; the button around it is taller, to be tapped. */
.quiz-segments {
  display: flex;
  gap: 0.3rem;
  flex: none;
}

.quiz-segment {
  flex: 1;
  height: 0.875rem;
  padding: 0;
  border: none;
  background: none;
}

.quiz-segment::after {
  content: "";
  display: block;
  height: 0.3rem;
  border-radius: 999px;
  background: var(--line);
}

.quiz-segment[data-state="right"]::after {
  background: var(--quiz-right-dot);
}

.quiz-segment[data-state="wrong"]::after {
  background: var(--quiz-amber);
}

.quiz-segment[data-state="current"]::after {
  background: var(--primary);
}

.quiz-segment:disabled {
  opacity: 1;
}

.quiz-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.5rem 0 0.75rem;
}

.quiz-question {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.3;
}

.quiz-choose {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  min-height: 4.25rem;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: 1rem;
  background: var(--field);
  color: var(--ink);
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
}

.quiz-number {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--waiting-surface);
  color: var(--muted);
  font-weight: 700;
}

.quiz-option[aria-pressed="true"] {
  border: 2px solid var(--quiz-pick);
  background: var(--quiz-pick-surface);
  color: var(--quiz-pick-ink);
}

.quiz-option[aria-pressed="true"] .quiz-number {
  background: var(--quiz-pick);
  color: var(--page);
}

/* Checked: the question and the other answers step back. */
.quiz-screen[data-step="answered"] .quiz-question {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
}

.quiz-screen[data-step="answered"] .quiz-choose {
  display: none;
}

.quiz-screen[data-step="answered"] .quiz-options {
  gap: 0.5rem;
}

.quiz-screen[data-step="answered"] .quiz-option {
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border-width: 1px;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 400;
  cursor: default;
}

.quiz-screen[data-step="answered"] .quiz-number {
  width: 1.5rem;
  height: 1.5rem;
  font-size: 0.875rem;
}

.quiz-screen[data-step="answered"] .quiz-option[data-result] {
  min-height: 4rem;
  padding: 0.75rem 1rem;
  border-width: 2px;
  font-size: 1.0625rem;
  font-weight: 700;
}

.quiz-option[data-result="right"] {
  border-color: var(--good);
  background: var(--quiz-right-surface);
  color: var(--quiz-right-ink) !important;
}

.quiz-option[data-result="wrong"] {
  border-color: var(--quiz-wrong);
  background: var(--quiz-wrong-surface);
  color: var(--quiz-wrong-ink) !important;
}

.quiz-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  color: var(--page);
}

.quiz-mark .icon {
  width: 1.25rem;
  height: 1.25rem;
}

.quiz-option[data-result="right"] .quiz-mark,
.quiz-verdict .quiz-mark {
  background: var(--good);
}

.quiz-option[data-result="wrong"] .quiz-mark {
  background: var(--quiz-wrong);
}

.quiz-option-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* The bottom: the Check answer button, or once checked a sheet that says why. */
.quiz-bottom {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: none;
  margin: 0 -1rem;
  padding: 0.75rem 1rem max(0.75rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--page);
}

.quiz-bottom[data-result] {
  padding-top: 1rem;
  border-top: 2px solid;
  border-radius: 1.25rem 1.25rem 0 0;
}

.quiz-bottom[data-result="right"] {
  border-color: var(--good);
  background: var(--quiz-right-surface);
}

.quiz-bottom[data-result="wrong"] {
  border-color: var(--quiz-wrong);
  background: var(--quiz-wrong-surface);
}

.quiz-sheet {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  max-height: 42dvh;
  overflow-y: auto;
}

.quiz-sheet:empty {
  display: none;
}

.quiz-verdict {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 0.25rem;
  font-size: 1.625rem;
  font-weight: 800;
}

.quiz-bottom[data-result="right"] .quiz-verdict {
  color: var(--quiz-right-ink);
}

.quiz-bottom[data-result="wrong"] .quiz-verdict {
  color: var(--quiz-wrong-ink);
}

.quiz-label {
  margin-top: 0.25rem;
  color: var(--good);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.quiz-label[data-tone="wrong"] {
  color: var(--quiz-wrong-ink);
}

.quiz-why {
  font-size: 1.0625rem;
  line-height: 1.5;
}

.quiz-remember {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  margin-top: 0.5rem;
  padding: 0.875rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--field);
  line-height: 1.4;
}

.quiz-remember .icon {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  color: var(--good);
}

.quiz-nav {
  display: flex;
  gap: 0.5rem;
}

.quiz-back-button {
  display: grid;
  place-items: center;
  flex: none;
  width: 3.5rem;
  height: 3.5rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--field);
  color: var(--ink);
}

.quiz-back-button .icon {
  width: 1.375rem;
  height: 1.375rem;
}

.quiz-main-button {
  flex: 1;
}

.quiz-main-button:disabled {
  background: var(--waiting-surface);
  color: var(--muted);
  box-shadow: none;
  opacity: 1;
}

.quiz-second-button {
  min-height: 3.5rem;
  border: 2px solid var(--line);
  border-radius: 1rem;
  background: var(--field);
  color: var(--ink);
  font-size: 1.0625rem;
  font-weight: 700;
}

.quiz-caption {
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
}

.quiz-caption:empty {
  display: none;
}

/* The score, in place of the question. */
.quiz-score {
  display: none;
}

.quiz-screen[data-step="score"] .quiz-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin: auto 0;
  text-align: center;
}

.quiz-screen[data-step="score"] :is(.quiz-question, .quiz-choose, .quiz-options, .quiz-segments, .quiz-count) {
  display: none;
}

.quiz-screen[data-step="score"] .quiz-bottom {
  border-top: none;
}

.quiz-trophy {
  display: grid;
  place-items: center;
  width: 6rem;
  height: 6rem;
  margin-bottom: 0.75rem;
  border-radius: 50%;
  background: var(--quiz-right-surface);
  color: var(--good);
}

.quiz-trophy .icon {
  width: 2.75rem;
  height: 2.75rem;
}

.quiz-finished {
  color: var(--muted);
  font-weight: 600;
}

.quiz-score-total {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.1;
}

.quiz-score-note {
  color: var(--muted);
  font-size: 1.0625rem;
}

.quiz-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.quiz-dot {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--quiz-right-dot);
}

.quiz-dot[data-state="wrong"] {
  background: var(--quiz-amber);
}

/* --- Talking, by holding or tapping the mic (Training and Home) ---------- */

.mic-button {
  touch-action: none; /* holding the button must not scroll or zoom the page */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.15s;
}

/* Red and pulsing while it records; larger only while a finger is on it.
   Tapped on, it shows a stop square: the next tap sends. */
.mic-button.recording {
  background: var(--sound-off-red);
  animation: mic-pulse 1.2s ease-out infinite;
}

.mic-button.held {
  transform: scale(1.15);
}

.mic-button:not(.tap-to-stop) .show-when-tap-to-stop,
.mic-button.tap-to-stop .show-when-mic-ready {
  display: none;
}

@keyframes mic-pulse {
  from {
    box-shadow: 0 0 0 0 rgb(200 66 58 / 0.45);
  }
  to {
    box-shadow: 0 0 0 0.875rem rgb(200 66 58 / 0);
  }
}

.listening-hint {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  height: 3rem;
  padding: 0 1.125rem;
  border-radius: 1.5rem;
  background: var(--field);
  border: 1px solid var(--sound-off-red);
  color: var(--sound-off-red);
  font-weight: 600;
}

.listening-dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  background: currentColor;
  animation: blink 1s steps(2) infinite;
}

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

/* The Home bot points at a button until it is tapped or 8 s pass: a solid
   gold ring, with a glow that swells and a gentle grow, once a second. The
   bot only points; tapping is up to the learner. */
.bot-pointing {
  box-shadow: 0 0 0 3px var(--pointer), 0 0 0 9px var(--pointer-glow);
  animation: bot-pointing-pulse 1s ease-in-out infinite;
}

@keyframes bot-pointing-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 3px var(--pointer), 0 0 0 3px var(--pointer-glow);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 3px var(--pointer), 0 0 0 9px var(--pointer-glow);
    transform: scale(1.03);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before {
    animation: none !important;
    transition: none !important;
  }

  /* No pulse: the gold ring and its glow stay still (.bot-pointing's own
     box-shadow), and the Trainer's thinking dots sit still at half strength. */
}

.icon-sprite {
  position: absolute;
}
