:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #17212f;
  --muted: #687387;
  --line: #dce4ef;
  --teal: #0f9f9a;
  --teal-strong: #08736f;
  --amber: #f4b740;
  --coral: #ec6b5f;
  --blue: #3578e5;
  --green: #27a66d;
  --shadow: 0 18px 50px rgba(32, 47, 74, 0.1);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: #ffffff;
  font-weight: 800;
  background: linear-gradient(135deg, var(--teal), var(--blue));
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.eyebrow,
.muted {
  color: var(--muted);
}

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

.nav-item {
  border: 0;
  background: transparent;
  color: #354156;
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.nav-item svg,
button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.nav-item.active,
.nav-item:hover {
  background: #e9f6f5;
  color: var(--teal-strong);
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.main {
  min-width: 0;
  padding: 28px;
}

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

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

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

h1 {
  margin-bottom: 0;
  font-size: 28px;
}

h2 {
  font-size: 20px;
  margin-bottom: 10px;
}

h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.top-actions,
.button-row,
.lesson-tools,
.quiz-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.ghost-button {
  border-radius: var(--radius);
  min-height: 40px;
  padding: 10px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.primary-button {
  background: var(--teal);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--teal-strong);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.secondary-button {
  background: #ffffff;
  border-color: var(--line);
  color: var(--ink);
}

.secondary-button:hover,
.ghost-button:hover {
  border-color: #bad4d3;
  background: #f7fbfb;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.grid {
  display: grid;
  gap: 18px;
}

.dashboard-grid {
  grid-template-columns: 1.4fr 1fr;
  align-items: stretch;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.panel-heading,
.lesson-head,
.quiz-toolbar,
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}

.pill {
  border: 1px solid #bee2de;
  background: #e9f8f6;
  color: var(--teal-strong);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 700;
}

.chapter-progress {
  display: grid;
  gap: 12px;
}

.chapter-row {
  display: grid;
  grid-template-columns: minmax(120px, 180px) 1fr auto;
  align-items: center;
  gap: 12px;
}

.progress-track,
.meter {
  height: 9px;
  background: #eaf0f6;
  border-radius: 999px;
  overflow: hidden;
}

.progress-track span,
.meter span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--amber));
  border-radius: inherit;
  width: 0;
  transition: width 0.25s ease;
}

.companion-card {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 18px;
  align-items: center;
  overflow: hidden;
}

.companion-visual {
  min-height: 150px;
  display: grid;
  place-items: center;
  position: relative;
}

.bulb-body {
  width: 104px;
  height: 118px;
  border-radius: 52% 52% 44% 44%;
  border: 5px solid rgba(91, 179, 185, 0.35);
  background: radial-gradient(circle at 48% 34%, #fff6b8 0 18%, #fffdf2 42%, #dff3f2 100%);
  box-shadow: 0 0 38px rgba(244, 183, 64, 0.38);
  position: relative;
  display: grid;
  place-items: center;
  animation: floaty 4s ease-in-out infinite;
}

.bulb-glow {
  width: 46px;
  height: 54px;
  border: 4px solid #f5cd55;
  border-bottom-width: 8px;
  border-radius: 46% 46% 38% 38%;
}

.bulb-face {
  position: absolute;
  top: 56px;
  display: flex;
  gap: 22px;
}

.bulb-face span {
  width: 10px;
  height: 10px;
  background: #19202c;
  border-radius: 999px;
}

.bulb-base {
  width: 54px;
  height: 30px;
  background: repeating-linear-gradient(180deg, #aeb8c4 0 6px, #d7dde5 6px 11px);
  border-radius: 0 0 8px 8px;
  margin-top: -38px;
}

.companion-visual.large .bulb-body {
  width: 170px;
  height: 190px;
}

.companion-visual.large .bulb-base {
  width: 82px;
  height: 42px;
  margin-top: -54px;
}

@keyframes floaty {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-7px);
  }
}

.stat-line {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.companion-tags,
.unlock-list,
.quest-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag,
.quest {
  border-radius: 999px;
  background: #f1f5fb;
  border: 1px solid var(--line);
  padding: 7px 10px;
  color: #354156;
  font-size: 13px;
}

.action-panel,
.stats-panel {
  min-height: 180px;
}

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

.mini-stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #fbfdff;
}

.mini-stat span,
.mini-stat strong {
  display: block;
}

.mini-stat span {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.mini-stat strong {
  font-size: 24px;
}

.learn-layout,
.practice-layout,
.companion-page {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 18px;
}

.chapter-list {
  display: grid;
  gap: 10px;
  align-content: start;
}

.chapter-button {
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: var(--radius);
  padding: 14px;
  text-align: left;
}

.chapter-button.active {
  border-color: #8ad2cd;
  background: #ebf8f7;
}

.chapter-button span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.lesson-content {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.lesson-block {
  border: 1px solid var(--line);
  background: #fbfdff;
  border-radius: var(--radius);
  padding: 16px;
}

.lesson-block ul {
  margin: 0;
  padding-left: 20px;
}

.lesson-block li {
  margin: 7px 0;
}

.lesson-block .secondary-button,
.lesson-block .ghost-button {
  margin-top: 10px;
}

.lesson-tools {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 16px;
}

.textbook-panel,
.experiment-panel {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.textbook-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.textbook-reader {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 300px;
  gap: 14px;
  align-items: stretch;
}

.textbook-frame {
  width: 100%;
  height: 620px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #eef3f8;
  overflow: auto;
  display: grid;
  justify-items: center;
  align-items: start;
  padding: 14px;
}

.textbook-frame img {
  width: min(100%, 700px);
  height: auto;
  display: block;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(32, 47, 74, 0.14);
}

.textbook-fallback {
  width: min(100%, 520px);
  min-height: 260px;
  border: 1px dashed #b9c6d8;
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--muted);
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  gap: 10px;
  padding: 28px;
}

.textbook-fallback strong {
  color: var(--ink);
}

.page-helper {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
  padding: 14px;
  min-height: 620px;
}

.page-helper-content {
  display: grid;
  gap: 12px;
}

.helper-card,
.helper-group {
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: var(--radius);
  padding: 12px;
}

.helper-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}

.helper-card strong {
  display: block;
  margin-bottom: 6px;
}

.helper-card p {
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}

.helper-group {
  display: grid;
  gap: 8px;
}

.helper-group h4 {
  margin: 0;
  font-size: 14px;
}

.helper-link {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f7fafd;
  padding: 10px;
  text-align: left;
  display: grid;
  gap: 4px;
  color: var(--ink);
}

.helper-link:hover,
.helper-link.active {
  border-color: #8ad2cd;
  background: #ebf8f7;
}

.helper-link span {
  font-weight: 700;
}

.helper-link b {
  color: var(--muted);
  font-size: 12px;
}

.textbook-note {
  color: var(--muted);
  font-size: 13px;
  margin: 10px 0 0;
}

.experiment-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.experiment-card {
  border: 1px solid var(--line);
  background: #fbfdff;
  border-radius: var(--radius);
  padding: 16px;
}

.experiment-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.experiment-topline span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.experiment-card p {
  color: #39465b;
  line-height: 1.65;
}

.experiment-practice {
  display: grid;
  gap: 6px;
  border-left: 3px solid var(--teal);
  background: #eff9f7;
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 10px 12px;
}

.experiment-practice span {
  color: var(--teal-strong);
  font-size: 12px;
  font-weight: 800;
}

.experiment-practice b {
  font-size: 14px;
  line-height: 1.5;
}

.experiment-card .secondary-button {
  margin-top: 12px;
}

.flashcard {
  margin-top: 14px;
  border: 1px solid #f0c66e;
  background: #fff8e7;
  border-radius: var(--radius);
  padding: 16px;
}

.hidden {
  display: none;
}

.quiz-toolbar {
  align-items: end;
}

.quiz-toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

select {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  min-height: 40px;
  padding: 8px 12px;
  color: var(--ink);
}

.question-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background: #fbfdff;
}

.question-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.question-meta span {
  border-radius: 999px;
  padding: 5px 9px;
  background: #eaf0f6;
  color: #40506a;
  font-size: 13px;
}

.options-box {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.option-button {
  width: 100%;
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: var(--radius);
  padding: 14px;
  text-align: left;
  color: var(--ink);
}

.option-button:hover,
.option-button.selected {
  border-color: #7fcac5;
  background: #ecf8f7;
}

.option-button.correct {
  border-color: rgba(39, 166, 109, 0.45);
  background: #eaf8f0;
}

.option-button.wrong {
  border-color: rgba(236, 107, 95, 0.5);
  background: #fff0ee;
}

.feedback-box {
  margin-top: 14px;
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.feedback-box.good {
  border-color: rgba(39, 166, 109, 0.5);
}

.feedback-box.bad {
  border-color: rgba(236, 107, 95, 0.5);
}

.practice-side {
  display: grid;
  gap: 12px;
  align-content: start;
}

.side-note {
  color: var(--muted);
  line-height: 1.6;
  background: #f6f9fd;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

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

.wide-panel {
  grid-column: 1 / -1;
}

.weakness-list,
.mistake-list,
.recommendation-box {
  display: grid;
  gap: 10px;
}

.feedback-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #fbfdff;
}

.feedback-item strong {
  display: block;
  margin-bottom: 4px;
}

.companion-page {
  grid-template-columns: 1fr 1fr;
}

.companion-stage {
  grid-row: span 2;
  display: grid;
  place-items: center;
  text-align: center;
  min-height: 470px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: #17212f;
  color: #ffffff;
  border-radius: var(--radius);
  padding: 12px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  box-shadow: var(--shadow);
  max-width: min(560px, calc(100vw - 32px));
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

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

  .brand,
  .sidebar-footer {
    display: none;
  }

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

  .nav-item {
    justify-content: center;
    padding: 10px 8px;
  }

  .nav-item span {
    display: none;
  }

  .main {
    padding: 18px;
  }

  .dashboard-grid,
  .learn-layout,
  .practice-layout,
  .feedback-grid,
  .companion-page {
    grid-template-columns: 1fr;
  }

  .lesson-content {
    grid-template-columns: 1fr;
  }

  .textbook-reader {
    grid-template-columns: 1fr;
  }

  .page-helper {
    min-height: auto;
  }

  .companion-stage {
    min-height: 360px;
  }
}

@media (max-width: 640px) {
  .topbar,
  .panel-heading,
  .lesson-head,
  .quiz-toolbar,
  .section-heading {
    display: grid;
  }

  h1 {
    font-size: 24px;
  }

  .companion-card {
    grid-template-columns: 1fr;
    text-align: center;
  }

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

  .top-actions,
  .button-row,
  .lesson-tools,
  .quiz-actions {
    width: 100%;
  }

  .primary-button,
  .secondary-button,
  .ghost-button {
    width: 100%;
  }

  .textbook-controls,
  .experiment-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .textbook-frame {
    height: 520px;
  }
}
