/* ==========================================================================
   GAME SHELF — style.css
   A wood-and-brass display case for a game collection.
   ========================================================================== */

:root {
  /* --- palette -------------------------------------------------------- */
  --room-1: #241609;
  --room-2: #0f0904;
  --wood-dark: #2a1a10;
  --wood-mid: #5c3b22;
  --wood-light: #8a5a34;
  --brass: #c9974c;
  --brass-bright: #eec98a;
  --paper: #f1e4cf;
  --paper-dim: #cbb99e;
  --ink: #140d08;
  --shadow: rgba(0, 0, 0, 0.6);
  --focus: #ffcf82;

  /* --- type ------------------------------------------------------------ */
  --font-display: "Fraunces", "Iowan Old Style", serif;
  --font-body: "Archivo", "Segoe UI", sans-serif;
  --font-mono: "Space Mono", "Courier New", monospace;

  /* --- layout geometry (matches the exported art) ----------------------
     outside/inside canvas: 3239 x 2167  =  back(1532) + spine(171) + front(1536)
     dvd: 1024 x 1024 perfect circle, no hole (we punch one with a mask)   */
  --spine-h: clamp(150px, 19vw, 250px);
  --row-gap-y: clamp(30px, 4.2vw, 58px);
  --row-gap-x: clamp(6px, 1vw, 14px);

  /* image-slicing math — recalculated by script.js from the LAYOUT
     constants at the top of that file, these are just the fallback
     defaults for the stock back|spine|front / 1532|171|1536 layout */
  --front-scale: 2.1087239583;
  --front-offset: 1.1087239583;
  --back-scale: 2.1142297649;
  --back-offset: 0;
  --spine-scale: 18.9415204678;
  --spine-offset: 8.9590643275;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--paper);
  background:
    radial-gradient(120% 70% at 50% -10%, #3a2410 0%, transparent 60%),
    linear-gradient(180deg, var(--room-1) 0%, var(--room-2) 100%);
  min-height: 100vh;
}

img { max-width: none; }

/* ==========================================================================
   HEADER
   ========================================================================== */

.site-header {
  text-align: center;
  padding: clamp(48px, 8vw, 88px) 20px 28px;
}

.eyebrow {
  font-family: var(--font-mono);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--brass-bright);
  opacity: 0.9;
}

.site-title {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 600;
  font-size: clamp(2.2rem, 6vw, 4rem);
  margin: 0.3em 0 0.2em;
  color: var(--paper);
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.5);
}

.site-sub {
  font-family: var(--font-body);
  color: var(--paper-dim);
  max-width: 46ch;
  margin: 0 auto;
  line-height: 1.55;
  font-size: 0.98rem;
}

.site-sub strong { color: var(--brass-bright); font-weight: 600; }

/* ==========================================================================
   SHELF
   ========================================================================== */

.shelf-section {
  padding: 10px 20px clamp(60px, 10vw, 120px);
  position: relative;
}

.shelf-wrap {
  max-width: 1240px;
  margin: 0 auto;
  position: relative;
}

/* soft gallery light glow above the collection — the one signature flourish */
.shelf-wrap::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -60px;
  width: 70%;
  height: 200px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(255, 210, 140, 0.16), transparent 70%);
  pointer-events: none;
  filter: blur(2px);
}

.shelf {
  --tile-h: 220px; /* overwritten by JS to match the real row height */
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  column-gap: var(--row-gap-x);
  row-gap: var(--row-gap-y);
  padding: 34px clamp(16px, 4vw, 56px) 26px;

  background-image: url("images/shelf-board.png");
  background-repeat: repeat-y;
  background-size: 100% var(--tile-h);
  background-position: top;
  border-radius: 6px;
  box-shadow:
    inset 0 0 60px rgba(0, 0, 0, 0.45),
    0 40px 70px -30px rgba(0, 0, 0, 0.7);
}

.shelf-empty {
  font-family: var(--font-mono);
  color: var(--paper-dim);
  text-align: center;
  padding: 70px 20px;
  width: 100%;
}

.shelf-empty strong { color: var(--brass-bright); }

/* ---- an individual box, seen edge-on (the spine) ----
   Deliberately simple: a flat lift + grow on hover, no 3D tilt. The
   shelf can hold a lot of these at once, all thin and side by side —
   a per-item mouse-tracking tilt reads as noisy/flickery at that scale.
   The tilt effect lives only in the case inspector, where there's one
   large object to focus on. */

.spine {
  position: relative;
  height: var(--spine-h);
  aspect-ratio: 171 / 2167;
  flex: 0 0 auto;
  border: 0;
  padding: 0;
  margin-bottom: 6px;
  cursor: pointer;
  border-radius: 3px 3px 1px 1px;
  background: #111;
  box-shadow:
    0 2px 0 rgba(0, 0, 0, 0.5),
    2px 10px 18px -8px rgba(0, 0, 0, 0.65);
  transform: translateY(0) scale(1);
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.25s ease, filter 0.25s ease;
  filter: brightness(0.94);
}

.spine:hover,
.spine:focus-visible {
  transform: translateY(-12px) scale(1.14);
  filter: brightness(1.08);
  z-index: 5;
  box-shadow:
    0 20px 30px -14px rgba(0, 0, 0, 0.75),
    0 0 0 1px rgba(255, 210, 140, 0.25);
}

.spine:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.spine .shine {
  opacity: 0.35;
  background-position: 70% 10%;
}
.spine:hover .shine { background-position: 20% 90%; }

/* ==========================================================================
   IMAGE SLICING
   One outside/inside PNG (3239x2167) is sliced into back / spine / front
   panels purely with CSS, by oversizing the image and shifting it inside
   an overflow:hidden box. No build step, no image duplication needed.
   ========================================================================== */

.slice { position: relative; overflow: hidden; }
.slice > img {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: auto;
  pointer-events: none;
  user-select: none;
}

.slice--front > img { width: calc(var(--front-scale) * 100%); left: calc(var(--front-offset) * -100%); }
.slice--back  > img { width: calc(var(--back-scale)  * 100%); left: calc(var(--back-offset)  * -100%); }
.slice--spine > img { width: calc(var(--spine-scale) * 100%); left: calc(var(--spine-offset) * -100%); }

/* plastic sheen, reused on spines + the big case faces */
.shine {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    115deg,
    transparent 32%,
    rgba(255, 255, 255, 0.55) 46%,
    rgba(255, 255, 255, 0.06) 56%,
    transparent 72%
  );
  background-size: 240% 240%;
  mix-blend-mode: screen;
  transition: background-position 0.9s ease;
}

/* ==========================================================================
   MODAL — the case inspector
   ========================================================================== */

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(16px, 4vw, 40px);
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 100;
}

.modal.is-open { visibility: visible; opacity: 1; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 100% at 50% 30%, rgba(30, 18, 10, 0.88), rgba(6, 4, 2, 0.96));
  backdrop-filter: blur(6px);
}

.modal-panel {
  position: relative;
  width: min(96vw, 980px);
  max-height: 92vh;
  overflow: auto;
  background: linear-gradient(180deg, #1b120a, #120b06);
  border: 1px solid rgba(201, 151, 76, 0.25);
  border-radius: 16px;
  padding: clamp(20px, 3vw, 40px);
  text-align: center;
  box-shadow: 0 60px 120px -30px rgba(0, 0, 0, 0.8);
  transform: translateY(14px) scale(0.98);
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal.is-open .modal-panel { transform: translateY(0) scale(1); }

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(201, 151, 76, 0.35);
  background: rgba(255, 255, 255, 0.04);
  color: var(--paper);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { background: rgba(255, 255, 255, 0.1); }
.modal-close:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.modal-eyebrow {
  font-family: var(--font-mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: var(--brass-bright);
  margin: 0 0 6px;
}

.modal-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.5rem, 3.4vw, 2.2rem);
  margin: 0 0 20px;
}

/* ---- the 3D stage ---- */

.stage {
  position: relative;
  min-height: min(58vh, 520px);
  perspective: 1100px;
}

.cover-view,
.open-view {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease, transform 0.5s ease;
  transform-style: preserve-3d;
}

.cover-view { z-index: 1; }
.open-view { z-index: 2; opacity: 0; transform: scale(0.94); pointer-events: none; }
.modal-panel[data-mode="open"] .open-view { opacity: 1; transform: scale(1); pointer-events: auto; }
.modal-panel[data-mode="open"] .cover-view { opacity: 0; pointer-events: none; transition-delay: 0s; }
.modal-panel:not([data-mode="open"]) .cover-view { transition-delay: 0.12s; }

.hinge {
  width: min(52vw, 340px);
  aspect-ratio: 1536 / 2167;
  transform-style: preserve-3d;
  transform-origin: left center;
  transform: rotateY(0deg);
  transition: transform 0.85s cubic-bezier(0.3, 0.7, 0.2, 1);
}

.modal-panel[data-mode="open"] .hinge { transform: rotateY(-108deg); }

.flip {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.65s cubic-bezier(0.4, 0.2, 0.2, 1);
}

.flip.flipped { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  background: #000;
  border-radius: 9px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  cursor: pointer;
  box-shadow: 0 40px 70px -24px rgba(0, 0, 0, 0.75), 0 2px 0 rgba(255, 255, 255, 0.05) inset;
}

.face-back { transform: rotateY(180deg); }

.face .shine { background-position: 78% 15%; opacity: 0.6; }
.face:hover .shine, .face:focus-visible .shine { background-position: 18% 85%; }
.face:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

/* ---- open / interior view ---- */

.spread {
  position: relative;
  width: min(88vw, 760px);
  aspect-ratio: 3239 / 2167;
  margin: 0 auto;
}

.inside-art {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  box-shadow: 0 40px 90px -24px rgba(0, 0, 0, 0.75);
}

.dvd {
  position: absolute;
  left: 76.3%;
  top: 50%;
  width: 34%;
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%) scale(0.9) rotate(-8deg);
  opacity: 0;
  border: 0;
  padding: 0;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  filter: drop-shadow(0 20px 34px rgba(0, 0, 0, 0.6));
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) 0.15s, opacity 0.5s ease 0.15s;
  /* dvd-tilt (below) applies its own rotateX/rotateY on hover — this
     keeps that from being flattened against this element's own
     translate/scale/rotate, which is what drives the open/close
     entrance animation above and must stay untouched by the tilt. */
  transform-style: preserve-3d;
}

.modal-panel[data-mode="open"] .dvd {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1) rotate(0deg);
}

/* the hover-tilt target — a plain wrapper so the tilt transform never
   has to compete with .dvd's own position/entrance transform above */
.dvd-tilt {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.dvd img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  -webkit-mask-image: radial-gradient(circle, transparent 0 12.4%, #000 13.2% 100%);
  mask-image: radial-gradient(circle, transparent 0 12.4%, #000 13.2% 100%);
}

.dvd-shine {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  background: conic-gradient(
    from 0deg,
    transparent 0deg, rgba(255, 255, 255, 0.55) 10deg, transparent 26deg,
    transparent 150deg, rgba(255, 255, 255, 0.4) 168deg, transparent 190deg,
    transparent 330deg, rgba(255, 255, 255, 0.45) 348deg, transparent 360deg
  );
  mix-blend-mode: screen;
  animation: dvd-spin 9s linear infinite;
  -webkit-mask-image: radial-gradient(circle, transparent 0 12.4%, #000 13.2% 100%);
  mask-image: radial-gradient(circle, transparent 0 12.4%, #000 13.2% 100%);
}

@keyframes dvd-spin { to { transform: rotate(360deg); } }

.dvd-hole {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26.4%;
  height: 26.4%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
  box-shadow: inset 0 3px 7px rgba(0, 0, 0, 0.7), inset 0 -1px 2px rgba(255, 255, 255, 0.08);
  background: radial-gradient(circle at 38% 32%, rgba(255, 255, 255, 0.1), transparent 65%);
}

/* ---- controls ---- */

.modal-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 26px;
}

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 11px 22px;
  border-radius: 999px;
  border: 1px solid rgba(201, 151, 76, 0.4);
  background: rgba(255, 255, 255, 0.04);
  color: var(--paper);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.1); transform: translateY(-1px); }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.btn-brass {
  background: linear-gradient(180deg, var(--brass-bright), var(--brass));
  color: #2a1a06;
  border-color: transparent;
}
.btn-brass:hover { filter: brightness(1.06); background: linear-gradient(180deg, var(--brass-bright), var(--brass)); }

.modal-hint {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--paper-dim);
  margin: 16px 0 0;
}

/* ==========================================================================
   FOOTER
   ========================================================================== */

.site-footer {
  text-align: center;
  padding: 20px 20px 60px;
  color: var(--paper-dim);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  opacity: 0.7;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 640px) {
  .hinge { width: min(70vw, 300px); }
  .spread { width: min(94vw, 520px); }
  .modal-panel[data-mode="open"] .hinge { transform: rotateY(-96deg); }
}

/* ==========================================================================
   ACCESSIBILITY
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

body.modal-locked { overflow: hidden; }
