:root {
  color-scheme: light dark;
  --bg: #eef4ef;
  --paper: #fbfaf4;
  --paper-soft: #f3f5ec;
  --surface: #fffffb;
  --surface-2: #edf3ea;
  --text: #1f2d25;
  --muted: #66736a;
  --soft: #8b958d;
  --accent: #2f7254;
  --accent-deep: #245740;
  --accent-2: #b95a3d;
  --line: rgba(31, 45, 37, 0.12);
  --line-strong: rgba(47, 114, 84, 0.22);
  --shadow: 0 22px 58px rgba(43, 74, 55, 0.13);
  --radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151c18;
    --paper: #202820;
    --paper-soft: #253026;
    --surface: #1e271f;
    --surface-2: #263126;
    --text: #eff6ed;
    --muted: #afbaaf;
    --soft: #8f9b91;
    --accent: #8ac99f;
    --accent-deep: #b8e2c5;
    --accent-2: #e79372;
    --line: rgba(239, 246, 237, 0.13);
    --line-strong: rgba(138, 201, 159, 0.28);
    --shadow: 0 22px 58px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background:
    linear-gradient(115deg, rgba(47, 114, 84, 0.08), transparent 34rem),
    linear-gradient(180deg, rgba(185, 90, 61, 0.08), transparent 22rem),
    repeating-linear-gradient(90deg, rgba(31, 45, 37, 0.024) 0 1px, transparent 1px 34px),
    linear-gradient(160deg, var(--bg), var(--paper-soft));
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(135deg, transparent 0 56%, rgba(47, 114, 84, 0.08) 56% 56.2%, transparent 56.2%),
    linear-gradient(24deg, transparent 0 68%, rgba(185, 90, 61, 0.06) 68% 68.18%, transparent 68.18%);
}

button,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  gap: 16px;
}

.brand,
.admin-link {
  color: inherit;
  text-decoration: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: block;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 14px;
  box-shadow: 0 12px 28px rgba(59, 146, 232, 0.18);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 18px;
  letter-spacing: 0.02em;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.admin-link {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 15px;
  color: var(--muted);
  background: rgba(255, 255, 251, 0.58);
  box-shadow: 0 8px 22px rgba(43, 74, 55, 0.07);
}

@media (prefers-color-scheme: dark) {
  .admin-link {
    background: rgba(32, 40, 32, 0.72);
  }
}

.hero {
  display: block;
  padding: 34px 0 22px;
}

.kicker {
  margin: 0 0 12px;
  color: var(--accent);
  font-weight: 800;
}

.hero h1 {
  max-width: 700px;
  margin: 0;
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "Songti SC", serif;
  font-size: clamp(42px, 7vw, 76px);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: 0;
}

.intro {
  max-width: 520px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.8;
}

.study-meter {
  position: relative;
  display: grid;
  grid-template-columns: auto auto auto;
  align-items: baseline;
  gap: 7px;
  min-height: 46px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 14px;
  background: var(--paper);
}

.study-meter::after {
  content: none;
}

@media (prefers-color-scheme: dark) {
  .study-meter {
    background: linear-gradient(150deg, rgba(32, 40, 32, 0.9), rgba(38, 49, 38, 0.96));
  }
}

.study-meter span,
.study-meter small {
  color: var(--muted);
}

.study-meter strong {
  display: block;
  margin: 0;
  color: var(--accent-2);
  font-size: 28px;
  line-height: 1;
}

.controls,
.poem-card,
.explain-panel,
.local-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 251, 0.9);
  box-shadow: var(--shadow);
}

@media (prefers-color-scheme: dark) {
  .controls,
  .poem-card,
  .explain-panel,
  .local-panel {
    background: rgba(30, 39, 31, 0.94);
  }
}

.controls {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 16px;
}

.grade-picker {
  display: grid;
  grid-template-columns: auto minmax(105px, 150px);
  align-items: center;
  gap: 10px;
  min-width: 0;
}

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

select {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 12px;
  color: var(--text);
  background: var(--paper);
}

button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 17px;
  color: var(--text);
  background: var(--paper);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:hover {
  border-color: var(--line-strong);
  box-shadow: 0 8px 20px rgba(43, 74, 55, 0.08);
}

button:active {
  transform: translateY(1px);
}

.primary-btn {
  border-color: var(--accent);
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #fbfaf4;
  font-weight: 800;
  box-shadow: 0 12px 24px rgba(47, 114, 84, 0.18);
}

.poem-card {
  position: relative;
  margin-top: 18px;
  overflow: hidden;
  padding: 26px;
  background:
    linear-gradient(90deg, rgba(47, 114, 84, 0.07), transparent 5px),
    linear-gradient(180deg, rgba(255, 255, 251, 0.96), rgba(251, 250, 244, 0.92));
}

.poem-card::before {
  content: "";
  position: absolute;
  inset: 14px 14px auto auto;
  width: 74px;
  height: 74px;
  border-top: 1px solid rgba(185, 90, 61, 0.18);
  border-right: 1px solid rgba(185, 90, 61, 0.18);
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  .poem-card {
    background:
      linear-gradient(90deg, rgba(138, 201, 159, 0.12), transparent 5px),
      linear-gradient(180deg, rgba(30, 39, 31, 0.98), rgba(32, 40, 32, 0.94));
  }
}

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

.card-head h2,
.explain-panel h2,
.local-panel h2 {
  margin: 0;
  font-size: 24px;
}

.card-head h2 {
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "Songti SC", serif;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 700;
}

#poemMeta {
  margin: 8px 0 0;
  color: var(--muted);
}

.poem-lines {
  display: grid;
  gap: 14px;
  margin: 30px 0;
  color: var(--text);
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "Songti SC", serif;
  font-size: clamp(26px, 5.2vw, 39px);
  font-weight: 650;
  line-height: 1.9;
}

.poem-lines p {
  margin: 0;
}

.pinyin-line,
.hanzi-line {
  display: block;
}

.pinyin-line {
  margin-bottom: 4px;
  color: var(--accent);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(13px, 2.7vw, 16px);
  font-weight: 700;
  line-height: 1.5;
  word-spacing: 0.16em;
}

.hanzi-line {
  line-height: 1.82;
}

.pinyin-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: -8px 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 8px 6px 12px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 13px;
}

.pinyin-control button {
  min-height: 30px;
  border-radius: 999px;
  padding: 0 11px;
  color: #fbfaf4;
  background: var(--accent);
  border-color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.skeleton p {
  width: min(100%, 520px);
  min-height: 42px;
  border-radius: 12px;
  color: transparent;
  background: linear-gradient(90deg, var(--surface-2), var(--paper), var(--surface-2));
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.actions button:first-child {
  border-color: var(--accent);
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #fbfaf4;
  font-weight: 800;
}

.status-text {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--muted);
}

.audio-panel {
  display: grid;
  gap: 9px;
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.audio-panel[hidden],
.pinyin-control[hidden] {
  display: none;
}

.audio-panel audio {
  width: 100%;
}

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

.explain-panel,
.local-panel {
  margin-top: 18px;
  padding: 22px;
}

.explain-panel h2,
.local-panel h2 {
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "Songti SC", serif;
  font-size: 28px;
}

.explain-panel p {
  color: var(--muted);
  line-height: 1.8;
}

.summary {
  position: relative;
  margin-top: 12px;
  border-radius: 16px;
  padding: 14px 16px;
  color: var(--text) !important;
  background: var(--surface-2);
  font-weight: 800;
}

.explain-block,
.word-bank,
.questions {
  margin-top: 17px;
  padding-top: 17px;
  border-top: 1px solid var(--line);
}

.explain-block strong,
.word-bank strong,
.questions strong {
  display: block;
  margin-bottom: 9px;
  color: var(--accent-deep);
}

.explain-block p {
  margin: 0;
}

.line-notes {
  display: grid;
  gap: 10px;
}

.line-notes article {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px;
  background: var(--paper-soft);
}

.line-notes article strong {
  color: var(--text);
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "Songti SC", serif;
  font-size: 20px;
}

.line-notes article p {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.75;
}

#wordList {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

#wordList span {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px;
  color: var(--text);
  background: var(--paper-soft);
  font-weight: 800;
}

#wordList small {
  color: var(--accent);
  font-size: 13px;
}

#wordList em {
  color: var(--muted);
  font-size: 14px;
  font-style: normal;
  font-weight: 500;
  line-height: 1.55;
}

.questions ol,
.local-panel ul {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.questions li,
.local-panel li {
  margin: 8px 0;
  color: var(--muted);
}

.questions ol {
  padding-left: 22px;
}

.local-panel {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 22px;
}

.local-panel p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.empty {
  list-style: none;
}

.history-btn {
  display: grid;
  width: 100%;
  min-height: 0;
  gap: 4px;
  border-color: transparent;
  padding: 13px;
  text-align: left;
  border-radius: 16px;
  background: var(--paper-soft);
}

.history-btn strong {
  color: var(--text);
}

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

.history-toggle {
  width: 100%;
  min-height: 40px;
  margin-top: 10px;
  border-color: var(--line);
  color: var(--accent);
  background: transparent;
  font-weight: 800;
}

.site-footer {
  display: flex;
  justify-content: center;
  padding: 24px 0 10px;
}

.hits-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  opacity: 0.78;
  line-height: 0;
  transition: opacity 160ms ease, transform 160ms ease;
}

.hits-badge:hover {
  opacity: 1;
  transform: translateY(-1px);
}

.hits-badge img {
  display: block;
  max-width: 100%;
  height: 20px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

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

  .topbar {
    min-height: 58px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .brand small {
    max-width: 150px;
  }

  .local-panel {
    grid-template-columns: 1fr;
  }

  .hero {
    gap: 14px;
    padding: 24px 0 16px;
  }

  .hero h1 {
    font-size: 43px;
  }

  .intro {
    font-size: 15px;
  }

  .study-meter {
    justify-content: center;
    width: 100%;
  }

  .study-meter strong {
    font-size: 26px;
  }

  .controls {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }

  .grade-picker {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
  }

  .grade-picker span {
    align-self: center;
  }

  .grade-picker select,
  .study-meter,
  .primary-btn {
    min-height: 42px;
  }

  .primary-btn {
    grid-column: 1 / -1;
  }

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

  .poem-card,
  .explain-panel,
  .local-panel {
    padding: 18px;
  }

  .poem-lines {
    gap: 10px;
    margin: 24px 0;
    font-size: clamp(25px, 8vw, 34px);
  }

  .card-head {
    align-items: start;
  }

  #wordList {
    grid-template-columns: 1fr;
  }
}
