:root {
  --bg: #171a21;
  --surface: #1f232c;
  --surface-hover: #262b36;
  --border: #2e3340;
  --text: #eceef2;
  --text-muted: #8d94a6;
  --accent: #5ec4b6;
  --accent-text: #0b2420;
  --rojo: #f87171;
  --alto-pestanas: 64px;
}

* { box-sizing: border-box; }

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

.oculto { display: none !important; }
.error { color: var(--rojo); margin: 0; }
.ayuda { color: var(--text-muted); margin: 0; }

input, select, button {
  font-size: 16px;            /* 16 px: por debajo, iOS hace zoom al enfocar */
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
button {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  font-weight: 600;
  cursor: pointer;
}
button.secundario { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
button.peligro { background: transparent; color: var(--rojo); border: 1px solid var(--rojo); }
button:disabled { opacity: 0.4; cursor: default; }

.pantalla-centrada {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.caja-form { display: flex; flex-direction: column; gap: 12px; width: min(360px, 100%); }
.caja-form h1, .caja-form h2 { margin: 0 0 4px; }
.dos-columnas { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dos-columnas input { min-width: 0; }
.botones { display: flex; gap: 12px; }
.botones button { flex: 1; }

header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--bg);
}

#estado-rejilla { margin: 0 12px 12px; color: var(--text-muted); }
#estado-rejilla.error { color: var(--rojo); }

#rejilla {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  padding: 0 12px calc(var(--alto-pestanas) + 90px);
}

.tarjeta { background: var(--surface); border-radius: 10px; overflow: hidden; cursor: pointer; }
.tarjeta .titulo { padding: 8px 10px 2px; font-size: 14px; font-weight: 600; line-height: 1.25; }
.tarjeta .autores { padding: 0 10px 10px; font-size: 12px; color: var(--text-muted); }

/* Sin portada todavia (llegan en la fase 2): un lomo de color con el titulo. */
.sin-portada {
  aspect-ratio: 2 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  text-align: center;
  font-weight: 700;
  color: var(--accent-text);
  background: linear-gradient(160deg, var(--accent), #2f7f74);
  overflow: hidden;
  overflow-wrap: anywhere;
}

#boton-anadir {
  position: fixed;
  right: 18px;
  bottom: calc(var(--alto-pestanas) + 18px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 28px;
  padding: 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

#pestanas {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--alto-pestanas) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 10;
}
#pestanas button {
  background: none;
  color: var(--text-muted);
  border-radius: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 20px;
  padding: 8px 0;
}
#pestanas button span { font-size: 11px; font-weight: 600; }
#pestanas button.activa { color: var(--accent); }

#vista-yo { padding: 16px 16px calc(var(--alto-pestanas) + 24px); display: flex; flex-direction: column; gap: 12px; }
#vista-yo h2, #vista-yo h3 { margin: 8px 0 0; }
#panel-admin { display: flex; flex-direction: column; gap: 10px; }
.lista { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lista li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.lista li .crece { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.lista li button { padding: 8px 12px; font-size: 14px; }
.lista li.vacia { color: var(--text-muted); justify-content: center; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 30;
}
.modal .caja-form { background: var(--bg); border: 1px solid var(--border); border-radius: 16px; padding: 18px; }
#dialogo { z-index: 50; }
.dialogo-caja { background: var(--bg); border: 1px solid var(--border); border-radius: 16px; padding: 18px; width: min(360px, 100%); }
#dialogo-texto { margin: 0 0 16px; white-space: pre-line; overflow-wrap: anywhere; }
.dialogo-botones { display: flex; gap: 12px; }
.dialogo-botones button { flex: 1; }

#ficha { position: fixed; inset: 0; background: var(--bg); overflow-y: auto; z-index: 20; }
#ficha-portada { position: relative; display: flex; justify-content: center; padding: 24px 16px 8px; }
#ficha-portada .sin-portada { width: min(220px, 60vw); border-radius: 10px; font-size: 20px; }
#boton-cerrar-ficha {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 22px;
}
#ficha-cuerpo { padding: 8px 16px 32px; display: flex; flex-direction: column; gap: 12px; max-width: 640px; margin: 0 auto; }
#ficha-titulo { margin: 0; }
#ficha-datos { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
#ficha-datos dt { color: var(--text-muted); }
#ficha-datos dd { margin: 0; overflow-wrap: anywhere; }
