/* ═══════════════════════════════════════════════════════════════
   AEI MOBILE — Shared responsive overrides for all pages
   Injected into every HTML file via <link> tag.
   Breakpoints: 768px (tablet), 480px (phone)
   ═══════════════════════════════════════════════════════════════ */

/* ─────────────── GLOBAL MOBILE FIXES ─────────────── */
@media (max-width: 768px) {

  /* --- Fixed elements repositioning --- */
  .aei-brand-bar {
    top: auto !important;
    bottom: 68px !important;
    left: 12px !important;
    padding: 5px 10px 5px 5px !important;
    border-radius: 20px !important;
    font-size: .58rem !important;
    opacity: .85;
    transform: scale(.9);
    transform-origin: bottom left;
  }
  .aei-brand-bar img { width: 22px !important; height: 22px !important; }
  .aei-brand-bar span { font-size: .55rem !important; }

  .aei-logout-pill {
    top: auto !important;
    bottom: 68px !important;
    right: 12px !important;
    left: auto !important;
    font-size: .55rem !important;
    padding: 4px 10px !important;
    opacity: .85;
  }

  .dark-toggle {
    top: 12px !important;
    right: 12px !important;
    width: 44px !important;
    height: 24px !important;
    z-index: 1000 !important;
  }
  .dark-toggle .toggle-knob { width: 17px !important; height: 17px !important; }
  html.dark .dark-toggle .toggle-knob { transform: translateX(20px) !important; }

  /* --- Typography scaling --- */
  .mast-title, .hero h1, .brand-title, .welcome-title {
    font-size: clamp(1.4rem, 6vw, 2rem) !important;
  }
  .mast-sub, .hero-sub, .welcome-sub, .doc-desc {
    font-size: .88rem !important;
  }
  .doc-title {
    font-size: clamp(1.2rem, 5vw, 1.6rem) !important;
  }
  .doc-num {
    font-size: 3rem !important;
    padding-right: 16px !important;
  }
  .doc-head {
    grid-template-columns: auto 1fr !important;
    gap: 14px !important;
  }

  /* --- Wrap container --- */
  .wrap, .content {
    padding: 20px 14px 100px !important;
  }
  .hero {
    margin: 16px 12px 20px !important;
    padding: 22px 18px !important;
  }

  /* --- Masthead / Hero tapes hide on small --- */
  .masthead::before, .masthead::after,
  .hero::before, .hero::after,
  .welcome-hero::before, .welcome-hero::after {
    display: none !important;
  }
  .masthead, .welcome-hero {
    padding: 20px 16px 16px !important;
    margin-bottom: 16px !important;
  }
  .mast-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .mast-meta {
    text-align: left !important;
    font-size: .65rem !important;
  }
  .mast-foot {
    flex-direction: column !important;
    gap: 10px !important;
    align-items: flex-start !important;
  }
  .chips { gap: 5px !important; }
  .chip { font-size: .58rem !important; padding: 3px 7px !important; }

  /* --- Tab navigation: horizontal scroll --- */
  .tabs {
    padding-top: 6px !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .tabstrip {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 4px !important;
    padding-bottom: 4px !important;
    scrollbar-width: none;
  }
  .tabstrip::-webkit-scrollbar { display: none; }
  .tab {
    padding: 10px 12px 8px !important;
    font-size: .6rem !important;
    min-width: max-content;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .tab .num { font-size: .58rem !important; padding: 1px 4px !important; }

  /* Sub-tab strips also scroll */
  .subtab-strip {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 4px !important;
    padding-bottom: 8px !important;
  }
  .subtab-strip::-webkit-scrollbar { display: none; }
  .subtab {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: .58rem !important;
    padding: 6px 10px 5px !important;
  }

  /* --- Column grids: stack --- */
  .cols {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
  }
  .rail {
    position: static !important;
    gap: 16px !important;
  }
  .rail > * {
    transform: none !important;
    max-width: 100% !important;
  }

  /* --- Sidebar: convert to off-canvas drawer --- */
  .sidebar {
    width: 260px !important;
    transform: translateX(-100%) !important;
    transition: transform .3s cubic-bezier(.4,0,.2,1) !important;
    z-index: 1100 !important;
    box-shadow: none !important;
  }
  .sidebar.mobile-open {
    transform: translateX(0) !important;
    box-shadow: 8px 0 30px rgba(0,0,0,.25) !important;
  }
  .main {
    margin-left: 0 !important;
  }

  /* --- Sidebar overlay backdrop --- */
  .mobile-sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1099;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s ease;
  }
  .mobile-sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: all;
  }

  /* --- Tables: horizontal scroll wrapper --- */
  table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    max-width: 100% !important;
  }
  .tbl { font-size: .78rem !important; }
  th, td { padding: 8px 10px !important; white-space: nowrap; }
  .table-card { overflow-x: auto !important; }

  /* --- Code blocks: scroll --- */
  .code, pre, .code-card {
    font-size: .72rem !important;
    max-width: 100% !important;
    overflow-x: auto !important;
  }

  /* --- SVG diagrams: scroll container --- */
  .diagram-wrap, .svg-box, .diagram-card {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .diagram-wrap svg, .svg-box svg, .diagram-body svg {
    min-width: 600px;
  }

  /* --- Step cards: reduce padding --- */
  .step {
    padding: 16px 16px 16px 58px !important;
    transform: none !important;
  }
  .step .step-num {
    width: 44px !important;
    font-size: 1.8rem !important;
  }
  .step h3 { font-size: 1.1rem !important; }

  /* --- Sticky notes: no rotation on mobile --- */
  .sticky {
    transform: none !important;
  }
  .sticky:hover {
    transform: translateY(-2px) !important;
  }

  /* --- Worked examples --- */
  .worked {
    padding: 18px 16px !important;
    margin: 20px 0 !important;
  }
  .worked::before {
    font-size: .55rem !important;
    top: -10px !important;
    left: 14px !important;
    padding: 1px 7px !important;
  }
  .worked .stamp {
    position: static !important;
    display: inline-block;
    margin-bottom: 8px !important;
    transform: none !important;
  }

  /* --- Compare grids: always stack --- */
  .compare {
    grid-template-columns: 1fr !important;
  }
  .compare > div + div {
    border-left: none !important;
    border-top: 1.5px solid var(--ink, #1a1a1a) !important;
  }

  /* --- Move cards grid --- */
  .moves-grid, .card-grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  /* --- Verdict grid --- */
  .verdict {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* --- Torn quote --- */
  .torn {
    padding: 20px 18px 22px !important;
    font-size: 1.2rem !important;
  }

  /* --- Template box --- */
  .tpl { padding: 16px 14px !important; }

  /* --- Anti / Pro --- */
  .anti, .pro { padding: 14px 16px !important; }

  /* --- Footer --- */
  .foot {
    flex-direction: column !important;
    gap: 8px !important;
    padding-top: 16px !important;
  }

  /* --- Pills --- */
  .hero-pills, .doc-tags, .pill-list {
    gap: 5px !important;
  }
  .pill {
    font-size: .56rem !important;
    padding: 2px 6px !important;
  }

  /* --- Opener blocks --- */
  .opener {
    padding: 18px 16px !important;
    margin: 14px 0 20px !important;
  }
  .opener::after { display: none !important; }
  .opener p { font-size: .95rem !important; }

  /* --- Section labels --- */
  .section-label { margin: 24px 0 12px !important; }

  /* --- Part headers --- */
  .part-header {
    gap: 14px !important;
    margin-top: 36px !important;
    margin-bottom: 24px !important;
  }
  .part-number {
    font-size: 2.4rem !important;
    padding-right: 14px !important;
  }
  .part-title {
    font-size: clamp(1.2rem, 4vw, 1.6rem) !important;
  }

  /* --- Callout blocks --- */
  .callout {
    padding: 18px 16px !important;
  }

  /* --- Beginner notes --- */
  .beginner-note-inner {
    padding: 16px !important;
  }

  /* --- Stamp block --- */
  .stamp-block {
    font-size: .6rem !important;
    padding: 5px 10px !important;
    transform: none !important;
  }

  /* --- Mermaid diagrams --- */
  .mermaid-box, .diagram-card {
    overflow-x: auto !important;
  }
  .mermaid {
    min-width: 500px;
  }

  /* --- TOC (brainmap-analysis style) --- */
  .toc {
    padding: .75rem 1rem !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .toc a {
    font-size: .6rem !important;
    margin-right: .5rem !important;
    padding: .15rem .35rem !important;
  }

  /* --- Section (brainmap-analysis style) --- */
  .section {
    padding: 2rem 1rem !important;
  }
  .section h2 { font-size: 1.3rem !important; }

  /* --- Annotation --- */
  .annotation {
    flex-direction: column !important;
    gap: .4rem !important;
    padding: .6rem .8rem !important;
    font-size: .78rem !important;
  }

  /* --- Progress bars --- */
  .progress-bar {
    height: 6px !important;
  }

  /* --- Gantt / Timeline blocks --- */
  .gantt-chart, .gantt-chart-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

}

/* ─────────────── EXTRA SMALL (< 480px) ─────────────── */
@media (max-width: 480px) {

  .brand-title, .mast-title, .hero h1, .welcome-title {
    font-size: clamp(1.2rem, 7vw, 1.6rem) !important;
    letter-spacing: -.01em !important;
  }

  .doc-num {
    font-size: 2.2rem !important;
  }

  .doc-head {
    grid-template-columns: 1fr !important;
    text-align: center;
  }
  .doc-num {
    padding-right: 0 !important;
    text-align: center;
  }
  .doc-num::after { display: none !important; }
  .doc-num small { margin-top: 4px !important; }

  .step {
    padding: 14px 12px 14px 14px !important;
  }
  .step .step-num {
    position: relative !important;
    width: auto !important;
    border-right: none !important;
    border-bottom: 1.5px solid var(--ink, #1a1a1a) !important;
    padding: 4px 12px !important;
    font-size: 1.4rem !important;
    margin-bottom: 10px !important;
    display: inline-block !important;
  }

  .verdict {
    grid-template-columns: 1fr !important;
  }

  .welcome-stats {
    grid-template-columns: 1fr 1fr 1fr !important;
    max-width: 100% !important;
  }

  .cards-grid {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
    max-width: 100% !important;
  }

  .login-card {
    padding: 22px 18px 18px !important;
  }
  .card-tape { display: none !important; }

  .logo-img {
    width: 64px !important;
    height: 64px !important;
  }

  .hero-meta {
    flex-direction: column !important;
    gap: .5rem !important;
  }

  .tab .swatch { display: none !important; }

  .aei-brand-bar { display: none !important; }
}

/* ─────────────── MOBILE BOTTOM NAV BAR ─────────────── */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--paper, #FCFAF3);
    border-top: 1px solid rgba(26,26,26,.08);
    box-shadow: 0 -4px 16px rgba(26,26,26,.08);
    z-index: 1050;
    align-items: center;
    justify-content: space-around;
    padding: 0 8px;
    gap: 4px;
  }

  .mobile-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: rgba(26,26,26,.5);
    font-family: 'Inter', sans-serif;
    font-size: .52rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    transition: color .2s ease;
    text-decoration: none;
    border-radius: 8px;
  }
  .mobile-nav-btn:hover, .mobile-nav-btn.active {
    color: var(--aub-deep, #5C3E6E);
    background: color-mix(in srgb, var(--aub, #B8A5C0) 12%, transparent);
  }
  .mobile-nav-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 2;
  }

  /* Push page content up so it's not hidden behind bottom nav */
  body {
    padding-bottom: 64px !important;
  }
  .foot, .footer, .footer-text {
    margin-bottom: 64px !important;
  }
}

/* ─────────────── MOBILE HAMBURGER BUTTON ─────────────── */
.mobile-hamburger {
  display: none;
}
@media (max-width: 768px) {
  .mobile-hamburger {
    display: flex;
    position: fixed;
    top: 10px;
    left: 12px;
    z-index: 1101;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(26,26,26,.1);
    background: var(--paper, #FCFAF3);
    box-shadow: -2px -2px 5px rgba(255,255,255,.92), 2px 2px 5px rgba(26,26,26,.08);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all .2s ease;
    padding: 0;
  }
  .mobile-hamburger:hover {
    box-shadow: -2px -2px 5px rgba(255,255,255,.92), 2px 2px 8px rgba(26,26,26,.14);
    transform: scale(1.05);
  }
  .mobile-hamburger svg {
    width: 18px;
    height: 18px;
    color: var(--ink, #1a1a1a);
  }
  html.dark .mobile-hamburger {
    background: var(--paper, #1C1B1A);
    border-color: rgba(255,255,255,.08);
    box-shadow: -2px -2px 5px rgba(255,255,255,.06), 2px 2px 5px rgba(0,0,0,.25);
  }
  html.dark .mobile-hamburger svg { color: var(--ink, #E8E4DA); }
}

/* ─────────────── DARK MODE MOBILE OVERRIDES ─────────────── */
@media (max-width: 768px) {
  html.dark .mobile-bottom-nav {
    background: var(--paper, #1C1B1A);
    border-top-color: rgba(255,255,255,.06);
    box-shadow: 0 -4px 16px rgba(0,0,0,.25);
  }
  html.dark .mobile-nav-btn {
    color: rgba(232,228,218,.5);
  }
  html.dark .mobile-nav-btn:hover,
  html.dark .mobile-nav-btn.active {
    color: var(--aub-deep, #C8A8E0);
    background: rgba(200,168,224,.08);
  }
  html.dark .mobile-sidebar-backdrop {
    background: rgba(0,0,0,.6);
  }
}

/* ─────────────── SMOOTH SCROLL HINT ─────────────── */
@media (max-width: 768px) {
  .tabstrip::after, .subtab-strip::after {
    content: "";
    flex-shrink: 0;
    width: 24px;
  }
}

/* ─────────────── PRINT: HIDE MOBILE ELEMENTS ─────────────── */
@media print {
  .mobile-bottom-nav,
  .mobile-hamburger,
  .mobile-sidebar-backdrop,
  .aei-brand-bar,
  .aei-logout-pill,
  .dark-toggle { display: none !important; }
}
