/* ============================================
   DESKTOP.CSS — Desktop layout, icons, wallpaper
   ============================================ */

/* Design tokens — single source of truth for the brand palette.
   --accent-on-light exists because #3DF2E5 fails WCAG contrast as text
   on light surfaces; use it for teal text on white/#F5F5F0. */
:root {
  --accent: #3DF2E5;
  --accent-on-light: #0E8C82;
  --ink: #1A1A1A;
  --chrome: #2A2A2A;
  --surface: #F5F5F0;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Desktop Grid Layout */
#desktop {
  display: grid;
  /* Taskbar row grows by the iOS home-indicator inset so the CTA stays visible */
  grid-template-rows: 28px 1fr calc(44px + env(safe-area-inset-bottom, 0px));
  height: 100vh;
  height: 100dvh; /* iOS Safari: track the visible viewport, not the layout viewport */
  width: 100vw;
  background-color: #E8E0D0;
  background-image:
    radial-gradient(circle at 20% 80%, rgba(61, 242, 229, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(61, 242, 229, 0.05) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0.02) 0%, transparent 80%);
  position: relative;
}

/* Desktop Icons Area — CSS Grid for free placement */
#desktop-icons {
  grid-row: 2;
  position: relative;
  padding: 12px 16px;
  display: grid;
  /* minmax lets columns/rows compress on 769–880px viewports (iPad portrait)
     instead of clipping the right-hand icons off-screen */
  grid-template-columns: repeat(10, minmax(0, 84px));
  grid-template-rows: repeat(8, minmax(0, 72px));
  gap: 0;
  pointer-events: none;
  z-index: 1;
}

/* Individual Desktop Icon */
.desktop-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-self: center;
  width: 76px;
  padding: 6px 4px;
  border-radius: 6px;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: auto;
  touch-action: none; /* desktop layout: icon drag must own the gesture (iPad) */
  transition: background-color 0.1s ease, transform 0.25s ease, grid-row 0.25s ease, grid-column 0.25s ease;
}

.desktop-icon.dragging {
  z-index: 100;
  opacity: 0.85;
  transform: scale(1.08);
  transition: none;
}

.desktop-icon:hover {
  background-color: rgba(61, 242, 229, 0.1);
}

.desktop-icon.selected {
  background-color: rgba(61, 242, 229, 0.2);
  outline: 1px solid rgba(61, 242, 229, 0.4);
}

.desktop-icon__image {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
  font-size: 26px;
  line-height: 1;
}

.desktop-icon__image svg {
  width: 100%;
  height: 100%;
}

.desktop-icon__label {
  font-family: 'Space Mono', monospace;
  font-size: 10.5px;
  color: var(--ink);
  text-align: center;
  line-height: 1.3;
  word-break: break-word;
  max-width: 84px;
  text-shadow: 0 1px 2px rgba(232, 224, 208, 0.8);
}

/* Windows Container */
#windows-container {
  position: absolute;
  top: 28px;
  left: 0;
  right: 0;
  bottom: calc(44px + env(safe-area-inset-bottom, 0px));
  z-index: 2;
  pointer-events: none;
}

#windows-container > * {
  pointer-events: auto;
}

/* Selection prevention during drag */
body.dragging {
  user-select: none;
  -webkit-user-select: none;
  cursor: grabbing !important;
}

body.resizing {
  user-select: none;
  -webkit-user-select: none;
}

/* ============================================
   DESKTOP WIDGETS — Clock, Sticky Note
   ============================================ */

.desktop-widget {
  pointer-events: none;
  position: absolute;
  z-index: 0;
}

.desktop-widget--clock {
  bottom: 60px;
  right: 24px;
  text-align: right;
}

.desktop-widget__time {
  font-family: 'Archivo Black', sans-serif;
  font-size: 48px;
  color: rgba(26, 26, 26, 0.08);
  line-height: 1;
}

.desktop-widget__date {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: rgba(26, 26, 26, 0.06);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.desktop-widget--sticky {
  bottom: 160px;
  right: 20px;
  pointer-events: auto;
  background: #FFF9C4;
  padding: 14px 16px;
  border-radius: 2px;
  width: 180px;
  box-shadow: 2px 3px 8px rgba(0,0,0,0.1);
  transform: rotate(1.5deg);
  z-index: 0;
}

.desktop-widget__sticky-title {
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  color: #B8860B;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.desktop-widget__sticky-text {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: #5D4037;
  line-height: 1.5;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  #desktop {
    grid-template-rows: 28px 1fr calc(52px + env(safe-area-inset-bottom, 0px));
  }

  #desktop-icons {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: center;
  }

  .desktop-icon {
    width: 76px;
    padding: 8px 4px;
    grid-row: unset !important;
    grid-column: unset !important;
    touch-action: auto; /* mobile: icon list scrolls, drag is disabled */
  }

  .desktop-icon__image {
    width: 36px;
    height: 36px;
    font-size: 28px;
  }

  .desktop-icon__label {
    font-size: 10px;
  }

  #windows-container {
    bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  }

  .desktop-widget--clock,
  .desktop-widget--sticky {
    display: none;
  }
}
