:root {
  color-scheme: light;
  --ink: #17201b;
  --muted: #6e746e;
  --paper: #f7f3ea;
  --panel: #fffdf7;
  --line: #ddd5c5;
  --green: #2f6b4f;
  --green-2: #dcebdd;
  --gold: #b47a1f;
  --rose: #b74d55;
  --blue: #375a7f;
  --shadow: 0 18px 50px rgba(23, 32, 27, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(47, 107, 79, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(180, 122, 31, 0.12), transparent 30%),
    var(--paper);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: env(safe-area-inset-top) 14px calc(132px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 10px;
  padding: 12px 0 10px;
  backdrop-filter: blur(18px);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(23, 32, 27, 0.12);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.72);
  box-shadow: 0 8px 24px rgba(23, 32, 27, 0.08);
}

.icon-button span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 2px 0;
  background: var(--ink);
}

.menu-button {
  gap: 4px;
}

.menu-button i {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--ink);
}

.menu-button i:nth-child(2) {
  width: 12px;
}

.menu-button i:nth-child(3) {
  width: 15px;
}

.title-block p {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 32, 27, 0.12);
}

.progress-track span {
  display: block;
  width: 1%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--gold), var(--rose));
  transition: width 180ms ease;
}

.lesson {
  display: grid;
  gap: 14px;
  max-width: 760px;
  margin: 0 auto;
}

.visual-stage {
  position: relative;
  width: min(100%, 520px);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(23, 32, 27, 0.1);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(47, 107, 79, 0.94), rgba(55, 90, 127, 0.9) 52%, rgba(180, 122, 31, 0.86)),
    #31543f;
  box-shadow: var(--shadow);
}

.visual-stage[hidden] {
  display: none;
}

.visual-stage img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.visual-stage img[src=""],
.visual-stage img.is-hidden {
  display: none;
}

.image-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 24px;
  color: #fffdf7;
  text-align: center;
}

.image-fallback[hidden] {
  display: none;
}

.image-fallback strong {
  font-size: 34px;
  line-height: 1;
  opacity: 0.55;
}

.image-number {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  min-width: 42px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.28);
  color: rgba(255, 255, 255, 0.92);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  text-shadow: 0 1px 7px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
}

.copy-panel {
  display: grid;
  gap: 12px;
}

.sentence-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.toggle-pill {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.78);
  font-size: 13px;
  font-weight: 800;
}

.toggle-pill input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.sentence-card {
  display: grid;
  gap: 10px;
  min-height: 120px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.92);
  box-shadow: 0 10px 28px rgba(23, 32, 27, 0.08);
}

.english-text,
.chinese-text {
  margin: 0;
}

.english-text {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  line-height: 1.45;
}

.chinese-text {
  color: #3f5046;
  font-size: 15px;
  line-height: 1.65;
}

.is-concealed {
  color: transparent;
  text-shadow: 0 0 12px rgba(23, 32, 27, 0.28);
  user-select: none;
}

.segments {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.segments::-webkit-scrollbar {
  display: none;
}

.segment-chip {
  flex: 0 0 auto;
  max-width: 82vw;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.82);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.segment-chip.active {
  border-color: rgba(47, 107, 79, 0.45);
  background: var(--green-2);
  color: var(--green);
}

textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: rgba(255, 253, 247, 0.94);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.55;
}

textarea:focus {
  border-color: rgba(47, 107, 79, 0.72);
  box-shadow: 0 0 0 3px rgba(47, 107, 79, 0.15);
}

.practice-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.practice-meta button,
.loop-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.85);
  font-size: 13px;
  font-weight: 800;
}

.practice-meta button {
  min-height: 34px;
  padding: 0 12px;
}

.study-notes {
  display: grid;
  gap: 10px;
  margin-top: 2px;
}

.notes-status,
.note-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.9);
  box-shadow: 0 8px 22px rgba(23, 32, 27, 0.06);
}

.notes-status {
  padding: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.note-block {
  overflow: hidden;
}

.note-block h2 {
  margin: 0;
  padding: 13px 14px 0;
  color: var(--green);
  font-size: 15px;
  line-height: 1.2;
}

.grammar-note p {
  margin: 0;
  padding: 10px 14px 14px;
  color: #34483e;
  font-size: 14px;
  line-height: 1.65;
}

.vocab-note summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 0 14px;
  color: var(--green);
  cursor: pointer;
  font-size: 15px;
  font-weight: 900;
  list-style: none;
}

.vocab-note summary::-webkit-details-marker {
  display: none;
}

.vocab-note summary::after {
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 150ms ease;
  content: "";
}

.vocab-note[open] summary::after {
  transform: rotate(225deg);
}

.vocab-note summary strong {
  min-width: 32px;
  margin-left: auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--green-2);
  color: var(--green);
  font-size: 12px;
  text-align: center;
}

.vocab-group {
  display: grid;
  gap: 8px;
  padding: 0 10px 10px;
}

.vocab-group h3 {
  margin: 2px 4px 0;
  color: var(--blue);
  font-size: 13px;
  line-height: 1.35;
}

.vocab-list {
  display: grid;
  gap: 8px;
}

.vocab-item {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid rgba(221, 213, 197, 0.8);
  border-radius: 8px;
  background: #fffaf0;
}

.vocab-item header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
}

.vocab-item header strong {
  color: var(--ink);
  font-size: 16px;
  line-height: 1.25;
}

.vocab-item header span {
  color: var(--muted);
  font-size: 12px;
}

.vocab-item p {
  margin: 0;
  color: #3f5046;
  font-size: 13px;
  line-height: 1.45;
}

.vocab-memory,
.vocab-related {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.vocab-memory span,
.vocab-related span {
  display: inline-flex;
  gap: 4px;
  max-width: 100%;
  padding: 5px 7px;
  border-radius: 8px;
  background: rgba(47, 107, 79, 0.08);
  color: #34483e;
  font-size: 12px;
  line-height: 1.35;
}

.vocab-memory b,
.vocab-related b {
  color: var(--green);
}

.empty-note {
  padding: 0 14px 14px;
  color: var(--muted);
  font-size: 13px;
}

.player {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 6;
  display: grid;
  gap: 10px;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(23, 32, 27, 0.12);
  background: rgba(255, 253, 247, 0.88);
  backdrop-filter: blur(22px);
  box-shadow: 0 -18px 50px rgba(23, 32, 27, 0.12);
}

.player-row {
  display: grid;
  grid-template-columns: 48px 1fr 48px 70px;
  gap: 10px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}

.round-button,
.play-button,
.loop-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
}

.round-button {
  background: #e8dfcf;
  font-size: 30px;
  line-height: 1;
}

.play-button {
  background: var(--ink);
  color: #fffdf7;
  font-size: 22px;
  font-weight: 900;
}

.loop-button.active {
  background: var(--green);
  color: #fffdf7;
}

.speed-row {
  display: grid;
  grid-template-columns: 42px 1fr 58px;
  align-items: center;
  gap: 10px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.speed-row input {
  width: 100%;
  accent-color: var(--green);
}

#settingsDialog,
#sentenceDialog {
  width: min(92vw, 560px);
  max-height: 82vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

#settingsDialog {
  width: min(88vw, 360px);
}

#settingsDialog::backdrop,
#sentenceDialog::backdrop {
  background: rgba(23, 32, 27, 0.36);
  backdrop-filter: blur(4px);
}

.dialog-header {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.dialog-header button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  font-size: 24px;
}

.sentence-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.sentence-list button {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 8px;
  align-items: start;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  text-align: left;
}

.sentence-list button.active {
  border-color: var(--green);
  background: var(--green-2);
}

.sentence-list strong {
  color: var(--green);
}

.sentence-list span {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.settings-list {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.settings-row,
.settings-command {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  font-size: 14px;
  font-weight: 800;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 12px;
}

.settings-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--green);
}

.settings-command {
  width: 100%;
}

@media (min-width: 820px) {
  .app-shell {
    padding-bottom: 142px;
  }

  .lesson {
    grid-template-columns: 420px minmax(0, 1fr);
    align-items: start;
    max-width: 980px;
  }

  .visual-stage {
    position: sticky;
    top: 72px;
  }

  .english-text {
    font-size: 22px;
  }
}
