:root {
  --bg: #0b0b10;
  --bg-2: #121219;
  --panel: #191922;
  --panel-2: #22222d;
  --line: #2c2c39;
  --text: #f4f4f6;
  --muted: #9a9aa8;
  --accent: #f5c542;
  --accent-ink: #15130b;
  --danger: #ff6b6b;
  --ok: #52d68a;
  --radius: 18px;
  --tap: 64px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}
body.idle-cursor { cursor: none; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }

/* ---------- Buttons ---------- */
.btn {
  min-height: var(--tap);
  padding: 0 26px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-weight: 650;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform .08s ease, background .15s ease, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-xl { min-height: 84px; font-size: 22px; width: 100%; }
.btn-hero { min-height: 96px; font-size: 28px; padding: 0 56px; box-shadow: 0 0 0 0 var(--accent); animation: pulse 2.4s infinite; }
.btn-ico { font-size: 1.2em; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  70% { box-shadow: 0 0 0 26px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.icon-btn {
  width: 56px; height: 56px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel);
  font-size: 24px; cursor: pointer; position: relative;
  display: grid; place-items: center; opacity: .55;
}
.icon-btn:active { opacity: 1; }

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: flex; }

/* ---------- Attract ---------- */
.attract {
  z-index: 5;
  align-items: center; justify-content: center; text-align: center;
  background:
    radial-gradient(1200px 700px at 50% 110%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
    radial-gradient(800px 500px at 10% -10%, #3b2a6655, transparent 70%),
    var(--bg);
  cursor: pointer;
}
.attract-inner { padding: 24px 16px; max-width: 900px; }
.attract-logo { display: block; max-width: min(360px, 60vw); max-height: 22vh; margin: 0 auto 22px; object-fit: contain; }
.attract-kicker { letter-spacing: .35em; text-transform: uppercase; color: var(--accent); font-weight: 700; font-size: 15px; margin-bottom: 14px; }
.attract-title { font-size: clamp(44px, 9vw, 112px); line-height: 1; margin: 0 0 14px; font-weight: 800; letter-spacing: -.02em; overflow-wrap: anywhere; }
.attract-sub { font-size: clamp(18px, 2.6vw, 28px); color: var(--muted); margin-bottom: 48px; min-height: 1em; }
.attract-note { margin-top: 28px; color: var(--muted); font-size: 15px; min-height: 1.4em; }
.attract-note.err { color: var(--danger); }
.corner-tools { position: absolute; right: 16px; bottom: calc(16px + var(--safe-b)); display: flex; gap: 12px; }
.pending-badge { position: absolute; left: 16px; bottom: calc(20px + var(--safe-b)); font-size: 13px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; }
.hold-ring { position: absolute; inset: -4px; width: 64px; height: 64px; transform: rotate(-90deg); pointer-events: none; }
.hold-ring circle { fill: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 100.5; stroke-dashoffset: 100.5; }
.hold-btn.holding { opacity: 1; }
.hold-btn.holding .hold-ring circle { transition: stroke-dashoffset 1.2s linear; stroke-dashoffset: 0; }

/* ---------- Booth ---------- */
.booth.active {
  display: grid;
  grid-template-columns: 1fr minmax(300px, 360px);
  gap: 20px;
  padding: calc(20px + var(--safe-t)) 20px calc(20px + var(--safe-b));
  background: var(--bg);
}
.vf-wrap { min-width: 0; min-height: 0; display: grid; place-items: center; container-type: size; }
.viewfinder {
  position: relative;
  aspect-ratio: var(--vf-ar, 1.5);
  width: min(100cqw, 100cqh * var(--vf-ar, 1.5));
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: 0 20px 60px #000a, 0 0 0 1px var(--line);
}
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: block; }
.viewfinder video.mirror { transform: scaleX(-1); }
/* Inside the FotoSpinBooth app the camera is drawn natively underneath the page (native.js). */
html.native-cam .viewfinder video { visibility: hidden; }
html.native-see-through, html.native-see-through body, html.native-see-through .booth.active,
html.native-see-through .viewfinder { background: transparent !important; }
.vignette { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .2s;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.55) 100%); }
.vignette.on { opacity: 1; }
.countdown {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: clamp(120px, 26cqh, 320px); font-weight: 800; color: #fff;
  text-shadow: 0 6px 40px rgba(0,0,0,.6); pointer-events: none;
}
.countdown.tick span { animation: tick .9s ease-out both; display: inline-block; }
.countdown .smile { font-size: .45em; }
@keyframes tick { 0% { transform: scale(1.6); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 100% { transform: scale(.9); opacity: .85; } }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .5s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }
.cam-error { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); background: #000c; font-size: 18px; }

.side { min-height: 0; display: flex; flex-direction: column; }
.side-inner { display: flex; flex-direction: column; gap: 14px; height: 100%; overflow: auto; padding: 4px; }
.booth[data-mode="ready"] .shooting-only,
.booth[data-mode="shooting"] .ready-only { display: none; }
.side-title { margin: 6px 0 0; font-size: 14px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.chip {
  border: 2px solid var(--line); background: var(--panel); border-radius: 14px;
  padding: 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-weight: 650; font-size: 15px; min-height: var(--tap);
}
.chip[aria-checked="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }
.chip .swatch { width: 100%; aspect-ratio: 3/2; border-radius: 8px; background-size: cover; background-position: center; }
.timers { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
.timers .chip { font-size: 22px; justify-content: center; }
.timers .chip small { font-size: 12px; color: var(--muted); font-weight: 500; }
.cam-fps { font-size: 13px; color: var(--muted); text-align: center; min-height: 1.2em; }
.side-actions { position: sticky; bottom: -4px; margin-top: auto; display: grid; gap: 8px; padding: 14px 0 4px; background: linear-gradient(transparent, var(--bg) 16px); }

.shot-label { font-size: 28px; font-weight: 800; text-align: center; padding: 8px 0; }
.thumbs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.thumb { aspect-ratio: 3/2; border-radius: 10px; background: var(--panel) center/cover no-repeat; border: 2px dashed var(--line); transition: border-color .2s; }
.thumb.filled { border: 2px solid transparent; animation: pop .35s ease-out; }
.thumb.next { border-color: var(--accent); }
@keyframes pop { 0% { transform: scale(.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
#cancelBtn { margin-top: auto; }

/* ---------- Result: full media on top, QR + actions below ---------- */
.result.active {
  z-index: 4; display: flex; flex-direction: column; align-items: center; gap: 16px;
  padding: calc(20px + var(--safe-t)) 16px calc(12px + var(--safe-b));
  background: radial-gradient(900px 600px at 50% 35%, #1d1d2a, var(--bg));
}
.result-media { position: relative; flex: 1 1 auto; min-height: 0; width: 100%; }
.result-media img, .result-media video {
  position: absolute; inset: 0; margin: auto;
  max-width: 100%; max-height: 100%;
  border-radius: 6px; box-shadow: 0 24px 70px #000c; animation: rise .6s ease-out; background: #000;
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.result-bottom { flex: none; width: min(920px, 100%); display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; align-items: stretch; }
.qr-card { background: #fff; color: #111; border-radius: var(--radius); padding: 14px; display: flex; gap: 16px; align-items: center; flex: 1 1 340px; max-width: 460px; }
#qrCanvas, .qr-placeholder { width: 132px; height: 132px; flex: none; border-radius: 6px; }
.qr-placeholder { display: grid; place-items: center; background: #eee; color: #777; font-size: 13px; text-align: center; padding: 10px; }
.qr-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.qr-text strong { font-size: 21px; }
.share-status { font-size: 14px; color: #555; overflow-wrap: anywhere; }
.share-status.ok { color: #13834a; }
.share-status.warn { color: #a65d00; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; flex: 1 1 280px; max-width: 420px; align-content: center; }
.result-actions #doneBtn { grid-column: 1 / -1; }
.result-actions #printBtn[hidden] + #retakeBtn { grid-column: 1 / -1; }
.reset-note { color: var(--muted); font-size: 14px; text-align: center; min-height: 1.2em; flex: none; }

/* ---------- Video mode ---------- */
.mode-switch { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); flex: none; }
.mode-switch button { min-height: 52px; border: 0; border-radius: 999px; background: transparent; font-weight: 700; font-size: 16px; cursor: pointer; }
.mode-switch button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.booth[data-kind="photo"] .video-only,
.booth[data-kind="video"] .photo-only,
.booth[data-kind="gif"] .video-only,
.booth[data-kind="gif"] .photo-only { display: none !important; }
.countdown .burst { font-size: .5em; animation: pop .25s ease-out; }
.countdown .burst small { font-size: .4em; color: #fffc; }
.result-media img.gif { image-rendering: auto; min-width: min(360px, 100%); }
.effects { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.effects .chip { flex-direction: row; justify-content: flex-start; gap: 10px; padding: 8px 12px; text-align: left; }
.effects .fx-ico { font-size: 26px; line-height: 1; }
.effects .chip small { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
.rec-badge { position: absolute; top: 14px; left: 14px; display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.55); color: #fff; padding: 6px 14px; border-radius: 999px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #ff3b30; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.rec-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; background: rgba(0,0,0,.4); }
.rec-bar > div { height: 100%; width: 0; background: #ff3b30; }
.processing { position: absolute; inset: 0; background: rgba(8,8,12,.78); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; padding: 20px; }
.proc-title { font-size: 24px; font-weight: 800; }
.proc-bar { width: min(320px, 70%); height: 10px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.proc-bar > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.proc-spin { width: 48px; height: 48px; border: 4px solid var(--panel-2); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Dialogs ---------- */
.dlg {
  border: 1px solid var(--line); border-radius: 22px; padding: 0;
  background: var(--bg-2); color: var(--text);
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  -webkit-user-select: text; user-select: text;
}
.dlg::backdrop { background: rgba(0,0,0,.7); backdrop-filter: blur(4px); }
.dlg form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.dlg-small { width: min(380px, calc(100vw - 32px)); }
.dlg-small form { padding: 24px; gap: 16px; }
.dlg-small h2 { margin: 0; }
.dlg-wide { width: min(1100px, calc(100vw - 32px)); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.dlg-head h2 { margin: 0; font-size: 22px; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.dlg-body { overflow: auto; padding: 8px 22px 22px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 12px; padding: 16px 22px; border-top: 1px solid var(--line); }
.dlg-small .dlg-actions { padding: 0; border: 0; }
fieldset { border: 1px solid var(--line); border-radius: 14px; margin: 16px 0 0; padding: 12px 16px 16px; display: grid; gap: 12px; }
legend { padding: 0 8px; font-weight: 700; color: var(--accent); }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 600; }
label.check { display: flex; align-items: center; gap: 12px; color: var(--text); font-size: 16px; min-height: 44px; }
label.check input { width: 26px; height: 26px; accent-color: var(--accent); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), select {
  min-height: 52px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 17px; width: 100%;
}
input[type="color"] { width: 100%; height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); padding: 4px; }
.pin-input { text-align: center; font-size: 28px !important; letter-spacing: .4em; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.hint strong { color: var(--text); }
.err-text { color: var(--danger); font-weight: 600; }

/* Logo / overlay / music uploads */
:root { --checker: repeating-conic-gradient(#2a2a35 0 25%, #1f1f28 0 50%); }
.asset { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.asset-thumb { width: 64px; height: 64px; border-radius: 8px; background-color: #1f1f28; background-image: var(--checker); background-size: 16px 16px; }
.asset.has .asset-thumb { background-size: contain, 16px 16px; background-repeat: no-repeat, repeat; background-position: center, 0 0; }
.asset[data-slot="music"] .asset-thumb { display: grid; place-items: center; background: var(--panel-2); }
.asset[data-slot="music"] .asset-thumb::after { content: "♪"; font-size: 30px; color: var(--muted); }
.asset.has[data-slot="music"] .asset-thumb::after { color: var(--accent); }
.asset-info { display: grid; gap: 2px; min-width: 0; color: var(--text); font-size: 15px; }
.asset-name { overflow-wrap: anywhere; }
.asset.has .asset-name { color: var(--ok); }
.asset-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.asset-btns .btn { min-height: 44px; font-size: 14px; padding: 0 14px; }
.asset-btns label.btn { display: inline-flex; color: var(--text); cursor: pointer; }
#musicPreview { width: 100%; }
@media (max-width: 560px) {
  .asset { grid-template-columns: 56px 1fr; }
  .asset-thumb { width: 56px; height: 56px; }
  .asset-btns { grid-column: 1 / -1; justify-content: flex-start; }
}
.err-text:empty { display: none; }

/* Account sign-in + event picker */
.acct-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.acct-actions .btn[hidden] { display: none; }
.acct-adv summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; }
.acct-adv label { margin-top: 10px; }
.ev-list { display: grid; gap: 8px; max-height: 50vh; overflow: auto; }
.ev-opt { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); cursor: pointer; color: var(--text); }
.ev-opt:has(input:checked) { border-color: var(--accent); }
.ev-opt input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.ev-opt span { display: grid; gap: 2px; font-size: 16px; }
.ev-opt small { color: var(--muted); font-size: 13px; font-weight: 500; }
.ev-opt small b { color: var(--ok); }

.gallery-grid { overflow: auto; padding: 20px 22px; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 18px; max-height: calc(100vh - 140px); }
.g-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.g-card img { width: 100%; aspect-ratio: 1/3; object-fit: cover; border-radius: 6px; background: #000; }
.g-meta { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.g-badge { font-size: 12px; font-weight: 700; }
.g-badge.ok { color: var(--ok); } .g-badge.wait { color: var(--accent); } .g-badge.off { color: var(--muted); }
.g-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.g-actions .btn { min-height: 44px; font-size: 14px; padding: 0 8px; }
.g-empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 60px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-b)); transform: translate(-50%, 30px);
  background: var(--panel-2); border: 1px solid var(--line); padding: 14px 22px; border-radius: 999px;
  opacity: 0; transition: .25s; z-index: 50; pointer-events: none; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Portrait / small ---------- */
@media (orientation: portrait), (max-width: 860px) {
  .booth.active { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; gap: 16px; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); }
  .side { max-height: 48vh; }
  .booth[data-mode="shooting"] .side { max-height: 30vh; }
  .countdown { font-size: clamp(110px, 30vw, 300px); }
  .side-inner { overflow: auto; }
  .thumbs { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 480px) {
  #qrCanvas, .qr-placeholder { width: 112px; height: 112px; }
  .qr-text strong { font-size: 18px; }
  .btn-hero { padding: 0 32px; font-size: 24px; }
}

/* ---------- Print: one 4x6 sheet ---------- */
.print-area { display: none; }
@page { size: 4in 6in; margin: 0; }
@media print {
  html, body { background: #fff !important; overflow: visible; height: auto; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; width: 4in; height: 6in; margin: 0; padding: 0; }
  .print-area img { width: 4in; height: 6in; display: block; }
}
