/* v2.9.1 — mobile-first usability and touch refinements */
html { min-width: 320px; -webkit-text-size-adjust: 100%; }
body { min-width: 320px; overflow-x: hidden; }
img, video, iframe, canvas, svg { max-width: 100%; }
button, input, select, textarea { touch-action: manipulation; }
:focus-visible { outline: 2px solid #66d9e9; outline-offset: 2px; }

/* The drawer scrim sits above the page and below the navigation drawer. */
.sidebar-backdrop { display: none; }

@media (max-width: 980px) {
  .sidebar { z-index: 50; padding-top: max(18px, env(safe-area-inset-top)); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 49;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    padding: 0;
    background: rgba(3, 8, 19, .62);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease, visibility .2s ease;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
  }
  .sidebar-backdrop.is-visible { opacity: 1; visibility: visible; pointer-events: auto; }
  .main-nav { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .mobile-menu { min-width: 44px; min-height: 44px; }
}

@media (max-width: 760px) {
  .main-area, .content-wrap, .view, .panel, .stat-card,
  .dashboard-priority-grid > *, .dashboard-secondary-grid > *,
  .library-results-grid > *, .study-subject-grid > * { min-width: 0; max-width: 100%; }
  .content-wrap { padding-bottom: calc(86px + env(safe-area-inset-bottom)); overflow-x: clip; }
  .topbar { padding-left: max(11px, env(safe-area-inset-left)); padding-right: max(11px, env(safe-area-inset-right)); }
  .btn, .icon-btn, .language-btn, .text-btn, .nav-item,
  .priority-exam-action, .priority-sub-link, .library-tab,
  .chapter-pick, .attempt-option, .quiz-nav-dot,
  .task-check, .ai-float-icon, .ai-float-send {
    min-height: 44px;
  }
  .nav-item { padding-top: 10px; padding-bottom: 10px; }
  input, select, textarea,
  .library-filter-row select, .exam-config-grid select,
  .board-exam-config select, .ai-float-controls select {
    min-height: 44px;
    font-size: 16px !important;
  }
  .ai-float-root {
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .ai-float-panel {
    width: min(390px, calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    height: min(590px, calc(100dvh - 88px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
    min-height: min(360px, calc(100dvh - 88px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  }
  .ai-float-form { grid-template-columns: minmax(0, 1fr) 44px; }
  .ai-float-form textarea { min-height: 44px; font-size: 16px; }
  .ai-float-send { width: 44px; height: 44px; }
  .dashboard-heading-actions { display: flex !important; width: 100%; }
  .dashboard-heading-actions .btn { width: 100%; justify-content: center; }
  .dashboard-task-preview { overflow-y: auto; overscroll-behavior: contain; }
  .dashboard-focus-subject-label select { width: 100%; }
  .library-resource-copy p, .priority-card-caption { font-size: 12px; line-height: 1.6; }
  .library-resource-card .resource-type, .library-resource-card .resource-access,
  .library-resource-card .resource-tags span { font-size: 9px; }
  .quiz-modal-card { width: calc(100vw - 20px); max-width: 100%; max-height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .quiz-modal { padding: 10px; }
  .exam-config-grid, .board-exam-config, .board-archive-filters,
  .library-filter-row, .resource-form, .submission-form { min-width: 0; }
  .exam-config-grid label, .board-exam-config label, .library-filter-row label { min-width: 0; }
  .chapter-pick { min-height: 48px; }
  .attempt-option { display: flex; align-items: center; gap: 9px; padding-top: 10px; padding-bottom: 10px; }
  .app-footer { flex-wrap: wrap; gap: 8px; padding: 16px 13px calc(20px + env(safe-area-inset-bottom)); }
}

@media (max-width: 480px) {
  .content-wrap { padding-left: 12px; padding-right: 12px; }
  .topbar { gap: 7px; }
  .top-actions { gap: 5px; }
  .language-btn { padding-inline: 9px; }
  .breadcrumb { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page-heading h1 { overflow-wrap: anywhere; }
  .dashboard-timer-controls { display: grid; grid-template-columns: 1fr 1fr; }
  .dashboard-timer-controls .btn:first-child { grid-column: 1 / -1; }
  .dashboard-task-preview .task-item { align-items: flex-start; }
  .dashboard-task-preview .task-content { min-width: 0; }
  .library-tabs { gap: 7px; }
  .library-tab { min-width: 0; line-height: 1.35; }
  .library-provider-search-card { flex-direction: column; }
  .provider-search-actions { width: 100%; }
  .provider-search-actions .btn, .provider-search-actions a { min-height: 44px; display: inline-flex; align-items: center; }
  .quiz-modal-card { padding: 12px; }
  .quiz-modal-actions { flex-wrap: wrap; }
}

@media (max-width: 360px) {
  .module-grid, .quick-actions, .study-subject-actions { grid-template-columns: 1fr 1fr; }
  .ai-float-launcher { min-height: 50px; }
  .ai-float-panel { border-radius: 16px; }
  .exam-config-grid { grid-template-columns: 1fr !important; }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 980px) {
  .ai-float-panel { height: calc(100dvh - 22px); min-height: 0; }
  .ai-float-controls { grid-template-columns: 1fr 1fr; }
}

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