*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --accent: #f5a623;
  --bg: #0a0a0a;
  --surface: #1a1a1a;
  --surface2: #252525;
  --text: #f0f0f0;
  --text-muted: #888;
  --danger: #e74c3c;
  --success: #2ecc71;
  --radius: 12px;
}

html {
  height: 100%;
  height: -webkit-fill-available;
}

body {
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── SCREENS ─────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
  z-index: 1;
}
.screen.active { display: flex; }

/* ── SETUP ───────────────────────────────── */
#screen-setup {
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.setup-container {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 8px;
}

.logo svg {
  width: 40px;
  height: 40px;
  color: var(--accent);
}

.logo h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.setup-desc {
  color: var(--text-muted);
  font-size: 15px;
  margin-top: -8px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  background: var(--surface2);
  border: 1.5px solid #333;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}

.form-group input:focus {
  border-color: var(--accent);
}

.form-group input::placeholder {
  color: #555;
}

/* ── BUTTONS ─────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  padding: 16px 24px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: opacity 0.2s, transform 0.1s;
  width: 100%;
  -webkit-appearance: none;
}

.btn-primary:active {
  opacity: 0.85;
  transform: scale(0.98);
}

.btn-primary svg {
  width: 20px;
  height: 20px;
}

/* ── CAMERA SCREEN ───────────────────────── */
#screen-camera {
  background: #000;
  justify-content: space-between;
}

.camera-container {
  position: relative;
  width: 100%;
  flex: 1 1 0;
  min-height: 0;        /* empêche le dépassement flex sur iOS */
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#video {
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-mask {
  position: absolute;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.55);
  z-index: 2;
  pointer-events: none;
}
.camera-mask.top { top: 0; }
.camera-mask.bottom { bottom: 0; }

.square-overlay {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  aspect-ratio: 1;
}

.square-overlay .corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border-color: var(--accent);
  border-style: solid;
  border-width: 0;
}

.corner.tl { top: 0;    left: 0;  border-top-width: 3px; border-left-width: 3px;  border-top-left-radius: 3px; }
.corner.tr { top: 0;    right: 0; border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 3px; }
.corner.bl { bottom: 0; left: 0;  border-bottom-width: 3px; border-left-width: 3px; border-bottom-left-radius: 3px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 3px; }

.crosshair-h, .crosshair-v {
  position: absolute;
  background: rgba(255,255,255,0.12);
  pointer-events: none;
}
.crosshair-h { top: 50%; left: 10%; right: 10%; height: 1px; transform: translateY(-50%); }
.crosshair-v { left: 50%; top: 10%; bottom: 10%; width: 1px; transform: translateX(-50%); }

.camera-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;       /* ne se compresse jamais */
  padding: 20px 40px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  background: #000;
  z-index: 5;
}

.btn-shutter {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
  -webkit-appearance: none;
}

.btn-shutter:active { transform: scale(0.9); }

.shutter-inner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #fff;
  transition: background 0.1s;
}

.btn-shutter:active .shutter-inner { background: #ccc; }

.btn-settings, .placeholder {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-settings {
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  -webkit-appearance: none;
}

.btn-settings svg { width: 20px; height: 20px; }

/* ── PREVIEW SCREEN ──────────────────────── */
#screen-preview {
  background: var(--bg);
}

.preview-header {
  display: flex;
  align-items: center;
  padding: 16px 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid #2a2a2a;
}

.btn-back {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  -webkit-appearance: none;
}

.btn-back svg { width: 20px; height: 20px; }

.preview-image-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #050505;
  padding: 16px;
}

.preview-image-wrap img {
  width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.preview-form {
  padding: 20px 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid #2a2a2a;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ref-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#input-ref {
  background: var(--surface2);
  border: 1.5px solid #333;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  letter-spacing: 2px;
  text-align: center;
  width: 100%;
}

#input-ref:focus { border-color: var(--accent); }

.btn-send { margin-top: 4px; }

/* ── OVERLAY SENDING ─────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.overlay.hidden { display: none; }

.sending-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.sending-box p {
  font-size: 16px;
  color: var(--text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #333;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── TOAST ───────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(32px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  max-width: calc(100vw - 40px);
  text-align: center;
  white-space: normal;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success { background: var(--success); color: #000; }
.toast.error   { background: var(--danger);  color: #fff; }

.toast.hidden { display: none; }

/* ── MODAL SETTINGS ──────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  z-index: 150;
  backdrop-filter: blur(4px);
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 { font-size: 18px; font-weight: 700; }

.modal-header button {
  background: var(--surface2);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
}

.modal-header button svg { width: 16px; height: 16px; }
