:root {
  color-scheme: dark;
}

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

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 10000;
  padding: 10px 14px;
  border-radius: 10px;
  color: #171b19;
  background: #fff4df;
  font-weight: 800;
  transform: translateY(-150%);
  transition: transform 140ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  width: min(980px, calc(100% - 36px));
  grid-template-columns: minmax(0, 1fr);
}

.study-panel {
  display: flex;
  flex-direction: column;
  border-radius: 1.15rem;
}

.study-panel > .prompt-card {
  width: 100%;
  flex: 1;
}

.runtime-settings {
  display: grid;
  gap: 12px;
}

.runtime-settings .app-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line, rgba(255, 255, 255, 0.12));
  border-radius: 14px;
  background: color-mix(in srgb, var(--card, #171c1a) 88%, transparent);
}

.runtime-settings .app-meta strong {
  font-size: 1rem;
}

.runtime-settings .app-version,
.runtime-settings .runtime-status {
  color: var(--muted, #a9b0aa);
  font-size: 0.86rem;
}

.runtime-settings .runtime-actions,
.runtime-settings .legal-links {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.runtime-settings .runtime-actions button,
.runtime-settings .legal-links a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 13px;
  border-radius: 11px;
}

.runtime-settings .legal-links a {
  color: var(--ink, #f8f1df);
  border: 1px solid var(--line, rgba(255, 255, 255, 0.12));
  text-decoration: none;
}

.app-toast {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 9999;
  max-width: min(390px, calc(100vw - 36px));
  padding: 13px 16px;
  border: 1px solid rgba(255, 244, 223, 0.2);
  border-radius: 14px;
  color: #fff8e8;
  background: rgba(20, 25, 23, 0.96);
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
  font-weight: 700;
}

.app-toast[hidden] {
  display: none;
}

.ai-report-trigger {
  color: var(--muted, #9aa4a1);
  font-size: .82rem;
}

.ai-report-dialog {
  width: min(34rem, calc(100vw - 2rem));
  max-height: min(46rem, calc(100dvh - 2rem));
  box-sizing: border-box;
  overflow: auto;
  border: 1px solid var(--line, rgba(255,255,255,.14));
  border-radius: 1.25rem;
  padding: 0;
  color: var(--ink, #f2e8d5);
  background: var(--paper-light, #172225);
  box-shadow: 0 1.5rem 5rem rgba(0,0,0,.45);
}

.ai-report-dialog::backdrop {
  background: rgba(5,10,11,.72);
  backdrop-filter: blur(4px);
}

.ai-report-form {
  display: grid;
  gap: 1rem;
  padding: clamp(1.25rem, 5vw, 2rem);
}

.ai-report-form h2,
.ai-report-form p {
  margin: 0;
}

.ai-report-form > p {
  color: var(--muted, #a8b0ad);
  line-height: 1.5;
}

.ai-report-preview {
  max-height: 9rem;
  overflow: auto;
  border-left: 3px solid var(--red, #f47a5a);
  padding: .8rem 1rem;
  white-space: pre-wrap;
  color: var(--ink, #f2e8d5);
  background: rgba(255,255,255,.045);
}

.ai-report-field {
  display: grid;
  gap: .45rem;
  font-weight: 750;
}

.ai-report-field select,
.ai-report-field textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line, rgba(255,255,255,.14));
  border-radius: .75rem;
  padding: .8rem .9rem;
  color: var(--ink, #f2e8d5);
  background: rgba(255,255,255,.06);
  font: inherit;
}

.ai-report-field textarea {
  min-height: 6rem;
  resize: vertical;
}

.ai-report-actions {
  display: flex;
  justify-content: flex-end;
  gap: .65rem;
  flex-wrap: wrap;
}

.ai-report-status {
  min-height: 1.4rem;
  color: var(--jade, #63d8c5);
  font-weight: 700;
}

.ai-report-status.error {
  color: var(--red, #f47a5a);
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 720px);
    margin-top: 12px;
  }

  .study-panel {
    min-height: calc(100dvh - 116px);
  }

  .runtime-settings .app-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .app-toast {
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    max-width: calc(100vw - 20px);
  }
}

/* Content-led study layout and stronger learning hierarchy. */
.study-panel {
  min-height: 0;
}

.study-panel > .prompt-card {
  min-height: 0;
  flex: 0 0 auto;
  gap: 1rem;
  padding: clamp(1.6rem, 5vw, 2.8rem) clamp(1.1rem, 5vw, 2.8rem);
}

.card-topline + .prompt-card {
  border-top: 0;
}

.prompt-card .meaning {
  font-size: clamp(1.45rem, 5vw, 2rem);
  line-height: 1.2;
}

.card-counter:empty {
  display: none;
}

.card-topline {
  min-height: 3.5rem;
  box-sizing: border-box;
  align-items: center;
  flex-wrap: wrap;
  gap: .25rem 1rem;
  padding: .85rem clamp(1rem, 4vw, 1.5rem);
}

.card-topline .eyebrow,
.card-topline .card-counter {
  display: flex;
  min-height: 1.5rem;
  align-items: center;
  margin: 0;
  line-height: 1.4;
}

.card-topline .eyebrow {
  font-size: .78rem;
}

.card-topline .card-counter {
  font-size: .9rem;
  text-align: right;
}

.prompt-card > .hanzi:not(.phrase),
#writingBlock > .hanzi:not(.phrase),
.pronunciation-view > .hanzi:not(.phrase) {
  font-size: clamp(5.5rem, 22vw, 9.5rem);
  line-height: 1.02;
}

.prompt-card > .hanzi.phrase,
#writingBlock > .hanzi.phrase,
.pronunciation-view > .hanzi.phrase {
  font-size: clamp(3.1rem, 12vw, 5.8rem);
  line-height: 1.12;
}

.pinyin {
  font-size: clamp(1.3rem, 4.5vw, 1.65rem);
  line-height: 1.4;
}

.pronunciation-view > .pinyin,
.learning-view .connected-speech-example em,
.learning-view .tone-word small,
.learning-view .tone-family-practice em {
  font-size: clamp(1.85rem, 7vw, 2.5rem);
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: .025em;
  padding-block: .12em .05em;
}

.pronunciation-note {
  margin: -.25rem 0 0;
  color: var(--teacher-muted, var(--muted));
  font-size: .82rem;
  font-weight: 700;
}

.answer-form {
  width: min(36rem, 100%);
}

.answer-input {
  min-height: 3.5rem;
  box-sizing: border-box;
  padding: .8rem 1rem;
  font-size: 1.08rem;
  line-height: 1.4;
}

.primary-button,
.ghost-button {
  min-height: 3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1.2;
}

.feedback {
  width: min(36rem, 100%);
  box-sizing: border-box;
  line-height: 1.5;
}

.feedback > .derivation {
  margin-top: .9rem;
  padding-top: .8rem;
  border-top: 1px solid var(--teacher-line, var(--line));
}

.feedback.wrong {
  border-left-width: 5px;
  background: color-mix(in srgb, var(--teacher-vermilion, #e15a3c) 12%, var(--teacher-paper-raised, #1d2522));
}

.feedback.correct {
  border-left-width: 5px;
  background: color-mix(in srgb, var(--teacher-jade, var(--jade)) 12%, var(--teacher-paper-raised, #1d2522));
  cursor: pointer;
}

.feedback.correct strong {
  font-size: 1.12rem;
  line-height: 1.35;
}

.draw-assessment.correct {
  border-color: var(--teacher-jade, var(--jade));
  background: color-mix(in srgb, var(--teacher-jade, var(--jade)) 12%, var(--teacher-paper-raised, #1d2522));
  cursor: pointer;
}

.draw-correct {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  flex-wrap: wrap;
  margin-top: .25rem;
}

.draw-correct b {
  font-size: 2.1rem;
  line-height: 1.1;
}

.draw-correct span {
  color: var(--teacher-jade, var(--jade));
  font-style: italic;
}

.draw-correct small {
  color: var(--teacher-muted, var(--muted));
  font-size: .95rem;
}

/* Locked by a Settings toggle rather than by progress: still tappable, and tapping it
   opens Settings. It must not read as disabled, or the learner will not try it. */
.mode-category-grid > button.mode-needs-setting {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--teacher-jade, var(--jade)) 55%, transparent);
  opacity: 1;
}

.mode-category-grid > button.mode-needs-setting small {
  color: var(--teacher-jade, var(--jade));
  font-weight: 700;
}

@media (prefers-reduced-motion: no-preference) {
  .feedback.correct {
    animation: hanflow-correct-in 140ms ease-out;
  }
}

@keyframes hanflow-correct-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.feedback-kicker,
.production-composition > p {
  margin: 0;
  color: var(--teacher-muted, var(--muted));
  font-size: .74rem;
  font-weight: 850;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.production-card {
  justify-content: flex-start;
  padding-block: clamp(2rem, 7vw, 3.5rem) !important;
}

.production-meaning {
  margin: 0;
  font-size: clamp(2.6rem, 10vw, 4.8rem);
  line-height: 1.12;
}

.production-card .feedback {
  margin-top: .35rem;
  padding: clamp(1rem, 4vw, 1.5rem);
}

.production-answer {
  display: grid;
  justify-items: center;
  gap: .2rem;
  margin: .45rem 0 1rem;
  padding: .9rem;
  border: 1px solid color-mix(in srgb, var(--teacher-gold, #d6a24f) 48%, transparent);
  background: color-mix(in srgb, var(--teacher-gold, #d6a24f) 7%, transparent);
  text-align: center;
}

.production-answer > b {
  color: var(--teacher-ink, var(--ink));
  font: 650 clamp(4.2rem, 18vw, 7.5rem)/1.05 var(--serif);
  letter-spacing: .05em;
}

.production-answer-pinyin {
  border: 0;
  padding: .25rem .55rem;
  color: var(--teacher-jade, var(--jade));
  background: transparent;
  font: italic 700 clamp(1.25rem, 5vw, 1.65rem)/1.35 var(--serif);
  cursor: pointer;
}

.production-answer-pinyin::before {
  content: "▶";
  margin-right: .4rem;
  font-size: .7em;
  font-style: normal;
}

.production-answer small {
  color: var(--teacher-muted, var(--muted));
  font-size: 1rem;
}

.production-attempt {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  margin: 0 0 1rem;
  padding: .7rem .85rem;
  border: 1px solid var(--teacher-line, var(--line));
}

.production-attempt span {
  color: var(--teacher-muted, var(--muted));
  font-size: .78rem;
  font-weight: 750;
  text-transform: uppercase;
}

.production-attempt b {
  overflow-wrap: anywhere;
  font-size: 1.05rem;
}

.production-composition {
  margin-top: .3rem;
}

.production-composition .derivation {
  margin-top: .55rem;
}

.derivation-main {
  font-size: 1.1rem;
  line-height: 1.55;
}

.derivation-main b {
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  line-height: 1.15;
}

.derivation-main em {
  color: var(--teacher-jade, var(--jade));
  font-size: 1.1rem;
}

.derivation-part b,
.part b,
.learning-parts b {
  font-size: clamp(2.5rem, 10vw, 3.6rem);
  line-height: 1.1;
}

.derivation-part em,
.derivation-part span,
.part span,
.learning-parts small {
  font-size: .95rem;
  line-height: 1.4;
}

.component-choices b {
  font-size: clamp(3rem, 12vw, 4.5rem);
}

.learning-view,
.empty-state,
.story-setup,
.build-lab,
.draw-wrap {
  min-height: 0;
}

.learning-body,
.build-body {
  min-height: 0;
  flex: 0 0 auto;
  padding-block: clamp(1.6rem, 5vw, 2.8rem);
}

.empty-state,
.story-setup,
.draw-wrap {
  padding-block: clamp(1.75rem, 6vw, 3rem);
}

.story-reader {
  min-height: 0;
}

.story-page {
  min-height: clamp(16rem, 42dvh, 24rem);
  padding-block: clamp(1.75rem, 6vw, 3rem);
}

.mode-select-view {
  box-sizing: border-box;
  padding: clamp(1rem, 4vw, 2rem);
}

.mode-category-heading small {
  white-space: nowrap;
}

@media (max-width: 820px) {
  .study-panel {
    min-height: 0;
  }
}

@media (max-width: 430px) {
  .card-topline {
    align-items: flex-start;
  }

  .card-topline .card-counter {
    margin-left: auto;
  }

  .production-attempt {
    align-items: flex-start;
    flex-direction: column;
    gap: .3rem;
  }

  .study-panel {
    border-radius: .85rem;
  }

  .card-topline {
    min-height: 3.2rem;
    padding-block: .7rem;
  }

  .draw-title .eyebrow {
    margin: 0 0 .2rem;
  }

  .mode-select-view {
    padding: .75rem;
  }
}

.hf-self-evaluate .hf-self-card {
  width: min(520px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
}

.hf-self-answer {
  display: grid;
  justify-items: center;
  gap: 5px;
  margin: 14px 0;
  padding: 18px;
  border: 1px solid var(--line, rgba(255, 255, 255, 0.14));
  border-radius: 14px;
  background: color-mix(in srgb, var(--card, #171c1a) 84%, transparent);
  text-align: center;
}

.hf-self-answer[hidden],
.hf-self-actions[hidden] {
  display: none !important;
}

.hf-self-answer strong {
  color: var(--ink, #fff4df);
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: clamp(4.5rem, 20vw, 8rem);
  line-height: 1;
}

.hf-self-answer span {
  color: var(--jade, #64c9b3);
  font-weight: 800;
}

.hf-self-answer p {
  margin: 2px 0 0;
}

.hf-self-model {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0;
  padding: 11px 12px;
  border-radius: 12px;
  background: rgba(216, 139, 61, 0.1);
}

.hf-self-model span {
  color: var(--muted, #a9b0aa);
  font-size: 0.86rem;
}

.hf-self-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 480px) {
  .hf-self-model {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skip-link {
    transition: none;
  }
}

/* Keep the web learning surface consistent with the portrait app. */
:root {
  --practice-column: 620px;
}

.topbar {
  padding-inline: max(16px, calc((100vw - var(--practice-column)) / 2));
}

.topbar .brand-copy,
.topbar .progression-trigger,
.topbar .header-stats,
.topbar [id*="level" i],
.topbar [id*="streak" i],
.topbar [id*="learned" i],
.progress-panel,
#progressionDialog {
  display: none !important;
}

.topbar {
  justify-content: space-between;
}

.topbar .top-actions {
  margin-left: auto;
}

.topbar .top-actions > :not(#modeMenuButton):not(.mode-menu-button) {
  display: none !important;
}

.topbar .brand-seal {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
}

#modeMenuButton {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
}

.app-shell {
  width: min(var(--practice-column), calc(100% - 24px));
  margin-inline: auto;
}

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

.mode-nav[hidden] {
  display: none !important;
}

.mode-nav:not([hidden]) {
  position: fixed !important;
  inset: 86px auto auto 50% !important;
  z-index: 9000;
  display: grid !important;
  width: min(var(--practice-column), calc(100vw - 24px));
  max-height: calc(100dvh - 102px);
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  transform: translateX(-50%) !important;
  overscroll-behavior: contain;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.46);
}

@media (max-width: 820px) {
  :root {
    --practice-column: 100vw;
  }

  .topbar {
    padding-inline: max(12px, env(safe-area-inset-left));
  }

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

  .mode-nav:not([hidden]) {
    inset: 78px auto auto 50% !important;
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 90px);
  }
}
