/* ==========================================================================
   La Gabbia · Neolatina
   Paleta, fuentes y formas originales; UI/UX responsive.
   ========================================================================== */

:root {
  --bg-color: #121316;
  --bg-secondary: #1a1c23;
  --text-color: #dcdcdd;
  --text-muted: #8c92a4;
  --accent-color: #d4af37; /* Oro / latón latino */
  --border-color: #282c37;
  --font-serif: 'Lora', 'Playfair Display', Georgia, serif;
  --font-display: 'Playfair Display', Georgia, serif;
  --max-width: 760px;
  --radius: 4px;
  --header-h: 5rem;
  color-scheme: dark;
}

html.light-theme {
  --bg-color: #f7f6f2;
  --bg-secondary: #eae8e1;
  --text-color: #2b2c2e;
  --text-muted: #5f6166;
  --accent-color: #7d5e0f;
  --border-color: #dcd9cd;
  color-scheme: light;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 1rem);
}

body {
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: var(--font-serif);
  line-height: 1.8;
  font-size: 1.1rem;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-wrap: break-word;
  text-rendering: optimizeLegibility;
  transition: background-color 0.3s ease, color 0.3s ease;
}

main { flex: 1 0 auto; width: 100%; }

img, iframe, video { max-width: 100%; }
[hidden] { display: none !important; }

a { color: var(--accent-color); text-underline-offset: 0.2em; }

::selection { background: var(--accent-color); color: var(--bg-color); }

:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 3px;
  border-radius: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
}

/* ---------- Cabecera fija ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--bg-color);
  border-bottom: 1px solid var(--border-color);
  padding: 1.1rem 0;
  padding-top: calc(1.1rem + env(safe-area-inset-top, 0px));
  margin-bottom: 3rem;
  transition: background-color 0.3s ease;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
}

.site-title {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-color);
  text-decoration: none;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1.3;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  align-items: center;
}

.site-nav a {
  color: var(--text-color);
  text-decoration: none;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.site-nav a:hover { color: var(--accent-color); }
.site-nav a[aria-current="page"] {
  color: var(--accent-color);
  border-bottom-color: var(--accent-color);
}

.theme-toggle-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0.4rem;
  min-width: 44px;
  min-height: 44px;
  color: var(--text-color);
  line-height: 1;
}

/* Barra de progreso de lectura (solo en entradas) */
.reading-progress {
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--accent-color);
  transform: scaleX(0);
  transform-origin: left;
}

/* ---------- Portada ---------- */
.hero-section {
  text-align: center;
  padding: 2rem 0 3rem;
  border-bottom: 1px dashed var(--border-color);
  margin-bottom: 3rem;
}

.hero-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 1.5rem + 2.5vw, 2.6rem);
  font-weight: 700;
  margin-bottom: 0.5rem;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.hero-subtitle {
  color: var(--text-muted);
  font-style: italic;
  font-size: clamp(1.05rem, 1rem + 0.3vw, 1.2rem);
}

.latest, .recent-posts, .topics { margin-bottom: 3.5rem; }

.section-heading {
  font-size: 1.3rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-color);
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  line-height: 1.4;
}

.page-title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 1.3rem + 1.5vw, 2.1rem);
  line-height: 1.25;
  margin-bottom: 1.5rem;
  text-wrap: balance;
}

/* ---------- Migas de pan ---------- */
.breadcrumb { margin-bottom: 1.2rem; font-size: 0.85rem; color: var(--text-muted); }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: 0.1rem 0.5rem; }
.breadcrumb li + li::before { content: "›"; margin-right: 0.5rem; opacity: 0.6; }
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent-color); text-decoration: underline; }
.breadcrumb [aria-current] { color: var(--text-color); }
.post-header .breadcrumb ol { justify-content: center; }

/* ---------- Lista de entradas ---------- */
.post-list { list-style: none; }

.post-item {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.post-thumb {
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 140px;
  height: 95px;
  overflow: hidden;
  border-radius: var(--radius);
  background-color: var(--bg-secondary);
}

.post-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}
.post-item:hover .post-thumb img { transform: scale(1.05); }

.post-thumb-initial {
  font-family: var(--font-display);
  font-size: 2.2rem;
  color: var(--accent-color);
  opacity: 0.7;
}

.post-info { flex: 1; min-width: 0; }

.post-date {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  font-family: monospace;
}

.post-title-heading {
  font-size: 1.3rem;
  line-height: 1.35;
  margin: 0.2rem 0 0.5rem;
  text-wrap: balance;
}

.post-link {
  color: var(--text-color);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.2s;
}
.post-link:hover { color: var(--accent-color); }

.post-summary {
  margin-top: 0.3rem;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-muted);
}

/* Entrada destacada (la última) */
.post-item--featured { border-bottom: none; padding-bottom: 0; margin-bottom: 0; gap: 1.8rem; }
.post-item--featured .post-thumb { width: 240px; height: 160px; }
.post-item--featured .post-thumb-initial { font-size: 3.2rem; }
.post-item--featured .post-title-heading { font-size: 1.7rem; font-family: var(--font-display); }
.post-item--featured .post-summary { font-size: 1.02rem; }

.see-all { margin-top: 1rem; text-align: right; font-size: 0.95rem; }
.btn-link {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 0.2s, background-color 0.2s;
}
.btn-link:hover { border-color: var(--accent-color); background-color: var(--bg-secondary); }
.no-posts { color: var(--text-muted); }

/* ---------- Archivo: buscador y años ---------- */
.archive-tools { margin: 0 0 2rem; }

.search-input {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--text-color);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  min-height: 46px;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { outline: none; border-color: var(--accent-color); }

.archive-count { margin-top: 0.6rem; font-size: 0.9rem; color: var(--text-muted); line-height: 1.5; }

.year-heading {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--accent-color);
  margin: 2.5rem 0 1.2rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px dashed var(--border-color);
}
.year-group:first-of-type .year-heading { margin-top: 1rem; }

/* ---------- Etiquetas ---------- */
.tag-cloud { list-style: none; display: flex; flex-wrap: wrap; gap: 0.6rem; }
.tag-cloud a {
  display: inline-block;
  padding: 0.15rem 0.8rem;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  color: var(--accent-color);
  text-decoration: none;
  font-size: 0.95rem;
  line-height: 1.7;
  transition: border-color 0.2s, background-color 0.2s;
}
.tag-cloud a:hover { border-color: var(--accent-color); background-color: var(--bg-secondary); }
.tag-count { color: var(--text-muted); font-size: 0.8rem; }
.tag-cloud--small { justify-content: center; }
.tag-cloud--small a { font-size: 0.82rem; }

/* ---------- Entrada ---------- */
.post-header { margin-bottom: 2.5rem; text-align: center; }

.post-title {
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 1.3rem + 2vw, 2.3rem);
  line-height: 1.25;
  margin-bottom: 0.7rem;
  text-wrap: balance;
}

.post-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.1rem 0.6rem;
  line-height: 1.6;
}

.post-content {
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
}

/* Los <p> heredan la alineación del contenedor (p. ej. versos centrados) */
.post-content p { margin-bottom: 1.6rem; text-align: inherit; text-wrap: pretty; }

.post-content a { text-decoration: underline; text-decoration-thickness: 1px; }
.post-content a:hover { text-decoration-thickness: 2px; }

.post-content h2, .post-content h3, .post-content h4 {
  font-family: var(--font-display);
  line-height: 1.3;
  margin: 2.2rem 0 1rem;
  text-align: left;
  text-wrap: balance;
}

.post-content ul, .post-content ol { margin: 0 0 1.6rem 1.5rem; }
.post-content li { margin-bottom: 0.4rem; }

.post-content hr {
  border: none;
  border-top: 1px dashed var(--border-color);
  margin: 2rem 0;
}

.post-content blockquote {
  border-left: 3px solid var(--accent-color);
  padding-left: 1.2rem;
  margin: 2rem 0;
  font-style: italic;
  color: var(--text-muted);
}

.post-content pre, .post-content table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  margin-bottom: 1.6rem;
}
.post-content table { border-collapse: collapse; }
.post-content th, .post-content td { border: 1px solid var(--border-color); padding: 0.4rem 0.7rem; }

.post-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: var(--radius);
}

/* Imágenes importadas de Blogger */
.post-content .separator { text-align: center; max-width: 100%; }
.post-content .separator a { margin: 0 !important; float: none !important; display: block; }

/* Videos: caben en pantalla y mantienen 16:9 */
.post-content iframe {
  display: block;
  width: 100%;
  max-width: 560px;
  height: auto;
  aspect-ratio: 16 / 9;
  border: 0;
  margin: 1.5rem auto;
}
.video-container { max-width: 560px; margin: 1.5rem auto; }
.video-container iframe { margin: 0; }

/* Pie de la entrada */
.post-footer {
  margin-top: 3rem;
  padding-top: 1.8rem;
  border-top: 1px solid var(--border-color);
}

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 2rem;
}
.post-nav-link {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-color);
  transition: border-color 0.2s, background-color 0.2s;
}
.post-nav-link:hover { border-color: var(--accent-color); background-color: var(--bg-secondary); }
.post-nav-link--newer { text-align: right; grid-column: 2; }
.post-nav-link--older { grid-column: 1; }
.post-nav-label { font-size: 0.8rem; color: var(--accent-color); letter-spacing: 0.04em; }
.post-nav-title { font-weight: 600; line-height: 1.4; font-size: 1rem; }

.related { margin-top: 3rem; }
.related .post-item:last-child { border-bottom: none; margin-bottom: 0; }

.not-found .post-list { margin: 2rem 0 1rem; }

/* ---------- Volver arriba ---------- */
.to-top {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 40;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--accent-color);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s;
}
.to-top:hover { border-color: var(--accent-color); }

/* ---------- Pie de página ---------- */
.site-footer {
  margin-top: 5rem;
  padding: 2.5rem 0 2rem;
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-color);
  font-size: 0.9rem;
  color: var(--text-muted);
}

.footer-grid {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem 3rem;
  flex-wrap: wrap;
  margin-bottom: 1.8rem;
}
.footer-brand { max-width: 22rem; }
.footer-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--accent-color);
}
.footer-brand p { margin-top: 0.3rem; font-style: italic; line-height: 1.6; }

.footer-links { display: flex; flex-wrap: wrap; gap: 0.2rem 1.5rem; align-content: flex-start; }
.footer-links a { color: var(--text-color); text-decoration: none; padding: 0.4rem 0; }
.footer-links a:hover { color: var(--accent-color); text-decoration: underline; }

.footer-credit {
  padding-top: 1.2rem;
  border-top: 1px dashed var(--border-color);
  text-align: center;
  font-size: 0.85rem;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

/* Tablets */
@media (max-width: 820px) {
  .post-item--featured .post-thumb { width: 200px; height: 135px; }
}

/* Móviles */
@media (max-width: 640px) {
  :root { --header-h: 4.2rem; }
  body { font-size: 1rem; }

  .container {
    padding-left: max(1.1rem, env(safe-area-inset-left));
    padding-right: max(1.1rem, env(safe-area-inset-right));
  }

  .site-header {
    padding: 0.5rem 0 0.1rem;
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
    margin-bottom: 2rem;
  }
  .header-inner { flex-direction: column; align-items: stretch; gap: 0; }
  .site-title { font-size: 1.2rem; line-height: 1.4; }
  .site-nav { width: 100%; flex-wrap: nowrap; justify-content: space-between; gap: 0 0.4rem; }
  .site-nav a { font-size: 0.72rem; letter-spacing: 0.03em; padding: 0.55rem 0; white-space: nowrap; }
  .theme-toggle-btn { min-width: 40px; min-height: 40px; padding: 0.2rem; font-size: 1.1rem; }

  .hero-section { padding: 1rem 0 2rem; margin-bottom: 2rem; }
  .section-heading { font-size: 1.1rem; margin-bottom: 1.2rem; }
  .latest, .recent-posts, .topics { margin-bottom: 2.5rem; }

  /* Lista: miniatura chica a la izquierda */
  .post-item { gap: 1rem; margin-bottom: 1.5rem; padding-bottom: 1.2rem; }
  .post-thumb { width: 88px; height: 66px; }
  .post-thumb-initial { font-size: 1.6rem; }
  .post-title-heading { font-size: 1.1rem; }
  .post-summary { font-size: 0.9rem; }

  /* Entrada destacada: imagen arriba, a todo el ancho */
  .post-item--featured { flex-direction: column; gap: 0.9rem; }
  .post-item--featured .post-thumb { width: 100%; height: auto; aspect-ratio: 16 / 9; }
  .post-item--featured .post-thumb-initial { font-size: 2.6rem; }
  .post-item--featured .post-title-heading { font-size: 1.35rem; }
  .post-item--featured .post-info { width: 100%; }

  .post-header { margin-bottom: 1.8rem; }
  .post-meta { font-size: 0.85rem; }

  /* Justificado en pantallas angostas deja "ríos" de espacio: alinear a la izquierda */
  .post-content { text-align: left; }

  .post-nav { grid-template-columns: 1fr; }
  .post-nav-link--newer, .post-nav-link--older { grid-column: 1; text-align: left; }

  .see-all { text-align: left; }
  .year-heading { font-size: 1.3rem; margin-top: 2rem; }

  .footer-grid { flex-direction: column; }
  .site-footer { margin-top: 3rem; padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px)); }
  .footer-links { gap: 0.2rem 1.2rem; }
}

@media (max-width: 380px) {
  .site-nav a { font-size: 0.66rem; letter-spacing: 0; }
  .hero-title { font-size: 1.75rem; }
  .post-title { font-size: 1.5rem; }
}

/* Pantallas grandes */
@media (min-width: 1400px) {
  body { font-size: 1.15rem; }
  :root { --max-width: 800px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}

@media print {
  .site-header, .site-footer, .theme-toggle-btn, .to-top, .post-footer, .breadcrumb { display: none; }
  body { background: #fff; color: #000; }
  .post-content { text-align: left; }
}
