:root {
  --bg-a: #f4f0e6;
  --bg-b: #e8f3ff;
  --ink: #1f2a35;
  --muted: #5d6772;
  --accent: #eb5b2d;
  --accent-2: #1971d3;
  --ok: #1d8a5a;
  --err: #a63232;
  --glass: rgba(255, 255, 255, 0.62);
  --glass-border: rgba(255, 255, 255, 0.74);
  --shadow: 0 20px 55px rgba(15, 34, 56, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  color: var(--ink);
  font-family: 'Outfit', sans-serif;
  background:
    radial-gradient(circle at 12% 12%, rgba(235, 91, 45, 0.23), transparent 38%),
    radial-gradient(circle at 86% 15%, rgba(25, 113, 211, 0.18), transparent 34%),
    linear-gradient(145deg, var(--bg-a), var(--bg-b));
  overflow-x: hidden;
}

.bg-shape {
  position: fixed;
  z-index: -1;
  filter: blur(8px);
  opacity: 0.65;
}

.shape-a {
  width: 280px;
  height: 280px;
  border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
  background: linear-gradient(130deg, rgba(235, 91, 45, 0.36), rgba(235, 91, 45, 0.06));
  top: -70px;
  right: -40px;
  animation: floatA 8s ease-in-out infinite;
}

.shape-b {
  width: 250px;
  height: 250px;
  border-radius: 63% 37% 24% 76% / 44% 51% 49% 56%;
  background: linear-gradient(140deg, rgba(25, 113, 211, 0.3), rgba(25, 113, 211, 0.05));
  bottom: -55px;
  left: -50px;
  animation: floatB 9s ease-in-out infinite;
}

.shell {
  width: min(1120px, 92vw);
  margin: 2.2rem auto 3rem;
}

.glass {
  backdrop-filter: blur(12px);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.65rem;
  border-radius: 16px;
  margin-bottom: 1rem;
}

.top-link {
  text-decoration: none;
  color: var(--ink);
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: all 160ms ease;
}

.top-link:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.6);
  border-color: rgba(255, 255, 255, 0.9);
}

.top-link.active {
  background: linear-gradient(120deg, var(--accent), #ff7f52);
  color: #fff;
}

.topbar form {
  margin-left: auto;
}

.logout-btn {
  border: 0;
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(120deg, var(--accent-2), #3d91ec);
}

.panel {
  border-radius: 22px;
  padding: 1.4rem;
  animation: slideIn 420ms ease;
}

.login-panel {
  width: min(460px, 92vw);
  margin: 9vh auto;
}

.kicker {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted);
}

h1 {
  margin: 0.35rem 0 0.55rem;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: clamp(1.8rem, 3.8vw, 2.9rem);
  line-height: 1.05;
}

.lead {
  margin-top: 0;
  color: var(--muted);
  max-width: 72ch;
}

.upload-form,
.stack-form {
  display: grid;
  gap: 0.85rem;
  margin-top: 1rem;
}

.file-zone {
  display: block;
  border-radius: 16px;
  border: 2px dashed rgba(31, 42, 53, 0.3);
  padding: 1.1rem;
  background: rgba(255, 255, 255, 0.45);
}

.file-zone-title {
  display: block;
  font-weight: 600;
}

.file-zone-sub {
  color: var(--muted);
  font-size: 0.92rem;
}

.file-input,
input[type='password'] {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(31, 42, 53, 0.25);
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.86);
  font-family: inherit;
}

.btn {
  border: 0;
  border-radius: 13px;
  padding: 0.8rem 1rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(130deg, var(--accent), #f1844e);
  transition: transform 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.alert {
  margin-top: 1rem;
  border-radius: 14px;
  padding: 0.7rem 0.9rem;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.75);
}

.alert.success {
  color: var(--ok);
}

.alert.error {
  color: var(--err);
}

.alert ul {
  margin: 0.5rem 0 0;
  padding-left: 1.1rem;
}

.ghost-link {
  color: var(--accent-2);
  text-decoration: none;
  font-weight: 600;
}

/* ── Gallery page layout ─────────────────────────────────────────── */

.gallery-page body {
  background-attachment: fixed;
}

.gallery-shell {
  width: min(1400px, 96vw);
  margin-top: 0;
  padding-top: 1.2rem;
}

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  border-radius: 20px;
  margin-bottom: 1.4rem;
  flex-wrap: wrap;
}

.gallery-header-left {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.gallery-title {
  margin: 0;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  line-height: 1.1;
}

.gallery-nav {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.gallery-count {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: rgba(31, 42, 53, 0.07);
}

/* ── Masonry grid ─────────────────────────────────────────────────── */

.masonry {
  columns: 4 240px;
  column-gap: 0.85rem;
}

.mcard {
  break-inside: avoid;
  margin: 0 0 0.85rem;
  border-radius: 16px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 24px rgba(15, 34, 56, 0.08);
  cursor: pointer;
  animation: popIn 480ms ease both;
  animation-delay: var(--delay, 0ms);
  transition: box-shadow 200ms ease, transform 200ms ease;
}

.mcard:hover,
.mcard:focus-visible {
  box-shadow: 0 14px 38px rgba(15, 34, 56, 0.18);
  transform: translateY(-3px);
  outline: none;
}

.mcard-img-wrap {
  position: relative;
  line-height: 0;
}

.mcard-img-wrap img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
  border-radius: 0;
}

.mcard-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 34, 56, 0);
  transition: background 200ms ease;
}

.mcard:hover .mcard-overlay,
.mcard:focus-visible .mcard-overlay {
  background: rgba(15, 34, 56, 0.34);
}

.overlay-icon {
  width: 40px;
  height: 40px;
  color: #fff;
  opacity: 0;
  transform: scale(0.75);
  transition: opacity 200ms ease, transform 200ms ease;
}

.mcard:hover .overlay-icon,
.mcard:focus-visible .overlay-icon {
  opacity: 1;
  transform: scale(1);
}

.mcard-caption {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.7rem;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid rgba(31, 42, 53, 0.06);
}

.mcard-date {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mcard-size {
  white-space: nowrap;
  font-weight: 600;
  color: var(--ink);
  opacity: 0.55;
}

/* ── RAW card ─────────────────────────────────────────────────────── */

.mcard-raw {
  cursor: default;
}

.raw-card-link {
  text-decoration: none;
  color: inherit;
  display: block;
}

.raw-card {
  height: 180px;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.4rem;
  background: linear-gradient(145deg, rgba(25, 113, 211, 0.1), rgba(235, 91, 45, 0.12));
  padding: 1rem;
}

.raw-badge {
  display: inline-block;
  justify-self: center;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
  background: linear-gradient(120deg, var(--accent-2), #3d91ec);
}

.raw-card small {
  color: var(--muted);
  font-size: 0.8rem;
}

.raw-dl {
  font-weight: 600;
  color: var(--accent-2) !important;
}

/* ── Empty state ──────────────────────────────────────────────────── */

.empty-panel {
  text-align: center;
  padding: 3rem 1.5rem;
  max-width: 380px;
  margin: 8vh auto;
}

.empty-icon {
  font-size: 3rem;
  margin: 0 0 0.5rem;
}

.empty-text {
  color: var(--muted);
  margin: 0 0 1.2rem;
}

/* ── Lightbox ─────────────────────────────────────────────────────── */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(10, 14, 20, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  backdrop-filter: blur(6px);
  animation: lbIn 180ms ease;
}

.lightbox[hidden] {
  display: none;
}

.lb-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 3.5rem 4.5rem 0.5rem;
  min-height: 0;
}

.lb-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  user-select: none;
  animation: lbImgIn 220ms ease;
}

.lb-close {
  position: absolute;
  top: 1rem;
  right: 1.1rem;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: #fff;
  font-size: 1.1rem;
  width: 2.4rem;
  height: 2.4rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 150ms ease;
  z-index: 10;
}

.lb-close:hover {
  background: rgba(255, 255, 255, 0.24);
}

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  color: #fff;
  font-size: 2.2rem;
  line-height: 1;
  width: 3rem;
  height: 3rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 150ms ease, transform 150ms ease;
  z-index: 10;
}

.lb-nav:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: translateY(-50%) scale(1.08);
}

.lb-prev { left: 1rem; }
.lb-next { right: 1rem; }

.lb-footer {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 1.2rem;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.83rem;
  gap: 1rem;
}

@keyframes lbIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes lbImgIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

.progress-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.6rem;
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(31, 42, 53, 0.12);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #f1844e);
  transition: width 120ms ease;
}

.progress-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  min-width: 4rem;
  text-align: right;
}

.card figcaption {
  padding: 0.65rem 0.75rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}

@keyframes floatA {
  0%,
  100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(18px) rotate(8deg); }
}

@keyframes floatB {
  0%,
  100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-14px) rotate(-7deg); }
}

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

@keyframes popIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 700px) {
  .shell {
    width: min(96vw, 900px);
    margin-top: 1rem;
  }

  .panel {
    padding: 1rem;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .topbar form {
    margin-left: 0;
  }

  .masonry {
    columns: 2 150px;
    column-gap: 0.6rem;
  }

  .mcard {
    margin-bottom: 0.6rem;
  }

  .gallery-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .lb-nav {
    width: 2.4rem;
    height: 2.4rem;
    font-size: 1.6rem;
  }

  .lb-prev { left: 0.4rem; }
  .lb-next { right: 0.4rem; }

  .lb-stage {
    padding: 3rem 2.8rem 0.5rem;
  }
}
