:root {
  --bg: #275841;
  --surface: #c4dfd3;
  --surface-2: #353f38;
  --text: #727268be;
  --muted: #7a6e63;
  --accent: #bce9d2;
  --accent-2: #91c573;
  --accent-3: #4db6ac;
  --border: #323336;
  --shadow: 0 12px 30px rgba(38, 31, 26, 0.08);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg) 0%, var(--surface-2) 100%);
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
}

.container {
  width: min(100%, 1280px);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 24px) 16px 60px;
}

#site-header-block {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.header-overlay {
  padding: 24px 28px;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.header-identity {
  display: flex;
  align-items: center;
  gap: 14px;
}

.site-pfp {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent);
}

.header-titles h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.site-tagline {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
}

#db-status {
  padding: 8px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.marquee-container {
  margin: 18px 0 22px;
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow);
}

.marquee {
  display: flex;
  white-space: nowrap;
  padding: 10px 0;
  animation: marquee 18s linear infinite;
}

.marquee span {
  color: white;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.8rem;
  padding: 0 18px;
}

@keyframes marquee {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-50%);
  }
}

.layout-wrapper {
  display: grid;
  grid-template-columns: minmax(180px, 220px) 1fr;
  gap: 22px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn:hover,
.nav-btn.active {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff;
  transform: translateX(2px);
}

main {
  min-width: 0;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
  animation: fadeInSection 0.25s ease;
}

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

.view-section h2 {
  margin: 0 0 16px;
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

#leaflets-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.leaflet-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition:
    transform 0.25s ease,
    box-shadow 0.25s ease;
}

.leaflet-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 34px rgba(38, 31, 26, 0.12);
}

.leaflet-media-container img {
  width: 100%;
  display: block;
  object-fit: cover;
}

.leaflet-body {
  padding: 16px;
}

.leaflet-content {
  font-size: 0.95rem;
  color: var(--muted);
}

.leaflet-content p {
  margin: 0 0 10px;
}

/* ============================================================
   MASONRY GALLERY — Pinterest-style infinite-scroll grid
   Instant placeholders + progressive image load
   ============================================================ */
#gallery-container {
  position: relative;
  width: 100%;
  min-height: 400px;
  border-radius: 24px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.masonry-grid {
  column-count: 5;
  column-gap: 12px;
  padding: 12px;
}

.masonry-item {
  position: relative;
  break-inside: avoid;
  margin-bottom: 12px;
  border-radius: 14px;
  overflow: hidden;
  cursor: zoom-in;
  contain: layout paint;
  content-visibility: auto;
  contain-intrinsic-size: auto 250px;
  /* Placeholder background is set inline by JS */
}

.masonry-item img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* No opacity transition — image renders progressively as it downloads */
}

.masonry-item:hover {
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.18);
  transform: translateY(-2px) scale(1.01);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.masonry-sentinel {
  height: 40px;
  margin: 20px auto;
  width: 40px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: masonrySpin 0.8s linear infinite;
}

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

/* Gallery lightbox */
#gallery-lightbox {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}

#gallery-lightbox.active {
  display: flex;
}

.gallery-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 8, 8, 0.94);
  backdrop-filter: blur(14px);
}

.gallery-lightbox-content {
  position: relative;
  max-width: min(96vw, 1200px);
  max-height: 96vh;
  z-index: 1;
}

.gallery-lightbox-content img {
  display: block;
  width: 100%;
  max-height: 96vh;
  object-fit: contain;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.gallery-lightbox-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  color: #1a1a1a;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease, background 0.2s ease;
}

.gallery-lightbox-close:hover {
  transform: scale(1.08);
  background: #fff;
}

/* ============================================================
   LORE SECTION
   ============================================================ */
#tab-lore {
  position: relative;
}

.lore-shell {
  position: relative;
  width: 100%;
  height: 72vh;
  min-height: 700px;
  background: var(--surface);
  border: 2px solid #000;
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 10px;
  overflow: hidden;
  display: grid;
  grid-template-columns: 40% 60%;
  grid-template-rows: 340px 1fr;
  gap: 12px;
}

.lore-activated-card,
.lore-info-panel {
  border: 2px solid #000;
  border-radius: 1rem;
  padding: 5px;
  background: rgba(255, 255, 255, 0.95);
  box-sizing: border-box;
  overflow: hidden;
}

.lore-activated-card {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 12;
}

.lore-activated-media {
  flex: 1;
  min-height: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #f5f5f5;
  position: relative;
}

/* Carousel */
.carousel-track {
  position: relative;
  width: 100%;
  height: 100%;
}

.carousel-slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}

.carousel-slide.active {
  opacity: 1;
  pointer-events: auto;
}

.carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 40px;
  height: 56px;
  border: none;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  backdrop-filter: blur(4px);
  transition: background 0.2s ease, transform 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.carousel-arrow:hover {
  background: rgba(0, 0, 0, 0.65);
  transform: translateY(-50%) scale(1.05);
}

.carousel-arrow:active {
  transform: translateY(-50%) scale(0.95);
}

.carousel-prev { left: 8px; }
.carousel-next { right: 8px; }

.carousel-dots {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
}

.carousel-dot {
  width: 8px;
  height: 8px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  padding: 0;
  transition: background 0.2s ease, transform 0.2s ease;
}

.carousel-dot.active {
  background: #fff;
  transform: scale(1.25);
}

/* .lore-activated-card shows image only */
.lore-info-title {
  margin: 0;
  font-size: 1.05rem;
  color: #2f2b28;
}

.lore-info-text p {
  margin: 0 0 0.8rem;
  color: #6d655f;
  line-height: 1.55;
  font-size: 0.9rem;
}

.lore-container {
  position: relative;
  grid-column: 1 / -1;
  grid-row: 2;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: visible;
  z-index: 13;
  cursor: grab;
  user-select: none;
  touch-action: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.lore-container.is-dragging {
  cursor: grabbing;
}

.lore-container.is-dragging .card {
  transition: none !important;
}

.lore-container .card {
  position: absolute;
  left: 50%;
  bottom: 10%;
  width: min(22vw, 170px);
  max-width: 180px;
  aspect-ratio: 24 / 32;
  border-radius: 16px;
  background: white;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 7px solid white;
  cursor: pointer;
  transition:
    transform 0.6s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.4s ease,
    left 0.6s cubic-bezier(0.22, 1, 0.36, 1),
    top 0.6s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.3s ease;
  transform-origin: 50% 100%;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.13);
  overflow: hidden;
  will-change: transform, left, top;
  z-index: var(--z, 10);
  pointer-events: auto;
  transform: translateX(-50%)
    translateX(calc(var(--i) * var(--spread, 18px) - var(--drag-offset, 0px)))
    rotate(calc(var(--i) * var(--fan-angle, 6deg) + var(--drag-angle, 0deg)));
}

.lore-container .card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  filter: blur(1.5px);
  opacity: 0.85;
  transition: filter 0.3s ease, opacity 0.3s ease;
}

.lore-container .card:hover img,
.lore-container .card.center img {
  filter: blur(0px);
  opacity: 1;
}

.lore-container .card.center {
  transform: translateX(-50%) translateX(0px) translateY(-5vh) rotate(0deg) scale(1.05);
  box-shadow: 0 22px 44px rgba(0, 0, 0, 0.22), 0 0 0 3px rgba(77, 182, 172, 0.45), 0 0 24px rgba(77, 182, 172, 0.25);
  z-index: 50;
}

.lore-container .card.selected {
  border-color: var(--accent-3);
  box-shadow: 0 0 0 4px var(--accent-3), 0 12px 30px rgba(0, 0, 0, 0.22);
  z-index: 25;
  filter: brightness(1.1);
}

.lore-info-panel {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 10px;
  z-index: 10;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

.lore-info-copy {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

.lore-info-text {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 6px;
  white-space: normal;
}

.lore-info-text::-webkit-scrollbar {
  width: 8px;
}

.lore-info-text::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.26);
  border-radius: 999px;
}

/* Info panel pagination */
.info-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 4px 4px;
  flex-shrink: 0;
}

.info-arrow {
  width: 40px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: background 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  flex-shrink: 0;
}

.info-arrow:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.65);
  transform: scale(1.05);
}

.info-arrow:active:not(:disabled) {
  transform: scale(0.95);
}

.info-arrow:disabled {
  opacity: 0.35;
  cursor: default;
  filter: grayscale(1);
}

.info-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}

.info-dot {
  width: 8px;
  height: 8px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
  padding: 0;
  transition: background 0.2s ease, transform 0.2s ease;
}

.info-dot.active {
  background: var(--accent-3);
  transform: scale(1.3);
}

/* ============================================================
   RESPONSIVE — Masonry columns
   ============================================================ */
@media (max-width: 1400px) {
  .masonry-grid {
    column-count: 5;
  }
}

@media (max-width: 1100px) {
  .masonry-grid {
    column-count: 4;
    column-gap: 10px;
    padding: 10px;
  }
  .masonry-item {
    margin-bottom: 10px;
    border-radius: 12px;
    contain-intrinsic-size: auto 200px;
  }
}

@media (max-width: 768px) {
  .masonry-grid {
    column-count: 3;
    column-gap: 8px;
    padding: 8px;
  }
  .masonry-item {
    margin-bottom: 8px;
    border-radius: 10px;
    contain-intrinsic-size: auto 180px;
  }
}

@media (max-width: 480px) {
  .masonry-grid {
    column-count: 2;
    column-gap: 6px;
    padding: 6px;
  }
  .masonry-item {
    margin-bottom: 6px;
    border-radius: 8px;
  }
  .gallery-lightbox-content {
    padding: 0 8px;
  }
  .gallery-lightbox-close {
    top: 8px;
    right: 8px;
  }
}

/* ============================================================
   RESPONSIVE — Lore
   ============================================================ */
@media (max-width: 920px) {
  .lore-shell {
    padding: 8px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(280px, auto) minmax(280px, auto) minmax(
        360px,
        1fr
      );
    min-height: 720px;
    height: auto;
  }

  .lore-activated-card {
    grid-column: 1;
    grid-row: 1;
  }

  .lore-info-panel {
    grid-column: 1;
    grid-row: 2;
    max-height: 320px;
    overflow: hidden;
  }

  .lore-container {
    grid-column: 1;
    grid-row: 3;
    min-height: 360px;
  }

  .lore-container .card {
    width: min(26vw, 160px);
    border-width: 6px;
  }

  .lore-container .card.center {
    transform: translateX(-50%) translateX(0px) translateY(-4vh) rotate(0deg) scale(1.04);
  }

  .carousel-arrow {
    width: 36px;
    height: 48px;
    font-size: 24px;
  }
}

@media (max-width: 640px) {
  .lore-shell {
    padding: 6px;
    min-height: 640px;
    grid-template-rows: minmax(220px, auto) minmax(220px, auto) minmax(280px, 1fr);
  }

  .lore-container {
    min-height: 280px;
  }

  .lore-container .card {
    width: min(30vw, 130px);
    border-width: 5px;
  }

  .lore-container .card.center {
    transform: translateX(-50%) translateX(0px) translateY(-3vh) rotate(0deg) scale(1.03);
  }

  .lore-info-panel {
    max-height: 260px;
  }

  .lore-info-title {
    font-size: 0.95rem;
  }

  .lore-info-text {
    font-size: 0.82rem;
  }

  .carousel-arrow {
    width: 32px;
    height: 44px;
    font-size: 22px;
  }

  .carousel-dot {
    width: 7px;
    height: 7px;
  }

  .info-arrow {
    width: 36px;
    height: 40px;
    font-size: 20px;
  }

  .info-dot {
    width: 7px;
    height: 7px;
  }
}

/* ============================================================
   FOOTER
   ============================================================ */
footer {
  margin-top: 30px;
  padding: 0 20px 30px;
}

#footer-text {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
}

/* ============================================================
   RESPONSIVE — General layout
   ============================================================ */
@media (max-width: 920px) {
  .layout-wrapper {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .nav-btn {
    flex: 1 1 140px;
    text-align: center;
  }
}

@media (max-width: 640px) {
  .container {
    padding: 16px 12px 40px;
  }

  .header-overlay {
    padding: 18px 18px;
  }

  .header-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .marquee-container {
    border-radius: 18px;
  }

  .marquee span {
    font-size: 0.72rem;
    padding: 0 12px;
  }

  #leaflets-container {
    grid-template-columns: 1fr;
  }
}
