:root {
  --bar-h: 52px;
  --ink: #16161a;
  --chrome: rgba(24, 24, 27, 0.88);
  --chrome-fg: #f4f4f5;
  --accent: #e11d2e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg, #cccccc);
  font: 400 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

.fallback { padding: 2rem; text-align: center; }

/* ---------------------------------------------------------------- stage */

#stage {
  position: absolute;
  inset: 0 0 var(--bar-h) 0;
  overflow: hidden;
  touch-action: pan-y;
}

#viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

#track {
  display: flex;
  height: 100%;
  will-change: transform;
  transform: translate3d(0, 0, 0);
}

.slide {
  flex: 0 0 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 14px;
}

#track.animate { transition: transform 340ms cubic-bezier(0.33, 0.9, 0.28, 1); }

@media (prefers-reduced-motion: reduce) {
  #track.animate { transition-duration: 1ms; }
}

.leaf {
  position: relative;
  height: 100%;
  flex: 0 1 auto;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22), 0 8px 26px rgba(0, 0, 0, 0.16);
}

.slide.pair .leaf:first-child { box-shadow: -1px 1px 3px rgba(0,0,0,.22), -6px 8px 26px rgba(0,0,0,.16); }
.slide.pair .leaf:last-child  { box-shadow:  1px 1px 3px rgba(0,0,0,.22),  6px 8px 26px rgba(0,0,0,.16); }

.leaf img,
.leaf canvas {
  display: block;
  height: 100%;
  width: auto;
  max-width: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

.leaf canvas { position: absolute; inset: 0; }

.leaf.pending { background: #fff center/28px no-repeat; }

/* ---------------------------------------------------------- link overlay */

.hot {
  position: absolute;
  display: block;
  border-radius: 2px;
  background: transparent;
  transition: background 140ms ease;
  -webkit-tap-highlight-color: transparent;
}

.hot:hover,
.hot:focus-visible {
  background: rgba(114, 230, 255, 0.28);
  outline: 2px solid rgba(114, 230, 255, 0.85);
  outline-offset: -2px;
}

body.hint-links .hot { background: rgba(114, 230, 255, 0.22); }

/* ------------------------------------------------------------------- nav */

.nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 74px;
  border: 0;
  padding: 0;
  cursor: pointer;
  background: rgba(24, 24, 27, 0.34);
  color: #fff;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 180ms ease, background 180ms ease;
}

#stage:hover .nav,
.nav:focus-visible { opacity: 1; }
.nav:hover { background: rgba(24, 24, 27, 0.6); }
.nav[disabled] { opacity: 0 !important; pointer-events: none; }

#prev { left: 0; border-radius: 0 4px 4px 0; }
#next { right: 0; border-radius: 4px 0 0 4px; }

.nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor;
           stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.loading {
  position: absolute;
  inset: auto 0 50% 0;
  text-align: center;
  font-size: 13px;
  color: rgba(0, 0, 0, 0.5);
}
.loading[hidden] { display: none; }

/* ------------------------------------------------------------------- bar */

#bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--bar-h);
  padding: 0 12px calc(env(safe-area-inset-bottom) * 0.5) 12px;
  display: grid;
  grid-template-columns: 1fr minmax(0, 2fr) 1fr;
  align-items: center;
  gap: 12px;
  background: var(--chrome);
  color: var(--chrome-fg);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
}

.bar-group { display: flex; align-items: center; gap: 6px; min-width: 0; }
.bar-right { justify-content: flex-end; }
.bar-center { justify-content: center; }

#bar button {
  border: 0;
  background: transparent;
  color: inherit;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

#bar button:hover { background: rgba(255, 255, 255, 0.12); }
#bar button:focus-visible { outline: 2px solid #72e6ff; outline-offset: 1px; }
#bar button[hidden] { display: none; }

#bar svg { width: 18px; height: 18px; fill: none; stroke: currentColor;
           stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

#zoom {
  -webkit-appearance: none;
  appearance: none;
  width: 92px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.34);
  outline: none;
}

#zoom::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--chrome-fg);
  cursor: pointer;
}
#zoom::-moz-range-thumb {
  width: 13px; height: 13px; border: 0; border-radius: 50%;
  background: var(--chrome-fg); cursor: pointer;
}

/* --------------------------------------------------------------- scrubber */

#scrub {
  position: relative;
  width: 100%;
  max-width: 560px;
  height: 34px;
  cursor: pointer;
  touch-action: none;
}

#scrub::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 3px;
  margin-top: -1.5px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.26);
}

#scrub-fill {
  position: absolute;
  left: 0; top: 50%;
  height: 3px;
  margin-top: -1.5px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.5);
  width: 0;
}

#scrub-pill {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translate(-50%, -50%);
  min-width: 44px;
  height: 26px;
  padding: 0 10px;
  border-radius: 13px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  display: grid;
  place-items: center;
  pointer-events: none;
  white-space: nowrap;
}

#scrub:focus-visible { outline: 2px solid #72e6ff; outline-offset: 2px; border-radius: 4px; }

/* -------------------------------------------------------------- thumbnails */

#thumbs {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 22, 0.96);
  color: #fff;
  z-index: 20;
  display: flex;
  flex-direction: column;
}
#thumbs[hidden] { display: none; }

.thumbs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 14px;
}

.thumbs-head button {
  border: 0; background: transparent; color: inherit;
  width: 34px; height: 34px; border-radius: 6px; cursor: pointer;
  display: grid; place-items: center;
}
.thumbs-head svg { width: 18px; height: 18px; fill: none; stroke: currentColor;
                   stroke-width: 1.9; stroke-linecap: round; }

#thumbs-grid {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 14px;
  padding: 16px;
}

.thumb {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.62);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.thumb img {
  display: block;
  width: 100%;
  height: auto;
  background: #2a2a2e;
  outline: 1px solid rgba(255, 255, 255, 0.14);
  outline-offset: -1px;
}

.thumb.current img { outline: 2px solid var(--accent); outline-offset: 0; }
.thumb span { display: block; padding-top: 5px; }

/* ------------------------------------------------------------ share sheet */

#share-sheet {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 30;
  display: grid;
  place-items: end center;
}
#share-sheet[hidden] { display: none; }

.sheet-inner {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 14px 14px 0 0;
  padding: 8px;
  margin-bottom: 0;
  display: grid;
  gap: 2px;
}

.sheet-inner button {
  border: 0;
  background: transparent;
  padding: 14px;
  font: inherit;
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
}
.sheet-inner button:hover { background: #f1f1f3; }
.sheet-close { color: #6b6b70; text-align: center !important; }

/* -------------------------------------------------------------- responsive */

@media (max-width: 720px) {
  :root { --bar-h: 48px; }
  .slide { padding: 6px; }
  .bar-left { display: none; }
  #bar { grid-template-columns: minmax(0, 1fr) auto; }
  .nav { display: none; }
  #thumbs-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; }
}

@media (max-width: 380px) {
  #scrub-pill { min-width: 38px; font-size: 11px; }
}
