/*
  desktop.css, the stage: root layers, wallpaper, icons, context menu,
                install animation, drag shield, snap preview
  ---------------------------------------------------------------------------
  Layer/stacking model (why these z-indexes):
    #os-desktop  z 0        wallpaper + icons
    #os-windows  z 1        app windows (own stacking context => can NEVER
                            cover the taskbar, however high a window's z gets)
    .os-drag-shield z 99999 transparent event-catcher during drag/resize
    #os-taskbar  z 100000   always above windows
    #os-overlay  z 100001   start menu, context menu, calendar (above all)
*/

#os-root {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* --- Desktop surface (wallpaper host) ------------------------------------- */
.os-desktop {
  position: absolute;
  inset: 0;
  z-index: 0;
  /* Default background before JS applies a wallpaper (avoids a white flash). */
  background: linear-gradient(180deg, var(--os-desktop-top), var(--os-desktop-bottom));
  /* Leave room so bottom-row icons aren't hidden behind the taskbar. */
  padding-bottom: var(--os-taskbar-h);
}

/* Window layer sits above the desktop but is its own stacking context. */
.os-windows {
  position: absolute;
  inset: 0 0 var(--os-taskbar-h) 0;
  z-index: 1;
  pointer-events: none; /* the layer itself is transparent to clicks... */
}
.os-windows > * {
  pointer-events: auto; /* ...but the windows inside it are interactive */
}

/* Overlay layer for menus/popovers. */
.os-overlay {
  position: absolute;
  inset: 0;
  z-index: 100001;
  pointer-events: none;
}
.os-overlay > * {
  pointer-events: auto;
}

/* --- Desktop icons -------------------------------------------------------- */
.os-icons {
  position: absolute;
  inset: 0;
  padding: 14px;
  /* Flow icons top-to-bottom in columns, like a real desktop. */
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
  pointer-events: none; /* clicks pass through gaps to the desktop */
}

.os-icon {
  pointer-events: auto;
  width: 88px;
  padding: 10px 6px 8px;
  border-radius: var(--os-radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  text-align: center;
  color: #fff;
  transition: background var(--os-dur-fast) var(--os-ease-out),
    transform var(--os-dur-fast) var(--os-ease-out);
}
.os-icon:hover { background: rgba(255, 255, 255, 0.08); }
.os-icon.is-selected { background: rgba(255, 122, 26, 0.18); }
.os-icon:active { transform: scale(0.96); }

.os-icon__art {
  position: relative;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
}
.os-icon__art img { width: 46px; height: 46px; border-radius: 12px; }

.os-icon__fallback {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 20px;
  color: var(--os-brand-contrast);
  background: linear-gradient(160deg, var(--os-orange-bright), var(--os-orange-deep));
}

.os-icon__label {
  font-size: 12px;
  line-height: 1.25;
  /* Dark scrim behind the text so labels stay legible on any wallpaper. */
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
  max-width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

/* Install animation: icon shimmers + a progress bar fills, then it settles. */
.os-icon.is-installing { animation: os-install-shimmer 1s linear infinite; }
.os-icon.is-installing .os-icon__label { color: var(--os-orange-bright); }
.os-icon.is-installed { animation: os-install-pop 380ms var(--os-ease-back); }

.os-icon__progress {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: -3px;
  height: 4px;
  border-radius: var(--os-radius-pill);
  background: rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
.os-icon__progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--os-orange), var(--os-orange-bright));
  transition: width 900ms var(--os-ease-out);
}

@keyframes os-install-shimmer {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
@keyframes os-install-pop {
  0% { transform: scale(0.8); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* --- Right-click context menu -------------------------------------------- */
.os-context {
  position: absolute;
  min-width: 190px;
  padding: 6px;
  border-radius: var(--os-radius);
  background: var(--os-glass-strong);
  -webkit-backdrop-filter: blur(var(--os-blur));
  backdrop-filter: blur(var(--os-blur));
  border: 1px solid var(--os-border);
  box-shadow: var(--os-shadow-menu);
  animation: os-pop-in 140ms var(--os-ease-out);
}
.os-context__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-radius: var(--os-radius-sm);
  font-size: 13px;
  color: var(--os-text);
}
.os-context__item:hover { background: var(--os-brand); color: var(--os-brand-contrast); }

/* --- Drag shield + snap preview ------------------------------------------ */
.os-drag-shield {
  position: fixed;
  inset: 0;
  z-index: 99999;
  /* Transparent, but present so pointermove keeps firing over iframes. */
  background: transparent;
}

.os-snap-preview {
  position: absolute;
  display: none;
  z-index: 99998;
  border-radius: var(--os-radius);
  background: rgba(255, 122, 26, 0.16);
  border: 2px solid var(--os-brand);
  pointer-events: none;
  transition: left 90ms var(--os-ease-out), top 90ms var(--os-ease-out),
    width 90ms var(--os-ease-out), height 90ms var(--os-ease-out);
}

/* Native-app load error card. */
.os-app-error {
  padding: 24px;
  color: var(--os-text);
  font-size: 14px;
  line-height: 1.5;
}
.os-app-error__detail {
  margin-top: 8px;
  font-size: 12px;
  color: var(--os-danger);
  word-break: break-word;
}

@keyframes os-pop-in {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- Mobile tweaks -------------------------------------------------------- */
@media (max-width: 640px) {
  .os-icons {
    /* Bigger touch targets, simple top-down flow. */
    gap: 10px;
    padding: 12px;
  }
  .os-icon { width: 76px; }
}
