:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #f0f6f5;
  --ink: #1f2933;
  --muted: #65727f;
  --line: #d8dedb;
  --accent: #167c80;
  --accent-2: #b45f3a;
  --accent-3: #2f5d8c;
  --danger: #a43d3d;
  --shadow: 0 10px 24px rgba(39, 51, 58, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 700;
}

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

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

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

.topbar h1,
.course-head h2,
.side-panel h2,
.section-head h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.status-row,
.button-row,
.tabs,
.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #dff2ef;
  color: #0d6165;
  font-size: 13px;
  font-weight: 800;
}

.status-pill.muted {
  background: #efe7dc;
  color: #79543d;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

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

.import-panel,
.library-panel,
.settings-panel,
.stats-panel,
.mobile-panel,
.workspace {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.import-panel,
.library-panel,
.settings-panel,
.stats-panel,
.mobile-panel {
  padding: 14px;
}

.side-panel h2 {
  margin-bottom: 10px;
  font-size: 15px;
}

.library-status,
.mobile-tip {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.45;
  font-size: 13px;
}

.primary-button,
.ghost-button,
.danger-button,
.file-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 9px 12px;
}

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

.ghost-button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
}

.danger-button {
  background: #f7e3df;
  color: var(--danger);
}

.file-box {
  min-height: 40px;
  margin: 8px 0;
  border: 1px dashed #a9b7b3;
  border-radius: 7px;
  color: var(--accent-3);
  font-weight: 800;
  cursor: pointer;
}

.file-box input {
  display: none;
}

textarea {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  margin-bottom: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fbfaf7;
  line-height: 1.5;
}

.settings-panel label {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

select,
input[type="range"] {
  width: 100%;
}

select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  background: #fbfaf7;
  color: var(--ink);
}

.stat-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.stat-line:last-child {
  border-bottom: 0;
}

.stat-line strong {
  color: var(--ink);
}

.lesson-catalog {
  display: grid;
  gap: 8px;
}

.lesson-link {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 10px;
  text-align: left;
  border: 1px solid var(--line);
  background: #fbfaf7;
  color: var(--ink);
}

.lesson-link.active {
  background: #dff2ef;
  border-color: #9ec9c3;
  color: #0d6165;
}

.lesson-link strong {
  font-size: 14px;
}

.lesson-link span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.workspace {
  min-height: calc(100vh - 124px);
  overflow: hidden;
}

.course-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.course-actions {
  display: flex;
  align-items: end;
  gap: 8px;
}

.course-picker {
  display: grid;
  gap: 5px;
  min-width: 250px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.speech-feedback {
  margin: 0;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: #f0f6f5;
  color: #0d6165;
  font-size: 13px;
  font-weight: 800;
}

.course-head .ghost-button,
.section-head .ghost-button,
.section-head .danger-button {
  width: auto;
  min-width: 108px;
}

.course-head h2 {
  font-size: 22px;
}

.tabs {
  padding: 10px 12px 0;
  background: #fbfaf7;
}

.tab {
  width: 88px;
  background: transparent;
  color: var(--muted);
  border-radius: 7px 7px 0 0;
}

.tab.active {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--line);
  border-bottom-color: var(--surface);
}

.tab-panel {
  display: none;
  padding: 16px;
}

.tab-panel.active {
  display: block;
}

.section-head {
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-head h3 {
  font-size: 17px;
}

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

.word-card,
.pattern-item,
.line-item,
.record-item,
.target-box,
.result-box,
.passage-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.word-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 176px;
  padding: 12px;
}

.word-card.known,
.pattern-item.known {
  background: #f0f6f5;
  border-color: #9ec9c3;
}

.word-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.word-term {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  color: var(--accent-3);
}

.word-term-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  min-height: 34px;
  padding: 0;
  background: transparent;
  text-align: left;
}

.word-play-label {
  padding: 4px 7px;
  border: 1px solid #c9dce4;
  border-radius: 6px;
  background: #edf4f7;
  color: #244d63;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.word-meaning {
  margin: 3px 0 10px;
  color: var(--accent-2);
  font-weight: 800;
}

.example,
.translation {
  margin: 0 0 6px;
  line-height: 1.45;
}

.translation {
  color: var(--muted);
}

.word-note {
  margin: 7px 0 0;
  color: #49626f;
  font-size: 13px;
  line-height: 1.45;
}

.word-note span {
  display: inline-block;
  min-width: 38px;
  margin-right: 6px;
  color: var(--accent-2);
  font-weight: 800;
}

.mini-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.mini-actions button,
.pattern-actions button,
.line-item button {
  min-height: 34px;
  padding: 6px 8px;
  background: #edf4f7;
  color: #244d63;
  border: 1px solid #c9dce4;
}

.check-button.active {
  background: #dff2ef;
  color: #0d6165;
  border-color: #9ec9c3;
}

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

.pattern-item {
  padding: 12px;
}

.pattern-item h4 {
  margin: 0 0 6px;
  font-size: 17px;
  color: var(--accent-3);
}

.pattern-meaning {
  margin: 0 0 10px;
  color: var(--accent-2);
  font-weight: 800;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
}

.pattern-code {
  padding: 10px;
  background: #fbfaf7;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.pattern-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.passage-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
}

#passageText {
  color: #193f5f;
  font-weight: 800;
}

#passageZh {
  color: var(--muted);
}

.practice-zone {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.target-box,
.result-box {
  min-height: 190px;
  padding: 14px;
}

#practiceTarget {
  min-height: 68px;
  margin: 0 0 14px;
  font-size: 22px;
  font-weight: 900;
  color: var(--accent-3);
  line-height: 1.35;
}

#transcriptText {
  min-height: 52px;
  margin: 0 0 10px;
  color: var(--ink);
  line-height: 1.45;
}

meter {
  width: 100%;
  height: 16px;
}

#scoreText {
  margin: 6px 0;
  font-weight: 900;
}

#feedbackText {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.practice-list,
.record-list {
  display: grid;
  gap: 8px;
}

.line-item,
.record-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
}

.line-item p,
.record-item p {
  margin: 0;
  line-height: 1.45;
}

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

@media (max-width: 900px) {
  .layout,
  .practice-zone,
  .passage-box {
    grid-template-columns: 1fr;
  }

  .side-panel {
    display: none;
  }

  .workspace {
    order: 1;
    min-height: 0;
  }

  .topbar,
  .course-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .course-actions,
  .course-picker,
  .course-head .ghost-button {
    width: 100%;
  }

  .course-actions {
    align-items: stretch;
    flex-direction: column;
  }
}

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

  .topbar h1 {
    font-size: 24px;
  }

  .mini-actions {
    grid-template-columns: 1fr 1.35fr 1fr;
  }

  .mini-actions button {
    min-width: 0;
    padding-inline: 5px;
    font-size: 13px;
  }

  .tab {
    width: calc(50% - 4px);
  }
}
