:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #f0f3f6;
  --text: #1f2933;
  --muted: #64727f;
  --line: #d8dee5;
  --accent: #176b5b;
  --accent-strong: #115345;
  --blue: #285fba;
  --red: #b53b3b;
  --green-soft: #e5f4ef;
  --red-soft: #f8e7e7;
  --shadow: 0 18px 45px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 20px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.title-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.83rem;
  font-weight: 700;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 3rem);
  line-height: 1.05;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 10px;
  min-width: min(390px, 100%);
}

.stat {
  display: flex;
  min-height: 74px;
  flex-direction: column;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 10px 12px;
}

.stat span {
  font-size: 1.7rem;
  font-weight: 800;
}

.stat small {
  color: var(--muted);
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 44px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0 18px;
  font-weight: 800;
}

.tab:hover,
.tab:focus-visible {
  color: var(--text);
}

.tab.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

.notice,
.toolbar,
.detail-panel,
.question-list-panel,
.feedback,
.results-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

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

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1.3fr) minmax(190px, 0.9fr) minmax(150px, 0.65fr) auto;
  align-items: end;
  gap: 14px;
  padding: 16px;
  margin-bottom: 16px;
}

#testView .toolbar {
  grid-template-columns: minmax(130px, 0.5fr) minmax(220px, 1fr) minmax(150px, 0.65fr) minmax(150px, 0.65fr) auto;
}

.field {
  min-width: 0;
}

.field label,
.checkline {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.field label {
  display: block;
  margin-bottom: 6px;
}

.field input,
.field select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  outline: 0;
}

.field input:focus,
.field select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 95, 186, 0.16);
}

.checkline {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}

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

.content-grid {
  display: grid;
  grid-template-columns: minmax(260px, 390px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.question-list-panel {
  overflow: hidden;
}

.list-head {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.list-head span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.question-list {
  max-height: calc(100vh - 310px);
  min-height: 360px;
  overflow: auto;
}

.question-row {
  display: grid;
  width: 100%;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  min-height: 76px;
  align-items: center;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  padding: 10px 12px;
  text-align: left;
}

.question-row:hover,
.question-row:focus-visible {
  background: #f4f8fb;
}

.question-row.is-active {
  background: var(--green-soft);
}

.question-number {
  display: inline-flex;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.question-row.is-active .question-number {
  background: var(--accent);
  color: #fff;
}

.question-summary {
  min-width: 0;
}

.question-summary strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 0.96rem;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.question-summary span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-panel {
  min-height: 420px;
  padding: 22px;
}

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

.pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  padding: 3px 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

.pill.is-open {
  border-color: #c8d7f5;
  background: #eaf1ff;
  color: var(--blue);
}

.question-title {
  margin: 0 0 18px;
  font-size: clamp(1.35rem, 2.1vw, 2.1rem);
  line-height: 1.2;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.browse-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 18px;
}

.browse-position {
  min-width: 84px;
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

.section-title {
  margin: 22px 0 9px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 900;
  text-transform: uppercase;
}

.options-list,
.answer-pick-list {
  display: grid;
  gap: 10px;
}

.answer-option,
.pick-option {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.answer-option.is-correct,
.pick-option.is-correct {
  border-color: #8bc6b3;
  background: var(--green-soft);
}

.answer-option.is-wrong,
.pick-option.is-wrong {
  border-color: #e0a1a1;
  background: var(--red-soft);
}

.option-letter {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--muted);
  font-weight: 900;
}

.option-text,
.explanation,
.correct-answer,
.open-user-answer {
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.answer-badge {
  align-self: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  padding: 4px 9px;
  font-size: 0.76rem;
  font-weight: 900;
}

.empty-state {
  color: var(--muted);
  font-weight: 700;
}

.primary-action,
.secondary-action,
.self-grade button {
  min-height: 44px;
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 900;
}

.primary-action {
  background: var(--accent);
  color: #fff;
}

.primary-action:hover,
.primary-action:focus-visible {
  background: var(--accent-strong);
}

.secondary-action,
.self-grade button {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.secondary-action:hover,
.secondary-action:focus-visible,
.self-grade button:hover,
.self-grade button:focus-visible {
  border-color: var(--blue);
}

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

.test-runner,
.results-panel {
  display: grid;
  gap: 14px;
}

.test-status {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.test-status > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-weight: 800;
}

.test-status strong {
  color: var(--text);
}

.progress {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.pick-option {
  cursor: pointer;
  grid-template-columns: auto 34px minmax(0, 1fr);
}

.pick-option input {
  width: 18px;
  height: 18px;
  margin-top: 5px;
  accent-color: var(--accent);
}

.pick-option:has(input:checked) {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 95, 186, 0.12);
}

.feedback {
  padding: 16px;
}

.feedback.is-correct {
  border-color: #8bc6b3;
  background: var(--green-soft);
}

.feedback.is-wrong {
  border-color: #e0a1a1;
  background: var(--red-soft);
}

.feedback.is-neutral {
  background: #fffaf0;
}

.feedback-title {
  margin: 0 0 10px;
  font-size: 1.08rem;
  font-weight: 900;
}

.test-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.self-grade {
  display: inline-flex;
  gap: 8px;
}

.open-user-answer {
  min-height: 150px;
  resize: vertical;
}

.results-panel {
  padding: 22px;
}

.results-panel h2 {
  margin: 0;
  font-size: clamp(1.45rem, 2.3vw, 2.2rem);
}

.result-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(100px, 1fr));
  gap: 10px;
}

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

.metric strong {
  display: block;
  font-size: 1.6rem;
}

.wrong-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

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

.wrong-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.wrong-item span {
  color: var(--muted);
  font-size: 0.86rem;
}

.question-image {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
}

@media (max-width: 960px) {
  .topbar {
    flex-direction: column;
  }

  .stats {
    min-width: 0;
  }

  .toolbar,
  #testView .toolbar,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .question-list {
    max-height: 360px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .toolbar,
  .detail-panel,
  .results-panel {
    padding: 16px;
  }

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

  .tabs {
    overflow-x: auto;
  }

  .question-row,
  .answer-option {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .answer-badge {
    grid-column: 2;
    justify-self: start;
  }

  .pick-option {
    grid-template-columns: auto 30px minmax(0, 1fr);
  }

  .test-status > div:first-child {
    flex-direction: column;
    gap: 4px;
  }
}
