:root {
  --paper: #fff;
  --ink: #111;
  --ash: #8a8a86;
  --text: "Instrument Sans", system-ui, sans-serif;
  --gutter: clamp(16px, 3vw, 40px);
  --ease: cubic-bezier(.22, .8, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--paper); color-scheme: light; }
html.lenis, html.lenis body { height: auto; }
.lenis.lenis-smooth { scroll-behavior: auto !important; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.55 var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
:focus-visible { outline: 1px solid var(--ink); outline-offset: 4px; }

/* ---------- Navbar ---------- */
:root { --serif: "Times New Roman", Times, Georgia, serif; --nav-h: 88px; }
.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 22; height: var(--nav-h);
  display: flex; align-items: baseline; gap: 34px;
  padding: 26px 18px 0;
  background: var(--paper); font-family: var(--serif); color: #000;
}
.nav-name { font-size: 34px; font-weight: 700; letter-spacing: .01em; line-height: 1; white-space: nowrap; }
.nav-links { display: flex; gap: 26px; font-size: 19px; }
.nav-links a, .nav-name { transition: opacity .3s var(--ease); }
.nav-links a { position: relative; }
.nav-links a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -3px; height: 1px; background: currentColor;
  transform: scaleX(0); transform-origin: left; transition: transform .5s var(--ease);
}
.nav-links a:hover::after, .nav-links a.is-active::after { transform: scaleX(1); }
.nav-name:hover { opacity: .6; }
.edit-toggle {
  margin-left: auto; font-family: var(--serif); font-size: 16px; color: var(--ash);
  transition: color .3s var(--ease);
}
.edit-toggle:hover { color: #000; }

.page-text {
  min-height: 100vh; padding: calc(var(--nav-h) + 9vh) 18px 20vh;
  font-family: var(--serif); font-size: clamp(20px, 2vw, 28px); line-height: 1.45; max-width: 38ch;
  opacity: 0; transform: translateY(10px);
  transition: opacity .7s var(--ease), transform .7s var(--ease);
}
.page-text.is-shown { opacity: 1; transform: none; }
.page-text p { margin: 0 0 .6em; }
.page-text a { border-bottom: 1px solid currentColor; }
.page-text a:hover { opacity: .6; }
.is-text-view .colorbar { opacity: 0; pointer-events: none; }
.colorbar { transition: opacity .45s var(--ease); }

/* ---------- Sequence ---------- */
html { scrollbar-width: none; }
html::-webkit-scrollbar { display: none; }
.sequence {
  position: relative; box-sizing: content-box;
  padding: calc(var(--nav-h) + 3vw) 0 140px 0;   /* photos run to the edges, like a contact sheet */
  transition: opacity .45s var(--ease);
}
.is-text-view .sequence { opacity: 0; }
.frame {
  margin: 0;
  position: absolute; overflow: hidden;
  will-change: transform;
  cursor: zoom-in;
  opacity: 0;
  transition: opacity .6s var(--ease);
}
.frame.is-in { opacity: 1; }
.frame.is-leaving { opacity: 0 !important; transition: opacity .45s var(--ease); pointer-events: none; }
.frame video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.frame.is-full img { object-fit: cover; }
.frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* ---------- Color bar ---------- */
.colorbar {
  position: fixed; right: 0; top: 12vh; bottom: 12vh; z-index: 20;
  width: 44px; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.colorbar.is-dragging { cursor: grabbing; }
.colorbar-rail {
  position: absolute; right: 11px; top: 0; bottom: 0; width: 2px; border-radius: 2px;
  background: #d6d6d2;
  transition: width .3s var(--ease), right .3s var(--ease);
}
.colorbar:hover .colorbar-rail, .colorbar.is-dragging .colorbar-rail, .colorbar:focus-visible .colorbar-rail { background: #b9b9b4; }
.colorbar-knob {
  position: absolute; right: 6px; width: 12px; height: 34px; margin-top: -17px;
  border-radius: 12px; background: #111;
  box-shadow: 0 0 0 3px var(--paper);
  transition: transform .4s var(--ease), box-shadow .4s var(--ease);
}
.colorbar:hover .colorbar-knob { transform: scaleX(1.15); }
.colorbar.is-dragging .colorbar-knob { transform: scale(1.2); box-shadow: 0 0 0 3px var(--paper), 0 6px 18px rgba(0,0,0,.25); }

/* while the slider is held, photos and films lift off the page */
.frame { transition: opacity .6s var(--ease), box-shadow .9s var(--ease); }
.is-lifting .frame { box-shadow: 0 44px 80px -34px rgba(0,0,0,.55), 0 12px 24px -16px rgba(0,0,0,.25); }
.colorbar:focus-visible { outline: none; }
.colorbar:focus-visible .colorbar-knob { box-shadow: 0 0 0 2px var(--ink); }

/* ---------- Editor ---------- */
.editor[hidden], .ed-saveas-form[hidden] { display: none !important; }
.is-editing .edit-toggle { display: none; }

.editor {
  --panel: 340px;
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 25;
  width: var(--panel); overflow-y: auto; overscroll-behavior: contain;
  background: var(--paper); border-left: 1px solid #e6e6e2;
  padding: 24px 20px 40px; font-size: 13px;
  animation: ed-in .5s var(--ease);
}
@keyframes ed-in { from { transform: translateX(24px); opacity: 0; } }
.is-editing .sequence { padding-right: 340px; }
.is-editing .nav { right: 340px; }
.is-editing .colorbar { display: none; }
.ed-top {
  position: sticky; top: -24px; z-index: 10; margin: -24px -20px 0; padding: 24px 20px 12px;
  background: var(--paper); border-bottom: 1px solid #eeeeea;
}
.ed-top + .ed-sec { border-top: 0; }
.ed-handle { display: none; }
.ed-head { display: flex; justify-content: space-between; align-items: baseline; }
.ed-head h2 { margin: 0; font-size: 15px; font-weight: 500; }
.ed-close { color: var(--ash); }
.ed-history { display: flex; gap: 4px; align-items: center; }
.editor .ed-undo, .editor .ed-redo { padding: 4px 10px !important; font-size: 12px; }
.ed-saveas-form { margin-top: 12px; }
.ed-saveas-form label { display: block; color: var(--ash); margin-bottom: 6px; }
.ed-saveas-form input {
  flex: 1; min-width: 0; font: inherit; padding: 6px 12px; border-radius: 999px;
  border: 0; box-shadow: inset 0 0 0 1px #dcdcd8; outline: none;
}
.ed-saveas-form input:focus { box-shadow: inset 0 0 0 1px var(--ink); }
.ed-saveas-form .ed-row { margin-top: 0; flex-wrap: nowrap; }
.ed-layouts li { gap: 8px; }
.ed-layouts strong { font-weight: 500; display: block; }
.ed-layouts .ed-row { margin-top: 0; flex-wrap: nowrap; }
.ed-status { color: var(--ash); margin: 8px 0 14px; min-height: 1.5em; }
.ed-status.is-strong { color: var(--ink); }
.ed-actions, .ed-row, .ed-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.ed-row { margin-top: 8px; }
.editor button:not(.ed-close):not([data-add]):not([data-pick]):not(.ed-map-item):not(.ed-handle) {
  padding: 6px 12px; border-radius: 999px; box-shadow: inset 0 0 0 1px #dcdcd8;
  transition: background .2s, color .2s, box-shadow .2s;
}
.editor button:not(.ed-close):not([data-add]):not([data-pick]):not(.ed-map-item):not(.ed-handle):hover:not(:disabled) { box-shadow: inset 0 0 0 1px var(--ink); }
.editor button:disabled { opacity: .35; cursor: default; }
.editor .ed-primary, .editor button[aria-pressed="true"] { background: var(--ink); color: var(--paper); box-shadow: inset 0 0 0 1px var(--ink) !important; }
.ed-sec { border-top: 1px solid #eeeeea; margin-top: 20px; padding-top: 16px; }
.ed-sec h3 { margin: 0 0 10px; font-size: 13px; font-weight: 500; }
.ed-sec h3 span { color: var(--ash); font-weight: 400; }
.ed-note { color: var(--ash); margin: 0 0 10px; }
.ed-sel-img { width: 100%; max-height: 220px; object-fit: contain; background: #f4f4f2; margin-bottom: 10px; }
.ed-thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ed-thumbs button { aspect-ratio: 1; overflow: hidden; background: #f2f2f0; }
.ed-thumbs img { width: 100%; height: 100%; object-fit: cover; transition: transform .4s var(--ease); }
.ed-thumbs button:hover img { transform: scale(1.06); }
.ed-thumbs .is-showing { opacity: .5; }
.ed-replace-list { margin-top: 4px; max-height: 260px; overflow-y: auto; }
.ed-versions { list-style: none; margin: 0; padding: 0; }
.ed-versions li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid #f0f0ec; }
.ed-versions em { font-style: normal; color: var(--ash); margin-left: 6px; }

.is-editing .frame { cursor: grab; }
.frame.is-selected { outline: 3px solid var(--ink); outline-offset: 3px; z-index: 2; }
.frame.is-lifted { opacity: .25 !important; }
.frame.is-drop-before { box-shadow: -6px 0 0 0 var(--ink); }
.frame.is-drop-after { box-shadow: 6px 0 0 0 var(--ink); }
.is-dragging-photo, .is-dragging-photo * { cursor: grabbing !important; user-select: none; }
.ed-ghost {
  position: fixed; left: 0; top: 0; z-index: 40; pointer-events: none;
  width: 120px; height: auto; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
@media (max-width: 760px) {
  .editor {
    --panel: 100%; width: 100%; top: auto; height: 46vh; border-left: 0; border-top: 1px solid #e6e6e2;
    border-radius: 14px 14px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.08);
    padding: 0 16px 40px; display: flex; flex-direction: column;
    transition: height .45s var(--ease);
  }
  .editor.is-expanded { height: 82vh; }
  .ed-top { top: 0; margin: 0 -16px; padding: 4px 16px 10px; }
  .ed-handle { display: block; width: 100%; height: 22px; display: grid; place-items: center; }
  .ed-handle span { width: 40px; height: 4px; border-radius: 4px; background: #d6d6d2; }
  /* the selected photo's controls come first */
  .editor > .ed-sec[data-sec="photo"] { order: 1; }
  .editor > .ed-sec:has(.ed-map) { order: 2; }
  .editor > .ed-sec { order: 3; }
  .editor > .ed-top { order: 0; }
  .editor button:not(.ed-close):not([data-add]):not([data-pick]):not(.ed-map-item):not(.ed-handle):not(.ed-handle) { padding: 9px 14px; }
  .ed-saveas-form input { font-size: 16px; padding: 9px 14px; }   /* no zoom-in on iPhone */
  .ed-thumbs { grid-template-columns: repeat(5, 1fr); }
  .is-editing .sequence { padding-bottom: 50vh; }
  .is-editing .sequence { padding-right: 0; padding-bottom: 60vh; }
  .is-editing .nav { right: 0; }
  .ed-map { max-height: 200px; }
}

.ed-upload span {
  display: inline-block; padding: 8px 16px; border-radius: 999px; cursor: pointer;
  background: var(--ink); color: var(--paper); font-weight: 500;
}
.ed-upload:focus-within span { outline: 1px solid var(--ink); outline-offset: 3px; }
.is-dropping::after {
  content: "Drop to upload"; position: fixed; inset: 12px; z-index: 50; pointer-events: none;
  display: grid; place-items: center; font-size: 15px; font-weight: 500; color: var(--ink);
  border: 2px dashed var(--ink); border-radius: 12px; background: rgba(255,255,255,.75);
}

/* on-photo controls, only while editing */
.ed-ov { display: none; }
.is-editing .ed-ov { display: block; position: absolute; inset: 0; pointer-events: none; }
.ed-ov button { pointer-events: auto; font: 500 11px/1 var(--text); color: var(--ink); }
.ed-x {
  position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: 15px !important;
  background: rgba(255,255,255,.92); box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.ed-x:hover { background: var(--ink); color: var(--paper) !important; }
.ed-tools {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px);
  display: flex; flex-wrap: nowrap; align-items: center; gap: 0; padding: 2px; overflow: hidden;
  border-radius: 999px; background: rgba(255,255,255,.92); box-shadow: 0 1px 4px rgba(0,0,0,.15);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.ed-tools button { flex: none; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; }
.ed-tools button:hover { background: #ececea; }
.ed-tools button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.ed-sep { flex: none; width: 1px; height: 12px; background: #dcdcd8; margin: 0 2px; }
.ed-x, .ed-tools { opacity: 0; transform: translateY(4px); transition: opacity .25s var(--ease), transform .25s var(--ease); }
.frame:hover .ed-x, .frame:hover .ed-tools, .frame.is-selected .ed-x, .frame.is-selected .ed-tools,
.frame:focus-within .ed-x, .frame:focus-within .ed-tools { opacity: 1; transform: none; }
/* touch screens: controls on the selected photo, with bigger targets */
@media (hover: none) {
  .is-editing .frame .ed-x { opacity: 1; transform: none; width: 32px; height: 32px; font-size: 18px !important; }
  .ed-tools { overflow-x: auto; scrollbar-width: none; right: 8px; max-width: none; padding: 3px; }
  .ed-tools::-webkit-scrollbar { display: none; }
  .ed-tools button { height: 30px; min-width: 32px; padding: 0 10px; font-size: 12px; }
  .frame:not(.is-selected) .ed-tools { opacity: 0; pointer-events: none; }
}

/* several photos selected */
.frame.is-picked { outline: 3px solid var(--ink); outline-offset: 3px; z-index: 2; }
.frame.is-picked::after {
  content: "✓"; position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; background: var(--ink); color: var(--paper);
}
.ed-link { font: inherit; font-weight: 400; color: var(--ash); margin-left: 8px; text-decoration: underline; padding: 0 !important; box-shadow: none !important; }

/* crop tool */
.cropper[hidden] { display: none; }
.cropper {
  position: fixed; inset: 0; z-index: 60; background: rgba(255,255,255,.97);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  font-size: 13px; animation: dlg .35s var(--ease);
}
.cr-stage { position: relative; overflow: hidden; touch-action: none; user-select: none; }
.cr-img { width: 100%; height: 100%; display: block; pointer-events: none; }
.cr-box {
  position: absolute; cursor: move;
  box-shadow: 0 0 0 9999px rgba(255,255,255,.72), inset 0 0 0 1px #fff, 0 0 0 1px rgba(0,0,0,.6);
  background:
    linear-gradient(to right, transparent 33.2%, rgba(255,255,255,.6) 33.3%, rgba(255,255,255,.6) 33.5%, transparent 33.6%, transparent 66.5%, rgba(255,255,255,.6) 66.6%, rgba(255,255,255,.6) 66.8%, transparent 66.9%),
    linear-gradient(to bottom, transparent 33.2%, rgba(255,255,255,.6) 33.3%, rgba(255,255,255,.6) 33.5%, transparent 33.6%, transparent 66.5%, rgba(255,255,255,.6) 66.6%, rgba(255,255,255,.6) 66.8%, transparent 66.9%);
}
.cr-box i { position: absolute; width: 18px; height: 18px; border: 3px solid var(--ink); background: transparent; }
.cr-box i[data-h="nw"] { left: -3px; top: -3px; border-right: 0; border-bottom: 0; cursor: nwse-resize; }
.cr-box i[data-h="ne"] { right: -3px; top: -3px; border-left: 0; border-bottom: 0; cursor: nesw-resize; }
.cr-box i[data-h="sw"] { left: -3px; bottom: -3px; border-right: 0; border-top: 0; cursor: nesw-resize; }
.cr-box i[data-h="se"] { right: -3px; bottom: -3px; border-left: 0; border-top: 0; cursor: nwse-resize; }
.cr-box i::before { content: ""; position: absolute; inset: -14px; }   /* bigger grab area */
.cr-bar { display: flex; flex-wrap: wrap; gap: 14px 28px; align-items: center; justify-content: center; padding: 0 16px; }
.cr-ratios, .cr-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.cropper button { padding: 6px 8px; color: var(--ash); transition: color .2s; }
.cropper button:hover { color: var(--ink); }
.cropper button[aria-pressed="true"] { color: var(--ink); text-decoration: underline; text-underline-offset: 5px; }
.cropper .cr-apply { background: var(--ink); color: var(--paper); border-radius: 999px; padding: 7px 18px; margin-left: 6px; }
.cr-ratios { gap: 2px; }
.cr-box i { width: 16px; height: 16px; border-width: 2px; }

/* mini preview */
.ed-map { position: relative; max-height: 300px; overflow-y: auto; overscroll-behavior: contain; background: #f6f6f4; border-radius: 6px; cursor: pointer; }
.ed-map-inner { position: relative; margin: 0 auto; }
.ed-map-item { position: absolute; padding: 0; overflow: hidden; }
.ed-map-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ed-map-item:hover { outline: 1px solid var(--ink); z-index: 1; }
.ed-map-item.is-selected { outline: 2px solid var(--ink); z-index: 2; }
.ed-map-view {
  position: absolute; left: 0; right: 0; top: 0; pointer-events: none; z-index: 3;
  box-shadow: inset 0 0 0 2px var(--ink); border-radius: 2px; background: rgba(255,255,255,.08);
}

/* ---------- Viewer ---------- */
dialog {
  outline: none;
  border: 0; padding: 0; margin: 0; max-width: none; max-height: none;
  width: 100vw; height: 100vh; height: 100dvh;
  background: var(--paper); color: var(--ink);
}
dialog::backdrop { background: var(--paper); }
dialog[open] { display: flex; flex-direction: column; align-items: center; justify-content: center; animation: dlg .6s var(--ease); }
@keyframes dlg { from { opacity: 0; } }
.viewer-close { position: absolute; top: 20px; right: var(--gutter); font-size: 13px; z-index: 2; }
.viewer-img, .viewer-video { max-width: 94vw; max-height: 84vh; object-fit: contain; transition: opacity .35s var(--ease); }
.viewer-video { background: #000; }
.viewer-stage { position: relative; display: flex; align-items: center; justify-content: center; }
.viewer-stage.is-cropped { overflow: hidden; }
.viewer-stage.is-cropped .viewer-img { position: absolute; max-width: none; max-height: none; }
.viewer, .viewer button { font-family: var(--serif); font-size: 15px; }
.viewer-img.is-loading { opacity: 0; }
.viewer-nav { display: flex; gap: 40px; align-items: center; margin-top: 20px; font-size: 13px; }
.viewer-count { color: var(--ash); font-variant-numeric: tabular-nums; min-width: 64px; text-align: center; }
.viewer-close:hover, .viewer-nav button:hover { opacity: .6; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  :root { --nav-h: 92px; }
  .nav { flex-wrap: wrap; align-content: flex-start; gap: 10px 20px; padding: 18px 14px 0; }
  .nav-name { font-size: 26px; flex-basis: 100%; }
  .nav-links { gap: 20px; font-size: 16px; }
  .edit-toggle { position: absolute; top: 22px; right: 14px; font-size: 14px; }
  .sequence { padding: calc(var(--nav-h) + 8px) 24px 96px 8px; }   /* room for the colour bar on the right */
  .page-text { padding: calc(var(--nav-h) + 6vh) 14px 20vh; font-size: 20px; }
  /* the bar's touch area stays inside the right margin, clear of the photos */
  .colorbar { width: 26px; top: 14vh; bottom: 14vh; }
  .colorbar-rail { right: 12px; width: 2px; }
  .colorbar-knob { right: 7px; width: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .frame { opacity: 1; transition: none; }
}
