:root {
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-soft: #eef4f0;
  --text: #18201f;
  --muted: #66736f;
  --line: #d7ded9;
  --primary: #147a6c;
  --primary-dark: #0d594f;
  --primary-ink: #ffffff;
  --amber: #d99b28;
  --danger: #c94d3f;
  --ok: #14804a;
  --shadow: 0 10px 24px rgba(24, 32, 31, 0.08);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(20, 122, 108, 0.08), transparent 260px),
    var(--bg);
  color: var(--text);
}

button {
  font: inherit;
}

.app {
  width: min(100%, 780px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  margin-bottom: 12px;
  padding: 0 2px;
}

.brand {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.brand strong {
  font-size: 22px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.brand span,
.subtle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.panel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(215, 222, 217, 0.95);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.home-grid,
.bank-switch,
.bank-section,
.bank-subjects,
.quiz-shell,
.progress-wrap,
.result,
.wrong-list,
.mini-options,
.option-list,
.reference-grid {
  display: grid;
  gap: 10px;
}

.quiz-shell {
  min-height: calc(100vh - 72px);
  grid-template-rows: auto minmax(0, 1fr);
  padding-bottom: 140px;
}

.bank-switch {
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3ef;
}

.bank-tab {
  min-height: 50px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: #374440;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
}

.bank-tab strong {
  font-size: 15px;
  line-height: 1.2;
}

.bank-tab span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.bank-tab.active {
  border-color: rgba(20, 122, 108, 0.28);
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(24, 32, 31, 0.08);
}

.bank-tab.active strong {
  color: var(--primary-dark);
}

.bank-section {
  gap: 10px;
}

.bank-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 0;
}

.bank-title {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.bank-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.subject-row {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.subject-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 0.95fr);
  gap: 12px;
  align-items: center;
}

.subject-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.subject-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.stat {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: #30413c;
  font-size: 12px;
  white-space: nowrap;
}

.stat.strong {
  background: #e5f2ef;
  color: #18564d;
  font-weight: 800;
}

.question-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 8px;
}

.question-chips span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid rgba(20, 122, 108, 0.18);
  border-radius: 999px;
  background: #eef6f2;
  color: #24594f;
  font-size: 12px;
  line-height: 1;
}

.mode-row,
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quiz-action-bar {
  position: fixed;
  left: max(16px, calc((100vw - 780px) / 2 + 16px));
  right: max(16px, calc((100vw - 780px) / 2 + 16px));
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 5;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(215, 222, 217, 0.95);
  border-radius: 8px;
  background: rgba(246, 247, 242, 0.96);
  box-shadow: 0 -10px 28px rgba(24, 32, 31, 0.08);
  backdrop-filter: blur(10px);
}

.restart-btn {
  min-height: 38px;
}

.mode-row.three,
.actions.three {
  grid-template-columns: 1fr 1fr 1fr;
}

.btn {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  user-select: none;
}

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

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}

.btn.warning {
  border-color: rgba(217, 155, 40, 0.5);
  background: #fff8e8;
  color: #573c0d;
}

.btn.ghost {
  background: transparent;
}

.btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  min-height: 20px;
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: #dde4de;
  overflow: hidden;
}

.progress > span {
  display: block;
  width: var(--value, 0%);
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--amber));
}

.question {
  min-height: calc(100vh - 220px);
  padding: 16px;
  align-self: stretch;
}

.question h1 {
  margin: 0 0 12px;
  font-size: 19px;
  line-height: 1.55;
  letter-spacing: 0;
}

.reference-image {
  margin: 0;
  min-height: 190px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  overflow: hidden;
}

.reference-image img {
  width: 100%;
  max-height: 42vh;
  object-fit: contain;
}

.video-card {
  display: grid;
  gap: 10px;
  margin: 0 0 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf7;
}

.video-card video {
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 58vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101615;
}

.option {
  min-height: 54px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 8px;
  text-align: left;
  cursor: pointer;
}

.option-key,
.image-option-key {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #edf1ed;
  color: #35413e;
  font-weight: 800;
}

.option-text {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.image-option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(154px, 1fr));
  gap: 10px;
}

.image-option-grid.paired {
  grid-template-columns: repeat(auto-fit, minmax(142px, 1fr));
}

.image-option-grid.many {
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
}

.image-option {
  position: relative;
  min-height: 0;
  aspect-ratio: 4 / 3;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  display: grid;
  place-items: center;
  padding: 36px 8px 8px;
  cursor: pointer;
  overflow: hidden;
}

.image-option-grid.paired .image-option {
  aspect-ratio: 1.35 / 1;
}

.image-option-grid.many .image-option {
  aspect-ratio: 1 / 1;
}

.image-option img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
}

.image-option.mask-source-mark::after {
  content: "";
  position: absolute;
  right: 7px;
  bottom: 7px;
  width: 24%;
  height: 22%;
  border-radius: 3px;
  background: var(--option-mask-fill, #fff);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4);
  pointer-events: none;
}

.image-option-key {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  box-shadow: 0 2px 8px rgba(24, 32, 31, 0.14);
}

.option.selected,
.image-option.selected {
  border-color: var(--primary);
  background: #edf8f5;
}

.option.selected .option-key,
.image-option.selected .image-option-key {
  background: var(--primary);
  color: var(--primary-ink);
}

.option.correct,
.image-option.correct {
  border-color: rgba(20, 128, 74, 0.65);
  background: #ecf8f0;
}

.option.correct .option-key,
.image-option.correct .image-option-key {
  background: var(--ok);
  color: white;
}

.option.wrong,
.image-option.wrong {
  border-color: rgba(201, 77, 63, 0.55);
  background: #fff0ee;
}

.option.wrong .option-key,
.image-option.wrong .image-option-key {
  background: var(--danger);
  color: white;
}

.feedback {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: #24332f;
  font-size: 14px;
  line-height: 1.5;
}

.feedback.ok {
  background: #ecf8f0;
  color: #145b38;
}

.feedback.bad {
  background: #fff0ee;
  color: #8d3027;
}

.result {
  padding: 16px;
  gap: 14px;
}

.score {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
}

.score-ring {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--primary) var(--angle, 0deg), #dfe6df 0);
}

.score-ring span {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: white;
  font-weight: 800;
}

.wrong-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}

.wrong-item strong {
  display: block;
  margin-bottom: 8px;
  line-height: 1.45;
}

.wrong-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.mini-option {
  display: block;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #2f3c38;
  line-height: 1.45;
}

.mini-image-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
  margin: 8px 0 10px;
}

.mini-image-option {
  position: relative;
  display: block;
  min-height: 88px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: white;
}

.mini-image-option strong {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 24px;
  height: 24px;
  margin: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #edf1ed;
  font-size: 12px;
}

.mini-image-option img {
  width: 100%;
  height: 96px;
  object-fit: contain;
}

.mini-option.correct,
.mini-image-option.correct {
  border-color: rgba(20, 128, 74, 0.6);
  background: #ecf8f0;
}

.mini-option.wrong,
.mini-image-option.wrong {
  border-color: rgba(201, 77, 63, 0.55);
  background: #fff0ee;
}

.empty,
.loading {
  padding: 18px;
  color: var(--muted);
  line-height: 1.6;
}

.loading {
  min-height: 70vh;
  display: grid;
  place-items: center;
}

.notice-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  background: rgba(14, 21, 20, 0.46);
}

.notice-dialog {
  width: min(100%, 430px);
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid rgba(215, 222, 217, 0.96);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 44px rgba(24, 32, 31, 0.22);
}

.notice-dialog h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.25;
}

.notice-dialog p {
  margin: 0;
  color: #35413e;
  font-size: 15px;
  line-height: 1.65;
}

.notice-check {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.notice-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.notice-actions {
  display: grid;
}

@media (max-width: 540px) {
  .app {
    padding-left: 12px;
    padding-right: 12px;
  }

  .quiz-shell {
    padding-bottom: 136px;
  }

  .quiz-action-bar {
    left: 12px;
    right: 12px;
  }

  .brand strong {
    font-size: 20px;
  }

  .mode-row,
  .mode-row.three {
    grid-template-columns: 1fr;
  }

  .actions,
  .actions.three {
    grid-template-columns: 1fr 1fr;
  }

  .actions.three {
    grid-template-columns: 1fr 1fr 1fr;
  }

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

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

  .bank-tab {
    min-height: 48px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 2px;
    padding: 7px 8px;
  }

  .bank-tab strong {
    font-size: 14px;
  }

  .subject-main {
    grid-template-columns: 1fr;
  }

  .subject-main .mode-row.three {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .subject-main .btn {
    min-height: 40px;
    padding: 0 8px;
  }

  .question {
    padding: 14px;
    min-height: calc(100vh - 206px);
  }

  .question h1 {
    font-size: 18px;
  }

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

  .image-option-grid.many {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .image-option {
    padding: 34px 6px 8px;
  }

  .image-option img {
    height: 100%;
  }

  .reference-image {
    min-height: 160px;
  }
}
