:root {
  --indigo: #4F46E5;
  --indigo-light: #818CF8;
  --ink: #3730a3;
  --grad: linear-gradient(135deg, #4F46E5 0%, #818CF8 100%);
  --grad-soft: linear-gradient(135deg, #a5b4fc 0%, #818CF8 100%);
  --wa: #25D366;
  --stage-h: calc(100vh - 190px);
  --media-h: 52vh;
}
@supports (height: 100dvh) {
  :root { --stage-h: calc(100dvh - 190px); }
}

.hidden { display: none !important; }

* { -webkit-tap-highlight-color: transparent; }

html, body { min-height: 100%; }

body {
  font-family: 'Outfit', system-ui, sans-serif;
  color: #1e1b4b;
  background: linear-gradient(160deg, #e0f2fe 0%, #e0f7ef 45%, #dbeafe 100%);
  background-attachment: fixed;
}

/* Dekorasi latar: blob & cincin biru transparan */
.bg-deco { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.bg-deco span { position: absolute; border-radius: 9999px; }
.bg-deco .blob1 { width: 420px; height: 420px; top: -140px; right: -120px; background: radial-gradient(circle at 30% 30%, rgba(96,165,250,.55), rgba(59,130,246,.15) 70%); filter: blur(2px); }
.bg-deco .blob2 { width: 360px; height: 360px; bottom: -140px; left: -110px; background: radial-gradient(circle at 60% 40%, rgba(129,140,248,.5), rgba(79,70,229,.12) 70%); }
.bg-deco .ring1 { width: 220px; height: 220px; top: 18%; left: -70px; border: 34px solid rgba(59,130,246,.18); }
.bg-deco .ring2 { width: 170px; height: 170px; bottom: 12%; right: -50px; border: 28px solid rgba(96,165,250,.22); }
.bg-deco .ring3 { width: 90px; height: 90px; top: 8%; left: 55%; border: 16px solid rgba(129,140,248,.18); }

/* Kartu & tombol */
.card { background: #fff; border-radius: 28px; box-shadow: 0 18px 50px -18px rgba(49,46,129,.35), 0 4px 14px -6px rgba(49,46,129,.12); }
.title { color: var(--ink); font-weight: 800; text-align: center; line-height: 1.15; letter-spacing: -.01em; }
.hint-wide { display: none; }
@media (min-width: 640px) { .hint-wide { display: block; } }
.subtitle { text-align: center; color: #64748b; margin-top: .5rem; font-size: clamp(.9rem, .85rem + .25vw, 1.05rem); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 56px; padding: 0 1.5rem; border-radius: 16px; font-weight: 700; font-size: 1.05rem; transition: transform .12s ease, box-shadow .2s ease, opacity .2s; user-select: none; cursor: pointer; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 10px 24px -10px rgba(79,70,229,.8); }
.btn-soft { background: var(--grad-soft); color: #fff; box-shadow: 0 10px 24px -12px rgba(129,140,248,.9); }
.btn-ghost { background: #fff; color: var(--ink); border: 2px solid #e0e7ff; }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-wa { background: var(--wa); color: #fff; box-shadow: 0 10px 24px -10px rgba(37,211,102,.85); }
.btn-wa:hover { background: #1ebe5a; }
.btn-sm { min-height: 40px; padding: 0 1rem; font-size: .9rem; border-radius: 12px; }

.btn-back, .btn-icon { width: 44px; height: 44px; border-radius: 9999px; display: inline-flex; align-items: center; justify-content: center; background: rgba(129,140,248,.25); color: var(--indigo); transition: background .2s; }
.btn-back:hover, .btn-icon:hover { background: rgba(129,140,248,.4); }
.btn-icon .ico-off, .btn-icon.muted .ico-on { display: none; }
.btn-icon.muted .ico-off { display: block; }
.btn-icon.muted { background: #fee2e2; color: #b91c1c; }

/* Layar (state machine) */
.app { position: relative; z-index: 1; width: 100%; max-width: 480px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; }
.screen { display: none; flex: 1; flex-direction: column; gap: 16px; width: 100%; min-width: 0; }
.screen.narrow { max-width: 600px; margin: 0 auto; }
.screen.active { display: flex; animation: screenIn .35s ease both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }

.screen-head { position: relative; padding: 28px 20px 24px; }
.screen-head .btn-back { position: absolute; left: 14px; top: 14px; }
.screen-head .title { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.5rem); }
.studio-logo { display: block; max-height: clamp(56px, 11vh, 110px); max-width: 70%; margin: -12px auto 10px; object-fit: contain; }
.studio-name { text-align: center; font-weight: 700; color: #6366f1; letter-spacing: .14em; text-transform: uppercase; font-size: clamp(.8rem, .75rem + .3vw, 1rem); margin-bottom: .35rem; }
.hero-band { background: linear-gradient(180deg, rgba(165,180,252,.55), rgba(255,255,255,0) 90%); border-radius: 28px 28px 0 0; height: 56px; margin: -28px -20px 8px; }

/* Daftar kamera */
.cam-item { width: 100%; text-align: center; padding: 14px 18px; border-radius: 9999px; background: #fff; border: 2px solid #eef2ff; box-shadow: 0 4px 12px -6px rgba(49,46,129,.25); color: #4338ca; font-size: .95rem; position: relative; transition: all .15s; }
.cam-item.selected { font-weight: 700; border-color: #a5b4fc; }
.cam-item.selected::before { content: ''; position: absolute; left: 22px; top: 50%; width: 10px; height: 10px; margin-top: -5px; border-radius: 9999px; background: #22c55e; box-shadow: 0 0 0 4px rgba(34,197,94,.18); }

/* Tombol kamera bulat besar */
.shutter { width: clamp(130px, min(48vw, 32vh), 260px); height: clamp(130px, min(48vw, 32vh), 260px); border-radius: 9999px; background: radial-gradient(circle at 50% 40%, #a5b4fc, #6366f1 70%); box-shadow: 0 0 0 16px rgba(165,180,252,.45), 0 24px 50px -16px rgba(79,70,229,.7); display: flex; align-items: center; justify-content: center; color: #fff; transition: transform .15s; animation: pulse 2.4s ease-in-out infinite; }
.shutter svg { width: 44%; height: 44%; }
.shutter:hover { transform: scale(1.03); }
.shutter:active { transform: scale(.95); }
.start-body { flex: 1; display: flex; flex-direction: column; gap: 16px; }
.start-label { font-size: clamp(1.4rem, 1.1rem + 1.2vw, 2.1rem); font-weight: 800; color: var(--ink); }

/* Form */
.field-label { font-weight: 700; color: var(--ink); font-size: 1.05rem; }
.field { width: 100%; min-height: 60px; padding: 0 18px; border-radius: 16px; border: 2px solid #e0e7ff; background: #f8faff; font-size: 1.25rem; font-weight: 600; color: #1e1b4b; transition: border-color .15s, box-shadow .15s; }
.field:focus { outline: none; border-color: var(--indigo-light); box-shadow: 0 0 0 4px rgba(129,140,248,.25); background: #fff; }
.field-error { color: #b91c1c; font-size: .9rem; margin-top: -4px; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 16px rgba(165,180,252,.45), 0 24px 50px -16px rgba(79,70,229,.7); } 50% { box-shadow: 0 0 0 26px rgba(165,180,252,.25), 0 24px 50px -16px rgba(79,70,229,.7); } }

/* Carousel template */
.carousel-wrap { position: relative; }
.carousel { --card-w: min(72vw, 300px); display: flex; gap: 16px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 12px 0 18px; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; scrollbar-width: none; outline: none; }
.carousel::-webkit-scrollbar { display: none; }
.carousel::before, .carousel::after { content: ''; flex: 0 0 calc(50% - var(--card-w) / 2 - 16px); }
.carousel.free { scroll-snap-type: none; }
.carousel.dragging { cursor: grabbing; user-select: none; }
.carousel.dragging .tpl-card { pointer-events: none; }
.tpl-card { flex: 0 0 var(--card-w); scroll-snap-align: center; background: #fff; border-radius: 24px; padding: 14px; border: 3px solid transparent; box-shadow: 0 10px 30px -14px rgba(49,46,129,.4); transition: border-color .25s, transform .35s cubic-bezier(.2,.8,.2,1), opacity .35s; text-align: center; transform: scale(.94); opacity: .7; user-select: none; }
.tpl-card.selected { border-color: var(--indigo-light); transform: scale(1); opacity: 1; }
.tpl-card .thumb { height: clamp(200px, 36vh, 400px); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.tpl-card canvas, .tpl-card img { max-width: 100%; max-height: 100%; border-radius: 6px; box-shadow: 0 4px 14px -6px rgba(0,0,0,.35); }
.carousel-nav { display: none; position: absolute; top: 50%; transform: translateY(-60%); z-index: 2; width: 54px; height: 54px; border-radius: 9999px; background: #fff; color: var(--indigo); align-items: center; justify-content: center; box-shadow: 0 10px 24px -10px rgba(49,46,129,.55); transition: opacity .2s, transform .15s; }
.carousel-nav:hover:not(:disabled) { transform: translateY(-60%) scale(1.08); }
.carousel-nav:disabled { opacity: .3; cursor: default; }
.carousel-nav.prev { left: 0; }
.carousel-nav.next { right: 0; }
.dots { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 9999px; background: #c7d2fe; transition: width .25s, background .25s; }
.dot.selected { width: 28px; background: var(--indigo); }
.bottom-bar { margin-top: auto; width: 100%; }
@media (hover: hover) and (pointer: fine) {
  .carousel { cursor: grab; }
}
@media (hover: hover) and (pointer: fine), (min-width: 768px) {
  .carousel-nav { display: flex; }
}

/* Sesi foto */
.stage { position: relative; margin: 0 auto; width: 100%; max-height: var(--stage-h); border-radius: 24px; overflow: hidden; background: #0f172a; }
.stage video { display: block; width: 100%; height: 100%; object-fit: contain; transform: scaleX(-1); }
.guide { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); border: 3px dashed rgba(255,255,255,.9); border-radius: 6px; box-shadow: 0 0 0 9999px rgba(15,23,42,.5); transition: width .3s, height .3s; }
.countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: clamp(5rem, 14vmin, 11rem); font-weight: 800; color: #fff; text-shadow: 0 6px 30px rgba(0,0,0,.45); pointer-events: none; }
.countdown.tick { animation: tick 1s ease-out both; }
@keyframes tick { from { transform: scale(1.6); opacity: 0; } 25% { opacity: 1; transform: scale(1); } to { opacity: .2; transform: scale(.85); } }
.flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 50; }
.flash.go { animation: flash .5s ease-out; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
.progress-pill { align-self: center; background: #fff; color: var(--ink); font-weight: 700; padding: 8px 18px; border-radius: 9999px; box-shadow: 0 6px 16px -8px rgba(49,46,129,.4); }

.cam-preview { position: relative; border-radius: 20px; overflow: hidden; background: #0f172a; aspect-ratio: 16/9; }
.cam-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }

/* Tinjau & hasil: 1 kolom di mobile, 2 kolom di desktop / tablet landscape */
.split { flex: 1; display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.split-media { display: flex; justify-content: center; align-items: center; min-width: 0; }
.split-side { display: flex; flex-direction: column; gap: 14px; flex: 1; }
.review-img { max-height: 40vh; max-width: 100%; border-radius: 10px; box-shadow: 0 10px 30px -12px rgba(30,27,75,.45); background: #fff; }
.print-preview { max-height: 45vh; max-width: 100%; background: #fff; box-shadow: 0 10px 30px -12px rgba(30,27,75,.45); border-radius: 4px; }

.polaroid { background: #fff; padding: 12px 12px 36px; border-radius: 6px; box-shadow: 0 24px 50px -18px rgba(30,27,75,.55); transform: rotate(-3deg); max-width: 78%; margin: 8px auto; animation: drop .6s cubic-bezier(.2,.9,.3,1.2) both; }
.polaroid img { display: block; width: 100%; max-height: var(--media-h); object-fit: contain; }
@keyframes drop { from { opacity: 0; transform: translateY(-30px) rotate(-10deg); } to { opacity: 1; transform: rotate(-3deg); } }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: auto; }
.actions > #btnPrint, .actions .span-all { grid-column: 1 / -1; }
.actions.has-wa > #btnPrint { grid-column: auto; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.thumb-item { background: #fff; border-radius: 16px; padding: 6px; text-align: center; box-shadow: 0 6px 14px -8px rgba(49,46,129,.35); }
.thumb-item canvas { width: 100%; height: 72px; object-fit: cover; border-radius: 10px; background: #e0e7ff; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 70; width: 90%; max-width: 440px; text-align: center; box-shadow: 0 16px 40px -16px rgba(30,27,75,.5); }

/* Tablet */
@media (min-width: 640px) {
  .app { max-width: 760px; padding: 24px; }
  .carousel { --card-w: 280px; }
  .thumbs { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .thumb-item canvas { height: 90px; }
  .polaroid { max-width: 60%; }
}

/* Desktop & tablet landscape: 2 kolom */
@media (min-width: 1024px), (min-width: 768px) and (orientation: landscape) {
  .app { max-width: 1180px; padding: 24px 32px; }
  .carousel { --card-w: 290px; -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 7%, #000 93%, transparent 100%); mask-image: linear-gradient(90deg, transparent 0, #000 7%, #000 93%, transparent 100%); }
  .carousel-nav.prev { left: 8px; }
  .carousel-nav.next { right: 8px; }
  .bottom-bar { max-width: 440px; margin-left: auto; margin-right: auto; }
  .split { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr); gap: 32px; align-items: center; }
  .split-side { flex: none; }
  .actions { margin-top: 0; }
  .actions .btn { min-height: 64px; font-size: 1.15rem; }
  .review-img { max-height: calc(100vh - 230px); }
  .polaroid { max-width: 82%; }
  :root { --media-h: calc(100vh - 290px); }
}
@media (min-width: 1440px) {
  .carousel { --card-w: 320px; }
  .tpl-card .thumb { height: clamp(260px, 40vh, 460px); }
}

/* Layar pendek (HP landscape) */
@media (max-height: 520px) and (orientation: landscape) {
  .app { padding-top: 10px; padding-bottom: 10px; }
  .screen { gap: 10px; }
  .screen-head { padding: 14px 20px 14px; }
  .hero-band { display: none; }
  .studio-logo { margin-top: 0; max-height: 48px; }
  .tpl-card .thumb { height: 42vh; }
  .screen-head .title { font-size: 1.45rem; }
  .start-body { display: grid; grid-template-columns: 1.3fr 1fr; align-items: center; }
  .start-body .flex-1 { padding: 0; gap: 10px; }
  .shutter { width: 130px; height: 130px; }
  .review-img { max-height: calc(100vh - 140px); }
  .split { gap: 20px; }
  .actions { gap: 8px; }
  .actions .btn { min-height: 50px; font-size: .95rem; padding: 0 .75rem; }
  :root { --stage-h: calc(100vh - 120px); --media-h: calc(100vh - 150px); }
}
@media (max-width: 639px) {
  :root { --media-h: 44vh; }
  .polaroid { padding: 10px 10px 28px; }
}
.actions .btn { white-space: nowrap; }

/* Admin: tabel pengunjung */
.visits-table th { text-align: left; padding: 12px 14px; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: #64748b; background: #f8fafc; white-space: nowrap; }
.visits-table td { padding: 12px 14px; border-top: 1px solid #eef2ff; white-space: nowrap; color: #334155; }
@media (max-width: 767px) {
  .visits-table thead { display: none; }
  .visits-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; padding: 14px 16px; border-top: 1px solid #eef2ff; }
  .visits-table td { border: 0; padding: 0; white-space: normal; }
  .visits-table td::before { content: attr(data-label); display: block; color: #94a3b8; font-size: .7rem; text-transform: uppercase; }
  .admin-nav { width: 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .admin-nav > * { flex: none; }
}

.spinner { width: 54px; height: 54px; border-radius: 9999px; border: 6px solid #e0e7ff; border-top-color: var(--indigo); animation: spin 1s linear infinite; }
.spinner-sm { width: 20px; height: 20px; border-width: 3px; border-color: rgba(255,255,255,.4); border-top-color: #fff; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.alert { border-radius: 16px; padding: 12px 16px; font-size: .95rem; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-ok { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.alert-info { background: #eef2ff; color: #3730a3; border: 1px solid #c7d2fe; }

/* Latar kotak-kotak transparansi */
.checker { background-color: #fff; background-image: linear-gradient(45deg, #e5e7eb 25%, transparent 25%), linear-gradient(-45deg, #e5e7eb 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e5e7eb 75%), linear-gradient(-45deg, transparent 75%, #e5e7eb 75%); background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0; }

/* Area cetak: hanya tampil saat print */
#printArea { display: none; }
@media print {
  html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; position: absolute; left: 0; top: 0; margin: 0; padding: 0; overflow: hidden; }
  #printArea img { display: block; margin: 0; padding: 0; }
}
