:root {
  --bg: #fbf8f6;
  --fg: #1d1a1f;
  --muted: #6b6470;
  --card: #ffffff;
  --line: #ebe4e6;
  --accent: #d2445f;
  /* Code blocks are always dark, in light and dark mode: the VS Code Dark+ palette. */
  --code-bg: #1e1e1e;
  --code-fg: #d4d4d4;
  --code-line: #333333;
  --code-punct: #d4d4d4;
  --code-interp: #569cd6;
  --code-comment: #6a9955;
  --code-keyword: #569cd6;
  --code-control: #c586c0;
  --code-string: #ce9178;
  --code-number: #b5cea8;
  --code-function: #dcdcaa;
  --code-builtin: #dcdcaa;
  --code-symbol: #4fc1ff;
  --code-variable: #9cdcfe;
  --code-constant: #4ec9b0;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141216;
    --fg: #f1edf0;
    --muted: #a59fab;
    --card: #1e1b21;
    --line: #2e2a32;
    --accent: #f07a90;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.top, main, footer {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-top: 24px;
  padding-bottom: 24px;
}

.mark { font-weight: 700; font-size: 1.1rem; color: var(--fg); }
.mark span { color: var(--accent); }

nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
nav a { color: var(--muted); }

#lang {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
}

section { padding: 40px 0; }

.hero { padding: 64px 0 40px; }
.kicker { color: var(--muted); margin: 0 0 8px; font-size: 0.95rem; }
h1 { font-size: clamp(2.4rem, 7vw, 4rem); line-height: 1.05; margin: 0 0 20px; letter-spacing: -0.02em; }
.lead { font-size: 1.2rem; max-width: 40ch; margin: 0; }

h2 { font-size: 1.4rem; margin: 0 0 20px; }
h3 { margin: 0 0 4px; font-size: 1.1rem; }

.cards {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.cards li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}

.cards p { margin: 0 0 10px; }
.meta { color: var(--muted); font-size: 0.9rem; }

.links { display: flex; gap: 20px; flex-wrap: wrap; }

footer { color: var(--muted); font-size: 0.9rem; padding-top: 24px; padding-bottom: 48px; border-top: 1px solid var(--line); }

.note { max-width: 62ch; margin: 0 0 12px; }

.hub a { display: block; color: inherit; text-decoration: none; height: 100%; }
.hub li { padding: 0; transition: border-color 0.15s, transform 0.15s; }
.hub li:hover { border-color: var(--accent); transform: translateY(-2px); }
.hub a { padding: 20px; }
.hub .go { color: var(--accent); font-size: 0.95rem; }

html[lang="en"] .t[lang="es"],
html[lang="es"] .t[lang="en"] { display: none !important; }

.hero.small { padding: 48px 0 8px; }
.hero.small h1 { font-size: clamp(2rem, 5vw, 2.8rem); }

.prose { max-width: 68ch; }
.prose p { margin: 0 0 16px; }
.prose h1 { font-size: clamp(2rem, 5vw, 2.6rem); line-height: 1.15; }
.prose img { max-width: 100%; height: auto; border-radius: 10px; }

.posts { list-style: none; padding: 0; margin: 0; }
.posts li { display: flex; align-items: center; gap: 20px; padding: 16px 0; border-bottom: 1px solid var(--line); }
/* Thumbnails alternate sides: left on odd rows, right on even rows. */
.posts li:nth-child(even) { flex-direction: row-reverse; }
.posts .thumb { flex: 0 0 38%; max-width: 280px; }
.posts .thumb img,
.posts .thumb .no-picture {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--line);
}
.posts li > div { flex: 1; min-width: 0; }
.posts li > div > a { font-weight: 600; }
.posts .meta { display: block; margin-top: 6px; }
.posts li .summary { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

a.plain { color: inherit; }
.back { margin: 0 0 40px; }

@media (max-width: 560px) {
  .top { flex-direction: column; align-items: flex-start; gap: 10px; }
  nav { gap: 14px; }
}

.groups { list-style: none; padding: 0; margin: -8px 0 24px; display: flex; gap: 8px; flex-wrap: wrap; }
.groups li { font-size: 0.85rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.prose pre { overflow-x: auto; background: var(--code-bg); color: var(--code-fg); border: 1px solid var(--code-line); border-radius: 10px; padding: 14px; }
.prose code { font-size: 0.9em; }

/* Syntax highlighting: Rouge token classes, colored from the --code-* tokens. */
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs, .highlight .cp { color: var(--code-comment); }
.highlight .kd, .highlight .kp, .highlight .kr, .highlight .kt, .highlight .kc, .highlight .ow { color: var(--code-keyword); }
.highlight .k, .highlight .kn { color: var(--code-control); }
.highlight .no, .highlight .nc, .highlight .nn { color: var(--code-constant); }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb, .highlight .sh, .highlight .sx, .highlight .sr, .highlight .se, .highlight .sd { color: var(--code-string); }
.highlight .si { color: var(--code-interp); }
.highlight .ss { color: var(--code-symbol); }
.highlight .m, .highlight .mi, .highlight .mf, .highlight .mh, .highlight .mo, .highlight .mb { color: var(--code-number); }
.highlight .nf, .highlight .fm { color: var(--code-function); }
.highlight .nb, .highlight .bp { color: var(--code-builtin); }
.highlight .n, .highlight .nv, .highlight .vi, .highlight .vc, .highlight .vg { color: var(--code-variable); }
.highlight .o, .highlight .p { color: var(--code-punct); }
.highlight .nt { color: var(--code-keyword); }
.highlight .na { color: var(--code-variable); }
.prose table { display: block; overflow-x: auto; border-collapse: collapse; margin: 0 0 1.2em; font-size: 0.92rem; }
.prose th, .prose td { text-align: left; vertical-align: top; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.prose th { color: var(--muted); font-weight: 600; }

.hero.with-photo {
  display: flex;
  gap: 40px;
}
.hero.with-photo > div { flex: 1 1 auto; min-width: 0; }
.portrait {
  display: block;
  height: auto;
  border-radius: 18px;
  border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.18);
}

/* Landscape: name and lead on the left, photo on the right at most half the screen tall. */
@media (orientation: landscape) {
  .hero.with-photo { flex-direction: row; align-items: center; }
  .portrait { flex: 0 0 auto; width: auto; max-width: 50%; max-height: 50vh; }
}

/* Portrait: two rows, photo at most half the screen wide. */
@media (orientation: portrait) {
  .hero.with-photo { flex-direction: column; gap: 28px; }
  .portrait { align-self: center; width: 50vw; max-width: 50vw; }
}

.picture { margin: 0 0 28px; }
.picture img { display: block; width: 100%; height: auto; border-radius: 14px; border: 1px solid var(--line); }
.picture figcaption { color: var(--muted); font-size: 0.9rem; margin-top: 8px; }
.posts .summary { margin: 4px 0 0; color: var(--muted); font-size: 0.95rem; }

/* Home page story previews: 3 columns x 2 rows in landscape, 2 x 3 in portrait. */
.story-cards {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
@media (orientation: portrait) {
  .story-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}
.story-cards li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
}
.story-cards li:hover { border-color: var(--accent); transform: translateY(-2px); }
.story-cards a { display: flex; flex-direction: column; height: 100%; color: inherit; text-decoration: none; }
/* The grid columns fix every cell's width; the picture fills it, cropped to 3:2 by CSS. */
.story-cards img,
.story-cards .no-picture {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  background: var(--line);
}
.story-cards h3 { margin: 12px 14px 4px; }
.story-cards p {
  margin: 0 14px 14px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Album pages: every photo cropped to 3:2 in a grid; a click opens the full picture. */
.photo-grid { list-style: none; padding: 0; margin: 0 0 48px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 560px) { .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } }
.photo-grid img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: var(--line); }

/* Picture viewer (assets/js/viewer.js): album photos and story pictures open full screen. */
.photo-grid img, article.prose img { cursor: zoom-in; }
html.viewer-open { overflow: hidden; }
.viewer {
  position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: #0b0a0c; color: #f1edf0;
  display: grid; grid-template-rows: auto 1fr auto; overflow: hidden;
}
.viewer:not([open]) { display: none; }
.viewer::backdrop { background: #0b0a0c; }
.viewer button, .viewer .v-original {
  display: inline-grid; place-items: center; min-width: 44px; height: 44px; padding: 0 10px;
  border: 0; border-radius: 999px; background: rgba(255, 255, 255, 0.08); color: inherit;
  font: 22px/1 system-ui, sans-serif; cursor: pointer; text-decoration: none;
}
.viewer button:hover, .viewer .v-original:hover { background: rgba(255, 255, 255, 0.18); text-decoration: none; }
.viewer button:disabled { opacity: 0.35; cursor: default; }
.viewer button[aria-pressed="true"] { background: #f1edf0; color: #0b0a0c; }
/* The tools button shows a dot of color while any tool is changed. */
.viewer .v-adjust { position: relative; }
.viewer .v-adjust.changed::after {
  content: ""; position: absolute; top: 6px; right: 6px; width: 10px; height: 10px; border-radius: 50%;
  background: conic-gradient(#ffd54a, #ff5c8a, #9ec5ff, #7cf0c8, #ffd54a); box-shadow: 0 0 0 2px #0b0a0c;
}
.viewer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; z-index: 2; }
.viewer-count { font-size: 0.9rem; color: #a59fab; padding-left: 4px; }
.viewer-tools { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.viewer-stage { position: relative; overflow: hidden; touch-action: none; cursor: grab; min-height: 0; }
.viewer-stage.zoomed { cursor: move; }
.viewer-stage img {
  position: absolute; inset: 0; margin: auto; max-width: 100%; max-height: 100%; user-select: none; -webkit-user-select: none;
  transform-origin: center; transition: opacity 0.2s; cursor: inherit;
}
.viewer-stage img.loading { opacity: 0.4; }
.viewer-caption { margin: 0; padding: 8px 16px 14px; text-align: center; font-size: 0.9rem; color: #a59fab; min-height: 1.6em; }
.viewer .v-prev, .viewer .v-next { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; font-size: 32px; }
.viewer .v-prev { left: 10px; }
.viewer .v-next { right: 10px; }
.viewer-panel {
  position: absolute; right: 12px; top: 64px; bottom: 12px; z-index: 3; width: min(320px, calc(100% - 24px));
  display: grid; align-content: start; gap: 14px; padding: 14px 16px; border-radius: 14px; overflow: auto;
  background: rgba(24, 22, 27, 0.95); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.viewer-panel[hidden] { display: none; }
.viewer-sliders { display: grid; gap: 12px; }

/* Each slider brings its own colors (set by viewer.js): --v-track draws what the
   effect does from end to end, --v-color marks the value once it leaves neutral. */
.v-slider { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 8px; font-size: 0.85rem; color: #b8b1bc; }
.v-slider .v-name { display: flex; align-items: center; gap: 8px; }
.v-slider output { font-variant-numeric: tabular-nums; color: #7d7682; }
.v-slider.active .v-name { color: #f1edf0; }
.v-slider.active output { color: var(--v-color); font-weight: 600; }
.v-slider.active .v-name::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--v-color);
  box-shadow: 0 0 8px var(--v-color);
}
.v-slider input[type="range"] {
  grid-column: 1 / -1; width: 100%; height: 22px; margin: 0; background: transparent;
  -webkit-appearance: none; appearance: none; cursor: pointer;
}
.v-slider input[type="range"]::-webkit-slider-runnable-track { height: 8px; border-radius: 999px; background: var(--v-track); }
.v-slider input[type="range"]::-moz-range-track { height: 8px; border-radius: 999px; background: var(--v-track); }
.v-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; margin-top: -5px; border-radius: 50%;
  background: #f1edf0; border: 3px solid #0b0a0c; box-shadow: 0 0 0 1px #7d7682;
}
.v-slider input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%; background: #f1edf0; border: 3px solid #0b0a0c; box-shadow: 0 0 0 1px #7d7682;
}
.v-slider.active input[type="range"]::-webkit-slider-thumb { background: var(--v-color); box-shadow: 0 0 0 2px var(--v-color), 0 0 10px var(--v-color); }
.v-slider.active input[type="range"]::-moz-range-thumb { background: var(--v-color); box-shadow: 0 0 0 2px var(--v-color), 0 0 10px var(--v-color); }
.v-slider input[type="color"] { width: 26px; height: 20px; padding: 0; border: 1px solid #555; border-radius: 6px; background: none; cursor: pointer; }

.viewer-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.viewer-actions button { font-size: 20px; }
.viewer-actions button.active, .viewer-actions button[aria-pressed="true"] {
  background: rgba(124, 240, 200, 0.18); color: #7cf0c8; box-shadow: inset 0 0 0 2px #7cf0c8;
}
.viewer-actions .v-rotate-right[data-turn]:not([data-turn=""])::after { content: attr(data-turn); font-size: 0.7rem; margin-left: 4px; }
.viewer-actions .v-rotate-right { grid-auto-flow: column; }
.viewer .viewer-actions .v-reset { font-size: 0.9rem; margin-left: auto; }
.viewer-defs { position: absolute; width: 0; height: 0; }
@media (max-width: 560px) {
  .viewer-panel {
    top: auto; bottom: 64px; left: 12px; right: 12px; width: auto; max-height: calc(100% - 140px);
  }
  .viewer-sliders { grid-template-columns: 1fr 1fr; gap: 10px 14px; }
  .viewer-caption { padding: 10px 64px 0; margin-bottom: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .viewer .v-prev, .viewer .v-next { top: auto; bottom: 8px; transform: none; }
}
