/* ==========================================================================
   FAST MATHS - Phone-Only & Touch Responsive Stylesheet (v3.1)
   HARD GUARD: Every rule in this file is strictly scoped to:
     - @media (max-width: 767px)
     - @media (max-width: 900px) and (max-height: 500px) and (orientation: landscape)
     - @media (hover: none) and (pointer: coarse)
   Desktop & MacBook viewports (>= 768px) are 100% untouched.
   ========================================================================== */

/* Desktop default: hide phone-only elements cleanly */
#mobile-pill-navbar-root,
.mobile-bottom-nav,
.mobile-drawer-account,
.phone-kbd-toggle-btn {
  display: none;
}

@media (min-width: 768px) {
  #mobile-pill-navbar-root,
  .fm-mob-popover-scrim,
  .fm-mob-sheet-scrim {
    display: none !important;
  }
}

@media (hover: none) and (pointer: coarse) {
  button, a, input, select, textarea {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  .calc-btn-7a,
  .mcq-option-pill {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
  .shortcut-hint-badge,
  .search-shortcut-badge,
  .theme-toggle-btn[data-tooltip]:hover::after {
    display: none !important;
  }
}

@media (max-width: 767px) {
  /* ---- Core iOS & Android Viewport / Typography / Contrast Guards ---- */
  html, body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overflow-x: clip !important;
    max-width: 100vw !important;
  }

  .app-container,
  .main-wrapper,
  .main-content {
    min-height: 100dvh;
    max-width: 100vw !important;
    overflow-x: clip !important;
  }

  .main-content {
    padding: 8px max(0.75rem, env(safe-area-inset-right)) 1.25rem max(0.75rem, env(safe-area-inset-left)) !important;
  }

  .app-footer {
    padding: 1rem max(0.75rem, env(safe-area-inset-left)) calc(78px + env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-right)) !important;
    margin-top: 0.75rem !important;
  }

  .compact-hero-heading.hero-brush-heading {
    font-size: clamp(28px, 7.2vw, 34px) !important;
    line-height: 1.24 !important;
    padding: 0.14em 0 !important;
  }

  body.fm-in-session .main-content {
    padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
  }

  /* Prevent iOS auto-zoom on form focus (< 16px triggers Safari zoom) */
  input, select, textarea {
    font-size: 16px !important;
  }

  /* Fix invisible gradient text bug on iOS Safari */
  .brand-name,
  [data-theme="golden"] .scorecard-main-title,
  [data-theme="golden"] .hero-main-heading,
  [data-theme="golden"] .compact-drill-question {
    background: none !important;
    -webkit-background-clip: border-box !important;
    background-clip: border-box !important;
    -webkit-text-fill-color: var(--text) !important;
    color: var(--text) !important;
  }

  /* Word wrapping so long topic titles never clip or overflow */
  h1, h2, h3, .topic-name, .pastel-card-title, .section-header-title,
  .drill-question-text, .compact-drill-question, .practice-ws-title {
    overflow-wrap: break-word;
    word-break: break-word;
    letter-spacing: normal;
  }

  /* KaTeX math overflow protection */
  .katex-display,
  .math-display-scroll {
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Performance on low-end phones: lighten heavy blur & shadows */
  .glassmorphism-card,
  .pd-stat-card,
  .pd-card,
  .fm-auth-overlay,
  .pd-modal-overlay {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  /* ---- PHONE HEADER: Always visible Login / Account / Theme / Menu >= 44px ---- */
  .navbar.fastmaths-navbar {
    min-height: calc(56px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-left)) 0 max(8px, env(safe-area-inset-right)) !important;
    overflow: visible !important;
  }

  .navbar .nav-container-inner {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 6px !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .navbar .nav-left {
    flex: 0 1 auto !important;
    min-width: 0 !important;
    gap: 4px !important;
  }

  .navbar .brand-logo-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    max-width: 108px;
  }

  .navbar .brand-logo-link img,
  .navbar .brand-logo-link svg {
    max-height: 28px !important;
    width: auto !important;
    max-width: 100% !important;
  }

  /* Hide desktop search bar, streak pill, sound toggle, and signup pill from top header
     so Log In, Account Pill, Theme, and Hamburger fit with 44px+ targets even at 320px */
  .navbar #nav-search-capsule,
  .navbar .nav-center.horizontal-links,
  .navbar .streak-pill,
  .navbar #sound-toggle-btn,
  .navbar #nav-notif-btn,
  .navbar #nav-signup-btn,
  .navbar .guest-header-hint {
    display: none !important;
  }

  .navbar .nav-right {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    flex-shrink: 0 !important;
    margin-left: auto !important;
  }

  .navbar #nav-login-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 58px !important;
    min-height: 44px !important;
    padding: 0 10px !important;
    font-size: 0.82rem !important;
    font-weight: 700 !important;
    white-space: nowrap !important;
  }

  .navbar #account-menu-trigger {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 4px 8px !important;
  }

  .navbar .account-pill-name {
    display: none !important;
  }

  .navbar #theme-toggle-btn,
  .navbar #mobile-nav-toggle {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 44px !important;
    min-height: 44px !important;
    width: 44px !important;
    height: 44px !important;
    padding: 0 !important;
  }

  /* ---- MOBILE DRAWER WITH ACCOUNT AT TOP & SIGN OUT PINNED AT BOTTOM ---- */
  #account-dropdown-card {
    display: none !important;
  }

  .mobile-nav-drawer {
    position: fixed !important;
    top: calc(56px + env(safe-area-inset-top)) !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    height: calc(100dvh - 56px - env(safe-area-inset-top)) !important;
    flex-direction: column !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    z-index: 1200 !important;
    padding: 0.75rem 1rem calc(2rem + env(safe-area-inset-bottom)) !important;
    background: var(--surface) !important;
  }

  .mobile-drawer-footer {
    margin-top: auto;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }

  .mobile-drawer-signout-footer-btn {
    width: 100%;
    min-height: 50px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 700 !important;
    border-radius: 12px !important;
  }

  .mobile-drawer-account {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.85rem;
    margin-bottom: 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 14px;
  }

  .mobile-nav-link {
    min-height: 46px !important;
    display: flex !important;
    align-items: center !important;
    font-size: 0.96rem !important;
  }

  /* ---- BOTTOM TAB BAR (5 Tabs, hidden during active sessions) ---- */
  .mobile-bottom-nav {
    display: flex !important;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 950;
    background: var(--nav-bg, var(--surface));
    border-top: 1px solid var(--border);
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    min-height: calc(58px + env(safe-area-inset-bottom));
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.16);
  }

  body.fm-in-session .mobile-bottom-nav {
    display: none !important;
  }

  .mob-tab-item {
    flex: 1;
    min-width: 44px;
    min-height: 46px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 4px 2px;
    cursor: pointer;
    border-radius: 10px;
  }

  .mob-tab-item.active {
    color: var(--primary, #f97316);
    background: rgba(249, 115, 22, 0.1);
  }

  .mob-tab-item svg {
    width: 20px;
    height: 20px;
  }

  /* ---- HOME DASHBOARD ---- */
  .hero-quick-access-strip,
  .quick-access-bar,
  .quick-access-row,
  .qa-chips-row {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.45rem !important;
    max-width: 100% !important;
  }
  .qa-chip {
    min-height: 44px !important;
    max-width: 100% !important;
    min-width: 0 !important;
    flex: 1 1 auto !important;
    white-space: normal !important;
  }

  .gov-exams-strip {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 0.45rem !important;
    padding-bottom: 4px;
  }
  .gov-exam-chip-btn {
    flex-shrink: 0 !important;
    min-height: 44px !important;
  }

  .topic-grid-minimal,
  .pastel-poster-grid,
  .topics-grid,
  .grid-cols-4,
  .grid-cols-3,
  .grid-cols-2 {
    grid-template-columns: 1fr !important;
  }

  .topic-card,
  .pastel-topic-card {
    min-height: auto !important;
    height: auto !important;
  }

  .pastel-card-arrow,
  .topic-arrow-btn {
    min-width: 44px !important;
    min-height: 44px !important;
  }

  /* Lift Back-to-Top button above bottom tab bar */
  #back-to-top-btn,
  .back-to-top-btn {
    bottom: calc(72px + env(safe-area-inset-bottom)) !important;
  }

  /* ---- TOPIC SETUP MODAL (Bottom Sheet, 92dvh max) ---- */
  .setup-modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  .setup-modal-dialog {
    width: 100% !important;
    max-width: 100vw !important;
    max-height: 92dvh !important;
    border-radius: 20px 20px 0 0 !important;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .setup-modal-footer,
  #setup-start-btn {
    min-height: 48px !important;
  }

  /* ---- PRACTICE / EXAM / SPEED SCREENS (Single-Page Old Desktop-Style Fit) ---- */
  .practice-arena-root,
  .active-practice-shell {
    overscroll-behavior: contain;
  }

  .drill-mcq-options-container {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.45rem !important;
  }

  .mcq-option-pill {
    min-height: 46px !important;
    padding: 0.45rem 0.65rem !important;
    font-size: 0.92rem !important;
  }

  .phone-kbd-toggle-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    margin: 3px auto 0 !important;
    min-height: 26px !important;
    height: 26px !important;
    padding: 2px 10px !important;
    font-size: 11px !important;
    font-weight: 700;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-secondary);
    cursor: pointer;
  }

  /* ---- RESULTS & ANSWER KEY (Clean Vertical Card Stack on Phones < 768px) ---- */
  .results-dashboard-wrapper,
  .compact-scorecard-wrapper,
  .results-screen-container,
  .compact-results-workspace {
    padding: 0.4rem 0.25rem calc(96px + env(safe-area-inset-bottom)) !important;
    max-width: 100% !important;
    overflow-x: clip !important;
  }

  .results-top-nav-bar,
  .results-top-actions-bar,
  .review-sticky-header {
    position: static !important;
    top: auto !important;
    z-index: auto !important;
  }

  .answer-key-pagination-bar {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 6px !important;
    padding: 0.55rem !important;
  }

  .answer-key-pagination-bar > div,
  .answer-key-pagination-bar > span {
    order: 1 !important;
    flex: 1 1 100% !important;
    text-align: center !important;
    font-size: 0.82rem !important;
  }

  .answer-key-pagination-bar .pagination-prev-btn,
  .answer-key-pagination-bar .pagination-next-btn {
    order: 2 !important;
    flex: 1 1 44% !important;
    min-height: 38px !important;
    font-size: 0.8rem !important;
    padding: 4px 8px !important;
    white-space: nowrap !important;
  }

  .compact-scorecard-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.55rem !important;
  }

  #review-table-container.compact-review-card,
  .review-table-card.compact-review-card {
    padding: 0.65rem 0.5rem !important;
    border-radius: 14px !important;
  }

  .review-filter-pills {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    width: 100% !important;
  }

  .review-filter-pills .rev-pill {
    font-size: 12px !important;
    padding: 4px 10px !important;
    min-height: 32px !important;
  }

  .compact-review-table-wrapper {
    overflow: visible !important;
    max-height: none !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    border-radius: 0 !important;
  }

  .compact-review-table,
  .compact-review-table tbody {
    display: block !important;
    width: 100% !important;
    background: transparent !important;
  }

  .compact-review-table thead {
    display: none !important;
  }

  /* Reset desktop height: 52px on tr.review-table-row so badges never overlap solution cards */
  .compact-review-table tr.review-table-row {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 6px 10px !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    background: var(--surface-2) !important;
    border: 1px solid var(--border) !important;
    border-radius: 12px !important;
    padding: 12px !important;
    margin-bottom: 10px !important;
    box-sizing: border-box !important;
    overflow: visible !important;
  }

  .compact-review-table tr.review-table-row td {
    display: block !important;
    border: none !important;
    padding: 0 !important;
    text-align: left !important;
    white-space: normal !important;
    word-break: break-word !important;
    box-sizing: border-box !important;
  }

  /* 1. Header Row: Question # on left, unclipped Status pill on right */
  .compact-review-table tr.review-table-row td:nth-child(1) {
    order: 1 !important;
    width: auto !important;
    font-size: 0.9rem !important;
  }

  .compact-review-table tr.review-table-row td:nth-child(5) {
    order: 2 !important;
    width: auto !important;
    margin-left: auto !important;
  }

  /* 2. Question prompt cleanly full width */
  .compact-review-table tr.review-table-row td:nth-child(2) {
    order: 3 !important;
    flex: 1 1 100% !important;
    width: 100% !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
    padding: 4px 0 !important;
  }

  /* 3. Answer summary row (Your Answer, Correct Answer, Time) */
  .compact-review-table tr.review-table-row td:nth-child(3),
  .compact-review-table tr.review-table-row td:nth-child(4),
  .compact-review-table tr.review-table-row td:nth-child(6) {
    order: 4 !important;
    width: auto !important;
    display: inline-flex !important;
    align-items: center !important;
  }

  /* 4. Action toggle row */
  .compact-review-table tr.review-table-row td:nth-child(7) {
    order: 5 !important;
    flex: 1 1 100% !important;
    width: 100% !important;
    padding-top: 4px !important;
  }

  .compact-review-table tr.review-table-row td:nth-child(7) > div {
    justify-content: flex-start !important;
  }

  /* Expanded Step-by-Step Solution & Mental Math Shortcut Stack */
  .compact-review-table tr.table-explanation-row {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: -4px 0 12px 0 !important;
    background: transparent !important;
  }

  .compact-review-table tr.table-explanation-row[style*="display: none"] {
    display: none !important;
  }

  .compact-review-table tr.table-explanation-row > td {
    display: block !important;
    width: 100% !important;
    padding: 0 !important;
    border: none !important;
  }

  .table-expanded-solution-card {
    width: 100% !important;
    padding: 0.75rem !important;
    border-radius: 12px !important;
    box-sizing: border-box !important;
  }

  .two-col-solution-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.65rem !important;
    width: 100% !important;
  }

  .solution-col-left,
  .shortcut-col-right {
    width: 100% !important;
    padding: 0.85rem !important;
    border-radius: 10px !important;
    font-size: 0.875rem !important;
    line-height: 1.55 !important;
    box-sizing: border-box !important;
  }

  .solution-col-body,
  .shortcut-col-body,
  .review-table-question-cell {
    overflow-wrap: break-word !important;
    word-break: normal !important;
    overflow-x: visible !important;
  }

  .solution-col-body .katex-display,
  .shortcut-col-body .katex-display,
  .review-table-question-cell .katex-display {
    overflow-x: auto !important;
    max-width: 100% !important;
  }

  /* Unpin sticky bottom actions so they sit cleanly above bottom mobile tab bar */
  .sticky-results-actions {
    position: static !important;
    bottom: auto !important;
    margin-top: 0.85rem !important;
    padding: 0.65rem 0.5rem !important;
    border-radius: 12px !important;
    border: 1px solid var(--border) !important;
    box-shadow: none !important;
  }

  /* ---- PRACTICE HUB TABLE -> CARDS ON PHONES ---- */
  .practice-ws-root,
  .practice-workspace-root {
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  .practice-topics-table,
  .practice-topics-table tbody,
  .practice-topics-table tr,
  .practice-topics-table td {
    display: block !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .practice-topics-table thead {
    display: none !important;
  }

  .practice-topics-table tbody tr {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem !important;
    margin-bottom: 0.6rem !important;
  }

  .practice-topics-table td {
    border: none !important;
    padding: 0.25rem 0 !important;
    white-space: normal !important;
  }

  .practice-topics-table button {
    min-height: 44px !important;
  }

  /* ---- PROGRESS PAGE & MASTERY TABLE ---- */
  .pd-stat-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  @media (max-width: 350px) {
    .pd-stat-grid {
      grid-template-columns: 1fr !important;
    }
  }

  #profile-tabs {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  #profile-tabs .tab-btn {
    flex-shrink: 0 !important;
    min-height: 44px !important;
  }

  /* Convert Topic Mastery Matrix table into clean stacked cards on phones (0 clipped buttons) */
  .profile-page-container table,
  .profile-page-container tbody,
  .profile-page-container tr,
  .profile-page-container td {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
  .profile-page-container thead {
    display: none !important;
  }
  .profile-page-container tbody tr {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem !important;
    margin-bottom: 0.65rem !important;
  }
  .profile-page-container tbody td {
    position: static !important;
    background: transparent !important;
    padding: 0.25rem 0 !important;
    border: none !important;
    text-align: left !important;
  }
  .profile-page-container .btn-practice-topic {
    min-height: 44px !important;
    width: 100% !important;
    margin-top: 0.35rem !important;
  }

  /* ---- CONCEPTS PAGE ---- */
  .concepts-module-root,
  .concepts-main-layout,
  .concepts-content-viewport,
  .concepts-lesson-body,
  .section-lesson-view,
  .concept-cards-grid,
  .concepts-grid-2,
  .mc-options-grid,
  .mc-opt-btn,
  .concepts-content-viewport > * {
    max-width: 100% !important;
    min-width: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
  }
  .concepts-topbar {
    flex-wrap: wrap !important;
    gap: 0.45rem !important;
    height: auto !important;
    padding: 0.6rem 0.75rem !important;
  }
  .concepts-topbar-left,
  .concepts-topbar-right,
  .concepts-breadcrumbs {
    flex-wrap: wrap !important;
    gap: 0.35rem !important;
    max-width: 100% !important;
  }
  .concepts-topbar button,
  .concepts-topbar a,
  .section-footer-actions button {
    min-width: 44px !important;
    min-height: 44px !important;
  }

  .concepts-content-viewport {
    font-size: 1rem !important;
    line-height: 1.55 !important;
    padding: 1rem 0.75rem calc(80px + env(safe-area-inset-bottom)) !important;
  }

  .concepts-content-viewport table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ---- DATA INTERPRETATION STIMULUS SCROLLING ---- */
  .di-stimulus-card table,
  .question-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ---- LANDSCAPE PHONE PRACTICE LAYOUT (Two Panes) ---- */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  .mobile-bottom-nav {
    display: none !important;
  }
  .compact-drill-body {
    display: grid !important;
    grid-template-columns: 1fr 280px !important;
    gap: 1rem !important;
    align-items: start !important;
  }
}


/* ==========================================================================
   ROUND 2 PHONE FIXES (F1–F6) & SHARED PHONE BOTTOM SHEET PORTAL (<= 767px)
   ========================================================================== */
.fm-phone-sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 10040;
  background: var(--bg-scrim, rgba(10, 14, 24, 0.64));
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overscroll-behavior: contain;
}

.fm-phone-sheet {
  width: 100%;
  max-width: 540px;
  max-height: 85dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  color: var(--text);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.35);
}

.fm-phone-sheet-handle {
  display: flex;
  justify-content: center;
  padding: 4px 0 8px;
}

.fm-phone-sheet-handle span {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
}

.fm-phone-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-hairline, var(--border));
  margin-bottom: 8px;
}

.fm-phone-sheet-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
}

.fm-phone-sheet-close {
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 10px;
}

.fm-phone-sheet-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fm-phone-sheet-item {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-hairline, var(--border));
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.fm-phone-sheet-item.is-danger {
  color: var(--danger);
}

.fm-phone-sheet-item.is-active {
  border-color: var(--primary);
}

@media (max-width: 767px) {
  /* Hide floating Back-to-Top button on phones (tap active Home bottom tab instead) */
  #back-to-top-btn,
  .back-to-top-btn {
    display: none !important;
  }

  /* Fix F2: Remove floating/sticky mid-screen detachment on mobile; keep section bar in normal flow */
  .sticky-mini-section-bar {
    position: static !important;
    top: auto !important;
    z-index: 1 !important;
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: 6px !important;
    padding: 6px 8px !important;
    border-radius: 12px !important;
    box-shadow: none !important;
    margin: 0 0 0.6rem 0 !important;
    background: var(--surface) !important;
  }
  .sticky-mini-section-bar::-webkit-scrollbar {
    display: none;
  }
  .mini-sec-btn {
    flex-shrink: 0 !important;
    min-height: 32px !important;
    padding: 4px 9px !important;
    font-size: 11.5px !important;
    white-space: nowrap !important;
  }

  #section-speed-drills,
  #section-arithmetical-ability,
  #section-data-interpretation,
  #curriculum-topics-section {
    scroll-margin-top: calc(var(--header-h, 56px) + 56px + env(safe-area-inset-top));
  }

  /* Fix F3: 3 Entrance Shortcut Tiles fit cleanly without overlap at 320-430px */
  .section-shortcuts-group {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
    width: 100% !important;
  }
  .section-shortcut-card {
    min-width: 0 !important;
    width: 100% !important;
    padding: 10px 6px !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    gap: 5px !important;
    min-height: 78px !important;
    overflow: hidden !important;
  }
  .shortcut-icon-badge {
    width: 30px !important;
    height: 30px !important;
  }
  .shortcut-icon-badge img {
    width: 28px !important;
    height: 28px !important;
  }
  .shortcut-text {
    width: 100% !important;
    align-items: center !important;
  }
  .shortcut-text strong {
    font-size: clamp(11px, 3vw, 13px) !important;
    line-height: 1.2 !important;
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    text-overflow: clip !important;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .shortcut-text small {
    font-size: 11px !important;
  }
  .shortcut-arrow {
    display: none !important;
  }

  /* Fix F6: Hide scrollbar track under Government Exams strip */
  .gov-exams-strip {
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
  }
  .gov-exams-strip::-webkit-scrollbar {
    display: none !important;
  }

  /* Fix F4: Filter pills horizontal scroll with no clipped DI button */
  .concepts-header-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.5rem !important;
  }
  .concepts-actions-group {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
    width: 100% !important;
  }
  .concepts-filter-pills {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    max-width: 100% !important;
    width: 100% !important;
    scrollbar-width: none !important;
    padding: 3px !important;
  }
  .concepts-filter-pills::-webkit-scrollbar {
    display: none !important;
  }
  .concepts-filter-pills .c-pill {
    flex-shrink: 0 !important;
    min-height: 36px !important;
    white-space: nowrap !important;
    padding: 0 8px !important;
    font-size: 0.74rem !important;
  }

  /* Quick Access bar visible cleanly in 1 row */
  .quick-access-strip {
    display: flex !important;
    width: 100% !important;
    gap: 6px !important;
    overflow-x: auto !important;
    scrollbar-width: none !important;
  }
  .quick-access-strip::-webkit-scrollbar {
    display: none !important;
  }

  /* Single-Page Compact Old-Style Session Fit on Phone: ALL options visible at once */
  body.fm-in-session .navbar {
    min-height: 44px !important;
    height: 44px !important;
    padding: 0 8px !important;
  }
  body.fm-in-session .main-content {
    padding: 4px max(6px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-right)) !important;
  }
  .practice-screen-container.compact-drill-workspace {
    display: flex !important;
    flex-direction: column !important;
    gap: 4px !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .practice-progress-track {
    height: 4px !important;
    margin: 0 !important;
  }

  .practice-screen-container .practice-top-bar.jumbo-bar,
  .practice-top-bar {
    position: static !important;
    top: auto !important;
    z-index: 20 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 6px !important;
    padding: 6px 8px !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }
  .practice-top-bar .bar-group-left {
    order: 1 !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    gap: 5px !important;
    flex-wrap: wrap !important;
  }
  .practice-top-bar .bar-group-center {
    order: 2 !important;
    flex: 0 0 auto !important;
    min-width: 0 !important;
    justify-content: flex-end !important;
    margin-top: 0 !important;
  }
  .practice-top-bar .bar-group-right {
    order: 3 !important;
    flex: 1 1 100% !important;
    justify-content: flex-start !important;
    gap: 5px !important;
    flex-wrap: wrap !important;
    min-width: 0 !important;
  }
  .practice-top-bar .jumbo-counter {
    font-size: 11px !important;
    white-space: nowrap !important;
  }
  .practice-top-bar .jumbo-counter strong {
    font-size: 12px !important;
  }
  .practice-top-bar .combo-meter-pill {
    display: none !important;
  }
  .practice-top-bar .small-training-mode-dropdown {
    max-width: 124px !important;
    font-size: 11px !important;
    padding: 2px 6px !important;
  }
  .practice-top-bar .shortcuts-btn,
  .practice-top-bar #keypad-toggle-btn {
    display: inline-flex !important;
    align-items: center !important;
    gap: 3px !important;
  }
  .practice-top-bar svg {
    width: 12px !important;
    height: 12px !important;
    flex-shrink: 0 !important;
  }
  .practice-top-bar #practice-timer-display {
    min-height: 28px !important;
    height: auto !important;
    padding: 3px 8px !important;
    font-size: 11.5px !important;
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    display: inline-flex !important;
    align-items: center !important;
  }
  .practice-top-bar .practice-bar-group button,
  .practice-top-bar .practice-bar-group .ctrl-btn,
  .practice-top-bar .practice-bar-group select,
  .practice-top-bar button,
  .practice-top-bar select {
    min-height: 30px !important;
    height: auto !important;
    font-size: 11px !important;
    padding: 3px 8px !important;
    border-radius: 8px !important;
    line-height: 1.15 !important;
    white-space: nowrap !important;
    min-width: 0 !important;
    overflow: visible !important;
  }

  .practice-card-box.compact-drill-card {
    padding: 8px 8px !important;
    margin-top: 0 !important;
    gap: 4px !important;
    display: flex !important;
    flex-direction: column !important;
    max-width: 100% !important;
  }
  .practice-card-box.compact-drill-card .practice-card-head {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 6px !important;
    margin-bottom: 2px !important;
    max-width: 100% !important;
  }
  .practice-card-box.compact-drill-card .practice-card-head > div {
    max-width: 100% !important;
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
    gap: 5px !important;
  }
  .practice-card-box.compact-drill-card .practice-topic-badge {
    font-size: 10px !important;
    padding: 2px 6px !important;
    max-width: 100% !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  .practice-card-box.compact-drill-card #input-mode-toggle-group {
    width: auto !important;
    flex: 0 0 auto !important;
    min-height: 24px !important;
    padding: 2px !important;
  }
  .practice-card-box.compact-drill-card .mode-toggle-pill-btn {
    min-height: 20px !important;
    padding: 1px 8px !important;
    font-size: 10.5px !important;
  }
  .practice-card-box.compact-drill-card .mark-review-btn,
  .practice-card-box.compact-drill-card #focus-mode-btn,
  .practice-card-box.compact-drill-card #btn-show-hint-trick,
  .practice-card-box.compact-drill-card #btn-toggle-instant-check,
  .practice-card-box.compact-drill-card .view-toggle-btn {
    min-height: 24px !important;
    padding: 1px 6px !important;
    font-size: 10px !important;
  }

  .speed-drill-hud-row {
    gap: 3px !important;
    margin-bottom: 1px !important;
    flex-wrap: nowrap !important;
    justify-content: center !important;
    overflow-x: auto !important;
    scrollbar-width: none !important;
  }
  .speed-drill-hud-row::-webkit-scrollbar {
    display: none !important;
  }
  .speed-timer-ring-wrapper.compact-ring {
    width: 26px !important;
    height: 26px !important;
    flex-shrink: 0 !important;
  }
  .speed-timer-ring-wrapper.compact-ring .speed-timer-svg {
    width: 26px !important;
    height: 26px !important;
  }
  .speed-timer-ring-wrapper.compact-ring .speed-timer-center-text {
    font-size: 8.5px !important;
  }
  .speed-hud-pill {
    padding: 1px 5px !important;
    font-size: 10px !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  .practice-card-box.compact-drill-card .drill-stimulus-box {
    max-height: 96px !important;
    padding: 5px !important;
    margin-bottom: 2px !important;
    overflow-y: auto !important;
  }

  .practice-question-display.compact-drill-question {
    margin: 1px 0 !important;
    font-size: clamp(1.2rem, 5vw, 1.65rem) !important;
    line-height: 1.15 !important;
  }
  .practice-instruction-prefix {
    font-size: 9.5px !important;
    margin-bottom: 0 !important;
  }

  .answer-input-container {
    margin: 1px 0 !important;
    padding: 0 !important;
  }
  .answer-input-meta {
    margin-bottom: 1px !important;
    font-size: 9.5px !important;
  }
  #practice-answer-input.compact-typed-answer-box {
    min-height: 36px !important;
    height: 36px !important;
    padding: 2px 10px !important;
    font-size: 1.2rem !important;
  }
  .phone-kbd-toggle-btn {
    margin: 2px auto 0 !important;
    min-height: 22px !important;
    height: 22px !important;
    padding: 1px 9px !important;
    font-size: 10px !important;
  }

  #practice-keypad-container.jumbo-calculator-wrapper {
    padding: 4px !important;
    margin: 1px 0 !important;
  }
  .compact-keypad-grid {
    gap: 4px !important;
  }
  .compact-keypad-grid .calc-btn-7a {
    min-height: 34px !important;
    height: 34px !important;
    padding: 0 2px !important;
    font-size: 0.94rem !important;
    border-radius: 7px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
  }
  .jumbo-keypad-grid-7a.compact-keypad-grid .calc-btn-7a.fn-enter-7a,
  .jumbo-keypad-grid-7a.compact-keypad-grid .calc-btn-7a.fn-clear-7a,
  .compact-keypad-grid .calc-btn-7a.fn-enter-7a,
  .compact-keypad-grid .calc-btn-7a.fn-clear-7a {
    font-size: 0.72rem !important;
    padding: 0 2px !important;
  }

  .jumbo-navigation-bar.compact-drill-nav {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 4px !important;
    margin: 2px 0 0 !important;
    padding: 0 !important;
    width: 100% !important;
  }
  .jumbo-navigation-bar.compact-drill-nav > div {
    display: flex !important;
    gap: 4px !important;
    flex: 0 1 auto !important;
  }
  .jumbo-navigation-bar.compact-drill-nav button {
    min-height: 34px !important;
    height: 34px !important;
    padding: 2px 6px !important;
    font-size: 10.5px !important;
    border-radius: 7px !important;
    margin: 0 !important;
    white-space: nowrap !important;
  }
  .jumbo-navigation-bar.compact-drill-nav #practice-submit-btn {
    flex: 1 1 auto !important;
    font-size: 11px !important;
  }

  /* ========================================================================
     DARK MODE PHONE RESPONSIVE ADAPTATIONS (320px - 767px)
     Scoped ONLY to html.dark / [data-theme="dark"] so Light Mode is untouched.
     ======================================================================== */
  html.dark .fastmaths-navbar,
  [data-theme="dark"] .fastmaths-navbar {
    height: auto !important;
    min-height: 0 !important;
    padding: 6px max(10px, env(safe-area-inset-left)) 8px max(10px, env(safe-area-inset-right)) !important;
  }

  html.dark .fastmaths-navbar .nav-container-inner,
  [data-theme="dark"] .fastmaths-navbar .nav-container-inner {
    flex-wrap: wrap !important;
    gap: 6px !important;
    align-items: center !important;
  }

  html.dark .fastmaths-navbar .nav-left,
  [data-theme="dark"] .fastmaths-navbar .nav-left {
    display: contents !important;
  }

  html.dark .fastmaths-navbar .brand-logo-link,
  [data-theme="dark"] .fastmaths-navbar .brand-logo-link {
    order: 1 !important;
    margin-right: auto !important;
  }

  html.dark .fastmaths-navbar .nav-right,
  [data-theme="dark"] .fastmaths-navbar .nav-right {
    order: 2 !important;
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
  }

  html.dark .fastmaths-navbar #nav-notif-btn,
  [data-theme="dark"] .fastmaths-navbar #nav-notif-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 44px !important;
    min-height: 44px !important;
  }

  html.dark .fastmaths-navbar #nav-login-btn,
  [data-theme="dark"] .fastmaths-navbar #nav-login-btn,
  html.dark .fastmaths-navbar #account-menu-trigger,
  [data-theme="dark"] .fastmaths-navbar #account-menu-trigger {
    display: none !important;
  }

  html.dark .fastmaths-navbar #nav-search-capsule,
  [data-theme="dark"] .fastmaths-navbar #nav-search-capsule {
    order: 3 !important;
    display: flex !important;
    width: 100% !important;
    flex: 1 1 100% !important;
    min-height: 44px !important;
    padding: 4px 12px !important;
  }

  html.dark .fastmaths-navbar #nav-search-capsule input,
  [data-theme="dark"] .fastmaths-navbar #nav-search-capsule input {
    font-size: 16px !important;
  }

  html.dark .compact-welcome-strip,
  [data-theme="dark"] .compact-welcome-strip {
    flex-direction: column !important;
    align-items: stretch !important;
    max-height: none !important;
    gap: 0.75rem !important;
    padding: 0.9rem !important;
  }

  html.dark .compact-hero-heading,
  [data-theme="dark"] .compact-hero-heading {
    font-size: 1.35rem !important;
  }

  html.dark .gov-exams-strip,
  [data-theme="dark"] .gov-exams-strip {
    flex-wrap: wrap !important;
    overflow-x: visible !important;
  }

  html.dark .compact-start-btn,
  [data-theme="dark"] .compact-start-btn {
    width: 100% !important;
    justify-content: center !important;
    min-height: 44px !important;
  }

  html.dark .compact-progress-card,
  [data-theme="dark"] .compact-progress-card {
    width: 100% !important;
    max-height: none !important;
  }

  /* Category cards stacked full-width with full titles */
  html.dark .section-shortcuts-group,
  [data-theme="dark"] .section-shortcuts-group {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  html.dark .section-shortcut-card,
  [data-theme="dark"] .section-shortcut-card {
    flex-direction: row !important;
    justify-content: space-between !important;
    text-align: left !important;
    padding: 0.7rem 0.9rem !important;
    min-height: 64px !important;
  }

  html.dark .shortcut-text,
  [data-theme="dark"] .shortcut-text {
    align-items: flex-start !important;
  }

  html.dark .shortcut-text strong,
  [data-theme="dark"] .shortcut-text strong {
    font-size: 0.95rem !important;
    white-space: normal !important;
    -webkit-line-clamp: unset !important;
  }

  html.dark .shortcut-arrow,
  [data-theme="dark"] .shortcut-arrow {
    display: inline-flex !important;
  }

  /* Quick Actions: 3 per row with second row centered (5 tiles -> 3 + 2 centered) */
  html.dark .quick-access-strip,
  [data-theme="dark"] .quick-access-strip {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: 8px !important;
    overflow-x: visible !important;
  }

  html.dark .quick-access-strip .qa-chip,
  [data-theme="dark"] .quick-access-strip .qa-chip {
    flex: 0 0 calc((100% - 16px) / 3) !important;
    min-height: 56px !important;
  }

  /* Filter tabs swipe horizontally; Collapse all on its own line */
  html.dark .concepts-actions-group,
  [data-theme="dark"] .concepts-actions-group {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }

  html.dark .btn-collapse-all-pill,
  [data-theme="dark"] .btn-collapse-all-pill {
    width: 100% !important;
    min-height: 44px !important;
    justify-content: center !important;
  }

  /* Topic cards: 1 column, icon left, text middle, arrow right */
  html.dark .speed-drills-grid,
  [data-theme="dark"] .speed-drills-grid,
  html.dark .arithmetical-grid,
  [data-theme="dark"] .arithmetical-grid,
  html.dark .di-grid,
  [data-theme="dark"] .di-grid,
  html.dark .pastel-poster-grid,
  [data-theme="dark"] .pastel-poster-grid {
    grid-template-columns: 1fr !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  html.dark .mob-tab-item.active,
  [data-theme="dark"] .mob-tab-item.active {
    color: var(--nav-active-text) !important;
    background: var(--nav-active-bg) !important;
  }

  html.dark .mobile-bottom-nav,
  [data-theme="dark"] .mobile-bottom-nav {
    background: var(--nav-bg) !important;
    border-top: 1px solid var(--nav-border) !important;
  }

  /* Admin Portal Phone Layout (< 768px) */
  .adm-u-desktop-table {
    display: none !important;
  }
  .adm-u-mobile-cards {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.7rem !important;
  }
  .adm-u-mobile-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.85rem;
  }
  .admin-users-tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .admin-users-tabs .adm-u-tab {
    flex-shrink: 0 !important;
    min-height: 44px !important;
  }

  /* Practice Menu Phone Cards (< 768px) — zero horizontal overflow */
  .practice-ws-header {
    padding: 0.85rem !important;
  }
  .practice-ws-tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .practice-ws-tab {
    flex-shrink: 0 !important;
    min-height: 44px !important;
  }
  .practice-ws-grid {
    grid-template-columns: 1fr !important;
  }
  .practice-topics-table,
  .practice-topics-table tbody,
  .practice-topics-table tr {
    display: block !important;
    width: 100% !important;
  }
  .practice-topics-table thead {
    display: none !important;
  }
  .practice-topic-row {
    border: 1px solid var(--border) !important;
    border-radius: 12px !important;
    padding: 0.75rem !important;
    margin-bottom: 0.65rem !important;
    background: var(--surface) !important;
  }
  .practice-topic-row td {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 0.25rem 0 !important;
    border: none !important;
    width: 100% !important;
    white-space: normal !important;
  }
  .practice-row-actions {
    width: 100% !important;
    flex-wrap: wrap !important;
    gap: 0.4rem !important;
    margin-top: 0.35rem !important;
  }
  .practice-row-actions .btn-row-practice,
  .practice-row-actions .btn-row-quick10,
  .practice-row-actions .btn-row-bookmark,
  .practice-row-actions .btn-row-formulas {
    min-height: 44px !important;
  }
  .practice-mobile-sticky-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(64px + env(safe-area-inset-bottom));
    z-index: 950;
    padding: 0.55rem 0.85rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow-md);
  }
}

/* =========================================================================
   Mobile Fast-Scroll GPU Repaint & Tile Starvation Fix (<= 768px)
   Prevents Android/iOS Chrome from blanking foreground content during flings.
   ========================================================================= */
@media (max-width: 768px) {
  html, body {
    overflow-x: clip !important;
    overflow-y: auto !important;
    overscroll-behavior-y: auto !important;
    height: auto !important;
    min-height: 100dvh;
    background-attachment: scroll !important;
  }

  .main-wrapper,
  .main-content {
    position: relative;
    z-index: 1;
    overflow-x: clip !important;
    transform: none !important;
    filter: none !important;
  }

  /* Disable expensive live backdrop-filter blur on scrolling cards & bars on mobile */
  .glassmorphism-card,
  .math-concept-card,
  .concept-capsule-card,
  .speed-drill-card,
  .compact-drill-card,
  .compact-hero-card,
  .jumbo-card,
  .hero-progress-card,
  .lr-card,
  .lr-summary-card,
  .lr-sketch-banner,
  .fastmaths-navbar,
  .sticky-mini-section-bar,
  .sfm-bar-wrap {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    will-change: auto !important;
  }
}

/* ==========================================================================
   MOBILE-ONLY FLOATING PILL NAVIGATION DOCK & SHEETS (Strictly < 768px)
   Matches warm ivory/amber pill bar & deep-navy squircles in Light Mode,
   with native Dark, Blue, and Golden theme adaptation.
   ========================================================================== */
@media (max-width: 767px) {
  #navbar-container > .navbar.fastmaths-navbar {
    display: none !important;
  }

  #mobile-pill-navbar-root {
    display: block !important;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    z-index: 980;
    width: 100%;
    pointer-events: auto;
  }

  .fm-mob-pill-dock {
    width: 100%;
    padding: max(env(safe-area-inset-top), 8px) 10px 8px;
    pointer-events: auto;
    background: #FFFDF9;
    border-bottom: 1px solid rgba(253, 226, 184, 0.7);
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background 0.18s ease, border-color 0.18s ease;
  }

  html.dark .fm-mob-pill-dock,
  [data-theme="dark"] .fm-mob-pill-dock {
    background: #07090F;
    border-bottom: 1px solid rgba(255, 201, 20, 0.15);
  }

  [data-theme="blue"] .fm-mob-pill-dock {
    background: #EFF6FF;
    border-bottom: 1px solid #BFDBFE;
  }

  [data-theme="golden"] .fm-mob-pill-dock {
    background: #0B0D14;
    border-bottom: 1px solid rgba(255, 201, 20, 0.25);
  }

  /* Row 1: Exact Desktop FastMaths Brand Header (100% Unclipped when visible) */
  .fm-mob-logo-row {
    pointer-events: auto;
    background: transparent;
    border: none;
    padding: 2px 8px;
    margin: 0 0 6px;
    height: auto;
    max-height: none;
    overflow: visible;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .fm-mob-logo-row:active {
    transform: scale(0.95);
  }
  .fm-mob-logo-row.is-logo-collapsed {
    display: none !important;
  }
  .fm-mob-logo-row .official-brand-logo {
    height: 36px !important;
    width: auto !important;
    max-width: 170px !important;
    object-fit: contain !important;
    display: block !important;
  }
  [data-theme="golden"] .fm-mob-logo-row .logo-variant-dark,
  [data-theme="golden"] .fm-mob-drawer-brand .logo-variant-dark {
    display: block !important;
  }
  [data-theme="golden"] .fm-mob-logo-row .logo-variant-light,
  [data-theme="golden"] .fm-mob-drawer-brand .logo-variant-light {
    display: none !important;
  }

  body.fm-in-session .fm-mob-pill-dock,
  .fm-mob-pill-dock.is-calm-exam {
    opacity: 1;
  }

  .fm-mob-pill-inner {
    pointer-events: auto;
    margin: 0 auto;
    width: 100%;
    max-width: 430px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    border-radius: 9999px;
    padding: 6px;
    background: #FFFDF9;
    border: 1px solid #FDE2B8;
    box-shadow: 0 6px 18px -4px rgba(245, 158, 11, 0.16), 0 2px 8px rgba(11, 25, 61, 0.06);
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    transition: box-shadow 0.2s ease, background 0.2s ease;
  }

  .fm-mob-pill-inner.is-scrolled {
    background: #FFFDF9;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    box-shadow: 0 8px 22px -4px rgba(245, 158, 11, 0.22), 0 3px 10px rgba(11, 25, 61, 0.1);
  }

  .fm-mob-pill-inner button {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    font-family: inherit;
    cursor: pointer;
  }

  /* Slot 1: Log In (or Signed-in FM Brand Pill) */
  .fm-mp-auth-btn {
    height: 40px;
    min-height: 40px;
    border-radius: 9999px;
    background: #FFFFFF;
    border: 1.5px solid #0B193D;
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 13px;
    font-weight: 700;
    color: #0B193D;
    white-space: nowrap;
    flex-shrink: 0;
    transition: transform 0.14s ease, background 0.16s ease;
  }
  .fm-mp-auth-btn.is-brand {
    padding: 0 11px;
    border-color: #E2C69B;
  }
  .fm-mp-auth-btn:active {
    transform: scale(0.95);
  }

  /* Slot 2: Streak Pill */
  .fm-mp-streak-btn {
    height: 40px;
    min-height: 40px;
    border-radius: 9999px;
    background: #FFF2CC;
    border: 1px solid #F8D38A;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: #0B193D;
    transition: transform 0.14s ease;
  }
  .fm-mp-streak-btn:active {
    transform: scale(0.95);
  }
  .fm-mp-flame-svg {
    color: #0B193D;
    flex-shrink: 0;
  }

  /* Slot 3: Center Profile Pill */
  .fm-mp-profile-btn {
    height: 40px;
    min-height: 40px;
    min-width: 0;
    flex: 1 1 auto;
    border-radius: 9999px;
    background: #FFFFFF;
    border: 1px solid #F5D6A7;
    padding: 4px 10px 4px 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    color: #0B193D;
    transition: transform 0.14s ease;
  }
  .fm-mp-profile-btn:active {
    transform: scale(0.97);
  }

  .fm-mp-avatar-circle {
    width: 32px;
    height: 32px;
    border-radius: 9999px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
    color: #FFFFFF;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-weight: 800;
    font-size: 14px;
  }
  .fm-mp-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }
  .fm-mp-avatar-init {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    line-height: 1;
  }
  .fm-mp-profile-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13.5px;
    font-weight: 700;
    color: #0B193D;
    text-align: left;
  }
  .fm-mp-chevron {
    flex-shrink: 0;
    margin-left: auto;
    color: #0B193D;
    transition: transform 0.2s ease;
  }
  .fm-mp-profile-btn.is-open .fm-mp-chevron {
    transform: rotate(180deg);
  }

  /* Slots 4 & 5: Action Squircles */
  .fm-mp-squircle {
    position: relative;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    flex-shrink: 0;
    border-radius: 14px;
    border: none;
    background: #0B193D;
    color: #FFFFFF;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(11, 25, 61, 0.18);
    transition: transform 0.14s ease, background 0.16s ease;
  }
  .fm-mp-squircle:active {
    transform: scale(0.9);
  }

  .fm-mp-bars {
    width: 17px;
    height: 13px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }
  .fm-mp-bars span {
    display: block;
    width: 100%;
    height: 2.2px;
    border-radius: 999px;
    background: currentColor;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }
  .fm-mp-menu-btn.is-open .fm-mp-bars span:nth-child(1) {
    transform: translateY(5.4px) rotate(45deg);
  }
  .fm-mp-menu-btn.is-open .fm-mp-bars span:nth-child(2) {
    opacity: 0;
  }
  .fm-mp-menu-btn.is-open .fm-mp-bars span:nth-child(3) {
    transform: translateY(-5.4px) rotate(-45deg);
  }

  .fm-mp-notif-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 9px;
    height: 9px;
    border-radius: 9999px;
    background: #EF4444;
    box-shadow: 0 0 0 2px #FFFDF9;
  }

  /* Strict Narrow-Phone Fit Guard (320px - 379px) */
  @media (max-width: 380px) {
    .fm-mob-pill-dock {
      padding-left: 6px;
      padding-right: 6px;
    }
    .fm-mob-pill-inner {
      gap: 4px;
      padding: 5px;
    }
    .fm-mp-auth-btn {
      padding: 0 10px;
      font-size: 12.2px;
      height: 36px;
      min-height: 36px;
    }
    .fm-mp-streak-btn {
      padding: 0 8px;
      font-size: 12.2px;
      height: 36px;
      min-height: 36px;
    }
    .fm-mp-profile-btn {
      height: 36px;
      min-height: 36px;
      padding: 3px 8px 3px 3px;
      gap: 5px;
    }
    .fm-mp-avatar-circle {
      width: 28px;
      height: 28px;
      font-size: 12.5px;
    }
    .fm-mp-profile-name {
      font-size: 12.5px;
    }
    .fm-mp-squircle {
      width: 36px;
      height: 36px;
      min-width: 36px;
      min-height: 36px;
      border-radius: 12px;
    }
  }

  /* ---- 4-THEME ADAPTATIONS FOR PILL DOCK ---- */
  /* Dark Theme (Obsidian & Gold) */
  html.dark .fm-mob-pill-inner,
  [data-theme="dark"] .fm-mob-pill-inner {
    background: #0E1421;
    border-color: rgba(255, 201, 20, 0.25);
    box-shadow: 0 8px 24px -4px rgba(255, 201, 20, 0.14);
  }
  html.dark .fm-mob-pill-inner.is-scrolled,
  [data-theme="dark"] .fm-mob-pill-inner.is-scrolled {
    background: #0E1421;
  }
  html.dark .fm-mp-auth-btn,
  [data-theme="dark"] .fm-mp-auth-btn {
    background: #151D2E;
    border-color: rgba(255, 201, 20, 0.72);
    color: #FFC914;
  }
  html.dark .fm-mp-streak-btn,
  [data-theme="dark"] .fm-mp-streak-btn {
    background: rgba(255, 201, 20, 0.15);
    border-color: rgba(255, 201, 20, 0.35);
    color: #FFC914;
  }
  html.dark .fm-mp-flame-svg,
  [data-theme="dark"] .fm-mp-flame-svg {
    color: #FFC914;
  }
  html.dark .fm-mp-profile-btn,
  [data-theme="dark"] .fm-mp-profile-btn {
    background: #151D2E;
    border-color: rgba(255, 255, 255, 0.12);
    color: #FFFFFF;
  }
  html.dark .fm-mp-profile-name,
  html.dark .fm-mp-chevron,
  [data-theme="dark"] .fm-mp-profile-name,
  [data-theme="dark"] .fm-mp-chevron {
    color: #FFFFFF;
  }
  html.dark .fm-mp-avatar-circle,
  [data-theme="dark"] .fm-mp-avatar-circle {
    box-shadow: 0 0 0 1.5px rgba(255, 201, 20, 0.55);
  }
  html.dark .fm-mp-squircle,
  [data-theme="dark"] .fm-mp-squircle {
    background: #1A2438;
    border: 1px solid rgba(255, 201, 20, 0.3);
    color: #FFC914;
  }
  html.dark .fm-mp-notif-dot,
  [data-theme="dark"] .fm-mp-notif-dot {
    box-shadow: 0 0 0 2px #0E1421;
  }

  /* Blue Theme */
  [data-theme="blue"] .fm-mob-pill-inner,
  [data-theme="blue"] .fm-mob-pill-inner.is-scrolled {
    background: #EFF6FF;
    border-color: #BFDBFE;
    box-shadow: 0 8px 24px -4px rgba(37, 99, 235, 0.16);
  }
  [data-theme="blue"] .fm-mp-auth-btn,
  [data-theme="blue"] .fm-mp-profile-btn {
    background: #FFFFFF;
    border-color: #93C5FD;
    color: #1E3A8A;
  }
  [data-theme="blue"] .fm-mp-profile-name,
  [data-theme="blue"] .fm-mp-chevron {
    color: #1E3A8A;
  }
  [data-theme="blue"] .fm-mp-streak-btn {
    background: #DBEAFE;
    border-color: #93C5FD;
    color: #1E3A8A;
  }
  [data-theme="blue"] .fm-mp-flame-svg {
    color: #1D4ED8;
  }
  [data-theme="blue"] .fm-mp-squircle {
    background: #1E3A8A;
    color: #FFFFFF;
  }

  /* Golden Theme */
  [data-theme="golden"] .fm-mob-pill-inner,
  [data-theme="golden"] .fm-mob-pill-inner.is-scrolled {
    background: #0B0D14;
    border-color: rgba(255, 201, 20, 0.45);
    box-shadow: 0 0 20px rgba(255, 201, 20, 0.2);
  }
  [data-theme="golden"] .fm-mp-auth-btn {
    background: #141720;
    border-color: #FFC914;
    color: #FFC914;
  }
  [data-theme="golden"] .fm-mp-streak-btn {
    background: rgba(255, 201, 20, 0.2);
    border-color: rgba(255, 201, 20, 0.5);
    color: #FFC914;
  }
  [data-theme="golden"] .fm-mp-flame-svg {
    color: #FFC914;
  }
  [data-theme="golden"] .fm-mp-profile-btn {
    background: #141720;
    border-color: rgba(255, 201, 20, 0.35);
    color: #FFF8DC;
  }
  [data-theme="golden"] .fm-mp-profile-name,
  [data-theme="golden"] .fm-mp-chevron {
    color: #FFF8DC;
  }
  [data-theme="golden"] .fm-mp-squircle {
    background: #0F1117;
    border: 1px solid rgba(255, 201, 20, 0.55);
    color: #FFC914;
  }

  /* ---- NATIVE POPOVERS & BOTTOM SHEETS ---- */
  .fm-mob-popover-scrim,
  .fm-mob-sheet-scrim {
    position: fixed;
    inset: 0;
    z-index: 1400;
    background: rgba(11, 25, 61, 0.38);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    display: flex;
    animation: fmMobFadeIn 0.16s ease-out;
  }
  .fm-mob-popover-scrim {
    align-items: flex-start;
    justify-content: center;
    padding: calc(max(env(safe-area-inset-top), 10px) + 60px) 12px 16px;
  }
  .fm-mob-sheet-scrim {
    align-items: flex-end;
    justify-content: center;
  }

  @keyframes fmMobFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }
  @keyframes fmMobSlideUp {
    from { transform: translateY(22px); opacity: 0.7; }
    to { transform: translateY(0); opacity: 1; }
  }

  .fm-mob-popover-card {
    width: 100%;
    max-width: 400px;
    border-radius: 20px;
    padding: 16px;
    background: var(--surface, #FFFFFF);
    border: 1px solid var(--border, #E2E8F0);
    color: var(--text, #0F172A);
    box-shadow: 0 20px 44px rgba(11, 25, 61, 0.22);
    animation: fmMobFadeIn 0.18s ease-out;
  }

  .fm-mob-pop-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
  }
  .fm-mob-pop-kicker {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.06em;
    color: var(--text-muted, #64748B);
  }
  .fm-mob-pop-title {
    margin: 2px 0 0;
    font-size: 1.15rem;
    font-weight: 800;
  }
  .fm-mob-best-pill {
    padding: 4px 10px;
    border-radius: 9999px;
    background: rgba(245, 158, 11, 0.15);
    color: #B45309;
    font-size: 12px;
    font-weight: 800;
  }
  html.dark .fm-mob-best-pill,
  [data-theme="dark"] .fm-mob-best-pill,
  [data-theme="golden"] .fm-mob-best-pill {
    color: #FFC914;
  }

  .fm-mob-week-strip {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin-bottom: 12px;
  }
  .fm-mob-day-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 7px 2px;
    border-radius: 12px;
    background: var(--surface-2, #F8FAFC);
    border: 1px solid var(--border, #E2E8F0);
    font-size: 11px;
    font-weight: 700;
  }
  .fm-mob-day-cell.is-done {
    background: rgba(245, 158, 11, 0.16);
    border-color: rgba(245, 158, 11, 0.45);
  }
  .fm-mob-day-cell.is-today {
    box-shadow: inset 0 0 0 1.5px var(--primary, #2563EB);
  }
  .fm-mob-streak-status {
    font-size: 0.84rem;
    font-weight: 600;
    padding: 9px 11px;
    border-radius: 12px;
    margin-bottom: 12px;
    background: rgba(245, 158, 11, 0.12);
  }
  .fm-mob-streak-status.is-ok {
    background: rgba(16, 185, 129, 0.14);
    color: #059669;
  }
  html.dark .fm-mob-streak-status.is-ok {
    color: #34D399;
  }
  .fm-mob-pop-actions {
    display: flex;
    gap: 8px;
  }
  .fm-mob-cta-btn {
    flex: 1;
    min-height: 44px;
    justify-content: center;
    font-weight: 800;
  }
  .fm-mob-close-mini {
    min-height: 44px;
  }

  /* 4-Theme Floating Picker */
  .fm-mob-theme-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .fm-mob-theme-chip {
    min-height: 46px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 14px;
    border: 1.5px solid var(--border, #E2E8F0);
    background: var(--surface-2, #F8FAFC);
    color: var(--text, #0F172A);
    font-size: 0.86rem;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
  }
  .fm-mob-theme-chip.is-active {
    border-color: var(--primary, #2563EB);
    background: rgba(37, 99, 235, 0.1);
  }
  .fm-mob-theme-swatch {
    width: 18px;
    height: 18px;
    border-radius: 9999px;
    flex-shrink: 0;
  }
  .fm-mob-theme-chk {
    margin-left: auto;
    font-weight: 900;
  }

  /* Native Bottom Sheets (Profile & Menu Drawer) */
  .fm-mob-sheet {
    width: 100%;
    max-width: 500px;
    max-height: 86dvh;
    border-radius: 24px 24px 0 0;
    background: var(--surface, #FFFFFF);
    border-top: 1px solid var(--border, #E2E8F0);
    color: var(--text, #0F172A);
    padding: 10px 16px max(env(safe-area-inset-bottom), 16px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 -14px 40px rgba(11, 25, 61, 0.25);
    animation: fmMobSlideUp 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .fm-mob-sheet-handle {
    display: flex;
    justify-content: center;
    padding: 2px 0 10px;
    cursor: grab;
  }
  .fm-mob-sheet-handle > span {
    width: 40px;
    height: 4px;
    border-radius: 9999px;
    background: var(--border, #CBD5E1);
  }

  .fm-mob-sheet-user-head,
  .fm-mob-drawer-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border, #E2E8F0);
  }
  .fm-mob-drawer-head {
    justify-content: space-between;
  }
  .fm-mp-avatar-lg {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }
  .fm-mob-sheet-user-meta {
    flex: 1;
    min-width: 0;
  }
  .fm-mob-sheet-name {
    font-weight: 800;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .fm-mob-sheet-sub {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 4px;
  }
  .fm-mob-tag-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 700;
    background: var(--surface-2, #F1F5F9);
    border: 1px solid var(--border, #E2E8F0);
  }
  .fm-mob-tag-pill.is-rank {
    background: rgba(255, 201, 20, 0.18);
    border-color: rgba(245, 158, 11, 0.45);
  }

  .fm-mob-sheet-x {
    width: 36px;
    height: 36px;
    border-radius: 9999px;
    border: 1px solid var(--border, #E2E8F0);
    background: var(--surface-2, #F8FAFC);
    color: var(--text, #0F172A);
    font-size: 15px;
    font-weight: 800;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .fm-mob-sheet-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 0;
    overflow-y: auto;
  }
  .fm-mob-sheet-row {
    width: 100%;
    min-height: 46px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    border-radius: 14px;
    border: 1px solid var(--border, #E2E8F0);
    background: var(--surface-2, #F8FAFC);
    color: var(--text, #0F172A);
    font-size: 0.92rem;
    font-weight: 700;
    text-align: left;
    touch-action: manipulation;
  }
  .fm-mob-row-lbl {
    flex: 1;
  }
  .fm-mob-row-arr {
    color: var(--text-muted, #64748B);
  }
  .fm-mob-unread-pill {
    padding: 2px 8px;
    border-radius: 9999px;
    background: #EF4444;
    color: #FFFFFF;
    font-size: 11px;
    font-weight: 800;
  }

  .fm-mob-sheet-foot {
    padding-top: 8px;
    border-top: 1px solid var(--border, #E2E8F0);
  }
  .fm-mob-foot-btn {
    width: 100%;
    min-height: 46px;
    justify-content: center;
    font-weight: 800;
    gap: 8px;
  }

  /* Mobile Full Navigation Drawer Sheet */
  .fm-mob-drawer-notif-bar {
    margin-top: 10px;
    width: 100%;
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-radius: 12px;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: var(--text, #0F172A);
    font-size: 0.85rem;
    font-weight: 700;
  }
  .fm-mob-drawer-scroll {
    overflow-y: auto;
    padding: 12px 0 8px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overscroll-behavior: contain;
  }
  .fm-mob-drawer-gtitle {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted, #64748B);
    margin-bottom: 6px;
  }
  .fm-mob-drawer-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .fm-mob-drawer-link {
    min-height: 46px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 13px;
    border: 1px solid var(--border, #E2E8F0);
    background: var(--surface-2, #F8FAFC);
    color: var(--text, #0F172A);
    font-size: 0.84rem;
    font-weight: 700;
    text-align: left;
    touch-action: manipulation;
  }
  .fm-mob-drawer-link.is-active {
    border-color: var(--primary, #2563EB);
    background: rgba(37, 99, 235, 0.12);
    color: var(--primary, #1D4ED8);
  }
  .fm-mob-drawer-legal-foot {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border, #E2E8F0);
    font-size: 0.78rem;
    color: var(--text-muted, #64748B);
  }
  .fm-mob-legal-link {
    background: none;
    border: none;
    color: var(--text-muted, #64748B);
    font-weight: 700;
    font-size: 0.78rem;
    padding: 4px 6px;
  }
}
