:root {
  color-scheme: light;
  --paper: #f4efe7;
  --panel: #fffaf6;
  --ink: #17201b;
  --muted: #66736b;
  --line: #ded5c6;
  --green: #8f2d24;
  --green-2: #f5dfd8;
  --red: #b4443f;
  --blue: #286173;
  --amber: #c47b1d;
  --shadow: 0 16px 40px rgba(39, 35, 28, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 24px;
  background: #ebe2d5;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--green);
  color: white;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p,
.eyebrow,
.phrase-meta,
.settings-note,
small {
  color: var(--muted);
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab,
.command-button,
.icon-button {
  border: 1px solid var(--line);
  background: #fffbf5;
  color: var(--ink);
  border-radius: 8px;
  cursor: pointer;
}

.nav-tab {
  text-align: left;
  padding: 12px 14px;
}

.nav-tab.active {
  border-color: var(--green);
  background: var(--green-2);
  color: var(--green);
  font-weight: 700;
}

.level-panel {
  margin-top: 28px;
  display: grid;
  gap: 8px;
}

.level-panel label {
  color: var(--muted);
  font-size: 14px;
}

select,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fffdf8;
  color: var(--ink);
}

.content {
  padding: 28px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.eyebrow {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.topbar h2 {
  font-size: 28px;
  line-height: 1.2;
}

.score-pill {
  min-width: 110px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  background: #fffdf8;
  text-align: center;
}

.practice-summary {
  display: flex;
  align-items: center;
  gap: 12px;
}

.score-pill span,
.stat span {
  display: block;
  font-size: 30px;
  font-weight: 800;
  color: var(--green);
}

.practice-layout,
.lesson-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(320px, 0.88fr);
  gap: 18px;
}

.phrase-board,
.feedback-panel,
.drill-strip,
.lesson-card,
.stat,
.history-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.phrase-board {
  min-height: 390px;
  padding: 28px;
  display: flex;
  flex-direction: column;
}

.phrase-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.phrase-board p {
  margin: 0;
  color: var(--muted);
  font-size: 20px;
}

#phraseSound,
.phrase-board h3,
#phrasePinyin {
  font-size: clamp(27px, 3vw, 34px);
  line-height: 1.24;
  font-weight: 750;
  letter-spacing: 0;
}

#phraseSound {
  margin: 24px 0 12px;
  color: var(--green);
}

.phrase-board h3 {
  margin: 0 0 12px;
}

#phrasePinyin {
  margin-bottom: 14px;
  color: var(--blue);
}

#phraseTranslation {
  font-size: 20px;
}

.phrase-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: auto;
  padding-top: 24px;
}

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

.command-button,
.icon-button {
  min-height: 44px;
  padding: 0 16px;
  font-weight: 700;
}

.icon-button {
  width: 48px;
  padding: 0;
  font-size: 18px;
}

.command-button.primary {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.command-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.command-button.recording {
  border-color: var(--red);
  background: var(--red);
}

.feedback-panel {
  padding: 22px;
}

.feedback-panel h3,
.drill-strip h3,
.lesson-card h3,
.history-panel h3 {
  margin: 0 0 14px;
  font-size: 18px;
}

.meter {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8dfd1;
}

#meterFill {
  width: 0%;
  height: 100%;
  background: var(--green);
  transition: width 240ms ease;
}

.score-line {
  margin: 14px 0 18px;
  font-weight: 800;
  font-size: 20px;
}

.result-grid {
  display: grid;
  gap: 14px;
  margin: 0;
}

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

dt {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

dd {
  margin: 0;
  line-height: 1.5;
}

.word-diff {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.word {
  border-radius: 8px;
  padding: 7px 9px;
  background: #ebe4d7;
  font-weight: 700;
}

.word.ok {
  background: var(--green-2);
  color: var(--green);
}

.word.miss {
  background: #f2d9d6;
  color: var(--red);
}

.drill-strip {
  margin-top: 18px;
  padding: 18px;
  box-shadow: none;
}

.phrase-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.phrase-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.phrase-item.active {
  border-color: var(--blue);
  background: #e5eff6;
}

.phrase-item strong {
  display: block;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.3;
}

.phrase-item span {
  display: block;
  margin-top: 6px;
  color: var(--blue);
  font-size: 16px;
  font-weight: 850;
  line-height: 1.3;
}

.phrase-item em {
  display: block;
  margin-top: 4px;
  color: var(--green);
  font-size: 16px;
  font-style: normal;
  font-weight: 850;
  line-height: 1.3;
}

.phrase-item small {
  display: block;
  margin-top: 4px;
  line-height: 1.4;
}

.lesson-card {
  padding: 22px;
  min-height: 220px;
}

.lesson-card.large {
  min-height: 430px;
}

.lesson-output {
  white-space: pre-wrap;
  line-height: 1.7;
}

#lessonGoals {
  margin: 0;
  padding-left: 20px;
  line-height: 1.8;
}

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

.stat {
  padding: 20px;
  box-shadow: none;
}

.history-panel {
  margin-top: 18px;
  padding: 18px;
  box-shadow: none;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 12px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.history-item strong {
  color: var(--green);
}

.history-item p {
  margin: 0;
}

.settings-form {
  display: grid;
  max-width: 720px;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--panel);
}

.settings-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.settings-note {
  max-width: 720px;
  line-height: 1.6;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

#glmStatus {
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav-tabs {
    grid-template-columns: repeat(4, 1fr);
  }

  .nav-tab {
    text-align: center;
    padding: 10px 6px;
  }

  .level-panel {
    margin-top: 12px;
  }

  .content {
    padding: 18px 14px 28px;
  }

  .topbar,
  .practice-layout,
  .lesson-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .practice-summary {
    display: grid;
    grid-template-columns: 1fr;
  }

  .phrase-board {
    min-height: 330px;
    padding: 20px;
  }

  .phrase-actions {
    display: grid;
    grid-template-columns: 48px 1fr 1fr;
  }

  #recordBtn {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  #nextBtn {
    grid-column: 3;
    grid-row: 1;
  }

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