:root {
  --paper: #f0f5f5;
  --ink: #121212;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  /* translucent control chrome */
  --glass: rgba(0, 0, 0, 0.34);
  --glass-ink: rgba(255, 255, 255, 0.9);
  --hair: rgba(255, 255, 255, 0.35);
  --ring: rgba(255, 255, 255, 0.55);

  --safe-b: env(safe-area-inset-bottom, 0px);

  /* time slider geometry — the knob position is derived from these, keep them in sync with the thumb */
  --track-w: 132px;
  --track-h: 26px;
  --track-pad: 8px; /* thumb centre travels 18px … width − 18px */
  --thumb: 20px;
  --knob: 22px;
  --line-inset: 8px; /* hairline stops this far from the pill ends */
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  /* single-finger drags belong to the blind (peek, cord, wand) and the photo; pinch zoom stays available */
  touch-action: pinch-zoom;
  /* a drag across the page peeks through the slats; it must not start a text selection or iOS callout */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* the blind's cursor (set by blinds.js) wins over the page's own, but not over the controls */
html[data-cursor="grab"],
html[data-cursor="grab"] :not(.control, #close) {
  cursor: grab !important;
}

html[data-cursor="grabbing"],
html[data-cursor="grabbing"] :not(.control, #close) {
  cursor: grabbing !important;
}

html[data-cursor="ns-resize"],
html[data-cursor="ns-resize"] :not(.control, #close) {
  cursor: ns-resize !important;
}

/* ---------- fixed layers (bottom → top): camera, page, photo, blind, controls ---------- */

#camera,
#page,
#blind {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
}

#camera {
  z-index: 0;
  display: none;
  object-fit: cover;
  transform: scaleX(-1); /* mirror, like a real mirror */
  background: #000;
}

#page {
  z-index: 0;
  overflow: visible;
  fill: var(--ink);
  font-family: var(--mono);
}

#page a,
#page a:visited {
  fill: var(--ink);
  color: var(--ink);
}

#photo {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1;
  display: block;
  max-width: none;
  object-fit: cover;
  border-radius: 3px;
  box-shadow:
    0 0.5px 1px rgba(0, 0, 0, 0.16),
    0 2px 4px rgba(0, 0, 0, 0.1),
    0 8px 16px rgba(0, 0, 0, 0.1),
    0 22px 40px rgba(0, 0, 0, 0.12);
  cursor: grab;
  touch-action: none;
  -webkit-user-drag: none;
}

#photo:active {
  cursor: grabbing;
}

#blind {
  z-index: 2;
  pointer-events: none;
}

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

.control,
#close {
  position: fixed;
  z-index: 3;
  box-sizing: border-box;
  margin: 0;
}

#clock {
  left: 50%;
  bottom: calc(48px + var(--safe-b));
  transform: translateX(-50%);
  height: 18px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--glass);
  color: var(--glass-ink);
  font: 500 11px/14px var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

#time {
  /* knob centre along the track: thumb/2 … track - thumb/2, as the native thumb travels */
  --c: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--p, 0.5));
  --edge: calc(var(--line-inset) - var(--track-pad));
  --line: linear-gradient(
      to right,
      transparent var(--edge),
      var(--hair) var(--edge),
      var(--hair) calc(var(--c) - var(--gap, 11.2px)),
      transparent 0,
      transparent calc(var(--c) + var(--gap, 11.2px)),
      var(--hair) 0,
      var(--hair) calc(100% - var(--edge)),
      transparent 0
    )
    0 calc(50% + 0.5px) / 100% 1px no-repeat; /* 1px line just below the centre: 13px down a 26px pill */

  -webkit-appearance: none;
  appearance: none;
  left: calc(50% - var(--track-w) / 2);
  bottom: calc(16px + var(--safe-b));
  width: var(--track-w);
  height: var(--track-h);
  padding: 0 var(--track-pad);
  border: 0;
  border-radius: 999px;
  background: var(--glass);
  outline: none;
  cursor: pointer;
}

/* no hover tint; keyboard focus hugs the pill. #close keeps the browser's own ring */
#time:focus-visible,
#sound:focus-visible {
  outline: 1px solid transparent; /* shows up in forced-colors mode */
  box-shadow: 0 0 0 1.5px var(--ring); /* a 1.5px outline would be snapped to 1px */
}

#time::-webkit-slider-runnable-track {
  height: 100%;
  border: 0;
  background: var(--line);
}

#time::-moz-range-track {
  height: 100%;
  border: 0;
  background: var(--line);
}

#time::-moz-range-progress {
  background: transparent;
}

#time::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: calc((var(--track-h) - var(--thumb)) / 2);
  border: 0;
  background: transparent;
  opacity: 0;
}

#time::-moz-range-thumb {
  width: var(--thumb);
  height: var(--thumb);
  border: 0;
  background: transparent;
  opacity: 0;
}

#knob {
  left: calc(
    50% - var(--track-w) / 2 + var(--track-pad) + var(--thumb) / 2 - var(--knob) / 2 +
      (var(--track-w) - 2 * var(--track-pad) - var(--thumb)) * var(--p, 0.5)
  );
  bottom: calc(16px + (var(--track-h) - var(--knob)) / 2 + var(--safe-b));
  width: var(--knob);
  height: var(--knob);
  overflow: visible;
  pointer-events: none;
}

#sound,
#close {
  bottom: calc(16px + var(--safe-b));
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: var(--glass);
  color: var(--glass-ink);
  cursor: pointer;
}

#sound {
  left: calc(50% + 74px);
  padding: 0;
  width: 26px;
  display: grid;
  place-items: center;
}

#sound svg {
  width: 26px;
  height: 26px;
}

#sound .cross,
#sound.off .waves {
  display: none;
}

#sound.off .cross {
  display: inline;
}

#close {
  left: 50%;
  bottom: calc(34px + var(--safe-b));
  transform: translateX(-50%);
  height: 40px;
  padding: 0 20px;
  color: rgba(255, 255, 255, 0.82);
  font: 500 13px/40px ui-rounded, system-ui, -apple-system, sans-serif;
  white-space: nowrap;
}

/* ---------- veil (until the blind's first frame) & camera mode: both switch at once ---------- */

body.veiled :is(#page, #photo, .control),
body.camera :is(#page, #photo, .control),
body:not(.camera) #close {
  opacity: 0;
  visibility: hidden;
}

body.camera #camera {
  display: block;
}
