:root {
  --fondo: #0d0e10;
  --capa: #17191d;
  --capa-2: #20232a;
  --borde: #2a2e36;
  --texto: #eceef1;
  --tenue: #8d939e;
  --fav: #ff4d6d;
  --arriba: env(safe-area-inset-top, 0px);
  --abajo: env(safe-area-inset-bottom, 0px);
  --pestanas: 56px;
  /* Ver «Escala» en app.js: con Chrome de Android en «Sitio de escritorio» la
     página se dibuja a 980 px de ancho y todo se ampliaría --escala veces. */
  --escala: 1;
  --vh: 1vh;
  --vw: 1vw;
}
@supports (height: 1dvh) { :root { --vh: 1dvh; } }
html.escalado { --vh: calc(1vh / var(--escala)); --vw: calc(1vw / var(--escala)); }
html.escalado #app, html.escalado #entrada, html.escalado .aviso { zoom: var(--escala); }
.visor-arriba, .visor-abajo { zoom: var(--escala-visor, 1); }

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

html { background: var(--fondo); color-scheme: dark; -webkit-text-size-adjust: 100%; }
html.con-visor, html.con-visor body { overflow: hidden; }

body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 24px; height: 24px; display: block; flex: none; }
.sprites { position: absolute; width: 0; height: 0; overflow: hidden; }

.icono {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--texto);
}
.icono:active { background: rgba(255, 255, 255, .12); }
.icono.tenue { color: var(--tenue); }
:focus-visible { outline: 2px solid #7fb2ff; outline-offset: 2px; }

/* ── Entrar ─────────────────────────────────────────────────────────────── */

.entrada {
  min-height: calc(var(--vh) * 100);
  display: grid; place-items: center;
  padding: 24px;
}
.tarjeta {
  width: min(100%, 340px);
  display: grid; gap: 14px;
}
.tarjeta .logo { width: 52px; height: 52px; color: var(--fav); margin: 0 auto; }
.tarjeta h1 { margin: 0 0 10px; text-align: center; font-size: 26px; font-weight: 650; letter-spacing: -.01em; }
.tarjeta label { display: grid; gap: 6px; }
.tarjeta label span { font-size: 13px; color: var(--tenue); }
.tarjeta input {
  height: 50px; padding: 0 14px;
  background: var(--capa); border: 1px solid var(--borde); border-radius: 12px;
  font-size: 17px;
}
.tarjeta input:focus { outline: none; border-color: #7fb2ff; }
.principal {
  height: 50px; margin-top: 6px;
  background: var(--texto); color: #111; border-radius: 12px;
  font-weight: 650; font-size: 17px;
}
.principal:disabled { opacity: .5; }
.error { margin: 0; color: #ff8095; font-size: 14px; }

/* ── Cabecera y pestañas ────────────────────────────────────────────────── */

.cabecera {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 2px;
  min-height: calc(56px + var(--arriba));
  padding: var(--arriba) 6px 0;
  background: rgba(13, 14, 16, .86);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--borde);
}
.titulos { flex: 1; min-width: 0; padding: 6px 8px; }
#atras:not([hidden]) + .titulos { padding-left: 2px; }
.titulos h1 {
  margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.migas {
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
  font-size: 13px; color: var(--tenue); white-space: nowrap;
}
.migas::-webkit-scrollbar { display: none; }
.migas:empty { display: none; }
.migas button { color: var(--tenue); padding: 2px 0; }
.migas button:active { color: var(--texto); }
.migas i { font-style: normal; opacity: .5; padding: 2px 5px; }

#contenido {
  padding-bottom: calc(var(--pestanas) + var(--abajo) + 24px);
  min-height: calc(var(--vh) * 60);
}

.pestanas {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex;
  height: calc(var(--pestanas) + var(--abajo));
  padding-bottom: var(--abajo);
  background: rgba(19, 21, 24, .92);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--borde);
}
.pestanas button {
  flex: 1; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--tenue); font-size: 11px; font-weight: 550;
}
.pestanas button.activa { color: var(--texto); }
.pestanas button[data-vista="favoritas"].activa svg { color: var(--fav); }
.pestanas b {
  position: absolute; top: 5px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px;
  display: grid; place-items: center;
  background: var(--fav); color: #fff; border-radius: 9px;
  font-size: 11px; font-weight: 700;
}

/* ── Carpetas ───────────────────────────────────────────────────────────── */

.resumen { margin: 0; padding: 12px 16px 8px; font-size: 13px; color: var(--tenue); }

.carpetas {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0 12px; padding: 4px 8px 10px;
}
.carpeta {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding: 8px 8px; border-radius: 10px;
  text-align: left; min-width: 0;
}
.carpeta:active { background: var(--capa); }
.carpeta svg:first-child { color: #6ea8ff; width: 28px; height: 28px; }
.carpeta span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.carpeta svg:last-child { width: 18px; height: 18px; color: var(--tenue); opacity: .6; }
@media (hover: hover) { .carpeta:hover { background: var(--capa); } }

/* ── Rejilla ────────────────────────────────────────────────────────────── */

.rejilla {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 3px; padding: 0 0 3px;
}
@media (min-width: 700px) {
  .rejilla { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 4px; padding: 0 4px 4px; }
}
/* Un teléfono en «Sitio de escritorio» dice medir 980 px: sigue siendo un teléfono. */
html.escalado .rejilla { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 3px; padding: 0 0 3px; }
.tesela {
  position: relative; aspect-ratio: 1; overflow: hidden;
  background: var(--capa);
}
.tesela img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  -webkit-user-drag: none; user-select: none; -webkit-touch-callout: none;
}
.tesela.rota img { visibility: hidden; }
.tesela.rota::after {
  content: "No se puede abrir"; position: absolute; inset: 0;
  display: grid; place-items: center; padding: 6px; text-align: center;
  font-size: 11px; color: var(--tenue);
}
.tesela .marca {
  position: absolute; right: 5px; bottom: 5px; width: 20px; height: 20px;
  color: var(--fav); filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .7));
  display: none;
}
.tesela.es-fav .marca { display: block; }
.tesela:active img { opacity: .8; }
@media (hover: hover) { .tesela:hover img { opacity: .88; } }

.grupo {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 16px 14px 9px; text-align: left;
  font-size: 14px; font-weight: 600;
}
.grupo svg { width: 20px; height: 20px; color: #6ea8ff; }
.grupo span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grupo em { font-style: normal; font-weight: 400; color: var(--tenue); font-size: 13px; }

.vacio {
  padding: calc(var(--vh) * 18) 32px 0; text-align: center; color: var(--tenue);
  display: grid; gap: 10px; justify-items: center;
}
.vacio svg { width: 44px; height: 44px; opacity: .5; }
.vacio strong { color: var(--texto); font-size: 17px; font-weight: 600; }
.vacio button { margin-top: 8px; padding: 10px 18px; border-radius: 10px; background: var(--capa-2); color: var(--texto); }

.cargando { padding: calc(var(--vh) * 20) 0 0; display: grid; place-items: center; }
.cargando::after {
  content: ""; width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--borde); border-top-color: var(--texto);
  animation: girar .8s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

/* ── Visor ──────────────────────────────────────────────────────────────── */

.visor {
  position: fixed; inset: 0; z-index: 20;
  background: #000;
  touch-action: none; user-select: none; -webkit-user-select: none;
  overflow: hidden;
}
.pista { position: absolute; inset: 0; touch-action: none; cursor: grab; }
.hoja { position: absolute; inset: 0; display: grid; place-items: center; }
/* La imagen va fuera del flujo: como hija normal de la rejilla, su alto en %
   se resolvía contra una fila «auto» y la foto, a todo el ancho, se salía de
   la pantalla por abajo en cuanto la ventana era más ancha que alta. */
.hoja img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: contain; display: block;
  -webkit-user-drag: none; user-select: none; pointer-events: none;
  will-change: transform;
}
.hoja.rota img { visibility: hidden; }
.hoja.rota::after {
  content: "No se puede abrir esta foto"; position: absolute; color: var(--tenue);
}

.visor-arriba, .visor-abajo, .flecha { transition: opacity .18s; }
.visor.limpio .visor-arriba, .visor.limpio .visor-abajo, .visor.limpio .flecha { opacity: 0; pointer-events: none; }

.visor-arriba {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 4px;
  padding: calc(var(--arriba) + 6px) 8px 22px;
  background: linear-gradient(rgba(0, 0, 0, .7), transparent);
}
.visor-titulo { flex: 1; min-width: 0; display: grid; text-align: center; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); }
#visor-nombre { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#visor-cuenta { font-size: 12px; color: rgba(255, 255, 255, .7); font-variant-numeric: tabular-nums; }

.visor-abajo {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: center;
  padding: 26px 16px calc(var(--abajo) + 18px);
  background: linear-gradient(transparent, rgba(0, 0, 0, .7));
  pointer-events: none;
}
.fav {
  pointer-events: auto;
  display: flex; align-items: center; gap: 9px;
  height: 52px; padding: 0 22px 0 18px; border-radius: 26px;
  background: rgba(40, 42, 48, .78);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, .14);
  font-weight: 600; font-size: 16px;
  transition: background .15s, transform .1s;
}
.fav:active { transform: scale(.95); }
.fav svg { width: 26px; height: 26px; }
.fav .lleno { display: none; color: var(--fav); }
.fav[aria-pressed="true"] { background: rgba(255, 77, 109, .22); border-color: rgba(255, 77, 109, .55); }
.fav[aria-pressed="true"] .hueco { display: none; }
.fav[aria-pressed="true"] .lleno { display: block; animation: latido .32s ease-out; }
@keyframes latido { 0% { transform: scale(.6); } 55% { transform: scale(1.28); } 100% { transform: scale(1); } }

.flecha {
  position: absolute; top: 50%; width: 48px; height: 48px; margin-top: -24px;
  display: none; place-items: center; border-radius: 50%;
  background: rgba(30, 32, 37, .6); color: #fff;
}
.flecha.izq { left: 14px; }
.flecha.der { right: 14px; }
.flecha:disabled { opacity: .25; cursor: default; }
@media (hover: hover) and (pointer: fine) {
  .flecha { display: grid; }
  .flecha:not(:disabled):hover { background: rgba(60, 63, 70, .85); }
}

.aviso {
  position: fixed; left: 50%; bottom: calc(var(--pestanas) + var(--abajo) + 18px); z-index: 40;
  transform: translateX(-50%);
  max-width: calc(var(--vw) * 100 - 32px); padding: 11px 16px; border-radius: 12px;
  background: #33363d; color: #fff; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
