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

:root {
  color-scheme: dark;
  font-family: Inter, -apple-system, Segoe UI, sans-serif;
  background: #070b14;
  color: #e6eefc;
}

body {
  min-height: 100vh;
  background: radial-gradient(circle at top, rgba(24,39,74,0.95), rgba(7,11,20,1) 58%), #070b14;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
button:disabled { opacity: 0.4; pointer-events: none; }
input[type="file"] { display: none; }

.app-root {
  max-width: 800px; margin: 0 auto; padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 100dvh;
}

.panel {
  background: rgba(14,23,42,0.84);
  border: 1px solid #22345b;
  border-radius: 16px;
  padding: 14px;
  backdrop-filter: blur(6px);
}

/* === VIEWFINDER PANEL === */
.viewfinder-panel {
  padding: 0; overflow: hidden;
  flex: 1 1 0;
  display: flex; flex-direction: column;
  min-height: 0;
}

#viewfinder {
  position: relative; width: 100%; flex: 1 1 0;
  background: #0a0a0a; display: flex; align-items: center; justify-content: center;
  overflow: hidden; min-height: 0;
}

#viewfinder-empty {
  color: #555; font-size: 14px; letter-spacing: 0.05em;
  display: flex; align-items: center; justify-content: center;
}

#captured-img, #sweep-live {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #000;
}

/* Sweep overlay */
#sweep-overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55);
}
#sweep-overlay[hidden] { display: none; }
#sweep-ring { width: 72px; height: 72px; margin-bottom: 14px; }
#sweep-ring svg { width: 100%; height: 100%; }
#sweep-msg { font-size: 13px; color: #ffd966; text-align: center; padding: 0 24px; line-height: 1.5; }

/* Status badge */
#status-badge {
  position: absolute; top: 10px; left: 10px; z-index: 5;
  display: flex; gap: 5px;
}
#mode-label, #stage-label {
  background: rgba(0,0,0,0.7); backdrop-filter: blur(6px);
  padding: 3px 10px; border-radius: 999px; font-size: 11px;
  letter-spacing: 0.04em; border: 1px solid rgba(255,255,255,0.1);
}
#mode-label { color: #8cf; }
#stage-label { color: #aaa; }

/* === CONTROLS BAR (below viewfinder) === */
#controls-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: rgba(10,19,35,0.9);
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

#mode-selector {
  display: flex; gap: 3px;
  background: rgba(255,255,255,0.06); border-radius: 999px; padding: 3px;
}
.mode-btn {
  padding: 5px 14px; border-radius: 999px; font-size: 12px; font-weight: 500;
  color: #888; transition: all 120ms ease;
}
.mode-btn.active { background: #fff; color: #111; }

#shutter {
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 100ms ease;
}
#shutter:active { transform: scale(0.9); }
#shutter:disabled { opacity: 0.4; }
#shutter svg { width: 52px; height: 52px; display: block; }

#actions-mini button {
  padding: 6px 10px; border-radius: 10px; font-size: 18px;
  background: rgba(255,255,255,0.06); transition: background 120ms;
  border: 1px solid rgba(255,255,255,0.06);
}
#actions-mini button:hover { background: rgba(255,255,255,0.12); }

/* === ACTIONS PANEL === */
.actions-panel { padding: 12px 14px; }

.actions-row {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.actions-row button {
  padding: 8px 14px; border-radius: 10px; font-size: 13px; font-weight: 500;
  background: linear-gradient(180deg, #1c2d50, #13233f);
  border: 1px solid #375386;
  transition: transform 120ms ease, border-color 120ms ease;
}
.actions-row button:hover:not(:disabled) {
  transform: translateY(-1px); border-color: #4d73b4;
}
#btn-save-preview {
  border-color: #4b76b9;
  background: linear-gradient(180deg, #214674, #143151);
}

.preview-msg {
  margin: 8px 0 0; color: #9dbaf1; font-size: 13px; line-height: 1.5;
}

/* === GALLERY PANEL === */
.gallery-panel { padding: 12px 14px; }

.panel-heading {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px;
}
.panel-heading h3 { margin: 0; font-size: 14px; font-weight: 600; }
.panel-meta { color: #8fb7ef; font-size: 12px; }

#gallery-strip {
  display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 6px;
  scrollbar-width: thin; min-height: 70px;
}
.empty-hint { color: #5a7aa9; font-size: 13px; padding: 10px 0; }

.gallery-card {
  min-width: 120px; max-width: 120px; flex-shrink: 0;
  border: 2px solid transparent; border-radius: 12px; overflow: hidden;
  cursor: pointer; transition: border-color 120ms;
  background: linear-gradient(180deg, rgba(18,30,56,0.92), rgba(10,19,35,0.96));
}
.gallery-card:hover { border-color: #4d73b4; }
.gallery-card.is-active { border-color: #ffd966; box-shadow: 0 0 0 1px rgba(255,215,0,0.15); }

.gallery-card img {
  width: 100%; aspect-ratio: 1.2; object-fit: cover; display: block;
  background: #081327; border-bottom: 1px solid #22345b;
}
.gallery-card-label {
  padding: 5px 8px; font-size: 11px; color: #bad0ff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* === EXPORT BOTTOM SHEET === */
#export-panel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: rgba(14,23,42,0.96); backdrop-filter: blur(16px);
  border-radius: 20px 20px 0 0;
  padding: 16px 20px env(safe-area-inset-bottom,16px);
  max-height: 60vh; overflow-y: auto;
  border-top: 1px solid #22345b;
}
#export-panel[hidden] { display: none; }

#export-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 16px; font-weight: 600; margin-bottom: 14px;
}
#export-close { font-size: 24px; color: #aaa; padding: 4px 8px; }

#export-body { display: flex; flex-wrap: wrap; gap: 8px; }
#export-body button {
  padding: 10px 16px; border-radius: 10px; font-size: 13px; font-weight: 500;
  background: linear-gradient(180deg, #1c2d50, #13233f);
  border: 1px solid #375386; text-align: left; flex: 1; min-width: 120px;
  transition: transform 120ms ease, border-color 120ms ease;
}
#export-body button:hover { transform: translateY(-1px); border-color: #4d73b4; }
#export-body .export-immersive {
  border-color: #ffd966; background: linear-gradient(180deg, #3a2f00, #1f1800); color: #ffd966;
  flex-basis: 100%;
}

/* === RESPONSIVE === */
@media (min-width: 640px) {
  .app-root { padding: 20px; gap: 14px; }
  .viewfinder-panel { border-radius: 20px; }
  #viewfinder { border-radius: 20px 20px 0 0; }
  #gallery-strip .gallery-card { min-width: 140px; max-width: 140px; }
}