/* ============================================================
   Responsive & Mobile CSS — Windows XP Portfolio
   Added at bottom of main stylesheet chain
   ============================================================ */

/* ── DESKTOP ICON GRID (column-first, XP-style) ── */
#desktop-icons {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
  padding: 10px 8px;
  height: calc(100vh - var(--taskbar-h));
  overflow: hidden;
  position: absolute;
  top: 0; left: 0; right: 0;
  bottom: var(--taskbar-h);
}

.desktop-icon {
  width: 76px;
  min-height: 82px;
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  padding: 6px 4px;
  border-radius: 2px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.1s;
}
.desktop-icon:hover  { background: rgba(255,255,255,0.15); }
.desktop-icon.selected { background: rgba(0,0,128,0.45); border: 1px dotted rgba(255,255,255,0.7); }

.di-emoji { font-size: 34px; line-height: 1; filter: drop-shadow(1px 2px 3px rgba(0,0,0,0.7)); pointer-events: none; }
.di-label { font-size: 11px; color: #fff; text-align: center; text-shadow: 1px 1px 3px rgba(0,0,0,1), 0 0 4px rgba(0,0,0,0.8); line-height: 1.25; word-break: break-word; max-width: 74px; pointer-events: none; }

/* ── WINDOW BASE ── */
.xt-window {
  position: absolute;
  min-width: 320px; min-height: 200px;
  display: flex; flex-direction: column;
  font-family: 'Tahoma', sans-serif; font-size: 11px;
  border: 3px solid #0831d9;
  border-radius: 8px 8px 4px 4px;
  overflow: hidden;
  box-shadow: 3px 3px 14px rgba(0,0,0,0.7), inset 0 0 0 1px rgba(100,160,255,0.25);
  animation: windowIn 0.12s ease-out forwards;
}

/* ── TASKBAR RESPONSIVE ── */
#taskbar {
  display: flex; align-items: center;
  height: var(--taskbar-h);
  overflow: hidden;
}

#taskbar-apps {
  display: flex; gap: 2px;
  flex: 1; overflow: hidden; padding: 0 2px;
}

.taskbar-app-btn {
  display: flex; align-items: center; gap: 4px;
  min-width: 30px; max-width: 160px;
  height: 28px; padding: 0 8px;
  background: linear-gradient(180deg, rgba(255,255,255,0.1) 0%, rgba(0,0,0,0.1) 100%);
  border: 1px solid;
  border-color: rgba(255,255,255,0.3) rgba(0,0,0,0.3) rgba(0,0,0,0.3) rgba(255,255,255,0.3);
  border-radius: 3px;
  color: #fff; font-family: 'Tahoma', sans-serif; font-size: 11px;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: all 60ms; flex-shrink: 1;
}
.taskbar-app-btn.active {
  background: linear-gradient(180deg, rgba(0,0,0,0.2) 0%, rgba(255,255,255,0.05) 100%);
  border-color: rgba(0,0,0,0.5) rgba(255,255,255,0.2) rgba(255,255,255,0.2) rgba(0,0,0,0.5);
  box-shadow: inset 1px 1px 3px rgba(0,0,0,0.3);
}
.taskbar-app-btn .app-icon { font-size: 14px; flex-shrink: 0; }
.taskbar-app-btn .app-title { overflow: hidden; text-overflow: ellipsis; }

/* ── SNAKE D-PAD BUTTONS ── */
.snake-d-btn {
  width: 44px; height: 44px;
  background: rgba(0,229,255,0.1);
  border: 1px solid rgba(0,229,255,0.3);
  border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #00E5FF;
  transition: all 0.08s; touch-action: manipulation;
}
.snake-d-btn:hover  { background: rgba(0,229,255,0.2); }
.snake-d-btn:active { background: rgba(0,229,255,0.35); transform: scale(0.92); }

/* ══════════════════════════════════════
   TABLET  (≤ 900px)
═══════════════════════════════════════ */
@media (max-width: 900px) {
  :root { --taskbar-h: 40px; }

  #desktop-icons {
    gap: 4px;
    padding: 6px;
  }
  .di-emoji { font-size: 28px; }
  .di-label  { font-size: 10px; }
  .desktop-icon { width: 68px; min-height: 74px; }

  .xt-window { min-width: 280px; }
  .taskbar-app-btn { max-width: 100px; font-size: 10px; padding: 0 6px; }
}

/* ══════════════════════════════════════
   MOBILE  (≤ 600px)
═══════════════════════════════════════ */
@media (max-width: 600px) {
  :root { --taskbar-h: 48px; }

    /* Desktop becomes a 4-column icon grid */
    #desktop-icons {
      display: grid !important;
      grid-template-columns: repeat(4, 1fr) !important;
      grid-template-rows: unset !important;
      grid-auto-flow: row !important;
      gap: 6px;
      height: auto;
      padding: 10px 6px;
      overflow-y: auto;
    }
  
    .desktop-icon { width: 100%; min-height: unset; }
    .di-emoji { font-size: 26px; }
    .di-label  { font-size: 9px; }

    /* Move gadgets to bottom, in a row, scaled down */
    #gadgets-sidebar {
      top: auto !important;
      bottom: calc(var(--taskbar-h) + 10px) !important;
      right: 10px !important;
      left: 10px !important;
      width: auto !important;
      flex-direction: row !important;
      justify-content: center !important;
      gap: 10px !important;
      transform: scale(0.8);
      transform-origin: bottom center;
    }
    .gadget-item { flex: 1; max-width: 150px; }

  /* Windows fill screen on mobile */
  .xt-window {
    position: fixed !important;
    top: 0 !important; left: 0 !important;
    width: 100% !important;
    height: calc(100% - var(--taskbar-h)) !important;
    border-radius: 0 !important;
    min-width: unset !important; min-height: unset !important;
    border-width: 2px !important;
  }

  .win-titlebar { cursor: default; height: 34px; }
  .win-titlebar-title { font-size: 11px; }
  .win-btn { width: 26px; height: 26px; }
  .win-resize-handle { display: none !important; }

  /* Taskbar tweaks */
  #start-button { padding: 0 6px 0 4px; height: 38px; font-size: 12px; }
  .start-logo { width: 16px; height: 16px; }
  .start-logo span { width: 6px; height: 6px; }
  #tray-live { display: none; }

  /* Taskbar app buttons: only icons on mobile */
  .taskbar-app-btn { max-width: 36px; min-width: 34px; padding: 0 4px; }
  .taskbar-app-btn .app-title { display: none; }
  .taskbar-app-btn .app-icon { font-size: 16px; }

  /* Start Menu fills screen on mobile */
  #start-menu {
    width: 100vw !important;
    bottom: var(--taskbar-h);
    border-radius: 12px 12px 0 0;
    max-height: calc(100vh - var(--taskbar-h) - 20px);
    display: flex;
    flex-direction: column;
  }
  .sm-header { padding: 10px; }
  .sm-header .sm-user-avatar { width: 40px; height: 40px; }
  .sm-header .sm-user-name { font-size: 16px; }
  
  .sm-body { height: auto !important; flex: 1; flex-direction: column !important; }
  .sm-left { width: 100% !important; padding: 10px; }
  .sm-right { width: 100% !important; display: flex; flex-direction: row; flex-wrap: wrap; padding: 10px; border-left: none; border-top: 1px solid rgba(255,255,255,0.1); }
  .sm-item { padding: 8px 10px !important; font-size: 13px !important; }
  .sm-right .sm-item { flex: 1 1 45%; }

  /* Quick launch: smaller */
  .ql-btn { width: 30px; height: 30px; font-size: 13px; }
  #quick-launch { gap: 0; }

  /* App content adjustments */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .gallery-grid { grid-template-columns: repeat(2, 1fr); }
  .ig-gallery { grid-template-columns: repeat(3, 1fr); gap: 2px; }
  .stream-schedule { grid-template-columns: 1fr; }
  .snake-d-btn { width: 50px; height: 50px; font-size: 20px; }
  #snake-canvas { max-width: 100%; }

  /* Login screen mobile */
  .login-center { flex-direction: column; gap: 20px; }
  .login-left { align-items: center; text-align: center; }
  .login-right { align-items: center; }

  /* Media Player mobile: stack vertically */
  #wmp-viz { display: none; }
}

/* ══════════════════════════════════════
   VERY SMALL (≤ 400px)
═══════════════════════════════════════ */
@media (max-width: 400px) {
  #desktop-icons { grid-template-columns: repeat(3, 1fr) !important; }
  .sm-right { display: none; }
  #start-menu { width: 100vw !important; }
}

/* ── Scrollbar improvements (all) ── */
* { scrollbar-width: thin; scrollbar-color: #cddbfa #f0f0f0; }

/* ── Win content inner scroll always works ── */
.win-content { overflow: auto !important; -webkit-overflow-scrolling: touch; }

/* ── Touch-friendly interactive elements ── */
@media (hover: none) {
  .sm-item:active { background: #316ac5 !important; color: #fff !important; }
  .desktop-icon:active { background: rgba(0,0,128,0.4); }
  .xt-btn:active { opacity: 0.8; }
  .win-btn-close:active, .win-btn-minimize:active, .win-btn-maximize:active { transform: scale(0.9); }
}

/* --------------------------------------
   SHORT HEIGHT (Landscape Mobile)
--------------------------------------- */
@media (max-height: 500px) {
  #gadgets-sidebar {
    display: flex !important;
    top: auto !important;
    bottom: calc(var(--taskbar-h) + 10px) !important;
    right: 10px !important;
    left: 10px !important;
    width: auto !important;
    flex-direction: row !important;
    justify-content: center !important;
    gap: 10px !important;
    transform: scale(0.7);
    transform-origin: bottom center;
  }
  .gadget-item { flex: 1; max-width: 150px; }
  #desktop-icons {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    height: auto !important;
  }
}
