:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #182230;
  --muted: #667085;
  --line: #d9e2ec;
  --accent: #1677c8;
  --accent-dark: #0f5d9d;
  --good: #138a4b;
  --bad: #b42318;
  --warn: #b76e00;
  --shadow: 0 18px 45px rgba(24, 34, 48, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
}

button,
input,
.bug-link {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #fbfdff;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
}

.brand h1,
.topbar h2 {
  margin: 0;
  line-height: 1.1;
}

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

.brand p,
.eyebrow,
.study-note,
.field span,
.stats-grid span {
  color: var(--muted);
}

.brand p {
  margin: 4px 0 0;
  font-size: 13px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stats-grid div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 10px;
}

.stats-grid strong {
  display: block;
  font-size: 20px;
}

.stats-grid span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
}

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

#progressBar {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.controls,
.filter-row,
.top-actions,
.question-toolbar,
.status-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: #fff;
}

.primary,
.secondary,
.ghost,
.chip,
.status,
.icon-button,
.bug-link {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 700;
}

.bug-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}

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

.primary:hover {
  background: var(--accent-dark);
}

.secondary {
  color: var(--accent-dark);
  background: #eaf4ff;
}

.ghost,
.chip {
  color: var(--text);
  background: #eef3f8;
}

.chip.active {
  color: #fff;
  background: #344054;
}

.question-list {
  display: grid;
  gap: 6px;
  overflow: auto;
  padding-right: 4px;
}

.question-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 10px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.question-item:hover,
.question-item.active {
  background: #eaf4ff;
}

.question-item span:last-child {
  min-width: 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #b8c4d2;
}

.question-item.correct span:last-child {
  background: var(--good);
}

.question-item.wrong span:last-child {
  background: var(--bad);
}

.question-item.review span:last-child {
  background: var(--warn);
}

.question-item.needs-correction {
  border-left: 3px solid #d0d7e2;
}

.question-item.has-correction span:first-child::after {
  content: " corr.";
  margin-left: 5px;
  color: var(--good);
  font-size: 11px;
  font-weight: 700;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

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

.icon-button {
  display: none;
  padding: 0 12px;
  background: #eaf4ff;
  color: var(--accent-dark);
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.trainer-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.question-toolbar {
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.status {
  color: #344054;
  background: #f0f3f7;
}

.status.correct.active,
.status.correct:hover {
  color: #fff;
  background: var(--good);
}

.status.wrong.active,
.status.wrong:hover {
  color: #fff;
  background: var(--bad);
}

.status.review.active,
.status.review:hover {
  color: #fff;
  background: var(--warn);
}

.question-card {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
}

.question-prompt p,
.question-context p {
  margin: 0 0 10px;
  font-size: 18px;
  line-height: 1.45;
}

.question-prompt p:last-child,
.question-context p:last-child {
  margin-bottom: 0;
}

.question-context {
  border-left: 4px solid #cfe7ff;
  padding-left: 14px;
}

.question-detail-list {
  display: grid;
  gap: 8px;
}

.question-detail-list span {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfdff;
  line-height: 1.35;
}

.inline-yesno-list {
  display: grid;
  border-top: 1px solid var(--line);
}

.inline-yesno-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.inline-yesno-row p {
  margin: 0;
  font-size: 16px;
  font-weight: 750;
  line-height: 1.4;
}

.inline-yesno-actions {
  display: grid;
  grid-template-columns: repeat(2, 62px);
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f8;
}

.inline-yn-button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.inline-yn-button.active {
  color: #fff;
}

.inline-yn-button.active.yes {
  background: #15803d;
}

.inline-yn-button.active.no {
  background: #b42318;
}

.image-frame {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  max-height: calc(100vh - 210px);
  margin-bottom: 14px;
}

.question-mask {
  overflow: hidden;
  width: fit-content;
  max-width: 100%;
  transition: max-height 180ms ease;
}

.question-mask.revealed {
  max-height: none !important;
}

#questionImage {
  display: block;
  width: min(100%, var(--image-width, 900px));
  height: auto;
}

.study-note {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
  font-size: 13px;
}

.answer-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdff;
}

.answer-head,
.correction-actions,
.manual-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.answer-head h3 {
  margin: 0;
  font-size: 18px;
}

.correction-state {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.answer-controls {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.letter-grid,
.choice-grid {
  display: grid;
  gap: 8px;
}

.letter-grid {
  grid-template-columns: repeat(6, minmax(44px, 1fr));
}

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

.letter-button,
.yn-button,
.choice-card,
.option-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
}

.letter-button.active,
.yn-button.active,
.choice-card.active,
.option-button.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.choice-card,
.option-button {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 10px 12px;
  text-align: left;
}

.choice-letter,
.option-letter {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #eaf4ff;
  color: var(--accent-dark);
  font-weight: 900;
}

.choice-card.active .choice-letter,
.option-button.active .option-letter {
  color: var(--accent-dark);
  background: #fff;
}

.choice-label,
.option-button span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.answer-textarea,
.answer-input,
.slot-select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  background: #fff;
}

.answer-textarea {
  min-height: 94px;
  resize: vertical;
}

.yesno-grid {
  display: grid;
  gap: 8px;
}

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

.slot-grid {
  display: grid;
  gap: 10px;
}

.slot-row {
  display: grid;
  grid-template-columns: minmax(150px, 0.9fr) minmax(0, 1.1fr);
  gap: 10px;
  align-items: center;
}

.slot-label {
  color: var(--muted);
  font-weight: 800;
  line-height: 1.25;
}

.slot-select {
  min-height: 42px;
  appearance: auto;
}

.choice-empty {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.yesno-row {
  display: grid;
  grid-template-columns: 90px 1fr 1fr;
  gap: 8px;
  align-items: center;
}

.yesno-row span {
  color: var(--muted);
  font-weight: 700;
}

.correction-actions {
  justify-content: flex-start;
  margin-top: 12px;
}

.correction-actions .status {
  min-height: 38px;
}

.result-panel {
  margin-top: 12px;
  border-radius: 8px;
  padding: 12px;
  line-height: 1.45;
  background: #eef3f8;
}

.result-panel.good {
  color: #075e34;
  background: #e7f6ee;
}

.result-panel.bad {
  color: #8a1f14;
  background: #fff0ee;
}

.result-panel.warn {
  color: #704700;
  background: #fff7df;
}

.correction-text {
  margin-top: 8px;
  white-space: pre-wrap;
  color: var(--muted);
  font-size: 13px;
}

.expected-answer {
  margin-top: 6px;
}

.source-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.source-note.low-confidence {
  color: var(--warn);
  font-weight: 700;
}

.exam-summary {
  gap: 18px;
}

.exam-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #f7fbff;
}

.exam-result span {
  align-self: center;
  font-size: 18px;
  font-weight: 900;
}

.exam-result strong {
  font-size: clamp(48px, 8vw, 78px);
  line-height: 0.9;
}

.exam-result em {
  margin-bottom: 7px;
  color: var(--muted);
  font-style: normal;
  font-weight: 800;
}

.exam-result.passed {
  border-color: #a5d6bb;
  background: #e7f6ee;
  color: #075e34;
}

.exam-result.failed {
  border-color: #f0b8b2;
  background: #fff0ee;
  color: #8a1f14;
}

.exam-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.exam-metrics div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.exam-metrics strong {
  display: block;
  font-size: 22px;
}

.exam-metrics span,
.exam-note,
.exam-clean {
  color: var(--muted);
  line-height: 1.45;
}

.exam-note,
.exam-clean {
  margin: 0;
}

.exam-review-list {
  display: grid;
  gap: 8px;
}

.exam-review-list h3 {
  margin: 0 0 2px;
  font-size: 18px;
}

.exam-review-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: #fff;
  text-align: left;
}

.exam-review-item:hover {
  border-color: #9fcdf4;
  background: #f3f9ff;
}

.exam-review-item span {
  overflow-wrap: anywhere;
}

.exam-review-item b {
  color: var(--bad);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 10;
    width: min(88vw, 340px);
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .workspace {
    padding: 10px 10px 86px;
  }

  .icon-button {
    display: inline-grid;
    place-items: center;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 6;
    margin: 0 -10px 10px;
    padding: 10px;
    align-items: flex-start;
    background: var(--bg);
  }

  .top-actions {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 8;
    width: 100%;
    padding: 10px;
    border-top: 1px solid var(--line);
    background: #fff;
    box-shadow: 0 -10px 30px rgba(24, 34, 48, 0.1);
  }

  .top-actions button {
    flex: 1;
  }

  .trainer-panel {
    border-radius: 8px;
    padding: 12px;
    box-shadow: none;
  }

  .question-toolbar {
    display: grid;
    gap: 10px;
  }

  .status-buttons,
  .question-toolbar .secondary,
  .correction-actions {
    width: 100%;
  }

  .status-buttons button,
  .correction-actions button,
  .question-toolbar .secondary {
    flex: 1;
  }

  .image-frame {
    max-height: 56vh;
  }

  .question-card {
    padding: 14px;
  }

  .question-prompt p,
  .question-context p {
    font-size: 16px;
  }

  .study-note {
    display: grid;
  }

  .choice-grid,
  .option-grid {
    grid-template-columns: 1fr;
  }

  .inline-yesno-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .inline-yesno-actions {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .letter-grid {
    grid-template-columns: repeat(3, minmax(44px, 1fr));
  }

  .yesno-row {
    grid-template-columns: 1fr 1fr;
  }

  .yesno-row span {
    grid-column: 1 / -1;
  }

  .slot-row {
    grid-template-columns: 1fr;
  }

  .answer-head {
    align-items: flex-start;
  }

  .answer-head .ghost {
    min-height: 34px;
    padding: 0 10px;
  }

  .exam-result {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .exam-result strong {
    font-size: 60px;
  }

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