:root {
  /* colors */
  --brand: #1D19B4;
  --accent: #EE8602;
  --accent-2: #F6B801;
  --bg: #F6F7FC;
  --bg-2: #EDE7FF;
  --white: #ffffff;
  --text: #0E1020;
  --muted: #666C80;
  --stroke: #E3E6EF;

  /* radii (8, 16, 32 + pill) */
  --radius-8: 0.5rem;
  --radius-16: 1rem;
  --radius-32: 2rem;
  --radius-pill: 999rem;

  --radius-sm: var(--radius-8);
  --radius-md: var(--radius-16);
  --radius-lg: var(--radius-32);

  /* shadows */
  --shadow-1: 0 0.5rem 1.5rem rgba(13, 17, 51, 0.06);

  /* spacing scale */
  --space-xxs: 0.25rem;
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;

  /* typography */
  --ff-base: "Commissioner", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;

  /*  ≈ 36–52px */
  --fs-h1: clamp(2.25rem, 1.75rem + 1.5vw, 3.25rem);
  /*  ≈ 32–40px */
  --fs-h2: clamp(2rem, 1.5rem + 1vw, 2.5rem);
  /*  ≈ 24–32px */
  --fs-h3: clamp(1.5rem, 1.25rem + 0.9vw, 2rem);
  /*  ≈ 20–24px */
  --fs-h4: clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem);
  /*  ≈ 16–18px */
  --fs-body: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  /*  ≈ 14–16px */
  --fs-small: clamp(0.875rem, 0.8rem + 0.25vw, 1rem);

  /* backward-compatible aliases (якщо десь ще звертаєшся) */
  --ff: var(--ff-base);
  --h1: var(--fs-h1);
  --h2: var(--fs-h2);
  --h3: var(--fs-h3);
  --h4: var(--fs-h4);
  --b1: var(--fs-body);
  --b4: var(--fs-body);
  --b5: var(--fs-small);
}

/* reset / base */

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--ff-base);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: var(--fs-body);
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: inherit;
  text-decoration: none;
}

/* layout helpers */

.container {
  margin: 0 auto;
  padding: var(--space-md);
}

.row {
  display: flex;
  gap: var(--space-md);
}

.wrap {
  flex-wrap: wrap;
}

.between {
  display: flex;
  justify-content: space-between;
}

.center {
  align-items: center;
}

.mb-8 {
  margin-bottom: 0.8rem;
}

.mt-16 {
  margin-top: 1rem;
}

.muted {
  color: var(--muted);
}

/* headings */

h1 {
  font-size: var(--fs-h1);
  line-height: 1.15;
  font-weight: 600;
  margin: 0 0 0.75rem;
}

h2 {
  font-size: var(--fs-h2);
  line-height: 1.15;
  font-weight: 600;
  margin: 0 0 0.625rem;
}

h3 {
  font-size: var(--fs-h3);
  line-height: 1.25;
  font-weight: 500;
  margin: 0 0 0.5rem;
}

h4 {
  font-size: var(--fs-h4);
  line-height: 1.25;
  font-weight: 600;
  margin: 0 0 0.375rem;
}

/* header bar */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 0.0625rem solid var(--stroke);
  backdrop-filter: saturate(140%) blur(0.375rem);
}

.bar:last-child {
  position: static;
  border-top: 0.0625rem solid var(--stroke);
  border-bottom: none;
}

.brand {
  font-weight: 700;
  color: var(--brand);
}

/* cards & tiles */

.card {
  background: var(--white);
  border: 0.0625rem solid var(--stroke);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  margin-bottom: var(--space-md);
}

.tile {
  display: block;
  padding: 1.125rem 1rem;
  background: var(--white);
  border: 0.0625rem solid var(--stroke);
  border-radius: var(--radius-lg);
  min-width: 15rem;
  transition:
    0.15s transform,
    0.15s box-shadow,
    0.15s border-color;
}

.tile:hover {
  transform: translateY(-0.125rem);
  border-color: var(--brand);
  box-shadow: 0 0.625rem 1.625rem rgba(29, 25, 180, 0.08);
}

/* buttons */

.btn {
  appearance: none;
  cursor: pointer;
  user-select: none;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 0.0625rem solid var(--brand);
  background: var(--brand);
  color: #ffffff;
  font-weight: 700;
  font-size: var(--fs-body);
  transition:
    filter 0.15s,
    transform 0.05s;
}

.btn:hover {
  filter: brightness(1.03);
}

.btn:active {
  transform: translateY(0.0625rem);
}

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

.btn.ghost {
  background: transparent;
  color: var(--brand);
}

/* HUD */

.hud {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.pill {
  padding: 0.375rem 0.75rem;
  border: 0.0625rem solid var(--stroke);
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: var(--fs-small);
  min-width: 12rem;
}

.progress {
  width: 16.25rem;
  height: 0.75rem;
  border: 0.0625rem solid var(--stroke);
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: #ffffff;
}

#pbar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--brand), #6d66ff);
}

/* questions */

.option {
  display: flex;
  gap: 0.625rem;
  align-items: center;
  padding: 0.625rem 0.75rem;
  border: 0.0625rem solid var(--stroke);
  border-radius: var(--radius-md);
  margin: 0.5rem 0;
  background: #ffffff;
  font-size: var(--fs-body);
}

.list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.inl {
  display: inline-block;
  padding: 0.5rem 0.625rem;
  border: 0.0625rem solid var(--stroke);
  border-radius: 0.625rem;
  background: #ffffff;
}

.card .option {
  flex: 1 1 100%;
}

/* MATCH: списки зверху */

.match-lists .col {
  flex: 1;
}

.match-lists .chip {
  width: 1.75rem;
  height: 1.75rem;
  min-width: 1.75rem;
  border-radius: 0.875rem;
  display: grid;
  place-items: center;
  background: #ffffff;
  border: 0.0625rem solid var(--brand);
  color: var(--brand);
  font-weight: 700;
  margin-right: 0.5rem;
}

.match-lists .rowitem {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  border: 0.0625rem solid var(--stroke);
  border-radius: 0.75rem;
  margin: 0.5rem 0;
  background: #ffffff;
}

/* MATCH: матриця */

.matrix-title {
  font-weight: 600;
  margin: 0.75rem 0 0.5rem;
}

.matrix {
  overflow: auto;
}

.matrix table {
  border-collapse: collapse;
  width: 100%;
}

.matrix th,
.matrix td {
  padding: 0.75rem;
  text-align: center;
  font-size: var(--fs-small);
}

.matrix .head {
  font-weight: 600;
}

.matrix .badge {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.875rem;
  display: inline-grid;
  place-items: center;
  border: 0.0625rem solid var(--brand);
  color: var(--brand);
  background: #ffffff;
  font-weight: 700;
}

/* великі радіокнопки */

.matrix input[type="radio"] {
  width: 1.375rem;
  height: 1.375rem;
  accent-color: var(--brand);
  transform: translateY(0.0625rem);
}

.matrix td {
  min-width: 2.75rem;
  min-height: 2.25rem;
}

/* ORDER DnD */

.dnd .option {
  cursor: grab;
}

.dnd .option.dragging {
  opacity: 0.9;
  box-shadow: 0 0.375rem 1.125rem rgba(0, 0, 0, 0.08);
}

/* results */

.stat {
  min-width: 8.75rem;
  text-align: center;
}

.stat__val {
  font-size: clamp(2rem, 1.8rem + 0.8vw, 2.5rem);
  font-weight: 800;
}

.acc {
  border: 0.0625rem solid var(--stroke);
  border-radius: var(--radius-md);
  margin: 0.5rem 0;
  padding: 0.75rem;
}

.acc > div {
  padding-top: 0.5rem;
}

.mbar {
  height: 0.75rem;
  border: 0.0625rem solid var(--stroke);
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: #ffffff;
}

.mbar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
  gap: var(--space-md);
}

.kpi {
  border: 0.0625rem solid var(--stroke);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  background: #ffffff;
}

.kpi .title {
  font-weight: 600;
  margin-bottom: 0.375rem;
  word-break: break-word;
}

/* loading */

.loading {
  position: fixed;
  inset: 0;
  background: rgba(13, 17, 51, 0.08);
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s;
}

.loading.active {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  width: 2.875rem;
  height: 2.875rem;
  border: 0.3125rem solid #e7e9f3;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* forms */

input[type="text"],
input[type="tel"],
input[type="email"],
select,
textarea {
  width: 100%;
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius-md);
  border: 0.0625rem solid var(--stroke);
  background: #ffffff;
  color: var(--text);
  font-size: var(--fs-body);
}

label.label {
  display: block;
  margin-bottom: 0.375rem;
  color: var(--muted);
  font-size: var(--fs-small);
}

/* grids */

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.grid-5 {
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* responsive base */

@media (max-width: 64rem) {
  .progress {
    width: 13.75rem;
  }

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

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

@media (max-width: 40rem) {
  .container {
    padding: 0.875rem;
  }

  .progress {
    display: none;
  }

  .hud {
    gap: 0.5rem;
  }

  .grid-4,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .tile {
    min-width: 100%;
  }

  .matrix th,
  .matrix td {
    padding: 0.625rem;
  }

  .matrix .badge {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 0.75rem;
    font-size: var(--fs-small);
  }

  .matrix input[type="radio"] {
    width: 1.5rem;
    height: 1.5rem;
  }
}

/* MATCH lists stack on phones */

@media (max-width: 40rem) {
  .match-lists {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .match-lists .col {
    width: 100%;
  }

  .match-lists .rowitem {
    margin: 0.375rem 0;
  }

  .matrix-title {
    margin-top: 0.5rem;
  }
}

/* ---------- HERO ---------- */

.hero {
  text-align: center;
  padding: 1.75rem 1.125rem;
  background: linear-gradient(
    180deg,
    rgba(237, 231, 255, 0.6),
    rgba(246, 247, 252, 0.9)
  );
  border: 0.0625rem solid var(--stroke);
  border-radius: var(--radius-lg);
}

.hero__eyebrow {
  font-size: var(--fs-small);
  margin-bottom: 0.375rem;
}

.hero__title {
  margin: 0.25rem 0 0.375rem;
}

.hero__subtitle {
  font-size: var(--fs-body);
  color: var(--muted);
  margin: 0;
}

/* ---------- SUBJECTS ---------- */

.subjects {
  margin-top: var(--space-md);
}

.subjects__title {
  margin: 0.625rem 0 0.75rem;
  text-align: center;
}

/* pill tiles */

.tile--pill {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  border-radius: var(--radius-lg);
  padding: 0.875rem 1rem;
  background: #ffffff;
  border: 0.125rem solid var(--stroke);
  font-weight: 600;
  justify-content: center;
}

.tile__icon {
  width: 4rem;
  height: 4rem;
  display: grid;
  place-items: center;
}

.tile--pill:hover {
  border-color: var(--brand);
  box-shadow: 0 0.5rem 1.375rem rgba(29, 25, 180, 0.08);
}

.tile--active {
  border-color: #d74bff;
  box-shadow: 0 0.5rem 1.25rem rgba(215, 75, 255, 0.15);
}

.cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.375rem;
  margin-top: 1.125rem;
}

.btn--xl {
  padding: 1rem 1.375rem;
  font-size: clamp(1.125rem, 1rem + 0.4vw, 1.25rem);
  border-radius: 0.875rem;
}

/* hero responsive tweaks */

@media (max-width: 64rem) {
  .hero {
    padding: 1.375rem 1rem;
  }
}

@media (max-width: 40rem) {
  .hero__title {
    font-size: var(--fs-h3);
    line-height: 1.25;
  }

  .subjects__title {
    font-size: var(--fs-h4);
  }

  .tile--pill {
    padding: 0.75rem 0.875rem;
  }

  .tile__icon {
    width: 1.625rem;
    height: 1.625rem;
    font-size: var(--fs-small);
  }
}

/* lead form / native select */

#lead-msg {
  color: #e7e9f3;
}

.native-select {
  appearance: auto;
  -webkit-appearance: menulist;
  -moz-appearance: auto;
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 0.0625rem solid var(--stroke);
  border-radius: var(--radius-md);
  background: #ffffff;
  line-height: 1.2;
}

/* фокус */

.native-select:focus {
  outline: 0.125rem solid #f1fbf3;
  outline-offset: 0.125rem;
}

/* lead form mobile */

.inside_card_form {
  gap: var(--space-md);
}

.card_form_image img {
  max-width: 16.25rem;
  height: auto;
}

#lead input[type="text"],
#lead input[type="tel"],
#lead input[type="email"],
#lead select {
  min-height: 3rem;
  font-size: var(--fs-body);
}

#lead button.btn {
  width: 100% !important;
}

@media (max-width: 64rem) {
  .card_form_image {
    width: 36% !important;
  }

  .inside_card_form > div:last-child {
    width: 60% !important;
  }
}

@media (max-width: 40rem) {
  .inside_card_form {
    flex-direction: column;
    align-items: stretch;
  }

  .card_form_image {
    display: none !important;
  }

  .inside_card_form > div:last-child {
    width: 100% !important;
  }

  .lead.grid-5 {
    gap: 0.625rem;
  }

  .page.result .card h3 {
    margin-bottom: 0.5rem;
  }
}

/* === Test page specific layout & overrides === */

body {
  background: linear-gradient(
    180deg,
    rgba(224, 228, 255, 1) 0%,
    rgba(255, 255, 255, 1) 100%
  ) !important;
}

/* HUD */

.page.test .hud {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.page.test .hud #time {
  min-width: 4.625rem;
  text-align: center;
}

.page.test .hud .progress {
  flex: 1;
  height: 0.75rem;
  border-radius: var(--radius-pill);
  background: #195de61a;
  border: 0;
  overflow: hidden;
}

.container.between.center.header-row {
  padding: 0 !important;
}

.page.test .hud .progress #pbar {
  height: 100%;
  width: 0;
  border-radius: var(--radius-pill);
  background: #195de6;
  transition: width 0.25s ease-out;
}

.page.test .hud #plabel {
  white-space: nowrap;
}

/* layout: left question, right tiles */

.page.test .test-layout {
  display: flex;
  align-items: stretch;
  gap: 1.5rem;
  margin-top: 1.5rem;
  width: 80%;
}

.page.test .test-main,
.page.test .test-sidebar {
  display: flex;
  flex-direction: column;
}

.test-main {
  width: 70%;
}

.test-sidebar {
  width: 30%;
}

.page.test #qbox.card {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.page.test .questions-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.questions-nav__title {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.questions-nav__grid {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  /* розносимо лише через gap, без вирівнювання */
  column-gap: var(--space-xs);   /* 0.5rem, ти вже маєш цю змінну в :root */
  row-gap: var(--space-xs);
  margin: 0.5rem 0;
  align-content: flex-start;
}

.question-tile {
  border-radius: 0.625rem;
  border: 0.0625rem solid #d8dbf0;
  background: #f7f7fb;
  height: 2rem;
  /* 4 колонки: (100% - 3 gaps) / 4 */
  flex: 0 0 calc((100% - 3 * var(--space-xs)) / 4);

  font-size: var(--fs-small);
  padding: 0.375rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease-out;
}

.question-tile.current {
  border-color: #1d19b4;
  background: #1d19b4;
  color: #ffffff;
  font-weight: 600;
}

.question-tile.answered {
  background: #f5fff8;
  border-color: #2ecc71;
}

.question-tile:hover {
  transform: translateY(-0.0625rem);
}

.finish-btn {
  width: 100%;
  margin-top: auto;
}

.test-controls {
  gap: 0.75rem;
  margin-top: 1rem;
}

.page.test #subjectName {
  margin-top: 1rem;
  margin-bottom: 1rem;
}

/* responsive: test page */

@media (max-width: 56.25rem) {
  .page.test .test-layout {
    flex-direction: column;
  }

  .page.test .test-sidebar {
    width: 100%;
  }
}

@media (max-width: 56.25rem) {
  .page.test .test-layout {
    width: 100%;
    margin-top: 1rem;
  }

  .page.test .test-main,
  .page.test .test-sidebar {
    width: 100%;
  }

  .page.test .test-controls {
    gap: 0.625rem;
  }

  .page.test .test-controls #prev,
  .page.test .test-controls #next {
    flex: 1;
  }
}

@media (max-width: 37.5rem) {
  .page.test .test-layout {
    width: 100%;
    margin-top: 0.75rem;
    gap: 0.75rem;
  }

  .page.test #qbox.card {
    padding: 1rem 0.875rem;
  }

  .page.test #qbox.card h3,
  .page.test #qbox.card h4 {
    font-size: var(--fs-h4);
  }

  .page.test #qbox.card .option {
    font-size: var(--fs-body);
    padding: 0.625rem 0.75rem;
  }

  .page.test .hud {
    gap: 0.5rem;
  }

  .page.test .hud .progress {
    height: 0.625rem;
  }

  #time.pill,
  #plabel.pill {
    padding-inline: 0.625rem;
    font-size: var(--fs-small);
  }

  .page.test .test-sidebar,
  .page.test .questions-nav {
    display: none;
  }

  .page.test .test-controls {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.875rem;
  }

  .page.test .test-controls #prev,
  .page.test .test-controls #next {
    flex: 1;
    font-size: var(--fs-body);
    padding: 0.75rem 0.625rem;
  }
}

/* мобільна правка для сторінки тесту */

@media (max-width: 40rem) {
  .page.test .hud .progress {
    display: block;
    flex: 1;
  }

  .page.test #time.pill {
    display: none !important;
  }
}
