:root {
  color-scheme: light;
  --ink: #18233f;
  --muted: #65708a;
  --paper: #fffdf8;
  --canvas: #f5f1e8;
  --line: #d9d3c8;
  --blue: #3157d5;
  --blue-dark: #2442a8;
  --blue-soft: #e9edff;
  --orange: #f28a44;
  --green: #25856f;
  --scoreboard-bg: #2442a8;
  --scoreboard-text: #ffffff;
  --scoreboard-score: #ffd09f;
  --shadow: 0 18px 44px rgba(35, 48, 84, 0.12);
  --student-nav-height: 58px;
  --standalone-height: 54px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f3f5ff;
  --muted: #aeb7ce;
  --paper: #171c2c;
  --canvas: #101522;
  --line: #343d56;
  --blue: #7691ff;
  --blue-dark: #9cafff;
  --blue-soft: #252f55;
  --orange: #ff9a5c;
  --green: #55bca3;
  --scoreboard-bg: #2f4594;
  --scoreboard-text: #ffffff;
  --scoreboard-score: #ffd1a8;
  --shadow: 0 20px 48px rgba(0, 0, 0, 0.28);
}
* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-width: 320px;
  margin: 0;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-rows: auto var(--student-nav-height) minmax(0, 1fr);
  color: var(--ink);
  background: var(--canvas);
}

html.is-embedded .standalone-only { display: none; }
html.is-embedded body {
  grid-template-rows: var(--student-nav-height) minmax(0, 1fr);
}
button, summary { font: inherit; }
button { color: inherit; }

button:focus-visible,
summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--orange) 75%, white);
  outline-offset: 3px;
}

.standalone-header {
  height: var(--standalone-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.standalone-header div { display: flex; align-items: baseline; gap: 10px; }
.standalone-header span,
.standalone-header small { color: var(--muted); }

.student-nav {
  width: min(760px, calc(100% - 32px));
  height: var(--student-nav-height);
  margin: 0 auto;
  display: flex;
  align-items: end;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.student-nav__item {
  min-height: 44px;
  padding: 0 18px 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.student-nav__item.is-active {
  color: var(--blue-dark);
  border-bottom-color: var(--blue);
}

.student-nav__number {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13px;
}

#main-content { min-height: 0; overflow: hidden; }

.screen {
  width: min(760px, calc(100% - 32px));
  height: 100%;
  margin: 0 auto;
  display: grid;
  align-items: center;
  padding: clamp(12px, 2.4vh, 24px) 0;
  overflow: hidden;
}

.screen[hidden] { display: none !important; }

.focus-card,
.task-card,
.result-card,
.route-screen {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.focus-card--home {
  min-height: min(430px, 100%);
  display: grid;
  grid-template-columns: minmax(190px, 0.72fr) minmax(0, 1.28fr);
  overflow: hidden;
}

.focus-card__art {
  position: relative;
  min-height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--blue-soft);
}

.sound-orbit {
  position: absolute;
  aspect-ratio: 1;
  border: 2px solid color-mix(in srgb, var(--blue) 45%, transparent);
  border-radius: 50%;
}

.sound-orbit--outer { width: 210px; }
.sound-orbit--inner { width: 136px; border-style: dashed; }

.sound-mark {
  position: relative;
  z-index: 1;
  width: 82px;
  height: 82px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  color: white;
  background: var(--blue);
  font-family: Georgia, serif;
  font-size: 58px;
  font-style: italic;
  box-shadow: 12px 14px 0 color-mix(in srgb, var(--orange) 75%, transparent);
  transform: rotate(-4deg);
}

.focus-card__body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(28px, 4vw, 52px);
}

.task-kicker {
  margin: 0 0 10px;
  color: var(--blue-dark);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1, h2, p { overflow-wrap: anywhere; }

h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.12;
  letter-spacing: -0.035em;
}

.task-instruction {
  margin: 16px 0 20px;
  color: var(--muted);
  font-size: clamp(15px, 1.8vw, 18px);
  line-height: 1.65;
}

.step-preview {
  margin: 0 0 24px;
  padding: 0;
  display: flex;
  gap: 8px;
  list-style: none;
}

.step-preview li {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.step-preview span {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--canvas);
  font-size: 12px;
  font-weight: 800;
}

.step-preview .is-current { color: var(--ink); font-weight: 750; }
.step-preview .is-current span { color: white; background: var(--blue); }

.primary-action,
.secondary-action,
.choice-grid button,
.recording-actions button {
  min-height: 50px;
  border-radius: 14px;
  font-weight: 800;
  cursor: pointer;
}

.primary-action {
  width: fit-content;
  min-width: 180px;
  padding: 0 24px;
  border: 1px solid var(--blue);
  color: white;
  background: var(--blue);
  box-shadow: 0 8px 0 color-mix(in srgb, var(--blue-dark) 85%, black);
}

.primary-action:active { transform: translateY(4px); box-shadow: 0 4px 0 var(--blue-dark); }

.total-scoreboard {
  width: 100%;
  min-height: 64px;
  margin: 0 0 20px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-radius: 14px;
  color: var(--scoreboard-text);
  background: var(--scoreboard-bg);
}

.total-scoreboard span { font-size: 15px; font-weight: 800; }
.total-scoreboard strong { color: var(--scoreboard-score); font-size: 30px; line-height: 1; white-space: nowrap; }

.route-screen {
  width: 100%;
  max-height: 100%;
  padding: clamp(20px, 4vh, 36px);
  display: grid;
  gap: 14px;
  box-shadow: none;
}

.screen-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.screen-heading .task-kicker { margin-bottom: 6px; }
.screen-heading h1 { font-size: clamp(25px, 3.4vw, 38px); }

.route-card {
  min-height: 74px;
  padding: 16px 18px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
}

.route-card--current { border: 2px solid var(--blue); background: var(--blue-soft); }
.route-card--next { opacity: 0.72; }
.route-card__number { color: var(--blue-dark); font-weight: 900; }
.route-card h2 { margin: 0 0 3px; font-size: 17px; }
.route-card p { margin: 0; color: var(--muted); font-size: 13px; }
.route-card__state { font-size: 12px; font-weight: 800; color: var(--blue-dark); }
.route-lower { display: grid; grid-template-columns: 0.82fr 1.18fr; gap: 12px; }

.completed-route {
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--canvas);
}

.completed-route summary {
  min-height: 72px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-weight: 800;
}

#completed-route { padding: 0 18px 14px; color: var(--muted); font-size: 13px; }
.route-hidden { margin: 0; text-align: center; color: var(--muted); font-size: 13px; }

.task-card {
  width: 100%;
  max-height: 100%;
  padding: clamp(18px, 3.5vh, 32px);
  display: flex;
  flex-direction: column;
}

.task-card__header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.task-card__header .task-kicker { margin: 0; }
.task-dots { display: flex; gap: 5px; }
.task-dots span { width: 24px; height: 5px; border-radius: 8px; background: var(--line); }
.task-dots .is-active { background: var(--blue); }

.task-content {
  flex: 1;
  min-height: 0;
  display: grid;
  align-content: center;
  justify-items: center;
}

.task-content[hidden],
.recording-practice[hidden] { display: none !important; }

#lesson-panel { width: 100%; }

.lesson-stage {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.lesson-stage[hidden] { display: none !important; }
.lesson-stage h1 { max-width: 620px; font-size: clamp(28px, 4vw, 44px); }
.lesson-stage h2 { margin: 6px 0 18px; font-size: clamp(25px, 3.4vw, 36px); }

.sound-focus {
  margin: 24px 0;
  display: flex;
  align-items: center;
  gap: 18px;
}

.sound-focus strong,
.sound-focus span {
  min-width: 126px;
  padding: 15px 20px;
  border-radius: 18px;
  background: var(--blue-soft);
  font-size: clamp(28px, 4vw, 42px);
}

.sound-focus span { background: var(--canvas); font-family: Georgia, serif; }

.stage-actions {
  width: min(510px, 100%);
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 10px;
}

.secondary-action { padding: 0 18px; border: 1px solid var(--line); background: var(--paper); }

.pattern-pair {
  margin-bottom: 18px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border: 2px solid var(--blue);
  border-radius: 18px;
  background: var(--blue-soft);
}

.pattern-pair strong { font-size: clamp(24px, 3.4vw, 36px); }
.pattern-pair span { color: var(--blue-dark); font-size: 20px; font-weight: 800; }

.word-chip-list {
  width: min(560px, 100%);
  margin-bottom: 22px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.word-chip-list > span {
  min-width: 0;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
}

.word-chip-list strong { font-family: Georgia, serif; font-size: 21px; }
.word-chip-list small { color: var(--muted); font-size: 12px; }

.read-word { margin-top: 4px; font-family: Georgia, serif; font-size: clamp(46px, 7vw, 70px); }
.read-ipa { margin-top: 2px; color: var(--blue-dark); font-size: 18px; font-weight: 750; }

.assessment-meta {
  width: min(530px, 100%);
  display: flex;
  justify-content: space-between;
  color: var(--blue-dark);
  font-size: 13px;
  font-weight: 800;
}

.assessment-word { margin: 8px 0 18px; font-size: 40px; }

.answer-grid {
  width: min(530px, 100%);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.answer-grid button {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  cursor: pointer;
}

.answer-grid button:hover { border-color: var(--blue); background: var(--blue-soft); }
.answer-grid button span { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 8px; color: white; background: var(--blue); font-size: 12px; font-weight: 900; }
.answer-grid button strong { font-family: Georgia, serif; font-size: 22px; }

.task-progress { width: min(430px, 100%); display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.task-progress progress { flex: 1; height: 7px; accent-color: var(--blue); }
.task-prompt { margin: 22px 0 4px; font-size: 17px; font-weight: 750; }
.survey-word { margin: 6px 0 0; font-family: Georgia, serif; font-size: clamp(54px, 8vw, 82px); letter-spacing: -0.04em; }
.task-help { margin: 0 0 20px; color: var(--muted); font-size: 13px; }

.construction-panel { width: 100%; text-align: center; }
.construction-meta {
  width: min(620px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--blue-dark);
  font-size: 14px;
  font-weight: 850;
}
.construction-meta strong {
  min-width: 64px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--blue-soft);
}
.construction-word {
  margin: 4px 0 12px;
  font-family: Georgia, serif;
  font-size: clamp(42px, 7vw, 64px);
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.construction-workspace {
  width: min(620px, 100%);
  display: grid;
  justify-items: center;
  gap: 12px;
}
.construction-slots,
.construction-bank {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.construction-slot,
.construction-card {
  min-width: 54px;
  min-height: 52px;
  padding: 8px 13px;
  border-radius: 12px;
  color: var(--ink);
  background: var(--paper);
  font-size: 20px;
  font-weight: 850;
  cursor: pointer;
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1), border-color 180ms ease, background-color 180ms ease;
}
.construction-slot { border: 2px solid var(--blue); background: var(--blue-soft); }
.construction-slot.is-empty { border-style: dashed; color: var(--muted); background: transparent; }
.construction-card { border: 1px solid var(--line); box-shadow: 0 3px 0 color-mix(in srgb, var(--line) 75%, transparent); }
.construction-card:hover { border-color: var(--blue); background: var(--blue-soft); transform: translateY(-1px); }
.construction-card:active { transform: translateY(1px); }
.construction-card:disabled { opacity: 0.28; cursor: default; box-shadow: none; transform: none; }
.construction-feedback { min-height: 22px; margin: 0; color: var(--muted); font-size: 14px; }
.construction-actions {
  width: min(520px, 100%);
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1fr 0.8fr 1fr;
  gap: 9px;
}
.construction-actions button { min-height: 48px; border-radius: 12px; }
.construction-delta { margin-top: 10px; color: var(--green); font-size: 24px; }

.choice-grid { width: min(530px, 100%); display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.choice-grid button,
.recording-actions button { border: 1px solid var(--line); background: var(--paper); }
.choice-grid button:hover { border-color: var(--blue); background: var(--blue-soft); }
[data-key-hint] { display: inline-grid; width: 24px; height: 24px; margin-right: 7px; place-items: center; border: 1px solid currentColor; border-radius: 7px; font-size: 12px; }

.recording-practice { width: min(590px, 100%); margin: 10px 0 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.recording-target { display: flex; align-items: baseline; gap: 10px; }
.recording-target strong { font-size: 24px; }
.recording-target small,
.recording-practice p { color: var(--muted); }
.recording-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.recording-actions button { min-height: 44px; }
.recording-list { margin-top: 7px; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); font-size: 12px; }
.recording-list[hidden] { display: none; }
.recording-list button { border: 0; color: var(--blue-dark); background: transparent; font-weight: 800; cursor: pointer; }
.text-action { border: 0; color: var(--blue-dark); background: transparent; font-weight: 800; cursor: pointer; }

.result-card {
  min-height: min(360px, 100%);
  padding: 38px;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
}

.result-badge { width: 64px; height: 64px; margin-bottom: 18px; display: grid; place-items: center; border-radius: 22px; color: white; background: var(--green); font-size: 32px; font-weight: 900; transform: rotate(-5deg); }
.result-card h1 { font-size: clamp(28px, 4vw, 42px); }
.result-card p:not(.task-kicker) { margin: 14px 0 24px; color: var(--muted); }
.audio-notice { position: fixed; left: 50%; bottom: 18px; z-index: 20; transform: translateX(-50%); padding: 10px 16px; border-radius: 12px; color: white; background: var(--ink); font-weight: 750; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 760px) {
  :root { --student-nav-height: 52px; }
  .standalone-header { display: none; }
  body { grid-template-rows: var(--student-nav-height) minmax(0, 1fr); }
  .student-nav { width: 100%; padding: 0 10px; justify-content: center; background: var(--paper); }
  .student-nav__item { flex: 1; min-height: 48px; justify-content: center; padding: 0 8px 7px; }
  .student-nav__number,
  [data-key-hint] { display: none; }
  .screen { width: 100%; padding: 10px 12px max(10px, env(safe-area-inset-bottom)); }
  .focus-card,
  .task-card,
  .result-card,
  .route-screen { border-radius: 22px; }
  .focus-card--home { min-height: 0; height: 100%; grid-template-columns: 1fr; grid-template-rows: minmax(92px, 0.6fr) minmax(0, 1.4fr); }
  .focus-card__art { min-height: 92px; }
  .sound-orbit--outer { width: 140px; }
  .sound-orbit--inner { width: 94px; }
  .sound-mark { width: 58px; height: 58px; border-radius: 18px; font-size: 42px; box-shadow: 7px 8px 0 color-mix(in srgb, var(--orange) 75%, transparent); }
  .focus-card__body { padding: 18px; justify-content: center; }
  h1 { font-size: clamp(27px, 8vw, 34px); }
  .task-instruction { margin: 10px 0 14px; font-size: 14px; line-height: 1.5; }
  .step-preview { margin-bottom: 16px; }
  .step-preview li { justify-content: center; font-size: 12px; }
  .step-preview li:not(.is-current) { color: transparent; flex: 0 0 28px; }
  .step-preview li:not(.is-current) span { color: var(--muted); }
  .primary-action { width: 100%; min-width: 0; min-height: 50px; }
  .total-scoreboard { min-height: 64px; margin-bottom: 12px; padding: 8px 14px; }
  .total-scoreboard strong { font-size: 28px; }
  .route-screen { padding: 16px; gap: 10px; box-shadow: none; }
  .screen-heading h1 { font-size: 26px; }
  .route-card { min-height: 68px; padding: 12px 14px; gap: 9px; }
  .route-card h2 { font-size: 15px; }
  .route-lower { grid-template-columns: 1fr; }
  .completed-route summary { min-height: 58px; }
  .route-hidden { font-size: 12px; }
  .task-card { height: 100%; padding: 16px; box-shadow: none; }
  .task-prompt { margin-top: 16px; font-size: 15px; }
  .survey-word { font-size: clamp(52px, 19vw, 72px); }
  .task-help { margin-bottom: 14px; text-align: center; }
  .choice-grid { grid-template-columns: 1fr; gap: 7px; }
  .choice-grid button { min-height: 48px; }
  .construction-word { margin-bottom: 8px; font-size: clamp(38px, 14vw, 54px); }
  .construction-workspace { gap: 9px; }
  .construction-slots,
  .construction-bank { gap: 6px; }
  .construction-slot,
  .construction-card { min-width: 48px; min-height: 48px; padding: 6px 10px; font-size: 17px; }
  .construction-feedback { min-height: 36px; font-size: 13px; }
  .construction-actions { margin-top: 10px; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .construction-actions button { min-height: 52px; padding: 0 8px; font-size: 13px; }
  .recording-actions { grid-template-columns: repeat(2, 1fr); }
  .lesson-stage h1 { font-size: 27px; }
  .lesson-stage h2 { margin-bottom: 12px; font-size: 25px; }
  .sound-focus { margin: 14px 0; gap: 8px; }
  .sound-focus strong,
  .sound-focus span { min-width: 104px; padding: 11px 13px; border-radius: 14px; font-size: 28px; }
  .stage-actions { grid-template-columns: 1fr; gap: 7px; }
  .stage-actions button { width: 100%; min-height: 48px; }
  .pattern-pair { margin-bottom: 10px; padding: 9px 13px; }
  .pattern-pair strong { font-size: 24px; }
  .pattern-pair span { font-size: 16px; }
  .word-chip-list { margin-bottom: 12px; grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .word-chip-list > span { padding: 6px; }
  .word-chip-list strong { font-size: 18px; }
  .read-word { font-size: 48px; }
  .read-ipa { font-size: 15px; }
  .recording-practice { margin: 6px 0 8px; padding-top: 6px; }
  .recording-practice p { margin: 4px 0 7px; font-size: 12px; }
  .recording-actions button { min-height: 42px; font-size: 12px; }
  .assessment-word { margin: 4px 0 10px; }
  .answer-grid { gap: 7px; }
  .answer-grid button { min-height: 52px; padding: 0 10px; }
  .answer-grid button strong { font-size: 18px; }
  .result-card { height: 100%; padding: 24px 18px; box-shadow: none; }
  html.is-embedded #continue-learning,
  html.is-embedded #result-continue,
  html.is-embedded #listen-next,
  html.is-embedded #pattern-next,
  html.is-embedded #read-next,
  html.is-embedded #lesson-complete,
  html.is-embedded #survey-actions,
  html.is-embedded .construction-actions {
    display: none !important;
  }
}

@media (max-height: 660px) {
  .screen { padding-top: 8px; padding-bottom: 8px; }
  .task-kicker { margin-bottom: 6px; }
  .task-instruction { margin-top: 8px; margin-bottom: 10px; }
  .step-preview { margin-bottom: 10px; }
  .total-scoreboard { margin-bottom: 8px; }
  .route-screen { gap: 8px; padding-top: 12px; padding-bottom: 12px; }
  .task-card { padding-top: 12px; padding-bottom: 12px; }
  .task-prompt { margin-top: 10px; }
  .survey-word { font-size: 50px; }
  .task-help { margin-bottom: 8px; }
  .construction-word { margin-top: 0; margin-bottom: 5px; font-size: 40px; }
  .construction-workspace { gap: 6px; }
  .construction-slot,
  .construction-card { min-height: 42px; padding-top: 4px; padding-bottom: 4px; }
  .construction-actions { margin-top: 7px; }
  .sound-focus { margin-top: 8px; margin-bottom: 8px; }
  .word-chip-list { margin-bottom: 8px; }
  .recording-actions button { min-height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
