/* Interstices — near-monochrome dark surface; a serif display (Playfair) over a
   grotesque UI (Geist). The whole design system lives in these tokens. */
:root {
  --bg: #0a0a0b;
  --bg-rgb: 10 10 11;
  --tile: #141417;
  --ink: rgba(255, 255, 255, 0.95);
  --muted: rgba(255, 255, 255, 0.56);
  --faint: rgba(255, 255, 255, 0.34);
  --line: rgba(255, 255, 255, 0.1);
  --glass: rgba(20, 20, 24, 0.72);
  --glass-hover: rgba(36, 36, 42, 0.82);
  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Instrument Serif", "Playfair Display", Georgia, serif;
  --marker: "Shantell Sans", "Comic Sans MS", var(--sans);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  /* naive onboarding layer */
  --crayon: #ff7a4d;
  --hand: #f1e4cf;
}
[data-theme="light"] {
  --bg: #f3f3f1;
  --bg-rgb: 243 243 241;
  --tile: #e4e4e0;
  --ink: rgba(18, 18, 20, 0.95);
  --muted: rgba(18, 18, 20, 0.56);
  --faint: rgba(18, 18, 20, 0.4);
  --line: rgba(0, 0, 0, 0.12);
  --glass: rgba(255, 255, 255, 0.72);
  --glass-hover: rgba(255, 255, 255, 0.92);
  --crayon: #e8542b;
  --hand: #3a3430;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.3s ease, color 0.3s ease;
}
::selection {
  background: rgba(255, 255, 255, 0.18);
  color: #0a0a0b;
}
:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: 8px;
}
a {
  color: inherit;
}

/* ── stage + wall ─────────────────────────────────────────── */
#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
  cursor: default;
}
#stage.grabbing {
  cursor: grabbing;
}
#wall {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  will-change: transform;
}
.tile {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0;
  border: 0;
  margin: 0;
  overflow: hidden;
  border-radius: 3px;
  background: var(--tile);
  transform-origin: center center;
  backface-visibility: hidden;
  will-change: transform, opacity;
  box-shadow: 0 12px 32px -20px rgba(0, 0, 0, 0.85);
}
.media {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

/* legibility wash behind the intro */
.wash {
  position: absolute;
  inset: 0;
  z-index: 14;
  pointer-events: none;
  background: radial-gradient(
    ellipse 86% 72% at 0% 100%,
    rgb(var(--bg-rgb) / 1) 0%,
    rgb(var(--bg-rgb) / 0.86) 24%,
    rgb(var(--bg-rgb) / 0.55) 46%,
    transparent 74%
  );
}

/* ── intro ────────────────────────────────────────────────── */
#intro {
  position: fixed;
  bottom: 28px;
  left: 28px;
  z-index: 35;
  max-width: 28rem;
  pointer-events: none;
}
.title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: -0.01em;
  font-size: clamp(3rem, 8.5vw, 6rem);
  line-height: 0.92;
}
#logo {
  display: block;
  max-width: 92vw;
  margin: 0 0 6px -12px;
}
.subtitle {
  margin: 12px 0 0;
  max-width: 24rem;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--muted);
}

/* ── scrim — the wall dims (stays visible) behind a focused photo ── */
#scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgb(var(--bg-rgb) / 0.64);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s var(--ease);
}
body.focused #scrim {
  opacity: 1;
  pointer-events: auto;
}
/* clear the chrome away while focused */
body.focused #intro,
body.focused #tools,
body.focused #theme,
body.focused #credits {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* ── preview / focused view (one element, two sizes) ───────────
   On hover it's a small card at the cursor; on focus it glides to centre and
   grows in place (height transitions, chrome fades in) — driven by frame(). */
#preview {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  pointer-events: none;
  opacity: 0;
  will-change: transform, opacity;
}
body.focused #preview {
  pointer-events: auto;
}
.preview-media {
  position: relative;
  height: clamp(168px, 36vh, 326px);
  /* aspect-ratio set inline per item → `contain` neither crops nor letterboxes */
  overflow: hidden;
  border-radius: 6px;
  background: var(--tile);
  box-shadow: 0 40px 80px -30px rgba(0, 0, 0, 0.95);
  transition: height 0.5s var(--ease), max-width 0.5s var(--ease),
    border-radius 0.4s var(--ease);
}
body.focused .preview-media {
  height: 58vh;
  max-width: min(86vw, 1100px);
  border-radius: 9px;
}
.preview-media .media {
  object-fit: contain;
}

/* hover caption (bottom-left, on the card) */
.preview-cap {
  position: absolute;
  left: 12px;
  bottom: 10px;
  z-index: 2;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
  transition: opacity 0.3s ease;
}
body.focused .preview-cap {
  opacity: 0;
}
.preview-cat {
  display: block;
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.75);
}
.preview-label {
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.15;
  color: #fff;
  max-width: 16rem;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* focus chrome — head above, foot below, positioned around the media so they
   never affect its size */
.pv-head,
.pv-foot {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease 0.06s;
}
.pv-head {
  bottom: 100%;
  margin-bottom: 18px;
}
.pv-foot {
  top: 100%;
  margin-top: 18px;
}
body.focused .pv-head,
body.focused .pv-foot {
  opacity: 1;
  pointer-events: auto;
}
.pv-headtext {
  text-align: center;
  max-width: min(70vw, 680px);
  overflow: hidden;
}
.pv-cat {
  display: block;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
}
.pv-title {
  display: block;
  font-family: var(--serif);
  font-size: clamp(1.5rem, 3.4vw, 2.3rem);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pv-meta {
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}
.pv-actions {
  display: inline-flex;
  gap: 8px;
}
.pv-nav,
.pv-btn {
  display: grid;
  place-items: center;
  border-radius: 9999px;
  border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s var(--ease), background-color 0.2s ease,
    color 0.2s ease;
}
.pv-nav {
  width: 40px;
  height: 40px;
}
.pv-btn {
  width: 34px;
  height: 34px;
  color: var(--muted);
}
.pv-nav:hover,
.pv-btn:hover {
  background: var(--glass-hover);
  color: var(--ink);
  transform: translateY(-1px);
}
.pv-nav:active,
.pv-btn:active {
  transform: scale(0.95);
}

/* ── glass controls (top-left) ────────────────────────────── */
#tools {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 60;
  display: flex;
  gap: 8px;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 11px;
  border-radius: 9999px;
  border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition:
    transform 0.15s var(--ease),
    background-color 0.2s ease;
}
.btn svg {
  width: 16px;
  height: 16px;
}
.btn:hover {
  background: var(--glass-hover);
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0) scale(0.98);
}
.btn.ghost {
  padding: 8px 13px;
  color: var(--muted);
  background: rgba(20, 20, 24, 0.55);
}
.btn.ghost:hover {
  color: var(--ink);
}
.btn[hidden] {
  display: none;
}

/* ── bottom-right credit + source ─────────────────────────── */
#credits {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11.5px;
  color: var(--faint);
  text-shadow: 0 1px 10px rgb(var(--bg-rgb) / 0.9);
}
#credits .credit a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
#credits .credit a:hover {
  color: var(--ink);
  border-color: var(--line);
}
.gh {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9999px;
  border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  color: var(--muted);
  transition:
    transform 0.15s var(--ease),
    color 0.2s ease,
    background-color 0.2s ease;
}
.gh:hover {
  color: var(--ink);
  background: var(--glass-hover);
  transform: translateY(-1px);
}

/* top-right theme toggle (reuses .gh) */
#theme {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 60;
}
#theme .ic-sun {
  display: none;
}
[data-theme="light"] #theme .ic-sun {
  display: block;
}
[data-theme="light"] #theme .ic-moon {
  display: none;
}

/* ── drag-drop overlay ────────────────────────────────────── */
#drop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 8, 10, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
#drop.show {
  opacity: 1;
}
.drop-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: clamp(40px, 8vw, 72px) clamp(48px, 12vw, 110px);
  border: 1.5px dashed rgba(255, 255, 255, 0.28);
  border-radius: 24px;
  background: rgba(20, 20, 24, 0.5);
  text-align: center;
  transform: scale(0.98);
  transition: transform 0.2s var(--ease), border-color 0.2s ease;
}
#drop.show .drop-card {
  transform: scale(1);
}
#drop.over .drop-card {
  border-color: rgba(255, 255, 255, 0.85);
}
.drop-card svg {
  width: 30px;
  height: 30px;
  color: rgba(255, 255, 255, 0.8);
}
.drop-title {
  font-family: var(--serif);
  font-size: 1.6rem;
}
.drop-sub {
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  color: var(--faint);
}

/* ── onboarding: roaming finger + naive doodle hints ──────────
   The "brand layer" — warm, hand-drawn, transient. Decorative only; it never
   touches the disciplined product UI, and it bows out the moment you engage. */
#finger {
  position: fixed;
  left: 34px;
  bottom: 132px;
  z-index: 40;
  width: 46px;
  height: 54px;
  fill: var(--hand);
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px) rotate(-10deg);
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.35));
  transition: opacity 0.5s ease, transform 0.5s var(--ease);
}
#finger.show {
  opacity: 0.96;
  transform: none;
  animation: finger-roam 4.6s var(--ease) infinite;
}
@keyframes finger-roam {
  0% {
    transform: translate(0, 0) rotate(-10deg);
  }
  22% {
    transform: translate(58px, -26px) rotate(-3deg);
  }
  46% {
    transform: translate(128px, -8px) rotate(-12deg);
  }
  54% {
    transform: translate(128px, -8px) rotate(-12deg) scale(0.88);
  }
  60% {
    transform: translate(128px, -8px) rotate(-12deg) scale(1);
  }
  78% {
    transform: translate(66px, -34px) rotate(-5deg);
  }
  100% {
    transform: translate(0, 0) rotate(-10deg);
  }
}

.hint {
  position: fixed;
  z-index: 58;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.45s ease, transform 0.45s var(--ease);
}
.hint.show {
  opacity: 1;
  transform: none;
}
#hint-upload {
  top: 12px;
  left: 60px;
}
#hint-source {
  bottom: 58px;
  right: 14px;
}
.doodle {
  display: block;
  overflow: visible;
  stroke: var(--crayon);
  filter: url(#wobble);
}
.hint-note {
  position: absolute;
  font-family: var(--marker);
  font-weight: 600;
  font-size: 0.98rem;
  color: var(--crayon);
  white-space: nowrap;
  text-shadow: 0 1px 10px rgb(var(--bg-rgb) / 0.95),
    0 0 3px rgb(var(--bg-rgb) / 0.85);
}
#hint-upload .hint-note {
  top: 50px;
  left: 96px;
  transform: rotate(-3deg);
}
#hint-source .hint-note {
  top: -2px;
  right: 84px;
  transform: rotate(2deg);
}
.draw {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}
.hint.show .draw {
  animation: draw 0.85s var(--ease) forwards;
}
.hint.show .d2 {
  animation-delay: 0.6s;
}
.hint.show .d3 {
  animation-delay: 0.72s;
}
@keyframes draw {
  to {
    stroke-dashoffset: 0;
  }
}

/* ── toast ────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 100;
  transform: translateX(-50%) translateY(12px);
  padding: 10px 16px;
  border-radius: 9999px;
  border: 1px solid var(--line);
  background: rgba(20, 20, 24, 0.82);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s var(--ease);
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 768px) {
  #intro {
    bottom: 18px;
    left: 18px;
  }
  #credits .credit {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
  /* show the finished drawing, never a frozen half-stroke or roaming loop */
  #finger.show {
    animation: none;
  }
  .draw,
  .hint.show .draw {
    stroke-dashoffset: 0;
    animation: none;
  }
}
