:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --surface: #ffffff;
  --surface-strong: #edf7f4;
  --ink: #17211f;
  --muted: #63716d;
  --line: #dce4df;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #c2410c;
  --gold: #b7791f;
  --blue: #2563eb;
  --shadow: 0 18px 45px rgba(15, 59, 55, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(88px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1180px;
  margin: 0 auto 16px;
}

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

h1 {
  margin-bottom: 0;
  font-size: 1.45rem;
}

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

h3 {
  font-size: 1.05rem;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
}

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

.side-panel,
.content-panel {
  display: grid;
  gap: 14px;
}

.hero-panel,
.progress-panel,
.topic-map,
.content-panel > .view,
.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px;
}

.hero-panel div {
  min-width: 0;
  border-radius: 6px;
  background: var(--surface-strong);
  padding: 12px;
}

.hero-panel strong {
  display: block;
  font-size: 1.45rem;
}

.hero-panel span,
.muted,
.topic-item span,
.stats-grid span,
.mistake-item span {
  color: var(--muted);
  font-size: 0.88rem;
}

.progress-panel,
.topic-map,
.view {
  padding: 16px;
}

.section-title,
.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title span,
.pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--primary-dark);
  background: #f8fbfa;
  font-size: 0.82rem;
  font-weight: 800;
}

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

.meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 180ms ease;
}

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

.topic-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: #fbfcfa;
}

.topic-item.current {
  border-color: rgba(15, 118, 110, 0.45);
  background: var(--surface-strong);
}

.topic-item strong,
.topic-item span {
  display: block;
}

.priority {
  min-width: 28px;
  border-radius: 999px;
  padding: 3px 8px;
  color: #fff;
  text-align: center;
  font-style: normal;
  font-size: 0.78rem;
  font-weight: 900;
}

.priority-a {
  background: var(--accent);
}

.priority-b {
  background: var(--gold);
}

.priority-c {
  background: var(--blue);
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(246, 247, 243, 0.92);
  padding: 6px;
  backdrop-filter: blur(12px);
}

.tab,
.primary,
.secondary,
.icon-button,
.rating-row button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.tab.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.task-list,
.quiz-list,
.mistake-list {
  display: grid;
  gap: 10px;
}

.task-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #fbfcfa;
}

.task-item input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

.task-item em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.82rem;
}

.action-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.action-row.wrap {
  flex-wrap: wrap;
}

.primary,
.secondary {
  flex: 1;
  padding: 0 14px;
}

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

.primary:active,
.tab.active:active {
  background: var(--primary-dark);
}

.lesson-content section {
  margin-bottom: 18px;
}

.lesson-content p,
.lesson-content li {
  color: #30413d;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface-strong);
}

tr:last-child td {
  border-bottom: 0;
}

.flashcard {
  min-height: 250px;
  border: 1px solid rgba(15, 118, 110, 0.35);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #eef8f5);
  padding: 20px;
  outline: none;
}

.flashcard h3 {
  margin-bottom: 20px;
  font-size: 1.35rem;
}

.card-answer {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  color: #283936;
}

.hidden {
  display: none;
}

.rating-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.rating-row button.selected {
  border-color: var(--primary);
  background: var(--surface-strong);
  color: var(--primary-dark);
}

.quiz-item {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 14px;
  background: #fbfcfa;
}

.quiz-item legend {
  padding: 0 4px;
  font-weight: 850;
}

.quiz-item label {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 10px;
}

.quiz-item input {
  margin-top: 4px;
  accent-color: var(--primary);
}

.quiz-feedback {
  display: none;
  margin-top: 12px;
  border-radius: 7px;
  padding: 10px;
  font-weight: 700;
}

.quiz-feedback.correct,
.quiz-feedback.wrong {
  display: block;
}

.quiz-feedback.correct {
  background: #e6f6ef;
  color: #166534;
}

.quiz-feedback.wrong {
  background: #fff1ed;
  color: #9a3412;
}

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

.stats-grid div {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfa;
  padding: 12px;
}

.stats-grid strong {
  display: block;
  font-size: 1.28rem;
}

.mistake-item,
.empty-state,
.notice {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #fbfcfa;
}

.mistake-item p {
  margin-bottom: 6px;
}

.notice {
  margin-top: 16px;
  box-shadow: none;
}

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

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

  .layout {
    grid-template-columns: minmax(260px, 0.85fr) minmax(420px, 1.5fr);
    align-items: start;
  }

  .side-panel {
    position: sticky;
    top: 16px;
  }

  h1 {
    font-size: 1.7rem;
  }
}

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

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

  .tabs {
    position: fixed;
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    top: auto;
    box-shadow: var(--shadow);
  }

  .tab {
    min-height: 46px;
    padding: 0 4px;
    font-size: 0.86rem;
  }

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

  .action-row {
    flex-direction: column;
  }

  .flashcard {
    min-height: 230px;
  }
}
