/* ==========================================================================
   Alex Boncza's Articles — editorial stylesheet
   Structure: 1. tokens → 2. base → 3. layout → 4. header → 5. home
              → 6. article → 7. prose → 8. about → 9. footer → 10. utilities
   Tune the whole publication from the token blocks.
   ========================================================================== */

/* 1. Design tokens
   -------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  --bg: #f7f6f2;
  /* warm off-white */
  --text: #20201e;
  /* charcoal */
  --muted: #6e6c66;
  /* warm gray — ≥4.5:1 on --bg at small sizes */
  --border: #dad8d1;
  /* hairlines */
  --border-strong: #b9b6ac;
  /* rules needing a little more presence */
  --accent: #a34a2a;
  /* muted rust — 5.4:1 on --bg */
  --code-bg: #efede6;

  --font-serif:
    Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia,
    "Times New Roman", serif;
  --font-sans:
    "Google Sans", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  --font-mono:
    "Google Sans Code", ui-monospace, "SF Mono", "Cascadia Mono", Menlo,
    Consolas, "Liberation Mono", monospace;

  --container: 42rem;
  /* one disciplined editorial column */
  --measure: 68ch;
  /* 65–75 characters per line in prose */
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #191a18;
  /* deep warm charcoal */
  --text: #eae8e1;
  /* soft warm off-white */
  --muted: #a5a39b;
  /* muted warm gray — ~7:1 on --bg */
  --border: #3a3b36;
  --border-strong: #55564f;
  --accent: #c97e58;
  /* desaturated rust — 5.5:1 on --bg */
  --code-bg: #212220;
}

/* No-JS fallback: follow the system preference until told otherwise. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    color-scheme: dark;
    --bg: #191a18;
    --text: #eae8e1;
    --muted: #a5a39b;
    --border: #3a3b36;
    --border-strong: #55564f;
    --accent: #c97e58;
    --code-bg: #212220;
  }
}

/* 2. Base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: clamp(1.03rem, 0.98rem + 0.35vw, 1.125rem);
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  transition:
    background-color 0.18s ease,
    color 0.18s ease;
}

h1,
h2,
h3,
h4,
p,
ul,
ol,
figure,
blockquote,
pre {
  margin: 0;
}

img {
  max-width: 100%;
  height: auto;
}

a {
  color: inherit;
  transition:
    color 0.18s ease,
    border-color 0.18s ease,
    background-color 0.18s ease;
}

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

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

/* 3. Layout primitives
   -------------------------------------------------------------------------- */
.container {
  width: min(100% - 2.5rem, var(--container));
  margin-inline: auto;
}

.site-main {
  flex: 1;
  padding-block: clamp(2.25rem, 6vh, 3.5rem) 4.5rem;
}

.square,
.endmark {
  width: 0.5rem;
  height: 0.5rem;
  background: var(--accent);
  flex: none;
}

.section-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.meta {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
  letter-spacing: 0.01em;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.crumb {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
}

.crumb:hover {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* 4. Header, navigation, theme toggle
   -------------------------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  min-height: 4rem;
  padding-block: 0.75rem;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-sans);
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}

.wordmark::before {
  content: "";
  width: 0.58rem;
  height: 0.58rem;
  background: var(--accent);
  flex: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.35rem;
}

.site-nav a {
  font-family: var(--font-sans);
  font-size: 0.92rem;
  color: var(--muted);
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--text);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.theme-toggle svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Light theme shows the moon (the target); dark theme shows the sun. */
.icon-sun {
  display: none;
}

.icon-moon {
  display: block;
}

[data-theme="dark"] .icon-sun {
  display: block;
}

[data-theme="dark"] .icon-moon {
  display: none;
}

/* 5. Homepage
   -------------------------------------------------------------------------- */
.intro {
  margin: clamp(1rem, 3vh, 1.5rem) 0 clamp(2.75rem, 8vh, 4rem);
}

.intro-text {
  font-size: clamp(1.15rem, 1.05rem + 0.45vw, 1.3rem);
  font-weight: 400;
  line-height: 1.5;
  max-width: 36ch;
  text-wrap: balance;
}

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-list > li {
  padding: 1.7rem 0 1.9rem;
}

.post-list > li + li {
  border-top: 1px solid var(--border);
}

.entry-title {
  font-size: clamp(1.22rem, 1.15rem + 0.3vw, 1.35rem);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.entry-lead .entry-title {
  font-size: clamp(1.5rem, 1.35rem + 0.7vw, 1.85rem);
  line-height: 1.22;
}

.entry-title a {
  text-decoration: none;
}

.entry-title a:hover {
  color: var(--accent);
}

.entry .meta {
  margin-top: 0.5rem;
}

.excerpt {
  margin-top: 0.55rem;
  max-width: 58ch;
  font-size: 0.95em;
  line-height: 1.65;
  color: var(--muted);
}

/* 6. Article page
   -------------------------------------------------------------------------- */
.article-title,
.page-title {
  margin-top: 1.5rem;
  font-size: clamp(1.95rem, 1.55rem + 1.9vw, 2.6rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.page-title {
  font-size: clamp(1.7rem, 1.4rem + 1.4vw, 2.2rem);
}

.article-header {
  margin-top: 1.1rem;
  padding-bottom: 2.4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.6rem;
}

.article-header .meta {
  margin-top: 0;
}

.article-end {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* 7. Prose (long-form typography)
   -------------------------------------------------------------------------- */
.prose {
  max-width: var(--measure);
  overflow-wrap: break-word;
}

.prose p {
  margin-bottom: 1.3em;
}

.prose h2 {
  margin: 2.4em 0 0.9em;
  font-size: 1.42em;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.prose h3 {
  margin: 2em 0 0.7em;
  font-size: 1.13em;
  font-weight: 600;
}

.prose ul,
.prose ol {
  margin-bottom: 1.3em;
  padding-left: 1.5em;
}

.prose li {
  margin: 0.3em 0;
}

.prose li::marker {
  color: var(--muted);
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

.prose a:hover {
  text-decoration-thickness: 2px;
}

.prose blockquote {
  margin-bottom: 1.3em;
  padding: 0.15em 0 0.15em 1.4em;
  border-left: 1px solid var(--border-strong);
  color: var(--muted);
  font-style: italic;
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: var(--code-bg);
  border-radius: 2px;
  padding: 0.15em 0.4em;
  overflow-wrap: break-word;
}

.prose pre {
  margin-bottom: 1.5em;
  padding: 1rem 1.15rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow-x: auto;
  font-size: 0.845em;
  line-height: 1.65;
}

.prose pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: 1em;
}

.prose img {
  display: block;
  margin: 0 auto 1.3em;
}

.prose figure {
  margin-bottom: 1.5em;
}

.prose figcaption {
  margin-top: 0.6em;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

/* Tables scroll independently on narrow screens. */
.prose table {
  display: block;
  width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin-bottom: 1.6em;
  font-size: 0.93em;
}

.prose th {
  padding: 0 0.9em 0.55em 0;
  border-bottom: 1px solid var(--border-strong);
  text-align: left;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.prose td {
  padding: 0.6em 0.9em 0.6em 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.prose hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.5em 0;
}

.prose .section-label {
  margin-top: 3rem;
}

.prose .lede {
  font-size: 1.12em;
  line-height: 1.6;
}

/* 8. Footer
   -------------------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--border);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding-block: 1.5rem;
}

.footer-line {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* 9. Utilities
   -------------------------------------------------------------------------- */
.skip-link {
  position: absolute;
  top: 0.8rem;
  left: 0.8rem;
  z-index: 20;
  padding: 0.45rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  transform: translateY(-300%);
}

.skip-link:focus {
  transform: none;
}

/* 10. Motion preferences
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}

/* Added helpers */
.article-header .meta {
  margin-top: 2ex;
}
/* Firefox specific tweaks */
@-moz-document url-prefix() {
  .article-header .meta {
    margin-top: 1ex;
  }
}
