:root {
  --bg: #0b0d12;
  --panel: #151a23;
  --panel-2: #1d2430;
  --text: #eef2f8;
  --muted: #93a0b4;
  --accent: #4f9cff;
  --accent-2: #34d399;
  --danger: #f87171;
  --warn: #fbbf24;
  --edge: #34d399;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* Kamera füllt den Hintergrund */
#video, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#overlay { pointer-events: none; }
#video { background: #000; }

/* Statusleiste */
#statusbar {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: 0; right: 0;
  display: flex;
  gap: 8px;
  justify-content: center;
  z-index: 5;
  pointer-events: none;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(11, 13, 18, 0.72);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 rgba(0,0,0,0);
  transition: background .2s;
}
.dot.searching { background: var(--muted); }
.dot.detecting { background: var(--warn); animation: pulse 1s infinite; }
.dot.captured  { background: var(--accent-2); }
.dot.waiting   { background: var(--accent); animation: pulse 1s infinite; }
.dot.uploading { background: var(--accent); animation: pulse .6s infinite; }
.dot.error     { background: var(--danger); }

@keyframes pulse {
  0%,100% { opacity: 1; }
  50% { opacity: .35; }
}

/* Countdown-Ring */
#countdown {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 160px; height: 160px;
  z-index: 6;
  display: grid;
  place-items: center;
}
#countdown svg { width: 100%; height: 100%; transform: rotate(-90deg); }
#countdown circle { fill: none; stroke-width: 8; }
#countdown .track { stroke: rgba(255,255,255,0.12); }
#countdown .progress {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset .1s linear;
}
.countdown-label {
  position: absolute;
  text-align: center;
}
.countdown-label span { font-size: 42px; font-weight: 700; }
.countdown-label small { display: block; color: var(--muted); font-size: 13px; }

/* Flash bei Erfassung */
#flash {
  position: absolute;
  inset: 0;
  background: #fff;
  z-index: 7;
  animation: flash .35s ease-out;
  pointer-events: none;
}
@keyframes flash {
  from { opacity: .85; }
  to { opacity: 0; }
}

/* Steuerleiste unten */
#controls {
  margin-top: auto;
  position: relative;
  z-index: 5;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px 16px calc(var(--safe-bottom) + 14px);
  background: linear-gradient(to top, rgba(11,13,18,0.85), rgba(11,13,18,0));
}
button {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 14px 18px;
  cursor: pointer;
  transition: transform .05s, background .15s, opacity .15s;
}
button:active { transform: scale(0.97); }
button.primary {
  flex: 1;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
}
button.ghost {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border-color: rgba(255,255,255,0.12);
}
button.icon {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  width: 50px; height: 50px;
  padding: 0;
  font-size: 20px;
  border-color: rgba(255,255,255,0.12);
}

/* Mehrseiten-Button */
button.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 12px 14px;
  white-space: nowrap;
}
button.mode-btn .mode-icon { font-size: 17px; line-height: 1; }
button.mode-btn .mode-label { font-size: 14px; }
button.mode-btn.active-once {
  background: rgba(79,156,255,0.22);
  border-color: rgba(79,156,255,0.6);
  color: #cfe4ff;
}
button.mode-btn.active-persist {
  background: rgba(52,211,153,0.22);
  border-color: rgba(52,211,153,0.65);
  color: #c8f5e4;
}

/* Modus-Badge oben mittig */
.mode-badge {
  position: absolute;
  top: calc(var(--safe-top) + 52px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  background: rgba(11,13,18,0.72);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
}

/* Einstellungen */
dialog#settings {
  border: none;
  border-radius: 18px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  width: min(440px, 92vw);
  max-height: 86vh;
}
dialog#settings::backdrop { background: rgba(0,0,0,0.55); backdrop-filter: blur(2px); }
dialog#settings form { padding: 22px; overflow-y: auto; max-height: 86vh; }
dialog#settings h2 { margin: 0 0 16px; font-size: 20px; }
dialog#settings label {
  display: block;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
dialog#settings label.row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}
dialog#settings input[type="number"],
dialog#settings input[type="text"],
dialog#settings input[type="password"] {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.14);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}
dialog#settings input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
dialog#settings small {
  display: block;
  margin-top: 5px;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.35;
}
dialog#settings menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 8px 0 0;
  padding: 0;
}

/* Toasts */
#toasts {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--safe-bottom) + 92px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 8;
  pointer-events: none;
}
.toast {
  background: rgba(21, 26, 35, 0.95);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  max-width: 88vw;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  animation: toastIn .2s ease-out;
}
.toast.success { border-color: rgba(52,211,153,0.5); }
.toast.error { border-color: rgba(248,113,113,0.5); }
.toast.info { border-color: rgba(79,156,255,0.5); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

[hidden] { display: none !important; }
