:root {
  --spar-green: #0d9b3a;
  --spar-green-dark: #087128;
  --spar-red: #e1141d;
  --spar-yellow: #ffd200;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
  --radius: 18px;
  --radius-lg: 26px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ─ Header ─────────────────────────────────────────── */
.hdr {
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark {
  width: 36px;
  height: 36px;
  background: var(--spar-green);
  border-radius: 8px;
  color: #fff;
  font-weight: 900;
  font-size: 22px;
  display: grid;
  place-items: center;
  letter-spacing: -1px;
}
.logo-text {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--spar-green);
}

/* ─ Screens ────────────────────────────────────────── */
.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 24px 20px;
  animation: fadeIn 0.25s ease;
}
.screen.active { display: flex; }

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

/* ─ Hero ───────────────────────────────────────────── */
.hero { text-align: center; padding: 12px 8px 24px; }
.hero-icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.hero h1 {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.1;
  margin-bottom: 10px;
}
.hero h1 span { color: var(--spar-green); }
.lead {
  font-size: 15px;
  color: var(--muted);
  max-width: 320px;
  margin: 0 auto;
}

/* ─ Source cards ───────────────────────────────────── */
.source-cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}
.source-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
  font: inherit;
  color: inherit;
}
.source-card:active { transform: scale(0.98); }
.source-card.primary {
  background: linear-gradient(135deg, var(--spar-green), var(--spar-green-dark));
  color: #fff;
  border: none;
  box-shadow: 0 8px 24px rgba(13, 155, 58, 0.3);
}
.source-card .ico { font-size: 36px; }
.source-card .lbl { font-size: 20px; font-weight: 800; }
.source-card .sub { font-size: 13px; opacity: 0.75; }

/* ─ Camera screen ─────────────────────────────────── */
#screen-camera { padding: 0; background: #000; }
.cam-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.cam-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cam-overlay {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 5;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  border: none;
  font-size: 22px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.icon-btn:active { transform: scale(0.92); }
.cam-bottom {
  position: absolute;
  bottom: 32px;
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  z-index: 5;
}
.shutter {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: #fff;
  border: 6px solid rgba(255, 255, 255, 0.4);
  cursor: pointer;
  outline: none;
  transition: transform 0.1s;
}
.shutter:active { transform: scale(0.92); }

/* ─ Step head / frame screen ───────────────────────── */
.step-head { text-align: center; margin-bottom: 20px; }
.step-head h2 {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 4px;
}
.muted { color: var(--muted); font-size: 14px; }

.preview-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.preview-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 14px;
  overflow: hidden;
  background: #f0f0f0;
}
.preview-stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#preview-frame {
  pointer-events: none;
  z-index: 2;
}

.frames-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.frame-thumb {
  background: var(--surface);
  border: 3px solid transparent;
  border-radius: 14px;
  padding: 6px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.frame-thumb:active { transform: scale(0.95); }
.frame-thumb.selected {
  border-color: var(--spar-green);
  box-shadow: 0 6px 16px rgba(13, 155, 58, 0.2);
}
.frame-thumb-img {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  background: #f0f0f0;
  background-size: cover;
  background-position: center;
}
.frame-thumb-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

/* ─ Buttons ────────────────────────────────────────── */
.actions {
  display: flex;
  gap: 10px;
  margin-top: auto;
}
.btn {
  flex: 1;
  padding: 16px 20px;
  border-radius: 60px;
  border: none;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.12s;
  letter-spacing: 0.3px;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.primary {
  background: var(--spar-green);
  color: #fff;
}
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 2px solid var(--border);
}
.btn.big { padding: 20px 28px; font-size: 18px; }

/* ─ Loader / Done ──────────────────────────────────── */
.loader-wrap, .done-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding: 40px 20px;
}
.loader-ring {
  width: 80px;
  height: 80px;
  border: 6px solid var(--border);
  border-top-color: var(--spar-green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-wrap h2, .done-wrap h2 {
  font-size: 26px;
  font-weight: 800;
}
.done-check, .err-x {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 56px;
  font-weight: 900;
  color: #fff;
  margin-bottom: 8px;
  box-shadow: var(--shadow-lg);
}
.done-check {
  background: var(--spar-green);
  animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.err-x {
  background: var(--spar-red);
}
@keyframes pop {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}
.done-wrap .btn { margin-top: 16px; min-width: 200px; flex: none; }

/* ─ Footer ─────────────────────────────────────────── */
.ftr {
  padding: 14px 20px env(safe-area-inset-bottom, 14px);
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.ftr a { color: var(--spar-green); text-decoration: none; font-weight: 600; }

/* ─ Hidden ─────────────────────────────────────────── */
.hidden { display: none !important; }
