:root {
  --bg: #0b0f19;
  --panel: rgba(255, 255, 255, 0.05);
  --panel2: rgba(255, 255, 255, 0.09);
  --accent: #007aff; /* iOS Blue */
  --accent-hover: #1a8cff;
  --accent2: #34c759; /* iOS Green */
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.55);
  --danger: #ff3b30; /* iOS Red */
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

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

[hidden] {
  display: none !important;
}

html, body { height: 100vh; width: 100vw; overflow: hidden; }

body {
  background: var(--bg);
  background-image: 
    radial-gradient(circle at 10% 10%, rgba(0, 122, 255, 0.12) 0%, transparent 40%),
    radial-gradient(circle at 90% 90%, rgba(52, 199, 89, 0.08) 0%, transparent 40%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

/* ===== Welcome ===== */
.welcome {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: 
    linear-gradient(rgba(11, 15, 25, 0.7), rgba(11, 15, 25, 0.85)),
    url('https://images.unsplash.com/photo-1542038784456-1ea8e935640e?q=80&w=1600&auto=format&fit=crop') no-repeat center center;
  background-size: cover;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.welcome.hide { opacity: 0; pointer-events: none; transform: scale(1.05); }

.welcome-inner { 
  max-width: 580px; 
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 28px;
  padding: 40px 30px;
  box-shadow: var(--glass-shadow);
}

.wlogo {
  font-size: 80px;
  line-height: 1;
  margin-bottom: 20px;
  filter: drop-shadow(0 10px 30px rgba(0, 122, 255, 0.4));
}

.welcome h1 {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -0.8px;
  background: linear-gradient(135deg, #ffffff 30%, rgba(255, 255, 255, 0.7));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 12px;
}

.wtag { color: var(--muted); font-size: 15px; line-height: 1.6; margin-bottom: 32px; }

.wsteps {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 32px;
}

.wstep {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  padding: 16px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}

.wstep span {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.wfoot { color: var(--muted); font-size: 12px; margin-top: 18px; }

/* ===== App Main & Header ===== */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.topbar h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.5px; }

.timer {
  background: rgba(255, 59, 48, 0.15);
  border: 1px solid rgba(255, 59, 48, 0.3);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #ff453a;
  padding: 6px 14px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 13px;
  animation: pulse 1s infinite alternate;
  display: flex;
  align-items: center;
  gap: 6px;
}

@keyframes pulse {
  0% { transform: scale(1); }
  100% { transform: scale(1.04); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.steps { display: flex; align-items: center; gap: 8px; font-size: 12px; }

.steps .step {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 6px 14px;
  border-radius: 999px;
  white-space: nowrap;
  font-weight: 500;
}

.steps .step.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.steps .sep { color: rgba(255, 255, 255, 0.25); }

/* ===== Layout Wrap ===== */
.wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  backdrop-filter: blur(30px) saturate(160%);
  -webkit-backdrop-filter: blur(30px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 28px;
  box-shadow: var(--glass-shadow);
  width: 100%;
  max-width: 1100px;
  height: 100%;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel h2 { 
  font-size: 18px; 
  font-weight: 700; 
  margin-bottom: 20px; 
  letter-spacing: -0.3px; 
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 12px;
  flex-shrink: 0;
}

/* ===== QRIS Payment Panel ===== */
.qris-panel {
  max-width: 480px;
  margin: 0 auto;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.qris-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-height: 0;
  justify-content: center;
}

.qris-card {
  background: #ffffff;
  border-radius: 20px;
  padding: 20px;
  width: 240px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #000000;
}

.qris-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #f2f2f7;
  padding-bottom: 8px;
  margin-bottom: 14px;
}

.qris-header h3 {
  font-size: 22px;
  font-weight: 800;
  color: #00254d;
  letter-spacing: 1px;
}

.qris-gpn {
  background: #ff3b30;
  color: #ffffff;
  font-size: 9px;
  font-weight: 900;
  padding: 2px 6px;
  border-radius: 4px;
}

.qris-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.qris-svg {
  background: #ffffff;
  padding: 8px;
  border: 1px solid #e5e5ea;
  border-radius: 12px;
  margin-bottom: 12px;
}

.qris-merchant {
  font-size: 12px;
  font-weight: 700;
  color: #3a3a3c;
}

.qris-amount {
  font-size: 20px;
  font-weight: 800;
  color: #000000;
  margin-top: 4px;
}

.qris-info {
  text-align: center;
  width: 100%;
}

.status-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: 12px;
}

.progress-bar-container {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 18px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent2);
  transition: width 0.1s linear;
}

.qris-info .desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 20px;
}

/* ===== Step Columns (Layout split for Frame / Camera) ===== */
.panel-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 28px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

/* ===== Frame Panel Layout ===== */
.frame-left-preview {
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  padding: 16px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.frame-left-preview img {
  max-height: 100%;
  max-width: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.frame-options {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding-right: 4px;
}

/* ===== Camera Panel Layout ===== */
.camera-box {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 20px;
  overflow: hidden;
  background: #000000;
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  max-height: 70%;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#video.flip { transform: scaleX(1); }

.flash {
  position: absolute;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
}

.flash.on { animation: flashanim 0.3s ease-out; }

@keyframes flashanim {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

.frame-hint {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #ffffff;
  font-size: 12px;
  font-weight: 500;
  padding: 8px 18px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.scanline {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 2px var(--accent);
  border-radius: 20px;
}

.countdown {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 110px;
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 0 30px rgba(0, 122, 255, 0.7);
  pointer-events: none;
}

.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
}

.camera-controls-column {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  gap: 16px;
  min-height: 0;
}

/* Slots for captured photos */
.slots {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.slot {
  flex: 1;
  aspect-ratio: 16 / 10;
  border-radius: 14px;
  border: 2px dashed rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  position: relative;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.02);
  transition: all 0.25s ease;
}

.slot span {
  font-size: 20px;
  font-weight: 700;
  color: var(--muted);
}

.slot em { font-style: normal; font-size: 11px; color: var(--muted); }

.slot.filled {
  border-style: solid;
  border-color: var(--accent2);
}

.slot.filled img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.slot.filled span {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  color: #ffffff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
  min-height: 48px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { background: rgba(255, 255, 255, 0.15); border-color: rgba(255, 255, 255, 0.25); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
}

.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.big { padding: 16px 36px; font-size: 17px; min-height: 54px; border-radius: 18px; }

.btn.full { width: 100%; }

/* ===== Fields & Inputs ===== */
.field { display: block; }

.field > span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.seg {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  padding: 4px;
  gap: 4px;
}

.seg button {
  flex: 1;
  background: transparent;
  color: var(--text);
  border: none;
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.seg button.active {
  background: var(--accent);
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

/* ===== Frame Picker ===== */
.frame-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.frame-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 8px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.frame-card:hover { border-color: rgba(255, 255, 255, 0.25); background: rgba(255, 255, 255, 0.06); }
.frame-card:active { transform: scale(0.96); }

.frame-card.selected {
  border-color: var(--accent2);
  background: rgba(52, 199, 89, 0.08);
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.2);
}

.frame-card.loading { opacity: 0.35; pointer-events: none; }

.frame-card .thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
  display: flex;
}

.frame-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.frame-card em {
  font-style: normal;
  font-size: 12px;
  font-weight: 600;
}

/* ===== Result Panel ===== */
.result-panel {
  max-width: 600px;
  margin: 0 auto;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.result-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.print-area {
  background: #ffffff;
  border-radius: 20px;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid var(--glass-border);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.print-area img {
  max-height: 100%;
  max-width: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  border-radius: 6px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  margin-top: 14px;
  text-align: center;
}

.foot {
  text-align: center;
  color: rgba(255, 255, 255, 0.25);
  font-size: 11px;
  padding: 16px;
  flex-shrink: 0;
}

/* ===== Responsive layout ===== */
@media (max-width: 860px) {
  html, body { overflow: auto; }
  .panel-grid { grid-template-columns: 1fr; }
  .wsteps { grid-template-columns: 1fr; }
  .wrap { padding: 16px; }
  .topbar { padding: 12px 16px; flex-direction: column; align-items: stretch; gap: 10px; }
  .topbar h1 { text-align: center; }
  .topbar .steps { justify-content: center; overflow-x: auto; padding-bottom: 4px; }
  .timer { align-self: center; }
}

/* ===== Print Styles (Optimized for Continuous Thermal Roll Paper - No Margin) ===== */
@media print {
  @page {
    margin: 0 !important;
    size: auto; /* Allow dynamic continuous height for roll paper */
  }
  
  html, body {
    height: auto !important;
    width: 100% !important;
    overflow: visible !important;
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body.printing * {
    visibility: hidden;
  }

  body.printing .print-area,
  body.printing .print-area img {
    visibility: visible;
  }

  body.printing .print-area {
    position: absolute;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff;
    box-shadow: none;
    border: none;
  }

  body.printing .print-area img {
    width: 100% !important;
    height: auto !important;
    max-width: 100% !important;
    box-shadow: none;
    margin: 0 !important;
    padding: 0 !important;
    display: block;
  }
}