:root {
  color-scheme: light;
  --navy: #102a43;
  --navy-2: #183f5f;
  --ink: #172b3a;
  --muted: #60768a;
  --line: #d8e4ec;
  --surface: #ffffff;
  --canvas: #f3f7fa;
  --teal: #0f9f8f;
  --teal-bright: #2dd4bf;
  --teal-soft: #e6f8f5;
  --coral: #ef6b5b;
  --coral-soft: #fff0ee;
  --amber: #e7a51a;
  --shadow: 0 18px 55px rgba(16, 42, 67, .11);
  --radius: 22px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--canvas); }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 9% 8%, rgba(45, 212, 191, .12), transparent 24rem),
    linear-gradient(180deg, #f8fbfd 0, var(--canvas) 28rem);
}

button, input { font: inherit; }
button { color: inherit; }

.topbar {
  min-height: 76px;
  padding: 12px clamp(18px, 4vw, 60px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  background: rgba(255, 255, 255, .9);
  border-bottom: 1px solid rgba(216, 228, 236, .85);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  border: 0;
  background: transparent;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  cursor: pointer;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--navy);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 22px rgba(16, 42, 67, .2);
}

.brand-mark svg { width: 32px; height: 32px; }
.brand-mark svg path:first-child { fill: var(--teal-bright); }
.brand-mark svg path:last-child { fill: none; stroke: white; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.brand strong, .brand small { display: block; }
.brand strong { color: var(--navy); font-size: 1.02rem; letter-spacing: -.01em; }
.brand small { color: var(--muted); margin-top: 1px; }

.top-stats { display: flex; align-items: center; gap: 18px; color: var(--muted); font-size: .9rem; }
.top-stats span + span { border-left: 1px solid var(--line); padding-left: 18px; }
.top-stats strong { color: var(--navy); }

#app { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 42px 0 64px; }
#app:focus { outline: none; }

.loading-card, .panel {
  background: var(--surface);
  border: 1px solid rgba(216, 228, 236, .9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.loading-card { min-height: 360px; display: grid; place-items: center; align-content: center; gap: 16px; color: var(--muted); }
.loading-orbit { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.setup-grid { display: grid; grid-template-columns: minmax(0, .86fr) minmax(430px, 1.14fr); gap: 22px; align-items: start; }
.panel { padding: clamp(22px, 3.5vw, 38px); }

.eyebrow { margin: 0 0 10px; color: var(--teal); font-size: .78rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 14px; color: var(--navy); font-size: clamp(2rem, 4vw, 3.6rem); line-height: 1.02; letter-spacing: -.045em; }
h2 { color: var(--navy); font-size: clamp(1.35rem, 2.3vw, 1.8rem); letter-spacing: -.025em; }
.lead { color: var(--muted); font-size: 1.05rem; line-height: 1.65; max-width: 48ch; }

.catalogue-band {
  margin: 28px 0;
  padding: 18px;
  border-radius: 18px;
  color: #dffaf6;
  background: linear-gradient(135deg, var(--navy), #174a67);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.catalogue-band strong { display: block; color: white; font-size: 1.65rem; line-height: 1; margin-bottom: 6px; }
.catalogue-band span { font-size: .86rem; opacity: .82; }

.field-group { margin-top: 24px; }
.field-label { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; color: var(--navy); font-size: .92rem; font-weight: 750; }
.field-hint { color: var(--muted); font-weight: 500; }
.choice-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.choice-chip {
  border: 1px solid var(--line);
  background: #f9fbfc;
  min-height: 44px;
  border-radius: 12px;
  font-weight: 750;
  cursor: pointer;
  transition: .16s ease;
}
.choice-chip:hover { border-color: #96b5c5; transform: translateY(-1px); }
.choice-chip.is-active { background: var(--navy); color: white; border-color: var(--navy); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 22px; }
.switch { width: 52px; height: 30px; border: 0; padding: 3px; border-radius: 20px; background: #b7c8d3; cursor: pointer; transition: .2s; }
.switch::after { content: ""; display: block; width: 24px; height: 24px; border-radius: 50%; background: white; box-shadow: 0 2px 7px rgba(16,42,67,.25); transition: .2s; }
.switch[aria-checked="true"] { background: var(--teal); }
.switch[aria-checked="true"]::after { transform: translateX(22px); }

.primary-button, .secondary-button, .ghost-button {
  min-height: 48px;
  border-radius: 13px;
  padding: 0 20px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.primary-button { border: 1px solid var(--teal); background: var(--teal); color: white; box-shadow: 0 10px 24px rgba(15,159,143,.22); }
.primary-button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 13px 30px rgba(15,159,143,.28); }
.primary-button:disabled { opacity: .48; cursor: not-allowed; box-shadow: none; }
.secondary-button { border: 1px solid var(--navy); background: white; color: var(--navy); }
.ghost-button { min-height: 38px; padding: 0 12px; border: 1px solid transparent; background: transparent; color: var(--teal); }
.ghost-button:hover { background: var(--teal-soft); }
.start-button { width: 100%; margin-top: 28px; }

.source-note { margin: 16px 0 0; color: var(--muted); text-align: center; font-size: .82rem; line-height: 1.45; }

.topics-panel { padding: 0; overflow: hidden; }
.topics-head { padding: 28px 30px 20px; border-bottom: 1px solid var(--line); }
.topics-title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.topics-title-row h2 { margin-bottom: 6px; }
.selected-count { color: var(--teal); font-weight: 800; font-size: .9rem; white-space: nowrap; }
.search-wrap { margin-top: 16px; position: relative; }
.search-wrap svg { position: absolute; width: 18px; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-input { width: 100%; min-height: 46px; padding: 0 14px 0 42px; border: 1px solid var(--line); border-radius: 13px; background: #f8fbfc; color: var(--ink); font-size: 1rem; outline: none; }
.search-input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,159,143,.12); }
.topics-actions { display: flex; gap: 6px; margin-top: 10px; }
.topic-list { max-height: 650px; overflow: auto; padding: 10px 16px 18px; scrollbar-color: #b8cbd5 transparent; }
.topic-item { display: grid; grid-template-columns: 28px minmax(0,1fr) auto; align-items: center; gap: 12px; padding: 13px 12px; border-radius: 14px; cursor: pointer; transition: background .14s; }
.topic-item:hover { background: #f2f7f9; }
.topic-item input { position: absolute; opacity: 0; pointer-events: none; }
.check-ui { width: 22px; height: 22px; border: 1.5px solid #9eb3c0; border-radius: 7px; display: grid; place-items: center; color: white; transition: .15s; }
.check-ui svg { width: 14px; opacity: 0; transform: scale(.6); transition: .15s; }
.topic-item input:checked + .check-ui { background: var(--teal); border-color: var(--teal); }
.topic-item input:checked + .check-ui svg { opacity: 1; transform: scale(1); }
.topic-copy strong { display: block; color: var(--navy); font-size: .91rem; line-height: 1.35; }
.topic-copy small { display: block; margin-top: 3px; color: var(--muted); }
.topic-count { min-width: 34px; padding: 5px 7px; border-radius: 10px; background: #edf3f6; color: var(--muted); font-size: .76rem; font-weight: 800; text-align: center; }
.empty-search { padding: 36px 16px; color: var(--muted); text-align: center; }

.quiz-shell { width: min(860px, 100%); margin: 0 auto; }
.quiz-progress-head { display: flex; justify-content: space-between; gap: 20px; color: var(--muted); font-size: .9rem; margin-bottom: 10px; }
.quiz-progress-head strong { color: var(--navy); }
.progress-track { height: 8px; border-radius: 99px; background: #dce7ed; overflow: hidden; margin-bottom: 20px; }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), var(--teal-bright)); transition: width .3s ease; }
.quiz-card { padding: clamp(22px, 5vw, 48px); }
.question-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; margin-bottom: 22px; }
.pill { display: inline-flex; align-items: center; min-height: 30px; border-radius: 99px; padding: 0 11px; font-size: .78rem; font-weight: 800; }
.pill-topic { max-width: 100%; color: var(--navy-2); background: #eaf1f5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill-multiple { color: #08766b; background: var(--teal-soft); }
.pill-single { color: #8a5a00; background: #fff5dc; }
.question-title { color: var(--navy); font-size: clamp(1.3rem, 2.6vw, 1.9rem); line-height: 1.4; letter-spacing: -.015em; margin-bottom: 12px; }
.question-instruction { color: var(--muted); margin-bottom: 24px; }
.options { display: grid; gap: 11px; }
.option {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0,1fr);
  align-items: start;
  gap: 13px;
  min-height: 60px;
  padding: 15px 17px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: #fcfdfe;
  cursor: pointer;
  line-height: 1.5;
  transition: .15s ease;
}
.option:hover { border-color: #9cb9c8; transform: translateY(-1px); }
.option input { position: absolute; opacity: 0; }
.option-marker { width: 30px; height: 30px; border: 1.5px solid #9fb3bf; border-radius: 50%; display: grid; place-items: center; color: white; font-size: .78rem; font-weight: 850; transition: .15s; }
.multiple .option-marker { border-radius: 8px; }
.option.is-selected { border-color: var(--teal); background: var(--teal-soft); }
.option.is-selected .option-marker { background: var(--teal); border-color: var(--teal); }
.option.is-correct { border-color: var(--teal); background: var(--teal-soft); }
.option.is-correct .option-marker { background: var(--teal); border-color: var(--teal); }
.option.is-wrong { border-color: var(--coral); background: var(--coral-soft); }
.option.is-wrong .option-marker { background: var(--coral); border-color: var(--coral); }
.option.is-dimmed { opacity: .58; }
.option-text { padding-top: 2px; overflow-wrap: anywhere; }

.feedback { margin-top: 22px; padding: 18px 19px; border-radius: 16px; border-left: 4px solid var(--teal); background: var(--teal-soft); }
.feedback.is-wrong { border-left-color: var(--coral); background: var(--coral-soft); }
.feedback strong { display: block; margin-bottom: 6px; color: var(--navy); }
.feedback p { margin: 0; color: #3b5566; line-height: 1.55; }
.quiz-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

.result-card { width: min(760px, 100%); margin: 0 auto; text-align: center; }
.score-ring { --score: 0deg; width: 164px; height: 164px; margin: 6px auto 26px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--teal) var(--score), #e3edf2 0); position: relative; }
.score-ring::before { content: ""; position: absolute; inset: 13px; border-radius: 50%; background: white; }
.score-ring span { position: relative; color: var(--navy); font-weight: 900; font-size: 2.25rem; letter-spacing: -.04em; }
.result-card h1 { font-size: clamp(2rem, 5vw, 3rem); }
.result-summary { color: var(--muted); font-size: 1.08rem; line-height: 1.6; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 28px 0; }
.result-stat { padding: 16px 10px; border-radius: 15px; background: #f2f7f9; }
.result-stat strong { display: block; color: var(--navy); font-size: 1.45rem; }
.result-stat span { color: var(--muted); font-size: .82rem; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

.error-card { max-width: 640px; margin: 60px auto; text-align: center; }
.error-card p { color: var(--muted); line-height: 1.6; }

button:focus-visible, input:focus-visible + .check-ui, .option:has(input:focus-visible) { outline: 3px solid rgba(15,159,143,.3); outline-offset: 3px; }

@media (max-width: 850px) {
  #app { padding-top: 24px; }
  .setup-grid { grid-template-columns: 1fr; }
  .topics-panel { order: -1; }
  .topic-list { max-height: 410px; }
}

@media (max-width: 560px) {
  .topbar { min-height: 66px; padding: 10px 16px; }
  .brand-mark { width: 40px; height: 40px; }
  .top-stats span:last-child { display: none; }
  .top-stats span + span { border: 0; padding: 0; }
  #app { width: min(100% - 20px, 1180px); padding-bottom: 36px; }
  .panel { border-radius: 18px; }
  .topics-head { padding: 22px 20px 16px; }
  .topic-list { padding-inline: 8px; }
  .choice-row { grid-template-columns: 1fr 1fr; }
  .catalogue-band { padding: 15px; }
  .quiz-progress-head { font-size: .82rem; }
  .question-meta { margin-bottom: 17px; }
  .quiz-card { padding: 22px 17px; }
  .option { padding: 13px; gap: 10px; }
  .quiz-actions { flex-direction: column; }
  .quiz-actions button { width: 100%; }
  .result-stats { grid-template-columns: 1fr; }
  .result-actions { flex-direction: column; }
  .result-actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
