:root {
  color-scheme: light;
  --bg: #f3efe6;
  --bg-accent: #dfe9df;
  --surface: #fffaf1;
  --surface-strong: #ffffff;
  --text: #17313a;
  --muted: #5e6d73;
  --border: rgba(23, 49, 58, 0.12);
  --primary: #1f6f78;
  --primary-strong: #14515a;
  --success: #1d7a4d;
  --danger: #b23b2f;
  --warning: #8d5b00;
  --shadow: 0 18px 50px rgba(24, 41, 47, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(31, 111, 120, 0.16), transparent 34%),
    radial-gradient(circle at top right, rgba(145, 119, 58, 0.18), transparent 28%),
    linear-gradient(180deg, #f7f2e8 0%, #f1ede4 45%, #e7efe8 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(23, 49, 58, 0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(23, 49, 58, 0.03) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.35), transparent 80%);
}

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: stretch;
  margin-bottom: 24px;
}

.hero__content,
.card {
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.hero__content {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: rgba(255, 250, 241, 0.78);
}

.hero__content {
  padding: clamp(24px, 4vw, 40px);
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.78rem;
  color: var(--primary-strong);
  font-weight: 700;
}

.hero h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.2rem, 5vw, 4.4rem);
  line-height: 0.96;
  letter-spacing: -0.04em;
  max-width: none;
}

.hero__text {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.7;
}

.app-grid {
  display: grid;
  gap: 24px;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: rgba(255, 250, 241, 0.9);
  padding: clamp(20px, 3vw, 32px);
}

.card--controls {
  overflow: hidden;
  transition: max-height 280ms ease, padding 220ms ease;
  max-height: 980px;
}

.card--controls.is-collapsed {
  max-height: 124px;
  padding-top: 18px;
  padding-bottom: 18px;
}

.card--controls.is-collapsed .selection-overview,
.card--controls.is-collapsed #start-quiz,
.card--controls.is-collapsed #setup-empty {
  opacity: 0;
  transform: translateY(-8px);
  max-height: 0;
  margin: 0;
  pointer-events: none;
}

.card--controls .selection-overview,
.card--controls #start-quiz,
.card--controls #setup-empty {
  transition: opacity 180ms ease, transform 180ms ease, max-height 220ms ease, margin 220ms ease;
}

.card--controls.is-collapsed .card__header {
  margin-bottom: 0;
}

.card__header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 20px;
}

.card__header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chip-button--reopen {
  display: none;
}

.card__header--stacked {
  flex-direction: column;
}

.card h2,
.report-block h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: -0.03em;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(31, 111, 120, 0.16);
  background: rgba(31, 111, 120, 0.08);
  color: var(--primary-strong);
  font-size: 0.92rem;
  font-weight: 700;
}

.status-pill--success {
  background: rgba(29, 122, 77, 0.09);
  border-color: rgba(29, 122, 77, 0.18);
  color: var(--success);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.selection-overview {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
}

.selection-overview__block {
  padding: 14px;
  border: 1px solid rgba(31, 111, 120, 0.18);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.62);
}

.selection-overview__label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.selection-overview__subject {
  margin: 0;
  color: var(--text);
  font-size: 1.04rem;
  font-weight: 700;
}

.field {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.field span {
  color: var(--text);
}

.field--topics {
  align-content: start;
}

.field-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.field-actions--modal {
  margin-top: 10px;
  margin-bottom: 10px;
}

.topic-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 46px;
  padding: 10px;
  border: 1px solid rgba(31, 111, 120, 0.24);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(255, 250, 241, 0.88));
}

.topic-summary__chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(31, 111, 120, 0.12);
  border: 1px solid rgba(31, 111, 120, 0.25);
  color: var(--primary-strong);
  font-size: 0.84rem;
  font-weight: 700;
}

.topic-summary__chip--more {
  background: rgba(141, 91, 0, 0.14);
  border-color: rgba(141, 91, 0, 0.24);
  color: #6f4b00;
}

.topic-summary__empty {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.chip-button {
  border: 1px solid rgba(31, 111, 120, 0.3);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--primary-strong);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 7px 12px;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.chip-button:hover:not(:disabled) {
  border-color: rgba(31, 111, 120, 0.6);
  background: rgba(31, 111, 120, 0.1);
}

.chip-button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.topic-multiselect {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 0;
  max-height: 280px;
  overflow: auto;
  padding: 10px;
  border: 1px solid rgba(31, 111, 120, 0.26);
  border-radius: var(--radius-md);
  background: rgba(255, 250, 241, 0.94);
}

.topic-multiselect--modal {
  max-height: min(52vh, 420px);
}

.topic-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(23, 49, 58, 0.12);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
}

.topic-option input {
  accent-color: var(--primary);
}

.field-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  min-height: 1.2em;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 30, 35, 0.48);
  backdrop-filter: blur(3px);
}

.modal__panel {
  position: relative;
  width: min(720px, calc(100% - 24px));
  max-height: min(82vh, 700px);
  overflow: auto;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(23, 49, 58, 0.14);
  background: linear-gradient(180deg, rgba(255, 250, 241, 0.98), rgba(244, 240, 232, 0.98));
  box-shadow: 0 28px 60px rgba(24, 41, 47, 0.3);
  padding: 18px;
}

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

.modal__header h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: -0.02em;
}

.modal__close {
  border: 1px solid rgba(23, 49, 58, 0.22);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.modal__close:hover {
  background: rgba(255, 255, 255, 1);
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.field select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  padding: 14px 44px 14px 16px;
  border: 1px solid rgba(31, 111, 120, 0.26);
  border-radius: var(--radius-md);
  background-color: rgba(255, 250, 241, 0.95);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='10' viewBox='0 0 14 10'%3E%3Cpath d='M1 2l6 6 6-6' fill='none' stroke='%2314515a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 14px 10px;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72), 0 6px 16px rgba(24, 41, 47, 0.06);
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

.field select:hover {
  border-color: rgba(31, 111, 120, 0.48);
  background-color: rgba(255, 250, 241, 1);
}

.field select:focus,
.field select:focus-visible {
  outline: none;
  border-color: rgba(31, 111, 120, 0.6);
  box-shadow: 0 0 0 3px rgba(31, 111, 120, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.76), 0 6px 16px rgba(24, 41, 47, 0.08);
}

.field select:disabled {
  opacity: 0.7;
  background-color: rgba(255, 255, 255, 0.82);
  cursor: not-allowed;
}

.field select option {
  background: #fffaf1;
  color: var(--text);
  font-weight: 600;
}

.button {
  border: 0;
  border-radius: 999px;
  padding: 14px 20px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

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

.button--primary {
  color: #f8fffd;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  box-shadow: 0 16px 30px rgba(31, 111, 120, 0.2);
}

.button--ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid var(--border);
}

.empty-state {
  margin-top: 18px;
  padding: 18px;
  border-radius: var(--radius-md);
  background: rgba(31, 111, 120, 0.06);
  color: var(--muted);
}

.progress-wrap {
  width: min(100%, 420px);
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.progress-bar {
  height: 12px;
  border-radius: 999px;
  background: rgba(23, 49, 58, 0.08);
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #1f6f78, #7ca989);
  transition: width 220ms ease;
}

.question-card {
  padding: 22px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(223, 233, 223, 0.28), rgba(255, 255, 255, 0.7));
  border: 1px solid rgba(23, 49, 58, 0.08);
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(31, 111, 120, 0.1);
  color: var(--primary-strong);
  font-size: 0.88rem;
  font-weight: 700;
}

.tag--soft {
  background: rgba(141, 91, 0, 0.1);
  color: var(--warning);
}

#question-text {
  margin: 0 0 18px;
  font-size: clamp(1.2rem, 2.2vw, 1.55rem);
  line-height: 1.45;
}

.options-list {
  display: grid;
  gap: 12px;
}

.option {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid rgba(23, 49, 58, 0.12);
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  border-radius: 18px;
  padding: 14px 16px;
  font: inherit;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.option:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(31, 111, 120, 0.34);
  box-shadow: 0 10px 18px rgba(24, 41, 47, 0.08);
}

.option.is-selected {
  border-color: rgba(31, 111, 120, 0.7);
  background: rgba(31, 111, 120, 0.11);
}

.option.is-correct {
  border-color: rgba(29, 122, 77, 0.55);
  background: rgba(29, 122, 77, 0.09);
}

.option.is-wrong {
  border-color: rgba(178, 59, 47, 0.56);
  background: rgba(178, 59, 47, 0.08);
}

.option:disabled {
  cursor: default;
}

.feedback-panel {
  margin-top: 18px;
  padding: 18px 20px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(23, 49, 58, 0.1);
  background: rgba(255, 255, 255, 0.74);
}

.feedback-panel__label {
  margin: 0 0 8px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.quiz-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 20px;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.result-tile {
  padding: 18px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(23, 49, 58, 0.1);
}

.result-tile span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
}

.result-tile strong {
  font-size: 1.4rem;
}

.report-block {
  padding: 18px 0 4px;
  border-top: 1px solid rgba(23, 49, 58, 0.08);
}

.report-block p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.topic-errors {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.topic-errors__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(23, 49, 58, 0.08);
}

.topic-errors__count {
  color: var(--text);
  font-size: 0.95rem;
}

.topic-errors__empty {
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px dashed rgba(23, 49, 58, 0.16);
}

.topic-chip {
  --topic-chip-text: var(--text);
  --topic-chip-bg: rgba(31, 111, 120, 0.12);
  --topic-chip-border: rgba(23, 49, 58, 0.2);
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--topic-chip-text);
  background: var(--topic-chip-bg);
  border: 1px solid var(--topic-chip-border);
}

.topic-chip--question {
  margin-bottom: 0;
}

.review-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.review-item {
  position: relative;
  padding: 16px;
  padding-right: 184px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(23, 49, 58, 0.08);
}

.review-item strong {
  display: block;
  margin-bottom: 8px;
}

.review-item__question {
  display: block;
  margin-bottom: 10px;
}

.review-item__topic {
  position: absolute;
  top: 14px;
  right: 14px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.review-item__line {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.review-item__line + .review-item__line {
  margin-top: 8px;
}

.review-item__label {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.review-item__label--correct {
  color: #0f5f3b;
  background: rgba(29, 122, 77, 0.14);
}

.review-item__label--selected {
  color: #8a4e00;
  background: rgba(141, 91, 0, 0.16);
}

.review-item__value {
  color: var(--text);
  font-weight: 500;
}

.review-item p {
  margin: 0;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .hero,
  .form-grid,
  .results-grid {
    grid-template-columns: 1fr;
  }

  .topic-multiselect {
    grid-template-columns: 1fr;
  }

  .topic-summary {
    min-height: 0;
  }

  .card__header {
    flex-direction: column;
  }

  .progress-wrap {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 12px;
  }

  .hero__content,
  .hero__panel,
  .card {
    border-radius: 22px;
  }

  .quiz-actions {
    justify-content: stretch;
  }

  .quiz-actions .button {
    width: 100%;
  }

  .review-item {
    padding-right: 16px;
  }

  .review-item__topic {
    position: static;
    display: inline-flex;
    margin-bottom: 10px;
    max-width: 100%;
    white-space: normal;
  }

  .progress-meta {
    font-size: 0.88rem;
  }

  .modal__panel {
    width: calc(100% - 12px);
    padding: 14px;
  }
}

.card--controls.is-collapsed .chip-button--reopen {
  display: inline-flex;
}