:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --ink: #172033;
  --muted: #697386;
  --line: #dfe4ee;
  --panel: #ffffff;
  --green: #2f8f62;
  --blue: #2d6cdf;
  --yellow: #f4c542;
  --red: #df5b57;
  --shadow: 0 14px 35px rgba(32, 42, 68, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: linear-gradient(180deg, #eef6ff 0%, var(--bg) 34%, #f9fbf3 100%);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1040px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar,
.flow-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.app-shell:not(.is-home) .topbar {
  display: none;
}

.flow-actions {
  display: flex;
  gap: 8px;
}

.test-flow-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
}

.test-head-side {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(30px, 5vw, 48px);
}

h2 {
  font-size: 28px;
}

.user-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-weight: 700;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-actions .primary-button {
  min-width: 150px;
}

select,
input {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  outline: none;
}

select:focus,
input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.15);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.login-panel {
  width: min(460px, 100%);
  margin: 9vh auto 0;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-description {
  margin: 12px 0 24px;
  color: var(--muted);
  font-weight: 700;
}

.login-form,
.login-form label {
  display: grid;
  gap: 8px;
}

.login-form {
  gap: 18px;
}

.login-form label {
  color: var(--muted);
  font-weight: 800;
}

.form-message {
  min-height: 22px;
  margin: 0;
  color: var(--red);
  font-weight: 800;
}

.top-entry-panel {
  max-width: 780px;
  margin: 46px auto 0;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.top-entry-text {
  margin: 10px 0 22px;
  color: var(--muted);
  font-weight: 700;
}

.user-entry-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.user-entry-button {
  min-height: 120px;
  display: grid;
  align-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 14px;
  text-align: left;
}

.user-entry-button strong {
  font-size: 28px;
  line-height: 1.1;
}

.user-entry-button span {
  color: var(--muted);
  font-weight: 800;
}

.user-entry-button:hover,
.user-entry-button:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.14);
  outline: none;
}

.entry-logout-button {
  min-width: 108px;
  margin-top: 20px;
  padding: 0 14px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card,
.quiz-panel,
.learn-card,
.result-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-card {
  min-height: 116px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

.stat-card span {
  color: var(--muted);
  font-weight: 700;
}

.stat-card strong {
  font-size: 38px;
  line-height: 1;
}

.settings-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  align-items: stretch;
  gap: 12px;
  margin-bottom: 18px;
}

.setting-chip {
  min-height: 74px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.setting-chip span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.setting-chip strong {
  font-size: 22px;
}

.settings-summary .secondary-button {
  min-width: 92px;
}

.settings-dialog {
  width: min(520px, calc(100% - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(19, 29, 50, 0.28);
}

.settings-dialog::backdrop {
  background: rgba(18, 28, 45, 0.42);
}

.settings-dialog form {
  display: grid;
  gap: 16px;
  padding: 24px;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.field,
.field-grid {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-weight: 800;
}

.field-grid {
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.settings-message {
  min-height: 22px;
  margin: 0;
  color: var(--red);
  font-weight: 800;
}

.ghost-text-button {
  min-height: 46px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  padding: 0 12px;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 20px;
  font-weight: 800;
}

.primary-button {
  background: var(--yellow);
  color: #1d2430;
}

.secondary-button {
  background: var(--blue);
  color: #fff;
}

.ghost-button {
  min-width: 46px;
  padding: 0;
  background: #fff;
  color: var(--blue);
  border: 1px solid var(--line);
}

.back-level-button,
.prev-question-button {
  min-width: 124px;
  padding: 0 14px;
}

.back-level-button {
  color: #1f4f9e;
}

.prev-question-button {
  color: var(--muted);
  border-style: dashed;
}

.top-switch-button {
  min-width: 140px;
  padding: 0 14px;
}

#logoutButton {
  min-width: 108px;
  padding: 0 14px;
}

.sound-button {
  width: 46px;
  height: 46px;
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--blue);
  padding: 0;
}

.sound-button.large {
  width: 56px;
  height: 56px;
}

.sound-button:hover:not(:disabled),
.sound-button:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.14);
  outline: none;
}

.sound-button:disabled {
  cursor: default;
  opacity: 0.45;
}

.sound-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.search-area {
  padding-top: 18px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 14px;
}

.dashboard-panel {
  min-height: 190px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.course-panel {
  grid-row: span 2;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-head h2 {
  font-size: 24px;
}

.large-rate {
  color: var(--green);
  font-size: 44px;
  line-height: 1;
}

.progress-track {
  width: 100%;
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf4;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), #69b875);
  transition: width 180ms ease;
}

.course-total {
  display: grid;
  gap: 4px;
  margin-top: 18px;
}

.course-total span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.course-total strong {
  font-size: 30px;
}

.level-metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.level-metric-grid div,
.daily-list div {
  min-height: 72px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
}

.level-metric-grid span,
.daily-list span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.level-metric-grid strong,
.daily-list strong {
  font-size: 25px;
}

.daily-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.day-mark {
  min-height: 82px;
  display: grid;
  place-items: center;
  gap: 5px;
  padding: 10px 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
  font-weight: 800;
}

.day-mark strong {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  color: #fff;
}

.day-mark.complete strong {
  background: var(--green);
}

.day-mark.partial strong {
  background: #d98a00;
}

.day-mark.none strong {
  background: var(--muted);
}

.day-mark span {
  color: var(--muted);
  font-size: 12px;
}

.search-row,
.answer-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
}

.answer-row .secondary-button {
  min-width: 84px;
}

.answer-row[hidden] {
  display: none;
}

.test-mode-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5f8fc;
}

.test-type-label {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5f8fc;
  color: var(--blue);
  font-weight: 800;
}

.test-type-label[hidden] {
  display: none;
}

.choice-prompt {
  font-size: 18px;
}

.choice-target-word {
  color: var(--red);
  font-weight: 900;
}

.mode-button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 0 18px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.mode-button.active {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 4px 12px rgba(45, 108, 223, 0.12);
}

.choice-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.choice-button {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  font-weight: 800;
  line-height: 1.45;
}

.choice-button:hover:not(:disabled) {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.12);
}

.choice-button:disabled {
  cursor: default;
  opacity: 0.78;
}

.choice-loading {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.word-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.word-item {
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.word-item-head,
.word-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.word-item-head {
  justify-content: space-between;
  margin-bottom: 4px;
}

.word-title-row {
  flex-wrap: wrap;
}

.word-item strong {
  display: block;
  font-size: 22px;
  margin-bottom: 0;
}

.word-item span,
.muted {
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: #e8f0ff;
  color: var(--blue);
  font-weight: 800;
}

.quiz-panel,
.learn-card,
.result-panel {
  padding: 28px;
}

.meaning {
  margin: 0 0 14px;
  font-size: 28px;
  font-weight: 800;
}

.sentence {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.6;
}

.feedback {
  min-height: 30px;
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 800;
}

.feedback:empty {
  display: none;
}

.feedback.correct {
  background: #edf8f1;
  color: var(--green);
}

.feedback.wrong {
  background: #fff3e8;
  color: var(--red);
}

.answer-reveal {
  display: grid;
  gap: 6px;
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
}

.answer-reveal[hidden] {
  display: none;
}

.reveal-word {
  margin: 0;
  font-size: 42px;
  line-height: 1;
  font-weight: 900;
}

.next-test-button {
  margin-top: 16px;
}

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

.big-word {
  margin: 0;
  font-size: clamp(48px, 10vw, 96px);
  line-height: 1;
  font-weight: 900;
}

.pronunciation {
  margin: 12px 0 20px;
  color: var(--blue);
  font-size: 20px;
  font-weight: 800;
}

.word-meta {
  min-height: 24px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
}

.phonics-practice {
  margin: 24px 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
}

.phonics-practice-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.phonics-practice-head h3 {
  margin: 2px 0 0;
  font-size: 22px;
}

.phonics-instruction {
  margin: 12px 0 18px;
  color: var(--muted);
  font-weight: 700;
}

.phonics-inputs {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 18px;
}

.phonics-chunk {
  position: relative;
  display: grid;
  gap: 7px;
  justify-items: center;
}

.phonics-chunk:not(:last-child)::after {
  position: absolute;
  right: -12px;
  bottom: 14px;
  color: var(--muted);
  content: "·";
  font-size: 24px;
  font-weight: 900;
}

.phonics-target {
  color: var(--blue);
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.phonics-input {
  width: calc(var(--chunk-width) + 28px);
  min-width: 70px;
  max-width: 230px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 22px;
  font-weight: 900;
  text-align: center;
}

.phonics-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.14);
  outline: none;
}

.phonics-input.invalid {
  border-color: var(--red);
  background: #fff8f2;
}

.phonics-input.completed {
  border-color: var(--green);
  background: #edf8f1;
  color: var(--green);
  opacity: 1;
}

.learn-card .primary-button,
.result-panel .primary-button {
  margin-top: 8px;
}

.learn-card .primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.result-panel {
  max-width: 680px;
  margin: 48px auto 0;
  text-align: center;
}

.result-panel p:last-of-type {
  color: var(--muted);
  font-size: 18px;
}

.result-praise {
  margin: 14px auto 8px;
  max-width: 520px;
  color: var(--green);
  font-size: 20px;
  font-weight: 900;
  line-height: 1.55;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 24px, 1040px);
    padding-top: 18px;
  }

  .topbar,
  .flow-head {
    align-items: stretch;
    flex-direction: column;
  }

  .test-flow-head {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .test-head-side {
    justify-content: space-between;
  }

  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-grid,
  .word-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-summary {
    grid-template-columns: 1fr;
  }

  .user-entry-buttons {
    grid-template-columns: 1fr;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .course-panel {
    grid-row: auto;
  }

  .level-metric-grid,
  .daily-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-row,
  .answer-row,
  .choice-options {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 460px) {
  .summary-grid,
  .word-list {
    grid-template-columns: 1fr;
  }

  .stat-card {
    min-height: 92px;
  }
}
