:root {
  --black: #181818;
  --white: #fff;
  --ink: #1a1a1a;
  --border: #b9b9b9;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --color-page: var(--white);
  --color-text: var(--ink);
  --color-text-muted: #999;
  --color-border: var(--border);
  --glow: rgba(0, 0, 0, 0.07);
  --shadow-soft: rgb(0 0 0 / 0.14);
  --book-shadow: drop-shadow(2px 4px 15px var(--shadow-soft));
}
html.dark {
  --color-page: var(--black);
  --color-text: #f2f2f2;
  --color-border: #3a3a3a;
  --glow: rgba(255, 255, 255, 0.10);
  --book-shadow: drop-shadow(0 0 .5px rgb(255 255 255 / 0.42))
                 drop-shadow(2px 4px 15px rgb(255 255 255 / 0.08));
}
html, body { transition: background-color 0.5s var(--ease-out); }

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { height: 100%; }
html, body {
  background: var(--color-page);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* first screen: switch card centered in the viewport */
.hero {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ---- Card (title + framed switch + caption) ---- */
.card {
  display: flex;
  flex-direction: column;
  width: min(440px, 86vw);
}
.card-title {
  align-self: flex-start;
  font-size: 32px;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin-bottom: 18px;
}
.card-caption {
  align-self: flex-end;
  font-size: 16px;
  font-weight: 400;
  margin-top: 14px;
}

.frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 2px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
/* soft halo behind the switch */
.frame::before {
  content: "";
  position: absolute;
  width: 46%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: radial-gradient(circle, var(--glow) 0%, transparent 62%);
  pointer-events: none;
}
/* lights out — no halo when the switch is off */
html.dark .frame::before { display: none; }

/* ---- Lightswitch ---- */
.lightswitch {
  position: relative;
  width: 64px;
  aspect-ratio: 836 / 1328;
  border: 0; background: transparent; padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.lightswitch:focus-visible { outline: 2px solid #999; outline-offset: 6px; border-radius: 6px; }

.lightswitch-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  user-select: none; -webkit-user-drag: none; pointer-events: none;
}
.lightswitch-img--on  { display: block; }
.lightswitch-img--off { display: none; }
html.dark .lightswitch-img--on  { display: none; }
html.dark .lightswitch-img--off { display: block; }

/* ---- Visuals gallery (title + strip + caption) ---- */
.gallery {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1040px, 92vw);
  padding: 0 0 96px;
}
/* title + caption are left-positioned via JS to track the active card's edges */
.gallery-title {
  position: relative;
  left: 0;
  align-self: flex-start;
  width: fit-content;
  white-space: nowrap;
  font-size: 32px;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin-bottom: 16px;
  min-height: 38px;
}
.gallery-caption {
  position: relative;
  left: 0;
  align-self: flex-start;
  width: fit-content;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 400;
  margin-top: 16px;
  min-height: 20px;
}

/* ---- Visuals accordion ---- */
.accordion {
  display: flex;
  gap: 3px;
  height: min(520px, 64vh);
  width: 100%;
  overflow: hidden;
}
.acc-card {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  margin: 0; padding: 0; border: 0;
  background: var(--acc, #111);
  cursor: pointer;
  overflow: hidden;
  filter: var(--book-shadow);
  transition: flex-grow 0.5s var(--ease-out);
}
.acc-card:hover,
.acc-card:focus-visible { flex-grow: 2.2; outline: none; }
.acc-card.selected { flex-grow: 9; cursor: default; }
.acc-card.selected:hover { flex-grow: 9; }
.acc-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.acc-card::after {
  content: "";
  position: absolute; inset: auto 0 0 0; height: 45%;
  background: linear-gradient(transparent, rgba(0,0,0,0.4));
  pointer-events: none;
}
/* a selected image card's flex-grow is set in JS so its width matches the
   image's aspect ratio — keeping it inside the flex-grow transition (smooth) */
.acc-card.has-img.selected::after { content: none; }

/* ---- More : compact grid (quantity over highlight) ---- */
.more {
  width: min(1040px, 92vw);
  display: flex;
  flex-direction: column;
  padding: 0 0 120px;
}
.more-title { font-size: 16px; font-weight: 600; margin-bottom: 14px; }
.grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 3px;
  margin: 0 auto;
  width: 100%;
}
.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--tile, #111);
  border: 0; margin: 0; padding: 0;
  cursor: pointer;
  overflow: hidden;
  filter: var(--book-shadow);
  transition: transform 0.25s var(--ease-out);
}
.tile:hover, .tile:focus-visible { transform: translateY(-2px); outline: none; }
.tile-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}

/* ---- Inline viewer : expanded image sits above the pixel grid ---- */
.more-viewer {
  display: none;
  justify-content: center;
  margin-bottom: 14px;
}
.more-viewer.open { display: flex; }
.more-frame {
  position: relative;
  padding: 0;
  filter: drop-shadow(0 10px 30px rgba(0,0,0,0.18));
  max-width: 100%;
  display: flex;
  animation: frame-in 0.32s var(--ease-out);
}
@keyframes frame-in {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}
.more-frame img {
  display: block;
  max-width: 100%;
  max-height: 72vh;
  object-fit: contain;
}
/* filename printed sideways down the right edge, reading top-to-bottom */
.more-frame-name {
  position: absolute;
  left: 100%; bottom: 0;
  margin-left: 7px;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  white-space: nowrap;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--color-text);
  opacity: 0.5;
  pointer-events: none;
}
/* the active grid tile reads as the one on display */
.tile.active {
  outline: 2px solid var(--color-text);
  outline-offset: -2px;
}

/* retro hourglass parked over the chosen tile's slot — covers the load wait
   and the gap left while the grid closes back up (positioned via JS) */
.tile-loader {
  position: absolute; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  transform-origin: center;
  pointer-events: none;
}
.tile-loader img {
  height: 50%; width: auto;
  object-fit: contain;
  image-rendering: pixelated;
  transform-origin: 50% 50%;
  animation: hourglass-flip 0.5s infinite;
  /* soften the pure-black PNG to a mid-grey */
  filter: invert(0.36);
}
/* on the dark page, keep it a muted grey rather than bright white */
html.dark .tile-loader img { filter: invert(0.78); }
/* 2 discrete frames: flipped 180° first, then as-sent */
@keyframes hourglass-flip {
  0%, 49.99% { transform: rotate(180deg); }
  50%, 100%  { transform: rotate(0deg); }
}

/* ---- Mobile ---- */
@media (max-width: 600px) {
  .card-title { font-size: 26px; margin-bottom: 14px; }
  .card-caption { font-size: 15px; }
  .accordion { height: 280px; gap: 1px; }
  /* no title/caption on mobile */
  .gallery-title, .gallery-caption { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 2px; }
  .more-frame-name { display: none; }

  .more-frame img { max-height: 60vh; }
}
