/* ══════════════════════════════════════════════════
   Good Reader  -  Nebbia Theme (dark / sepia / light)
   Grey fog, graphite ink and a single warm light
   that never quite wins against the grey.
   Copyright (c) 2026 Stefano Marinelli
   ══════════════════════════════════════════════════ */

:root {
  --bg: #d8d5ce;
  --bg-card: #e1ded7;
  --bg-elevated: #ccc8bf;
  --text: #1f1d1a;
  --text-muted: #3f3b35;
  --text-dim: #4f4a43;
  --border: #bfbab0;
  --accent: #6f4513;
  --accent-hover: #5a370d;
  --accent-glow: rgba(214, 150, 60, 0.16);
  --overlay: rgba(0, 0, 0, 0.08);
  --shadow: none;
  --radius: 2px;
  --radius-sm: 2px;

  --halo: rgba(240, 180, 90, 0.38);
  --window: rgba(240, 180, 90, 0.3);
  --fog: rgba(216, 213, 206, 0.95);
  --header-bg: rgba(216, 213, 206, 0.9);
  --img-tone: contrast(0.9);

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-serif: Charter, 'Bitstream Charter', 'Iowan Old Style', 'Sitka Text', Cambria, Georgia, serif;
  --font-display: Charter, 'Bitstream Charter', 'Iowan Old Style', 'Sitka Text', Cambria, Georgia, serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, 'DejaVu Sans Mono', Consolas, monospace;

  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* sepia: the yellow bulb in a grey room */
[data-theme="sepia"] {
  --bg: #d8d5ce;
  --bg-card: #e1ded7;
  --bg-elevated: #ccc8bf;
  --text: #1f1d1a;
  --text-muted: #3f3b35;
  --text-dim: #4f4a43;
  --border: #bfbab0;
  --accent: #6f4513;
  --accent-hover: #5a370d;
  --accent-glow: rgba(214, 150, 60, 0.16);
  --halo: rgba(240, 180, 90, 0.38);
  --window: rgba(240, 180, 90, 0.3);
  --fog: rgba(216, 213, 206, 0.95);
  --header-bg: rgba(216, 213, 206, 0.9);
  --img-tone: contrast(0.9);
}

/* light: a foggy morning */
[data-theme="light"] {
  --bg: #e3e5e6;
  --bg-card: #eceeef;
  --bg-elevated: #d6d9db;
  --text: #1f2326;
  --text-muted: #40464b;
  --text-dim: #51585e;
  --border: #c7cbce;
  --accent: #74501a;
  --accent-hover: #5e400f;
  --accent-glow: rgba(190, 140, 60, 0.12);
  --overlay: rgba(0, 0, 0, 0.06);
  --halo: rgba(255, 255, 255, 0.9);
  --window: rgba(235, 190, 115, 0.22);
  --fog: rgba(227, 229, 230, 0.95);
  --header-bg: rgba(227, 229, 230, 0.9);
  --img-tone: contrast(0.85) brightness(1.05);
}

/* dark: 22:53, lit windows in the fog */
[data-theme="dark"] {
  --bg: #0f1316;
  --bg-card: #151a1e;
  --bg-elevated: #1d2328;
  --text: #d6d6d1;
  --text-muted: #a2a6a9;
  --text-dim: #8b9095;
  --border: #262d33;
  --accent: #e8ad5c;
  --accent-hover: #f3c684;
  --accent-glow: rgba(232, 173, 92, 0.12);
  --overlay: rgba(0, 0, 0, 0.5);
  --halo: rgba(232, 173, 92, 0.14);
  --window: rgba(232, 173, 92, 0.2);
  --fog: rgba(15, 19, 22, 0.95);
  --header-bg: rgba(15, 19, 22, 0.88);
  --img-tone: brightness(0.75);
}

/* Without JS there is no data-theme: follow the system */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0f1316;
    --bg-card: #151a1e;
    --bg-elevated: #1d2328;
    --text: #d6d6d1;
    --text-muted: #a2a6a9;
    --text-dim: #8b9095;
    --border: #262d33;
    --accent: #e8ad5c;
    --accent-hover: #f3c684;
    --accent-glow: rgba(232, 173, 92, 0.12);
    --overlay: rgba(0, 0, 0, 0.5);
    --halo: rgba(232, 173, 92, 0.14);
    --window: rgba(232, 173, 92, 0.2);
    --fog: rgba(15, 19, 22, 0.95);
    --header-bg: rgba(15, 19, 22, 0.88);
    --img-tone: brightness(0.75);
  }
}

html {
  background: var(--bg);
}

body {
  background: transparent;
}

/* The lamp, on its own fixed layer so scrolling doesn't repaint it */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(60% 520px at 50% 0, var(--halo), transparent) no-repeat;
  pointer-events: none;
}

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

/* The fog bank at the bottom of the lists. Posts come out of it while scrolling. */
body:has(.post-grid):not(:has(.article))::after {
  content: '';
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12vh;
  background: linear-gradient(to top, var(--fog), transparent);
  pointer-events: none;
  z-index: 50;
}

body:has(.post-grid):not(:has(.article)) .footer {
  padding-bottom: 14vh;
}

@media (prefers-contrast: more) {
  body:has(.post-grid):not(:has(.article))::after {
    content: none;
  }
}

/* ── Header ──────────────────────────────────── */
/* The lamp stays at the top of the window and the bar carries
   the same light, so there is no edge between the two */
.header {
  position: relative;
  background: transparent;
  border-bottom: none;
}

.header::before {
  content: '';
  position: absolute;
  inset: 0 0 -32px;
  z-index: -1;
  background: radial-gradient(60% 520px at 50% 0, var(--halo), transparent) no-repeat var(--header-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  -webkit-mask-image: linear-gradient(#000 55%, transparent);
  mask-image: linear-gradient(#000 55%, transparent);
  pointer-events: none;
}

.logo {
  font-size: 1.7rem;
  font-weight: 400;
  font-style: italic;
  letter-spacing: 0;
}

.motto {
  font-family: var(--font-serif);
  font-style: italic;
}

.nav-link:hover {
  background: transparent;
}

.icon-btn {
  background: transparent;
}

/* ── Search ──────────────────────────────────── */
.list-toolbar {
  max-width: 880px;
  margin: 0 auto;
  padding-top: 48px;
}

.search-input {
  max-width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.05rem;
}

/* ── Cards: windows in the fog ───────────────── */
.post-grid {
  grid-template-columns: 1fr;
  max-width: 880px;
  margin: 0 auto;
  gap: 32px;
}

.post-card {
  --fade: min(1, calc(0.45 + var(--age, 0) * 0.02));
  flex-direction: row;
  background: transparent;
  border: 1px solid transparent;
  transition: background-color 0.5s ease, border-color 0.5s ease, box-shadow 0.5s ease;
}

.post-card:hover,
.post-card:focus-within {
  transform: none;
  background: var(--bg-card);
  border-color: var(--border);
  box-shadow: inset 0 0 90px var(--window), 0 0 30px var(--accent-glow);
}

.post-card-image {
  width: auto;
  height: auto;
  align-self: flex-start;
  flex-shrink: 0;
  background: transparent;
}

.post-card-image:empty {
  display: none;
}

.post-card-image::after {
  content: none;
}

/* Older posts sink deeper into the fog.
   aspect-ratio: auto ignores the width/height attributes, so a blocked image takes no room */
.post-card-image img {
  width: 300px;
  height: auto;
  max-height: 220px;
  aspect-ratio: auto;
  filter: grayscale(var(--fade)) var(--img-tone);
  opacity: max(0.5, calc(1 - var(--age, 0) * 0.008));
  -webkit-mask-image: linear-gradient(to right, #000 55%, transparent);
  mask-image: linear-gradient(to right, #000 55%, transparent);
  transition: filter 0.9s ease, opacity 0.9s ease;
}

.post-card:hover .post-card-image img {
  transform: none;
}

.post-card:hover .post-card-image img,
.post-card:focus-within .post-card-image img {
  filter: none;
  opacity: 1;
}

@media (hover: none) {
  .post-card-image img {
    filter: grayscale(calc(var(--fade) - 0.45));
  }
}

/* The newest post: the window that is still lit */
#postGrid > .post-card:first-child {
  flex-direction: column;
  background: var(--bg-card);
  border-color: var(--border);
  box-shadow: inset 0 0 120px var(--window), 0 0 40px var(--accent-glow);
  margin-bottom: 16px;
}

#postGrid > .post-card:first-child .post-card-image,
#postGrid > .post-card:first-child .post-card-image img {
  width: 100%;
}

#postGrid > .post-card:first-child .post-card-image img {
  max-height: 400px;
  filter: none;
  opacity: 1;
  -webkit-mask-image: linear-gradient(to bottom, #000 60%, transparent);
  mask-image: linear-gradient(to bottom, #000 60%, transparent);
}

#postGrid > .post-card:first-child .post-card-body {
  padding: 0 32px 28px;
}

#postGrid > .post-card:first-child .post-card-title {
  font-size: 2.1rem;
}

#postGrid > .post-card:first-child .post-card-description {
  font-size: 1.05rem;
}

.post-card-body {
  padding: 16px 28px 16px 12px;
  justify-content: center;
}

.post-card-title {
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: 0;
}

.post-card-description {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  flex: 0 1 auto;
}

.post-card-date,
.article-date,
.article-reading-time {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.post-card-date {
  order: -2;
  margin-bottom: 6px;
}

.tag {
  border: none;
  border-radius: 0;
  padding: 0;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.tag::before {
  content: '#';
  color: var(--accent);
}

.post-card-tags,
.article-tags {
  gap: 4px 12px;
}

.post-card-tags {
  order: 1;
  margin: 12px 0 0;
}

.related-posts .post-card-image img {
  width: 200px;
}

/* ── Article ──────────────────────────────────── */
.post-nav {
  margin-top: 16px;
}

.article-hero {
  height: auto;
  min-height: 64px;
  background: transparent;
  border-radius: 0;
  margin-bottom: 24px;
}

.article-hero::after {
  content: none;
}

.article-hero img {
  height: auto;
  max-height: 460px;
  aspect-ratio: auto;
  -webkit-mask-image: radial-gradient(ellipse 75% 70% at 50% 45%, #000 45%, transparent 100%);
  mask-image: radial-gradient(ellipse 75% 70% at 50% 45%, #000 45%, transparent 100%);
}

.article-header {
  text-align: center;
  margin-bottom: 56px;
}

.article-header .article-date {
  display: block;
  margin-bottom: 14px;
}

.article-meta,
.article-tags {
  justify-content: center;
}

.article-title,
.list-title,
.related-posts-title,
.archive-year-title {
  font-weight: 400;
  letter-spacing: -0.01em;
}

.article-title {
  font-size: 2.9rem;
  margin-bottom: 20px;
}

.article-body {
  font-size: 1.1rem;
  line-height: 1.85;
}

.article-body p {
  margin-bottom: 1.4em;
}

.article-body a {
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.article-body h1,
.article-body h2,
.article-body h3 {
  font-weight: 400;
}

.article-body blockquote {
  background: none;
  border-left: 2px solid var(--accent);
  border-radius: 0;
  padding: 0.2em 0 0.2em 1.2em;
}

.article-body hr {
  border: none;
  margin: 2.5em 0;
  text-align: center;
  color: var(--accent);
  overflow: visible;
}

.article-body hr::before {
  content: '· · ·';
  font-size: 1.6rem;
  line-height: 1;
  letter-spacing: 0.6em;
}

.article-body code {
  background: var(--bg-elevated);
}

/* The screen is always dark: the safe harbour */
.article-body pre {
  background: #0d1012;
  border: 1px solid #262b30;
  border-radius: var(--radius-sm);
  color: #e8b66b;
  line-height: 1.2;
}

.article-body pre code {
  color: inherit;
}

.article-body img {
  border-radius: var(--radius-sm);
}

/* ── Archives: the drawer ─────────────────────── */
.list-header:has(+ .archives) {
  max-width: 720px;
  margin: 0 auto;
  padding-left: 24px;
  padding-right: 24px;
}

.archive-month-title,
.archive-list {
  font-family: var(--font-serif);
}

.archive-month-title {
  font-weight: 400;
  font-style: italic;
  color: var(--text-muted);
}

.list-subtitle {
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--text-muted);
  margin-top: -12px;
}

.archive-year {
  margin-bottom: 8px;
}

.archive-year[open] {
  margin-bottom: 40px;
}

.archive-year-title {
  list-style: none;
  cursor: pointer;
  border-bottom-width: 1px;
  margin-bottom: 16px;
}

.archive-year-title::-webkit-details-marker {
  display: none;
}

.archive-year-title::before {
  content: '+';
  display: inline-block;
  width: 1em;
  font-family: var(--font-mono);
  font-size: 0.7em;
  color: var(--text-dim);
}

.archive-year[open] > .archive-year-title::before {
  content: '−';
}

.archive-year:not([open]) > .archive-year-title {
  color: var(--text-dim);
}

.archive-date {
  font-variant-numeric: tabular-nums;
}

/* ── 404 ─────────────────────────────────────── */
.error-code {
  font-weight: 400;
}

.error-message {
  font-family: var(--font-serif);
  font-style: italic;
}

.error-message a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* ── Footer ──────────────────────────────────── */
.footer {
  border-top: none;
  font-family: var(--font-serif);
  font-style: italic;
}

.footer-human {
  margin: 10px 0 6px;
  color: var(--text-muted);
}

/* ── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
  .post-card {
    flex-direction: column;
  }

  .post-card-image,
  .post-card-image img,
  .related-posts .post-card-image img {
    width: 100%;
  }

  .post-card-image img,
  #postGrid > .post-card:first-child .post-card-image img {
    max-height: 200px;
    -webkit-mask-image: linear-gradient(to bottom, #000 55%, transparent);
    mask-image: linear-gradient(to bottom, #000 55%, transparent);
  }

  .post-card-body {
    padding: 4px 16px 16px;
  }

  #postGrid > .post-card:first-child .post-card-body {
    padding: 0 16px 20px;
  }

  #postGrid > .post-card:first-child .post-card-title {
    font-size: 1.6rem;
  }

  .article-title {
    font-size: 2rem;
  }

  body:has(.post-grid):not(:has(.article))::after {
    height: 8vh;
  }
}

@media print {
  body::before,
  body::after {
    display: none;
  }
}
