/* ---------------- RESET & BASE ---------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  scroll-behavior: smooth;
}

/* ---------------- THEME VARIABLES ---------------- */
:root {
  --bg-main: #faf7f5;
  --bg-card: #ffffff;
  --bg-overlay: rgba(0,0,0,0.6);

  --text-main: #2c2c2c;
  --text-muted: #555;

  --border-soft: #e0d6d8;

  --accent: #b76e79;
  --accent-light: #d9a7b0;

  --shadow-soft: rgba(0,0,0,0.25);
}

/* ---------------- HEADER ---------------- */
header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* ---------------- BUTTONS ---------------- */
button {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: white;
  box-shadow: 0 4px 12px rgba(183,110,121,0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(183,110,121,0.45);
}

button.secondary {
  background: #e0e0e0;
  color: #333;
  box-shadow: none;
}

/* ---------------- GALLERY GRID ---------------- */
.gallery {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

@media (max-width: 480px) {
  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
  }
}

/* ---------------- GALLERY IMAGES ---------------- */
.gallery img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 14px;
  cursor: pointer;
  background: #eee;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.gallery img:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}

/* ---------------- OVERLAY ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.hidden {
  display: none;
}

/* ---------------- CARD ---------------- */
.card {
  background: var(--bg-card);
  border-radius: 18px;
  padding: 28px 24px 30px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 40px var(--shadow-soft);
}

.card h1 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 600;
}

.card p {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--text-muted);
}

/* ---------------- FORM ---------------- */
.form-group {
  position: relative;
  margin-bottom: 16px;
}

.form-group input {
  width: 100%;
  padding: 14px;
  font-size: 14px;
  border-radius: 12px;
  border: 1.5px solid var(--border-soft);
  background: var(--bg-card);
  color: var(--text-main);
  outline: none;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(183,110,121,0.15);
}

.form-group label {
  position: absolute;
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 0 6px;
  transition: 0.2s ease;
  pointer-events: none;
}

.form-group input:focus + label,
.form-group input:not(:placeholder-shown) + label {
  top: -6px;
  font-size: 10px;
  color: var(--accent);
}

#welcome button {
  width: 100%;
  margin-top: 6px;
  padding: 12px 18px;
}

/* ---------------- CAMERA ---------------- */
video {
  width: 100%;
  max-width: 300px;
  border-radius: 14px;
  margin-bottom: 14px;
  background: black;
}

/* ---------------- LOADER ---------------- */
.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid #e4e4e4;
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 1s linear infinite;
}

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

/* ---------------- VIEWER ---------------- */
#viewer {
  flex-direction: column;
}

#viewer img {
  max-width: 92vw;
  max-height: 78vh;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
  background: black;
}

#downloadBtn {
  margin-top: 14px;
  display: inline-block;
  padding: 10px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: white;
  text-decoration: none;
}

/* ---------------- MESSAGE ---------------- */
.message {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 200;
}

/* ---------------- LOAD MORE ---------------- */
#loadMoreWrapper {
  position: relative;
  z-index: 2;
}

/* ---------------- DARK MODE ---------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-main: #141414;
    --bg-card: #1f1f1f;
    --bg-overlay: rgba(0,0,0,0.75);

    --text-main: #f2f2f2;
    --text-muted: #b8b8b8;

    --border-soft: #333;

    --accent: #d9a7b0;
    --accent-light: #b76e79;

    --shadow-soft: rgba(0,0,0,0.6);
  }

  header {
    background: rgba(25,25,25,0.92);
    box-shadow: 0 2px 10px rgba(0,0,0,0.7);
  }

  .gallery img {
    background: #222;
  }

  button.secondary {
    background: #333;
    color: #eee;
  }
}

/* ---------------- PERFORMANCE SAFETY ---------------- */
img {
  will-change: transform;
}

/* ---------------- HEADER USER GREETING ---------------- */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-greeting {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Optional: hide greeting on very small screens */
@media (max-width: 360px) {
  .user-greeting {
    display: none;
  }
}

/* ---------------- SKELETON ---------------- */
.skeleton {
  background: linear-gradient(
    90deg,
    #eee 25%,
    #f5f5f5 37%,
    #eee 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ---------------- RESULT INFO ---------------- */
.result-info {
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------------- SWITCH USER ---------------- */
.switch-user {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
}
.switch-user:hover {
  text-decoration: underline;
}

/* ---------------- OFFLINE BANNER ---------------- */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #333;
  color: white;
  text-align: center;
  padding: 8px 12px;
  font-size: 13px;
  z-index: 500;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  height: 36px;
  width: auto;
  border-radius: 6px;
}
/* Mobile safety */
@media (max-width: 480px) {
  .logo {
    height: 30px;
  }
}

.logo {
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.logo:hover {
  transform: scale(1.05);
  opacity: 0.9;
}

/* =======================
   VIEWER LOADING STATE
======================= */

#viewerImg {
  transition: filter 0.25s ease, opacity 0.25s ease;
}

#viewerImg.loading {
  filter: blur(10px);
  opacity: 0.5;
}
/* =======================
   DESKTOP LOGO FIX (SAFE)
======================= */

/* Prevent logo from ever stretching header */
header {
  max-height: 64px;
}

/* Hard safety on logo size */
.logo {
  max-height: 36px;
  height: 36px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

/* Extra safety for large screens */
@media (min-width: 1024px) {
  .logo {
    max-height: 32px;
    height: 32px;
  }
}

/* =======================
   VIEWER IMAGE LOADING UX
======================= */

/* Reserve space so viewer is never blank */
#viewer img {
  min-width: 280px;
  min-height: 280px;
}

/* Loading state */
#viewerImg.loading {
  filter: blur(12px);
  opacity: 0.6;
}

/* Spinner overlay */
#viewer {
  position: fixed;
}

#viewer.loading::after {
  content: "";
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.25);
  border-top-color: white;
  position: absolute;
  animation: spin 1s linear infinite;
}

/* Spinner animation already exists but ensure safety */
@keyframes spin {
  to { transform: rotate(360deg); }
}
