:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #23211d;
  --muted: #6a6258;
  --line: #ded6c8;
  --accent: #1f6f6d;
  --accent-strong: #155250;
  --accent-soft: #dfeeed;
  --gold: #a56a1f;
  --red: #a13d37;
  --green: #2f7a45;
  --shadow: 0 18px 40px rgba(40, 34, 25, 0.1);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(31, 111, 109, 0.08), transparent 340px),
    var(--paper);
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: 2.25rem;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.55rem;
}

h3 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

.status-pill,
.timebox {
  min-width: 128px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  background: rgba(255, 253, 248, 0.8);
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  align-items: start;
}

.lesson-stage,
.side-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.lesson-stage {
  padding: 20px;
}

.side-panel {
  display: grid;
  gap: 16px;
  padding: 16px;
  position: sticky;
  top: 12px;
}

.lesson-meta,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.step-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 20px 0;
}

.step {
  min-height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.step.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.step.done {
  border-color: rgba(47, 122, 69, 0.42);
  background: #eef6ef;
  color: var(--green);
}

.step.done.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.listen-panel,
.choice-area,
.reveal-area,
.queue-panel,
.vocab-panel {
  border-top: 1px solid var(--line);
  padding-top: 18px;
  margin-top: 18px;
}

.reading-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf6ec;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.reading-panel span {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--gold);
  font-size: 0.86rem;
  font-weight: 800;
}

.reading-panel p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.ladder-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 14px;
  margin-bottom: 14px;
}

.ladder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.ladder-head strong {
  color: var(--accent-strong);
}

.ladder-panel p {
  min-height: 56px;
  margin: 12px 0 10px;
  color: var(--ink);
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.ladder-panel ruby {
  ruby-position: over;
}

.ladder-panel rt {
  color: var(--accent-strong);
  font-size: 0.58em;
  font-weight: 700;
}

.pending-reading {
  display: inline-block;
  border-bottom: 3px solid var(--accent);
  color: var(--accent-strong);
}

.ladder-dots {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.ladder-dots span {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #e8dfd0;
}

.ladder-dots span.active {
  background: var(--accent);
}

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

.audio-display {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  min-height: 110px;
}

.audio-copy {
  min-width: 0;
}

.prompt-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.prompt-text {
  margin-bottom: 0;
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.25;
}

.icon-button {
  width: 58px;
  height: 58px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--ink);
  display: inline-grid;
  place-items: center;
  font-size: 1.4rem;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.icon-button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.icon-button.primary {
  width: 76px;
  height: 76px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 1.8rem;
}

.control-row,
.stage-actions,
.shadow-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.control-row {
  margin-top: 12px;
}

.speed-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.preview-subtitle {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 12px 14px;
  color: var(--ink);
  font-size: 1.18rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.preview-subtitle.masked {
  background: #fbf6ec;
}

select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 0 10px;
}

.text-button,
.secondary-button,
.primary-button,
.small-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 0 14px;
  font-weight: 700;
}

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

.secondary-button {
  color: var(--accent-strong);
}

.small-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.88rem;
}

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

.choice-button {
  min-height: 82px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 12px;
  text-align: left;
  display: grid;
  gap: 4px;
}

.choice-lock {
  grid-column: 1 / -1;
  min-height: 82px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbf6ec;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.choice-button strong {
  font-size: 1.2rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.choice-button ruby {
  ruby-position: over;
}

.choice-button rt {
  color: var(--accent-strong);
  font-size: 0.68rem;
  font-weight: 700;
}

.choice-button span {
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.choice-button.correct {
  border-color: var(--green);
  background: #e9f4ec;
}

.choice-button.wrong {
  border-color: var(--red);
  background: #f9e9e7;
}

.choice-button:disabled:not(.correct):not(.wrong) {
  cursor: not-allowed;
  opacity: 0.58;
}

.answer-status {
  margin-bottom: 14px;
  border-radius: 6px;
  padding: 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.answer-status.wrong {
  background: #f9e9e7;
  color: var(--red);
}

.subtitle-stack {
  display: grid;
  gap: 10px;
}

.subtitle-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 14px;
}

.subtitle-block span {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.subtitle-block p {
  margin-bottom: 0;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.subtitle-block ruby,
.word-card ruby {
  ruby-position: over;
}

.subtitle-block rt,
.word-card rt {
  color: var(--accent-strong);
  font-size: 0.62em;
  font-weight: 700;
}

.subtitle-block.ja p {
  font-size: 1.48rem;
}

.context-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 12px 14px;
}

.context-panel summary {
  color: var(--accent-strong);
  cursor: pointer;
  font-weight: 800;
}

.context-grid {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.context-grid div {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.context-grid span {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.context-grid p {
  margin-bottom: 0;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.word-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 0.8fr);
  gap: 12px;
  align-items: center;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbf6ec;
}

.word-main {
  margin-bottom: 4px;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.word-kana,
.word-meaning {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.word-meaning {
  color: var(--ink);
  font-weight: 700;
}

.explain-card {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 14px;
}

.explain-card .section-heading span {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 4px 9px;
}

.explain-list {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
}

.explain-list div {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.explain-list dt {
  color: var(--muted);
  font-weight: 800;
}

.explain-list dd {
  margin: 0;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.shadow-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-strong);
}

.shadow-panel p {
  margin-bottom: 0;
  color: var(--muted);
}

#recordingAudio {
  width: 100%;
  margin-top: 12px;
}

.stage-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

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

.metric-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 12px 8px;
  text-align: center;
}

.metric-grid span {
  display: block;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent-strong);
}

.metric-grid p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.review-list,
.vocab-list {
  display: grid;
  gap: 8px;
  max-height: 330px;
  overflow: auto;
  padding-right: 2px;
  margin-top: 12px;
}

.list-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 10px;
  text-align: left;
}

.list-item strong {
  display: block;
  margin-bottom: 2px;
  overflow-wrap: anywhere;
}

.list-item span {
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.list-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 14px;
  text-align: center;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: static;
  }
}

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

  .topbar,
  .lesson-meta,
  .section-heading,
  .shadow-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .status-pill,
  .timebox {
    width: 100%;
  }

  .lesson-stage,
  .side-panel {
    padding: 14px;
  }

  .step-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .audio-display {
    grid-template-columns: 1fr;
    place-items: center;
    text-align: center;
  }

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

  .choice-button {
    min-height: 74px;
  }

  h1 {
    font-size: 1.7rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  .prompt-text {
    font-size: 1.38rem;
  }

  .ladder-panel p {
    font-size: 1.38rem;
  }

  .subtitle-block.ja p {
    font-size: 1.25rem;
  }

  .word-main {
    font-size: 1.55rem;
  }

  .stage-actions .primary-button,
  .stage-actions .secondary-button,
  .control-row .text-button {
    flex: 1 1 140px;
  }

  .speed-control {
    flex: 1 1 160px;
  }

  .speed-control select {
    flex: 1;
  }
}
