:root {
  --bg: #0b1f3a;
  --bg2: #12325c;
  --fg: #ffffff;
  --muted: #a9bad3;
  --accent: #f2b33d;
  --ok: #2fbf71;
  --err: #e5484d;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: #0d2a6e url("img/bg.jpg") center top / cover no-repeat;
  color: var(--fg);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;          /* tanpa zoom double-tap di tablet */
  overscroll-behavior: none;           /* tanpa pull-to-refresh */
  cursor: default;
}
.top { padding-top: calc(20px + env(safe-area-inset-top)) !important; }

/* ===================== LAYAR ===================== */
/* --hero = tinggi area gambar kuda di atas; konten mulai di bawahnya */
#screen { --hero: max(27vh, 45vw); position: relative; height: 100vh; height: 100dvh; display: flex; flex-direction: column; text-shadow: 0 2px 10px rgba(0, 10, 40, .55); }
.top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; padding: 20px 32px; z-index: 1; }
.event-name { font-size: 28px; font-weight: 700; letter-spacing: .5px; color: var(--accent); }
.event-sub { font-size: 16px; color: #dbe6f7; }
.clock { font-size: 32px; font-weight: 300; font-variant-numeric: tabular-nums; }

.panel { flex: 1; display: none; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: var(--hero) 32px 0; }
.panel > * { max-width: 100%; }

/* Layar landscape: gambar dilebarkan penuh & digeser agar kuda tetap di atas */
@media (orientation: landscape) {
  /* gambar utama dikecilkan agar kuda tidak menutupi konten; sisi kiri-kanan diisi versi blur */
  body { background: #0d2a6e; }
  body::before, body::after { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; }
  body::before { background: url("img/bg.jpg") center 65% / cover no-repeat; filter: blur(28px) brightness(.85); transform: scale(1.08); }
  body::after {
    background: url("img/bg.jpg") center -14vh / auto 185vh no-repeat;
    -webkit-mask-image: linear-gradient(to right, transparent calc(50% - 54vh), #000 calc(50% - 38vh), #000 calc(50% + 38vh), transparent calc(50% + 54vh));
            mask-image: linear-gradient(to right, transparent calc(50% - 54vh), #000 calc(50% - 38vh), #000 calc(50% + 38vh), transparent calc(50% + 54vh));
  }
  #screen { --hero: 34vh; }
  .panel h1 { font-size: clamp(24px, 4.2vh, 40px); margin-top: 1.5vh; }
  .scan-icon svg { width: 13vh; height: 13vh; }
  .seat-number { font-size: clamp(80px, 17vh, 180px) !important; margin: 0 0 2vh !important; }
  .person-name { font-size: clamp(24px, 4vh, 40px) !important; }
  .print-status { margin-top: 2vh !important; }
}
.state-standby .panel-standby,
.state-ready .panel-ready,
.state-loading .panel-loading,
.state-success .panel-success,
.state-error .panel-error { display: flex; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h1 { font-size: 40px; margin: 24px 0 8px; font-weight: 600; }
.hint { font-size: 20px; color: var(--muted); margin: 0; }

.scan-icon { position: relative; color: var(--accent); }
.scan-line { position: absolute; left: 8%; right: 8%; height: 3px; background: var(--accent); box-shadow: 0 0 12px var(--accent); top: 15%; animation: scan 2s ease-in-out infinite alternate; }
@keyframes scan { to { top: 82%; } }

/* Pratinjau kamera: melayang di pojok kanan bawah, tetap aktif di semua layar */
.camera-box {
  position: fixed; z-index: 4;
  right: calc(24px + env(safe-area-inset-right)); bottom: calc(24px + env(safe-area-inset-bottom));
  width: clamp(180px, 22vmin, 280px); aspect-ratio: 1;
  border-radius: 16px; overflow: hidden; background: #000;
  border: 3px solid var(--accent); box-shadow: 0 8px 30px rgba(0,0,0,.45);
}
#camera-box { width: 100%; height: 100%; }
.camera-box video { width: 100% !important; height: 100% !important; object-fit: cover; }
.camera-box img[alt="Info icon"], .camera-box #qr-shaded-region { display: none !important; }

.standby-icon { color: var(--accent); opacity: .9; animation: breathe 3s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .45; } }
.panel-standby h1 { font-size: clamp(30px, 5vmin, 56px); max-width: 900px; }
.panel-standby .hint { font-size: clamp(18px, 2.6vmin, 26px); max-width: 800px; color: #dbe6f7; }

.spinner { width: 72px; height: 72px; border: 6px solid rgba(255,255,255,.15); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.seat-label { font-size: 22px; text-transform: uppercase; letter-spacing: 4px; color: var(--muted); }
.seat-number { font-size: 180px; font-weight: 800; line-height: 1; color: var(--accent); margin: 8px 0 24px; }
.person-name { font-size: 40px; font-weight: 700; }
.person-meta { font-size: 24px; color: var(--muted); margin-top: 6px; }
.person-meta.strong { color: var(--fg); }
.print-status { margin-top: 32px; font-size: 20px; color: var(--ok); }

.error-icon { width: 96px; height: 96px; border-radius: 50%; background: var(--err); font-size: 64px; font-weight: 800; display: grid; place-items: center; }

/* Menu bawah tersembunyi; muncul saat mouse/sentuhan di area bawah layar.
   Sengaja pakai opacity (bukan display:none) agar input scanner tetap fokus & menerima scan. */
.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 48px 40px 16px;               /* area atas transparan = zona pemicu hover */
  background: linear-gradient(to top, rgba(4, 14, 44, .85), rgba(4, 14, 44, 0));
  opacity: 0;
  transition: opacity .3s ease .8s;      /* jeda sebelum menghilang */
}
.bottom > * { transform: translateY(14px); transition: transform .3s ease .8s; }
.bottom:hover, .bottom.show { opacity: 1; transition-delay: 0s; }
.bottom:hover > *, .bottom.show > * { transform: none; transition-delay: 0s; }
.bottom { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
#scan-form { flex: 1; }
#scan-input { width: 100%; max-width: 360px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); color: var(--muted); border-radius: 8px; padding: 10px 14px; font-size: 15px; outline: none; }
#scan-input:focus { border-color: rgba(242,179,61,.5); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid rgba(255,255,255,.2); border-radius: 8px; padding: 10px 16px; font-size: 15px; cursor: pointer; }
.btn-ghost.active { color: var(--bg); background: var(--accent); border-color: var(--accent); }
.print-status.fail { color: var(--err); }

.seat-number.pending { font-size: clamp(40px, 7vh, 72px) !important; color: #ffd58a; margin: 16px 0 28px !important; }

/* ---------- Hasil + rute wayfinding ---------- */
.success-info { display: flex; flex-direction: column; align-items: center; }
.state-success .panel-success.has-map {
  display: grid; grid-template-columns: minmax(280px, 36%) 1fr; gap: 28px; align-items: center;
  padding: calc(92px + env(safe-area-inset-top)) 32px 28px;
}
.has-map .seat-number { font-size: clamp(72px, 13vh, 150px) !important; margin-bottom: 12px !important; }
.has-map .person-name { font-size: clamp(22px, 3.2vh, 34px) !important; }
.has-map .person-meta { font-size: clamp(16px, 2.2vh, 22px); }
.success-route {
  align-self: stretch; min-height: 0; display: flex; flex-direction: column; gap: 12px;
  padding: 16px; border-radius: 20px;
  background: rgba(4, 14, 44, .86); border: 1px solid rgba(255, 255, 255, .12);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.wf-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; font-size: 20px; text-align: left; }
.wf-head b { color: var(--accent); }
.wf-stats { color: #dbe6f7; font-size: 17px; }
.success-route .wf-map { flex: 1; min-height: 220px; }
.success-route .wf-steps { max-height: 32%; overflow-y: auto; padding-right: 4px; }
@media (orientation: portrait) {
  .state-success .panel-success.has-map { grid-template-columns: 1fr; grid-template-rows: auto 1fr; gap: 20px; padding-top: calc(var(--hero) - 30px); }
}
#kiosk-loc { padding: 9px 10px; max-width: 220px; }
#kiosk-loc option { color: #000; }
.bt-warning { margin-top: 28px; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 18px 28px; border-radius: 14px; background: rgba(229,72,77,.12); border: 1px solid rgba(229,72,77,.4); font-size: 20px; }
.bt-connect { background: var(--accent); color: #1a1a1a; border: 0; border-radius: 10px; padding: 14px 28px; font-size: 20px; font-weight: 700; cursor: pointer; margin-top: 12px; }
.bt-chip { display: inline-flex; align-items: center; gap: 8px; }
.bt-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--err); }
.bt-chip.on .bt-dot { background: var(--ok); }
.bt-chip.busy .bt-dot { background: var(--accent); animation: blink .8s infinite alternate; }
@keyframes blink { to { opacity: .3; } }
.printer-mode { font-size: 14px; color: var(--muted); }
.btn-icon { display: inline-grid; place-items: center; padding: 8px 10px; text-decoration: none; }
.status-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--ok); }
.status-dot.offline { background: var(--err); }

/* ===================== TIKET (hanya saat print) ===================== */
#ticket { display: none; }

@media print {
  html, body { background: #fff !important; color: #000; height: auto; overflow: visible; }
  #screen { display: none !important; }
  #ticket {
    display: block;
    width: 72mm;                 /* area cetak efektif thermal 80mm */
    margin: 0 auto;
    padding: 3mm 1mm 2mm;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    font-family: Arial, Helvetica, sans-serif;
    color: #000;
    text-align: center;
    page-break-after: avoid;
    page-break-inside: avoid;
  }
  .t-event { font-size: 15pt; font-weight: 800; letter-spacing: .5pt; }
  .t-sub { font-size: 9pt; }
  .t-divider { border-top: 1.2pt dashed #000; margin: 2.5mm 0; }
  .t-seat-label { font-size: 9pt; letter-spacing: 2pt; font-weight: 700; }
  .t-seat { font-size: 48pt; font-weight: 900; line-height: 1.05; }
  .t-seat.len-m { font-size: 38pt; }
  .t-seat.len-l { font-size: 28pt; }
  .t-name { font-size: 13pt; font-weight: 800; line-height: 1.2; }
  .t-name.len-m { font-size: 11pt; }
  .t-name.len-l { font-size: 9.5pt; }
  .t-row { font-size: 9.5pt; margin-top: 1mm; line-height: 1.25; }
  .t-strong { font-weight: 700; }
  .t-footer { display: flex; justify-content: space-between; font-size: 7pt; margin-top: 3mm; }
}
