* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --text: #0f172a;
  --muted: rgba(15, 23, 42, 0.62);
  --muted2: rgba(15, 23, 42, 0.72);
  --border: rgba(15, 23, 42, 0.12);
  --border2: rgba(15, 23, 42, 0.16);
  --panel-bg: rgba(255, 255, 255, 0.85);
  --panel-bg2: rgba(255, 255, 255, 0.70);
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.10);
  --primary: #2563eb;
  --primary-2: #1d4ed8;
  --primary-bg: rgba(37, 99, 235, 0.10);
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.10);
  --ok: #059669;
  --ok-bg: rgba(5, 150, 105, 0.10);
  --warn: #d97706;
  --warn-bg: rgba(217, 119, 6, 0.12);
  --surface: rgba(255, 255, 255, 0.92);
  --surface2: rgba(255, 255, 255, 0.75);
  --input-bg: rgba(255, 255, 255, 0.92);
  --input-border: rgba(15, 23, 42, 0.16);
  --code-bg: rgba(15, 23, 42, 0.05);
  --code-border: rgba(15, 23, 42, 0.12);
}

html,
body {
  min-height: 100%;
  height: auto;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border);
  background: rgba(246, 247, 251, 0.85);
  backdrop-filter: blur(10px);
}

.topbar__inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar__onlyWhenCollapsed {
  display: none;
}

body.sidebar-collapsed .topbar__onlyWhenCollapsed {
  display: inline-flex;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.5px;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 18px 16px 56px;
}

.appLayout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 14px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  overflow-x: hidden;
}

.mainContent {
  min-width: 0;
}

.panel--tight {
  margin-bottom: 0;
}

body.sidebar-collapsed .appLayout {
  grid-template-columns: 0 1fr;
}

body.sidebar-collapsed .sidebar {
  max-height: 0;
  overflow: hidden;
}

@media (max-width: 980px) {
  .appLayout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
  }
  body.sidebar-collapsed .appLayout {
    grid-template-columns: 1fr;
  }
  body.sidebar-collapsed .sidebar {
    max-height: 0;
    overflow: hidden;
  }
}

.panel {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-bg);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.panel--hidden {
  display: none;
}

.panel__title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 650;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.picker {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebarActions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0 12px;
}

.sidebarPanel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebarActions--bottom {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.btn--sm {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
}

.btn--sm.btn--wide {
  width: 100%;
}

.picker__row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.picker__row--controls {
  align-items: flex-end;
}

.picker__col {
  flex: 1;
  min-width: 240px;
}

.picker__col--actions {
  flex: 0 0 auto;
  min-width: auto;
}

.input--select {
  padding: 12px 14px;
  border-radius: 12px;
  appearance: auto;
  font-weight: 650;
  cursor: pointer;
  line-height: 1.2;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 1px 0 rgba(15, 23, 42, 0.03);
}

.col {
  flex: 1;
  min-width: 240px;
}

.col--actions {
  flex: 0 0 auto;
  min-width: auto;
}

.label {
  display: block;
  font-size: 12px;
  color: var(--muted2);
  margin-bottom: 6px;
}

.input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  outline: none;
}

.input:focus {
  border-color: rgba(37, 99, 235, 0.65);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

.input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  box-shadow: none;
}

select.input option {
  color: var(--text);
  background: #ffffff;
}

.input--small {
  width: 110px;
}

.btn {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(37, 99, 235, 0.55);
  background: rgba(37, 99, 235, 0.12);
  color: var(--text);
  cursor: pointer;
}

.btn:hover {
  background: rgba(37, 99, 235, 0.18);
}

.btn:active {
  transform: translateY(1px);
}

.btn--ghost {
  border-color: var(--border2);
  background: rgba(255, 255, 255, 0.70);
}

.btn--wide {
  width: 100%;
  justify-content: center;
}

.hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.status {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted2);
  white-space: pre-wrap;
}

.meta {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted2);
  white-space: pre-wrap;
}

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

.quizTitle {
  font-weight: 700;
  font-size: 16px;
}

.quizSubTitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.progress {
  width: min(360px, 92vw);
}

.quizActions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

.quizActions__buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text);
}

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

.pill__v {
  font-variant-numeric: tabular-nums;
}

.progress__text {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.progress__bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

.progress__barFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.80), rgba(5, 150, 105, 0.70));
}

.questionCard {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.70);
  padding: 12px;
}

.questionCard__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border2);
  background: rgba(255, 255, 255, 0.82);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text);
}

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

.stem {
  line-height: 1.45;
  font-size: 15px;
  padding: 6px 0 2px;
}

.md-line {
  white-space: pre-wrap;
}

.md a {
  color: var(--primary);
  text-decoration: none;
}

.md a:hover {
  text-decoration: underline;
}

.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.92em;
  padding: 0.12em 0.35em;
  border-radius: 8px;
  border: 1px solid var(--code-border);
  background: var(--code-bg);
}

.md-pre {
  margin: 8px 0;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--code-border);
  background: rgba(255, 255, 255, 0.85);
  overflow: auto;
}

.md pre code {
  display: block;
  white-space: pre;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 13px;
  line-height: 1.45;
}

.hl {
  color: #0f172a;
}

.hl-keyword {
  color: #7c3aed;
  font-weight: 650;
}

.hl-type {
  color: #0f766e;
}

.hl-func {
  color: #1d4ed8;
}

.hl-number {
  color: #b45309;
}

.hl-string {
  color: #047857;
}

.hl-comment {
  color: rgba(15, 23, 42, 0.55);
  font-style: italic;
}

.hl-preproc {
  color: #be123c;
}

.hl-op {
  color: rgba(15, 23, 42, 0.75);
}

.hl-punc {
  color: rgba(15, 23, 42, 0.72);
}

.md pre code::before {
  content: attr(class);
  display: none;
}

.md img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin: 10px 0;
}

.md-math {
  font-family: ui-serif, "Times New Roman", Times, serif;
  letter-spacing: 0.2px;
}

.tex-frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
  vertical-align: middle;
  margin: 0 1px;
}

.tex-frac__num,
.tex-frac__den {
  font-size: 0.86em;
  padding: 0 2px;
}

.tex-frac__bar {
  width: 100%;
  border-top: 1px solid rgba(15, 23, 42, 0.55);
  margin: 2px 0;
}

.tex-script {
  display: inline-flex;
  align-items: flex-start;
  vertical-align: middle;
}

.tex-script__base {
  display: inline-block;
}

.tex-script__sup {
  font-size: 0.72em;
  line-height: 1;
  margin-left: 1px;
  transform: translateY(-0.35em);
}

.tex-script__sub {
  font-size: 0.72em;
  line-height: 1;
  margin-left: 1px;
  transform: translateY(0.35em);
}

.tex-group {
  display: inline;
}

.tex-text {
  display: inline;
}

.tex-text--mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.95em;
  padding: 0 2px;
}

.options {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.option {
  display: inline-grid;
  grid-template-columns: 18px auto;
  align-items: flex-start;
  gap: 8px;
  border-radius: 12px;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.92);
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  width: fit-content;
  max-width: 100%;
}

.option:hover {
  border-color: rgba(37, 99, 235, 0.45);
}

.option__text {
  white-space: pre-wrap;
  line-height: 1.42;
  text-align: left;
  overflow-wrap: anywhere;
}

.option__marker {
  width: 18px;
  height: 18px;
  border-radius: 0;
  border: 0;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  font-size: 13px;
  font-weight: 750;
  color: rgba(15, 23, 42, 0.75);
  user-select: none;
}

.option--selected {
  border-color: rgba(37, 99, 235, 0.60);
  background: rgba(37, 99, 235, 0.10);
}

.option--correct {
  border-color: rgba(5, 150, 105, 0.60);
  background: var(--ok-bg);
}

.option--wrong {
  border-color: rgba(220, 38, 38, 0.60);
  background: var(--danger-bg);
}

.questionCard__actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.result {
  margin-top: 10px;
  line-height: 1.42;
}

.footerRow {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.sheet {
  margin-top: 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.70);
  padding: 10px;
}

.sheet--hidden {
  display: none;
}

.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.sheet__title {
  font-weight: 700;
  font-size: 13px;
}

.sheet__legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.legendItem {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid var(--border2);
  background: rgba(15, 23, 42, 0.04);
}

.dot--unanswered {
  background: rgba(15, 23, 42, 0.06);
}

.dot--answered {
  background: rgba(37, 99, 235, 0.20);
  border-color: rgba(37, 99, 235, 0.35);
}

.dot--correct {
  background: rgba(5, 150, 105, 0.20);
  border-color: rgba(5, 150, 105, 0.45);
}

.dot--wrong {
  background: rgba(220, 38, 38, 0.20);
  border-color: rgba(220, 38, 38, 0.45);
}

.dot--current {
  background: rgba(217, 119, 6, 0.18);
  border-color: rgba(217, 119, 6, 0.40);
}

.sheet__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 10px;
}

.sheetItem {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.90);
  color: var(--text);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.sheetItem:hover {
  border-color: rgba(37, 99, 235, 0.45);
}

.sheetItem--answered {
  border-color: rgba(37, 99, 235, 0.55);
  background: rgba(37, 99, 235, 0.10);
}

.sheetItem--correct {
  border-color: rgba(5, 150, 105, 0.55);
  background: var(--ok-bg);
}

.sheetItem--wrong {
  border-color: rgba(220, 38, 38, 0.55);
  background: var(--danger-bg);
}

.sheetItem--current {
  outline: 3px solid rgba(217, 119, 6, 0.16);
  border-color: rgba(217, 119, 6, 0.50);
}

.jump {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

/* ========================
   移动端适配 - 竖排 + 大字体
   ======================== */

@media (max-width: 700px) {
  .container {
    padding: 10px 8px 40px;
  }
  .fence-top {
    height: 5px;
  }
  .appLayout {
    gap: 10px;
  }
  .picker__col {
    min-width: 100%;
  }
  .picker__col--actions {
    min-width: 100%;
  }
  .picker__row {
    gap: 10px;
  }
  .label {
    font-size: 14px;
  }
  .input--select {
    font-size: 15px;
    padding: 14px;
  }
  .sidebarPanel {
    min-height: 0;
  }
  .sidebar {
    max-height: none;
    overflow: visible;
  }
  body.sidebar-collapsed .sidebar {
    max-height: 0;
    overflow: hidden;
  }
  .quizHeader {
    flex-direction: column;
    gap: 10px;
  }
  .quizHeader__left,
  .quizHeader__right {
    width: 100%;
  }
  .quizTitle {
    font-size: 18px;
  }
  .quizSubTitle {
    font-size: 14px;
  }
  .progress {
    width: 100%;
  }
  .progress__text {
    font-size: 14px;
  }
  .progress__bar {
    height: 14px;
  }
  .quizActions {
    justify-content: flex-start;
    width: 100%;
  }
  .quizActions__buttons {
    width: 100%;
  }
  .quizActions__buttons .btn {
    flex: 1;
    text-align: center;
    font-size: 14px;
    padding: 12px 10px;
  }
  .stats {
    width: 100%;
    justify-content: flex-start;
  }
  .pill {
    font-size: 13px;
    padding: 8px 12px;
  }
  .questionCard {
    padding: 14px;
  }
  .badge {
    font-size: 13px;
    padding: 8px 12px;
  }
  .stem {
    font-size: 17px;
    line-height: 1.6;
  }
  .option {
    padding: 12px 14px;
    font-size: 16px;
    gap: 10px;
    border-radius: 14px;
    width: 100%;
    max-width: 100%;
  }
  .option__marker {
    width: 22px;
    height: 22px;
    font-size: 16px;
  }
  .questionCard__actions .btn {
    flex: 1;
    text-align: center;
    font-size: 14px;
    padding: 12px 10px;
  }
  .footerRow {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .jump {
    justify-content: center;
  }
  .jump .label {
    font-size: 14px;
  }
  .jump .input--small {
    width: 80px;
    font-size: 15px;
    padding: 10px;
  }
  .jump .btn {
    font-size: 14px;
    padding: 10px 14px;
  }
  .sheet__grid {
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 8px;
  }
  .sheetItem {
    height: 42px;
    font-size: 15px;
    border-radius: 10px;
  }
  .home-btn {
    top: 6px;
    left: 6px;
    padding: 6px 12px;
    font-size: 11px;
    z-index: 100000;
  }
  .topbar__inner {
    padding: 12px 14px;
  }
  .brand {
    font-size: 18px;
  }
  .topbar__onlyWhenCollapsed {
    font-size: 14px;
    padding: 8px 12px;
  }
  .muted {
    font-size: 14px;
  }
  #autosaveHint {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .fence-top {
    height: 4px;
  }
  .topbar__inner {
    padding: 10px 12px;
  }
  .brand {
    font-size: 16px;
  }
  .panel {
    padding: 12px;
  }
  .panel__title {
    font-size: 17px;
  }
  .input--select {
    font-size: 14px;
    padding: 12px;
  }
  .questionCard {
    padding: 12px;
  }
  .quizTitle {
    font-size: 16px;
  }
  .quizSubTitle {
    font-size: 13px;
  }
  .stem {
    font-size: 16px;
  }
  .option {
    font-size: 15px;
    padding: 10px 12px;
  }
  .option__marker {
    width: 20px;
    height: 20px;
    font-size: 15px;
  }
  .badge {
    font-size: 12px;
    padding: 6px 10px;
  }
  .pill {
    font-size: 12px;
    padding: 6px 10px;
  }
  .btn {
    padding: 10px 12px;
    font-size: 13px;
  }
  .quizActions__buttons .btn {
    font-size: 13px;
    padding: 10px 8px;
  }
  .questionCard__actions .btn {
    font-size: 13px;
    padding: 10px 8px;
  }
  .sheet__grid {
    grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
    gap: 6px;
  }
  .sheetItem {
    height: 38px;
    font-size: 14px;
    border-radius: 8px;
  }
  .home-btn {
    padding: 5px 10px;
    font-size: 10px;
  }
  .muted {
    font-size: 13px;
  }
}

/* ========================
   手机横屏适配 - 跟随系统横屏
   ======================== */
@media (orientation: landscape) and (max-height: 600px) {
  html, body { height: auto; min-height: 100%; }
  .container {
    padding: 6px 6px 24px;
  }
  .appLayout {
    grid-template-columns: 220px 1fr;
    gap: 6px;
  }
  .topbar {
    position: static;
  }
  .topbar__inner {
    padding: 6px 10px;
  }
  .brand {
    font-size: 14px;
  }
  .topbar__onlyWhenCollapsed {
    font-size: 11px;
    padding: 4px 8px;
  }
  .sidebar {
    position: sticky;
    top: 4px;
    max-height: calc(100vh - 50px);
    overflow: auto;
  }
  .sidebarPanel {
    min-height: auto;
    padding: 8px;
  }
  .panel {
    padding: 8px;
    margin-bottom: 6px;
    border-radius: 10px;
  }
  .panel__title {
    font-size: 13px;
    margin-bottom: 8px;
  }
  .picker__col {
    min-width: 100%;
  }
  .picker__row {
    gap: 4px;
  }
  .label {
    font-size: 11px;
    margin-bottom: 3px;
  }
  .input--select {
    font-size: 12px;
    padding: 8px 10px;
    border-radius: 8px;
  }
  .quizHeader {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }
  .quizTitle {
    font-size: 14px;
  }
  .quizSubTitle {
    font-size: 11px;
  }
  .progress {
    width: auto;
    min-width: 140px;
  }
  .progress__text {
    font-size: 11px;
  }
  .progress__bar {
    height: 8px;
  }
  .quizActions {
    margin-top: 4px;
  }
  .quizActions__buttons .btn {
    font-size: 11px;
    padding: 6px 10px;
  }
  .stats {
    gap: 4px;
  }
  .pill {
    font-size: 11px;
    padding: 4px 8px;
  }
  .stem {
    font-size: 14px;
    line-height: 1.5;
  }
  .option {
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 10px;
    width: fit-content;
    max-width: 100%;
  }
  .option__marker {
    width: 18px;
    height: 18px;
    font-size: 13px;
  }
  .questionCard {
    padding: 8px;
  }
  .questionCard__actions .btn {
    padding: 6px 10px;
    font-size: 12px;
  }
  .badge {
    font-size: 11px;
    padding: 4px 8px;
  }
  .sheet__grid {
    grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
    gap: 4px;
  }
  .sheetItem {
    height: 28px;
    font-size: 11px;
    border-radius: 6px;
  }
  .footerRow {
    flex-direction: row;
    gap: 6px;
  }
  .jump .input--small {
    width: 60px;
    font-size: 12px;
    padding: 6px;
  }
  .jump .btn {
    font-size: 11px;
    padding: 6px 10px;
  }
  .muted {
    font-size: 11px;
  }
  #autosaveHint {
    font-size: 11px;
  }
  .home-btn {
    top: 4px;
    left: 4px;
    padding: 3px 6px;
    font-size: 8px;
    z-index: 100000;
  }
  .home-btn:hover {
    transform: none;
  }
}
