:root {
  --tray-w: 220px;
  --orange: #f5b942;          /* pirate gold */
  --orange-deep: #d97706;
  --gold-shadow: #7c4a03;
  --glow: 245, 185, 66;
  --green: #8cff5a;
  --card: rgba(14, 24, 48, 0.88);
  --line: rgba(245, 185, 66, 0.35);
  --text: #eef3ff;
  --muted: #a9bfe4;
  --title-font: 'Pirata One', 'Nunito', serif;
}

* { box-sizing: border-box; margin: 0; }

html, body { height: 100%; }

body {
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #241a52 0%, #16244a 35%, #0d1a33 65%, #07101f 100%);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- Scene ---------- */
.scene { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }

.stars span {
  position: absolute; width: 2px; height: 2px; border-radius: 50%;
  background: #fff; opacity: .6; animation: twinkle 3s ease-in-out infinite;
}

.moon {
  position: absolute; top: 5vh; right: 7vw; width: clamp(80px, 11vw, 160px); aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 70% 32%, rgba(214,174,92,.55) 0 11%, transparent 12%),
              radial-gradient(circle at 34% 68%, rgba(214,174,92,.5) 0 13%, transparent 14%),
              radial-gradient(circle at 40% 40%, #fff4c2, #f6d27a);
  box-shadow: 0 0 60px 20px rgba(253, 224, 138, .25), 0 0 140px 50px rgba(253, 224, 138, .1);
}

.web { position: absolute; top: 0; left: 0; width: clamp(130px, 15vw, 220px); }

.spider {
  position: absolute; top: 0; left: clamp(150px, 16vw, 240px);
  display: flex; flex-direction: column; align-items: center;
  animation: dangle 5s ease-in-out infinite; transform-origin: top center;
}
.spider .thread { width: 1px; height: 90px; background: rgba(255,255,255,.35); }

.bat { position: absolute; width: 54px; height: 22px; animation: flap .35s ease-in-out infinite alternate, drift 14s ease-in-out infinite; }
.b1 { top: 18vh; left: 58%; }
.b2 { top: 24vh; left: 70%; width: 40px; animation-delay: .1s, -5s; }
.b3 { top: 32vh; left: 82%; width: 34px; animation-delay: .2s, -9s; }

.tree { position: absolute; bottom: 30px; height: 70vh; width: calc(70vh * 300 / 700); z-index: 2; }
.tree-left { left: -3vw; }
.tree-right { right: -3vw; transform: scaleX(-1); }

/* Sea, moonlight and the ghost ship */
.sea { position: absolute; left: 0; right: 0; bottom: 70px; height: 170px; }
.wave { position: absolute; left: 0; bottom: 0; width: 200%; animation: waves linear infinite; }
.w1 { height: 120px; bottom: 50px; animation-duration: 40s; }
.w2 { height: 100px; bottom: 20px; animation-duration: 28s; animation-direction: reverse; }
.w3 { height: 80px; bottom: 0; animation-duration: 20s; }
.moonpath {
  position: absolute; right: calc(7vw + clamp(80px, 11vw, 160px) / 2 - 60px); bottom: 20px; width: 120px; height: 150px;
  background: repeating-linear-gradient(180deg, rgba(253, 224, 138, .35) 0 3px, transparent 3px 11px);
  -webkit-mask-image: radial-gradient(ellipse at 50% 30%, #000 20%, transparent 70%);
  mask-image: radial-gradient(ellipse at 50% 30%, #000 20%, transparent 70%);
  filter: blur(1px); animation: shimmer 3s ease-in-out infinite;
}
.ship {
  position: absolute; left: 4vw; bottom: 34px; height: clamp(110px, 22vh, 220px); aspect-ratio: 320 / 220;
  opacity: .9; filter: drop-shadow(0 0 18px rgba(140, 255, 90, .22));
  animation: bob 7s ease-in-out infinite;
}

.ground { position: absolute; left: 0; right: 0; bottom: 0; height: 160px; z-index: 3; }
.hills { position: absolute; inset: 0; width: 100%; height: 100%; }
.prop { position: absolute; bottom: 44px; width: auto; transform: translateX(-50%); }
.prop.chest { aspect-ratio: 100 / 80; filter: drop-shadow(0 0 14px rgba(var(--glow), .35)); }
.prop.barrel { aspect-ratio: 60 / 80; }
.pumpkin {
  position: absolute; bottom: -6px; aspect-ratio: 100 / 92; transform: translateX(-50%);
  filter: drop-shadow(0 0 16px rgba(249, 115, 22, .55));
  animation: glow 3s ease-in-out infinite;
}
.pumpkin:nth-of-type(even) { animation-delay: -1.5s; }

.embers span {
  position: absolute; bottom: 0; width: 4px; height: 4px; border-radius: 50%;
  background: #fcd34d; box-shadow: 0 0 8px #fcd34d; opacity: 0;
  animation: rise linear infinite;
}

/* ---------- Layout ---------- */
main {
  position: relative; z-index: 1; height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(10px, 2.2vh, 22px); padding: 16px 16px 120px;
}

.title {
  font-family: var(--title-font); font-weight: 400; letter-spacing: .06em;
  font-size: clamp(2.2rem, 6.5vh, 4.6rem); line-height: 1; text-align: center;
  color: var(--orange);
  text-shadow: 0 0 18px rgba(var(--glow), .5), 0 3px 0 var(--gold-shadow);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: clamp(12px, 2vh, 20px);
  display: flex; flex-direction: column; align-items: center; gap: clamp(12px, 2vh, 18px);
  box-shadow: 0 20px 60px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.05);
  backdrop-filter: blur(6px);
  max-width: 100%;
}

/* ---------- Camera stage ---------- */
.stage {
  --ar: 1.3333;
  position: relative;
  width: min(calc(100vw - 72px - var(--tray-w) - 18px), calc((100dvh - 380px) * var(--ar)), 1000px);
  aspect-ratio: var(--ar);
  transition: width .35s ease;
  border-radius: 18px; overflow: hidden; background: #040a16;
  border: 2px solid rgba(var(--glow), .25);
  box-shadow: 0 0 40px rgba(var(--glow), .15);
}
.stage video, .stage img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
}
/* Preview is cropped exactly like the print (center crop) */
.stage video { object-fit: cover; }
.stage video.mirror { transform: scaleX(-1); }
.stage img { background: #040a16; animation: develop .5s ease-out; }

.stage img.result {
  background: radial-gradient(ellipse at center, #16244a 0%, #07101f 75%);
  animation: develop .6s ease-out; padding: 16px 0;
}

.shot-badge {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 2;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; border-radius: 999px; font-weight: 800; font-size: 1.05rem;
  background: rgba(4, 10, 22, .72); border: 1px solid var(--line); backdrop-filter: blur(4px);
}
.shot-badge .dots { display: flex; gap: 6px; }
.shot-badge i { width: 9px; height: 9px; border-radius: 50%; background: rgba(169,191,228,.3); }
.shot-badge i.done { background: var(--green); box-shadow: 0 0 8px var(--green); }
.shot-badge i.now { background: var(--orange); box-shadow: 0 0 8px var(--orange); }

.countdown {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--title-font); font-size: min(42vh, 30vw); line-height: 1;
  color: var(--green);
  text-shadow: 0 0 30px rgba(140, 255, 90, .7), 0 6px 0 #166534;
  background: radial-gradient(circle, rgba(0,0,0,.15), rgba(0,0,0,.45));
}
.countdown.tick { animation: pop 1s ease-out; }

.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .6s ease-out; }

.cam-msg {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center; font-size: 1.15rem; color: var(--muted);
}
.cam-msg[hidden], [hidden] { display: none !important; }

/* ---------- Controls ---------- */
.controls { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }

.timer {
  display: flex; padding: 5px; gap: 4px; border-radius: 999px;
  background: rgba(4, 10, 22, .55); border: 1px solid rgba(169, 191, 228, .2);
}
.timer button {
  font: inherit; font-weight: 800; font-size: 1.1rem; color: var(--muted);
  background: none; border: 0; border-radius: 999px; padding: 10px 20px; cursor: pointer;
  transition: background .2s, color .2s;
}
.timer button { display: inline-flex; align-items: center; gap: 7px; }
.timer button[aria-checked="true"] { background: var(--orange); color: #1a1206; }
body.counting .timer { opacity: .4; pointer-events: none; }

.btn {
  font: inherit; font-weight: 800; font-size: 1.2rem;
  display: inline-flex; align-items: center; gap: 10px;
  border-radius: 999px; padding: 14px 30px; cursor: pointer; border: 0;
  transition: transform .15s, box-shadow .2s, opacity .2s;
}
.btn:active:not(:disabled) { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: default; }

.btn-primary {
  color: #1a1206;
  background: linear-gradient(180deg, #ffd36b, var(--orange-deep));
  box-shadow: 0 0 24px rgba(var(--glow), .45), inset 0 1px 0 rgba(255,255,255,.4);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 0 34px rgba(var(--glow), .7), inset 0 1px 0 rgba(255,255,255,.4); }

.btn-ghost {
  color: var(--text); background: rgba(255,255,255,.06);
  border: 1px solid rgba(169, 191, 228, .3);
}

/* ---------- Photo wall prompt ---------- */
.modal {
  position: fixed; inset: 0; z-index: 4; display: grid; place-items: center; padding: 16px;
  background: rgba(3, 8, 18, .72); backdrop-filter: blur(6px);
  animation: fadeIn .2s ease-out;
}
.modal-card {
  width: min(460px, 100%); text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 28px;
  padding: 28px 24px 18px; box-shadow: 0 24px 70px rgba(0,0,0,.55);
  animation: rise-in .3s cubic-bezier(.2,.9,.3,1.2);
}
.modal-ghost { animation: float 3s ease-in-out infinite; filter: drop-shadow(0 0 16px rgba(238,243,255,.45)); }
.modal-card h2 {
  font-family: var(--title-font); font-weight: 400; letter-spacing: .04em;
  font-size: 2.2rem; color: var(--orange); margin: 10px 0 6px;
  text-shadow: 0 0 14px rgba(var(--glow), .45);
}
.modal-card p { color: var(--muted); font-weight: 700; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.link-btn {
  margin-top: 14px; font: inherit; font-weight: 700; color: var(--muted);
  background: none; border: 0; padding: 8px 12px; cursor: pointer; opacity: .8;
}

@keyframes fadeIn { from { opacity: 0; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(16px) scale(.96); } }
@keyframes float { 50% { transform: translateY(-8px); } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 5;
  transform: translate(-50%, 20px); opacity: 0;
  padding: 12px 22px; border-radius: 14px; font-weight: 700;
  background: var(--card); border: 1px solid var(--line);
  transition: opacity .25s, transform .25s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: rgba(140, 255, 90, .5); color: #d9ffc7; }
.toast.err { border-color: rgba(248, 113, 113, .6); color: #fecaca; }

/* ---------- Animations ---------- */
@keyframes twinkle { 50% { opacity: .15; } }
@keyframes waves { to { transform: translateX(-50%); } }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-1.5deg); } 50% { transform: translateY(8px) rotate(1.5deg); } }
@keyframes shimmer { 50% { opacity: .55; transform: scaleX(1.15); } }
@keyframes dangle { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(14px) rotate(2deg); } }
@keyframes flap { to { transform: scaleY(.55); } }
@keyframes drift { 0%,100% { translate: 0 0; } 50% { translate: -40px 14px; } }
@keyframes glow { 50% { filter: drop-shadow(0 0 26px rgba(249, 115, 22, .8)); } }
@keyframes rise {
  10% { opacity: .9; }
  100% { transform: translate(var(--dx), -70vh); opacity: 0; }
}
@keyframes pop {
  0% { transform: scale(1.6); opacity: 0; }
  20% { transform: scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: scale(.85); opacity: 0; }
}
@keyframes flash { 0% { opacity: .95; } 100% { opacity: 0; } }
@keyframes develop { from { filter: brightness(2.2) saturate(0); } to { filter: none; } }

@media (max-width: 700px) {
  .tree, .web, .spider { display: none; }
  .ship { left: 2vw; }
  .stage { width: min(calc(100vw - 56px), calc((100dvh - 470px) * var(--ar))); }
  .btn { padding: 12px 22px; font-size: 1.05rem; }
  .timer button { padding: 9px 15px; }
}

/* ---------- Print (4x6 portrait: two 2x6 strips) ---------- */
.print-area { display: none; }

@page { size: 4in 6in; margin: 0; }

@media print {
  html, body { height: auto; overflow: visible; background: #fff !important; }
  .scene, main, .toast, .modal, canvas { display: none !important; }
  .print-area { display: block; width: 4in; height: 6in; overflow: hidden; }
  .print-area img { display: block; width: 100%; height: 100%; object-fit: contain; }
}

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

/* ---------- Login ---------- */
.login-card { display: flex; flex-direction: column; align-items: center; animation: rise-in .3s cubic-bezier(.2,.9,.3,1.2); }
.login-card p { margin-bottom: 16px; }
.login-card input {
  width: 100%; font: inherit; font-weight: 700; font-size: 1.15rem; color: var(--text);
  padding: 14px 18px; border-radius: 16px; text-align: center;
  background: rgba(4, 10, 22, .6); border: 1px solid rgba(169, 191, 228, .3); outline: none;
  -webkit-user-select: text; user-select: text;
}
.login-card input:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(var(--glow), .25); }
.login-card .login-error { min-height: 1.4em; margin: 10px 0 12px; color: #fecaca; }
.login-card .btn { width: 100%; justify-content: center; }
.shake { animation: shake .4s ease-in-out; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }


/* ---------- Booth: camera + tray ---------- */
.booth-row { display: flex; gap: 18px; align-items: stretch; }
.tray {
  width: var(--tray-w); display: flex; flex-direction: column; gap: 12px;
  padding: 14px; border-radius: 18px;
  background: rgba(4, 10, 22, .55); border: 1px solid rgba(169, 191, 228, .16);
  min-height: 0;
}
.tray-head { display: flex; flex-direction: column; gap: 2px; }
.tray-name {
  font-family: var(--title-font); font-size: 1.6rem; line-height: 1.1; color: var(--orange);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tray-count { font-weight: 800; color: var(--muted); font-size: .95rem; }
.tray-list {
  flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-content: start;
}
.tray-thumb {
  aspect-ratio: 2 / 3; border-radius: 10px; overflow: hidden;
  background: #040a16; border: 1px solid rgba(var(--glow), .3);
}
.tray-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.tray-thumb.pop { animation: pop-in .5s cubic-bezier(.2,.9,.3,1.3); border-color: var(--green); }
.tray-empty { grid-column: 1 / -1; color: var(--muted); font-weight: 700; font-size: .95rem; opacity: .75; padding: 6px 2px; }
.btn-block { width: 100%; justify-content: center; }

.saved-badge { color: #d9ffc7; border-color: rgba(140, 255, 90, .55); gap: 8px; animation: rise-in .3s ease-out; }
.saved-badge svg { color: var(--green); }

@keyframes pop-in { from { transform: scale(.4); opacity: 0; } }

/* ---------- Checkout ---------- */
.checkout {
  width: min(1100px, 100%); height: calc(100dvh - 120px - clamp(2.2rem, 6.5vh, 4.6rem) - 60px);
  align-items: stretch; gap: 14px;
}
.checkout-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.checkout-head h2 {
  font-family: var(--title-font); font-weight: 400; font-size: 2.2rem; line-height: 1.1; color: var(--orange);
  text-shadow: 0 0 14px rgba(var(--glow), .35);
}
.checkout-head p { color: var(--muted); font-weight: 700; margin-top: 4px; }
.checkout-head .link-btn { margin: 0; white-space: nowrap; }

.grid {
  flex: 1; min-height: 0; overflow-y: auto; padding: 4px 4px 8px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; align-content: start;
}
.tile { display: flex; flex-direction: column; gap: 8px; }
.tile-pick {
  position: relative; display: block; width: 100%; aspect-ratio: 2 / 3; padding: 0; cursor: pointer;
  border-radius: 16px; overflow: hidden; background: #040a16;
  border: 3px solid rgba(169, 191, 228, .18);
  transition: border-color .2s, transform .15s, box-shadow .2s;
}
.tile-pick:active { transform: scale(.97); }
.tile-pick img { width: 100%; height: 100%; object-fit: contain; display: block; opacity: .55; transition: opacity .2s; }
.tile.selected .tile-pick { border-color: var(--orange); box-shadow: 0 0 22px rgba(var(--glow), .35); }
.tile.selected .tile-pick img { opacity: 1; }
.tile-check {
  position: absolute; top: 8px; left: 8px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; color: transparent;
  background: rgba(4, 10, 22, .7); border: 2px solid rgba(238, 243, 255, .6);
}
.tile.selected .tile-check { background: var(--orange); border-color: var(--orange); color: #1a1206; }
.tile-type {
  position: absolute; bottom: 8px; right: 8px; padding: 2px 9px; border-radius: 999px;
  font-size: .78rem; font-weight: 800; color: var(--muted); background: rgba(4, 10, 22, .75);
}
.tile-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mini {
  font: inherit; font-weight: 800; font-size: .92rem; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 6px; border-radius: 12px; cursor: pointer;
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(169, 191, 228, .25);
  transition: background .2s, border-color .2s, color .2s;
}
.mini:disabled { opacity: .6; cursor: default; }
.mini.on { background: rgba(140, 255, 90, .14); border-color: rgba(140, 255, 90, .6); color: #d9ffc7; }

.checkout-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.bar-right { display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- Modals: name, QR ---------- */
form.modal-card { display: flex; flex-direction: column; align-items: center; }
.field {
  width: 100%; font: inherit; font-weight: 700; font-size: 1.2rem; color: var(--text);
  padding: 14px 18px; border-radius: 16px; text-align: center; margin-bottom: 14px;
  background: rgba(4, 10, 22, .6); border: 1px solid rgba(169, 191, 228, .3); outline: none;
  -webkit-user-select: text; user-select: text;
}
.field:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(var(--glow), .25); }
.qr-card p { margin-bottom: 14px; }
.qr-box {
  width: min(280px, 70vw); aspect-ratio: 1; margin: 0 auto 12px; padding: 12px;
  background: #fff; border-radius: 18px; box-shadow: 0 0 30px rgba(var(--glow), .35);
}
.qr-box img { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.qr-card .qr-url { font-size: .95rem; word-break: break-all; color: var(--text); opacity: .8; margin-bottom: 18px; }

/* ---------- Scrolling pages (share, admin) ---------- */
body.page-scroll { overflow: auto; -webkit-user-select: auto; user-select: auto; }

@media (max-width: 900px) {
  :root { --tray-w: 0px; }
  .booth-row { flex-direction: column; }
  .tray { width: 100%; padding: 10px 12px; flex-direction: row; align-items: center; }
  .tray-head { min-width: 0; flex: 0 1 auto; }
  .tray-list { display: flex; overflow-x: auto; overflow-y: hidden; flex: 1; }
  .tray-thumb { height: 64px; flex: 0 0 auto; }
  .tray-empty { display: none; }
  .tray .btn-block { width: auto; }
  .checkout-head { flex-direction: column; align-items: flex-start; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
a.btn { text-decoration: none; }
.mini span { white-space: nowrap; }

/* ---------- Email in QR popup ---------- */
.email-row { display: flex; flex-direction: row; gap: 8px; margin: 0 0 6px; }
.email-row .field { margin: 0; text-align: left; font-size: 1.05rem; padding: 12px 16px; }
.email-row .btn { flex-shrink: 0; padding: 12px 20px; }
.modal-card .email-note { font-size: .92rem; margin: 6px 0 14px; }
.email-note.ok { color: #d9ffc7; }
.email-note.err { color: #fecaca; }
.qr-card .modal-actions { margin-top: 12px; }
