/* Tablet */
@media (max-width: 980px) {
  .quiz-window {
    min-height: 650px;
  }

  .quiz-card {
    min-height: 650px;
    padding-inline: 24px;
  }

  .usage-grid {
    grid-template-columns: repeat(2, minmax(0, 295px));
  }

  .shape-grid {
    gap: 10px;
  }

  .sleep-grid {
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
  }

  .sleep-choice {
    width: 100%;
  }

  .person-sections.has-two {
    gap: 18px;
  }

  .person-sections.has-two .body-icon,
  .person-sections.has-two .body-icon img {
    width: 70px;
  }
}

/* Narrow tablets: keep each person's choices readable instead of compressing them. */
@media (min-width: 761px) and (max-width: 840px) {
  .person-sections.has-two {
    display: block;
    width: min(720px, 100%);
  }

  .person-sections.has-two .person-selection-section + .person-selection-section {
    margin-top: 34px;
  }

  .person-sections.has-two .shape-grid {
    gap: 12px;
  }

  .person-sections.has-two .shape-choice {
    height: 190px;
  }

  .person-sections.has-two .body-icon,
  .person-sections.has-two .body-icon img {
    width: 105px;
    height: 125px;
  }

  .sleep-sections.has-two .sleep-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
  }

  .sleep-sections.has-two .sleep-choice {
    height: 235px;
  }

  .sleep-sections.has-two .sleep-illustration,
  .sleep-sections.has-two .sleep-illustration img {
    width: 82px;
    height: 145px;
  }
}

/* Mobile */
@media (max-width: 760px) {
  :root {
    --mobile-side: 16px;
  }

  body {
    overflow-x: hidden;
  }

  .page-shell {
    padding: 6px;
    display: block;
  }

  .quiz-window {
    width: 100%;
    min-height: calc(100dvh - 12px);
    border-radius: 8px;
  }

  .quiz-card {
    min-height: calc(100dvh - 12px);
    padding: 22px var(--mobile-side) 100px;
  }

  .language-switch {
    top: 15px;
    left: 18px;
    font-size: 20px;
  }

  .help-mark {
    top: 14px;
    left: 14px;
    width: 44px;
    height: 44px;
  }

  .help-tooltip {
    position: fixed;
    top: max(70px, env(safe-area-inset-top));
    left: 12px;
    z-index: 100;
    width: calc(100vw - 24px);
    min-height: auto;
    max-height: calc(100dvh - 90px);
    padding: 18px 20px;
    overflow-y: auto;
    border-radius: 22px;
    transform: translateY(-7px) scale(0.99);
  }

  .help-tooltip::before {
    display: none;
  }

  .help-tooltip.is-open {
    transform: translateY(0) scale(1);
  }

  .help-tooltip p {
    font-size: 14px;
    line-height: 1.55;
  }

  .question-header {
    gap: 12px;
  }

  .brand-logo {
    width: 118px;
    height: 69px;
  }

  .question-header h1 {
    max-width: 95%;
    font-size: 14px;
    line-height: 1.45;
  }

  .usage-grid {
    width: 100%;
    margin-top: 32px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .usage-card {
    width: 100%;
    height: clamp(246px, 67vw, 285px);
  }

  .usage-card .visual-choice-panel {
    padding: 15px 7px 14px;
    gap: 9px;
    border-radius: 24px;
  }

  .usage-image-wrap {
    width: 100%;
    height: auto;
    min-height: 128px;
    flex: 1;
  }

  .usage-image {
    width: min(100%, 155px);
    height: auto;
    max-height: 150px;
  }

  .visual-choice-title {
    font-size: 12px;
  }

  .selection-circle,
  .multi-check {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
    background-size: 42px 42px;
  }

  .range-people,
  .range-people.has-two {
    width: 100%;
    margin-top: 42px;
    display: flex;
    flex-direction: column;
    gap: 28px;
  }

  .measurement-value,
  .range-people.has-two .measurement-value {
    height: 88px;
  }

  .measurement-value strong,
  .range-people.has-two .measurement-value strong {
    font-size: clamp(58px, 18vw, 72px);
    line-height: 88px;
  }

  .measurement-value span,
  .range-people.has-two .measurement-value span {
    margin: 0 0 18px 3px;
    font-size: 17px;
  }

  .range-shell,
  .range-people.has-two .range-shell {
    width: calc(100% - 12px);
    max-width: 520px;
  }

  .person-sections,
  .person-sections.has-two {
    width: 100%;
    margin-top: 36px;
    display: block;
  }

  .person-selection-section + .person-selection-section {
    margin-top: 38px;
  }

  .shape-grid,
  .person-sections.has-two .shape-grid {
    width: 100%;
    max-width: 370px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .shape-choice,
  .person-sections.has-two .shape-choice {
    width: 100%;
    height: 184px;
  }

  .shape-choice:nth-child(5) {
    grid-column: 1 / -1;
    width: calc((100% - 12px) / 2);
    justify-self: center;
  }

  .shape-choice .visual-choice-panel,
  .person-sections.has-two .shape-choice .visual-choice-panel {
    padding: 17px 8px 14px;
    gap: 8px;
    border-radius: 24px;
  }

  .body-icon,
  .body-icon img,
  .person-sections.has-two .body-icon,
  .person-sections.has-two .body-icon img {
    width: 112px;
    height: 112px;
  }

  .person-sections.has-two .visual-choice-title {
    font-size: 12px;
  }

  .sleep-grid,
  .sleep-sections.has-two .sleep-grid {
    width: 100%;
    max-width: 370px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .sleep-choice,
  .sleep-sections.has-two .sleep-choice {
    width: 100%;
    height: 252px;
  }

  .sleep-choice .visual-choice-panel,
  .sleep-sections.has-two .sleep-choice .visual-choice-panel {
    padding: 12px 6px 13px;
    gap: 9px;
    border-radius: 24px;
  }

  .sleep-illustration,
  .sleep-illustration img,
  .sleep-sections.has-two .sleep-illustration,
  .sleep-sections.has-two .sleep-illustration img {
    width: 82px;
    height: 150px;
  }

  .sleep-sections.has-two .selection-circle {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
    background-size: 42px 42px;
  }

  .sleep-sections.has-two .visual-choice-title {
    font-size: 12px;
  }

  .multi-choice-grid {
    width: 100%;
    max-width: 430px;
    margin-top: 42px;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .multi-choice-card {
    min-height: 60px;
    padding: 9px 12px;
    gap: 11px;
  }

  .multi-choice-text {
    font-size: 13px;
  }

  .quiz-navigation {
    position: sticky;
    left: auto;
    bottom: 0;
    z-index: 20;
    width: 100%;
    min-height: 72px;
    margin-top: auto;
    padding: 14px var(--mobile-side) max(14px, env(safe-area-inset-bottom));
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0), #fff 24%, #fff 100%);
    transform: none;
  }

  .navigation-button {
    min-width: 0;
    width: min(45%, 160px);
    min-height: 48px;
    padding-inline: 7px;
    font-size: 17px;
  }

  .validation-message {
    bottom: 63px;
    font-size: 11px;
  }

  .is-result .page-shell {
    padding: max(20px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
  }

  .result-logo {
    width: 124px;
    height: 73px;
    margin-bottom: 18px;
  }

  .mattress-results-grid {
    gap: 10px;
  }

  .mattress-card-content {
    min-height: 102px;
    padding: 12px;
  }

  .mattress-card-content h2 {
    font-size: 13px;
  }

  .result-actions {
    flex-wrap: wrap;
    gap: 12px;
  }
}

@media (max-width: 520px) {
  .mattress-results-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 350px) {
  .quiz-card {
    padding-inline: 10px;
  }

  .usage-grid,
  .shape-grid,
  .sleep-grid {
    gap: 8px;
  }

  .navigation-button {
    font-size: 15px;
  }
}

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