:root {
  --bg: #faf7f2;
  --fg: #2c2620;
  --muted: #7a7168;
  --accent: #a9764f;
  --line: #e6ddd2;
  --tile: 220px;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1815;
    --fg: #f1ece3;
    --muted: #a89f92;
    --accent: #d8a97a;
    --line: #332d26;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

.app {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--line);
  padding: 3px;
  border-radius: 999px;
}

.bottombar {
  justify-content: center;
  margin: 4px auto 20px;
}

.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}

.tab.active {
  background: var(--bg);
  color: var(--fg);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.tab:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.size-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

.size-control input[type="range"] {
  width: 90px;
  accent-color: var(--accent);
}

.stage {
  position: relative;
  padding: 18px;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 300px;
  color: var(--muted);
  font-size: 0.9rem;
}

.view { animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Carousel ---------- */
.view-carousel { max-width: 980px; margin: 0 auto; }

.carousel-track-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.carousel-track {
  overflow: hidden;
  border-radius: var(--radius);
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--line);
  position: relative;
}

.carousel-track .slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.carousel-track .slide.active { opacity: 1; }

.carousel-track img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.nav {
  position: absolute;
  z-index: 2;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: rgba(0,0,0,0.35);
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  backdrop-filter: blur(2px);
}

.nav.prev { left: 10px; }
.nav.next { right: 10px; }
.nav:hover { background: rgba(0,0,0,0.55); }

.dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
  border: none;
  cursor: pointer;
  padding: 0;
}

.dot.active { background: var(--accent); width: 18px; border-radius: 4px; }

/* ---------- Mosaic ---------- */
.mosaic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
  gap: 8px;
}

.mosaic-grid figure {
  margin: 0;
  overflow: hidden;
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--line);
}

.mosaic-grid img {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.mosaic-grid figure:nth-child(3n+1) img { aspect-ratio: 4/5; }
.mosaic-grid figure:nth-child(5n+2) img { aspect-ratio: 16/10; }

.mosaic-grid figure:hover img { transform: scale(1.04); }

/* ---------- Simple gallery ---------- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
  gap: 10px;
}

.gallery-grid figure {
  margin: 0;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  background: var(--line);
  aspect-ratio: 4/3;
}

.gallery-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.gallery-grid figure:hover img { transform: scale(1.05); }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  flex-direction: column;
}

.lightbox[hidden] { display: none; }

.lb-img {
  max-width: min(92vw, 1100px);
  max-height: 80vh;
  object-fit: contain;
  border-radius: 6px;
}

.lb-caption {
  color: #eee6da;
  font-size: 0.85rem;
  margin-top: 10px;
  opacity: 0.8;
}

.lb-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
}

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: #fff;
  font-size: 2.4rem;
  cursor: pointer;
  padding: 10px 18px;
}

.lb-prev { left: 4px; }
.lb-next { right: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar { display: none; }
  .stage { padding: 10px; }
  .nav { width: 34px; height: 34px; font-size: 1.2rem; }
  .size-control { display: none; }
}

@media (min-width: 1400px) {
  .stage { max-width: 1400px; margin: 0 auto; }
}
