:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --text: #e8eaed;
  --muted: #9aa0aa;
  --accent: #4a9eff;
  --border: #2a2f3a;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* El atributo [hidden] debe ganarle a los display:flex/grid de las clases.
   Sin esto, .viewer y .progress (display:flex) quedan siempre visibles. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

img { display: block; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: rgba(15, 17, 21, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.15rem; margin: 0; font-weight: 600; }
.count { color: var(--muted); font-size: 0.85rem; margin-left: auto; }

main { padding: 18px; max-width: 1400px; margin: 0 auto; }

/* Botones */
.btn {
  font: inherit;
  color: var(--text);
  background: var(--accent);
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: var(--panel-2); }

/* Grid de álbumes */
.albums-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.album-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.album-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.album-cover {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--panel-2);
}
.album-meta { padding: 10px 12px; }
.album-meta .name { font-weight: 600; word-break: break-word; }
.album-meta .n { color: var(--muted); font-size: 0.85rem; }

/* Toolbar del álbum */
.album-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.album-toolbar h2 { margin: 0; font-size: 1.1rem; word-break: break-word; }
.album-toolbar .btn { margin-left: auto; }

/* Grid de fotos */
.photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.photo-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
  transition: transform .12s, outline-color .12s;
  outline: 2px solid transparent;
}
.photo-thumb:hover { transform: scale(1.02); outline-color: var(--accent); }

/* Visor */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .92);
}
.viewer-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 92vw;
  max-height: 92vh;
  gap: 12px;
}
#viewerImg {
  max-width: 92vw;
  max-height: 78vh;
  object-fit: contain;
  border-radius: 6px;
  transition: filter .2s;
}
#viewerImg.loading { filter: blur(8px) brightness(.8); }
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 10px;
  max-width: 92vw;
}
.viewer-name { font-weight: 600; word-break: break-all; }
.viewer-index { color: var(--muted); font-size: .85rem; }
.viewer-close {
  position: absolute;
  top: 16px; right: 20px;
  font-size: 1.6rem;
  background: none; border: none; color: #fff;
  cursor: pointer; line-height: 1;
}
.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 3rem;
  background: none; border: none; color: #fff;
  cursor: pointer;
  padding: 0 18px;
  opacity: .7;
  transition: opacity .15s;
}
.viewer-nav:hover { opacity: 1; }
.viewer-nav.prev { left: 4px; }
.viewer-nav.next { right: 4px; }

/* Progreso */
.progress {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .75);
}
.progress-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: min(420px, 90vw);
  text-align: center;
}
.progress-box p { margin: 0 0 14px; }
.progress-track {
  height: 8px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 16px;
}
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width .2s; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 12px 18px;
  border-radius: 10px;
  z-index: 40;
  max-width: 90vw;
}

.empty { color: var(--muted); padding: 40px; text-align: center; }

@media (max-width: 600px) {
  .photos-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}
