/*
 * Placed sticker objects and their editing panel on the desktop. Keeps each sticker hit box fixed (no
 * transform, rotation or scale) so only the artwork inside rotates, through the --rot variable; styles the
 * floating tools panel (.desktop-sticker-tools: move, rotate, motion and remove buttons); adds touch rules and
 * the phone placement of the starter souvenirs. It loads after the desktop themes and hyd-stickers.css so it
 * can take over their sticker rules.
 */

/* Stable sticker hit boxes; only the artwork rotates. Load after desktop themes. */
#world #home .desktop-sticker.illustrated-sticker {
  position: absolute;
  display: block;
  /*
   * !important (transform, rotate, scale): hyd-stickers.css lifts stickers on hover and drag with scale, and
   * other rules may rotate them. The hit box must not move or resize; only the artwork inside rotates.
   */
  transform: none !important;
  rotate: none !important;
  scale: 1 !important;
  padding: 3px;
  overflow: visible;
  touch-action: none;
  pointer-events: auto;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  animation: none;
  transition: none;
}

#world #home .desktop-sticker.illustrated-sticker .desktop-sticker-art {
  display: block;
  width: 100%;
  height: 100%;
  transform: rotate(var(--rot,0deg));
  transform-origin: center;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

#world #home .desktop-sticker.illustrated-sticker .desktop-sticker-art :is(img, svg) {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

#world #home .desktop-sticker.illustrated-sticker:is(.is-dragging, .is-rotating) {
  cursor: grabbing;
  filter: drop-shadow(2px 5px 3px #08031177);
}

#world #home .desktop-sticker.illustrated-sticker.is-selected {
  outline: 1px dashed #f3eafa;
  outline-offset: 3px;
  box-shadow: 0 0 0 1px #291c3988;
}

#world #home .desktop-sticker.illustrated-sticker:focus-visible {
  outline: 2px solid #f3eafa;
  outline-offset: 3px;
}

/* --- Editing panel --- */
#world #home .desktop-sticker-tools {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  width: 286px;
  max-width: calc(100% - 8px);
  padding: 8px;
  box-sizing: border-box;
  border: 1px solid var(--paper-edge,#867a90);
  border-radius: 4px;
  background: var(--paper-panel,#ddd6e2);
  color: var(--paper-text,#281d30);
  box-shadow:
    inset 0 1px #fff4,
    1px 3px 7px #170e2950;
  transform: none;
  rotate: none;
  scale: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#world #home .desktop-sticker-tools[hidden],
#world #home .desktop-sticker-tools [hidden] {
  display: none;
}

#world #home .desktop-sticker-tools button {
  position: static;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  min-width: 28px;
  width: auto;
  height: 28px;
  padding: 0 6px;
  margin: 0;
  border: 1px solid var(--paper-edge,#867a90);
  border-radius: 3px;
  background: var(--paper-panel,#ddd6e2);
  color: var(--paper-text,#281d30);
  font: calc(18 * var(--px))/1 var(--desktop-font,Tahoma,Arial,sans-serif);
  box-shadow:
    inset 1px 1px #fff8,
    inset -1px -1px #0002;
  transform: none;
  rotate: none;
  scale: 1;
  touch-action: none;
  pointer-events: auto;
  cursor: pointer;
}

#world #home .desktop-sticker-tools :is(button, .desktop-sticker-tools-header b) {
  font: calc(11 * var(--px))/1.2 var(--desktop-font,'Lucida Grande',Tahoma,sans-serif);
  text-shadow: none;
  letter-spacing: 0;
}

#world #home .desktop-sticker-tools-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#world #home .desktop-sticker-tools-header b {
  font-weight: 700;
  min-width: 0;
}

#world #home .desktop-sticker-tools-header #finish-sticker-edit {
  height: 23px;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  text-decoration: underline;
  text-underline-offset: 2px;
}

#world #home .desktop-sticker-move-hint {
  font: calc(10 * var(--px))/1.3 var(--desktop-font,'Lucida Grande',Tahoma,sans-serif);
  color: var(--paper-muted,#655b6d);
}

#world #home .desktop-sticker-tools-edit {
  display: flex;
  /* wrap: in bigger text the rotate buttons take a second line instead of running off a narrow phone. */
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

#world #home .desktop-sticker-tools-edit button {
  flex: 1 0 auto;
  padding-inline: 5px;
}

#world #home .desktop-sticker-tools .desktop-sticker-angle {
  min-width: 24px;
}

/* --- Motion buttons --- */
#world #home .sticker-motion-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
}

#world #home .sticker-motion-buttons button {
  width: 100%;
  border-radius: 0;
  margin-left: -1px;
}

#world #home .sticker-motion-buttons button:first-child {
  margin-left: 0;
  border-radius: 3px 0 0 3px;
}

#world #home .sticker-motion-buttons button:last-child {
  border-radius: 0 3px 3px 0;
}

#world #home .sticker-motion-buttons:has(button[hidden]) {
  grid-template-columns: 1fr;
}

#world #home .sticker-motion-buttons:has(button[hidden]) button:not([hidden]) {
  border-radius: 3px;
}

#world #home .sticker-motion-buttons button[aria-pressed='true'] {
  background: var(--desktop-selection,#507faa);
  color: #fff;
  box-shadow: inset 0 1px 3px #17324b66;
  border-color: #416789;
}

/* --- Footer, drag handles and button states --- */
#world #home .desktop-sticker-tools-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 2px;
}

#world #home .desktop-sticker-tools-footer .desktop-sticker-remove {
  margin-left: auto;
}

#world #home .desktop-sticker-tools [data-sticker-handle] {
  cursor: grab;
}

#world #home .desktop-sticker-tools:is(.is-moving, .is-rotating) [data-sticker-handle] {
  cursor: grabbing;
}

#world #home .desktop-sticker-tools button:active {
  box-shadow:
    inset 1px 1px #0003,
    inset -1px -1px #fff6;
}

#world #home .desktop-sticker-tools button:focus-visible {
  outline: 2px solid var(--paper-text,#281d30);
  outline-offset: 1px;
}

#world #home .desktop-sticker-angle {
  min-width: 31px;
  text-align: center;
  color: var(--paper-text,#281d30);
  font: calc(10 * var(--px))/1 var(--desktop-font,Tahoma,Arial,sans-serif);
  font-variant-numeric: tabular-nums;
}

#world #home #desk-stickers :is(#rotate-sticker-left, #rotate-sticker-right) {
  min-width: 30px;
  font-size: calc(16 * var(--px));
  padding: 3px 6px;
}

#world #home #desk-stickers #reset-sticker-rotation {
  margin-left: 2px;
}

#world #home .desktop-sticker-tools button.desktop-sticker-open {
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
  padding: 0 7px;
  font: calc(12 * var(--px))/1 var(--desktop-font,Tahoma,Arial,sans-serif);
  white-space: nowrap;
}

/*
 * Touch: 44px buttons. The panel scrolls vertically (pan-y) while stickers and drag handles capture touches
 * (touch-action: none).
 */
@media (pointer: coarse) {
  #world #home .desktop-sticker.illustrated-sticker {
    touch-action: none;
  }

  #world #home .desktop-sticker-tools {
    touch-action: pan-y;
  }

  #world #home .desktop-sticker-tools [data-sticker-handle] {
    touch-action: none;
  }

  #world #home .desktop-sticker-tools button,
  #world #home .desktop-sticker-tools-header #finish-sticker-edit {
    min-width: 44px;
    min-height: 44px;
    height: 44px;
  }

  #world #home .desktop-sticker-tools-edit {
    gap: 3px;
  }

  #world #home .desktop-sticker-tools-edit button {
    min-width: 44px;
    padding-inline: 3px;
  }

  #world #home .desktop-sticker-tools .desktop-sticker-angle {
    min-width: 22px;
  }

  #world #home .desktop-sticker-tools button.desktop-sticker-open {
    white-space: normal;
    text-align: center;
    max-width: calc(100% - 65px);
  }
}

/* Phone desktops give the starter souvenirs their own strip, below the title.
   The art still has free drag handles; the strip only reserves breathing room. */
@media (max-width: 620px) {
  /* A deliberately placed souvenir stays grabbable over the shortcut shelf.
    Application windows (100+) and their controls still remain in front. */
  #world #home .mobile-desktop .desktop-sticker.illustrated-sticker[data-user-placed='true'] {
    /*
     * !important: fixes the stacking order of placed souvenirs (10, selected 11) below the application windows,
     * whatever z-index other sticker rules set.
     */
    z-index: 10 !important;
  }

  #world #home .mobile-desktop .desktop-sticker.illustrated-sticker.is-selected {
    /* !important: same reason as above, one step higher for the selected souvenir. */
    z-index: 11 !important;
  }

  #world #home .portal-collage .web-desktop:has(.desktop-sticker[data-default-sticker='true']) {
    padding-top: var(--starter-content-top,496px);
  }

  #world #home .web-desktop:has(.desktop-sticker[data-default-sticker='true']) .desktop-icons {
    top: var(--starter-icons-top,251px);
  }

  #world
    #home
    .desktop-sticker.illustrated-sticker[data-default-sticker='true']:has(img[src*='hyd-']) {
    width: 76px;
    height: 76px;
  }
}
