/* The crosshair studio as a window on a desktop. The wallpaper is Bliss, the
   Windows XP default; see NOTICE.md. */

/* The studio's own mono face, for the word a phone shows while it loads. The
   studio asks for the same file, so it is fetched once. */
@font-face {
  font-family: "Chivo Mono";
  font-style: normal;
  font-weight: 100 900;
  font-display: block;
  src: url("studio/fonts/chivo-mono-latin.woff2") format("woff2");
}

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

html,
body {
  height: 100%;
  margin: 0;
}

/* The colour of the wallpaper's sky stands in until the picture has loaded. */
body {
  overflow: hidden;
  background: linear-gradient(180deg, rgb(85 135 238), rgb(125 165 241) 60%) fixed;
}

.desktop {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.desktop::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("bliss.webp") center / cover no-repeat;
  opacity: 0;
  transition: opacity 400ms cubic-bezier(0.22, 1, 0.36, 1);
}

.desktop[data-wallpaper]::before,
html[data-cached] .desktop::before {
  opacity: 1;
}

/* A wallpaper the browser already has is simply there, as on the last visit. */
html[data-cached] .desktop::before {
  transition: none;
}

/* The window is moved with transform, so nothing around it is laid out again
   while it is dragged. JavaScript sets --x, --y, --w and --h in pixels. It is
   not shown until the studio inside it has loaded, and then it arrives. */
.window {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--w, 800px);
  height: var(--h, 600px);
  overflow: hidden;
  border-radius: 18px;
  background: oklch(0.2 0.01 120);
  box-shadow:
    0 2px 6px oklch(0 0 0 / 0.12),
    0 12px 32px -6px oklch(0 0 0 / 0.22),
    0 32px 72px -16px oklch(0 0 0 / 0.2);
  /* Placed with the individual translate property, so the appearing animation
     (a transform) turns about the window's own centre and not about where the
     window would be without it. */
  translate: var(--x, 0px) var(--y, 0px);
  visibility: hidden;
}

/* The legacy look is a square-cornered window. */
html[data-ui="legacy"] .window {
  border-radius: 0;
}

.window[data-ready] {
  visibility: visible;
  animation: window-appear 420ms cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

@keyframes window-appear {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(12px);
  }
}

.window[data-dragging],
.window[data-resizing] {
  box-shadow:
    0 4px 10px oklch(0 0 0 / 0.14),
    0 18px 44px -8px oklch(0 0 0 / 0.26),
    0 44px 90px -18px oklch(0 0 0 / 0.22);
}

.window[data-dragging] {
  will-change: translate;
}

.window-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

/* While a drag or a resize is under way the frame must not take the pointer
   back. */
.window[data-dragging] .window-frame,
.window[data-resizing] .window-frame {
  pointer-events: none;
}

/* Resize handles: a strip along each edge and a square at each corner, over the
   studio's outer padding. */
.grip {
  position: absolute;
  z-index: 1;
  touch-action: none;
}

.grip[data-edge="n"], .grip[data-edge="s"] { left: 14px; right: 14px; height: 6px; cursor: ns-resize; }
.grip[data-edge="e"], .grip[data-edge="w"] { top: 14px; bottom: 14px; width: 6px; cursor: ew-resize; }
.grip[data-edge="n"] { top: 0; }
.grip[data-edge="s"] { bottom: 0; }
.grip[data-edge="e"] { right: 0; }
.grip[data-edge="w"] { left: 0; }
.grip[data-edge="nw"], .grip[data-edge="ne"], .grip[data-edge="sw"], .grip[data-edge="se"] { width: 14px; height: 14px; }
.grip[data-edge="nw"] { top: 0; left: 0; cursor: nwse-resize; }
.grip[data-edge="se"] { bottom: 0; right: 0; cursor: nwse-resize; }
.grip[data-edge="ne"] { top: 0; right: 0; cursor: nesw-resize; }
.grip[data-edge="sw"] { bottom: 0; left: 0; cursor: nesw-resize; }

@media (prefers-reduced-motion: reduce) {
  .desktop::before {
    transition-duration: 1ms;
  }
  .window[data-ready] {
    animation-duration: 1ms;
  }
}

/* The word a phone shows while the studio loads. Hidden at the desktop, where
   the wallpaper is what waits. */
.loading {
  display: none;
}

/* On a phone the window is the screen: not moved, not resized, and no
   wallpaper. The page is the studio's own green from edge to edge, behind the
   status bar and the browser's bar too: the window is fixed to the whole
   screen and keeps its content out of the unsafe areas with padding, so the
   colour is what Safari sees at both edges. The top is the chassis' top colour
   and the rest its bottom one, so the studio's own gradient joins it without a
   seam. "Loading" stands in the middle until the studio is shown. */
@media (max-width: 699px) {
  html {
    background: #46503e;
    overflow: hidden;
    overscroll-behavior: none;
  }
  html[data-ui="legacy"] {
    background: #4c5844;
  }
  body {
    background: none;
  }
  .desktop {
    background: linear-gradient(180deg, #4c5844 0, #4c5844 env(safe-area-inset-top), #46503e env(safe-area-inset-top));
  }
  html[data-ui="legacy"] .desktop {
    background: #4c5844;
  }
  .desktop::before {
    display: none;
  }
  .window {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    border-radius: 0;
    background: none;
    box-shadow: none;
    translate: none;
    will-change: auto;
  }
  .window[data-ready] {
    animation-name: window-fade;
  }
  .grip {
    display: none;
  }
  .loading {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    margin: 0;
    color: #c4b550;
    font: 600 14px/1 "Chivo Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    letter-spacing: 0.04em;
    pointer-events: none;
    animation: loading-pulse 1.4s ease-in-out infinite;
    transition: opacity 200ms linear;
  }
  .desktop[data-ready] .loading {
    opacity: 0;
    animation: none;
  }
}

@media (max-width: 699px) and (prefers-reduced-motion: reduce) {
  .loading {
    animation: none;
  }
}

@keyframes window-fade {
  from {
    opacity: 0;
  }
}

@keyframes loading-pulse {
  50% {
    opacity: 0.45;
  }
}
