:root {
  --yellow: #f4c63d;
  --yellow-dark: #d39a12;
  --black: #16130f;
  --paper: #fbf1d7;
  --paper-2: #ead8a8;
  --red: #d73624;
  --green: #2f7f68;
  --ink: #252018;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.55), transparent 28rem),
    linear-gradient(135deg, #165a62 0%, #ef7d57 52%, #f4c63d 100%);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.shell {
  height: 100svh;
  display: grid;
  place-items: center;
  padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.camera {
  width: min(100%, 460px);
  height: min(780px, calc(100svh - 16px));
  display: grid;
  grid-template-rows: auto minmax(190px, 1fr) auto auto auto;
  gap: 10px;
  padding: 12px;
  border: 3px solid #231f19;
  border-radius: 20px;
  background:
    linear-gradient(90deg, transparent 0 47%, rgba(255, 255, 255, 0.12) 47% 49%, transparent 49%),
    var(--yellow);
  box-shadow: 0 18px 42px rgba(18, 13, 8, 0.42);
  overflow: hidden;
}

.top-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  color: #f8ead1;
  background: var(--black);
  border: 2px solid #000;
  border-radius: 12px;
}

.brand {
  display: grid;
  gap: 1px;
  text-transform: uppercase;
}

.brand-main {
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: 28px;
  line-height: 0.9;
  letter-spacing: 0;
}

.brand-sub,
.counter small,
.advance-copy small,
.status {
  font-size: 11px;
  letter-spacing: 0;
}

.brand-sub {
  color: #f2cd57;
}

.counter {
  min-width: 74px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  padding: 5px 7px;
  color: #2b1a0e;
  background: #efe3bd;
  border: 2px inset #7e6b48;
  border-radius: 8px;
}

.counter span {
  min-width: 34px;
  text-align: right;
  font-size: 32px;
  line-height: 1;
  font-weight: 900;
}

.counter.low {
  color: var(--red);
}

.viewfinder-wrap {
  position: relative;
  overflow: hidden;
  border: 3px solid #1b1710;
  border-radius: 14px;
  background: #15120f;
  min-height: 190px;
  isolation: isolate;
}

.viewfinder,
.photo-frame {
  width: 100%;
  height: 100%;
  min-height: 190px;
}

.viewfinder {
  display: block;
  object-fit: cover;
  filter: sepia(0.24) saturate(0.92) contrast(1.08) brightness(1.04);
  transform: scaleX(-1);
}

.viewfinder-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 42%, transparent 0 36%, rgba(16, 8, 2, 0.34) 84%),
    linear-gradient(rgba(255,255,255,0.08), transparent 12%, rgba(0,0,0,0.12));
  mix-blend-mode: multiply;
}

.photo-frame {
  position: absolute;
  inset: 0;
  z-index: 3;
  padding: 10px 10px 28px;
  background: #fff9e8;
  transform: rotate(-0.8deg);
}

.photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  filter: sepia(0.18) saturate(0.82) contrast(1.1);
}

.date-stamp {
  position: absolute;
  right: 20px;
  bottom: 35px;
  color: #ff8c1a;
  font-size: 13px;
  font-weight: 900;
  text-shadow: 0 1px 1px rgba(40, 12, 0, 0.45);
}

.permission {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: #fff4d8;
  background: radial-gradient(circle at 50% 35%, #332719, #100d0b 70%);
}

.permission h1 {
  margin: 0;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(32px, 9vw, 42px);
  line-height: 0.95;
  letter-spacing: 0;
  text-transform: uppercase;
}

.permission p {
  margin: 0;
  color: #e8d19d;
  font-size: 12px;
}

.flash {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  opacity: 0;
  background: #fff;
}

.flash.fire {
  animation: flash 360ms ease-out;
}

@keyframes flash {
  0% { opacity: 0; }
  12% { opacity: 1; }
  100% { opacity: 0; }
}

.name-card,
.caption-card {
  padding: 10px;
  border: 2px dashed rgba(30, 24, 15, 0.42);
  border-radius: 12px;
  background: rgba(255, 244, 211, 0.62);
}

label,
.advance-copy span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.name-row,
.caption-actions {
  display: flex;
  gap: 8px;
}

input {
  min-width: 0;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff8e6;
  border: 2px solid #1f1a12;
  border-radius: 8px;
  outline: none;
}

input:focus {
  box-shadow: 0 0 0 3px rgba(47, 127, 104, 0.32);
}

button {
  border: 2px solid #17120d;
  border-radius: 8px;
  color: #fff7df;
  background: #1a1712;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.name-row button,
.save {
  min-width: 76px;
  padding: 0 14px;
  font-weight: 900;
  text-transform: uppercase;
}

.advance {
  padding: 10px;
  color: #f8ead1;
  background: #231f19;
  border: 2px solid #000;
  border-radius: 14px;
}

.advance-copy {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.advance-copy span {
  margin: 0;
}

.advance-copy small {
  color: #e6c96a;
  text-align: right;
}

.track {
  position: relative;
  height: 54px;
  margin-top: 8px;
  border: 2px inset #000;
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(244,198,61,0.2), rgba(244,198,61,0.05)),
    #0e0c0a;
  overflow: hidden;
  touch-action: none;
}

.notches {
  position: absolute;
  inset: 9px 16px;
  opacity: 0.65;
  background: repeating-linear-gradient(90deg, #f2d16a 0 3px, transparent 3px 17px);
}

.thumb {
  position: absolute;
  left: 6px;
  top: 6px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  background:
    radial-gradient(circle at 50% 50%, #ffd86a 0 15%, #8a430e 16% 24%, transparent 25%),
    repeating-conic-gradient(from 8deg, #fff0a9 0deg 10deg, #d88716 10deg 23deg, #5b2c0d 23deg 31deg),
    radial-gradient(circle at 34% 28%, #fff0b6, #d88716 48%, #5b2c0d 100%);
  box-shadow: 0 4px 0 rgba(0,0,0,0.42);
  will-change: transform;
  transition: transform 140ms cubic-bezier(.2, .8, .2, 1);
}

.track.dragging .thumb {
  transition: none;
}

.thumb span {
  display: block;
  width: 15px;
  height: 15px;
  margin: auto;
  border: 3px solid rgba(35, 18, 7, 0.78);
  border-radius: 50%;
  background: rgba(255, 235, 142, 0.8);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.22);
}

.advance.armed {
  background: #193f35;
}

.controls {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 10px;
  align-items: center;
}

.shutter {
  height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #1c120b;
  background: #e5402d;
  box-shadow: 0 5px 0 #801d14;
  font-weight: 900;
  text-transform: uppercase;
}

.shutter:not(:disabled):active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #801d14;
}

.lens-dot {
  width: 16px;
  height: 16px;
  border: 2px solid #2b120d;
  border-radius: 50%;
  background: #fff0df;
}

.status {
  margin: 0;
  color: #3d2c18;
  line-height: 1.35;
}

.caption-card {
  display: grid;
  gap: 7px;
}

.caption-actions {
  justify-content: flex-end;
}

.save {
  height: 40px;
  background: var(--green);
}

.roll-loaded .name-card,
.shot-pending .advance,
.shot-pending .controls {
  display: none;
}

.finished .viewfinder-wrap {
  filter: grayscale(1);
}

@media (max-height: 740px) {
  .shell {
    padding: max(6px, env(safe-area-inset-top)) 6px max(6px, env(safe-area-inset-bottom));
  }

  .camera {
    height: calc(100svh - 12px);
    gap: 8px;
    padding: 10px;
    border-radius: 18px;
  }

  .top-strip {
    padding: 6px 8px;
  }

  .brand-main {
    font-size: 24px;
  }

  .brand-sub,
  .counter small,
  .advance-copy small,
  .status {
    font-size: 10px;
  }

  .counter span {
    font-size: 27px;
  }

  .name-card,
  .caption-card,
  .advance {
    padding: 8px;
  }

  input {
    height: 36px;
  }

  .track {
    height: 48px;
    margin-top: 6px;
  }

  .thumb {
    width: 36px;
    height: 36px;
  }

  .shutter {
    height: 50px;
  }
}

@media (max-width: 380px) {
  .camera {
    padding: 10px;
    gap: 8px;
    border-radius: 18px;
  }

  .brand-main {
    font-size: 25px;
  }

  .counter {
    min-width: 68px;
  }

  .counter span {
    font-size: 28px;
  }

  .controls {
    grid-template-columns: 104px 1fr;
  }
}

/* ============ film-advance THUMBWHEEL (spins as you drag) ============ */
.wheel {
  position: relative;
  height: 30px;
  margin-top: 8px;
  border: 2px solid #000;
  border-radius: 6px;
  background: linear-gradient(#080706, #171310 18%, #050403 88%);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  box-shadow: inset 0 7px 11px rgba(0,0,0,0.65), inset 0 -7px 11px rgba(0,0,0,0.6);
}
.wheel.dragging { cursor: grabbing; }
.wheel-serrations {
  position: absolute;
  inset: 0;
  will-change: background-position;
  background-image: repeating-linear-gradient(90deg,
    #f4d477 0 1px, #d88716 1px 4px, #7a4210 4px 7px, #341a07 7px 9px, #86490f 9px 11px);
  background-size: 11px 100%;
}
.wheel::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(rgba(255,240,180,0.30), rgba(255,220,140,0.05) 26%,
    transparent 52%, rgba(0,0,0,0.42) 78%, rgba(0,0,0,0.62));
}
.wheel.armed .wheel-serrations {
  background-image: repeating-linear-gradient(90deg,
    #9fe6c0 0 1px, #2f7f68 1px 4px, #1c5040 4px 7px, #0b241c 7px 9px, #24705a 9px 11px);
}

/* ============ party / event ============ */
.mode-row { display: flex; gap: 6px; margin-bottom: 8px; }
.mode-row button {
  flex: 1;
  height: 38px;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  background: #2b2620;
}
.mode-row button.on { background: var(--green); color: #fff7df; }

.party-panel {
  padding: 10px;
  border: 2px dashed rgba(30, 24, 15, 0.42);
  border-radius: 12px;
  background: rgba(255, 244, 211, 0.62);
  display: grid;
  gap: 8px;
}

/* the broadcasting horn + canister code label */
.canister {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  color: #f8ead1;
  background: var(--black);
  border: 2px solid #000;
  border-radius: 10px;
}
.canister .code {
  font-family: Impact, Haettenschweiler, sans-serif;
  font-size: 30px;
  letter-spacing: 4px;
  color: var(--yellow);
}
.canister small { color: #e6c96a; font-size: 10px; text-transform: uppercase; }
.waveform {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 22px;
}
.waveform i {
  width: 3px;
  height: 20%;
  background: var(--yellow);
  border-radius: 2px;
  animation: wf 900ms ease-in-out infinite;
}
.waveform.idle i { animation: none; opacity: 0.3; }
.waveform i:nth-child(2){animation-delay:.1s}.waveform i:nth-child(3){animation-delay:.2s}
.waveform i:nth-child(4){animation-delay:.3s}.waveform i:nth-child(5){animation-delay:.15s}
.waveform i:nth-child(6){animation-delay:.25s}.waveform i:nth-child(7){animation-delay:.05s}
@keyframes wf { 0%,100%{height:18%} 50%{height:95%} }

/* event pulse banner during the party (imageless) */
.event-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  color: #f8ead1;
  background: #231f19;
  border: 2px solid #000;
  border-radius: 10px;
  font-size: 11px;
}
.event-banner .ev-name { font-weight: 900; text-transform: uppercase; color: var(--yellow); }
.event-banner .ev-pulse { color: #e6c96a; }

/* your own latent film strip (undeveloped negatives) */
.latent-strip {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding: 6px;
  background: rgba(10,8,6,0.5);
  border: 2px inset #000;
  border-radius: 10px;
  scrollbar-width: thin;
}
.latent-strip:empty { display: none; }
.latent-frame {
  flex: 0 0 auto;
  width: 34px;
  height: 46px;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid #3a2e1a;
  background: #120d07;
  position: relative;
  cursor: pointer;
}
.latent-frame img {
  width: 100%; height: 100%; object-fit: cover;
  /* undeveloped: amber negative, blurred so it jogs memory but doesn't preview */
  filter: invert(0.86) sepia(0.7) hue-rotate(150deg) saturate(1.4) brightness(0.72) blur(1.1px);
}
.latent-frame.has-note::after {
  content: "•"; position: absolute; right: 2px; bottom: 0;
  color: var(--yellow); font-size: 12px;
}
.latent-frame.latest { border-color: var(--yellow); box-shadow: 0 0 0 1px var(--yellow); }

/* note sheet (notate AFTER, by tapping a frame) */
.note-sheet {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 12;
  padding: 12px;
  display: grid;
  gap: 8px;
  background: #1b1710;
  border-top: 3px solid var(--yellow);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.5);
}
.note-sheet label { color: var(--yellow); }
.note-sheet .note-preview {
  width: 54px; height: 72px; object-fit: cover; border-radius: 4px;
  filter: invert(0.86) sepia(0.7) hue-rotate(150deg) saturate(1.4) brightness(0.72) blur(1px);
}

/* ============ develop reveal + album ============ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: radial-gradient(circle at 50% 20%, #2a2016, #0c0a08 75%);
  color: #f8ead1;
}
.overlay-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; gap: 10px;
}
.overlay-head h2 {
  margin: 0;
  font-family: Impact, Haettenschweiler, sans-serif;
  font-size: clamp(22px, 6vw, 32px);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.overlay-head .x { width: 40px; background: #2b2620; }
.album-grid {
  overflow-y: auto;
  padding: 4px 12px 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  align-content: start;
}
.album-cell {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 6px;
  overflow: hidden;
  background: #16110b;
  border: 1px solid #3a2e1a;
}
.album-cell img { width: 100%; height: 100%; object-fit: cover; filter: sepia(0.18) saturate(0.86) contrast(1.1); }
.album-cell .cap {
  position: absolute; inset: auto 0 0 0;
  padding: 10px 6px 4px; font-size: 10px; line-height: 1.2;
  background: linear-gradient(transparent, rgba(0,0,0,0.72));
}
.album-cell .who { color: var(--yellow); font-weight: 900; }
.overlay-foot { padding: 12px 16px; display: grid; gap: 8px; }
.overlay-foot .share {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 10px; background: #201c16; border: 2px solid #000; border-radius: 10px;
}
.overlay-foot .share input { background: #0e0c0a; color: #f8ead1; border-color: #000; }
.overlay-foot button.primary { height: 44px; background: var(--green); color: #fff7df; font-weight: 900; text-transform: uppercase; }

.develop-wait { text-align: center; display: grid; place-content: center; gap: 10px; padding: 24px; }
.develop-wait .big {
  font-family: Impact, Haettenschweiler, sans-serif;
  font-size: clamp(28px, 8vw, 40px); text-transform: uppercase; color: var(--yellow);
}

/* intro container (mode chooser + panels) */
.intro-card { display: grid; gap: 8px; }
.roll-loaded .intro-card { display: none; }
/* in a loaded roll, the advance + controls always show (no pre-save hold) */
.roll-loaded .advance, .roll-loaded .controls { display: grid; }

/* owner curate selection */
.album-cell .pick {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--green); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 900;
  box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.album-cell:not(.sel) { filter: grayscale(.75) brightness(.45); }
.album-cell:not(.sel) .pick { display: none; }

/* ============ flip: camera front <-> live wall back ============ */
.flip {
  width: min(100%, 460px);
  height: min(780px, calc(100svh - 16px));
  perspective: 1800px;
}
.flip-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform .7s cubic-bezier(.4, .05, .2, 1);
  transform-style: preserve-3d;
}
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flip-back { transform: rotateY(180deg); }
.flip .camera { width: 100%; height: 100%; }

.wall-btn {
  height: 44px; background: #193f35; color: #fff7df;
  font-weight: 900; text-transform: uppercase; border-radius: 10px;
}

/* the wall (back face) */
.album-face {
  width: 100%; height: 100%;
  display: grid; grid-template-rows: auto 1fr; gap: 10px; padding: 12px;
  border: 3px solid #231f19; border-radius: 20px;
  background: linear-gradient(160deg, #3a2f22, #17110b 90%);
  box-shadow: 0 18px 42px rgba(18, 13, 8, 0.42); overflow: hidden;
}
.album-face-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; color: #f8ead1; background: var(--black);
  border: 2px solid #000; border-radius: 12px;
}
.album-face-head .x { min-width: auto; padding: 6px 10px; }
.live-feed {
  overflow-y: auto; display: grid; gap: 18px;
  padding: 6px 4px 24px; align-content: start; scrollbar-width: thin;
}
.live-feed:empty::after {
  content: "No shots yet — flip back and take one.";
  color: #c9b78a; font-size: 12px; text-align: center; padding: 30px 10px;
}

/* polaroid */
.polaroid {
  background: #fffdf5; padding: 11px 11px 14px; border-radius: 3px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4); transform: rotate(var(--rot, 0deg));
}
.polaroid > img {
  width: 100%; display: block; border-radius: 1px; background: #111;
  filter: sepia(0.16) saturate(0.9) contrast(1.08);
}
.pol-caption {
  font-family: 'Caveat', 'Segoe Print', 'Bradley Hand', cursive;
  font-size: 23px; line-height: 1.05; color: #2a2118; text-align: center;
  margin-top: 9px; word-break: break-word;
}
.pol-caption:empty { display: none; }
.pol-meta { font-size: 10px; color: #9a8a63; text-align: right; margin-top: 3px; letter-spacing: .3px; }

/* comments under each photo */
.comments { margin-top: 9px; border-top: 1px solid #e7ddc1; padding-top: 7px; display: grid; gap: 5px; }
.comment { font-size: 12.5px; color: #3d2c18; line-height: 1.3; }
.comment b { color: #14100a; }
.add-comment { display: flex; gap: 6px; margin-top: 3px; }
.add-comment input { height: 34px; font-size: 12px; padding: 0 9px; }
.add-comment button { min-width: 42px; padding: 0; background: var(--green); }
