/* mobile-fixes.css — compact mobile layer (loaded LAST so it wins over
   every feature stylesheet).
   Strategy:
     1. Uniform downscale via root font-size — every rem-sized element
        shrinks proportionally ("সব ছোট ছোট"): ≤560px → 15px, ≤420px → 14px.
     2. iOS safe-area (notch / home indicator) — fixed bars never sit under
        the status bar or overlap the home indicator.
     3. Overflow hardening — tables scroll inside, never the page. */

/* ---- 1. Fluid typography — scales smoothly with viewport width ---- */
html{
  /* Base 16px, clamps between 15px (small phones) and 18px (1200px+).
     The floor used to drop to 12–13px on small phones, which made body
     text hard to read for students — 15px is the comfort floor now. */
  font-size:clamp(15px, 1.1vw + 9px, 18px);
}
@media(max-width:560px){
  html{font-size:clamp(14.5px, 3.2vw + 3px, 15.5px)}
}
@media(max-width:420px){
  html{font-size:clamp(14.5px, 3.5vw + 1px, 15px)}
}
@media(min-width:1600px){
  html{font-size:18px}
}

/* ---- 2. iOS safe-area ---- */
@media(max-width:980px){
  header{
    height:auto;
    min-height:calc(60px + env(safe-area-inset-top,0px));
    padding-top:calc(env(safe-area-inset-top,0px) + 8px) !important;
    padding-bottom:calc(env(safe-area-inset-top,0px) + 8px) !important;
  }
  .bottom-nav{
    padding-bottom:calc(4px + env(safe-area-inset-bottom,0px));
  }
  .install-card{bottom:calc(74px + env(safe-area-inset-bottom,0px))}
  #tts-toggle-fab{bottom:calc(72px + env(safe-area-inset-bottom,0px))}
  .note-fab{bottom:calc(176px + env(safe-area-inset-bottom,0px))}
  .chat-fab{bottom:calc(124px + env(safe-area-inset-bottom,0px)) !important}
  .content{padding-bottom:calc(90px + env(safe-area-inset-bottom,0px)) !important}
}

/* ---- 3. Overflow hardening — tables scroll horizontally inside,
   and no child ever forces the page to scroll sideways ---- */
@media(max-width:640px){
  table,
  .feature-matrix,
  .lb-table{
    display:block;
    max-width:100%;
    overflow-x:auto;
  }
  .content .card table{white-space:nowrap}
  .preview-row,.list-item,.notice{min-width:0}
  .chat-shell-input{grid-template-columns:1fr auto auto}
  .chat-shell-input textarea{min-width:0}
  /* Grid/flex children may never exceed the viewport — min-width:0 lets
     them shrink below their content instead of forcing horizontal scroll. */
  .dashboard-widget-grid > *,
  .preview-grid > *,
  .feature-grid > *,
  .recent-notes-grid > *,
  #resource-list > *,
  #resource-shared-list > *,
  .manage-grid > *,
  .community-grid > *,
  .qbclass-subjects,
  .qbclass-widget-body,
  .gm-dash-card,
  .dash-task-main,
  .dash-lb-name{min-width:0;max-width:100%}
}

/* ---- 4. Floating buttons never cover card content ----
   FABs use position:fixed and float OVER content — no padding-right needed.
   Content uses full viewport width on mobile. */
@media(max-width:600px){
  .content{padding-right:12px !important}
}
@media(max-width:420px){
  .content{padding-right:10px !important}
}

/* ---- 4b. Horizontal scroll utility ----
   Use .hs on any container that should scroll horizontally.
   Page itself never scrolls sideways. */
.hs{
  width:100%;max-width:100%;min-width:0;
  overflow-x:auto;overflow-y:hidden;
  display:flex;flex-wrap:nowrap;gap:8px;
  -webkit-overflow-scrolling:touch;
  overscroll-behavior-x:contain;
  scrollbar-width:thin;
  padding-bottom:4px;
}
.hs>*{flex:0 0 auto;min-width:0}
.hs::-webkit-scrollbar{height:4px}
.hs::-webkit-scrollbar-thumb{background:var(--border);border-radius:99px}

/* ---- 5. Fluid spacing & component scaling ---- */
/* Everything uses clamp() for smooth scaling between mobile and desktop */
@media(max-width:980px){
  .card,.manage-card,.resource-card,.stat-card,.note-card,.focus-card,
  .focus-history,.syllabus-card,.planner-card,.list-item,.faq-item,
  .preview-card,.revision-panel,.dashboard-banner,.auth-card,.auth-brand,
  .modal-card,.chat-shell,.resource-card{
    padding:clamp(10px, 2vw, 16px);
    border-radius:clamp(10px, 2vw, 16px);
  }
  .btn{padding:clamp(6px, 1.2vw, 10px) clamp(8px, 1.5vw, 14px);font-size:clamp(.72rem, 1.1vw, .86rem)}
  .btn-sm{padding:clamp(4px, 0.8vw, 6px) clamp(6px, 1vw, 10px);font-size:clamp(.64rem, 0.9vw, .78rem)}
  .btn-lg{padding:clamp(8px, 1.4vw, 12px) clamp(12px, 1.8vw, 18px);font-size:clamp(.82rem, 1.1vw, .95rem)}
}

/* ---- 6. Smooth font scaling for all text elements ---- */
@media(max-width:768px){
  .section-title{font-size:clamp(.88rem, 2.5vw, 1.1rem)}
  .card-title{font-size:clamp(.78rem, 2.2vw, .95rem)}
  .note-title{font-size:clamp(.76rem, 2.2vw, .92rem)}
  .stat-value{font-size:clamp(1rem, 3vw, 1.6rem)}
  .brain-greeting{font-size:clamp(.9rem, 3vw, 1.5rem)}
  .brain-subtitle{font-size:clamp(.68rem, 1.8vw, .84rem)}
  .detail-title{font-size:clamp(.82rem, 2.4vw, 1.05rem)}
  .modal-title{font-size:clamp(.8rem, 2.2vw, 1rem)}
  .chat-msg{font-size:clamp(.72rem, 2vw, .86rem)}
  .question-q{font-size:clamp(.76rem, 2.2vw, .92rem)}
  .focus-big-timer{font-size:clamp(1.2rem, 4vw, 2rem)}
}

/* ---- 7. Touch-friendly sizing for all interactive elements ---- */
@media(max-width:980px){
  /* Minimum 40px touch targets for all interactive elements */
  .btn-icon,.modal-close,.input-action,.chat-send,.chat-hub-head button,
  .note-actions .btn-icon,.detail-action-btn,.setup-item input[type="checkbox"],
  .syllabus-chk input[type="checkbox"]{
    min-width:40px;min-height:40px
  }
  /* Minimum 36px for secondary interactive elements */
  .filter-tab,.focus-stat-tab,.rr-tab,.nav-item,
  .daily-target-select,.syllabus-card-head{
    min-height:36px
  }
  /* Minimum 44px for primary touch targets */
  .dm-friend,.sb-palette-item,.chapter-item,.mcq-option,.kd-opt{
    min-height:44px
  }
  /* Larger toggle switches on mobile */
  .tgl{width:48px;height:26px}
  .tgl-sl::before{width:20px;height:20px;top:3px;left:3px}
  .tgl input:checked + .tgl-sl::before{transform:translateX(22px)}
  /* Larger checkboxes */
  input[type="checkbox"]{min-width:18px;min-height:18px}
  input[type="radio"]{min-width:18px;min-height:18px}
  /* Larger color pickers */
  input[type="color"]{min-height:44px;min-width:44px}
  /* Larger file inputs */
  input[type="file"]{min-height:44px;padding:14px 12px;font-size:.8rem}
  input[type="file"]::file-selector-button{min-height:36px;padding:8px 14px}
}

/* ---- 8. Scrollable areas get proper momentum scrolling ---- */
@media(max-width:768px){
  .notes-grid,.feature-grid,.recent-notes-grid,.preview-grid,
  .dashboard-widget-grid,.manage-grid,.community-grid,.package-grid,
  .focus-date-sessions,.chapter-list,.questions-panel,
  .planner-subjects,.syllabus-card-chapters,.planner-routine,
  .subject-tags,.subject-manager-list{
    max-height:min(80vh, 600px);
    overflow-y:auto;
    -webkit-overflow-scrolling:touch;
    overscroll-behavior-y:contain
  }
  /* Horizontal scroll for wide tables/lists */
  .feature-matrix,.lb-table,.sb-table-wrap,.syllabus-ocr-class{
    overflow-x:auto;
    -webkit-overflow-scrolling:touch
  }
}

/* ---- 9. Auth screen responsive ---- */
@media(max-width:768px){
  .auth-card{grid-template-columns:1fr;gap:10px}
  .auth-brand{padding:14px}
  .auth-tabs{gap:6px}
  .secure-auth-note{font-size:.74rem}
}
@media(max-width:480px){
  .auth-card{padding:12px}
  .auth-brand{padding:10px;font-size:.82rem}
  .auth-tabs .btn{padding:5px 8px;font-size:.72rem}
}

/* ---- 10. Settings responsive ---- */
@media(max-width:1100px){
  .settings-layout{grid-template-columns:1fr}
  .settings-nav{flex-wrap:wrap;gap:4px}
  .settings-nav .nav-item{padding:6px 10px;font-size:.78rem}
}
@media(max-width:760px){
  .settings-nav{gap:3px}
  .settings-nav .nav-item{min-height:36px;font-size:.74rem;padding:5px 8px}
}

/* ---- 11. DM / Social responsive ---- */
@media(max-width:768px){
  .dm-layout{grid-template-columns:1fr}
  .dm-sidebar{max-height:35vh;flex:none}
  .dm-friend{min-height:44px;padding:8px 10px}
  .community-grid{grid-template-columns:1fr}
  .community-card{padding:10px 12px}
}
@media(max-width:560px){
  .dm-layout{grid-template-columns:1fr}
  .dm-sidebar{max-height:30vh}
  .dm-friend{padding:7px 9px}
}

/* ---- 12. Gamification / Duels / Races responsive ---- */
@media(max-width:768px){
  .kd-card{padding:10px 12px}
  .kd-opt{padding:6px 10px}
  .lr-row{padding:8px 10px}
  .lr-room{padding:8px 10px}
  .rr-tab{padding:5px 10px}
  .gm-dash-card{padding:10px 12px}
  .sb-palette-item{padding:8px 10px}
  .notif-item{padding:8px 10px}
}
@media(max-width:560px){
  .kd-card{padding:8px 10px}
  .kd-opt{padding:5px 8px;font-size:.76rem}
  .lr-row{padding:6px 8px}
  .lr-room{padding:6px 8px}
  .notif-item{padding:6px 8px;font-size:.74rem}
  .sb-palette-item{padding:6px 8px}
}

/* ---- 13. YouTube / Media responsive ---- */
@media(max-width:768px){
  .yt-player-inner{grid-template-columns:1fr}
  .yt-player-side{border-left:0;border-top:1px solid var(--border);padding-top:12px}
  .yt-course-card{padding:10px 12px}
  .yt-course-title{font-size:.84rem}
  .yt-course-meta{font-size:.7rem}
}
@media(max-width:560px){
  .yt-player-inner{grid-template-columns:1fr}
  .yt-course-card{padding:8px 10px}
  .yt-course-title{font-size:.78rem}
}

/* ---- 14. Leaderboard responsive ---- */
@media(max-width:768px){
  .lb-tabs{flex-wrap:wrap;gap:4px}
  .lb-tab{padding:5px 10px;font-size:.72rem}
  .lb-table{font-size:.76rem}
  .lb-table th,.lb-table td{padding:5px 4px}
}
@media(max-width:560px){
  .lb-table{font-size:.7rem}
  .lb-table th,.lb-table td{padding:4px 3px}
}

/* ---- 15. Notes detail responsive ---- */
@media(max-width:768px){
  .detail-actions-grid{grid-template-columns:repeat(auto-fit,minmax(100px,1fr));gap:6px}
  .detail-action-btn{padding:7px 9px;font-size:.74rem}
  .note-detail-content{padding:12px 14px;font-size:.85rem}
  .note-detail-meta{gap:6px;font-size:.7rem}
  .tts-speed-control{font-size:.68rem;padding:4px 8px}
  .tts-speed-slider{height:3px}
  .tts-speed-slider::-webkit-slider-thumb{width:14px;height:14px}
}

/* ---- 16. Public landing page responsive ---- */
@media(max-width:768px){
  .pl-hero{padding:20px 16px}
  .pl-hero h1{font-size:1.3rem}
  .pl-hero p{font-size:.82rem}
  .pl-features{grid-template-columns:1fr}
  .pl-feature-card{padding:12px 14px}
  .pl-feature-title{font-size:.88rem}
  .pl-feature-desc{font-size:.78rem}
  .pl-pricing{grid-template-columns:1fr}
  .pl-pkg{padding:14px}
  .pl-pkg-name{font-size:.9rem}
  .pl-pkg-price{font-size:1.1rem}
  .pl-faq{gap:6px}
  .pl-faq-q{font-size:.8rem;padding:9px 11px}
  .pl-faq-a{font-size:.76rem}
}
@media(max-width:560px){
  .pl-hero h1{font-size:1.1rem}
  .pl-hero p{font-size:.76rem}
  .pl-feature-card{padding:10px 12px}
  .pl-feature-title{font-size:.82rem}
  .pl-pkg{padding:12px}
  .pl-pkg-name{font-size:.84rem}
  .pl-pkg-price{font-size:1rem}
}

/* ---- 17. SaaS / Payment responsive ---- */
@media(max-width:768px){
  .pay-method-list{grid-template-columns:1fr 1fr}
  .pkg-summary{flex-direction:column;text-align:center;gap:8px}
  .refer-stats{grid-template-columns:repeat(3,1fr)}
  .refer-stat-num{font-size:1.2rem}
  .refer-stat{padding:8px 6px}
  .refer-table{font-size:.72rem}
  .refer-code{font-size:1rem}
}
@media(max-width:560px){
  .pay-method-list{grid-template-columns:1fr}
  .refer-stats{grid-template-columns:1fr 1fr 1fr;gap:6px}
  .refer-stat-num{font-size:1.1rem}
  .refer-share{flex-direction:column}
  .refer-share .btn{width:100%}
}

/* ---- 18. Table responsive ---- */
@media(max-width:560px){
  table{font-size:.78rem}
  table th,table td{padding:5px 4px}
  .feature-matrix{font-size:.72rem}
  .lb-table{display:block;overflow-x:auto;white-space:nowrap}
  .sb-table-wrap{overflow-x:auto}
}

/* ---- 19. Notice / Banner responsive ---- */
@media(max-width:560px){
  .notice{grid-template-columns:auto 1fr;gap:8px;padding:10px}
  .notice-close{position:absolute;top:6px;right:6px}
  .notice{position:relative}
  .notice-popup{left:6px;right:6px;transform:none;max-width:none;bottom:14px}
  .install-card{bottom:calc(74px + env(safe-area-inset-bottom))}
}

/* ---- 20. Dashboard overflow prevention ---- */
@media(max-width:600px){
  .preview-grid,
  .feature-grid,
  .dashboard-widget-grid{
    gap:8px;
  }
  .preview-grid > *,
  .feature-grid > *,
  .dashboard-widget-grid > *{
    min-width:0;
    max-width:100%;
    overflow:hidden;
  }
  .preview-title,
  .preview-row-name,
  .dash-task-title,
  .dash-lb-name{
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
  }
  .preview-row{
    min-width:0;
    overflow:hidden;
  }
  .preview-card{
    padding:10px;
  }
}

/* ---- 21. Daily target + focus timer compact on very small screens ---- */
@media(max-width:420px){
  .daily-target-header{
    border-radius:8px;
    padding:4px 6px;
  }
  .daily-target-label{
    font-size:.6rem;
    max-width:60%;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
  }
  .daily-target-pct{
    font-size:.58rem;
  }
  .focus-timer-header .focus-time-pill{
    padding:4px 8px;
    font-size:.72rem;
  }
}

/* ---- 22. Brain hero subtitle on very small screens ---- */
@media(max-width:380px){
  .brain-subtitle{
    display:none;
  }
  .brain-greeting{
    font-size:.88rem;
  }
}

/* ---- 23. School info / qbclass widget compact on mobile ---- */
@media(max-width:600px){
  .qbclass-widget-head{
    flex-wrap:wrap;
    gap:6px;
  }
  .qbclass-class-badge{
    font-size:.72rem;
    padding:3px 8px;
  }
  .qbclass-widget-actions{
    gap:6px;
  }
  .qbclass-widget-actions .btn{
    font-size:.68rem;
    padding:4px 8px;
  }
  .qbclass-subjects{
    gap:5px;
  }
  .chip{
    font-size:.76rem;
    padding:5px 10px;
  }
}

/* ---- 24. Content full width on mobile (no black gap) ---- */
@media(max-width:768px){
  .main-layout{
    grid-template-columns:1fr;
  }
  .content{
    width:100%;
    min-width:0;
    overflow-x:hidden;
  }
}

/* ---- 25. UX comfort pass (student phones, night reading, slow data) ----
   Loaded last, so these win over every feature stylesheet. */

/* Form controls at a true 16px on small screens — anything smaller makes
   iOS Safari auto-zoom on focus, which feels broken mid-study. px (not
   rem) so the root font-size scaling can never shrink it back down. */
@media(max-width:768px){
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]),
  select,
  textarea{
    font-size:16px !important;
  }
}

/* Touch targets: fingers get ~44px wherever the desktop design is tighter.
   pointer:coarse = touch devices only, mouse layouts stay untouched. */
@media(pointer:coarse){
  .btn{min-height:44px}
  .btn-sm{min-height:40px}
  .btn-icon{width:44px;height:44px}
  .user-avatar{width:40px;height:40px}
  .nav-item{min-height:44px}
  .bottom-nav-item{min-height:50px;justify-content:center}
  .filter-tab{min-height:40px;display:inline-flex;align-items:center}
  .lb-tab{min-height:40px}
  .cm-tab{min-height:40px}
  .chip{min-height:36px;display:inline-flex;align-items:center}
  .toast-action{min-height:40px;display:inline-flex;align-items:center}
  .sb-install-close{width:40px;height:40px}
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  select{min-height:44px}
}

/* Tap feedback for tappable chips/tabs that had none, and no grey flash. */
a,button,[role="button"],input,select,textarea,label{-webkit-tap-highlight-color:transparent}
.filter-tab,.lb-tab,.cm-tab,.chip{transition:transform var(--dur-fast) var(--ease-accel),background var(--dur-fast),color var(--dur-fast),border-color var(--dur-fast)}
.filter-tab:active,.lb-tab:active,.cm-tab:active,.chip:active{transform:scale(.96)}

/* Embedded media can never push the page sideways. */
video,iframe{max-width:100%}