:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #5f6b7a;
  --line: #dfe4ec;
  --shadow: 0 12px 36px rgba(23, 32, 51, 0.08);
  --grammar: #c62828;
  --question: #1565c0;
  --time: #ef6c00;
  --pronoun: #6a1b9a;
  --verb: #00838f;
  --phrase: #606a75;
  --sentence: #2e7d32;
  --rule: #ad7c00;
  --focus: #1f6feb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(21, 101, 192, 0.08), transparent 28%),
    linear-gradient(315deg, rgba(239, 108, 0, 0.08), transparent 24%),
    var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 380px);
  gap: 24px;
  align-items: end;
  max-width: 1180px;
  margin: 0 auto;
  padding: 34px 20px 22px;
}

.header-main h1 {
  margin: 4px 0 10px;
  font-size: clamp(32px, 5vw, 58px);
  line-height: 1.05;
  letter-spacing: 0;
}

.header-copy,
.section-note {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0;
  color: #334f7d;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

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

.header-stats div {
  min-height: 92px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.header-stats strong {
  display: block;
  font-size: 30px;
}

.header-stats span {
  color: var(--muted);
  font-size: 13px;
}

.top-tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 8px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 20px;
  background: rgba(246, 247, 251, 0.92);
  backdrop-filter: blur(14px);
  overflow-x: auto;
}

.tab-button,
.ghost-button,
.primary-button,
.hard-toggle,
.day-button,
.check-row {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.tab-button {
  padding: 0 14px;
  white-space: nowrap;
  font-weight: 700;
}

.tab-button.active,
.primary-button {
  border-color: #1f6feb;
  background: #1f6feb;
  color: white;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 20px 46px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-head {
  display: flex;
  gap: 18px;
  align-items: end;
  justify-content: space-between;
  margin: 12px 0 18px;
}

.section-head h2 {
  margin: 4px 0 0;
  font-size: clamp(22px, 3vw, 34px);
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.unit-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: -2px 0 18px;
}

.unit-chip {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font-weight: 850;
}

.unit-chip.active {
  border-color: #1f6feb;
  background: #eaf2ff;
  color: #174ea6;
  box-shadow: inset 0 0 0 2px #1f6feb;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
}

.search-box input {
  width: min(44vw, 280px);
  border: 0;
  outline: 0;
}

select {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.ghost-button,
.primary-button {
  padding: 0 14px;
  font-weight: 800;
}

.ghost-button.danger {
  color: #a12828;
}

.legend,
.grammar-summary,
.vocab-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 18px;
}

.legend-pill,
.summary-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 800;
}

.legend-pill {
  cursor: pointer;
}

.legend-pill.active {
  border-color: #1f6feb;
  box-shadow: inset 0 0 0 2px #1f6feb;
}

.color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.unit-list,
.grammar-columns,
.hard-board,
.vocab-board {
  display: grid;
  gap: 16px;
}

.unit-section,
.study-panel,
.grammar-group,
.quiz-card,
.vocab-section {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.unit-title-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.unit-title-row h3 {
  margin: 0;
  font-size: 22px;
}

.unit-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.vocab-table {
  display: grid;
  gap: 10px;
}

.vocab-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1.15fr) minmax(0, 1.15fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--phrase);
  border-radius: 8px;
  background: white;
}

.vocab-kind {
  display: grid;
  gap: 6px;
  justify-items: start;
}

.dictation-tag {
  border: 1px solid #ffc257;
  color: #7a4d00;
  background: #fff6df;
}

.vocab-row strong,
.vocab-answer strong {
  display: block;
  font-size: 18px;
  line-height: 1.25;
  word-break: break-word;
}

.vocab-row span,
.vocab-answer span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.vocab-answer {
  min-height: 48px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f6f8fb;
}

.vocab-answer.hidden strong,
.vocab-answer.hidden span {
  color: transparent;
  text-shadow: 0 0 9px rgba(23, 32, 51, 0.45);
  user-select: none;
}

.vocab-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.reveal-button,
.audio-button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  font-weight: 800;
}

.audio-button {
  border-color: #b9d0ff;
  color: #174ea6;
  background: #eef5ff;
}

.audio-button.playing {
  border-color: #2e7d32;
  color: #1d6b35;
  background: #effaf1;
}

.item-card {
  display: flex;
  min-height: 210px;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--phrase);
  border-radius: 8px;
  background: white;
}

.item-card h3 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  word-break: break-word;
}

.item-card .chinese {
  margin: 0;
  color: var(--muted);
}

.card-top,
.meta-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.meta-row {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.badge,
.mini-tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 6px;
  color: white;
  font-size: 12px;
  font-weight: 900;
}

.mini-tag {
  color: var(--ink);
  background: #eef2f7;
}

.hard-toggle {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
}

.hard-toggle.active {
  border-color: #a12828;
  background: #fff1f1;
  color: #a12828;
}

.tip-box {
  margin-top: auto;
  padding: 10px;
  border-radius: 8px;
  background: #f6f8fb;
  color: #334155;
  font-size: 14px;
}

.tip-box p {
  margin: 4px 0;
}

.day-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.day-button {
  padding: 12px 10px;
  text-align: left;
}

.day-button strong,
.day-button span {
  display: block;
}

.day-button span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.day-button.active {
  border-color: #1f6feb;
  box-shadow: inset 0 0 0 2px #1f6feb;
}

.study-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.study-panel h3 {
  margin: 0 0 10px;
  font-size: 22px;
}

.daily-main {
  min-width: 0;
}

.daily-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.daily-box {
  min-width: 0;
}

.focus-list,
.check-list,
.prompt-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.focus-list li,
.prompt-list li {
  padding: 10px 12px;
  border-radius: 8px;
  background: #f6f8fb;
}

.check-row {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
}

.check-row.done {
  border-color: #2e7d32;
  background: #f0faf2;
}

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

.grammar-group h3 {
  margin: 0;
  font-size: 24px;
}

.grammar-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 14px;
}

.grammar-summary-line {
  margin: 8px 0 0;
  color: var(--muted);
}

.grammar-formula {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  background: #f6f8fb;
  font-weight: 900;
}

.grammar-body {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 16px;
}

.grammar-diagram {
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  overflow: hidden;
}

.grammar-diagram svg {
  display: block;
  width: 100%;
  height: auto;
}

.grammar-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.grammar-detail {
  min-width: 0;
  padding: 12px;
  border-radius: 8px;
  background: #f6f8fb;
}

.grammar-detail h4 {
  margin: 0 0 8px;
  font-size: 16px;
}

.grammar-detail ul,
.grammar-detail ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
}

.grammar-examples {
  grid-column: 1 / -1;
}

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

.example-row {
  padding: 10px;
  border-left: 4px solid var(--phrase);
  border-radius: 8px;
  background: white;
}

.example-row strong,
.example-row span {
  display: block;
}

.example-row span {
  margin-top: 4px;
  color: var(--muted);
}

.spelling-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.spelling-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 9px;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--line);
  font-weight: 900;
}

.empty-state {
  padding: 28px;
  border: 1px dashed #aab4c2;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  text-align: center;
}

.quiz-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.quiz-card h3 {
  margin-top: 0;
}

.choice-question {
  padding: 12px;
  border-radius: 8px;
  background: #f6f8fb;
  margin-bottom: 12px;
}

.choice-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.choice-options button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.choice-options button.correct {
  border-color: #2e7d32;
  background: #effaf1;
}

.choice-options button.wrong {
  border-color: #c62828;
  background: #fff0f0;
}

.answer-note {
  min-height: 22px;
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.grammar { border-left-color: var(--grammar); }
.question { border-left-color: var(--question); }
.time { border-left-color: var(--time); }
.pronoun { border-left-color: var(--pronoun); }
.verb { border-left-color: var(--verb); }
.phrase { border-left-color: var(--phrase); }
.sentence { border-left-color: var(--sentence); }
.rule { border-left-color: var(--rule); }

.bg-grammar { background: var(--grammar); }
.bg-question { background: var(--question); }
.bg-time { background: var(--time); }
.bg-pronoun { background: var(--pronoun); }
.bg-verb { background: var(--verb); }
.bg-phrase { background: var(--phrase); }
.bg-sentence { background: var(--sentence); }
.bg-rule { background: var(--rule); }

@media (max-width: 900px) {
  .app-header,
  .study-panel,
  .quiz-layout,
  .grammar-body,
  .grammar-columns,
  .daily-bottom {
    grid-template-columns: 1fr;
  }

  .grammar-detail-grid,
  .example-grid {
    grid-template-columns: 1fr;
  }

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

  .vocab-row {
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .vocab-row .vocab-answer,
  .vocab-row .vocab-tip,
  .vocab-row .vocab-actions {
    grid-column: 1 / -1;
  }

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

@media (max-width: 620px) {
  .app-header {
    padding-top: 24px;
  }

  .header-stats {
    grid-template-columns: 1fr;
  }

  .section-head,
  .unit-title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .card-grid,
  .day-grid {
    grid-template-columns: 1fr;
  }

  .vocab-row {
    grid-template-columns: 1fr;
  }

  .vocab-row .vocab-answer,
  .vocab-row .vocab-tip,
  .vocab-row .vocab-actions {
    grid-column: auto;
  }

  .search-box input {
    width: 100%;
  }

  .toolbar {
    width: 100%;
  }
}
