:root {
  --cork: #be9468;
  --cork-dark: #8a5f3b;
  --ink: #1d1a17;
  --paper: #fdfcf8;
  --pencil: #5b5550;
  --stamp: #ff6a14;
  --accent: #e2551b;
  --accent-ink: #ffffff;
  --night: #121110;
  --night-2: #23201d;
  --focus: #ffd166;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --radius: 10px;
  --sans: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --hand: 'Caveat', 'Bradley Hand', cursive;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--cork);
  /* Seamless 1024 px cork tile (scripts/cork.py), drawn at 512 px so it's sharp on 2x screens. */
  background-image: url('/cork.webp?v=a83aa5c1e0');
  background-size: 512px 512px;
  padding-bottom: calc(112px + env(safe-area-inset-bottom));
}

button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
svg { width: 22px; height: 22px; flex: none; }

/* --- Header: a label-maker strip and an index card --- */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--s4) var(--s5);
  max-width: 1240px;
  margin: 0 auto;
  padding: var(--s6) var(--s4) var(--s5);
}

.label {
  margin: 0;
  transform: rotate(-1.5deg);
}
.label span {
  display: inline-block;
  padding: 10px 20px 9px;
  background: linear-gradient(180deg, #2b2826, #141210 60%, #1e1b19);
  color: #f4f1ea;
  font-weight: 800;
  font-size: clamp(28px, 6vw, 40px);
  letter-spacing: .16em;
  text-transform: uppercase;
  line-height: 1;
  border-radius: 3px;
  text-shadow: 0 1px 0 rgba(0,0,0,.6), 0 -1px 0 rgba(255,255,255,.12);
  box-shadow: 0 2px 0 rgba(0,0,0,.25), 0 6px 14px rgba(40,20,5,.35);
}

.intro {
  flex-basis: 100%;
  margin: 0;
  max-width: 32ch;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  color: #2a1b0e;
}

.foot { text-align: center; padding: var(--s6) var(--s4) 0; }
.foot a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--s4);
  border-radius: 999px;
  background: rgba(253,252,248,.82);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}
.foot a:hover { text-decoration: underline; }

.printer {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: #2a1b0e;
}
.printer:empty { display: none; }
.printer .dot { width: 10px; height: 10px; border-radius: 50%; background: #3fa34d; box-shadow: 0 0 0 3px rgba(255,255,255,.35); }
.printer.off .dot { background: #8b8178; }
.printer span:last-child { background: rgba(253,252,248,.82); padding: 4px 10px; border-radius: 999px; }

/* --- The wall --- */

main { flex: 1 0 auto; width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 var(--s4); }
.top { width: 100%; }

.wall {
  list-style: none;
  margin: 0;
  padding: var(--s3) 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 56px var(--s5);
}
@media (min-width: 720px) { .wall { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 64px var(--s6); } }

.card {
  position: relative;
  transform: rotate(var(--tilt, 0deg));
  transition: transform .2s ease;
}
.card button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
  border-radius: 2px;
}
.card img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 3;
  background: var(--paper);
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,.25), 0 10px 18px -6px rgba(45,22,5,.55);
}
@media (hover: hover) { .card:hover { transform: rotate(0deg) scale(1.03); z-index: 1; } }

/* Push pin */
.card::before {
  content: '';
  position: absolute;
  top: -7px;
  left: calc(50% - 9px);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.75) 0 2px, transparent 3px), var(--pin, #d23b2a);
  box-shadow: inset -2px -3px 4px rgba(0,0,0,.35), 2px 4px 4px rgba(0,0,0,.35);
  z-index: 2;
}

/* Print status on a paper tag just under the card, clear of any caption */
.card .status {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) rotate(calc(var(--tilt, 0deg) * -1));
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 1px 10px 2px;
  white-space: nowrap;
  background: var(--paper);
  border-radius: 2px;
  box-shadow: 0 3px 6px rgba(40,20,5,.3);
  font-family: var(--hand);
  font-size: 18px;
  color: var(--pencil);
  pointer-events: none;
}
.card .status svg { width: 16px; height: 16px; }
.card .status.printing svg { animation: spin 1s linear infinite; }
.card.new { animation: drop .5s cubic-bezier(.2,.9,.3,1.2); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes drop { from { opacity: 0; transform: translateY(-30px) rotate(calc(var(--tilt) * -2)) scale(1.08); } }

.empty {
  margin: var(--s7) auto;
  max-width: 320px;
  padding: var(--s5);
  text-align: center;
  background: var(--paper);
  font-family: var(--hand);
  font-size: 26px;
  line-height: 1.2;
  transform: rotate(-1deg);
  box-shadow: 0 8px 18px rgba(40,20,5,.35);
}
.empty p { margin: 0; }

.more {
  display: block;
  margin: var(--s7) auto 0;
  min-height: 44px;
  padding: 0 var(--s5);
  border: 0;
  border-radius: 999px;
  background: rgba(253,252,248,.9);
  font-weight: 700;
  cursor: pointer;
}

/* --- Dock --- */

.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  padding: var(--s4) var(--s4) calc(var(--s4) + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(60,35,15,.45));
  pointer-events: none;
}
.shoot {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--s3);
  min-height: 60px;
  padding: 0 var(--s6);
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .01em;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(20,10,0,.45);
}
.shoot:active { transform: translateY(1px); }

/* --- Camera --- */

.camera {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--night);
  color: #fff;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.camera[hidden] { display: none; }

.camera-top {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  min-height: 60px;
}
.hint { margin: 0; font-size: 14px; color: #bdb5ad; }
@media (max-width: 430px) { .hint { display: none; } }

/* Print style: Polaroid (framed, room to write) or Full (the photo edge to edge). */
.layout {
  display: flex;
  margin-left: auto;
  padding: 3px;
  border-radius: 999px;
  background: var(--night-2);
}
.layout button {
  min-height: 44px;
  padding: 0 var(--s4);
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #d8d1c9;
  font: 700 15px/1 var(--sans);
  cursor: pointer;
}
.layout button[aria-pressed='true'] { background: #fff; color: var(--ink); }
.layout button:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 48px;
  height: 48px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: var(--night-2);
  color: #fff;
  cursor: pointer;
}
.icon-btn:disabled { opacity: .35; cursor: default; }
.timer span { font-size: 14px; font-weight: 700; }
.timer[aria-pressed='true'] { background: var(--stamp); color: #1b0d03; }

/* Card geometry matches server/render.js: a 1200x1800 card with the 1050x1312 photo at (75, 75) and the caption
   area from y = 1407 to 1770, 1040 wide. */
.print {
  position: relative;
  flex: none;
  margin: auto;
  width: min(100%, calc((100vh - 220px) * .8), 640px);
  aspect-ratio: 4 / 5;
}
.finder {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
}
.camera.reviewing .print {
  width: min(calc(100% - 32px), calc((100vh - 230px) * 2 / 3), 520px);
  aspect-ratio: 2 / 3;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 16px 40px rgba(0,0,0,.55);
}
.camera.reviewing .finder {
  inset: 4.1667% auto auto 6.25%;
  width: 87.5%;
  height: 72.889%;
}
@supports (height: 100dvh) {
  .print { width: min(100%, calc((100dvh - 220px) * .8), 640px); }
  .camera.reviewing .print { width: min(calc(100% - 32px), calc((100dvh - 230px) * 2 / 3), 520px); }
}
/* Full: the viewfinder is the whole 2:3 card, and after the shot the photo fills it with no frame. */
.camera.full .print { width: min(100%, calc((100vh - 220px) * 2 / 3), 560px); aspect-ratio: 2 / 3; }
.camera.full.reviewing .print { width: min(calc(100% - 32px), calc((100vh - 230px) * 2 / 3), 520px); }
.camera.full.reviewing .finder { inset: 0; width: 100%; height: 100%; }
@supports (height: 100dvh) {
  .camera.full .print { width: min(100%, calc((100dvh - 220px) * 2 / 3), 560px); }
  .camera.full.reviewing .print { width: min(calc(100% - 32px), calc((100dvh - 230px) * 2 / 3), 520px); }
}
.finder video, .finder canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* The same film look the server applies: warmer, a little less saturated, lifted blacks, vignette. */
/* Approximates the disposable-camera look the server applies (see filmPhoto in server/render.js), on the live
   viewfinder too: faded warm colour, soft edges, darker corners and film grain. */
.finder video, .finder canvas { filter: sepia(.07) saturate(.88) contrast(.92) brightness(1.04); }
.lens { position: absolute; inset: 0; pointer-events: none; }
.lens .soft {
  position: absolute;
  inset: 0;
  -webkit-backdrop-filter: blur(1.5px);
  backdrop-filter: blur(1.5px);
  -webkit-mask-image: radial-gradient(72% 72% at 50% 50%, transparent 45%, #000 100%);
  mask-image: radial-gradient(72% 72% at 50% 50%, transparent 45%, #000 100%);
}
.lens .vignette {
  position: absolute;
  inset: 0;
  mix-blend-mode: multiply;
  background: radial-gradient(72% 72% at 50% 48%, #fff 48%, #d9cfc4 80%, #8f8072 100%);
}
.lens .grain {
  position: absolute;
  inset: 0;
  mix-blend-mode: soft-light;
  background: url('/grain.png?v=a83aa5c1e0') 0 0 / 128px 128px;
}

.caption {
  position: absolute;
  left: 6.667%;
  top: 78.17%;
  width: 86.667%;
  height: 20.17%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: #1c1d24;
  font-family: 'Permanent Marker', var(--hand);
  line-height: 1.1;
  text-align: center;
  resize: none;
  overflow: hidden;
  transform: rotate(-1.2deg);
}
.caption::placeholder { color: #b3ada7; }
.caption:focus { outline: none; }
.caption:focus-visible { outline: 2px dashed #c9c2ba; outline-offset: 2px; }
.finder.mirror video { transform: scaleX(-1); }

.stamp { position: absolute; right: 3.8%; bottom: 2.7%; line-height: 0; pointer-events: none; }
.stamp svg { width: auto; height: auto; }

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 120px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 4px 30px rgba(0,0,0,.6);
  pointer-events: none;
}
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .45s ease-out; }
@keyframes flash { from { opacity: .95; } to { opacity: 0; } }

.finder-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s4);
  padding: var(--s5);
  text-align: center;
  line-height: 1.45;
  color: #e9e3dc;
  background: #000;
}
.finder-msg[hidden] { display: none; }

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(100%, 420px);
  margin: 0 auto;
  padding: var(--s5) var(--s5) var(--s5);
}
.controls[hidden] { display: none; }

.shutter {
  width: 78px;
  height: 78px;
  padding: 6px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform .1s; }
.shutter:active span { transform: scale(.9); }
.shutter:disabled { opacity: .4; }

.review { gap: var(--s3); }
.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 56px;
  padding: 0 var(--s4);
  border: 0;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.btn.ghost { background: var(--night-2); color: #fff; }
.btn.primary { background: var(--accent); color: var(--accent-ink); flex: 1.4; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.busy svg { animation: spin 1s linear infinite; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- Viewer --- */

.viewer {
  width: min(92vw, 560px);
  max-height: 92vh;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
}
.viewer::backdrop { background: rgba(18,12,6,.82); }
.viewer img {
  display: block;
  width: 100%;
  max-height: calc(92vh - 60px);
  object-fit: contain;
  background: var(--paper);
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.viewer p { margin: var(--s3) 0 0; text-align: center; color: #f4ede4; font-size: 15px; }
.viewer .icon-btn { position: absolute; top: -12px; right: -8px; z-index: 1; box-shadow: 0 4px 12px rgba(0,0,0,.4); }

/* --- Admin --- */

.label {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom, so three quick taps arrive as three clicks */
  cursor: pointer;
}

.sheet {
  width: min(calc(100vw - 32px), 380px);
  padding: var(--s5);
  border: 0;
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
}
.sheet::backdrop { background: rgba(18,12,6,.6); }
.sheet form { margin: 0; }
.sheet h2 { display: flex; align-items: center; gap: var(--s2); margin: 0 0 var(--s4); font-size: 20px; }
.sheet label { display: block; margin-bottom: var(--s2); font-size: 14px; font-weight: 700; }
.sheet input {
  width: 100%;
  min-height: 48px;
  padding: 0 var(--s3);
  border: 1px solid #b9b0a6;
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 17px;
}
.sheet input:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.form-error { margin: var(--s2) 0 0; color: #b3261e; font-size: 14px; font-weight: 700; }
.sheet-actions { display: flex; gap: var(--s3); margin-top: var(--s5); }
.sheet-actions .btn { min-height: 48px; }
.btn.light { background: #e8e2da; color: var(--ink); }

.admin-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s2) var(--s4);
  padding-top: calc(var(--s2) + env(safe-area-inset-top));
  background: #b3261e;
  color: #fff;
  font-weight: 700;
}
.admin-bar p { margin: 0; font-size: 15px; }
.admin-bar .btn { flex: none; min-height: 44px; padding: 0 var(--s5); }

.card .remove {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  display: none;
  width: 48px;
  height: 48px;
  padding: 0;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: #b3261e;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}
.admin .card .remove { display: inline-flex; }
.admin .card .remove:disabled { opacity: .6; }

/* --- Toast --- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  z-index: 40;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: var(--s3) var(--s4);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  line-height: 1.4;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
