:root {
  --bg: #fbf8f6;
  --fg: #1d1a1f;
  --muted: #6b6470;
  --card: #ffffff;
  --line: #ebe4e6;
  --accent: #d2445f;
  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; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }

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(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.prose code { font-size: 0.9em; }
.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;
}
