/* Darkroom: near-black, film base browns, one safelight red. */
:root {
  color-scheme: dark;
  --ink: #0c0b0a;
  --base: #1c1915;
  --line: #2f2a25;
  --text: #ebe4d9;
  --muted: #8c8379;
  --safe: #ff4530;
  --glow: rgba(255, 69, 48, 0.35);
  --mono: ui-monospace, "SF Mono", Menlo, "Roboto Mono", monospace;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--ink);
  color: var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}

/* Film grain over everything. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---- Header ---- */

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

h1 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font: 600 0.95rem/1 var(--mono);
  letter-spacing: 0.32em;
  text-transform: uppercase;
}

.mark {
  width: 3px;
  height: 18px;
  background: var(--safe);
  box-shadow: 0 0 10px var(--glow);
}

.timecode {
  margin-left: auto;
  font: 0.8rem/1 var(--mono);
  letter-spacing: 0.08em;
  color: var(--safe);
  text-shadow: 0 0 8px var(--glow);
  font-variant-numeric: tabular-nums;
}
.timecode.idle { color: #4a423b; text-shadow: none; }

/* ---- Layout and text ---- */

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 16px calc(100px + env(safe-area-inset-bottom));
}

.label, .readout {
  font: 0.72rem/1 var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.readout { width: 3.2em; text-align: right; color: var(--text); letter-spacing: 0.04em; }

.hint { color: var(--muted); font-size: 0.85rem; margin: 10px 0; }

.info {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  font: 0.75rem/1.7 var(--mono);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* ---- Film strip frame with sprocket holes ---- */

.film {
  --hole: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='12'%3E%3Crect x='5' y='3' width='8' height='6' rx='1.5' fill='%230c0b0a'/%3E%3C/svg%3E");
  position: relative;
  padding: 16px 0;
  background: var(--base);
  border-radius: 3px;
}
.film::before, .film::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 12px;
  background: var(--hole) repeat-x 3px 0;
}
.film::before { top: 2px; }
.film::after { bottom: 2px; }

.pick { text-align: center; padding-top: 6vh; }
.film.empty .frames {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 8px;
  padding: 0 8px;
}
.film.empty .frames span {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 6px;
  aspect-ratio: 4 / 3;
  background: #12100e;
  border: 1px solid #2a2520;
  font: 0.6rem/1.3 var(--mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #5a5048;
}
.lede { font-size: 1.1rem; margin: 32px auto 28px; max-width: 24em; }
.pick .hint { max-width: 26em; margin: 22px auto; }

/* ---- Buttons and inputs ---- */

button, .button, select {
  font: 600 0.8rem/1 var(--mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px 18px;
  min-height: 48px;
  cursor: pointer;
}
button:active, .button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; }

.primary {
  background: var(--safe);
  border-color: var(--safe);
  color: #160604;
  box-shadow: 0 0 28px var(--glow);
}
.big { display: inline-block; padding: 18px 34px; font-size: 0.9rem; }
.quiet { min-height: 34px; padding: 8px 12px; font-size: 0.68rem; color: var(--muted); }
.button input { display: none; }

select {
  appearance: none;
  -webkit-appearance: none;
  text-align: left;
  font-weight: 400;
  letter-spacing: 0.08em;
  padding-right: 36px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238c8379' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 14px center;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 36px;
  background: transparent;
}
input[type="range"]:focus { outline: none; }
input[type="range"]:focus-visible { outline: 1px dashed var(--muted); outline-offset: 2px; }
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--line); }
input[type="range"]::-moz-range-track { height: 2px; background: var(--line); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 4px;
  height: 26px;
  margin-top: -12px;
  border-radius: 1px;
  background: var(--text);
}
input[type="range"]::-moz-range-thumb { width: 4px; height: 26px; border: 0; border-radius: 1px; background: var(--text); }
/* The slit slider's thumb is the slit itself. */
#position::-webkit-slider-thumb { background: var(--safe); box-shadow: 0 0 10px var(--glow); }
#position::-moz-range-thumb { background: var(--safe); box-shadow: 0 0 10px var(--glow); }

/* ---- Setup ---- */

.stage {
  position: relative;
  margin: 0 auto;
  background: #000;
  overflow: hidden;
  touch-action: none;
  max-width: 100%;
}
.stage video { display: block; width: 100%; height: 100%; }

.slit {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--safe);
  box-shadow: 0 0 12px 1px var(--glow);
  pointer-events: none;
}

.row { display: flex; align-items: center; gap: 14px; margin-top: 10px; }
.row .label { width: 5.5em; flex: none; }

.options { border: 0; padding: 0; margin: 14px 0 0; display: grid; gap: 10px; }
.field { display: flex; align-items: center; gap: 14px; }
.field .label { width: 5.5em; flex: none; }
.field select { flex: 1; }

.segmented { display: flex; flex: 1; gap: 6px; }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 12px 6px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  font: 0.72rem/1 var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}
.segmented input:checked + span {
  color: var(--safe);
  border-color: var(--safe);
  background: rgba(255, 69, 48, 0.08);
  text-shadow: 0 0 8px var(--glow);
}
.segmented input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 2px; }
.segmented.wide { margin-top: 14px; }

/* ---- Result ---- */

.output {
  overflow: auto;
  background: #000;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.output::-webkit-scrollbar { display: none; }
.output canvas { display: block; }
.output.fit canvas { width: 100%; height: auto; }
.output.full canvas { max-height: 45dvh; width: auto; }
.output.full.clock canvas { max-height: none; }

.progress {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
  font: 0.75rem/1 var(--mono);
  letter-spacing: 0.06em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.bar { flex: 1; height: 2px; background: var(--line); }
.bar div { height: 100%; width: 0; background: var(--safe); box-shadow: 0 0 10px var(--glow); }

/* ---- Bottom actions ---- */

.actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--ink) 35%);
}
.actions button { flex: 1; max-width: 340px; }
