/* collection shelf: horizontal, endlessly looping row of cards */
.app { position: relative; }
.gallery {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(90% 60% at 50% 46%, rgba(64, 58, 128, 0.42) 0%, rgba(18, 18, 42, 0) 70%),
    radial-gradient(120% 90% at 50% 42%, var(--bg-1) 0%, var(--bg-0) 72%);
  transition: opacity 0.3s ease, transform 0.3s ease;
  user-select: none;
  -webkit-user-select: none;
}
.gallery[hidden] { display: none; }
.gallery.leaving { opacity: 0; transform: scale(1.06); pointer-events: none; }
.gallery.entering { opacity: 0; transform: scale(1.04); }
.g-head {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  padding: max(18px, env(safe-area-inset-top)) 16px 0;
}
.g-head h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: 0.32em; text-indent: 0.32em; color: var(--gold); }
.g-count { margin: 0; font-size: 12px; letter-spacing: 0.12em; color: var(--ink-dim); }
.g-track {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  perspective: 1400px;
  touch-action: none;
  cursor: grab;
}
.g-track.dragging { cursor: grabbing; }
.g-card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--cw, 200px);
  height: var(--ch, 300px);
  margin: calc(var(--ch, 300px) / -2) 0 0 calc(var(--cw, 200px) / -2);
  padding: 0;
  border: 0;
  border-radius: calc(var(--cw, 200px) * 0.045);
  background: #0a0a16;
  overflow: hidden;
  cursor: inherit;
  will-change: transform;
  box-shadow: 0 0 0 1px rgba(241, 223, 174, 0.34), 0 22px 46px rgba(0, 0, 0, 0.62);
  -webkit-tap-highlight-color: transparent;
}
.g-card img { display: block; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.g-card::after {                       /* cards away from the middle sit in shade */
  content: "";
  position: absolute;
  inset: 0;
  background: #05050c;
  opacity: var(--dim, 0);
  pointer-events: none;
}
.g-sheen {                             /* a band of foil light that sweeps as the card passes the middle */
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: 0.5;
  background: linear-gradient(112deg, rgba(255, 255, 255, 0) 38%, rgba(190, 220, 255, 0.34) 46%, rgba(255, 244, 214, 0.5) 50%, rgba(255, 196, 236, 0.3) 54%, rgba(255, 255, 255, 0) 62%);
  background-size: 300% 100%;
  background-position: calc(50% + var(--d, 0) * 46%) 0;
}
.g-card.mid { box-shadow: 0 0 0 1px rgba(241, 223, 174, 0.7), 0 0 34px rgba(241, 223, 174, 0.22), 0 26px 54px rgba(0, 0, 0, 0.66); cursor: pointer; }
.g-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.g-info {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0 16px max(14px, env(safe-area-inset-bottom));
  text-align: center;
}
.g-name { margin: 0; font-size: 20px; letter-spacing: 0.22em; text-indent: 0.22em; }
.g-meta { margin: 0; font-size: 12px; letter-spacing: 0.14em; color: var(--gold); }
.g-dots { display: flex; gap: 7px; margin: 4px 0 2px; }
.g-dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(190, 188, 220, 0.3); transition: background 0.2s ease, transform 0.2s ease; }
.g-dots i.on { background: var(--gold); transform: scale(1.35); }
.g-actions { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.btn.round { width: 44px; padding: 0; justify-content: center; font-size: 20px; line-height: 1; }
.btn.primary { border-color: rgba(241, 223, 174, 0.6); color: var(--gold); }
.btn.to-shelf {
  position: absolute;
  z-index: 10;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  min-height: 40px;
  padding: 0 16px 0 12px;
}
@media (max-height: 480px) {
  .g-head { padding-top: 8px; }
  .g-head h1 { font-size: 14px; }
  .g-name { font-size: 15px; }
  .g-info { gap: 3px; padding-bottom: 8px; }
  .g-info .hint, .g-dots { display: none; }
  .g-actions .btn { min-height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  .gallery { transition: none; }
}

/* hosted copy: the link back to the portfolio shows on the shelf; a card shows the way back to the shelf instead */
.app > a.back { z-index: 30; }
.app:not(.shelf-open) > a.back { display: none; }

/* with WebGL the row is the real 3D cards drawn by the viewer underneath: the shelf becomes see-through and a tile
   whose card is drawn in 3D keeps only its place (touch target, keyboard focus) */
.gallery.gl-on { background: none; }
.g-card.gl { background: none; box-shadow: none; overflow: visible; }
.g-card.gl img, .g-card.gl .g-sheen, .g-card.gl::after { display: none; }
.bar[hidden] { display: none; }
.g-info { position: relative; }
.gallery.gl-on .g-info::before {          /* keeps the caption readable over the picture */
  content: "";
  position: absolute;
  inset: -40px 0 0;
  background: linear-gradient(180deg, rgba(7, 8, 15, 0) 0%, rgba(7, 8, 15, 0.82) 45%, #07080f 100%);
  z-index: -1;
  pointer-events: none;
}

/* ---------- a card lifted out of the row (held, or picked up with the keyboard) ---------- */
.gallery { -webkit-touch-callout: none; }
.g-head, .g-info { transition: opacity 0.28s ease, transform 0.28s ease; }
.app.viewing .gallery { pointer-events: none; }
.app.viewing .g-head { opacity: 0; transform: translateY(-10px); }
.app.viewing .g-info { opacity: 0; transform: translateY(14px); }
.app.viewing .gallery:not(.gl-on) { opacity: 0; }          /* no WebGL: the still picture underneath is the lifted card */
.g-hud {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  pointer-events: none;
  /* not quite 0: the browser keeps drawing the layer (nothing of it can be seen), so the blur behind the pills is
     already set up when the first card is lifted. Starting it at that moment stalled the lift for a few frames. */
  opacity: 0.004;
  transition: opacity 0.3s ease 0.08s;
}
.app.viewing .g-hud { opacity: 1; }
.hud-name { margin: 0; font-size: 13px; letter-spacing: 0.2em; text-indent: 0.2em; color: var(--gold); text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8); }
.hud-hint {
  margin: 0;
  padding: 8px 16px;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--ink);
  background: rgba(14, 14, 30, 0.6);
  border: 1px solid var(--line);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
/* the press is charging: a ring closes around the finger, and the card is lifted when it is full */
.g-ring {
  position: fixed;
  z-index: 40;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  background: conic-gradient(var(--gold) var(--a, 0deg), rgba(241, 223, 174, 0.14) 0);
  -webkit-mask: radial-gradient(circle, transparent 25px, #000 26px, #000 30px, transparent 31px);
  mask: radial-gradient(circle, transparent 25px, #000 26px, #000 30px, transparent 31px);
}
@property --a { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
.g-ring.on { animation: ring-fill 0.34s linear forwards; }
@keyframes ring-fill {
  0% { opacity: 0; --a: 0deg; transform: scale(0.7); }
  25% { opacity: 1; }
  100% { opacity: 1; --a: 360deg; transform: scale(1); }
}
.hint.pulse { animation: hint-pulse 0.9s ease; }
@keyframes hint-pulse { 0%, 100% { color: var(--ink-dim); transform: none; } 30% { color: var(--gold); transform: scale(1.08); } }
.g-actions .toggle { min-height: 40px; padding: 0 14px; font-size: 13px; }
.stage { cursor: grabbing; }
@media (max-height: 480px) { .g-actions .toggle { min-height: 34px; } }

/* ---------- polish after the independent review ---------- */
.g-hud { transition: opacity 0.12s ease; }
.app.viewing .g-hud { transition: opacity 0.26s ease 0.24s; }
.hud-name {
  padding: 7px 16px;
  background: rgba(14, 14, 30, 0.6);
  border: 1px solid rgba(241, 223, 174, 0.3);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.g-ring {
  width: 104px;
  height: 104px;
  margin: -52px 0 0 -52px;
  -webkit-mask: radial-gradient(circle, transparent 41px, #000 42px, #000 50px, transparent 51px);
  mask: radial-gradient(circle, transparent 41px, #000 42px, #000 50px, transparent 51px);
  filter: drop-shadow(0 0 6px rgba(241, 223, 174, 0.7));
}
/* the 3D card is not exactly where its touch target is, so focus is shown on the caption instead of a box */
.gallery.gl-on .g-card:focus-visible { outline: none; }
.g-track:has(.g-card:focus-visible) ~ .g-info .g-name { text-decoration: underline; text-decoration-color: var(--gold); text-underline-offset: 8px; text-decoration-thickness: 2px; }
.app.viewing .stage:focus-visible::after { display: none; }
.g-actions .toggle { white-space: nowrap; }
@media (max-width: 360px) { .g-actions { gap: 6px; } .g-actions .toggle { padding: 0 10px; font-size: 12px; } .g-actions .toggle .dot { display: none; } }
@media (max-height: 480px) { .g-info .hint { display: block; font-size: 11px; } }

/* the layers that fade when a card is lifted exist from the start: creating them at the first lift stalled a few frames */
.g-head, .g-info { will-change: opacity, transform; }

/* "card flash": the wave of light on demand. One button under the shelf, one beside a lifted card. */
.btn .spark { color: var(--gold); font-size: 13px; line-height: 1; }
.btn.to-flash {
  position: absolute;
  z-index: 10;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  min-height: 40px;
  padding: 0 14px 0 12px;
  display: none;
}
.app.viewing .btn.to-flash { display: inline-flex; }
/* three buttons and two arrows in one row, down to the narrowest phones */
@media (max-width: 460px) { .g-actions { gap: 6px; } .g-actions .toggle { padding: 0 9px; font-size: 12px; gap: 5px; } .g-actions .toggle .dot { display: none; } .g-actions .btn.round { width: 38px; } }
@media (max-width: 345px) { .g-actions { gap: 4px; } .g-actions .toggle { padding: 0 6px; } .g-actions .toggle .spark { display: none; } .g-actions .btn.round { width: 32px; } }
/* narrow screens: the card's name sits under the two buttons instead of between them */
@media (max-width: 620px) { .g-hud { padding-top: calc(max(12px, env(safe-area-inset-top)) + 50px); } }

/* a lifted card can be exchanged for its neighbour without putting it back: arrows in the bottom corners */
.btn.to-prev, .btn.to-next { position: absolute; z-index: 10; bottom: max(14px, env(safe-area-inset-bottom)); }
.btn.to-prev { left: max(12px, env(safe-area-inset-left)); }
.btn.to-next { right: max(12px, env(safe-area-inset-right)); }
@media (max-width: 620px) { .btn.to-prev, .btn.to-next { width: 40px; min-height: 40px; } .g-hud { padding-left: 58px; padding-right: 58px; } .hud-hint { text-align: center; line-height: 1.5; } }

/* zoomed in: what a drag does (move the picture / turn the card), one tap to change */
.btn.to-drag {
  position: absolute; z-index: 10; left: 50%; transform: translateX(-50%);
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 56px);
  min-height: 38px; padding: 0 16px; font-size: 13px; white-space: nowrap;
}
.btn.to-drag[aria-pressed="true"] { border-color: rgba(241, 223, 174, 0.7); color: var(--gold); }
@media (max-width: 620px) { .btn.to-drag { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 76px); } }

/* phones: tilt the phone to turn the lifted card, like a real foil card in the hand - its switch sits between the two top buttons */
.btn.to-gyro {
  position: absolute; z-index: 10; left: 50%; transform: translateX(-50%);
  top: max(12px, env(safe-area-inset-top));
  min-height: 40px; padding: 0 12px; font-size: 13px; gap: 6px; white-space: nowrap; display: none;
}
.app.viewing .btn.to-gyro:not([hidden]) { display: inline-flex; }
@media (max-width: 360px) { .btn.to-gyro { padding: 0 8px; font-size: 12px; } .btn.to-gyro .dot { display: none; } .btn.to-shelf { padding: 0 10px 0 8px; font-size: 13px; } .btn.to-flash { padding: 0 10px 0 8px; font-size: 13px; } }
