/*
 * Modal interaction adapted from https://uiverse.io/00Kubi/cowardly-eagle-56
 * Keycap interaction adapted from https://uiverse.io/Cksunandh/stale-dog-84
 * MIT License
 * Copyright (c) 2026 kennyotsu (kotsu), 00Kubi (Kubi), Cksunandh (Sunandh ck)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

/* Grazing light catches the two edges nearest the pointer. The small bright
   marks carry through the coloured acrylic, metal and paper case housings. */
dialog[open] {
  --pitch: 0deg;
  --yaw: 0deg;
  --edge-light: color-mix(in srgb, var(--accent) 68%, ivory);
}
dialog[open]::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  border-radius: inherit;
  opacity: 0;
  background:
    linear-gradient(var(--edge-light) 0 0) left 9px top 5px / 24px 1px,
    linear-gradient(var(--edge-light) 0 0) left 5px top 9px / 1px 13px,
    linear-gradient(var(--edge-light) 0 0) right 9px top 5px / 24px 1px,
    linear-gradient(var(--edge-light) 0 0) right 5px top 9px / 1px 13px,
    linear-gradient(var(--edge-light) 0 0) left 9px bottom 5px / 24px 1px,
    linear-gradient(var(--edge-light) 0 0) left 5px bottom 9px / 1px 13px,
    linear-gradient(var(--edge-light) 0 0) right 9px bottom 5px / 24px 1px,
    linear-gradient(var(--edge-light) 0 0) right 5px bottom 9px / 1px 13px,
    radial-gradient(ellipse 48% 83% at var(--mx) var(--my),
      color-mix(in srgb, var(--accent) 10%, transparent),transparent 74%);
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--accent) 56%,transparent),
              inset 0 0 22px -12px var(--accent);
  transition: opacity .18s ease;
}
dialog[open][data-lit]::after {opacity:1}
@media (hover:hover) and (prefers-reduced-motion:no-preference) {
  dialog[open] {
    transform-origin: center;
    transform: scale(var(--sheet-fit,1)) perspective(max(1700px,250vmax)) rotateX(var(--pitch)) rotateY(var(--yaw));
    transition: transform .2s cubic-bezier(.2,.65,.35,1);
  }
  dialog[open][data-lit] {transition-duration: 110ms}
  dialog[open][data-aiming] {transform:var(--held-pose);transition:none}
  dialog[open][data-lit]::before {
    content:"";
    position:absolute;
    inset:5% 4% 15%;
    z-index:7;
    pointer-events:none;
    background:
      radial-gradient(circle,var(--edge-light) 0 1px,transparent 2px) 2% 28% / 5px 5px,
      radial-gradient(circle,var(--edge-light) 0 1px,transparent 2px) 95% 48% / 5px 5px,
      radial-gradient(circle,var(--edge-light) 0 1px,transparent 2px) 91% 72% / 4px 4px,
      linear-gradient(90deg,transparent,var(--edge-light),transparent) 6% 81% / 7% 1px,
      linear-gradient(90deg,transparent,var(--edge-light),transparent) 92% 13% / 10% 1px;
    background-repeat:no-repeat;
    animation:sheet-glints 2.8s ease-in-out infinite;
  }
}
@keyframes sheet-glints {
  from {opacity:0;transform:translateY(7px)}
  45% {opacity:.65}
  to {opacity:0;transform:translateY(-8px)}
}

/* A shallow moulded key. The cap and its bevel travel down together. A
   separate CSS translate also works on pins positioned by the 3D camera. */
:root {
  --key-shell: #29343d;
  --key-face: #f0efe7;
  --key-ink: #29312e;
  --key-shadow: #080f15;
  --key-gloss: #ffffff32;
  --key-well: #00000038;
}
:is(header button,header .contact,.world-tools button,.drive-controls button,.dock .pill,
    .map-label,dialog button,dialog .actions a,#external) {
  --step: 3px;
  box-shadow:
    inset 0 1px var(--key-gloss),inset 1px 0 #ffffff0e,inset -1px -1px var(--key-well),
    0 var(--step) 0 var(--key-shadow),0 calc(var(--step) + 2px) 5px #02080b46;
  transition: translate 115ms ease-out,box-shadow 115ms ease-out,background-color 115ms ease-out;
}
.world-tools {
  gap: 4px;
  padding: 3px 4px 6px;
  overflow: visible;
}
.world-tools button,.world-tools button:first-child {
  color: var(--key-ink);
  border: 1px solid #acaea7;
  border-radius: 7px;
  background: linear-gradient(150deg,#f9f8f2 0%,#e9e9e2 64%,#d9dbd4);
  --key-gloss: #ffffffdf;
  --key-shadow: #89908b;
  --key-well: #99a09788;
}
.world-tools button:hover {background: linear-gradient(155deg,#fffefa,#e7eadf)}
.world-tools button[aria-pressed=true] {color:#173d32;background:#c7e9d9;--key-shadow:#6d9686}
header .plain:not(.identity) {border-radius:6px;padding:4px 10px;background:var(--key-shell)}
header .identity {--step:1px;box-shadow:none}
.transport button,.cross {border-radius:7px}
.transport button {margin:2px 2px 5px}
.pill {--key-shadow:color-mix(in srgb,var(--accent,var(--acid)) 50%,#16272a)}
.map-label,#filmstrip button {--step:2px}
#screen-button {--step:1px;box-shadow:none}
dialog .actions a,#external {border-radius:6px;padding:5px 8px;text-decoration:none}
/* The dossier has its own paper, ink and metal palette. Keep those face
   colours on project keys and use the shared travel and compression. */
:is(header button,header .contact,.world-tools button,.drive-controls button,.dock .pill,
    .map-label,dialog button,dialog .actions a,#external):not(:disabled):active,
dialog[open]:is(#project-sheet,#demo,#index-sheet,#profile-sheet) button:not(:disabled):active,
#boost[aria-pressed=true] {
  translate: 0 var(--step,3px);
  box-shadow: inset 0 2px 4px #13202757,inset 0 -1px #ffffff39,0 1px 1px #0000003d;
  transition-duration: 0s;
}
@media(max-width:640px) {
  header .plain:not(.identity) {padding-inline:5px}
  .world-tools {gap:3px;padding:2px 3px 5px}
}
@media(max-width:420px) {
  #world .world-tools {top:74px}
}
@media(prefers-reduced-motion:reduce) {
  :is(header button,header .contact,.world-tools button,.drive-controls button,.dock .pill,
      .map-label,dialog button,dialog .actions a,#external) {transition:none;translate:none!important}
}
@media(forced-colors:active) {
  dialog[open]::after {display:none}
  .world-tools button {border:1px solid ButtonText}
}
