:root {
  --teacher-ink: #e8dfcc;
  --teacher-muted: #a89f8d;
  --teacher-paper: #151b1a;
  --teacher-paper-raised: #1d2522;
  --teacher-vermilion: #e15a3c;
  --teacher-gold: #d6a24f;
  --teacher-jade: #5ca88c;
  --teacher-line: rgba(232, 223, 204, .14);
}

[data-theme="light"] {
  --teacher-ink: #292821;
  --teacher-muted: #706b5f;
  --teacher-paper: #eee7d7;
  --teacher-paper-raised: #f8f2e5;
  --teacher-vermilion: #bd422e;
  --teacher-gold: #9b6b20;
  --teacher-jade: #357c67;
  --teacher-line: rgba(41, 40, 33, .14);
}

body {
  color: var(--teacher-ink);
  background:
    radial-gradient(circle at 16% 8%, rgba(225, 90, 60, .12), transparent 32rem),
    radial-gradient(circle at 88% 82%, rgba(92, 168, 140, .09), transparent 34rem),
    linear-gradient(145deg, var(--teacher-paper), color-mix(in srgb, var(--teacher-paper) 88%, black));
  font-family: "Noto Sans CJK SC", "Source Han Sans SC", "Segoe UI", sans-serif;
}

.topbar {
  border-bottom: 1px solid var(--teacher-line);
  background: color-mix(in srgb, var(--teacher-paper) 84%, transparent);
  backdrop-filter: blur(18px) saturate(125%);
}

.brand strong,
.prompt-card .meaning,
.learning-view h1,
.game-center h2 {
  font-family: "Iowan Old Style", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
}

.brand-seal {
  box-shadow: 0 8px 28px rgba(225, 90, 60, .24), inset 0 0 0 1px rgba(255,255,255,.16);
}

.header-stats > div {
  min-width: 3.8rem;
}

.header-stats strong {
  color: var(--teacher-ink);
  font-variant-numeric: tabular-nums;
}

.header-stats span {
  color: var(--teacher-muted);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.study-panel > * {
  animation: teacher-arrive .34s cubic-bezier(.2,.78,.25,1) both;
}

.prompt-card,
.learning-view,
.microgame-view,
.conversation-view,
.pronunciation-view {
  border: 1px solid var(--teacher-line);
  background:
    linear-gradient(135deg, rgba(255,255,255,.035), transparent 38%),
    color-mix(in srgb, var(--teacher-paper-raised) 94%, transparent);
  box-shadow: 0 24px 72px rgba(0,0,0,.2);
}

.prompt-card::before,
.learning-view::before {
  background: linear-gradient(90deg, var(--teacher-vermilion), var(--teacher-gold), transparent 82%);
}

.primary-button {
  background: linear-gradient(135deg, var(--teacher-vermilion), color-mix(in srgb, var(--teacher-vermilion) 76%, #8b281e));
  box-shadow: 0 10px 26px rgba(225, 90, 60, .2);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[role="button"]:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--teacher-gold) 75%, white);
  outline-offset: 3px;
}

.freedom-note {
  margin: 1.25rem 0 0;
  padding: .9rem 1rem;
  border-left: 2px solid var(--teacher-jade);
  color: var(--teacher-muted);
  line-height: 1.55;
}

.game-hud {
  gap: .42rem;
  width: auto;
  padding-inline: .72rem;
  border-color: var(--teacher-line);
  background: color-mix(in srgb, var(--teacher-paper-raised) 88%, transparent);
}

.game-hud-symbol {
  color: var(--teacher-gold);
  font-family: "Noto Serif CJK SC", serif;
  font-size: 1.05rem;
}

.game-hud-label {
  color: var(--teacher-muted);
  font-size: .72rem;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.game-center-intro {
  max-width: 42rem;
  color: var(--teacher-muted);
  font-size: 1.02rem;
  line-height: 1.6;
}

.tone-family-practice,
.pronunciation-family {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  gap: .7rem;
  width: 100%;
}

.tone-family-practice button,
.pronunciation-family button {
  display: grid;
  gap: .2rem;
  padding: .8rem;
  border: 1px solid var(--teacher-line);
  border-radius: 14px;
  color: var(--teacher-ink);
  background: color-mix(in srgb, var(--teacher-paper) 72%, transparent);
  text-align: center;
}

.tone-family-practice b,
.pronunciation-family b {
  font-family: "Noto Serif CJK SC", "Source Han Serif SC", serif;
  font-size: 2rem;
}

.tone-family-practice em,
.pronunciation-family small,
.connected-speech-example em,
.sentence-pattern em {
  color: var(--teacher-gold);
  font-style: normal;
}

.connected-speech-example {
  display: grid;
  justify-items: center;
  gap: .25rem;
  padding: 1rem;
}

.connected-speech-example b {
  font-family: "Noto Serif CJK SC", "Source Han Serif SC", serif;
  font-size: clamp(3rem, 10vw, 6rem);
}

.connected-speech-rule {
  padding: .9rem 1rem;
  border-left: 2px solid var(--teacher-gold);
  background: color-mix(in srgb, var(--teacher-gold) 7%, transparent);
  line-height: 1.55;
}

.sentence-pattern {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .65rem;
  width: 100%;
}

.sentence-pattern > div {
  display: grid;
  min-width: 7rem;
  gap: .2rem;
  padding: .85rem;
  border: 1px solid var(--teacher-line);
  border-radius: 14px;
  text-align: center;
}

.sentence-pattern b {
  font-family: "Noto Serif CJK SC", "Source Han Serif SC", serif;
  font-size: 2rem;
}

.sentence-pattern small {
  color: var(--teacher-vermilion);
}

.pronunciation-listening-lab {
  display: grid;
  gap: .8rem;
  width: min(100%, 38rem);
  margin: .5rem auto 1rem;
  padding: 1rem;
  border: 1px solid var(--teacher-line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--teacher-jade) 7%, transparent);
}

.pronunciation-listening-lab > div:first-child {
  display: grid;
  gap: .2rem;
}

.pronunciation-listening-lab span,
.pronunciation-listening-lab small {
  color: var(--teacher-muted);
}

.adaptive-evidence-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: .65rem;
}

.adaptive-evidence-grid > div {
  display: grid;
  gap: .22rem;
  padding: .85rem;
  border: 1px solid var(--teacher-line);
  border-radius: 13px;
}

.adaptive-evidence-grid span {
  color: var(--teacher-jade);
}

.adaptive-evidence-grid small,
.adaptive-empty,
.local-data-settings > p,
.backup-status {
  color: var(--teacher-muted);
}

.local-data-settings {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--teacher-line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--teacher-paper-raised) 72%, transparent);
}

.local-data-settings h3,
.local-data-settings p {
  margin-top: 0;
}

.local-data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
}

.backup-status {
  min-height: 1.3em;
  margin: .7rem 0 0;
}

.backup-status.failed {
  color: var(--teacher-vermilion);
}

@keyframes teacher-arrive {
  from { opacity: 0; transform: translateY(9px) scale(.995); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 720px) {
  .game-hud-label { display: none; }
  .game-hud { width: 2.7rem; padding-inline: 0; }
  .header-stats > div { min-width: 3rem; }
  .tone-family-practice { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sentence-pattern > div { flex: 1 1 6.5rem; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* Keep scaled text, dialogs, and controls inside the visual viewport. */
html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

html { overflow-y: auto; }
body { overflow-y: visible; }

@supports (overflow: clip) {
  html,
  body { overflow-x: clip; }
}

body { min-height: 100dvh; }

.topbar,
.topbar > *,
.app-shell,
.app-shell > *,
.right-rail,
.study-panel,
.prompt-card,
.settings-dialog form,
.toggle-row > span,
.field-row > span {
  min-width: 0;
}

.topbar {
  width: 100%;
  max-width: 100%;
  justify-content: space-between;
}

.practice-menu-trigger {
  display: inline-grid;
  place-items: center;
  align-items: center;
  width: 50px;
  height: 50px;
  margin-left: auto;
  padding: 0;
  border: 1px solid var(--teacher-line);
  border-radius: 50%;
  background: color-mix(in srgb, var(--teacher-paper) 82%, transparent);
  color: var(--teacher-jade);
  font: inherit;
  cursor: pointer;
}

.practice-menu-trigger span { font-size: 1.15rem; line-height: 1; }

.practice-menu-heading {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  min-width: 0;
  padding: .25rem .25rem .65rem;
  border-bottom: 1px solid var(--teacher-line);
}

.practice-menu-heading > div { display: grid; gap: .15rem; min-width: 0; }
.practice-menu-heading small { color: var(--teacher-muted); font-size: .65rem; font-weight: 800; letter-spacing: .1em; }
.practice-menu-heading strong { font-family: "Iowan Old Style", "Noto Serif CJK SC", Georgia, serif; font-size: 1.35rem; }

.practice-settings-button {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  flex: none;
  padding: .55rem .7rem;
  border: 1px solid var(--teacher-line);
  border-radius: .75rem;
  background: transparent;
  color: var(--teacher-ink);
  font: inherit;
  font-size: .8rem;
  font-weight: 750;
  cursor: pointer;
}

.practice-stats {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-width: 0;
  padding: .35rem 0 .55rem;
}

.practice-stats > div {
  min-width: 0;
  padding: .4rem;
  border-right: 1px solid var(--teacher-line);
  text-align: center;
}

.practice-stats > div:last-child { border-right: 0; }
.practice-stats strong,
.practice-stats span { display: block; }
.practice-stats strong { color: var(--teacher-ink); font: 700 1.15rem/1.1 "Iowan Old Style", Georgia, serif; font-variant-numeric: tabular-nums; }
.practice-stats span { margin-top: .15rem; color: var(--teacher-muted); font-size: .62rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }

.app-shell,
.study-panel,
.prompt-card {
  max-width: 100%;
}

input,
select,
textarea {
  min-width: 0;
  max-width: 100%;
}

.settings-dialog {
  width: min(610px, calc(100vw - 16px));
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  overflow: hidden;
}

.settings-dialog form {
  max-height: calc(100dvh - 18px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.settings-sections {
  display: grid;
  gap: 14px;
}

.settings-section {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--teacher-line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--teacher-paper) 72%, transparent);
}

.settings-section-heading {
  display: grid;
  gap: .15rem;
  margin-bottom: .45rem;
}

.settings-section-heading small {
  color: var(--teacher-jade);
  font-size: .65rem;
  font-weight: 800;
  letter-spacing: .11em;
}

.settings-section-heading h3 {
  margin: 0;
  font: 700 1.35rem/1.15 "Iowan Old Style", "Noto Serif CJK SC", Georgia, serif;
}

.settings-section > .toggle-row:first-of-type,
.settings-section > .field-row:first-of-type {
  border-top: 0;
}

#aiSettingsHost:empty,
#modelSettingsHost:empty { display: none; }

#aiSettingsHost .ai-settings {
  margin: 0;
  padding: 0;
  border: 0;
}

@media (max-width: 560px) {
  .topbar {
    display: flex;
    gap: 8px;
    min-height: calc(84px + env(safe-area-inset-top));
    padding: calc(12px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 12px max(10px, env(safe-area-inset-left));
  }

  .brand { gap: 8px; min-width: 0; }
  .brand > span:last-child { display: block; min-width: 0; }
  .brand-seal { flex: none; width: 44px; height: 44px; }
  .brand strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .practice-menu-trigger { flex: none; width: 44px; height: 44px; }

  .app-shell {
    width: calc(100% - 20px);
    margin-inline: auto;
  }

  .mode-nav {
    left: max(10px, env(safe-area-inset-left)) !important;
    width: calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)) !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .settings-dialog form {
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }

  .voice-controls,
  .google-sync-actions,
  .local-data-actions,
  .dialog-actions {
    min-width: 0;
    flex-wrap: wrap;
  }
}

@media (max-width: 350px) {
  .brand > span:last-child { display: none; }
}

.mode-nav {
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
}

.google-sync-settings {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--teacher-line);
  border-radius: 16px;
  background:
    radial-gradient(circle at 100% 0, rgba(66, 133, 244, .1), transparent 18rem),
    color-mix(in srgb, var(--teacher-paper-raised) 76%, transparent);
}

.google-sync-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.google-sync-heading h3,
.google-sync-heading p {
  margin-top: 0;
}

.google-sync-heading p,
.google-sync-privacy,
.google-sync-status {
  color: var(--teacher-muted);
  line-height: 1.5;
}

.sync-indicator {
  flex: none;
  padding: .35rem .62rem;
  border: 1px solid var(--teacher-line);
  border-radius: 999px;
  color: var(--teacher-muted);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.sync-indicator[data-state="synced"] {
  border-color: color-mix(in srgb, var(--teacher-jade) 60%, transparent);
  color: var(--teacher-jade);
  background: color-mix(in srgb, var(--teacher-jade) 10%, transparent);
}

.sync-indicator[data-state="syncing"] {
  border-color: color-mix(in srgb, #4285f4 60%, transparent);
  color: #76a7fa;
}

.sync-indicator[data-state="error"] {
  border-color: color-mix(in srgb, var(--teacher-vermilion) 60%, transparent);
  color: var(--teacher-vermilion);
}

.google-sync-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .65rem;
  margin-top: .9rem;
}

.google-sync-status {
  min-height: 1.4em;
  margin: .75rem 0 0;
  font-size: .88rem;
}
