:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --text: #1d1b18;
  --muted: #6d675e;
  --line: #e0dbd2;
  --accent: #b5521b;
  --star: #d99a00;
  --film: #1f1c19;
  --film-text: #e9c98a;
  --sprocket: #f6f4f0;
  --grease: #e4572e;
  --tape: #ede3c8;
  --radius: 8px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --surface: #1e1c19;
    --text: #ece8e1;
    --muted: #9b958b;
    --line: #34302b;
    --accent: #e07a3c;
    --star: #f2b72f;
    --film: #0a0908;
    --sprocket: #2a2723;
    --tape: #d6caa9;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
img { display: block; max-width: 100%; }
h1 { font-size: 1.5rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }
.muted { color: var(--muted); }
.error { color: #c0392b; }

button, .button {
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: default; }
button.link { border: 0; background: none; padding: 0 8px; color: var(--muted); }

input, textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 16px;
  min-height: 52px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; text-decoration: none; }
.topbar nav { display: flex; align-items: center; }
.topbar nav a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  color: var(--muted);
  text-decoration: none;
}
.topbar form { margin: 0; }

main { padding: 16px; max-width: 1200px; margin: 0 auto; }

.roll-grid, .frame-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.roll-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.frame-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }

.roll-card {
  display: block;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.roll-card img { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; background: var(--line); }
.roll-info { display: flex; flex-direction: column; padding: 8px 10px; font-size: 0.9rem; }

.frame-cell { position: relative; }
.frame-cell img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: 4px;
  background: var(--line);
}
.frame-no {
  position: absolute;
  left: 4px;
  bottom: 4px;
  padding: 0 4px;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 3px;
}
.frame-cell .star { position: absolute; top: 0; right: 0; }
.empty { grid-column: 1 / -1; }

/* Sleeve view: strips of 6 frames (3 on a phone), each frame whole. */
.sleeve {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  row-gap: 14px;
}
@media (max-width: 600px) {
  .sleeve { grid-template-columns: repeat(3, 1fr); row-gap: 10px; }
}
.sleeve-frame {
  position: relative;
  padding: 15px 4px 30px;
  background:
    repeating-linear-gradient(90deg, var(--sprocket) 0 5px, transparent 5px 13px) left 4px top 4px / calc(100% - 4px) 6px no-repeat,
    repeating-linear-gradient(90deg, var(--sprocket) 0 5px, transparent 5px 13px) left 4px bottom 4px / calc(100% - 4px) 6px no-repeat,
    var(--film);
}
.sleeve-frame a { position: relative; display: block; aspect-ratio: 3 / 2; }
.sleeve-frame img { width: 100%; height: 100%; object-fit: contain; }
.edge-no {
  position: absolute;
  left: 6px;
  bottom: 12px;
  font: 600 0.7rem/1 ui-monospace, Menlo, monospace;
  letter-spacing: 0.04em;
  color: var(--film-text);
}
.grease {
  position: absolute;
  inset: -7% -5%;
  width: 110%;
  height: 114%;
  overflow: visible;
  pointer-events: none;
}
.grease path {
  fill: none;
  stroke: var(--grease);
  stroke-width: 3.5px;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  opacity: 0.9;
}
.sleeve-frame .star { position: absolute; right: 0; bottom: 0; font-size: 1.15rem; color: var(--film-text); text-shadow: none; opacity: 0.55; }
.sleeve-frame .star.on { color: var(--star); opacity: 1; }
.sleeve .empty { padding: 8px 0; }

.star {
  border: 0;
  background: none;
  padding: 0;
  font-size: 1.4rem;
  color: #fff;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
}
.star.on { color: var(--star); }

.roll-head p { margin: 0 0 0.5rem; color: var(--muted); }
.lab {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 0 0 1rem;
  font-size: 0.85rem;
}
.lab dt { color: var(--muted); }
.lab dd { margin: 0; font-variant-numeric: tabular-nums; }
.grid-bar { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }
.toggle input { width: 20px; min-height: 20px; }

/* Canister label: the roll's details as a strip of tape, each part editable in place. */
.tape {
  display: inline-block;
  max-width: 100%;
  margin: 0 0 0.6rem;
  padding: 0 14px;
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.2;
  color: #2a2620;
  background: var(--tape);
  transform: rotate(-0.4deg);
  clip-path: polygon(0 4%, 2% 0, 98% 3%, 100% 0, 99% 50%, 100% 100%, 97% 96%, 3% 100%, 0 97%, 1% 50%);
}
.tape .dot { color: rgba(42, 38, 32, 0.45); }
.part-text {
  min-height: 44px;
  min-width: 0;
  padding: 0 2px;
  border: 0;
  border-radius: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  gap: 0.3em;
}
.part-text.blank { opacity: 0.45; font-style: italic; font-weight: 400; }
.part-text.fallback { opacity: 0.6; font-weight: 400; }
.part-note { font-size: 0.75em; }
.part-input {
  width: auto;
  min-height: 44px;
  padding: 0 2px;
  border: 0;
  border-bottom: 2px dashed currentColor;
  border-radius: 0;
  background: none;
  color: inherit;
  font: inherit;
}
.part-input:focus { outline: none; }
.meta { color: var(--muted); }
.meta .part-text { min-height: 36px; }
.caption { margin-bottom: 0.75rem; }
.caption .part-text { white-space: pre-wrap; color: var(--text); min-height: 36px; }
.caption .part-text.blank { color: var(--muted); }
.caption .part-notes { display: block; }
.caption .part-input { width: 100%; max-width: 60ch; padding: 6px 2px; resize: vertical; }
.save-status { font-size: 0.85rem; }

/* Loupe: the frame fills the screen; the bars fade, and a tap brings them back. */
body.loupe-open { overflow: hidden; }
.loupe {
  position: fixed;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  background: #000;
  color: #f2efe9;
}
.loupe-stage {
  position: absolute;
  inset: 0;
  touch-action: none;
  cursor: zoom-in;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.loupe.zoomed .loupe-stage { cursor: grab; }
.loupe-stage img { width: 100%; height: 100%; max-width: none; object-fit: contain; will-change: transform; }
.loupe-stage img.animate { transition: transform 0.22s ease-out; }
.chrome { transition: opacity 0.3s; }
.loupe.idle .chrome { opacity: 0; pointer-events: none; }
.loupe-top, .loupe-bottom {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
}
.loupe-top {
  top: 0;
  align-items: center;
  padding-top: max(8px, env(safe-area-inset-top));
  background: linear-gradient(rgba(0, 0, 0, 0.7), transparent);
}
.loupe-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.frame-label { font-variant-numeric: tabular-nums; }
.loupe .muted { color: rgba(242, 239, 233, 0.6); }
.canister { font-size: 0.8rem; opacity: 0.75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loupe-bottom {
  bottom: 0;
  flex-direction: column;
  align-items: center;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}
.loupe .button, .loupe .nav {
  background: rgba(0, 0, 0, 0.35);
  color: inherit;
  border-color: rgba(255, 255, 255, 0.25);
}
.loupe .star { color: inherit; text-shadow: none; }
.loupe .star.on { color: var(--star); }
.nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 1.6rem; }
.nav.prev { left: 12px; }
.nav.next { right: 12px; }
.nav:disabled { visibility: hidden; }
@media (pointer: coarse) { .nav { display: none; } }

/* Filmstrip: the thumb under the center is the frame shown. */
.strip {
  align-self: stretch;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 4px calc(50% - 22px);
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior: contain;
  touch-action: pan-x;
}
.strip::-webkit-scrollbar { display: none; }
.strip-frame {
  position: relative;
  flex: 0 0 44px;
  height: 44px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 3px;
  background: #222;
  opacity: 0.55;
  scroll-snap-align: center;
}
.strip-frame img { width: 100%; height: 100%; object-fit: cover; border-radius: 1px; }
.strip-frame.current { border-color: #fff; opacity: 1; }
.strip-frame.kept::after {
  content: '★';
  position: absolute;
  top: -4px;
  right: 0;
  font-size: 0.75rem;
  color: var(--star);
  text-shadow: 0 0 2px #000, 0 0 2px #000;
}

/* Swipe-up star feedback, shown even while the bars are hidden. */
.loupe-flash {
  position: absolute;
  left: 50%;
  top: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 22px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.55);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.loupe-flash .glyph { font-size: 3.5rem; line-height: 1; }
.loupe-flash.on .glyph { color: var(--star); }
.loupe-flash.show { animation: flash 0.9s ease-out; }
@keyframes flash {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  35% { transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%); }
}
@media (prefers-reduced-motion: reduce) {
  .loupe-stage img.animate { transition: none; }
}

.fav-roll h2 a { text-decoration: none; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  z-index: 3;
}

body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.login-form label { font-size: 0.85rem; color: var(--muted); }
