/* --- Tokens --- */

:root {
  /* Color */
  --primary-color: #0077cc;
  --primary-dark: #0055a0;
  --primary-light: #e6f2ff;
  --text-color: #1a1a1a;
  --text-muted: #666;
  --background-color: #fff;
  --surface-color: #fafafa;
  --border-color: #e0e0e0;
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);

  /* Font stacks — platform-native */
  --font-sans:
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-serif:
    ui-serif, "New York", "Iowan Old Style", Charter, Georgia, Cambria, serif;
  --font-mono:
    ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;

  /* Fluid type — small viewport → large viewport */
  --fs-base: clamp(1.0625rem, 1rem + 0.25vw, 1.1875rem); /* 17 → 19 */
  --fs-h1: clamp(2rem, 1.55rem + 2vw, 2.75rem); /* 32 → 44 */
  --fs-h2: clamp(1.5rem, 1.3rem + 1vw, 2rem); /* 24 → 32 */
  --fs-h3: clamp(1.25rem, 1.15rem + 0.5vw, 1.5rem); /* 20 → 24 */
  --fs-h4: clamp(1.125rem, 1.075rem + 0.25vw, 1.25rem); /* 18 → 20 */
  --fs-small: 0.9rem;

  /* Measure — comfortable line length for prose */
  --measure-prose: 38rem; /* ~65–70ch in system fonts */
  --measure-shell: 38rem; /* unified column: nav, content, footer */
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary-color: #4ea8e6;
    --primary-dark: #82c2ec;
    --primary-light: #1a3a5c;
    --text-color: #e8e8e8;
    --text-muted: #a8a8a8;
    --background-color: #1a1a1a;
    --surface-color: #2d2d2d;
    --border-color: #444;
  }
}

/* --- Reset & base --- */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-serif);
  font-size: var(--fs-base);
  line-height: 1.55;
  color: var(--text-color);
  background: var(--background-color);
  max-width: var(--measure-shell);
  margin: 0 auto;
  padding: 1.5rem;
  transition:
    background-color 0.2s,
    color 0.2s;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@media (max-width: 640px) {
  body {
    padding: 1rem;
  }
}

/* --- Skip link (keyboard a11y) --- */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--primary-color);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 4px;
  font-weight: 600;
  text-decoration: none;
  z-index: 100;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
}

/* --- Typography --- */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-serif);
  line-height: 1.2;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 1rem;
  color: var(--text-color);
  text-wrap: balance;
}

h1 {
  font-size: var(--fs-h1);
  margin-top: 0;
  margin-bottom: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h2 {
  font-size: var(--fs-h2);
  margin-top: 2rem;
  margin-bottom: 1rem;
}

h3 {
  font-size: var(--fs-h3);
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}

h4 {
  font-size: var(--fs-h4);
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

p {
  margin-bottom: 1.25rem;
  text-wrap: pretty;
}

/* --- Links --- */

a {
  color: var(--primary-color);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
  transition: color 0.2s;
}

a:hover {
  color: var(--primary-dark);
}

/* --- Header & nav --- */

header {
  margin-bottom: 2.5rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-color);
}

.primary-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
}

.nav-brand {
  flex-shrink: 0;
}

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  text-decoration: none;
  transition: transform 0.2s;
}

.logo img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  margin: 0;
}

.logo:hover {
  transform: scale(1.05);
}

.nav-links {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
}

.nav-link {
  color: var(--text-color);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--fs-small);
  position: relative;
  padding: 0.75rem 0.5rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  transition: color 0.2s;
}

.nav-link::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--primary-color);
  transition: width 0.3s ease;
}

.nav-link:hover::after,
.nav-link.active::after {
  width: 100%;
}

.nav-link:hover,
.nav-link.active {
  color: var(--primary-color);
}

@media (max-width: 480px) {
  .primary-nav {
    gap: 0.75rem;
    flex-wrap: wrap;
  }

  .nav-links {
    gap: 0.75rem;
  }

  .logo {
    width: 36px;
    height: 36px;
  }
}

/* --- Main (prose-width container) --- */

main {
  max-width: var(--measure-prose);
  margin: 0 auto;
  padding: 0.5rem 0;
  min-height: calc(100vh - 320px);
}

/* --- Code & blockquotes --- */

code {
  background: var(--surface-color);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

pre {
  background: var(--surface-color);
  padding: 1.25rem;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 1.5rem;
  border-left: 4px solid var(--primary-color);
  font-size: 0.9rem;
}

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

blockquote {
  border-left: 4px solid var(--primary-color);
  padding-left: 1.25rem;
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-style: italic;
}

/* --- Lists & images --- */

ul,
ol {
  margin-left: 1.5rem;
  margin-bottom: 1.25rem;
}

li {
  margin-bottom: 0.4rem;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem 0;
  border-radius: 8px;
}

hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 2rem 0;
}

/* --- Tables --- */

.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
}

.content th,
.content td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}

.content th {
  background: var(--surface-color);
  font-weight: 600;
}

.content tbody tr:hover {
  background: var(--surface-color);
}

@media (max-width: 640px) {
  .content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* --- Articles (single post — plain, no card) --- */

article {
  margin-bottom: 2rem;
}

article > header {
  border: none;
  margin-bottom: 1.5rem;
  padding-bottom: 0;
}

article > header time {
  display: block;
  color: var(--text-muted);
  font-size: var(--fs-small);
  margin-top: 0.5rem;
}

/* --- Posts list (cards) --- */

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

.posts li {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border-color);
}

.posts .date {
  flex: 0 0 9rem;
  color: var(--text-muted);
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
}

.posts .title {
  flex: 1;
  min-width: 0;
  color: var(--text-color);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.posts .title:hover,
.posts .title:focus {
  color: var(--primary-color);
}

@media (max-width: 480px) {
  .posts li {
    flex-direction: column;
    gap: 0.25rem;
  }

  .posts .date {
    flex: 0 0 auto;
  }
}

.pagination {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  margin: 2.5rem 0 0;
  padding: 0;
  font-size: var(--fs-small);
}

.pagination li.current {
  padding: 0.5rem 0.75rem;
  font-weight: 700;
  color: var(--text-color);
}

.pagination a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  background: var(--primary-light);
  color: var(--primary-color);
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
  transition:
    background 0.2s,
    color 0.2s;
}

.pagination a:hover,
.pagination a:focus {
  background: var(--primary-color);
  color: white;
}

/* --- Homepage --- */

.homepage-content {
  margin-bottom: 2.5rem;
}

.homepage-content p:last-child {
  margin-bottom: 0;
}

/* --- Utilities --- */

.latin-motto {
  font-family: var(--font-serif);
  font-style: italic;
  text-align: center;
  color: var(--text-muted);
  margin: 2rem 0;
}

.latin-motto p {
  letter-spacing: 0.05em;
  text-indent: 0.05em;
  margin-bottom: 0;
}

/* --- Footer --- */

footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  padding-bottom: 1rem;
  border-top: 1px solid var(--border-color);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--fs-small);
}

footer p {
  margin-bottom: 0.5rem;
}

/* --- Focus styles (keyboard) --- */

:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
  border-radius: 3px;
}

/* --- Reduced motion --- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- Print --- */

@media print {
  body {
    max-width: 100%;
    padding: 0;
    font-size: 11pt;
  }

  header,
  footer,
  nav {
    display: none;
  }

  a {
    color: inherit;
  }

  a[href]::after {
    content: " (" attr(href) ")";
  }

  article {
    background: none;
    padding: 0;
    box-shadow: none;
  }
}
