:root {
  color-scheme: dark;
  --room: #131017;
  --cream: #f3efe4;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(circle at 50% 45%, #2a2530 0, var(--room) 68%),
    var(--room);
  color: var(--cream);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

a { -webkit-tap-highlight-color: transparent; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- Brand floater ------------------------------------------------- */

.brand-floater {
  position: fixed;
  z-index: 20;
  top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  display: block;
  transition: transform 0.18s ease;
}

.brand-floater:hover { transform: scale(1.04); }

.brand-floater img {
  display: block;
  width: clamp(180px, 20vw, 280px);
  height: auto;
  filter: drop-shadow(0 6px 22px rgba(0, 0, 0, 0.45));
}

.brand-floater:focus-visible {
  outline: 2px solid var(--cream);
  outline-offset: 4px;
}

/* ---- Hint ----------------------------------------------------------- */

.hint {
  position: fixed;
  z-index: 20;
  top: max(22px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
  margin: 0;
  padding: 9px 14px;
  border-radius: 999px;
  color: rgba(243, 239, 228, 0.85);
  background: rgba(18, 15, 21, 0.6);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.hint.gone { opacity: 0; }

@media (max-width: 600px) {
  .brand-floater img { width: 160px; }
}

/* ---- Wall ----------------------------------------------------------- */

.wall {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  cursor: grab;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.wall.is-dragging { cursor: grabbing; }
.wall.is-dragging .cell { pointer-events: none; }

.wall:focus-visible::after {
  content: "";
  position: absolute;
  z-index: 8;
  inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  border: 2px solid var(--cream);
  pointer-events: none;
}

.stage {
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 100px;
  transform-origin: 0 0;
  /* No will-change here: a pinned raster never re-rasterizes, which turns
     deep zoom into a stretched 1× texture blur. */
  isolation: isolate;
  background: #292929;
  box-shadow: 0 26px 90px rgba(0, 0, 0, 0.6);
}

.stage > picture,
.stage .base {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* Poster cells sit between the base image and the lighting overlay, so
   the overlay's relief blends onto them — until one is hovered and lifts
   above the lighting at full color. */
.cell {
  position: absolute;
  z-index: 1;
  display: block;
  outline: 0;
}

.cell img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  transition: transform 0.16s ease-out, box-shadow 0.16s ease-out;
}

/* Field cells keep the wall's baked-in fade; the T stays luminous.
   Hovering a faded poster switches its light back on. */
.cell.dim::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(26, 23, 30, 0.66);
  transition: opacity 0.16s ease-out;
  pointer-events: none;
}

.cell.dim:focus-visible::after { opacity: 0; }

.cell:focus-visible {
  z-index: 3;
}

.cell:focus-visible img {
  transform: scale(1.45);
  box-shadow: 0 0.4em 1.6em rgba(0, 0, 0, 0.65);
}

.cell:focus-visible img { outline: 0.12em solid rgba(255, 255, 255, 0.95); }

@media (hover: hover) and (pointer: fine) {
  .cell.dim:hover::after { opacity: 0; }
  .cell:hover { z-index: 3; }
  .cell:hover img {
    transform: scale(1.45);
    box-shadow: 0 0.4em 1.6em rgba(0, 0, 0, 0.65);
  }
}

.overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  mix-blend-mode: overlay;
  pointer-events: none;
}

/* Once JS composites base × overlay into the canvas, the source images
   drop out and the canvas becomes the backdrop (WebKit renders CSS
   blend-under-transform unreliably; the canvas path never blends live). */
.flattened {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.has-flattened > picture,
.has-flattened > .overlay { visibility: hidden; }

/* Counter-scaled tile layer: laid out at on-screen size, scaled back down,
   so tiles rasterize at native resolution at any zoom. */
.cells {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  contain: layout style;
}

/* ---- Transient chrome ----------------------------------------------- */

.loading {
  position: absolute;
  z-index: 9;
  top: 50%;
  left: 50%;
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  color: var(--cream);
  background: rgba(18, 15, 21, 0.82);
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  transform: translate(-50%, -50%);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.loading[hidden] { display: none; }

.tooltip {
  position: fixed;
  z-index: 12;
  max-width: min(300px, calc(100vw - 24px));
  margin: 0;
  padding: 7px 11px;
  border-radius: 8px;
  color: #121015;
  background: rgba(255, 255, 255, 0.96);
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.25;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.tooltip[hidden] { display: none; }

.attribution {
  position: fixed;
  z-index: 10;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  margin: 0;
  color: rgba(243, 239, 228, 0.42);
  font-size: 0.66rem;
  pointer-events: none;
}

.attribution a {
  color: inherit;
  pointer-events: auto;
}

/* ---- Debug panel ------------------------------------------------------ */

.debug-panel {
  position: fixed;
  z-index: 40;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  background: rgba(14, 12, 17, 0.92);
  font-size: 0.78rem;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
}

.debug-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.debug-panel input[type="range"] { width: 110px; }

.stage.debug-no-tiles .cell { display: none; }
.stage.debug-no-fade .cell.dim::after { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .cell img,
  .brand-floater { transition: none; }
}

@media (forced-colors: active) {
  .stage { outline: 2px solid CanvasText; }
  .cell:hover,
  .cell:focus-visible { outline: 2px solid LinkText; }
}
