/* ===== MOBILE RESPONSIVE STYLES ===== */
/* Comprehensive mobile-first responsive design for the portfolio */

/* ===== MOBILE BREAKPOINTS ===== */
/* - 640px: Mobile phones (portrait) */
/* - 768px: Tablets and large phones (landscape) */
/* - 1024px: Small laptops and tablets */

/* ===== ROOT MOBILE TOKENS ===== */
@media (max-width: 768px) {
  :root {
    --mobile-safe-area-top: env(safe-area-inset-top, 0px);
    --mobile-safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --mobile-header-height: 72px;
    --mobile-footer-height: 88px;
    --mobile-gutter: 20px;
    --mobile-card-scale: 0.85;
  }
}

/* ===== MOBILE SHELL ===== */
@media (max-width: 640px) {
  /* Show full desktop shell on mobile instead of placeholder */
  .desktop .site-shell {
    display: block !important;
  }

  .mobile {
    display: none !important;
  }

  .mobile-placeholder {
    display: none !important;
  }

  /* Full-width shell */
  body.page-home .site-shell {
    max-width: 100%;
    padding-top: 0;
    min-height: 100vh;
    min-height: 100dvh;
  }

  /* Site background */
  .site-bg::before {
    background: var(--white-100);
  }
  
  /* Ensure body doesn't scroll during intro */
  body:not(.intro-animation-complete) {
    overflow: hidden;
  }
}

/* ===== MOBILE HEADER ===== */
@media (max-width: 640px) {
  .site-topbar,
  .header-switch {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: var(--mobile-header-height, 72px);
    padding: 0 var(--mobile-gutter, 20px);
    padding-top: var(--mobile-safe-area-top, 0px);
    background: var(--white-100);
    border-bottom: none;
    z-index: 100;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .site-topbar::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: var(--mobile-gutter, 20px);
    right: var(--mobile-gutter, 20px);
    height: 1px;
    background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(188, 184, 174, 0.3) 20%,
      rgba(188, 184, 174, 0.3) 80%,
      transparent 100%
    );
  }

  .site-topbar .topbar-logo {
    width: 44px;
    height: 44px;
    border-radius: 14px;
  }

  .site-topbar .topbar-cta {
    height: 44px;
    padding: 10px 16px;
    border-radius: 14px;
    gap: 8px;
  }

  .site-topbar .topbar-cta .text-sm {
    font-size: 1rem;
    font-weight: 500;
  }

  .site-topbar .talk-icon {
    width: 18px;
    height: 10px;
  }
}

/* ===== MOBILE INTRO CONTAINER ===== */
@media (max-width: 640px) {
  .intro-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: var(--white-100);
    perspective: 600px !important;
    perspective-origin: center center;
  }

  .intro-container .scene {
    transform: scale(0.65) !important;
    transform-origin: center center;
  }

  .intro-animation-complete .intro-container {
    background-color: transparent;
    pointer-events: none;
  }

  /* Carousel center star on mobile */
  .carousel-center-star {
    top: 50%;
  }

  .carousel-center-star img {
    width: 28px;
    height: 28px;
  }

  /* Loader */
  .loader-container {
    bottom: calc(var(--mobile-footer-height, 88px) + 20px);
  }

  .loader-counter {
    font-size: 1.125rem;
  }

  /* Card sizing for mobile carousel */
  .intro-container .card {
    border-width: 5px;
    box-shadow: 
      rgba(0, 0, 0, 0.04) 0px 3px 12px 0px,
      rgba(0, 0, 0, 0.06) 0px 0px 0px 1px;
  }
}

/* ===== MOBILE WORK GRID ===== */
@media (max-width: 640px) {
  :root {
    --work-card-width: clamp(140px, 38vw, 180px);
    --work-card-height: calc(var(--work-card-width) * 3 / 5);
    --work-gap: clamp(16px, 4vw, 24px);
  }

  .work-grid {
    grid-template-columns: repeat(2, minmax(0, var(--work-card-width)));
    justify-content: center;
    align-content: center;
    justify-items: center;
    align-items: start;
    column-gap: var(--work-gap);
    row-gap: clamp(20px, 5vw, 32px);
    padding: calc(var(--mobile-header-height, 72px) + 24px) var(--mobile-gutter, 20px) calc(var(--mobile-footer-height, 88px) + 140px);
    pointer-events: auto;
  }

  .work-group {
    gap: 14px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .work-group:active {
    transform: scale(0.97);
  }

  .work-cards {
    width: var(--work-card-width);
    height: var(--work-card-height);
    will-change: transform;
  }

  .work-grid .card {
    border-width: 6px;
    box-shadow: 
      rgba(0, 0, 0, 0.04) 0px 4px 16px 0px,
      rgba(0, 0, 0, 0.06) 0px 0px 0px 1px;
  }

  .work-grid .case-trigger {
    font-size: clamp(0.875rem, 3.5vw, 1rem);
    line-height: 1.3;
    max-width: calc(var(--work-card-width) + 20px);
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  /* Video glow on mobile - simplified */
  .work-grid .work-video-glow {
    width: clamp(240px, 60vw, 400px);
    height: clamp(180px, 45vw, 300px);
    filter: blur(24px);
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }

  .work-grid .work-group.is-active .work-video-glow {
    opacity: 0.7;
    filter: blur(32px);
    transform: translate(-50%, -50%) scale(1.1);
  }

  /* Touch-friendly interactions */
  .work-group.is-active {
    opacity: 1;
  }

  .work-grid.is-hovering .work-group:not(.is-active) {
    opacity: 0.5;
  }
}

/* ===== MOBILE PLAYGROUND ===== */
@media (max-width: 640px) {
  .playground-container {
    inset: 0;
    padding-bottom: calc(var(--mobile-footer-height, 88px) + 100px);
  }

  .playground-container .card--playground {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .playground-container .card--playground:active {
    transform: scale(0.98) !important;
  }

  /* Hide tuning panel on mobile */
  .playground-tuning,
  .playground-tuning__toggle {
    display: none !important;
  }
}

/* ===== MOBILE ABOUT VIEW ===== */
@media (max-width: 640px) {
  .about-view-content,
  .selected-work-view-content,
  .playground-view-content {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: calc(var(--mobile-header-height, 72px) + 32px) var(--mobile-gutter, 20px) calc(var(--mobile-footer-height, 88px) + 160px);
    align-content: start;
  }

  .about-view-side {
    max-width: 100%;
    text-align: center;
  }

  .about-view-side--left,
  .about-view-side--right {
    grid-column: 1;
    justify-self: center;
    text-align: center;
  }

  .about-view-title {
    font-size: clamp(1.5rem, 7vw, 2rem);
    line-height: 1.1;
    text-wrap: balance;
  }

  .about-view-description {
    font-size: clamp(0.9rem, 3.5vw, 1rem);
    line-height: 1.5;
    opacity: 0.8;
    text-wrap: balance;
  }

  .about-social-links {
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem 1.5rem;
    margin-top: 1.25rem;
  }

  .about-social-links .social-link {
    font-size: 0.9rem;
  }

  .playground-view-copy {
    max-width: 90%;
    padding: 0;
  }

  .playground-view-copy .about-view-title {
    margin-bottom: 12px;
  }
}

/* ===== MOBILE FOOTER / DOCK ===== */
@media (max-width: 640px) {
  .footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: calc(var(--mobile-footer-height, 88px) + var(--mobile-safe-area-bottom, 0px));
    padding: 0 var(--mobile-gutter, 20px);
    padding-bottom: var(--mobile-safe-area-bottom, 0px);
    gap: 0;
    background: var(--white-100);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: var(--mobile-gutter, 20px);
    right: var(--mobile-gutter, 20px);
    height: 1px;
    background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(188, 184, 174, 0.3) 20%,
      rgba(188, 184, 174, 0.3) 80%,
      transparent 100%
    );
  }

  .footer-left,
  .footer-right {
    display: none;
  }

  .footer-center {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  /* Mobile dock styling */
  .footer-btn--tabs {
    background-color: var(--white-100);
    border: 1px solid rgba(188, 184, 174, 0.25);
    border-radius: 24px;
    padding: 6px;
    gap: 4px;
    width: fit-content;
    height: auto;
    box-shadow: 
      0 2px 8px rgba(0, 0, 0, 0.04),
      0 0 0 1px rgba(188, 184, 174, 0.1);
  }

  .view-tab {
    width: 48px;
    height: 48px;
    border-radius: 18px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .view-tab img {
    width: 22px;
    height: 22px;
  }

  .view-tab .about-icon {
    width: 18px;
    height: 18px;
  }

  .view-tab:hover:not(.active) {
    background-color: rgba(188, 184, 174, 0.2);
  }

  .view-tab.active {
    background-color: var(--black-100);
    transform: scale(1.05);
  }

  .view-tab.active img {
    filter: brightness(0) invert(1);
  }
}

/* ===== MOBILE CASE MODAL ===== */
@media (max-width: 640px) {
  .case-modal {
    padding: 0;
  }

  .case-modal__dialog {
    position: fixed;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
    height: 100dvh !important;
    border-radius: 0;
    border: none;
  }

  .case-modal__sidebar {
    position: fixed;
    right: 0;
    top: 0;
    left: auto;
    width: auto;
    height: auto;
    background: transparent;
    border: none;
    border-left: none;
    padding: 16px;
    padding-top: max(16px, var(--mobile-safe-area-top, 0px));
    z-index: 10;
    overflow: visible;
  }

  .case-modal__back {
    width: 44px;
    height: 44px;
    background: var(--white-100);
    border: 1px solid rgba(188, 184, 174, 0.3);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .case-modal__back svg {
    width: 18px;
    height: 18px;
  }

  .case-modal__header,
  .case-modal__nav,
  .case-modal__cta {
    display: none;
  }

  .case-modal__slides-container {
    margin-left: 0;
    margin-right: 0;
    padding-top: max(72px, calc(var(--mobile-safe-area-top, 0px) + 56px));
    padding-bottom: calc(var(--mobile-footer-height, 88px) + var(--mobile-safe-area-bottom, 0px) + 16px);
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--black-100);
  }

  .case-modal__slides {
    padding: 16px;
    padding-top: 24px;
    gap: 16px;
  }

  .case-modal__slide {
    width: 100%;
    aspect-ratio: 9 / 16;
    max-height: 70vh;
    margin-bottom: 16px;
  }

  .case-modal__slide-media {
    border-radius: 12px;
    border-width: 0.5px;
  }

  .case-modal__slide video {
    border-radius: 12px;
    border-width: 0.5px;
  }

  /* Hide thumbnails on mobile */
  .case-modal__thumbnails {
    display: none;
  }

  /* Mobile indicator (dots at bottom) */
  .case-modal__indicator {
    display: none;
  }
}

/* ===== MOBILE CASE LIST (legacy) ===== */
@media (max-width: 640px) {
  .main-content {
    grid-template-columns: 1fr;
    min-height: 100vh;
    min-height: 100dvh;
    padding: calc(var(--mobile-header-height, 72px) + 24px) var(--mobile-gutter, 20px) calc(var(--mobile-footer-height, 88px) + 100px) !important;
    gap: 0;
  }

  .col-list {
    padding: 0;
  }

  .kicker {
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    margin-bottom: 20px;
  }

  .case-trigger {
    font-size: 1.5rem;
    line-height: 1.25;
    margin-bottom: 24px;
  }

  .case-list > div:first-child {
    display: none;
  }
}

/* ===== TABLET STYLES (641px - 1024px) ===== */
@media (min-width: 641px) and (max-width: 1024px) {
  .site-topbar {
    left: var(--page-gutter);
    right: var(--page-gutter);
    width: auto;
    height: 88px;
  }

  .footer {
    left: var(--page-gutter);
    right: var(--page-gutter);
    width: auto;
    height: 88px;
  }

  .site-topbar .topbar-logo {
    width: 42px;
    height: 42px;
  }

  .site-topbar .topbar-cta {
    height: 42px;
    padding: 9px 14px;
  }

  .site-topbar .topbar-cta .text-sm {
    font-size: 0.95rem;
  }

  .main-content {
    padding-top: 7rem !important;
    padding-left: 48px;
    padding-right: 48px;
  }

  .col-list {
    padding-right: 48px;
  }

  :root {
    --work-card-width: clamp(150px, 22vw, 210px);
    --work-gap: clamp(18px, 3vw, 28px);
  }

  .work-grid {
    grid-template-columns: repeat(2, minmax(0, var(--work-card-width)));
    row-gap: clamp(16px, 3vw, 28px);
    column-gap: var(--work-gap);
  }

  .intro-container .scene {
    transform: scale(0.75) !important;
  }
}

/* ===== LANDSCAPE MOBILE ===== */
@media (max-width: 896px) and (orientation: landscape) {
  :root {
    --work-card-width: clamp(130px, 22vw, 180px);
    --mobile-footer-height: 72px;
    --mobile-header-height: 56px;
  }

  .intro-container .scene {
    transform: scale(0.45) !important;
  }

  .work-grid {
    padding-top: calc(var(--mobile-header-height, 56px) + 16px);
    padding-bottom: calc(var(--mobile-footer-height, 72px) + 80px);
  }

  .footer {
    height: var(--mobile-footer-height, 72px);
  }

  .site-topbar {
    height: var(--mobile-header-height, 56px);
  }

  .about-view-content,
  .selected-work-view-content,
  .playground-view-content {
    padding-top: calc(var(--mobile-header-height, 56px) + 16px);
    padding-bottom: calc(var(--mobile-footer-height, 72px) + 60px);
  }
}

/* ===== DARK MODE MOBILE ===== */
@media (max-width: 640px) {
  body.dark .site-topbar {
    background: var(--color-bg);
  }

  body.dark .site-topbar::after {
    background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(46, 42, 26, 0.5) 20%,
      rgba(46, 42, 26, 0.5) 80%,
      transparent 100%
    );
  }

  body.dark .footer {
    background: var(--color-bg);
  }

  body.dark .footer::before {
    background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(46, 42, 26, 0.5) 20%,
      rgba(46, 42, 26, 0.5) 80%,
      transparent 100%
    );
  }

  body.dark .footer-btn--tabs {
    background-color: var(--color-dock-bg);
    border-color: var(--color-border);
  }

  body.dark .view-tab:hover:not(.active) {
    background-color: var(--color-dock-active);
  }

  body.dark .view-tab.active {
    background-color: var(--color-text-primary);
  }

  body.dark .case-modal__back {
    background: var(--color-card);
    border-color: var(--color-border);
    color: var(--color-text-primary);
  }
}

/* ===== ACCESSIBILITY: REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  .intro-container .scene {
    transform: none !important;
  }

  .work-group,
  .view-tab,
  .card {
    transition: none !important;
  }
}

/* ===== TOUCH DEVICE OPTIMIZATIONS ===== */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  .work-group {
    min-height: 120px;
  }

  .view-tab {
    min-width: 48px;
    min-height: 48px;
  }

  .site-topbar .topbar-logo,
  .site-topbar .topbar-cta {
    min-width: 44px;
    min-height: 44px;
  }

  /* Remove hover effects that don't work on touch */
  .work-grid.is-hovering .work-group:not(.is-active) {
    opacity: 1;
  }

  /* Active states instead */
  .work-group:active {
    transform: scale(0.97);
    opacity: 0.9;
  }

  .view-tab:active:not(.active) {
    background-color: rgba(188, 184, 174, 0.3);
    transform: scale(0.95);
  }
}

/* ===== SAFE AREA INSETS (iPhone X+) ===== */
@supports (padding: env(safe-area-inset-top)) {
  @media (max-width: 640px) {
    .site-topbar {
      padding-top: max(0px, env(safe-area-inset-top));
    }

    .footer {
      padding-bottom: max(0px, env(safe-area-inset-bottom));
    }

    .case-modal__slides-container {
      padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .case-modal__sidebar {
      padding-top: max(16px, env(safe-area-inset-top));
    }
  }
}

/* ===== MOBILE NAVIGATION DOTS (Case Modal) ===== */
@media (max-width: 640px) {
  .case-modal__mobile-dots {
    position: fixed;
    bottom: calc(var(--mobile-safe-area-bottom, 0px) + 24px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 10;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .case-modal__mobile-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    transition: all 0.25s ease;
  }

  .case-modal__mobile-dot.is-active {
    width: 20px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.9);
  }

  body.dark .case-modal__mobile-dots {
    background: rgba(0, 0, 0, 0.3);
  }

  body.dark .case-modal__mobile-dot {
    background: rgba(181, 170, 125, 0.4);
  }

  body.dark .case-modal__mobile-dot.is-active {
    background: rgba(181, 170, 125, 0.9);
  }
}

/* ===== MOBILE SWIPE HINT ===== */
@media (max-width: 640px) {
  .case-modal__swipe-hint {
    position: fixed;
    bottom: calc(var(--mobile-safe-area-bottom, 0px) + 80px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
    font-family: 'Figtree', sans-serif;
    letter-spacing: 0.05em;
    opacity: 1;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 5;
  }

  .case-modal__swipe-hint::before {
    content: '';
    width: 24px;
    height: 24px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.5)' stroke-width='1.5'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3Cpath d='M7 6l5 5 5-5'/%3E%3C/svg%3E");
    background-size: contain;
    animation: swipeHintBounce 1.5s ease-in-out infinite;
  }

  @keyframes swipeHintBounce {
    0%, 100% {
      transform: translateY(0);
    }
    50% {
      transform: translateY(4px);
    }
  }

  .case-modal__swipe-hint--hidden {
    opacity: 0;
  }

  body.dark .case-modal__swipe-hint {
    color: rgba(181, 170, 125, 0.5);
  }

  body.dark .case-modal__swipe-hint::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='rgba(181,170,125,0.5)' stroke-width='1.5'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3Cpath d='M7 6l5 5 5-5'/%3E%3C/svg%3E");
  }
}

/* ===== MOBILE PULL TO CLOSE (Case Modal) ===== */
@media (max-width: 640px) {
  .case-modal--pulling {
    transition: none !important;
  }

  .case-modal--pulling .case-modal__dialog {
    transition: transform 0.1s linear !important;
  }

  .case-modal--pull-threshold .case-modal__dialog {
    opacity: 0.8;
  }
}

/* ===== MOBILE WORK GRID ANIMATIONS ===== */
@media (max-width: 640px) {
  /* Staggered entrance for work groups */
  body.intro-animation-complete .work-group {
    animation: workGroupEntrance 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    animation-delay: calc(var(--work-index, 0) * 0.05s);
  }

  @keyframes workGroupEntrance {
    from {
      opacity: 0;
      transform: translateY(16px) scale(0.95);
    }
    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }

  /* Set work-index for stagger */
  .work-group:nth-child(1) { --work-index: 0; }
  .work-group:nth-child(2) { --work-index: 1; }
  .work-group:nth-child(3) { --work-index: 2; }
  .work-group:nth-child(4) { --work-index: 3; }
}

/* ===== MOBILE VIEW TRANSITIONS ===== */
@media (max-width: 640px) {
  /* Smooth view transitions on mobile */
  body.view-transitioning {
    pointer-events: none;
  }

  body.view-transitioning .work-grid,
  body.view-transitioning .about-view-content,
  body.view-transitioning .selected-work-view-content,
  body.view-transitioning .playground-view-content {
    transition: opacity 0.2s ease;
  }

  /* About view entrance animation on mobile */
  body.view-about .about-view-content {
    animation: aboutViewEntrance 0.3s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  @keyframes aboutViewEntrance {
    from {
      opacity: 0;
      transform: translateY(12px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* Mobile-specific view visibility */
  body.view-work .about-view-content {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  body.view-work .selected-work-view-content {
    opacity: 1 !important;
    visibility: visible !important;
  }

  body.view-work .work-grid {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  body.view-about .selected-work-view-content,
  body.view-about .work-grid {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  body.view-about .about-view-content {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

}

/* ===== MOBILE OVERSCROLL PREVENTION ===== */
@media (max-width: 640px) {
  html {
    overscroll-behavior: none;
  }

  body {
    overscroll-behavior-y: contain;
  }

  .case-modal__slides-container {
    overscroll-behavior-y: contain;
  }

  .work-grid {
    overscroll-behavior: contain;
  }
}

/* ===== MOBILE KEYBOARD HANDLING ===== */
@media (max-width: 640px) {
  /* Hide footer when keyboard is likely visible */
  body.keyboard-visible .footer {
    transform: translateY(100%);
    opacity: 0;
  }

  /* Adjust modal when keyboard is visible */
  body.keyboard-visible .case-modal__slides-container {
    padding-bottom: 16px;
  }
}
