/* ==========================================================================
   Responsive — Mobile Adaptation (<=768px)
   Win95 Desktop -> Touch Launcher
   Fullscreen windows, launcher grid, FAB avatar, static wallpaper,
   disabled drag-select, swipe-friendly layout.
   ========================================================================== */

@media (max-width: 768px) {
  /* --- Desktop: Launcher Grid --- */
  .desktop {
    padding-top: 12px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    height: 100vh;
  }

  .desktop-icons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    padding: 16px;
    justify-items: center;
    /* Override any absolute positioning from desktop drag */
    position: relative !important;
    z-index: var(--z-icons);
    height: auto;
    padding-bottom: 80px; /* Space above taskbar + avatar */
  }

  .desktop-icon {
    /* Reset any absolute positioning from drag */
    position: static !important;
    left: auto !important;
    top: auto !important;
    /* Larger touch targets */
    width: 72px;
    padding: 8px;
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
  }

  .desktop-icon-img,
  .desktop-icon .icon-folder,
  .desktop-icon .icon-computer,
  .desktop-icon .icon-globe,
  .desktop-icon .icon-mail,
  .desktop-icon .icon-media {
    width: 40px;
    height: 40px;
  }

  .desktop-icon-label {
    font-size: 7px;
    margin-top: 4px;
    word-break: break-word;
    text-align: center;
  }

  .desktop-icon:active {
    background: rgba(0, 0, 170, 0.3);
    border-radius: 8px;
  }

  /* --- Video Wallpaper -> Static background --- */
  .video-wallpaper {
    display: none !important;
  }

  .video-overlay {
    display: none !important;
  }

  /* Use pixelated island wallpaper on mobile too */
  .desktop {
    background-color: var(--win95-desktop-teal);
    background-image: url('https://diegocuevas.com/wp-content/uploads/2019/01/LeTahaa-26-of-27-510x382.jpg.webp');
    background-size: cover;
    background-position: center;
    image-rendering: pixelated;
    filter: contrast(1.2) saturate(1.3);
  }

  /* --- Windows: Fullscreen --- */
  .win95-window {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    width: 100vw !important;
    height: calc(100vh - var(--win95-taskbar-height)) !important;
    min-width: unset !important;
    min-height: unset !important;
    border-radius: 0;
    z-index: var(--z-windows);
  }

  .win95-window .win95-titlebar {
    /* Slightly taller for touch */
    height: 32px;
    padding: 0 8px;
  }

  .win95-window .win95-titlebar-btn {
    width: 28px;
    height: 24px;
    font-size: 14px;
  }

  /* Hide resize handles on mobile */
  .win95-resize-n,
  .win95-resize-s,
  .win95-resize-e,
  .win95-resize-w,
  .win95-resize-ne,
  .win95-resize-nw,
  .win95-resize-se,
  .win95-resize-sw {
    display: none !important;
  }

  /* Hide maximize button (already fullscreen) */
  .win95-titlebar-btn[data-action="maximize"] {
    display: none;
  }

  /* Hide minimize button on mobile — use swipe instead */
  .win95-titlebar-btn[data-action="minimize"] {
    display: none;
  }

  .win95-window-body {
    font-size: 14px;
    padding: 8px;
    /* Enable smooth scrolling in window content */
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
  }

  /* --- Taskbar: Mobile Adaptation --- */
  .taskbar {
    height: 44px;
    padding: 2px 8px;
  }

  .start-btn {
    padding: 4px 8px;
  }

  .start-btn-text,
  .start-btn > span:last-child {
    /* Hide text, keep icon on small screens */
    display: none;
  }

  .taskbar-windows {
    /* Smaller window buttons on mobile */
    gap: 2px;
  }

  .taskbar-window-btn {
    max-width: 80px;
    font-size: 10px;
    padding: 2px 4px;
  }

  .taskbar-clock {
    font-size: 12px;
    min-width: 50px;
    padding: 2px 4px;
  }

  /* --- Start Menu: Fullscreen on Mobile --- */
  #start-menu {
    position: fixed;
    left: 0;
    bottom: 44px; /* Above mobile taskbar */
    width: 100vw;
    max-height: 70vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .win95-menu-item {
    padding: 12px 24px 12px 36px; /* Larger touch targets */
    font-size: 14px;
  }

  /* --- Context Menu: Larger Touch Targets --- */
  #context-menu .win95-menu-item {
    padding: 12px 24px;
    font-size: 14px;
  }

  /* --- Drag Select: Disabled --- */
  .drag-select-rect {
    display: none !important;
  }

  /* --- Avatar: Floating Action Button --- */
  .avatar-widget {
    position: fixed;
    width: 56px;
    height: 56px;
    bottom: 60px; /* Above taskbar */
    right: 16px;
    border-radius: 50%;
    background: var(--win95-accent-cyan);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-windows);
    /* Floating action button style */
  }

  .avatar-widget.hidden {
    display: none !important;
  }

  /* --- Boot Screen: Mobile Adjustments --- */
  .boot-bios-text {
    font-size: 8px;
    padding: 0 16px;
  }

  .boot-logo-img {
    font-size: 24px;
  }

  .boot-progress-container {
    width: 200px;
  }

  .boot-click-prompt {
    font-size: 10px;
  }
}

/* Small phones */
@media (max-width: 480px) {
  .desktop-icons {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding: 12px;
  }

  .desktop-icon-label {
    font-size: 6px;
  }

  .taskbar-window-btn {
    max-width: 60px;
  }

  #start-menu {
    max-height: 80vh;
  }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  .desktop-icons {
    grid-template-columns: repeat(auto-fill, 72px);
    padding: 8px;
    gap: 8px;
  }

  .win95-window {
    height: calc(100vh - 36px) !important;
  }
}
