:root {
  --ink: #1f2933;
  --muted: #637083;
  --line: #d8dee8;
  --paper: #f7f8fb;
  --surface: #ffffff;
  --green: #0f766e;
  --blue: #2563eb;
  --red: #dc2626;
  --amber: #b45309;
  --shadow: 0 14px 34px rgba(31, 41, 51, 0.1);
  --study-font: "Kaiti SC", "STKaiti", "KaiTi", "BiauKai", "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--study-font);
  font-size: 22px;
  font-weight: 700;
}

button {
  font: inherit;
  cursor: pointer;
}

.app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0 18px;
  background: var(--paper);
}

.kicker {
  margin: 0 0 2px;
  color: var(--green);
  font-size: 1.05rem;
  font-weight: 800;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.2rem, 6vw, 4rem);
  line-height: 1.1;
}

.icon-button,
.review-button,
.reset-button,
.text-button,
.primary-button,
.secondary-button,
.chapter-card,
.options button,
.weak-item {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  width: 64px;
  min-height: 64px;
  font-size: 1.65rem;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.review-button,
.reset-button,
.text-button,
.primary-button,
.secondary-button {
  padding: 0 18px;
  font-weight: 750;
  font-size: 1.05rem;
}

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

.reset-button {
  color: var(--red);
}

.secondary-button.active {
  border-color: var(--amber);
  background: #fff7ed;
  color: var(--amber);
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.hero,
.question-panel,
.empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero {
  padding: 24px;
}

.hero p {
  color: var(--muted);
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.summary span {
  padding: 12px;
  border-radius: 8px;
  background: #eef6f4;
  color: var(--muted);
}

.summary b {
  display: block;
  color: var(--ink);
  font-size: 2rem;
}

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

.chapter-card,
.weak-item {
  display: grid;
  gap: 6px;
  min-height: 132px;
  padding: 22px;
  text-align: left;
}

.chapter-card:hover,
.weak-item:hover {
  border-color: var(--green);
}

.chapter-card:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.chapter-card span,
.chapter-card small,
.weak-item span {
  color: var(--muted);
}

.chapter-card strong,
.weak-item strong {
  font-size: 1.45rem;
}

.chapter-toolbar,
.bottom-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.progress-text {
  color: var(--muted);
  font-weight: 800;
  font-size: 1.2rem;
}

.question-panel {
  padding: clamp(24px, 5vw, 42px);
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.question-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 1.2rem;
  font-weight: 750;
}

.audio-box {
  margin-bottom: 16px;
}

audio {
  width: 100%;
}

.audio-track {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.audio-track span {
  color: var(--muted);
  font-size: 1rem;
}

#questionText {
  line-height: 1.35;
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  white-space: pre-line;
}

#questionText.reading-question {
  font-size: clamp(1.3rem, 2.7vw, 1.9rem);
  line-height: 1.7;
}

.question-image-wrap {
  display: flex;
  justify-content: center;
  margin: 20px 0 8px;
}

.question-image {
  width: min(240px, 70vw);
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  object-fit: cover;
}

.options {
  display: grid;
  gap: 16px;
  margin-top: 28px;
}

.options button {
  min-height: 76px;
  padding: 18px 28px;
  text-align: left;
  line-height: 1.35;
  font-size: clamp(1.45rem, 3vw, 2rem);
}

.options button.has-image {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 16px;
  align-items: center;
}

.choice-image {
  width: 96px;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  object-fit: cover;
}

.choice-text {
  min-width: 0;
}

.options button.correct {
  border-color: var(--green);
  background: #ecfdf5;
  color: #065f46;
}

.options button.wrong {
  border-color: var(--red);
  background: #fef2f2;
  color: #991b1b;
}

.input-answer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
  margin-top: 28px;
}

.input-answer label {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 1.25rem;
  font-weight: 800;
}

.input-answer input {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 18px;
  color: var(--ink);
  background: var(--surface);
  font: inherit;
  font-size: clamp(1.5rem, 3vw, 2.1rem);
}

.explanation {
  margin-top: 28px;
  padding: 28px;
  border-left: 8px solid var(--green);
  background: #f0fdfa;
  border-radius: 8px;
  font-size: clamp(1.35rem, 2.6vw, 1.8rem);
}

.explanation p {
  margin: 16px 0 0;
  line-height: 1.65;
}

.answer-detail {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid rgba(15, 118, 110, 0.22);
}

.answer-detail h3 {
  margin: 0 0 18px;
  font-size: clamp(2.1rem, 5vw, 3rem);
}

.question-pinyin {
  margin: -8px 0 18px;
  color: var(--muted);
  font-size: clamp(1.25rem, 2.4vw, 1.65rem);
  line-height: 1.5;
}

.answer-detail dl {
  display: grid;
  gap: 10px;
  margin: 0 0 22px;
}

.answer-detail dl div {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 18px;
}

.answer-detail dl div.plain-detail {
  grid-template-columns: 1fr;
  gap: 0;
}

.answer-detail dt {
  color: var(--muted);
  font-weight: 800;
}

.answer-detail dd {
  margin: 0;
}

.answer-detail ul {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.answer-detail li {
  line-height: 1.55;
  font-size: clamp(1.25rem, 2.4vw, 1.65rem);
}

.choice-extra {
  display: block;
  margin-top: 8px;
  line-height: 1.55;
  color: var(--muted);
  font-size: 0.88em;
}

.bottom-actions {
  margin-top: 14px;
}

.empty {
  grid-column: 1 / -1;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.hidden {
  display: none;
}

@media (max-width: 720px) {
  .app {
    padding: 12px;
  }

  body {
    font-size: 19px;
  }

  .chapter-grid,
  .weak-list,
  .summary {
    grid-template-columns: 1fr;
  }

  .header {
    grid-template-columns: 52px 1fr auto;
  }

  .icon-button {
    width: 52px;
    min-height: 52px;
  }

  .question-panel {
    padding: 20px;
  }

  .question-image {
    width: min(200px, 70vw);
  }

  .options button.has-image {
    grid-template-columns: 76px 1fr;
    gap: 12px;
  }

  .choice-image {
    width: 76px;
  }

  .answer-detail dl div {
    grid-template-columns: 92px 1fr;
  }

  .input-answer {
    grid-template-columns: 1fr;
  }

  .bottom-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  #nextQuestion {
    grid-column: 1 / -1;
  }
}

#loginScreen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--paper);
}

.loginBox {
  width: min(420px, 100%);
  padding: 32px 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.loginBox h2 {
  margin-bottom: 10px;
  color: var(--green);
  font-size: clamp(1.7rem, 6vw, 2.4rem);
  line-height: 1.2;
}

.loginBox p {
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 1.05rem;
}

#passwordInput {
  width: 100%;
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  color: var(--ink);
  background: var(--surface);
  font: inherit;
  font-size: 1.05rem;
}

#passwordInput:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

#loginButton {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--green);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
}

#loginButton:active {
  transform: translateY(1px);
}

#loginError {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--red);
  font-size: 0.95rem;
}
