@font-face {
  font-family: Figtree;
  src: url("assets/Figtree.ttf") format("truetype");
  font-weight: 300 900;
  font-display: swap;
}

:root {
  --bg: #161514;
  --stage: #1d1d1c;
  --ink: #eee8de;
  --ink-2: rgb(238 232 222 / 0.72);
  --ink-3: rgb(238 232 222 / 0.46);
  --line: rgb(238 232 222 / 0.1);
  --line-2: rgb(238 232 222 / 0.18);
  --safelight: #f2a33a;
  --safelight-ink: #1a1206;
  --radius: 7px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Figtree, Ubuntu, system-ui, sans-serif;
  font-weight: 435;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button,
input,
label {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
[hidden] {
  display: none !important;
}
:focus-visible {
  outline: 2px solid var(--safelight);
  outline-offset: 2px;
}

/* ---------- layout: one screen on desktop, the photo takes what is left ---------- */

.app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 340px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "top top top"
    "film stage light";
  height: 100dvh;
  gap: 0;
}
@media (min-width: 1900px) {
  .app {
    grid-template-columns: 340px minmax(0, 1fr) 380px;
  }
}
.top {
  grid-area: top;
}
.film {
  grid-area: film;
}
.stage {
  grid-area: stage;
}
.light {
  grid-area: light;
}

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

.top {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.brand {
  display: flex;
  flex-direction: column;
  flex: none;
  width: 260px;
}
.brand b {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.brand span {
  color: var(--ink-3);
  font-size: 13px;
}
.roll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  scrollbar-width: thin;
  padding: 2px;
}
.frame-thumb {
  flex: none;
  width: 62px;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  overflow: hidden;
  background: #000;
  opacity: 0.55;
  transition: opacity 0.15s;
  position: relative;
}
.frame-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.frame-thumb:hover {
  opacity: 0.9;
}
.frame-thumb[aria-pressed="true"] {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--safelight);
}
.frame-thumb.own::after {
  content: "";
  position: absolute;
  right: 4px;
  top: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--safelight);
}
.frame-thumb.broken {
  outline: 1px dashed #d46a5a;
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line-2);
  background: rgb(238 232 222 / 0.04);
  font-weight: 520;
  font-size: 14px;
  white-space: nowrap;
  transition:
    background 0.15s,
    border-color 0.15s,
    opacity 0.15s;
}
.btn:hover:not(:disabled) {
  background: rgb(238 232 222 / 0.1);
}
.btn:disabled {
  opacity: 0.38;
  cursor: default;
}
.btn.primary {
  background: var(--ink);
  color: #151412;
  border-color: var(--ink);
}
.btn.primary:hover:not(:disabled) {
  background: #fff;
}
.btn.ghost {
  cursor: pointer;
}
.btn.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--ink-2);
}
.btn.quiet:hover:not(:disabled) {
  color: var(--ink);
}
.btn.small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}
.btn.mode[aria-pressed="true"],
.ring-steps .btn[aria-pressed="true"] {
  background: var(--safelight);
  color: var(--safelight-ink);
  border-color: var(--safelight);
}
.export {
  position: relative;
  display: flex;
}
.export #export {
  border-radius: var(--radius) 0 0 var(--radius);
}
.export .more {
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0 9px;
  border-left: 1px solid #b9b2a7;
}
.export .more svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  width: 270px;
  padding: 8px;
  background: #23211f;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgb(0 0 0 / 0.45);
  display: flex;
  flex-direction: column;
}
.menu-label {
  margin: 4px 8px 2px;
  color: var(--ink-3);
  font-size: 12px;
}
.menu-row,
.menu button,
.menu a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 6px;
  border: 0;
  background: none;
  text-align: left;
  text-decoration: none;
  font-size: 14px;
}
.menu-row {
  cursor: pointer;
}
.menu button:hover,
.menu a:hover,
.menu-row:hover {
  background: rgb(238 232 222 / 0.08);
}
.menu input[type="radio"] {
  accent-color: var(--safelight);
  margin: 0;
}
.menu hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 6px 0;
  width: 100%;
}

/* ---------- side panels ---------- */

.film,
.light {
  padding: 18px 20px 20px;
  overflow-y: auto;
  scrollbar-width: thin;
  min-height: 0;
}
.film {
  border-right: 1px solid var(--line);
}
.light {
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.panel-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.panel-head p {
  margin: 2px 0 0;
  color: var(--ink-3);
  font-size: 13px;
}

/* film looks: the photo itself is the swatch */
.looks {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 12px -8px 12px;
}
.look {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 12px;
  align-items: center;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
}
.look:hover {
  background: rgb(238 232 222 / 0.06);
}
.look canvas {
  width: 84px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  background: #0d0d0c;
  display: block;
}
.look[aria-checked="true"] {
  background: rgb(242 163 58 / 0.12);
}
.look[aria-checked="true"] canvas {
  box-shadow: 0 0 0 2px var(--safelight);
}
.look-text b {
  display: block;
  font-weight: 600;
  font-size: 15px;
}
.look-text small {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--ink-3);
  font-size: 12.5px;
  line-height: 1.3;
}
.look[aria-checked="true"] .look-text b {
  color: var(--safelight);
}
.film-dials {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.texture-head,
.spot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink-2);
  font-size: 14px;
}
.switch {
  min-width: 46px;
  height: 26px;
  border-radius: 13px;
  border: 1px solid var(--line-2);
  background: transparent;
  font-size: 12px;
  color: var(--ink-3);
}
.switch[aria-checked="true"] {
  background: var(--safelight);
  color: var(--safelight-ink);
  border-color: var(--safelight);
}
.film-dials.texture-off .tape.texture {
  opacity: 0.4;
}

/* ---------- tapes ---------- */

.tape {
  --track-h: 30px;
  user-select: none;
  border-radius: 6px;
}
.tape.big {
  --track-h: 44px;
}
.tape-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.tape-name {
  color: var(--ink-2);
  font-size: 13.5px;
}
.tape-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-2);
}
.tape.moved .tape-value {
  color: var(--safelight);
}
.tape.big .tape-name {
  font-size: 15px;
  color: var(--ink);
}
.tape.big .tape-value {
  font-size: 20px;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.tape.big.moved .tape-value {
  color: var(--safelight);
}
.tape-track {
  position: relative;
  height: var(--track-h);
  overflow: hidden;
  border-radius: 6px;
  background: rgb(0 0 0 / 0.28);
  cursor: ew-resize;
  touch-action: pan-y;
  mask-image: linear-gradient(
    90deg,
    transparent,
    #000 18%,
    #000 82%,
    transparent
  );
}
.tape-ruler {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background:
    repeating-linear-gradient(
      90deg,
      rgb(238 232 222 / 0.75) 0 1.5px,
      transparent 1.5px var(--major)
    )
    0 0 / 100% 46% no-repeat,
    repeating-linear-gradient(
      90deg,
      rgb(238 232 222 / 0.32) 0 1px,
      transparent 1px var(--minor)
    )
    0 0 / 100% 26% no-repeat,
    var(--paint, transparent) 0 100% / 100% 4px no-repeat;
  transition: transform 0.06s linear;
}
.tape.dragging .tape-ruler {
  transition: none;
}
.tape-ruler::after {
  /* closes the last major tick at the range end */
  content: "";
  position: absolute;
  right: -1px;
  top: 0;
  height: 46%;
  width: 1.5px;
  background: rgb(238 232 222 / 0.75);
}
.tick-label {
  position: absolute;
  bottom: 6px;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.tape.big .tick-label {
  font-size: 12px;
  bottom: 8px;
}
.tick-label.zero {
  color: var(--ink-2);
}
.tape-needle {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--safelight);
  box-shadow: 0 0 10px rgb(242 163 58 / 0.6);
  pointer-events: none;
}
.tape:focus-visible {
  outline-offset: 4px;
}

.histogram {
  margin: 0;
  flex: 1 1 96px;
  min-height: 84px;
  max-height: 220px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.histogram canvas {
  flex: 1;
  min-height: 0;
  width: 100%;
  border-radius: 6px;
  background: rgb(0 0 0 / 0.28);
}
.histogram figcaption {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-3);
}
#clip-note.warn {
  color: var(--safelight);
}
.light-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.light-shape {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.spot-panel {
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.spot-dials {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
  align-items: end;
}
.spot-dials > .tape:first-child {
  grid-column: 1 / -1;
}
.reset {
  align-self: flex-start;
}

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

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--stage);
}
.view {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 18px 22px 0;
  display: grid;
  place-items: center;
}
.frame {
  position: relative;
  touch-action: none;
  cursor: ns-resize;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.35);
}
.frame:focus-visible {
  outline-offset: 4px;
}
.frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.before {
  opacity: 0;
  pointer-events: none;
}
.before.full,
.before.split {
  opacity: 1;
}
.before.full {
  clip-path: none !important;
}
.split-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
  pointer-events: none;
}
.split-line span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.4);
}
.split-line span::before {
  content: "‹ ›";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #151412;
  font-size: 14px;
  font-weight: 700;
}
.frame:has(.split-line:not([hidden])) {
  cursor: ew-resize;
}
.tag {
  position: absolute;
  left: 12px;
  top: 12px;
  padding: 3px 9px;
  border-radius: 20px;
  background: rgb(10 10 10 / 0.7);
  font-size: 12.5px;
  color: var(--ink);
  pointer-events: none;
}
.hud {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  padding: 8px 16px 9px;
  border-radius: 12px;
  background: rgb(12 12 11 / 0.72);
  backdrop-filter: blur(8px);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
}
.hud.show {
  opacity: 1;
  transition: opacity 0.05s;
}
.hud b {
  display: block;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.hud span {
  font-size: 12.5px;
  color: var(--ink-2);
}
.loading {
  position: absolute;
  inset: auto 0 12px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
  margin: 0;
  pointer-events: none;
}

/* the placed light: a dashed pool with a dot to move it and a handle to resize */
.spot {
  position: absolute;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1.5px dashed rgb(255 236 200 / 0.75);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.25);
  pointer-events: none;
  opacity: 0.85;
  transition: opacity 0.2s;
}
.frame.dragging .spot {
  opacity: 0.25;
}
.spot-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgb(242 163 58 / 0.9);
  box-shadow: 0 0 18px rgb(255 200 120 / 0.8);
  pointer-events: auto;
  cursor: move;
  touch-action: none;
}
.spot-size {
  position: absolute;
  right: -9px;
  top: 50%;
  width: 18px;
  height: 18px;
  margin-top: -9px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #1d1d1c;
  pointer-events: auto;
  cursor: ew-resize;
  touch-action: none;
}

/* ring-around: the middle is now, the others are one move away */
.ring {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, var(--tile-w));
  grid-auto-rows: auto;
  gap: 10px;
  justify-content: center;
  align-content: center;
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
}
.tile canvas {
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 4px;
  display: block;
  object-fit: cover;
  transition:
    transform 0.15s,
    box-shadow 0.15s;
}
.tile:hover canvas {
  transform: scale(1.015);
  box-shadow: 0 0 0 2px var(--ink);
}
.tile.now canvas {
  box-shadow: 0 0 0 2px var(--safelight);
}
.tile span {
  font-size: 13px;
  color: var(--ink-2);
  height: 22px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: var(--tile-w);
}
.tile.now span {
  color: var(--safelight);
}
.ring-steps {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  justify-content: center;
}

/* ---------- dock under the photo: undo, keep, modes ---------- */

.dock {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 12px 22px 14px;
}
.dock-group {
  display: flex;
  gap: 4px;
  align-items: center;
}
.kept-chip {
  border: 1px dashed var(--line-2);
  background: none;
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 12.5px;
  color: var(--ink-2);
  touch-action: none;
  user-select: none;
}
.kept-chip:active {
  background: rgb(238 232 222 / 0.1);
}
.note {
  flex: 1 1 320px;
  margin: 0;
  color: var(--ink-3);
  font-size: 13.5px;
  text-align: right;
  min-width: 0;
}
.note.error {
  color: #ec8b7a;
}

/* ---------- phone and narrow windows: one column, the photo first ---------- */

@media (max-width: 899px) {
  .app {
    display: flex;
    flex-direction: column;
    height: auto;
  }
  .top {
    flex-wrap: wrap;
    gap: 10px 14px;
    padding: 10px 14px;
  }
  .brand {
    width: auto;
    flex: 1;
  }
  .brand span {
    display: none;
  }
  .roll {
    order: 3;
    flex-basis: 100%;
  }
  .top-actions .btn {
    min-height: 40px;
  }
  .stage {
    order: 0;
  }
  .view {
    margin: 10px 12px 0;
    flex: none;
  }
  .light {
    order: 2;
    border: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
    padding: 16px 14px;
  }
  /* on a phone the film strip sits right under the photo, its dials at the end */
  .film {
    display: contents;
  }
  .film .panel-head {
    display: none;
  }
  .looks {
    order: 1;
    flex-direction: row;
    overflow-x: auto;
    margin: 0;
    padding: 4px 12px 10px;
    scroll-snap-type: x proximity;
    background: var(--stage);
  }
  .film-dials {
    order: 3;
    padding: 16px 14px 40px;
  }
  .brand b {
    white-space: nowrap;
  }
  .wide-only {
    display: none;
  }
  .ring {
    gap: 6px;
  }
  .look {
    grid-template-columns: 1fr;
    width: 132px;
    flex: none;
    gap: 6px;
    padding: 4px;
    scroll-snap-align: start;
  }
  .look canvas {
    width: 124px;
    height: 88px;
  }
  .look-text small {
    display: none;
  }
  .dock {
    padding: 8px 12px 4px;
    gap: 4px 8px;
  }
  .dock .btn {
    padding: 0 10px;
  }
  .note {
    flex-basis: 100%;
    text-align: left;
    order: 5;
  }
  .ring {
    position: static;
  }
  .stage:has(.ring:not([hidden])) .view {
    height: auto !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
