:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #eef2f7;
  --ink: #17202e;
  --muted: #607089;
  --line: #d8e0ea;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #d9f3ee;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --ok: #137333;
  --ok-soft: #e3f3e8;
  --warn: #8a5200;
  --warn-soft: #fff2d7;
  --shadow: 0 18px 50px rgba(22, 34, 51, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
select,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 7px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  background: var(--panel-soft);
  color: var(--ink);
}

button.secondary:hover {
  background: #dde6f0;
}

button.ghost {
  background: transparent;
  color: var(--accent-strong);
}

button.danger {
  background: var(--danger);
}

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

.app {
  min-height: 100vh;
}

.shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

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

.brand h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

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

.stat strong {
  display: block;
  font-size: 1.25rem;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.83rem;
  margin-top: 3px;
}

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  align-items: start;
}

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

.controls {
  position: sticky;
  top: 12px;
  padding: 14px;
}

.control-group {
  display: grid;
  gap: 9px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.control-group:last-child {
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}

.control-group h2,
.section-title {
  margin: 0;
  font-size: 0.92rem;
  letter-spacing: 0;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 4px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.segmented button {
  min-height: 38px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(22, 34, 51, 0.12);
}

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

select,
input[type="text"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 11px;
}

.actions {
  display: grid;
  gap: 8px;
}

.content {
  display: grid;
  gap: 14px;
}

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

.mode-card,
.summary-card,
.question-card,
.review-card {
  padding: 16px;
}

.mode-card {
  display: grid;
  gap: 12px;
  align-content: start;
}

.mode-card h2 {
  margin: 0;
  font-size: 1.08rem;
}

.mode-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.topic-list {
  display: grid;
  gap: 8px;
  max-height: 380px;
  overflow: auto;
  padding-right: 2px;
}

.topic-button {
  text-align: left;
  min-height: 0;
  padding: 11px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 650;
}

.topic-button:hover,
.topic-button.active {
  background: var(--accent-soft);
  border-color: #95d8cf;
  color: var(--accent-strong);
}

.topic-button span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 4px;
  font-weight: 600;
}

.attempt-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  gap: 10px;
  padding: 12px 0;
  background: var(--bg);
}

.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.progress-bar div {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 160ms ease;
}

.attempt-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.pill.bad {
  background: var(--danger-soft);
  color: var(--danger);
}

.question-card {
  display: grid;
  gap: 14px;
}

.question-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.question-title {
  margin: 0;
  font-size: 1.05rem;
}

.stem {
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 1rem;
}

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

.option {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: start;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  line-height: 1.45;
  cursor: pointer;
}

.option input {
  margin-top: 3px;
}

.option.correct {
  border-color: #79c991;
  background: var(--ok-soft);
}

.option.wrong {
  border-color: #ee9b94;
  background: var(--danger-soft);
}

.answer-grid {
  display: grid;
  gap: 9px;
}

.answer-row {
  display: grid;
  grid-template-columns: minmax(100px, 1fr) minmax(120px, 1fr);
  gap: 8px;
  align-items: center;
}

.feedback {
  border-radius: 8px;
  padding: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.feedback.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.feedback.bad {
  background: var(--danger-soft);
  color: var(--danger);
}

.feedback.neutral {
  background: var(--panel-soft);
  color: var(--ink);
}

.pdf-source {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.pdf-source summary {
  min-height: 44px;
  padding: 12px 13px;
  color: var(--accent-strong);
  font-weight: 800;
  cursor: pointer;
}

.pdf-pages {
  display: grid;
  gap: 12px;
  padding: 0 12px 12px;
}

.pdf-pages a {
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--panel-soft);
}

.pdf-pages img {
  display: block;
  width: 100%;
  height: auto;
}

.question-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

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

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

.review-card {
  display: grid;
  gap: 10px;
}

.review-card h3 {
  margin: 0;
  font-size: 1rem;
}

.answer-line {
  font-weight: 800;
}

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

@media (max-width: 860px) {
  .shell {
    padding: 12px;
  }

  .layout,
  .home-grid {
    grid-template-columns: 1fr;
  }

  .controls {
    position: static;
  }

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

@media (max-width: 520px) {
  .brand {
    display: grid;
  }

  .brand h1 {
    font-size: 1.25rem;
  }

  .stats-row,
  .summary-grid,
  .question-actions,
  .answer-row {
    grid-template-columns: 1fr;
  }

  .attempt-header {
    padding-top: 8px;
  }
}
