*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0b1020;
  background-image:
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.12) 0%, transparent 50%),
    radial-gradient(at 100% 100%, rgba(168, 85, 247, 0.10) 0%, transparent 50%);
  background-attachment: fixed;
  color: #f1f5f9;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  font-feature-settings: 'cv11', 'ss01';
  letter-spacing: -0.01em;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- Topbar ---------- */
#topbar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  padding: env(safe-area-inset-top, 0) 0.75rem 0;
  height: calc(60px + env(safe-area-inset-top, 0));
  background: rgba(11, 16, 32, 0.85);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
}
.brand-icon { font-size: 1.2rem; }
.brand-name {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: none;
  background: rgba(255, 255, 255, 0.04);
  color: #cbd5e1;
  cursor: pointer;
  transition: all 0.15s ease;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.10); transform: scale(0.96); }
.icon-btn[hidden] { display: none; }

.net-status {
  display: flex;
  align-items: center;
  padding: 0 0.4rem;
}
.net-status .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
  transition: all 0.2s ease;
}
.net-status.offline .dot {
  background: #ef4444;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

.queue-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.04);
  color: #e2e8f0;
  border: none;
  padding: 0.45rem 0.75rem;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  transition: all 0.15s ease;
}
.queue-btn:active { background: rgba(255, 255, 255, 0.10); transform: scale(0.96); }
.queue-btn.has-items {
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: white;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

/* ---------- Screens ---------- */
#screen-root {
  flex: 1;
  position: relative;
}
.screen {
  display: none;
  flex-direction: column;
  padding: 1.5rem 1.25rem;
  gap: 1.25rem;
  height: 100%;
}
.screen.active { display: flex; }

h1 { font-size: 1.5rem; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; font-weight: 600; margin: 0 0 0.75rem; letter-spacing: -0.01em; }

.muted { color: #94a3b8; }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.error { color: #f87171; min-height: 1.2em; text-align: center; margin: 0.75rem 0 0; font-size: 0.9rem; }

/* ---------- Login ---------- */
.login-box {
  margin: auto;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.login-header { margin-bottom: 1.5rem; }
.login-emoji {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  filter: drop-shadow(0 4px 12px rgba(99, 102, 241, 0.3));
}
.login-box h1 {
  margin: 0 0 0.4rem;
  font-size: 1.75rem;
  background: linear-gradient(135deg, #fff, #cbd5e1);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.pin-display {
  display: flex;
  justify-content: center;
  gap: 0.65rem;
  margin: 1.75rem 0;
}
.pin-display span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  transition: all 0.2s ease;
}
.pin-display span.filled {
  background: linear-gradient(135deg, #6366f1, #a855f7);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.5);
  transform: scale(1.1);
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
}
.pin-pad button {
  font-family: inherit;
  font-size: 1.7rem;
  font-weight: 500;
  padding: 1.05rem;
  background: rgba(255, 255, 255, 0.04);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.pin-pad button:active {
  background: rgba(255, 255, 255, 0.10);
  transform: scale(0.96);
}
.pin-pad button.aux {
  background: transparent;
  color: #94a3b8;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pin-pad button.aux:active { background: rgba(255, 255, 255, 0.05); }

/* ---------- Main screen ---------- */
.hostess-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
}
.hostess-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  color: white;
  flex-shrink: 0;
}
.hostess-name {
  font-weight: 600;
  font-size: 1.05rem;
  margin: 0.1rem 0;
}

.guest-code-box {
  text-align: center;
  padding: 1.5rem 1rem;
  background: rgba(99, 102, 241, 0.08);
  border: 2px solid rgba(99, 102, 241, 0.25);
  border-radius: 20px;
}
.guest-code-box .muted {
  margin-bottom: 0.4rem;
  font-weight: 500;
}
.guest-code {
  font-size: 4rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, #a5b4fc, #f9a8d4);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
}

.copies-box {
  padding: 0;
}
.copies-box label {
  display: block;
  margin-bottom: 0.6rem;
  font-size: 0.9rem;
  color: #94a3b8;
  font-weight: 500;
  text-align: center;
}
.copies-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  padding: 0.5rem;
}
.copies-btn {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  border: none;
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font-size: 1.6rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s ease;
}
.copies-btn:active { background: rgba(255, 255, 255, 0.15); transform: scale(0.94); }
.copies-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.copies-value {
  font-size: 2.2rem;
  font-weight: 700;
  color: white;
  min-width: 60px;
  text-align: center;
}

.big-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 1.15rem;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 600;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: -0.01em;
}
.big-btn:active { transform: scale(0.98); }
.big-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.primary-btn {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
  margin-top: auto;
}
.primary-btn:active:not(:disabled) { box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4); }
.primary-btn:disabled { background: rgba(255, 255, 255, 0.04); color: rgba(255, 255, 255, 0.3); box-shadow: none; }

.success-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.35);
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.04);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.ghost-btn:active { background: rgba(255, 255, 255, 0.08); }

.last-status {
  text-align: center;
  font-size: 0.85rem;
  color: #64748b;
  padding: 0.5rem;
}

/* ---------- Camera screen ---------- */
#screen-camera, #screen-preview {
  position: fixed;
  inset: 0;
  z-index: 50;
  padding: 0;
  background: black;
}
#screen-preview { display: none; flex-direction: column; }
#screen-preview.active { display: flex; }
body.fullscreen-mode #topbar { display: none; }

#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: black;
}

/* Ramka kadrowania — pokazuje obszar który wyjdzie na druku (proporcja 68:44) */
.frame-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.frame-window {
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 6px;
  box-shadow:
    0 0 0 9999px rgba(0, 0, 0, 0.55),
    inset 0 0 0 1px rgba(0, 0, 0, 0.5);
  /* aspect-ratio i wymiary ustawiane z JS po starcie streamu */
}
.frame-window::before,
.frame-window::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border: 3px solid white;
}
.frame-window::before {
  top: -3px;
  left: -3px;
  border-right: none;
  border-bottom: none;
  border-top-left-radius: 6px;
}
.frame-window::after {
  bottom: -3px;
  right: -3px;
  border-left: none;
  border-top: none;
  border-bottom-right-radius: 6px;
}

.camera-overlay {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0) + 1rem);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.5);
  padding: 0.55rem 1.25rem;
  border-radius: 999px;
  z-index: 2;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.camera-info { font-size: 1.1rem; font-weight: 600; }

.camera-controls {
  position: absolute;
  bottom: calc(2rem + env(safe-area-inset-bottom, 0));
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 2;
  padding: 0 1.5rem;
}
.round-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.round-btn:active { transform: scale(0.92); }
.round-btn.ghost {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.round-btn.primary {
  width: 84px;
  height: 84px;
  background: white;
  border: 5px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.85), 0 8px 24px rgba(0, 0, 0, 0.4);
}
.round-btn.primary:active { background: #e5e7eb; }

/* ---------- Preview ---------- */
#preview-img {
  flex: 1;
  object-fit: contain;
  width: 100%;
  min-height: 0;
}
.preview-controls {
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
  background: black;
}
.preview-controls .big-btn { margin-top: 0; }

/* ---------- Queue ---------- */
#queue-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.queue-hint { margin-top: 1rem; }
.queue-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 14px;
}
.queue-item .thumb {
  width: 60px;
  height: 60px;
  border-radius: 10px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}
.queue-item .meta { flex: 1; font-size: 0.9rem; min-width: 0; }
.queue-item .meta strong { color: white; font-size: 1.05rem; font-weight: 600; }
.queue-item .status {
  font-size: 0.7rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.status.pending { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.status.uploading { background: rgba(99, 102, 241, 0.15); color: #a5b4fc; }
.status.failed { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(1.5rem + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%) translateY(2rem);
  background: rgba(30, 41, 59, 0.95);
  color: white;
  padding: 0.85rem 1.35rem;
  border-radius: 12px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 100;
  max-width: 90%;
  font-weight: 500;
  font-size: 0.95rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success {
  background: linear-gradient(135deg, #059669, #047857);
  border-color: rgba(16, 185, 129, 0.4);
}
.toast.error {
  background: linear-gradient(135deg, #b91c1c, #991b1b);
  border-color: rgba(239, 68, 68, 0.4);
}

/* ---------- Install prompt ---------- */
.install-prompt {
  position: fixed;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0));
  left: 1rem;
  right: 1rem;
  z-index: 90;
  animation: slideUp 0.3s ease;
}
.install-prompt[hidden] { display: none; }

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.install-content {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(168, 85, 247, 0.15)), #1e293b;
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 16px;
  padding: 1.25rem;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}
.install-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.install-emoji { font-size: 1.4rem; }
.install-header strong {
  flex: 1;
  font-size: 1.05rem;
}
.install-close {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #cbd5e1;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s ease;
}
.install-close:active { background: rgba(255, 255, 255, 0.16); transform: scale(0.94); }
.install-text {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
  color: #cbd5e1;
  line-height: 1.45;
}
.install-steps {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.88rem;
  color: #e2e8f0;
  line-height: 1.6;
}
.install-steps li { margin-bottom: 0.3rem; }
.install-steps strong { color: white; }
