/*
 * Cuadernos — CSS
 *
 * Diseño "híbrido refinado":
 *   - Estructura (header, índice, navegación, metadata): serif clásica
 *     elegante. Tono editorial sobrio.
 *   - Cuerpo del artículo: tipografía monoespaciada. Declara identidad
 *     técnica desde la lectura misma.
 *
 * Decisiones:
 *   - Solo fuentes del sistema. CERO web fonts externos (coherente con
 *     la temática editorial: no se carga nada de terceros).
 *   - Sin JavaScript en el front. Sin tracking. Sin pop-ups. Sin ads.
 *   - Columna estrecha (~70 caracteres por línea) para lectura cómoda.
 *   - Modo claro y oscuro respetando preferencia del sistema.
 */

/* ── Reset mínimo ──────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
img { max-width: 100%; height: auto; display: block; }
a { color: inherit; }

/* ── Variables ─────────────────────────────────────────────────── */

/* TEMA CLARO (default + cuando data-theme="light").
   Crema cálida, no blanco nuclear. Ajuste Ramón 2026-05-16:
   "que no te queme la retina". */
:root, :root[data-theme="light"] {
  --bg: #f4efe4;
  --bg-elev: #faf6ec;
  --fg: #1f1c17;
  --fg-soft: #5b554c;
  --fg-faint: #8a8378;
  --accent: #6d3f1c;
  --rule: #d8d0bf;
  --rule-soft: #ebe5d5;

  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif;
  --mono: "JetBrains Mono", "IBM Plex Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;

  --width-text: 38rem;
  --width-wide: 52rem;
}

/* TEMA OSCURO "papel viejo" — sepia oscuro cálido (no negro frío).
   Crítica Gemini 2026-05-16: abogados leen de noche, modo oscuro debe ser cálido. */
:root[data-theme="dark"] {
  --bg: #1c1814;
  --bg-elev: #25201b;
  --fg: #eee5d6;
  --fg-soft: #b8aa92;
  --fg-faint: #847868;
  --accent: #d4a677;
  --rule: #3a322a;
  --rule-soft: #2a241e;
}

/* Si NO hay preferencia explícita (data-theme ausente), respetar el
   tema del sistema. Es lo que ve un visitante en su primera visita,
   antes de tocar el toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #1c1814;
    --bg-elev: #25201b;
    --fg: #eee5d6;
    --fg-soft: #b8aa92;
    --fg-faint: #847868;
    --accent: #d4a677;
    --rule: #3a322a;
    --rule-soft: #2a241e;
  }
}

/* ── Tipografía base ───────────────────────────────────────────── */

body {
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Layout común ──────────────────────────────────────────────── */

.cuadernos-header {
  border-bottom: 1px solid var(--rule);
  padding: 2rem 1.5rem 1.5rem;
  position: relative;
}

.cuadernos-header-inner {
  max-width: var(--width-wide);
  margin: 0 auto;
}

/* Controles del header: toggle tema + selector idioma (arriba a la derecha).
   El JavaScript de Cuadernos se limita a estos dos controles + atajos
   de teclado. Declarado con honestidad en el footer. */
.cuadernos-header-controls {
  position: absolute;
  top: 1.4rem;
  right: 1.5rem;
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.cuadernos-theme-toggle,
.cuadernos-lang-toggle {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--fg-soft);
  background: transparent;
  border: 1px solid var(--rule);
  padding: 0.4rem 0.8rem;
  border-radius: 3px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background 0.15s, color 0.15s;
}
.cuadernos-theme-toggle:hover,
.cuadernos-lang-toggle:hover {
  background: var(--rule-soft);
  color: var(--accent);
}

/* Menú desplegable del selector de idioma */
.cuadernos-lang-wrap {
  position: relative;
}
.cuadernos-lang-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.4rem;
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  min-width: 12rem;
  max-height: 22rem;
  overflow-y: auto;
  z-index: 100;
}
.cuadernos-lang-menu.is-open {
  display: block;
}
.cuadernos-lang-item {
  display: block;
  padding: 0.45rem 0.9rem;
  font-family: var(--serif);
  font-size: 0.9rem;
  color: var(--fg-soft);
  text-decoration: none;
  border-bottom: 1px solid var(--rule-soft);
}
.cuadernos-lang-item:last-child {
  border-bottom: none;
}
.cuadernos-lang-item:hover {
  background: var(--rule-soft);
  color: var(--accent);
}
.cuadernos-lang-item.is-current {
  color: var(--accent);
  font-weight: 600;
  background: var(--rule-soft);
}
.cuadernos-lang-item.is-highlight {
  background: var(--rule-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* Search input inside the language menu — paridad con el landing principal,
   normalización Unicode para selección rápida entre 41 idiomas. */
.cuadernos-lang-search-wrap {
  padding: 0.5rem;
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 1;
}
.cuadernos-lang-search {
  width: 100%;
  padding: 0.4rem 0.6rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--fg);
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: 3px;
  outline: none;
  box-sizing: border-box;
}
.cuadernos-lang-search:focus {
  border-color: var(--accent);
}
.cuadernos-lang-search::-webkit-search-cancel-button { -webkit-appearance: none; }
.cuadernos-lang-list { display: block; }

@media (max-width: 640px) {
  .cuadernos-header-controls {
    position: static;
    margin-top: 0.8rem;
    justify-content: flex-end;
  }
  .cuadernos-lang-menu {
    right: auto;
    left: 0;
  }
}

.cuadernos-header h1,
.cuadernos-header .cuadernos-title {
  font-family: var(--serif);
  font-weight: normal;
  font-size: 2.4rem;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.1;
}

.cuadernos-header h1 a,
.cuadernos-header .cuadernos-title a {
  text-decoration: none;
  color: var(--fg);
}

.cuadernos-tagline {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--fg-soft);
  margin: 0.4rem 0 0;
}

/* Kicker line: tagline on the left, compact prev/next on the right. */
.cuadernos-kicker-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
}
.cuadernos-kicker-line .cuadernos-tagline { margin: 0.4rem 0 0; flex: 0 1 auto; }

.cuadernos-prevnext-compact {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--fg-soft);
  margin-top: 0.4rem;
  text-align: right;
}
.cuadernos-prevnext-compact:empty { display: none; }
.cuadernos-prevnext-compact-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted transparent;
  transition: color 0.15s, border-bottom-color 0.15s;
}
.cuadernos-prevnext-compact-link:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.cuadernos-prevnext-compact-sep {
  opacity: 0.45;
  margin: 0 0.5em;
}

.cuadernos-back {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--fg-soft);
  text-decoration: none;
  display: inline-block;
  margin-bottom: 0.6rem;
}
.cuadernos-back:hover { color: var(--accent); }

.cuadernos-main {
  max-width: var(--width-wide);
  margin: 3rem auto;
  padding: 0 1.5rem;
}

.cuadernos-footer {
  border-top: 1px solid var(--rule);
  padding: 2rem 1.5rem 3rem;
  margin-top: 5rem;
}
.cuadernos-footer-inner {
  max-width: var(--width-wide);
  margin: 0 auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--fg-faint);
  line-height: 1.7;
}
/* Balance long attribution lines so they don't wrap with an orphan word.
   The attribution paragraph has 4 segments separated by " · "; we cap
   the per-paragraph width so it splits at the natural editorial-vs-
   institutional boundary, and ask the browser for balanced wrapping. */
.cuadernos-footer-inner p {
  max-width: 36rem;
  margin-left: auto;
  margin-right: auto;
  text-wrap: pretty;
}
.cuadernos-footer a {
  color: var(--fg-soft);
  text-decoration: none;
  border-bottom: 1px dotted var(--rule);
}
.cuadernos-footer a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Portada (index) ───────────────────────────────────────────── */

.cuadernos-intro {
  font-family: var(--serif);
  font-size: 1.1rem;
  color: var(--fg-soft);
  max-width: var(--width-text);
  margin: 0 0 3rem;
  line-height: 1.7;
}
.cuadernos-intro p + p { margin-top: 1rem; }

.cuadernos-articles {
  list-style: none;
  padding: 0;
  margin: 0;
}
.cuadernos-articles > li {
  padding: 1.6rem 0;
  border-top: 1px solid var(--rule-soft);
}
.cuadernos-articles > li:last-child {
  border-bottom: 1px solid var(--rule-soft);
}

.cuadernos-meta {
  font-family: var(--mono);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-faint);
  margin-bottom: 0.3rem;
}
.cuadernos-meta .cuadernos-sep { padding: 0 0.4em; opacity: 0.5; }

.cuadernos-articles h2 {
  font-family: var(--serif);
  font-weight: normal;
  font-size: 1.5rem;
  line-height: 1.25;
  margin: 0 0 0.4rem;
}
.cuadernos-articles h2 a {
  text-decoration: none;
  color: var(--fg);
}
.cuadernos-articles h2 a:hover {
  color: var(--accent);
}

.cuadernos-articles .cuadernos-summary {
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--fg-soft);
  margin: 0;
  max-width: var(--width-text);
}

/* ── Artículo ──────────────────────────────────────────────────── */

.cuadernos-article {
  max-width: var(--width-text);
  margin: 0 auto;
}

.cuadernos-article-header {
  margin-bottom: 2.5rem;
}

.cuadernos-article h1 {
  font-family: var(--serif);
  font-weight: normal;
  font-size: 2.2rem;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0.5rem 0 0.8rem;
}

.cuadernos-article .cuadernos-subtitle {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.2rem;
  color: var(--fg-soft);
  margin: 0;
  line-height: 1.5;
}

/* Cuerpo del artículo en MONOESPACIADA.
   Ajustes 2026-05-16 (auditoría Gemini): line-height generoso y
   font-size ligeramente mayor para evitar fatiga en artículos largos.
   La identidad técnica se mantiene; la legibilidad para audiencia legal
   no se sacrifica. */
.cuadernos-body {
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.85;
  color: var(--fg);
  letter-spacing: -0.005em;
}

.cuadernos-body p {
  margin: 1.4rem 0;
}

.cuadernos-body h2 {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin: 2.8rem 0 0.6rem;
}

.cuadernos-body h3 {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
  margin: 2.2rem 0 0.5rem;
}

.cuadernos-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
}
.cuadernos-body a:hover { border-bottom-color: var(--accent); }

.cuadernos-body blockquote {
  margin: 1.5rem 0;
  padding: 0.2rem 0 0.2rem 1.2rem;
  border-left: 2px solid var(--rule);
  color: var(--fg-soft);
  font-style: italic;
}
.cuadernos-body blockquote p { margin: 0.4rem 0; }

.cuadernos-body ul, .cuadernos-body ol {
  padding-left: 1.5rem;
  margin: 1.2rem 0;
}
.cuadernos-body li { margin: 0.4rem 0; }

.cuadernos-body code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--rule-soft);
  padding: 0.1em 0.35em;
  border-radius: 2px;
}

.cuadernos-body pre.cuadernos-code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--rule-soft);
  padding: 1rem 1.25rem;
  border-left: 3px solid var(--rule);
  border-radius: 2px;
  margin: 1.6rem 0;
  overflow-x: auto;
  line-height: 1.5;
  white-space: pre;
}
.cuadernos-body pre.cuadernos-code code {
  background: transparent;
  padding: 0;
  font-size: 1em;
  border-radius: 0;
}

/* Definición inline para términos técnicos (bits/bytes, etc.) que merecen
   explicación cerca de donde aparecen. Bloque compacto que interrumpe
   brevemente el flujo con un diagrama visual en texto monoespaciado.
   Idea Ramón 2026-05-18. */
.cuadernos-body aside.cuadernos-aside-defn {
  background: var(--rule-soft);
  border-left: 3px solid var(--rule);
  padding: 0.9rem 1.1rem;
  margin: 1.5rem 0;
  font-size: 0.92em;
  line-height: 1.55;
  color: var(--fg-soft);
  border-radius: 2px;
}
.cuadernos-body aside.cuadernos-aside-defn strong {
  color: var(--fg);
  font-weight: 600;
  display: block;
  margin-bottom: 0.55rem;
}
.cuadernos-body aside.cuadernos-aside-defn pre {
  font-family: var(--mono);
  font-size: 0.92em;
  margin: 0.55rem 0;
  background: transparent;
  padding: 0;
  white-space: pre;
  overflow-x: auto;
  color: var(--fg);
}

.cuadernos-body aside.cuadernos-tldr {
  background: var(--rule-soft);
  padding: 0.9rem 1.1rem;
  margin: 1.5rem 0;
  font-size: 0.92em;
  line-height: 1.55;
  color: var(--fg-soft);
  border-radius: 2px;
}
.cuadernos-body aside.cuadernos-tldr strong {
  color: var(--fg);
  font-weight: 600;
  display: block;
  margin-bottom: 0.55rem;
}

/* Editorial-honesty note appended at the bottom of every LIVE Cuaderno.
   Frames the editorial stance for articles that name companies critically;
   reads sensibly on articles that don't (uses "cuando" conditional). Visually
   quieter than the TLDR — no background, just a top rule line + smaller font,
   so it doesn't compete with body argumentation. Ramón calibration 2026-05-20. */
.cuadernos-body aside.cuadernos-honesty-note {
  background: transparent;
  border-top: 1px solid var(--rule);
  padding: 1.2rem 0 0;
  margin: 2.5rem 0 0;
  font-size: 0.85em;
  line-height: 1.6;
  color: var(--fg-soft);
}
.cuadernos-body aside.cuadernos-honesty-note strong {
  color: var(--fg);
  font-weight: 600;
}

.cuadernos-body hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 3rem 0;
}

.cuadernos-references {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}
.cuadernos-references h3 {
  font-family: var(--mono);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-faint);
  margin: 0 0 0.8rem;
}
.cuadernos-references ul {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--fg-soft);
  padding-left: 1.2rem;
  margin: 0;
  line-height: 1.7;
}

/* Descarga del artículo en Markdown. El usuario elige destino:
   disco duro, Solo2 (vía share/import), WhatsApp en móvil, etc.
   Idea Ramón 2026-05-16, refinando propuesta Gemini. */
.cuadernos-download {
  margin-top: 2.5rem;
  padding: 1.2rem 1.5rem;
  background: var(--rule-soft);
  border-radius: 4px;
}
.cuadernos-download p {
  margin: 0 0 0.5rem;
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--fg-soft);
}
.cuadernos-download a {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--accent);
  padding: 0.45rem 0.9rem;
  border-radius: 3px;
  display: inline-block;
  margin-top: 0.4rem;
  margin-right: 0.4rem;
  transition: background 0.15s;
}
.cuadernos-download a:hover {
  background: var(--accent);
  color: var(--bg);
}
.cuadernos-download .cuadernos-download-note {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--fg-faint);
  margin-top: 0.6rem;
  margin-bottom: 0;
  line-height: 1.5;
}

/* Sello de integridad SHA-256 — "lacre digital" al pie del artículo.
   Sugerencia Gemini 2026-05-16: en una publicación de autoridad los
   errores se corrigen con transparencia. Si el contenido cambia, el
   hash cambia. */
.cuadernos-seal {
  margin-top: 3rem;
  padding-top: 1.2rem;
  border-top: 1px dashed var(--rule);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--fg-faint);
  letter-spacing: 0.02em;
  line-height: 1.5;
}
.cuadernos-seal-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-soft);
  display: block;
  margin-bottom: 0.3rem;
}
.cuadernos-seal-hash {
  word-break: break-all;
  user-select: all;
}

/* ── Responsive ────────────────────────────────────────────────── */

@media (max-width: 640px) {
  body { font-size: 17px; }
  .cuadernos-header h1,
  .cuadernos-header .cuadernos-title { font-size: 1.9rem; }
  .cuadernos-article h1 { font-size: 1.7rem; }
  .cuadernos-article .cuadernos-subtitle { font-size: 1.05rem; }
  .cuadernos-body { font-size: 0.9rem; }
  .cuadernos-body aside.cuadernos-tldr { padding: 0.8rem 0.95rem; margin: 1.3rem 0; }
  .cuadernos-main { margin: 2rem auto; }
}

/* ── Prev / Next navigation (between articles) ─────────────────── */

.cuadernos-prevnext {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 2.5rem 0;
  padding: 0;
  font-size: 0.9rem;
}
.cuadernos-prevnext-bottom { margin: 2rem 0; }

/* Each side is a clearly-bordered card. The border-bottom override
   neutralizes the body-link underline that would otherwise cascade
   onto the bottom nav (which sits inside .cuadernos-body). */
.cuadernos-prevnext a,
.cuadernos-prevnext > span {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
  color: var(--fg);
  text-decoration: none;
  padding: 0.85rem 1.1rem;
  background-color: var(--bg-elev);
  border: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  border-radius: 4px;
  transition: border-color 0.15s, background-color 0.15s;
}
.cuadernos-prevnext a:hover {
  border-color: var(--accent);
  border-bottom-color: var(--accent);
  background-color: var(--bg);
}
.cuadernos-prevnext-prev { text-align: left; align-items: flex-start; }
.cuadernos-prevnext-next { text-align: right; align-items: flex-end; }

.cuadernos-prevnext-label {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--fg-soft);
  letter-spacing: 0.02em;
}
.cuadernos-prevnext-title {
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Empty side (when at first/last article): keep the slot to preserve
   left/right alignment of the active side, but render no visible frame. */
.cuadernos-prevnext-disabled {
  visibility: hidden;
  pointer-events: none;
  background-color: transparent !important;
  border-color: transparent !important;
}

/* ── Lecturas recientes (tail block) ───────────────────────────── */

.cuadernos-recent {
  margin: 3rem 0 1.5rem 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}
.cuadernos-recent h3 {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0 0 1.25rem 0;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-soft);
}
.cuadernos-recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.cuadernos-recent-list li { margin: 0; padding: 0; }
.cuadernos-recent-list a {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  color: var(--fg);
  text-decoration: none;
  padding: 0.4rem 0;
}
.cuadernos-recent-list a:hover { color: var(--accent); }

.cuadernos-recent-meta {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--fg-faint);
  letter-spacing: 0.02em;
}
.cuadernos-recent-title {
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.35;
}

/* ── Imprimible decente ────────────────────────────────────────── */

@media print {
  body { background: white; color: black; font-size: 11pt; }
  .cuadernos-back, .cuadernos-footer { display: none; }
  .cuadernos-prevnext, .cuadernos-recent { display: none; }
  .cuadernos-body a { color: black; border-bottom: none; }
  .cuadernos-body a::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #555; }
}
