:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #eef4f8;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #d7dee8;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --good: #15803d;
  --bad: #b91c1c;
  --warn: #b45309;
  --shadow: 0 16px 40px rgba(30, 41, 59, 0.11);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #334155;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #2dd4bf;
  --accent-2: #60a5fa;
  --good: #4ade80;
  --bad: #f87171;
  --warn: #fb923c;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

body,
.controls,
.question-list,
.list-head,
.quiz-panel,
.score-board div {
  transition: background 0.3s ease, background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

.list-item,
.option-btn,
.option-key,
.feedback {
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

[data-theme="dark"] body {
  background: linear-gradient(180deg, #0f172a 0, #1e293b 100%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #eef4f8 0, #f5f7fb 34%, #f9fafb 100%);
  color: var(--ink);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

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

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.2;
  letter-spacing: 0;
}

.score-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(82px, 1fr));
  gap: 10px;
}

.score-board div {
  min-width: 82px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  text-align: center;
}

.score-board span {
  display: block;
  font-size: 24px;
  font-weight: 800;
}

.score-board small {
  color: var(--muted);
}

.controls {
  display: grid;
  grid-template-columns: 170px 180px minmax(240px, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select,
input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

select:focus,
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.button-row {
  display: grid;
  grid-template-columns: repeat(4, max-content);
  gap: 8px;
}

.study-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.question-list,
.quiz-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.question-list {
  min-height: 620px;
  overflow: hidden;
}

.list-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

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

.list-items {
  max-height: 578px;
  overflow: auto;
}

.list-item {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 72px;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  text-align: left;
}

.list-item.active {
  background: #e7f6f3;
  color: var(--accent);
}

.list-item.correct {
  border-left: 4px solid var(--good);
}

.list-item.wrong {
  border-left: 4px solid var(--bad);
}

.list-title {
  color: inherit;
  font-weight: 800;
}

.list-snippet {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.quiz-panel {
  min-height: 620px;
  padding: 28px;
}

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

.question-meta span {
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

h2 {
  margin: 0 0 22px;
  font-size: 25px;
  line-height: 1.45;
  letter-spacing: 0;
}

.options {
  display: grid;
  gap: 12px;
}

.option-btn {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 58px;
  padding: 10px 14px;
  text-align: left;
}

.option-key {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 800;
}

.option-btn.correct {
  border-color: var(--good);
  background: #ecfdf3;
  color: var(--good);
}

.option-btn.wrong {
  border-color: var(--bad);
  background: #fef2f2;
  color: var(--bad);
}

.feedback {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff7ed;
}

.feedback strong {
  color: var(--warn);
}

.feedback p {
  margin: 8px 0 0;
  line-height: 1.65;
}

.hidden {
  display: none;
}

.nav-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}

.nav-row button {
  min-width: 110px;
}

.empty-state {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .study-layout {
    display: flex;
    flex-direction: column;
  }

  .quiz-panel {
    order: 1; /* 手机端答题区置顶，核心做题区域一目了然 */
    min-height: auto;
  }

  .question-list {
    order: 2; /* 题目大纲在底部，作为辅助跳转 */
    min-height: auto;
    margin-top: 16px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }

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

  .list-items {
    max-height: 200px; /* 适当压缩底部大纲高度，保持页面利落 */
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 16px;
  }

  h1 {
    font-size: 24px; /* 微调标题大小适合小屏 */
  }

  .title-row {
    gap: 10px; /* 减小间距 */
  }

  h2 {
    font-size: 19px; /* 微调题目文字大小 */
    margin: 0 0 16px; /* 减小间距 */
  }

  /* 单元与题型在窄屏下并排展示，搜索框与按钮横跨，极度节约纵向空间 */
  .controls {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px;
  }

  .controls label:nth-of-type(1),
  .controls label:nth-of-type(2) {
    grid-column: span 1;
  }

  .controls label.search-box {
    grid-column: span 2;
  }

  .controls .button-row {
    grid-column: span 2;
    grid-template-columns: repeat(2, 1fr); /* 按钮双列 2x2 紧凑布局 */
  }

  .button-row button {
    font-size: 13px; /* 减小按钮文字字号，防溢出 */
    min-height: 38px; /* 稍微压缩按钮高度 */
  }

  /* 答题选项的移动端精致优化 */
  .quiz-panel {
    padding: 16px; /* 缩小面板边距 */
  }

  .option-btn {
    min-height: 48px; /* 压缩选项按钮高度 */
    padding: 8px 12px;
  }
}

/* 暗黑模式适配与微调 */
[data-theme="dark"] .list-item.active {
  background: rgba(45, 212, 191, 0.15);
}

[data-theme="dark"] .option-btn.correct {
  background: rgba(74, 222, 128, 0.08);
}

[data-theme="dark"] .option-btn.wrong {
  background: rgba(248, 113, 113, 0.08);
}

[data-theme="dark"] .feedback {
  background: #2d2318;
}

[data-theme="dark"] .score-board div {
  background: rgba(30, 41, 59, 0.86);
}

/* 标题栏与主题切换按钮样式 */
.title-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.theme-toggle-btn {
  position: relative;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
}

.theme-toggle-btn svg {
  position: absolute;
  width: 20px;
  height: 20px;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  color: var(--accent);
}

.theme-toggle-btn .sun-icon {
  opacity: 1;
  transform: rotate(0deg);
}

.theme-toggle-btn .moon-icon {
  opacity: 0;
  transform: rotate(90deg);
}

[data-theme="dark"] .theme-toggle-btn .sun-icon {
  opacity: 0;
  transform: rotate(-90deg);
}

[data-theme="dark"] .theme-toggle-btn .moon-icon {
  opacity: 1;
  transform: rotate(0deg);
}
