/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #c9a96e;
  --bg: #1a1208;
  --bg2: #221a0e;
  --card: #2b2010;
  --text: #f0e6d3;
  --muted: #9e8a72;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

/* ── Offline banner ── */
#offline-banner {
  display: none;
  background: #3a2010;
  color: #e8c48a;
  font-size: 0.78rem;
  text-align: center;
  padding: 8px 16px;
  border-bottom: 1px solid #5a3a1a;
}

#offline-banner.visible {
  display: block;
}

/* ── Header ── */
header {
  text-align: center;
  padding: 32px 20px 20px;
}

header h1 {
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

header h1 em {
  font-style: italic;
  color: var(--accent);
}

header p {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

/* ── Tabs ── */
#tabs-container {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid #3a2e1a;
}

#tabs {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px;
  gap: 4px;
}

#tabs::-webkit-scrollbar { display: none; }

.tab {
  flex-shrink: 0;
  padding: 12px 18px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  white-space: nowrap;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Main content ── */
main {
  flex: 1;
  padding: 24px 16px;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}

/* ── Pet profile card ── */
#profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

#avatar-wrap {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--accent);
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  flex-shrink: 0;
}

#avatar-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#profile-info {
  text-align: center;
}

#pet-name {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
}

#pet-years {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 2px;
}

#pet-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}

/* ── Tribute ── */
#tribute {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  margin-bottom: 28px;
}

/* ── Photo collage ── */
#collage {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 130px;
  gap: 6px;
  margin-bottom: 28px;
}

.foto-celda {
  border-radius: 10px;
  overflow: hidden;
  background: var(--card);
  cursor: pointer;
  position: relative;
}

/* Pattern A (cells 1–7 in every 14-step cycle): tall left, wide right */
.foto-celda:nth-child(14n+1)  { grid-row: span 2; }
.foto-celda:nth-child(14n+4)  { grid-column: span 2; }

/* Pattern B (cells 8–14 in every 14-step cycle): wide left, tall center */
.foto-celda:nth-child(14n+8)  { grid-column: span 2; }
.foto-celda:nth-child(14n+11) { grid-row: span 2; }

.foto-celda img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  transition: transform 0.3s ease;
}

.foto-celda:hover img,
.foto-celda:focus img {
  transform: scale(1.04);
}

/* Celda con imagen no disponible */
.foto-celda.foto-error {
  cursor: default;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.7rem;
  opacity: 0.5;
  pointer-events: none;
}

.foto-celda.foto-error::before {
  content: '✕';
  font-size: 1.2rem;
}

/* Collage vacío */
#collage-empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 32px 0;
  display: none;
}

/* ── Lightbox ── */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
}

#lightbox.open { display: flex; }

#lb-img {
  max-width: min(92vw, 860px);
  max-height: 88vh;
  object-fit: contain;
  border-radius: 8px;
  user-select: none;
  -webkit-user-drag: none;
}

#lb-close {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  right: 16px;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Nav arrows — desktop only */
.lb-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 1.8rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

@media (hover: hover) {
  .lb-arrow { display: flex; }
}

#lb-prev { left: 16px; }
#lb-next { right: 16px; }

#lb-counter {
  position: absolute;
  bottom: calc(var(--safe-bot) + 16px);
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.6);
  font-size: 0.8rem;
}

/* ── Slideshow button ── */
#slideshow-btn-wrap {
  display: none;
  justify-content: flex-end;
  margin-bottom: 10px;
}

#slideshow-btn {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 60%, transparent);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 20px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

#slideshow-btn:hover {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  border-color: var(--accent);
}

/* ── Slideshow overlay ── */
#slideshow {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 150;
}

#slideshow.open { display: block; }

#ss-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.ss-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 1.2s ease;
  will-change: transform, opacity;
}

.ss-img.visible { opacity: 1; }

/* Paneo sutil sin zoom — 4 direcciones distintas */
@keyframes kb1 { from { transform: translate( 0.6%,  0.4%); } to { transform: translate(-0.6%, -0.4%); } } /* →izq+arriba */
@keyframes kb2 { from { transform: translate(-0.6%, -0.4%); } to { transform: translate( 0.6%,  0.4%); } } /* →der+abajo  */
@keyframes kb3 { from { transform: translate(-0.6%,  0.4%); } to { transform: translate( 0.6%, -0.4%); } } /* →der+arriba */
@keyframes kb4 { from { transform: translate( 0.6%, -0.4%); } to { transform: translate(-0.6%,  0.4%); } } /* →izq+abajo  */

.ss-img.kb1 { animation: kb1 5s ease-in-out forwards; }
.ss-img.kb2 { animation: kb2 5s ease-in-out forwards; }
.ss-img.kb3 { animation: kb3 5s ease-in-out forwards; }
.ss-img.kb4 { animation: kb4 5s ease-in-out forwards; }

/* Botón cerrar */
#ss-close {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  right: 16px;
  width: 40px;
  height: 40px;
  background: rgba(0,0,0,0.45);
  border: none;
  color: #fff;
  font-size: 1.5rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* Contador */
#ss-counter {
  position: absolute;
  top: calc(var(--safe-top) + 20px);
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.55);
  font-size: 0.78rem;
  z-index: 10;
  pointer-events: none;
}

/* Controles inferiores */
#ss-controls {
  position: absolute;
  bottom: calc(var(--safe-bot) + 28px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  align-items: center;
  z-index: 10;
}

#ss-controls button {
  background: rgba(0,0,0,0.45);
  border: none;
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.2s;
}

#ss-controls button:hover {
  background: rgba(0,0,0,0.65);
}

#ss-play {
  width: 56px;
  height: 56px;
  font-size: 1.1rem;
  letter-spacing: 2px;
}


/* ── Footer ── */
footer {
  text-align: center;
  padding: 20px 16px;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid #3a2e1a;
}

/* ── Loading spinner ── */
#loading {
  display: flex;
  justify-content: center;
  padding: 60px 0;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--card);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Error state ── */
#error-msg {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 0.9rem;
  display: none;
}
