/* ============================================================
   mobile.css — Responsive overrides for the stack/SP components
   Supplements the inline <style> block in index.html
   ============================================================ */

/* ── Hamburger button: hidden on desktop ── */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  width: 32px;
  height: 32px;
}

.nav-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--color-text);
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.25s ease;
  transform-origin: center;
}

/* Animate to X when open */
.nav-hamburger.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.is-open span:nth-child(2) { opacity: 0; }
.nav-hamburger.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Fullscreen mobile menu ── */
.mobile-menu {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  z-index: 200;
  flex-direction: column;
  padding: 0 1.5rem 2rem;
  overflow-y: auto;
}

.mobile-menu.is-open {
  display: flex;
}

.mobile-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--nav-height);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.mobile-menu-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--color-muted);
  padding: 4px;
  line-height: 1;
}

.mobile-menu-nav {
  display: flex;
  flex-direction: column;
  padding-top: 2rem;
}

.mobile-menu-section-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 400;
  color: #636363;
  margin-bottom: 16px;
}

.mobile-menu-section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.mobile-menu-section-row .mobile-menu-section-label {
  margin-bottom: 0;
}

.mobile-menu-section-label--spaced {
  margin-top: 24px;
}

.mobile-menu-link {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
  letter-spacing: -0.02em;
}

.mobile-menu-link--top-border {
  margin-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

.mobile-menu-link--no-border {
  border-bottom: none;
}

/* ── Mobile menu stagger animation ── */
@keyframes menuItemIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.mobile-menu.is-open .mobile-menu-nav > * {
  opacity: 0;
  animation: menuItemIn 0.3s ease forwards;
}

.mobile-menu.is-open .mobile-menu-nav > *:nth-child(1)  { animation-delay: 0.05s; }
.mobile-menu.is-open .mobile-menu-nav > *:nth-child(2)  { animation-delay: 0.10s; }
.mobile-menu.is-open .mobile-menu-nav > *:nth-child(3)  { animation-delay: 0.15s; }
.mobile-menu.is-open .mobile-menu-nav > *:nth-child(4)  { animation-delay: 0.20s; }
.mobile-menu.is-open .mobile-menu-nav > *:nth-child(5)  { animation-delay: 0.25s; }
.mobile-menu.is-open .mobile-menu-nav > *:nth-child(6)  { animation-delay: 0.30s; }
.mobile-menu.is-open .mobile-menu-nav > *:nth-child(7)  { animation-delay: 0.35s; }
.mobile-menu.is-open .mobile-menu-nav > *:nth-child(8)  { animation-delay: 0.40s; }
.mobile-menu.is-open .mobile-menu-nav > *:nth-child(9)  { animation-delay: 0.45s; }
.mobile-menu.is-open .mobile-menu-nav > *:nth-child(10) { animation-delay: 0.50s; }
.mobile-menu.is-open .mobile-menu-nav > *:nth-child(11) { animation-delay: 0.55s; }

.mobile-menu-socials {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  margin-top: auto;
  padding-top: 2rem;
}

.mobile-menu-socials a {
  font-size: 0.8rem;
  color: var(--color-muted);
  text-decoration: none;
  white-space: nowrap;
}

.mobile-menu-socials span {
  color: var(--color-muted);
}

.mobile-menu-tag {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--color-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .nav-hamburger { display: flex; }
  .nav-links { display: none; }
  .nav-l2 { display: none !important; }
}

/* ── Stack scroll container: reduce height so cards sit on-screen ── */
@media (max-width: 768px) {
  /* Tighten the sticky scroll zone on mobile so the card stack
     enters view without a massive blank gap */
  .stack-scroll-container {
    height: 120vh;
  }

  /* ── SP Hero: tighten top offset to match shorter hero text block ── */
  .sp-hero {
    top: var(--nav-height);
    left: 0;
    width: 100%;
    padding: 2rem 1.25rem 64px;
  }

  /* ── Section header row (Recent Work + Stack/Grid/Flow) ──
     Prevent the toggle buttons from overflowing or touching edges */
  .sp-section-header {
    padding: 0 1.25rem;
    gap: 0.75rem;
    flex-wrap: wrap;
  }

  .sp-view-toggle {
    gap: 0.25rem;
    flex-shrink: 0;
  }

  .sp-toggle-btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
  }

  /* ── Cards: tighter vertical positioning ── */
  /* JS sets inline top via layoutCards(); these just guard against
     the CSS media-query fallback being too far down */
  .sp-cards-inner {
    top: 360px; /* fallback; JS overrides at runtime */
  }

  /* ── sp-info: respect side padding ── */
  .sp-info {
    left: 1.25rem;
    right: 1.25rem;
    width: auto; /* let it fill the padded width */
    top: 616px;  /* fallback; JS overrides at runtime */
  }

  /* ── Card front/back sizes already set in inline styles,
     but clamp the card to never overflow viewport width ── */
  .sp-card-front,
  .sp-card-mid,
  .sp-card-back {
    max-width: 100%;
  }

  /* ── Nav arrows: keep them visually inside the viewport ── */
  .sp-nav-prev-wrap {
    left: 4px;
  }

  .sp-nav-next-wrap {
    right: 4px;
  }

  /* ── SP Pills: allow wrapping on small screens ── */
  .sp-pills {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  /* ── Grid view: 2 columns down to 1 on very small screens ──
     The inline CSS already does 2 cols at ≤600px; override below */
  .sp-grid-view {
    padding: 0 1.25rem;
    gap: 0.875rem;
  }

  /* ── SP Detail (expanded inline detail): breathing room ── */
  .spd-section,
  .spd-header {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }

  .spd-meta-grid {
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
  }

  .spd-impact-grid {
    grid-template-columns: 1fr;
    gap: 1px;
  }

  /* ── Expanded Panel (pe-panel) ── */
  .pe-top-bar {
    padding: 0.875rem 1.25rem;
  }

  .pe-body {
    padding: 1.5rem 1.25rem;
  }

  /* ── Experiments section: add side padding on mobile ── */
  .exp-section {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
  }
}

/* ── Very small phones (≤ 390px) ── */
@media (max-width: 390px) {
  .stack-scroll-container {
    height: 110vh;
  }

  .sp-hero {
    top: var(--nav-height);
    padding-top: 1.5rem;
  }

  .sp-cards-inner {
    top: 330px;
  }

  .sp-info {
    top: 590px;
  }

  /* Single-column grid on tiny phones */
  .sp-grid-view {
    grid-template-columns: 1fr !important;
  }

  /* Tighten toggle text */
  .sp-toggle-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }

  /* Stack section label + toggle: stack vertically if needed */
  .sp-section-header {
    gap: 0.5rem;
  }
}

/* ── Landscape phones ── */
@media (max-width: 896px) and (max-height: 430px) and (orientation: landscape) {
  .stack-scroll-container { height: auto; }
  #spPage { position: relative; }
  .sp-hero {
    position: relative;
    top: auto;
    left: auto;
    width: 100%;
    padding: calc(var(--nav-height) + 0.75rem) 1.25rem 0.75rem;
  }
  .hero-label { font-size: 1rem; margin-bottom: 0.25rem; }
  .hero-title { font-size: 1.1rem; line-height: 1.4; }
  .sp-section-bar {
    position: relative;
    top: auto;
    left: auto;
    width: auto;
    padding: 0.5rem 1.25rem;
  }
  .sp-cards-container {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    width: calc(100% - 2.5rem);
    margin: 0 auto;
  }
  .sp-cards-inner {
    position: relative;
    top: auto !important;
  }
  .sp-info {
    position: relative;
    top: auto !important;
    left: auto;
    width: 100%;
    padding: 1rem 1.25rem;
    margin-top: 1rem;
  }
  .sp-card-front { height: 160px; }
  .sp-card-back { height: 55%; }
  .sp-card-mid { height: 62%; }
}

/* ── Tablet portrait (iPad Mini / Air / Pro) ── */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
  /* Stack scroll container — give it enough sticky zone */
  .stack-scroll-container { height: 150vh; }

  /* Hero text — use full available width with comfortable padding */
  .sp-hero {
    left: 2rem;
    width: calc(100% - 4rem);
    top: var(--nav-height);
    padding: 2.5rem 2rem 2rem;
  }

  /* Cards container — center with tablet-appropriate width */
  .sp-cards-container {
    width: min(680px, calc(100% - 4rem));
  }

  /* Front card — taller than mobile, shorter than desktop */
  .sp-card-front { height: 340px; }
  .sp-page.is-expanded .sp-card-front { height: 460px; }

  /* Back and mid cards scale with front */
  .sp-card-back { height: 62%; top: -40px; }
  .sp-card-mid  { height: 67%; top: -20px; }

  /* Nav arrows — show them on tablet (hide was mobile-only) */
  .sp-nav-prev-wrap,
  .sp-nav-next-wrap { display: flex; }

  /* Info block — align with card container left edge */
  .sp-info {
    left: max(2rem, calc(50% - 340px));
    width: min(680px, calc(100% - 4rem));
  }

  /* Expanded info position */
  .sp-page.is-expanded .sp-info {
    top: calc(var(--nav-height) + 16px + 460px + 40px);
  }

  /* Grid view — 2 columns on tablet portrait */
  .sp-grid-view {
    width: min(680px, calc(100% - 4rem));
    grid-template-columns: repeat(2, 1fr);
  }

  /* Section padding — more breathing room than mobile */
  .section { padding: 3.5rem 2rem; }

  /* About grid — restore two columns */
  .section--about .about-grid {
    grid-template-columns: 160px 1fr;
    gap: 3rem;
  }

  /* Case study overrides */
  .cs-overview-grid { grid-template-columns: repeat(2, 1fr); }
  .cs-two-col { grid-template-columns: 1fr 1fr; gap: 2.5rem; }
  .cs-pillars { grid-template-columns: repeat(3, 1fr); }
  .cs-impact-grid { grid-template-columns: repeat(3, 1fr); }
}
