/* ============================================
   CANVENA Responsive App-Layer (Relaunch 2026)
   Desktop: unchanged
   Tablet (<=1024): App-like padding/cards
   Mobile (<=640): Full app-shell with drawer + bottom-tab-bar
   Loaded AFTER style.css + premium.css → overrides only what's needed
   ============================================ */

/* === Safe-Area for iOS notch / Android navbar === */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
}

/* === Universal Touch-Target Minimums (WCAG 2.5.5 / Apple HIG) === */
@media (hover: none) and (pointer: coarse) {
  a, button, .btn, .nav__link, .lang-switcher__option, .nav-dropdown-item,
  .tier-card__cta, input[type="submit"], input[type="button"] {
    min-height: 44px;
    min-width: 44px;
  }
  /* Disable hover transforms on touch */
  *:hover { transform: none !important; }
}

/* ============================================
   TABLET LAYER (601-1024px) — App-like
   ============================================ */
@media (min-width: 601px) and (max-width: 1024px) {
  .container { padding-left: 32px; padding-right: 32px; }
  .nav__inner { padding: 12px 20px; }
  .btn, .tier-card__cta { padding: 14px 22px; font-size: 0.95rem; }
  /* Larger card padding, app-feel */
  .tier-card { padding: 36px 24px 28px; border-radius: 22px; }
  /* Snap-scroll for horizontal card rows */
  .tier-grid-5, .grid-3 { scroll-behavior: smooth; }
}

/* ============================================
   MOBILE LAYER (<=640px) — Full App Shell
   ============================================ */
@media (max-width: 640px) {
  /* === Body padding for fixed top-nav + bottom-tab-bar === */
  body {
    padding-bottom: calc(var(--tabbar-h) + var(--safe-bot)) !important;
    -webkit-tap-highlight-color: transparent;
  }

  /* === Top Nav — compact app header === */
  .nav {
    padding-top: var(--safe-top);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    background: rgba(13, 22, 42, 0.78);
    border-bottom: 1px solid rgba(212, 175, 55, 0.08);
  }
  .nav__inner { padding: 10px 16px; min-height: 56px; }
  .nav__logo { font-size: 1.05rem; letter-spacing: 0.04em; }

  /* === Hide desktop nav-links, show drawer instead === */
  .nav__links {
    /* Use override-class for drawer */
    display: none;
  }
  .nav__hamburger {
    display: flex !important;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: transparent;
    border: 1px solid rgba(212, 175, 55, 0.18);
    border-radius: 12px;
    cursor: pointer;
  }
  .nav__hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: #F5F0E8;
    margin: 2px 0;
    transition: transform 0.3s cubic-bezier(0.16,1,0.3,1), opacity 0.2s;
  }
  .nav__hamburger.active span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .nav__hamburger.active span:nth-child(2) { opacity: 0; }
  .nav__hamburger.active span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

  /* === Side Drawer (Mobile Menu) === */
  .app-drawer-backdrop {
    position: fixed; inset: 0;
    background: rgba(8, 14, 30, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.16,1,0.3,1);
    z-index: 10000; /* above nav (1000) and any other layer except consent */
  }
  .app-drawer-backdrop.open { opacity: 1; pointer-events: auto; }

  .app-drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(86vw, 360px);
    background: linear-gradient(180deg, #14213D 0%, #0D162A 100%);
    border-left: 1px solid rgba(212, 175, 55, 0.12);
    box-shadow: -24px 0 60px rgba(0, 0, 0, 0.5);
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 10001; /* above backdrop, above nav */
    display: flex;
    flex-direction: column;
    padding-top: calc(var(--safe-top) + 12px);
    padding-bottom: calc(var(--safe-bot) + 20px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .app-drawer.open { transform: translateX(0); }

  .app-drawer__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid rgba(245, 240, 232, 0.06);
  }
  .app-drawer__logo {
    font-family: var(--font-editorial, 'Fraunces', serif);
    font-size: 1.15rem;
    font-weight: 500;
    color: #F5F0E8;
    text-decoration: none;
    letter-spacing: 0.04em;
  }
  .app-drawer__logo span { color: #D4AF37; }
  .app-drawer__close {
    width: 36px; height: 36px;
    border: none;
    background: rgba(245, 240, 232, 0.06);
    color: #F5F0E8;
    border-radius: 50%;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
  }

  .app-drawer__nav {
    display: flex;
    flex-direction: column;
    padding: 12px 16px;
    gap: 2px;
  }
  .app-drawer__nav a, .app-drawer__nav button {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 16px;
    color: rgba(245, 240, 232, 0.92);
    text-decoration: none;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 12px;
    border: none;
    background: transparent;
    text-align: left;
    width: 100%;
    cursor: pointer;
    transition: background 0.2s;
  }
  .app-drawer__nav a:active, .app-drawer__nav button:active { background: rgba(212, 175, 55, 0.08); }
  .app-drawer__group {
    display: flex; flex-direction: column;
    margin: 4px 0;
    border-radius: 12px;
    overflow: hidden;
  }
  .app-drawer__group-toggle::after {
    content: '+';
    color: rgba(212, 175, 55, 0.7);
    font-size: 1.2rem;
    transition: transform 0.3s;
  }
  .app-drawer__group.open .app-drawer__group-toggle::after { content: '−'; }
  .app-drawer__sublist {
    display: none;
    flex-direction: column;
    padding-left: 18px;
    border-left: 2px solid rgba(212, 175, 55, 0.15);
    margin-left: 16px;
    margin-bottom: 8px;
  }
  .app-drawer__group.open .app-drawer__sublist { display: flex; }
  .app-drawer__sublist a {
    padding: 12px 14px;
    font-size: 0.93rem;
    color: rgba(245, 240, 232, 0.72);
  }

  .app-drawer__divider {
    height: 1px;
    background: rgba(245, 240, 232, 0.06);
    margin: 16px 24px;
  }

  .app-drawer__langs {
    display: flex; flex-wrap: wrap;
    gap: 8px;
    padding: 8px 24px 16px;
  }
  .app-drawer__langs button {
    padding: 8px 14px;
    background: rgba(245, 240, 232, 0.06);
    border: 1px solid transparent;
    color: rgba(245, 240, 232, 0.7);
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    min-height: 36px;
  }
  .app-drawer__langs button.active {
    background: rgba(212, 175, 55, 0.16);
    border-color: rgba(212, 175, 55, 0.35);
    color: #D4AF37;
  }

  .app-drawer__cta {
    margin: 12px 20px;
    padding: 16px;
    display: flex; align-items: center; justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, #D4AF37 0%, #E8C547 100%);
    color: #0D162A;
    font-weight: 700;
    font-size: 0.95rem;
    border-radius: 14px;
    text-decoration: none;
    box-shadow: 0 8px 24px rgba(212, 175, 55, 0.28);
  }

  /* === Bottom Tab Bar (App-style) === */
  .app-tabbar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 9998; /* below drawer (10001) but above page nav (1000) */
    height: calc(var(--tabbar-h) + var(--safe-bot));
    padding-bottom: var(--safe-bot);
    background: rgba(13, 22, 42, 0.92);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-top: 1px solid rgba(212, 175, 55, 0.12);
    display: flex;
    z-index: 997;
  }
  .app-tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: rgba(245, 240, 232, 0.55);
    text-decoration: none;
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: color 0.2s;
    padding: 6px 4px;
  }
  .app-tabbar a svg {
    width: 22px; height: 22px;
    stroke: currentColor;
    stroke-width: 1.7;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .app-tabbar a[aria-current="page"],
  .app-tabbar a.active {
    color: #D4AF37;
  }
  .app-tabbar a:active { transform: scale(0.95); }

  /* === Hero Mobile-Scaling (cv-hero-cinematic on all tier pages) === */
  .cv-hero-cinematic, .hero {
    min-height: 78vh !important;
    padding-top: 100px !important;
    padding-bottom: 40px !important;
  }
  .cv-hero-cinematic h1, .cv-hero__title, .hero h1 {
    font-size: clamp(2rem, 1.2rem + 5vw, 3.4rem) !important;
    line-height: 1.05 !important;
    letter-spacing: -0.02em !important;
  }
  .cv-hero-cinematic .cv-hero__lead, .cv-hero-cinematic p, .hero p {
    font-size: clamp(0.95rem, 0.85rem + 0.5vw, 1.15rem) !important;
    line-height: 1.5 !important;
    max-width: 92% !important;
    margin-left: auto; margin-right: auto;
  }
  .cv-hero__eyebrow, .hero__subtitle {
    font-size: 0.7rem !important;
    letter-spacing: 0.18em !important;
  }
  .cv-hero__ctas, .hero__ctas {
    flex-direction: column !important;
    gap: 12px !important;
    width: 100% !important;
    align-items: stretch !important;
  }
  .cv-hero__ctas .btn, .hero__ctas .btn { width: 100% !important; }

  /* === Tier-Cards stacked on mobile === */
  .tier-grid-5 {
    grid-template-columns: 1fr !important;
    display: grid !important;
    overflow: visible !important;
    padding: 0 !important;
    margin-inline: 0 !important;
    gap: 14px !important;
  }
  .tier-grid-5 > .tier-card {
    flex: none !important;
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* === Spec stats / general grids stack === */
  .cv-spec-stats, .stats-bar, .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  .cv-spec-stat__num { font-size: clamp(2rem, 1.4rem + 3vw, 3rem) !important; }

  /* === Funding Signals Ticker — clip overflow === */
  .live-funding-signals, .cv-ticker, .marquee {
    overflow: hidden !important;
    max-width: 100vw;
    margin-inline: 0 !important;
  }

  /* === Cookie Banner — bottom sheet style, above tabbar === */
  /* Lift consent banner above the bottom tab bar so it stays usable */
  #canvena-consent {
    bottom: calc(var(--tabbar-h) + var(--safe-bot) + 8px) !important;
  }
  .cookie-banner, #cookie-banner, .consent-banner {
    position: fixed !important;
    bottom: calc(var(--tabbar-h) + var(--safe-bot) + 8px) !important;
    left: 8px !important; right: 8px !important;
    border-radius: 18px !important;
    padding: 16px !important;
    max-width: none !important;
    z-index: 996;
  }
  .cookie-banner .btn, #cookie-banner button {
    width: 100% !important;
    margin-top: 8px;
  }

  /* === Footer compact on mobile === */
  .footer__grid {
    grid-template-columns: 1fr !important;
    gap: 28px !important;
    text-align: left;
  }
  .footer { padding-bottom: 24px !important; }

  /* === Section padding tighter === */
  section { padding-top: 56px !important; padding-bottom: 56px !important; }
  .container { padding-left: 18px !important; padding-right: 18px !important; }

  /* === Disable expensive animations on mobile for perf === */
  .cv-hero-mesh::before, .aurora, .particle-network { will-change: auto; }
}

/* === Very small phones (<= 380px) === */
@media (max-width: 380px) {
  .nav__inner { padding: 8px 12px; }
  .nav__logo { font-size: 0.95rem; }
  .cv-hero-cinematic h1, .hero h1 { font-size: 1.85rem !important; }
  .app-tabbar a { font-size: 0.6rem; }
  .app-tabbar a svg { width: 20px; height: 20px; }
}

/* === Disable drawer/tabbar above 640px === */
@media (min-width: 641px) {
  .app-drawer, .app-drawer-backdrop, .app-tabbar { display: none !important; }
}
