/* ============================================================
   HYPagotchi · Mobile Responsive Stylesheet  v5
   Comprehensive responsive overrides for every page.
   Uses !important to beat inline style= attributes.
   ============================================================ */

/* ─────────────────────────────────────────────────────────
   GLOBAL BASE — applies at all sizes
   ───────────────────────────────────────────────────────── */
html, body {
  overflow-x: hidden !important;
  max-width: 100vw !important;
}
*, *::before, *::after { box-sizing: border-box; }
img, svg, canvas, video, iframe { max-width: 100%; }

/* Prevent any fixed-width element from blowing out the page */
[style*="min-width:"], [style*="min-width :"] {
  min-width: 0 !important;
}

/* Mobile nav drawer state */
body.menu-open { overflow: hidden; }
.menu-toggle.is-open svg { transform: rotate(90deg); transition: transform .15s ease; }

/* ═══════════════════════════════════════════════════════════
   ≤ 1100px  — hide desktop nav early, show hamburger
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  .nav-links { display: none !important; }
  .menu-toggle { display: inline-flex !important; }
  /* Compact header padding */
  .site-header .inner { padding: 0 20px !important; }
}

/* ═══════════════════════════════════════════════════════════
   ≤ 900px  — grids collapse, sections tighten
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  /* ── Containers ── */
  .container, .container-wide {
    padding-left: 18px !important;
    padding-right: 18px !important;
    max-width: 100% !important;
  }

  /* ── Typography scale ── */
  h1 { font-size: clamp(32px, 8vw, 64px) !important; line-height: 1.05 !important; }
  h2, .section-title { font-size: clamp(26px, 6vw, 48px) !important; line-height: 1.1 !important; }
  h3 { font-size: clamp(18px, 4.5vw, 26px) !important; }

  /* ── Section padding ── */
  .section { padding: 56px 0 !important; }
  .section-tight { padding: 40px 0 !important; }
  section[style*="padding:96px"],
  section[style*="padding: 96px"] { padding-top: 56px !important; padding-bottom: 56px !important; }
  section[style*="padding:88px"],
  section[style*="padding: 88px"] { padding-top: 56px !important; padding-bottom: 56px !important; }
  section[style*="padding:80px"],
  section[style*="padding: 80px"] { padding-top: 48px !important; padding-bottom: 48px !important; }
  section[style*="padding:72px"],
  section[style*="padding: 72px"] { padding-top: 44px !important; padding-bottom: 44px !important; }

  /* ── Buttons ── */
  .btn, button.btn, a.btn { min-height: 44px !important; }
  .btn-lg { font-size: 15px !important; padding: 14px 22px !important; }

  /* ── Cards ── */
  .card { transform: none !important; } /* kill rotated cards on mobile */

  /* ── Footer ── */
  .site-footer .grid { grid-template-columns: 1fr 1fr !important; gap: 28px !important; }
  .site-footer { padding: 48px 0 24px !important; margin-top: 40px !important; }

  /* ──────── INDEX ──────── */
  #hero-grid {
    grid-template-columns: 1fr !important;
    gap: 32px !important;
  }
  .hero-wrap { min-height: auto !important; padding: 100px 0 56px !important; }
  /* hero stat tiles 2×2 */
  #hero-grid > div > div[style*="grid-template-columns:repeat(4,1fr)"],
  #hero-grid > div > div[style*="grid-template-columns: repeat(4,1fr)"],
  #hero-grid > div > div[style*="grid-template-columns:repeat(4, 1fr)"],
  #hero-grid > div > div[style*="grid-template-columns: repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
  .how-grid { grid-template-columns: 1fr !important; gap: 20px !important; }
  #speciesGrid { grid-template-columns: repeat(2, 1fr) !important; gap: 16px !important; }
  #hyperGrid { grid-template-columns: 1fr !important; gap: 32px !important; }
  /* token banner on index */
  #tokenBanner { grid-template-columns: 1fr !important; gap: 28px !important; }

  /* ──────── HATCHERY ──────── */
  #hatchGrid { grid-template-columns: 1fr !important; gap: 24px !important; }
  .egg-stage { max-width: 240px !important; margin: 0 auto !important; }

  /* ──────── SPECIES ──────── */
  .exec-grid { grid-template-columns: 1fr !important; gap: 20px !important; }
  /* inner spec pills — allow wrap */
  .exec-grid > div[style*="min-width:240px"] { min-width: 0 !important; width: 100% !important; }
  .sp-row { grid-template-columns: 1fr !important; }

  /* ──────── LEADERBOARD ──────── */
  #topStats { grid-template-columns: 1fr 1fr !important; gap: 12px !important; }
  #podium { grid-template-columns: 1fr !important; gap: 14px !important; }
  #podium > a { transform: none !important; }
  #speciesRankings { grid-template-columns: 1fr 1fr !important; gap: 12px !important; }
  #lbFilterRow {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 8px !important;
    gap: 8px !important;
    scrollbar-width: none;
  }
  #lbFilterRow::-webkit-scrollbar { display: none; }
  #lbFilterRow > * { flex-shrink: 0 !important; }

  /* ──────── TOKEN ──────── */
  #tokenHeroGrid { grid-template-columns: 1fr !important; gap: 32px !important; }
  #purposesGrid { grid-template-columns: 1fr !important; gap: 20px !important; }
  #distributionGrid { grid-template-columns: 1fr 1fr !important; gap: 14px !important; }

  /* ──────── CREDITS ──────── */
  #creditsGrid { grid-template-columns: 1fr !important; gap: 20px !important; }
  #howGrid { grid-template-columns: 1fr !important; gap: 20px !important; }

  /* ──────── STAKING ──────── */
  #tiersGrid { grid-template-columns: 1fr 1fr !important; gap: 14px !important; }
  #stakeGrid { grid-template-columns: 1fr !important; gap: 20px !important; }
  #poolGrid { grid-template-columns: 1fr !important; gap: 20px !important; }
  #poolStatsRow { grid-template-columns: repeat(2, 1fr) !important; gap: 12px !important; }
  #principlesGrid { grid-template-columns: 1fr !important; gap: 16px !important; }
  #modeGrid { grid-template-columns: 1fr !important; gap: 20px !important; }

  /* ──────── AIRDROP ──────── */
  #airGrid { grid-template-columns: 1fr !important; gap: 20px !important; }
  #wayGrid { grid-template-columns: 1fr !important; gap: 14px !important; }
  .air-hero { padding: 80px 0 60px !important; }

  /* ──────── ROADMAP ──────── */
  .phase-grid { grid-template-columns: 1fr !important; gap: 24px !important; }
  .phase-grid > div:first-child p[style*="max-width:280px"] { max-width: 100% !important; }

  /* ──────── WHITEPAPER ──────── */
  .wp-grid { grid-template-columns: 1fr !important; gap: 20px !important; }
  .wp-toc { display: none !important; }
  .wp-mobile-toc { display: block !important; }

  /* ──────── DASHBOARD ──────── */
  #summaryTiles { grid-template-columns: 1fr 1fr !important; gap: 12px !important; }
  #agentGrid { grid-template-columns: 1fr !important; gap: 16px !important; }
}

/* ═══════════════════════════════════════════════════════════
   ≤ 768px  — full mobile treatment, nav drawer
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* ── Nav drawer ── */
  .nav-links { display: none !important; }
  .menu-toggle { display: inline-flex !important; z-index: 9999 !important; }

  .nav-links.open, .nav-links.is-open {
    display: flex !important;
    position: fixed !important;
    top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
    background: var(--bg, #FDF5F0) !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    padding: 86px 20px 32px !important;
    gap: 0 !important;
    z-index: 9998 !important;
    overflow-y: auto !important;
    border: none !important;
    list-style: none !important;
    margin: 0 !important;
  }
  .nav-links.open a, .nav-links.is-open a {
    padding: 16px 8px !important;
    border-bottom: 1.5px solid rgba(0,0,0,0.07) !important;
    font-size: 17px !important;
    font-weight: 700 !important;
    width: 100% !important;
    border-radius: 0 !important;
    background: transparent !important;
    min-height: 52px !important;
    display: flex !important;
    align-items: center !important;
  }
  .menu-toggle.is-open { background: var(--ink, #1A202C) !important; }
  .menu-toggle.is-open svg path,
  .menu-toggle.is-open svg line { stroke: white !important; }

  /* ── Header ── */
  .site-header .inner { height: 64px !important; padding: 0 16px !important; }
  #connectBtn { font-size: 12px !important; padding: 8px 12px !important; }
  .nav-right .icon-btn[aria-label="Discord"],
  .nav-right .icon-btn[aria-label="X / Twitter"] { display: none !important; }

  /* ── HyperCore strip ── */
  .hyper-strip { font-size: 10px !important; gap: 8px !important; padding: 5px 12px !important; }
  .hyper-strip .hide-sm { display: none !important; }

  /* ── Typography ── */
  h1 { font-size: clamp(30px, 9vw, 52px) !important; }
  h2, .section-title { font-size: clamp(24px, 7vw, 40px) !important; }
  .section-sub { font-size: 15px !important; }
  p { font-size: 15px !important; }

  /* ── INDEX: hero stats 2×2 ── */
  #hero-grid > div > div[style*="grid-template-columns:repeat(4,1fr)"],
  #hero-grid > div > div[style*="grid-template-columns: repeat(4,1fr)"],
  #hero-grid > div > div[style*="grid-template-columns:repeat(4, 1fr)"],
  #hero-grid > div > div[style*="grid-template-columns: repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
    margin-top: 28px !important;
  }
  /* hero CTA row wraps full-width */
  #hero-grid > div > div[style*="display:flex"][style*="gap:12px"] {
    flex-direction: column !important;
    gap: 10px !important;
  }
  #hero-grid .btn-lg { width: 100% !important; justify-content: center !important; }
  /* species grid 1-col on phones */
  #speciesGrid { grid-template-columns: 1fr !important; }

  /* ── AIRDROP: hero CTA buttons stack ── */
  #airHeroCta {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    max-width: 400px !important;
    margin: 0 auto !important;
  }
  #airHeroCta .discord-btn,
  #airHeroCta .btn {
    width: 100% !important;
    justify-content: center !important;
  }

  /* ── HATCHERY ── */
  #hatchGrid { grid-template-columns: 1fr !important; }

  /* ── SPECIES: species jump pills wrap ── */
  #speciesJumps { justify-content: flex-start !important; }

  /* ── TOKEN: hero card remove rotation ── */
  #tokenHeroGrid .card[style*="rotate"] { transform: none !important; }
  #tokenHeroGrid .card[style*="rotate(-2deg)"] { transform: none !important; }
  /* token hero CTA row */
  #tokenHeroGrid > div:first-child > div[style*="display:flex"] {
    flex-direction: column !important;
    gap: 10px !important;
  }
  #tokenHeroGrid > div:first-child .btn { width: 100% !important; justify-content: center !important; }
  #distributionGrid { grid-template-columns: 1fr !important; gap: 14px !important; }

  /* ── AIRDROP ── */
  .air-hero h1 { font-size: clamp(36px, 10vw, 68px) !important; }
  .air-hero p { font-size: 16px !important; }
  .air-hero > section > div > div[style*="display:flex"],
  section.air-hero div[style*="display:flex"][style*="gap:14px"] {
    flex-direction: column !important; gap: 10px !important;
  }
  .discord-btn { width: 100% !important; justify-content: center !important; }
  .air-hero .btn { width: 100% !important; justify-content: center !important; }
  /* airdrop register box */
  .register-box { padding: 24px 18px !important; }
  /* Discord CTA card inner flex */
  .card[style*="background:#404EED"] > div[style*="display:flex"] {
    flex-direction: column !important;
    gap: 12px !important;
    align-items: flex-start !important;
  }

  /* ── STAKING ── */
  #tiersGrid { grid-template-columns: 1fr 1fr !important; }
  #poolStatsRow { grid-template-columns: repeat(2, 1fr) !important; }
  /* tier cards font shrink */
  #tiersGrid .card > div[style*="font-size: 32px"],
  #tiersGrid .card > div[style*="font-size:32px"] { font-size: 24px !important; }

  /* ── LEADERBOARD filter ── */
  #lbFilterRow { margin-left: -18px !important; margin-right: -18px !important; padding-left: 18px !important; padding-right: 18px !important; }

  /* ── ROADMAP phase items ── */
  .phase-grid > div:last-child > .card-soft {
    padding: 14px 16px !important;
  }
  /* phase item row: stack chip below text on small screens */
  .card-soft[style*="justify-content:space-between"] {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  /* ── WHITEPAPER ── */
  .wp-section { padding: 20px 0 !important; }

  /* ── Footer ── */
  .site-footer .grid { grid-template-columns: 1fr 1fr !important; gap: 24px !important; }
  .site-footer .bottom { flex-direction: column !important; gap: 8px !important; text-align: center !important; }
  .site-footer .bottom span:last-child { text-align: center !important; }

  /* ── Modals ── */
  .hyp-modal { padding: 0 !important; align-items: flex-end !important; }
  .hyp-modal-card {
    max-width: 100% !important;
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    border-top-left-radius: 20px !important;
    border-top-right-radius: 20px !important;
    padding: 24px 18px 36px !important;
  }

  /* ── Generic flex rows that overflow ── */
  .site-footer .bottom[style*="display:flex"] {
    flex-direction: column !important;
    gap: 8px !important;
  }
}

/* ═══════════════════════════════════════════════════════════
   ≤ 480px  — small phones
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .container, .container-wide { padding-left: 14px !important; padding-right: 14px !important; }

  /* ── Typography ── */
  h1 { font-size: clamp(28px, 9.5vw, 40px) !important; }
  h2, .section-title { font-size: clamp(22px, 7.5vw, 32px) !important; }
  body { font-size: 14px !important; }

  /* ── Header brand ── */
  .brand { font-size: 18px !important; gap: 8px !important; }
  .brand .mark { width: 32px !important; height: 32px !important; }
  .site-header .inner { height: 60px !important; padding: 0 14px !important; }

  /* ── Buttons ── */
  .btn-lg { font-size: 14px !important; padding: 13px 18px !important; }
  .btn-sm { font-size: 12px !important; padding: 9px 14px !important; }
  #connectBtn { font-size: 11px !important; padding: 7px 10px !important; }

  /* ── Cards ── */
  .card { padding: 18px !important; border-radius: 16px !important; }
  .card-soft { padding: 14px 16px !important; }

  /* ── INDEX ── */
  .hero-wrap { padding: 88px 0 44px !important; }
  #hero-grid > div > div[style*="grid-template-columns"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    margin-top: 24px !important;
  }
  .hero-stat-num,
  #hero-grid div[style*="font-size:clamp(26px"] { font-size: 20px !important; }

  /* ── STAKING ── */
  #tiersGrid { grid-template-columns: 1fr !important; gap: 12px !important; }
  #poolStatsRow { grid-template-columns: repeat(2, 1fr) !important; }

  /* ── TOKEN ── */
  #distributionGrid { grid-template-columns: 1fr !important; gap: 12px !important; }
  #tokenHeroGrid .card > div[style*="font-size: 64px"],
  #tokenHeroGrid .card > div[style*="font-size:64px"] { font-size: 36px !important; }

  /* ── AIRDROP ── */
  .teaser-pill { font-size: 10px !important; letter-spacing: .06em !important; padding: 6px 12px !important; }
  /* stat tiles 1-col on 375px */
  #airGrid > div > div > div[style*="grid-template-columns:1fr 1fr"],
  #airGrid > div > div > div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* ── LEADERBOARD ── */
  #topStats { grid-template-columns: 1fr 1fr !important; }
  #speciesRankings { grid-template-columns: 1fr !important; gap: 10px !important; }

  /* ── ROADMAP ── */
  .phase-grid > div:last-child > .card-soft[style*="justify-content:space-between"] {
    flex-direction: column !important;
    align-items: flex-start !important;
  }

  /* ── Footer ── */
  .site-footer .grid { grid-template-columns: 1fr !important; gap: 20px !important; }
  .site-footer { padding: 40px 0 20px !important; }

  /* ── Toast ── */
  .hyp-toast-wrap { bottom: 14px !important; right: 14px !important; left: 14px !important; }
  .hyp-toast { font-size: 13px !important; padding: 10px 14px !important; }
}

/* ═══════════════════════════════════════════════════════════
   ≤ 380px  — very small phones (Galaxy S8 etc)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 380px) {
  h1 { font-size: clamp(26px, 10vw, 36px) !important; }
  h2, .section-title { font-size: clamp(20px, 8vw, 28px) !important; }
  .container, .container-wide { padding-left: 12px !important; padding-right: 12px !important; }
  .btn-lg { font-size: 13px !important; padding: 12px 14px !important; }
  /* token symbol card on token page */
  #tokenHeroGrid .card > div[style*="font-size: 64px"] { font-size: 28px !important; }
  /* nav brand text cut short */
  .brand span:last-child { display: none !important; }
  /* airdrop stat tiles always 1-col */
  #airGrid > div > div > div[style] { grid-template-columns: 1fr !important; }
}

/* ═══════════════════════════════════════════════════════════
   WHITEPAPER: mobile TOC dropdown
   ═══════════════════════════════════════════════════════════ */
.wp-mobile-toc { display: none; }
.wp-mobile-toc select {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-family: var(--font-body, system-ui);
  font-weight: 600;
  border: 2px solid var(--ink, #1a1a1a);
  border-radius: 12px;
  background: white;
  margin-bottom: 24px;
  box-shadow: 3px 3px 0 var(--ink, #1a1a1a);
}
@media (max-width: 900px) {
  .wp-mobile-toc { display: block !important; }
  .wp-toc { display: none !important; }
}

/* ═══════════════════════════════════════════════════════════
   UTILITY: table horizontal scroll on mobile
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .table-scroll-mob, [id$="Table"] { overflow-x: auto !important; -webkit-overflow-scrolling: touch !important; }
  table { min-width: 480px; }
  /* Leaderboard / dashboard tables hide optional cols */
  table.responsive-trades th.opt,
  table.responsive-trades td.opt { display: none !important; }
}

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