/* =============================================================================
   Site-wide mobile / tablet responsiveness
   Breakpoints: mobile ≤767px · tablet 768–1023px · desktop ≥1024px
   Desktop layouts stay intact; these rules only tighten small viewports.
   ============================================================================= */

:root {
  --nav-collapse: 1023px;
}

html {
  overflow-x: clip;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: clip;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

#app,
.main-content,
.site-header,
.site-footer,
.card,
.grid-2,
.grid-4,
.practice-exam-grid {
  min-width: 0;
}

img,
video {
  max-width: 100%;
  height: auto;
}

.logo-piece img,
.logo-wordmark img {
  max-width: none;
  width: 100%;
  height: 100%;
}

body:has(.modal-backdrop),
body.nav-open {
  overflow: hidden;
}

.nav-icon-label {
  display: none;
}

.nav-overlay {
  display: none;
}

.exam-pane-tabs {
  display: none;
}

.exam-mobile-notice {
  display: none;
}

/* ----- Tablet + phone: collapse site nav into a drawer ----- */
@media (max-width: 1023px) {
  :root {
    --header-h: calc(56px + env(safe-area-inset-top, 0px));
  }

  .site-header {
    gap: 0.45rem;
    height: var(--header-h);
    padding: env(safe-area-inset-top, 0px) 0.85rem 0;
    overflow: hidden;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: var(--surface-solid);
  }

  .site-header > .logo {
    flex: 1 1 auto;
    min-width: 0;
  }

  .logo-wordmark {
    height: 1.55rem;
    max-width: min(11.5rem, 46vw);
  }

  .logo-mark {
    font-size: 0.72rem;
    padding: 0.42rem 0.55rem;
  }

  .site-header > .auth-slot {
    display: none;
  }

  .theme-toggle {
    margin-left: auto;
    width: 2.5rem;
    height: 2.5rem;
    flex-shrink: 0;
  }

  .nav-toggle {
    display: flex;
    margin-left: 0;
    width: 2.5rem;
    height: 2.5rem;
    align-items: center;
    justify-content: center;
    padding: 0.55rem;
    flex-shrink: 0;
    z-index: 130;
  }

  .nav-toggle span {
    transform-origin: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  body.nav-open .nav-toggle span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }
  body.nav-open .nav-toggle span:nth-child(2) {
    opacity: 0;
  }
  body.nav-open .nav-toggle span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  body.nav-open .site-header {
    z-index: 125;
  }

  .nav-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .nav-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
  }

  .main-nav {
    display: flex;
    position: fixed;
    top: 0;
    right: 0;
    left: auto;
    width: min(22rem, 88vw);
    height: 100dvh;
    max-height: 100dvh;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0.15rem;
    margin: 0;
    padding: calc(var(--header-h) + 0.5rem) 1rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
    background: var(--surface-solid);
    border-bottom: none;
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 120;
    transform: translateX(110%);
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.28s var(--ease-out), visibility 0.28s;
  }
  .main-nav.open {
    display: flex;
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }

  .main-nav > a,
  .main-nav .nav-dropdown-toggle {
    width: 100%;
    min-height: 2.75rem;
    justify-content: flex-start;
    padding: 0.7rem 0.9rem;
    font-size: 0.95rem;
    border-radius: var(--radius-sm);
  }

  .main-nav a.nav-icon {
    width: 100%;
    height: auto;
    justify-content: flex-start;
    gap: 0.55rem;
    padding: 0.7rem 0.9rem;
  }

  .nav-icon-label {
    display: inline;
  }

  .nav-dropdown {
    width: 100%;
  }
  .nav-dropdown-toggle {
    width: 100%;
    justify-content: space-between;
  }
  .nav-dropdown-menu {
    position: static;
    box-shadow: none;
    border: none;
    background: transparent;
    padding: 0 0 0.4rem 0.7rem;
    min-width: 0;
  }
  .nav-dropdown-link {
    padding: 0.6rem 0.85rem;
    min-height: 2.5rem;
  }

  .main-nav .auth-slot {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
    margin: 0.85rem 0 0;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
    width: 100%;
  }
  .main-nav .auth-slot .btn {
    width: 100%;
    min-height: 2.75rem;
  }
  .main-nav .auth-menu {
    width: 100%;
  }
  .main-nav .auth-menu-toggle {
    width: 100%;
    max-width: none;
    min-height: 2.75rem;
    justify-content: space-between;
  }
  .main-nav .auth-menu-dropdown {
    position: static;
    display: flex;
    flex-direction: column;
    width: 100%;
    margin-top: 0.35rem;
    box-shadow: none;
    border: 1px solid var(--border);
  }
  .main-nav .auth-menu.open .auth-menu-dropdown,
  .main-nav .auth-menu-dropdown {
    display: flex;
  }
  .main-nav .auth-user {
    max-width: none;
  }

  .main-content {
    padding: 1.35rem 1rem 3rem;
    max-width: 100%;
  }

  .main-content.home-active {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .site-footer {
    padding: 2rem 1rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  }

  .footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
  }

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

  h1 {
    font-size: clamp(1.65rem, 6vw, 2.35rem);
  }

  .hero h1,
  .home-hero h1 {
    font-size: clamp(1.85rem, 7.2vw, 2.5rem);
    max-width: none;
  }

  .home-hero {
    gap: 1.75rem;
    padding-top: 0.35rem;
  }

  .home-hero-badge {
    display: none;
  }

  .home-cta {
    white-space: normal;
  }

  .home-hero-actions .btn,
  .home-cta {
    min-height: 2.75rem;
  }

  .home-stat-value {
    font-size: 1.7rem;
  }

  .home-qbank,
  .home-targeted {
    padding: 1.25rem 1rem 1.4rem;
  }

  .home-qbank-copy h2,
  .home-feature-content h2,
  .home-targeted-copy h2 {
    max-width: none;
    overflow-wrap: break-word;
  }

  .home-targeted-part {
    min-height: 2.75rem;
  }

  .home-targeted-path {
    justify-content: flex-start;
  }

  .home-exam-body {
    grid-template-columns: 4.4rem minmax(0, 1fr);
  }

  .home-listen-extracts {
    grid-template-columns: 1fr;
  }

  .home-read-split,
  .home-write-split {
    grid-template-columns: 1fr;
  }

  .home-read-texts,
  .home-write-notes {
    border-right: 0;
    border-bottom: 1px solid #e2e8f0;
  }

  .home-tool-stats {
    grid-template-columns: 1fr;
  }

  .home-tool-stats .home-cta {
    grid-column: 1;
  }

  .home-access-inner,
  .home-free-inner,
  .home-final-cta {
    padding: 1.6rem 1.1rem;
  }

  .home-feature-section {
    padding: 1.15rem;
  }

  .btn {
    min-height: 2.75rem;
  }

  .form-field input,
  .form-field select,
  .form-field textarea,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px;
  }

  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    max-width: none;
    width: 100%;
    max-height: min(92dvh, 100%);
    overflow-y: auto;
    border-radius: 18px 18px 0 0;
    padding: 1.35rem 1.15rem calc(1.35rem + env(safe-area-inset-bottom, 0px));
    margin: 0;
  }

  .modal-actions {
    flex-wrap: wrap;
  }
  .modal-actions .btn {
    flex: 1 1 8rem;
  }

  .modal-close {
    position: absolute;
    top: 0.65rem;
    right: 0.65rem;
  }

  .practice-exam-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.1rem;
  }

  .practice-exam-head {
    margin-bottom: 1.65rem;
  }

  .exclusive-exams-btn {
    min-width: 0;
    flex: 1 1 11rem;
  }
}

@media (max-width: 767px) {
  .footer-grid {
    grid-template-columns: 1fr;
  }

  .home-hero-actions {
    flex-direction: column;
  }

  .home-hero-actions .btn,
  .home-inline-actions .btn,
  .home-access-actions .btn,
  .home-free-actions .btn,
  .home-final-actions .btn {
    width: 100%;
  }

  .home-targeted-path li {
    font-size: 0.78rem;
  }

  .home-stats-grid {
    gap: 0.7rem;
  }

  .home-page {
    --home-section-gap: 3.25rem;
  }

  .logo-wordmark {
    height: 1.4rem;
    max-width: min(9.5rem, 42vw);
  }

  .main-content {
    padding: 1.1rem 0.85rem 2.75rem;
  }

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

  .practice-exam-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.95rem;
  }

  .mock-test-card--compact {
    padding: 1.1rem 1rem 1.1rem;
    gap: 0.85rem;
  }

  .main-content:has(#practice-root) > p:first-child {
    margin-bottom: 0.9rem;
  }

  .exclusive-exams-btn {
    flex: 1 1 100%;
    max-width: none;
    min-width: 0;
    width: 100%;
  }

  .page-lead {
    font-size: 1rem;
  }

  .btn-block,
  .auth-form .btn-primary,
  .spelling-actions .btn-primary,
  .rpb-actions .btn-primary {
    width: 100%;
  }

  .modal-actions .btn-primary {
    width: 100%;
    flex: 1 1 100%;
  }
}

/* ----- Modal close control (all widths; compact on desktop) ----- */
.modal {
  position: relative;
}

.modal-close {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--surface-solid);
}

/* ----- Forms, cards, media ----- */
@media (max-width: 767px) {
  .card {
    padding: 1rem;
  }

  .hl-toolbar,
  .reading-pdf-hl-toolbar,
  .oet-reading-hl-toolbar {
    flex-wrap: wrap;
  }

  .highlight-hint {
    width: 100%;
    margin-left: 0;
  }

  audio {
    width: 100%;
    max-width: 100%;
  }

  .audio-controls,
  .lpb-audio,
  .lpa-audio,
  .lpb-audio-transport {
    max-width: 100%;
  }

  .lpb-audio,
  .lpa-audio {
    max-width: none;
  }

  .lpb-play-btn,
  .lpb-skip-btn {
    min-height: 2.75rem;
    padding: 0.55rem 0.85rem;
  }

  .mcq-option {
    min-height: 2.75rem;
    padding: 0.85rem 0.9rem;
    overflow-wrap: anywhere;
  }

  .gap-input {
    font-size: 16px;
    min-width: 0;
  }

  .gap-fill-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ----- Dashboard / results ----- */
@media (max-width: 767px) {
  .dashboard-head,
  .exam-dashboard-head,
  .gallery-admin-head,
  .rpb-practice-header,
  .attempts-tab-head {
    flex-direction: column;
    align-items: stretch;
  }

  .dashboard-head .btn,
  .exam-dashboard-head .btn {
    width: 100%;
  }

  .results-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-score-menu > summary {
    padding: 1rem 1.1rem;
    min-height: 3.5rem;
  }

  .dashboard-score-menu-title {
    font-size: 1.05rem;
  }

  .dashboard-score-menu-body {
    padding: 0 1.1rem 1.1rem;
  }

  .dashboard-score-item {
    flex-wrap: wrap;
  }

  .results-toolbar,
  .attempt-filter {
    flex-direction: column;
    align-items: stretch;
  }

  .attempt-filter select {
    width: 100%;
    min-height: 2.75rem;
    font-size: 16px;
  }
}

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

/* ----- Tables: cards on small screens; keep desktop tables ----- */
@media (max-width: 767px) {
  .attempts-table-wrap,
  .word-list-table-wrap,
  .reading-answer-table-wrap {
    overflow: visible;
  }

  .attempts-table thead,
  .word-list-table thead,
  .reading-answer-table thead {
    display: none;
  }

  .attempts-table,
  .word-list-table,
  .reading-answer-table,
  .attempts-table tbody,
  .word-list-table tbody,
  .reading-answer-table tbody {
    display: block;
    width: 100%;
  }

  .attempts-table tr,
  .word-list-table tr,
  .reading-answer-table tr {
    display: grid;
    gap: 0.35rem;
    width: 100%;
    margin: 0 0 0.75rem;
    padding: 0.85rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-solid);
  }

  .attempts-table th,
  .attempts-table td,
  .word-list-table th,
  .word-list-table td,
  .reading-answer-table th,
  .reading-answer-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    width: 100%;
    padding: 0.2rem 0;
    border: none;
    text-align: right;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .attempts-table td::before,
  .word-list-table td::before,
  .reading-answer-table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-muted);
    text-align: left;
    flex: 0 0 auto;
    max-width: 42%;
  }

  .attempts-table td:not([data-label])::before,
  .word-list-table td:not([data-label])::before,
  .word-list-table td[data-label=""]::before,
  .attempts-table td[data-label=""]::before {
    display: none;
  }

  .attempts-table tr.attempt-detail-row,
  .attempts-table tr.attempt-detail-row td {
    display: block;
  }

  .attempts-table tr.attempt-detail-row td::before {
    display: none;
  }

  .word-list-table .spelling-audio-col,
  .word-list-table .spelling-audio-cell,
  .word-list-table .spelling-icons-col,
  .word-list-table .spelling-icons-cell,
  .word-list-table .word-list-num-col {
    width: auto;
    white-space: normal;
  }

  .spelling-audio-actions,
  .spelling-word-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .spelling-fav-btn,
  .spelling-listen-sm,
  .spelling-ar-toggle {
    min-width: 2.75rem;
    min-height: 2.75rem;
  }
}

/* Course comparison keeps columns — controlled scroll only on that widget */
@media (max-width: 767px) {
  .cmp-scroll {
    margin-inline: -0.25rem;
  }
}

/* ----- Question banks ----- */
@media (max-width: 767px) {
  .rpb-layout,
  .lpb-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .rpb-index {
    position: static;
    max-height: 14rem;
  }

  .rpb-index-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .rpb-index-btn {
    min-height: 2.75rem;
    height: 2.75rem;
  }

  .rpb-header-actions,
  .rpb-actions {
    width: 100%;
  }

  .rpb-flag-btn,
  .rpb-actions .btn {
    min-height: 2.75rem;
    flex: 1 1 auto;
  }

  .rpb-timer {
    font-size: 1.2rem;
    width: 100%;
    text-align: center;
  }

  .rpb-question-panel,
  .rpb-passage,
  .rpb-feedback {
    overflow-wrap: anywhere;
  }
}

@media (max-width: 419px) {
  .rpb-index-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* ----- Spelling & vocabulary ----- */
@media (max-width: 767px) {
  .spelling-play-btn {
    width: 100%;
    min-width: 0;
    min-height: 3rem;
  }

  .spelling-play-row {
    flex-direction: column;
  }

  .spelling-input {
    font-size: 1.15rem;
    min-height: 3rem;
  }

  .spelling-actions {
    flex-direction: column;
  }

  .spelling-actions .btn {
    width: 100%;
  }

  .spelling-word-display {
    font-size: clamp(1.25rem, 6vw, 1.75rem);
    overflow-wrap: anywhere;
  }

  .spelling-options,
  .spelling-tab-filters,
  .vocab-filters {
    grid-template-columns: 1fr;
  }

  .vocab-card,
  .spelling-session-card,
  .spelling-category-card {
    overflow-wrap: anywhere;
  }

  .vocab-nav-btn,
  .spelling-nav-btn,
  .notebook-nav-btn {
    min-height: 2.5rem;
  }
}

/* ----- Practice / courses / notebook ----- */
@media (max-width: 767px) {
  .practice-block-title {
    font-size: 1.05rem;
    padding: 0 0 0.6rem;
    margin-bottom: 0.8rem;
  }

  .practice-block {
    margin-bottom: 1.5rem;
  }

  .practice-hero {
    margin-bottom: 1.35rem;
  }

  .practice-hero h1 {
    font-size: clamp(1.6rem, 7vw, 2.1rem);
  }

  .practice-skill-card,
  .practice-tool-card {
    padding: 0.9rem 0.8rem 0.85rem;
  }

  .practice-icon {
    width: 2.85rem;
    height: 2.85rem;
  }

  .practice-icon svg {
    width: 1.55rem;
    height: 1.55rem;
  }

  .admin-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.2rem;
  }

  .admin-tab {
    flex: 0 0 auto;
    min-height: 2.5rem;
  }

  .notebook-exam-date-head {
    flex-direction: column;
    align-items: stretch;
  }

  .writing-area {
    min-height: 16rem;
    font-size: 16px;
  }
}

/* ----- Exam chrome (non-OET shell) ----- */
@media (max-width: 767px) {
  .exam-bar {
    gap: 0.55rem;
    padding: 0.7rem 0.85rem;
    margin-left: -0.85rem;
    margin-right: -0.85rem;
  }

  .main-content.exam-active {
    padding-top: calc(var(--exam-bar-h) + 0.75rem);
  }

  .main-content.exam-active .exam-bar {
    padding-left: max(0.85rem, env(safe-area-inset-left));
    padding-right: max(0.85rem, env(safe-area-inset-right));
  }

  .main-content.exam-active #exam-workspace {
    padding: 0 0.85rem 3rem;
  }

  .exam-bar .timer {
    font-size: 1.15rem;
  }

  .exam-bar .phase {
    flex: 1 1 100%;
    font-size: 0.82rem;
  }
}

/* ----- Reading split: Passage | Questions toggle on phones ----- */
@media (max-width: 767px) {
  .exam-pane-tabs {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 6;
    gap: 0.35rem;
    margin: 0 0 0.65rem;
    padding: 0.3rem;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-sm);
  }

  .oet-practice .exam-pane-tabs {
    background: #ffffff;
    border-color: #b8c4d4;
  }

  .exam-pane-tab {
    flex: 1;
    min-height: 2.5rem;
    border: none;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
  }

  .exam-pane-tab.is-active {
    background: rgba(99, 102, 241, 0.14);
    color: var(--primary-dark);
  }

  .oet-practice .exam-pane-tab.is-active {
    background: #1e3a6e;
    color: #fff;
  }

  .reading-part-a-split {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
    height: auto;
    min-height: 0;
  }

  .reading-part-a-split[data-mobile-pane="texts"] .reading-part-a-pane--questions,
  .reading-part-a-split[data-mobile-pane="questions"] .reading-part-a-pane--texts,
  .reading-part-a-split[data-mobile-pane="questions"] .reading-part-a-pane--pdf {
    display: none;
  }

  .oet-reading-layout-split[data-mobile-pane="texts"] .oet-reading-layout-questions,
  .oet-reading-layout-split[data-mobile-pane="questions"] .oet-reading-layout-texts {
    display: none;
  }

  .oet-reading-bc-workspace--split[data-mobile-pane="texts"] .oet-reading-bc-questions-pane,
  .oet-reading-bc-workspace--split[data-mobile-pane="questions"] .oet-reading-bc-passage {
    display: none;
  }

  .reading-part-a-pane {
    min-height: min(62dvh, 32rem);
    overflow-wrap: anywhere;
  }

  .oet-practice .oet-reading-layout-texts,
  .oet-practice .oet-reading-layout-questions,
  .oet-practice .oet-reading-bc-passage,
  .oet-practice .oet-reading-bc-questions-pane {
    min-height: 0;
    overflow-wrap: anywhere;
  }

  .reading-part-a-pane--texts {
    border-right: none;
    border-bottom: none;
  }
}

/* ----- Full-exam mobile notice ----- */
.exam-mobile-notice {
  position: fixed;
  left: 0.75rem;
  right: 0.75rem;
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  z-index: 180;
  display: none;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 0.95rem;
  background: var(--surface-solid);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.exam-mobile-notice.is-visible {
  display: flex;
}

.exam-mobile-notice p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.45;
  flex: 1;
}

.exam-mobile-notice-dismiss {
  flex-shrink: 0;
  min-height: 2.5rem;
  padding: 0.4rem 0.85rem;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

@media (min-width: 768px) {
  .exam-mobile-notice {
    display: none !important;
  }
}
