:root {
  --bg: #101318;
  --panel: #171c23;
  --panel-2: #202733;
  --line: #303a48;
  --line-soft: #26303d;
  --text: #f0f3f7;
  --muted: #a7b0be;
  --dim: #7a8494;
  --blue: #4f8cff;
  --blue-2: #7fb0ff;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --cyan: #22d3ee;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.26);
  --radius: 8px;
  --font: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
}

button {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 64px;
  padding: 0 28px;
  background: rgba(16, 19, 24, 0.92);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  color: #071018;
  background: linear-gradient(135deg, var(--cyan), var(--amber));
  font-size: 13px;
}

.nav {
  display: flex;
  gap: 8px;
}

.nav-link,
.ghost,
.secondary,
.primary,
.success {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 8px 14px;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.nav-link,
.ghost,
.secondary {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.nav-link {
  min-width: 82px;
}

.nav-link.is-active,
.nav-link:hover,
.ghost:hover,
.secondary:hover {
  color: var(--text);
  background: var(--panel-2);
  border-color: #465469;
}

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

.success {
  background: var(--green);
  border-color: var(--green);
  color: #04130a;
  font-weight: 700;
}

.primary:hover,
.success:hover {
  transform: translateY(-1px);
}

.primary:disabled,
.success:disabled,
.secondary:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.big {
  min-height: 48px;
  padding-inline: 26px;
  font-weight: 700;
}

.page {
  display: none;
}

.page.is-active {
  display: block;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 24px;
  align-items: stretch;
  padding: 54px 32px 26px;
  max-width: 1240px;
  margin: 0 auto;
}

.hero h1 {
  margin: 4px 0 10px;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.1;
  letter-spacing: 0;
}

.hero-copy {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-size: 17px;
}

.eyebrow {
  margin: 0;
  color: var(--blue-2);
  font-size: 13px;
  font-weight: 700;
}

.hero-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero-panel div,
.stat-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 16px;
  background: #12171f;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

.hero-panel strong,
.stat-card strong {
  font-size: 28px;
  color: var(--cyan);
}

.hero-panel span,
.stat-card span {
  color: var(--muted);
}

.subject-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 32px 60px;
}

.subject-card,
.topic-card,
.quiz-card,
.exam-card,
.result-card,
.stats-card,
.side-panel {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

.subject-card {
  min-height: 260px;
  padding: 20px;
  cursor: pointer;
}

.subject-card:hover,
.topic-card:hover {
  border-color: #4a5a70;
  background: var(--panel-2);
}

.subject-card h2 {
  margin: 10px 0 8px;
  font-size: 20px;
  line-height: 1.35;
}

.subject-card p,
.topic-card p,
.exam-card p {
  color: var(--muted);
}

.subject-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 6px;
  background: #12171f;
  color: var(--muted);
  border: 1px solid var(--line-soft);
  font-size: 12px;
}

.tag.wiring {
  color: #ffd48a;
  border-color: rgba(245, 158, 11, 0.45);
}

.tag.mastery {
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.48);
}

.tag.danger {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.48);
}

.page-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 22px 32px;
  background: #12171f;
  border-bottom: 1px solid var(--line-soft);
}

.page-head h2 {
  margin: 2px 0 0;
  line-height: 1.25;
}

.topic-list,
.stats-body,
.result-body {
  max-width: 980px;
  margin: 0 auto;
  padding: 26px 32px 60px;
}

.topic-card {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 18px;
  margin-bottom: 12px;
  cursor: pointer;
}

.topic-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: #101720;
  color: var(--cyan);
  border: 1px solid var(--line-soft);
  font-weight: 800;
}

.topic-card h3 {
  margin: 0;
  font-size: 17px;
}

.topic-card p {
  margin: 4px 0 0;
}

.topic-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.meter {
  min-width: 170px;
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

.bar {
  height: 7px;
  margin-top: 6px;
  overflow: hidden;
  background: #0d1117;
  border-radius: 99px;
  border: 1px solid var(--line-soft);
}

.bar i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--cyan));
  transition: width 0.25s ease;
}

.quiz-card {
  max-width: 920px;
  min-height: 360px;
  margin: 28px auto;
  padding: 28px;
}

.question-title {
  margin: 6px 0 22px;
  font-size: 20px;
}

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

.option {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  width: 100%;
  min-height: 52px;
  padding: 12px;
  text-align: left;
  background: #12171f;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
}

.option:hover,
.option.is-selected {
  border-color: var(--blue);
  background: #172236;
}

.option.is-correct {
  border-color: var(--green);
  background: rgba(34, 197, 94, 0.12);
}

.option.is-wrong {
  border-color: var(--red);
  background: rgba(239, 68, 68, 0.12);
}

.letter {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: #0d1117;
  color: var(--blue-2);
  border: 1px solid var(--line);
  font-weight: 700;
}

.explain {
  margin-top: 18px;
  padding: 16px;
  border-left: 3px solid var(--blue);
  background: #12171f;
  color: var(--muted);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.bottom-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 14px 18px;
  background: rgba(16, 19, 24, 0.94);
  border-top: 1px solid var(--line-soft);
}

.wiring-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}

.status-pill {
  flex: 1;
  min-width: 220px;
  text-align: center;
  color: var(--muted);
}

.wiring-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 186px);
}

.canvas-wrap {
  overflow: auto;
  min-height: 690px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px),
    #0d1117;
  background-size: 22px 22px;
}

#wiring-canvas {
  display: block;
  cursor: crosshair;
}

.side-panel {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr 1.5fr;
  gap: 16px;
  padding: 18px;
  overflow: auto;
  max-height: none;
}

.side-panel h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.side-panel h3:not(:first-child) {
  margin-top: 18px;
}

.step-panel {
  min-width: 0;
}

.wiring-step {
  min-height: 132px;
  padding: 12px;
  background: #101720;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  color: var(--muted);
}

.wiring-step strong {
  display: block;
  color: var(--cyan);
  margin-bottom: 6px;
}

.wiring-step .step-edge {
  display: block;
  margin-top: 8px;
  color: #ffd48a;
  font-size: 13px;
}

.side-panel ol {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}

.connection-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.wire-chip {
  padding: 4px 7px;
  border-radius: 6px;
  background: #101720;
  color: var(--muted);
  border: 1px solid var(--line-soft);
  font-size: 12px;
}

.wire-chip.good {
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.55);
}

.wire-chip.bad {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.55);
}

.simulation-panel {
  min-height: 110px;
  padding: 12px;
  background: #101720;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  color: var(--muted);
}

.sim-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.sim-state {
  display: grid;
  gap: 8px;
}

.state-line {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #0d1117;
}

.state-line strong {
  color: var(--cyan);
}

.sim-feedback {
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: 6px;
  color: #dce5ef;
  background: rgba(56, 189, 248, 0.08);
}

.exam-start {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 64px);
  padding: 32px;
}

.exam-card {
  max-width: 650px;
  padding: 34px;
  box-shadow: var(--shadow);
}

.exam-card h1 {
  margin: 4px 0 8px;
}

.exam-card dl {
  display: grid;
  gap: 10px;
  margin: 26px 0;
}

.exam-card dl div {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

.exam-card dt {
  color: var(--text);
  font-weight: 700;
}

.exam-card dd {
  margin: 0;
  color: var(--muted);
}

.exam-strip {
  position: sticky;
  top: 64px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 32px;
  background: #12171f;
  border-bottom: 1px solid var(--line-soft);
}

#exam-timer {
  color: var(--amber);
  font-size: 24px;
  min-width: 74px;
}

#exam-body {
  padding: 28px 32px 60px;
  max-width: 980px;
  margin: 0 auto;
}

.exam-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.exam-answer-state {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.compact {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stats-section {
  margin-top: 28px;
}

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

.stats-head h3 {
  margin: 2px 0 0;
  font-size: 19px;
}

.wrong-list,
.topic-progress-grid {
  display: grid;
  gap: 12px;
}

.wrong-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.topic-progress-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.wrong-card,
.topic-progress-card,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

.wrong-card,
.topic-progress-card {
  padding: 16px;
}

.wrong-card h3,
.topic-progress-card h3 {
  margin: 4px 0 0;
  font-size: 15px;
  line-height: 1.45;
}

.topic-progress-card {
  display: grid;
  align-content: start;
  gap: 12px;
}

.topic-progress-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.progress-line {
  height: 8px;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 99px;
  background: #0d1117;
}

.progress-line i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--cyan));
}

.empty-state {
  padding: 18px;
  color: var(--muted);
}

.stats-table-wrap {
  overflow-x: auto;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
}

.stats-table th,
.stats-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
}

.stats-table th {
  color: var(--muted);
  background: #12171f;
  font-weight: 600;
}

.result-card {
  padding: 34px;
  text-align: center;
}

.score {
  margin: 14px 0;
  font-size: 76px;
  line-height: 1;
  color: var(--cyan);
  font-weight: 800;
}

.score.pass {
  color: var(--green);
}

.score.fail {
  color: var(--red);
}

.toast {
  position: fixed;
  right: 20px;
  top: 82px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: #101720;
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: var(--shadow);
}

@media (max-width: 1060px) {
  .subject-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .side-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 12px 14px;
  }

  .nav {
    width: 100%;
  }

  .nav-link {
    flex: 1;
    min-width: 0;
  }

  .hero {
    grid-template-columns: 1fr;
    padding: 30px 16px 14px;
  }

  .subject-grid,
  .topic-list,
  .stats-body,
  .result-body {
    grid-template-columns: 1fr;
    padding-inline: 16px;
  }

  .page-head {
    align-items: flex-start;
    padding: 16px;
    flex-wrap: wrap;
  }

  .meter {
    width: 100%;
    margin-left: 0;
  }

  .topic-card {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .topic-card .tag {
    grid-column: 2;
    justify-self: start;
  }

  .topic-badges {
    grid-column: 2;
    justify-content: flex-start;
  }

  .quiz-card,
  #exam-body {
    margin: 16px;
    padding: 18px;
  }

  .bottom-actions {
    flex-wrap: wrap;
  }

  .wiring-toolbar {
    padding: 10px 12px;
  }

  .wiring-workbench {
    padding: 10px;
  }

  .canvas-wrap {
    min-height: 470px;
  }

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

  .stats-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .wrong-list,
  .topic-progress-grid {
    grid-template-columns: 1fr;
  }
}
