/* ===== 모바일 반응형 보강 =====================================
   이 파일의 모든 규칙은 반드시 @media 블록 안에만 작성한다.
   미디어 쿼리 밖에 규칙을 두면 PC 디자인이 바뀌므로 넣지 말 것.

   로드 순서상 마지막에 연결되므로, 같은 선택자·같은 명시도이면
   이 파일이 이긴다. quiz.html 의 인라인 critical CSS 보다도 뒤에 온다.
   ============================================================== */

/* ───────────────────────────────────────────────────────────────
   노트북(13~15인치, Windows 125~150% 확대)에서 한글 줄이 겹치지 않게
   ─────────────────────────────────────────────────────────────── */
@media (max-width: 1600px) {
  .qcard__text,
  .qcard__passage,
  .option__text,
  .review__q,
  .review__explain,
  .ai__body,
  .plan__feat {
    line-height: 1.6;
  }
  .qbar {
    flex-wrap: wrap;
    row-gap: 6px;
  }
}

/* ───────────────────────────────────────────────────────────────
   태블릿 ~ 모바일 (사이드바가 드로어로 바뀌는 지점과 동일)
   ─────────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  :root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --shell-top: calc(var(--topbar-h) + var(--safe-top));
  }

  /* ── 문서 스크롤 되살리기 ───────────────────────
     PC 는 .main 안쪽만 스크롤하지만, 모바일에서 그렇게 하면
     주소창이 접히고 펼쳐질 때 높이가 흔들려 하단이 잘린다.
     모바일에서는 문서 전체가 스크롤되게 한다. */
  html,
  html:has(body.auth-page) {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-text-size-adjust: 100%;
  }
  body,
  body.auth-page,
  body:has(.layout) {
    height: auto;
    min-height: 100%;
    overflow: visible;
  }

  .layout {
    height: auto;
    min-height: calc(100dvh - var(--shell-top));
    margin-top: var(--shell-top);
    overflow: visible;
  }

  .main,
  .main.main--home,
  .main.main--billing,
  .main.main--quiz {
    height: auto;
    min-height: 0;
    overflow: visible !important;
    scrollbar-gutter: auto;
    padding: 14px 14px calc(18px + var(--safe-bottom));
  }

  /* 홈 과목·메뉴 카드: 글자만 -1, 박스 크기(패딩·min-height)는 유지 */
  .card__title { font-size: 15px; }
  .card__cta,
  .card__meta { font-size: 12px; }
  .card__badge { font-size: 10px; }
  .feature__title { font-size: 13.5px; }
  .feature__desc { font-size: 11.5px; }
  .feature__cta { font-size: 12.5px; }

  /* ── 상단 바: 노치·홈 인디케이터 영역 확보 ────── */
  .topbar {
    height: var(--shell-top);
    padding: var(--safe-top) calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
    gap: 6px;
  }
  .topbar__menu,
  .topbar__icon {
    width: 44px;
    height: 44px;
  }
  .topbar__btn {
    min-height: 44px;
    height: 44px;
  }

  /* ── 사이드바 드로어 ─────────────────────────── */
  .sidebar {
    top: var(--shell-top);
    height: calc(100dvh - var(--shell-top));
    padding-bottom: calc(10px + var(--safe-bottom));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .scrim {
    top: var(--shell-top);
    bottom: 0;
  }
  /* 드로어는 세로로 길어질 수 있으므로 메뉴가 잘리지 않게 한다 */
  .nav {
    flex: 0 0 auto;
    min-height: 0;
    overflow: visible;
  }
  .nav__link {
    min-height: 48px;
    padding: 11px 12px;
    touch-action: manipulation;
  }

  /* ── 터치 영역 최소 44px ─────────────────────── */
  .btn {
    min-height: 44px;
    height: auto;
    padding: 0 16px;
    touch-action: manipulation;
  }
  .btn--sm {
    min-height: 44px;
    height: 44px;
    padding: 0 14px;
  }
  .skip-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }

  /* iOS 는 글자 16px 미만 입력란에 포커스하면 화면을 확대한다 */
  input:not([type='checkbox']):not([type='radio']),
  select,
  textarea {
    font-size: 16px;
  }

  /* ── 공지 팝오버 ─────────────────────────────── */
  .notice-pop {
    width: calc(100vw - 20px) !important;
    left: 10px !important;
    right: 10px !important;
  }

  /* ───────── 문제 풀이 화면 ───────── */
  .main.main--quiz {
    overscroll-behavior: auto;
  }
  .qbar__back {
    width: 44px;
    height: 44px;
  }

  /* 중첩 스크롤 컨테이너를 모두 풀어 한 번만 스크롤되게 한다 */
  .qlayout {
    display: flex;
    flex-direction: column;
    flex: none;
    gap: 12px;
    min-height: 0;
    overflow: visible;
  }
  .qmain,
  .qmain.is-ai-open {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: auto;
    max-height: none;
    overflow: visible;
  }
  .qmain.is-ai-open .qcard,
  .qmain.is-ai-open .ai,
  .qmain.is-ai-open .qactions {
    grid-column: auto;
    grid-row: auto;
    flex: none;
    width: 100%;
  }
  .qmain.is-ai-open .ai {
    position: relative;
    z-index: 2;
    background: #fff;
  }
  .qlayout.is-ai-open .qnav,
  .qlayout:has(.qmain.is-ai-open) .qnav {
    display: none;
  }
  .qcard,
  .qmain.is-ai-open .qcard {
    flex: none;
    min-height: 0;
    overflow: visible;
    padding: 16px 16px 10px;
  }
  .qcard__body,
  .qmain.is-ai-open .qcard__body {
    flex: none;
    min-height: 0;
    max-height: none;
    overflow: visible;
    scrollbar-gutter: auto;
  }
  .ai,
  .qmain.is-ai-open .ai {
    flex: none;
    min-height: 0;
    overflow: visible;
  }
  .ai__body {
    grid-template-columns: minmax(0, 1fr);
    max-height: none;
    overflow: visible;
    padding: 12px 12px 20px;
  }

  /* 문제와 보기를 세로로 */
  .options,
  .qmain.is-ai-open .options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
  }

  /* 정답 선택 버튼: 최소 44px 터치 영역 (여유 있게 48px) */
  .option,
  .qmain.is-ai-open .option {
    min-height: 48px;
    gap: 12px;
    padding: 12px 14px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  .option__mark {
    width: 22px;
    height: 22px;
  }
  .option__mark::after {
    width: 8px;
    height: 8px;
  }
  .option__text {
    font-size: 15px;
    line-height: 1.5;
  }
  /* 터치 기기에는 hover 가 없어 잔상만 남으므로 끈다 */
  .option:hover {
    border-color: var(--line);
    background: #fff;
  }
  .option.is-selected:hover {
    border-color: var(--primary);
    background: #f4f8ff;
  }

  /* 이전·AI 해설·다음 버튼을 카드 하단에 고정해 항상 닿게 한다 */
  .qactions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 14px -16px 0;
    padding: 10px 16px calc(8px + var(--safe-bottom));
    background: #fff;
    box-shadow: 0 -6px 14px rgba(37, 99, 235, .07);
  }
  .qmain.is-ai-open .qactions {
    position: static;
    z-index: auto;
    box-shadow: none;
  }
  .qactions .btn,
  .qmain.is-ai-open .qactions .btn {
    min-height: 44px;
    height: 44px;
    min-width: 0;
  }

  /* AI 해설 헤더: 좁은 폭에서 두 줄로 */
  .ai__head {
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: 8px;
    padding: 10px 12px;
  }
  .ai__similar {
    grid-column: 1 / -1;
    justify-self: stretch;
    min-height: 44px;
    font-size: 14px;
  }
  .ai__close {
    min-height: 46px;
    padding: 7px 16px;
    font-size: 14px;
  }
  .ai__close svg {
    width: 16px;
    height: 16px;
  }
  .ai__tab {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 14.5px;
  }
  .ai__title {
    font-size: 16px;
  }
  .ai__answer {
    font-size: 15.5px;
  }
  .ai__sec-title {
    font-size: 15px;
  }
  .ai__list li,
  .ai__side-title {
    font-size: 14.5px;
  }

  /* 문제 번호 패널 */
  .qnav {
    max-height: none;
    overflow: visible;
  }
  .qnav__grid {
    max-height: 272px;
    overflow-y: auto;
  }
  .qdot {
    min-height: 44px;
    height: 44px;
    font-size: 14px;
    touch-action: manipulation;
  }
  .qnav__sets {
    max-height: 147px;
  }
  .qnav__set {
    min-height: 44px;
    height: 44px;
  }
  .qnav__move {
    min-height: 44px;
    height: 44px;
    padding: 0 12px;
    font-size: 12.5px;
  }
  .qnav__session {
    font-size: 11px;
  }
  .legend {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px 14px;
  }

  /* 채점 결과 시트: 하단에서 올라오는 형태 */
  .result {
    align-items: end;
    padding: 10px;
  }
  .result__panel {
    max-height: calc(100dvh - 20px);
    padding: 18px 16px calc(18px + var(--safe-bottom));
  }
  .result__foot .btn {
    flex: 1 1 calc(50% - 8px);
    min-height: 44px;
  }

  /* ───────── 로그인 · 회원가입 · 비밀번호 찾기 ───────── */
  .auth {
    align-items: flex-start;
    min-height: 100dvh;
    padding: calc(var(--shell-top) + 10px) 14px calc(16px + var(--safe-bottom));
  }
  .auth__card {
    padding: 22px 18px 20px;
  }
  .auth__card--login {
    padding: 10px 14px 14px;
  }
  .auth__form .field {
    height: 48px;
  }
  .auth__submit,
  .auth-login-btn {
    min-height: 48px;
    height: 48px;
  }
  .auth-pill {
    min-height: 44px;
  }
  .sns-btn,
  .sns-btn img {
    width: 60px;
    height: 60px;
  }

  /* ───────── 마이페이지 · 결제 ───────── */
  .mypage__tab {
    min-height: 44px;
  }
  .pay-table-wrap,
  .record__table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .paybox__actions {
    flex-direction: column-reverse;
  }
  .paybox__actions .btn {
    width: 100%;
  }

  /* ───────── 홈 화면에 추가 안내 배너 ───────── */
  .pwa-hint {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + var(--safe-bottom));
    z-index: 55;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    box-shadow: var(--shadow-lg);
  }
  .pwa-hint__icon {
    width: 36px;
    height: 36px;
    flex: none;
    border-radius: 9px;
  }
  .pwa-hint__text {
    flex: 1;
    min-width: 0;
    margin: 0;
    color: var(--text-soft);
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.4;
  }
  .pwa-hint__text b {
    color: var(--text);
    font-weight: 800;
  }
  .pwa-hint__btn {
    flex: none;
    min-height: 44px;
    padding: 0 14px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
  }
  .pwa-hint__close {
    flex: none;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 20px;
    line-height: 1;
  }
}

/* ───────────────────────────────────────────────────────────────
   스마트폰 세로 폭
   ─────────────────────────────────────────────────────────────── */
@media (max-width: 560px) {
  .main,
  .main.main--home,
  .main.main--billing,
  .main.main--quiz {
    padding: 12px 12px calc(16px + var(--safe-bottom));
  }

  .topbar {
    padding-right: calc(8px + var(--safe-right));
    padding-left: calc(8px + var(--safe-left));
    gap: 4px;
  }
  .topbar__dot {
    display: none;
  }
  .topbar__title,
  .topbar__home {
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar__btn {
    padding: 0 11px;
    font-size: 12.5px;
  }

  /* 시험 정보 바를 두 줄로 흘린다 */
  .qbar {
    flex-wrap: wrap;
    row-gap: 8px;
    padding: 8px 10px;
  }
  .qbar__crumb {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 13px;
  }
  .qbar__right {
    order: 2;
    margin-left: auto;
  }
  .qbar__count {
    order: 3;
    flex: 1 1 100%;
    margin-left: 0;
    font-size: 11.5px;
  }
  .qbar__quota {
    order: 4;
    flex: 1 1 100%;
  }

  .qcard,
  .qmain.is-ai-open .qcard {
    padding: 14px 14px 10px;
  }
  .qactions,
  .qmain.is-ai-open .qactions {
    margin-left: -14px;
    margin-right: -14px;
    padding-left: 14px;
    padding-right: 14px;
  }
  .qactions .btn,
  .qmain.is-ai-open .qactions .btn {
    padding: 0 10px;
    font-size: 13px;
  }

  .qnav__grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .qnav__grid.is-similar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .result__foot .btn {
    flex: 1 1 100%;
  }

  .similar--grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ───────────────────────────────────────────────────────────────
   가로 모드에서 세로 공간이 부족할 때
   ─────────────────────────────────────────────────────────────── */
@media (max-width: 860px) and (orientation: landscape) and (max-height: 520px) {
  .auth {
    align-items: flex-start;
    padding-top: calc(var(--shell-top) + 6px);
  }
  .qactions,
  .qmain.is-ai-open .qactions {
    position: static;
    box-shadow: none;
  }
}
