/* Main Styles - Default Theme */
/* Note: variables.css is loaded via <link> in base.html - no @import needed */

@layer reset {
/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

/* Prevent font scaling in landscape on mobile */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

}

@layer base {

/* ==========================================================================
   Skip Link (Accessibility)
   ========================================================================== */

.skip-link {
  position: absolute;
  top: var(--space-4, 1rem);
  left: var(--space-4, 1rem);
  display: inline-block;
  padding: var(--space-2, 0.5rem) var(--space-4, 1rem);
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius, 0.375rem);
  text-decoration: none;
  z-index: 9999;
  transform: translateY(-200%);
  transition: transform 0.15s ease;
}

.skip-link:focus,
.skip-link:focus-visible {
  transform: translateY(0);
}

.skip-link:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

@supports (color: color-mix(in srgb, #000 50%, #fff)) {
  .skip-link:focus-visible {
    outline-color: color-mix(in srgb, var(--color-primary) 30%, #fff);
  }
}

/* Inherit fonts for form elements */
input, button, textarea, select {
  font: inherit;
}

/* ==========================================================================
   Theme-aware Browser Defaults
   ========================================================================== */

/* accent-color: Theme native form controls (checkboxes, radios, range, progress) */
:root {
  accent-color: var(--color-primary);
}

/* caret-color: Theme the text cursor in inputs */
input,
textarea,
[contenteditable="true"] {
  caret-color: var(--color-primary);
}

/* ::marker: Theme list bullet/number colors */
::marker {
  color: var(--color-text-muted);
}

/* ==========================================================================
   Form Elements Base Styling
   ========================================================================== */

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
select,
textarea {
  color: var(--color-text);
  background-color: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: var(--radius, 0.375rem);
  padding: var(--space-2, 0.5rem) var(--space-3, 0.75rem);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 20%, transparent);
}

/* Placeholder text */
::placeholder {
  color: var(--color-text-muted);
  opacity: 0.7;
}

/* Button base styling */
button,
input[type="submit"],
input[type="button"],
input[type="reset"] {
  cursor: pointer;
  color: var(--color-text);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius, 0.375rem);
  padding: var(--space-2, 0.5rem) var(--space-4, 1rem);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

button:hover,
input[type="submit"]:hover,
input[type="button"]:hover,
input[type="reset"]:hover {
  background-color: var(--color-background);
  border-color: var(--color-primary);
}

button:focus-visible,
input[type="submit"]:focus-visible,
input[type="button"]:focus-visible,
input[type="reset"]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Disabled form elements */
input:disabled,
select:disabled,
textarea:disabled,
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* File input button */
::file-selector-button {
  font: inherit;
  color: var(--color-text);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius, 0.375rem);
  padding: var(--space-2, 0.5rem) var(--space-4, 1rem);
  margin-right: var(--space-3, 0.75rem);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

::file-selector-button:hover {
  background-color: var(--color-background);
  border-color: var(--color-primary);
}

/* Search input cancel button */
input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  height: 1em;
  width: 1em;
  border-radius: 50%;
  background-color: var(--color-text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}

input[type="search"]:focus::-webkit-search-cancel-button,
input[type="search"]:not(:placeholder-shown)::-webkit-search-cancel-button {
  opacity: 0.6;
}

input[type="search"]::-webkit-search-cancel-button:hover {
  opacity: 1;
}

/* Shared backdrop styling; keep blur off for fullscreen media performance */
::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
}

/* High contrast mode overrides */
@media (prefers-contrast: more) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
  select,
  textarea,
  button {
    border-width: 2px;
  }
}

/* Base */
html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scrollbar-gutter: stable;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  color: var(--color-text);
  background-color: var(--color-background);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: var(--leading-tight);
  margin-top: var(--space-8);
  margin-bottom: var(--space-4);
  color: var(--color-text);
  position: relative;
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); font-weight: 600; }

/* Heading Anchors */
.heading-anchor {
  opacity: 0;
  margin-left: var(--space-2);
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 400;
  transition: opacity 0.2s, color 0.2s;
}

h1:hover .heading-anchor,
h2:hover .heading-anchor,
h3:hover .heading-anchor,
h4:hover .heading-anchor,
h5:hover .heading-anchor,
h6:hover .heading-anchor,
.heading-anchor:focus {
  opacity: 1;
}

.heading-anchor:hover {
  color: var(--color-primary);
  text-decoration: none;
}

p {
  margin-bottom: var(--space-4);
}

a {
  color: var(--color-link, var(--color-primary));
  text-decoration: none;
  transition: color 0.2s;
}

a:hover {
  color: var(--color-link-hover, var(--color-primary-dark));
  text-decoration: underline;
}


/* Lists */
ul, ol {
  margin-bottom: var(--space-4);
  padding-left: var(--space-6);
}

li {
  margin-bottom: var(--space-2);
}

li > ul, li > ol {
  margin-top: var(--space-2);
  margin-bottom: 0;
}

/* Blockquotes */
blockquote {
  border-left: 4px solid var(--color-primary);
  margin: var(--space-4) 0;
  padding: var(--space-4);
  padding-left: var(--space-6);
  background: var(--color-surface);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
  color: var(--color-text-muted);
}

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

/* Images */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

figure {
  margin: var(--space-6) 0;
}

figcaption {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
  margin-top: var(--space-2);
}

/* Videos */
video,
.md-video {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ==========================================================================
   Post Content Media Styling

   Following best practices from Tailwind Typography, Astro, and other SSGs:
   - Minimal default styling (no borders by default)
   - Proper spacing with margin
   - Optional decorative styles via classes
   ========================================================================== */

/* Base media in post content - clean minimal styling */
.post-content img,
.post-content video,
.post-content .md-video {
  /* Prevent overflow */
  max-width: 100%;
  height: auto;

  /* Block display with spacing (like Tailwind Typography) */
  display: block;
  margin-top: var(--space-6);
  margin-bottom: var(--space-6);

  /* Subtle rounding */
  border-radius: var(--radius-lg);
}

/* Center larger images, but allow small inline images */
.post-content p > img:only-child,
.post-content figure img {
  margin-left: auto;
  margin-right: auto;
}

/* Figure styling */
.post-content figure {
  margin: var(--space-8) 0;
}

.post-content figure > img,
.post-content figure > video {
  margin-top: 0;
  margin-bottom: 0;
}

.post-content figcaption {
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--color-text-muted);
  text-align: center;
  margin-top: var(--space-3);
}

/* Small inline images (badges, icons) - no special treatment */
.post-content img.inline,
.post-content img[height="16"],
.post-content img[height="20"],
.post-content img[height="24"],
.post-content img[height="32"] {
  display: inline;
  margin: 0;
  border-radius: var(--radius);
  vertical-align: middle;
}

/* ==========================================================================
   Optional Media Decorations

   Apply these via frontmatter css_class or directly on elements.
   These are opt-in, not default.
   ========================================================================== */

/* Bordered style - subtle border */
.post-content.bordered img,
.post-content.bordered video,
.post-content img.bordered,
.post-content video.bordered {
  border: 1px solid var(--color-border);
}

/* Shadow style - elevated card look */
.post-content.shadow img,
.post-content.shadow video,
.post-content img.shadow,
.post-content video.shadow {
  box-shadow:
    0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Framed style - border + shadow + padding (like a photo frame) */
.post-content.framed img,
.post-content.framed video,
.post-content img.framed,
.post-content video.framed {
  border: 1px solid var(--color-border);
  padding: var(--space-2);
  background: var(--color-surface);
  box-shadow:
    0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Dark mode adjustments for framed */
@media (prefers-color-scheme: dark) {
  .post-content.framed img,
  .post-content.framed video,
  .post-content img.framed,
  .post-content video.framed {
    box-shadow:
      0 4px 6px -1px rgba(0, 0, 0, 0.3),
      0 2px 4px -1px rgba(0, 0, 0, 0.2);
  }
}

/* ==========================================================================
   Gradient Borders (Opt-in decorative style)

   Use padding + background technique for gradient borders.
   Apply via css_class in frontmatter.
   ========================================================================== */

/* Base gradient border setup */
.post-content.gradient-borders img,
.post-content.gradient-borders video,
.post-content.gradient-borders .md-video,
.media-frame.gradient-border > img,
.media-frame.gradient-border > video {
  padding: var(--media-border-width, 3px);
  background: var(--gradient-accent);
  background-origin: border-box;
  /* Inner content needs its own border-radius */
  border-radius: var(--radius-lg);
}

/* Gradient variants */
.post-content.gradient-vibrant img,
.post-content.gradient-vibrant video { background: var(--gradient-vibrant); }

.post-content.gradient-warm img,
.post-content.gradient-warm video { background: var(--gradient-warm); }

.post-content.gradient-cool img,
.post-content.gradient-cool video { background: var(--gradient-cool); }

.post-content.gradient-sunset img,
.post-content.gradient-sunset video { background: var(--gradient-sunset); }

.post-content.gradient-ocean img,
.post-content.gradient-ocean video { background: var(--gradient-ocean); }

/* Palette-specific gradients */
.post-content.gradient-catppuccin img,
.post-content.gradient-catppuccin video { background: var(--gradient-catppuccin); }

.post-content.gradient-nord img,
.post-content.gradient-nord video { background: var(--gradient-nord); }

.post-content.gradient-dracula img,
.post-content.gradient-dracula video { background: var(--gradient-dracula); }

.post-content.gradient-gruvbox img,
.post-content.gradient-gruvbox video { background: var(--gradient-gruvbox); }

.post-content.gradient-rose-pine img,
.post-content.gradient-rose-pine video { background: var(--gradient-rose-pine); }

.post-content.gradient-solarized img,
.post-content.gradient-solarized video { background: var(--gradient-solarized); }

.post-content.gradient-tokyo-night img,
.post-content.gradient-tokyo-night video { background: var(--gradient-tokyo-night); }

/* Animated gradient border */
@keyframes gradient-rotate {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.post-content.gradient-animated img,
.post-content.gradient-animated video {
  padding: var(--media-border-width, 3px);
  background: linear-gradient(270deg, #667eea, #764ba2, #f093fb, #667eea);
  background-size: 300% 300%;
  animation: gradient-rotate 6s ease infinite;
}

/* Glow effect for media */
.post-content.glow img,
.post-content.glow video {
  box-shadow:
    0 0 20px rgba(102, 126, 234, 0.3),
    0 0 40px rgba(118, 75, 162, 0.2),
    0 0 60px rgba(240, 147, 251, 0.1);
}

/* Enhanced glow in dark mode */
@media (prefers-color-scheme: dark) {
  .post-content.glow img,
  .post-content.glow video {
    box-shadow:
      0 0 30px rgba(102, 126, 234, 0.4),
      0 0 60px rgba(118, 75, 162, 0.3),
      0 0 90px rgba(240, 147, 251, 0.2);
  }
}

/* Full-width media - breaks out of content width */
.post-content img.full-width,
.post-content video.full-width {
  width: 100vw;
  max-width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  border-radius: 0;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-4) 0;
}

th, td {
  padding: var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

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

/* Horizontal rule */
hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-8) 0;
}

/* Layout */
.container {
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.content-width {
  max-width: var(--content-width);
  margin: 0 auto;
}

main {
  flex: 1;
  padding: var(--space-8) var(--space-4);
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
}

/* Content background utility - use when decorative backgrounds are enabled */
main.content-bg {
  background: var(--article-bg, var(--color-background));
  border-radius: var(--radius-lg);
  box-shadow: var(--article-shadow);
  backdrop-filter: var(--article-backdrop-filter, none);
}

/* Header */
.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-4);
}

.site-header .container {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  max-width: var(--page-width);
  margin: 0 auto;
}

.site-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  text-decoration: none;
  flex-shrink: 0;
  grid-column: 1;
  justify-self: start;
}

.site-title:hover {
  color: var(--color-primary);
  text-decoration: none;
}


/* Header controls: search + theme switcher - pushed to right on wide, centered when wrapped */
.header-controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
  grid-column: 3;
  justify-self: end;
  position: relative;
  z-index: 30;
}

/* Footer */
.site-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.site-footer .container {
  max-width: var(--page-width);
  margin: 0 auto;
}

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin: var(--space-4) 0;
}

.footer-links a {
  color: var(--color-text-muted);
}

.footer-links a:hover {
  color: var(--color-primary);
}

/* Post Styles */
.post {
  max-width: var(--content-width);
  margin: 0 auto;
}

/* Article wrapper styling */
article.post {
  padding: var(--space-6) var(--space-8);
  border-radius: var(--radius-lg);
}

/* When background decorations are present, ensure content stands out */
body:has(.background-layer) article.post,
body:has(.background-decoration) article.post {
  background: var(--article-bg, var(--color-background));
  backdrop-filter: var(--article-backdrop-filter, none);
}

.post-header {
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid color-mix(in srgb, var(--color-border) 70%, transparent);
}

.post-header__title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-8);
  flex-wrap: wrap;
}

.post-header h1 {
  margin-top: 0;
  margin-bottom: 0;
  flex: 1 1 20rem;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.post-meta time {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Author h-card (post header) */
.post-byline {
  display: inline-grid;
  grid-template-columns: 44px auto;
  grid-template-rows: auto auto;
  column-gap: var(--space-3);
  row-gap: var(--space-1);
  margin: 0;
  align-items: center;
  justify-items: start;
  text-align: left;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.post-meta--header {
  margin-top: var(--space-1);
}

@media (max-width: 560px) {
  .post-header__title-row {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }

  /* In column layout, don't let the title reserve a huge flex-basis height */
  .post-header h1 {
    flex: 0 1 auto;
    width: 100%;
  }
}

.post-byline__photo {
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.post-byline__name {
  grid-column: 2;
  grid-row: 1;
  color: inherit;
  text-decoration: none;
  line-height: 1.2;
  justify-self: start;
}

.post-byline__name:hover {
  color: var(--color-text);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--color-primary) 70%, transparent);
}

.post-byline__meta {
  grid-column: 2;
  grid-row: 2;
  margin-top: 0;
  justify-self: start;
}

/* ==========================================================================
   Multi-Author Byline
   ========================================================================== */

.post-byline--multi {
  /* Override the single-author inline-grid layout */
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  /* Reset grid-specific properties inherited from .post-byline */
  grid-template-columns: unset;
  grid-template-rows: unset;
}

.post-byline__authors {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

/* Subtle separator between authors */
.post-byline__authors > .post-byline__author + .post-byline__author {
  position: relative;
  padding-left: var(--space-3);
}

.post-byline__authors > .post-byline__author + .post-byline__author::before {
  content: '';
  position: absolute;
  left: 0;
  top: 15%;
  height: 70%;
  width: 1px;
  background: var(--color-border);
}

.post-byline__author {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.post-byline__author .post-byline__photo {
  /* Slightly smaller avatar in multi-author context to stay compact */
  width: 36px;
  height: 36px;
  /* Override single-author grid placement */
  grid-column: unset;
  grid-row: unset;
  flex-shrink: 0;
}

.post-byline__author-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.post-byline__author-info .post-byline__name {
  /* Override single-author grid placement */
  grid-column: unset;
  grid-row: unset;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
}

.post-byline__role {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-style: italic;
  line-height: 1.2;
  opacity: 0.85;
}

/* --------------------------------------------------------------------------
   Author Details Tooltip (CSS-only)
   Shows per-post contribution details on hover via data-details attribute.
   The native title attribute provides a fallback for non-hover devices.
   -------------------------------------------------------------------------- */

.post-byline__author[data-details] {
  position: relative;
  cursor: help;
  z-index: 1;
}

.post-byline__author[data-details]:hover {
  z-index: 100;
}

/* Small info indicator for authors with details */
.post-byline__details-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  font-size: 10px;
  font-style: italic;
  font-family: Georgia, serif;
  color: var(--color-text-muted);
  opacity: 0.7;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
}

.post-byline__author[data-details]:hover .post-byline__details-icon {
  opacity: 1;
  border-color: var(--color-text-muted);
}

/* Tooltip via ::after pseudo-element */
.post-byline__author[data-details]::after {
  content: attr(data-details);
  position: absolute;
  left: 0;
  top: 100%;
  margin-top: var(--space-1);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface, #f9fafb);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius, 6px);
  font-size: var(--text-xs);
  font-style: normal;
  line-height: 1.4;
  white-space: normal;
  min-width: 160px;
  max-width: 280px;
  width: max-content;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.post-byline__author[data-details]:hover::after {
  opacity: 1;
  transform: translateY(0);
}

/* Hide native title tooltip when CSS tooltip is active (title can't be fully
   suppressed in CSS, but the CSS tooltip appears faster and covers it). */

/* Multi-author meta (date/reading time) sits below the authors row */
.post-byline--multi .post-byline__meta {
  /* Override single-author grid placement */
  grid-column: unset;
  grid-row: unset;
  margin-top: 0;
}

/* On narrow viewports, authors stack vertically and separator shifts */
@media (max-width: 560px) {
  .post-byline__authors {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }

  .post-byline__authors > .post-byline__author + .post-byline__author {
    padding-left: 0;
    padding-top: var(--space-2);
  }

  .post-byline__authors > .post-byline__author + .post-byline__author::before {
    /* Horizontal separator on mobile */
    top: 0;
    left: 0;
    height: 1px;
    width: 100%;
  }
}

.post-content {
  margin-bottom: var(--space-8);
  /* Prevent content from overflowing horizontally */
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.post-content > *:first-child {
  margin-top: 0;
}

.post-footer {
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-border);
}

/* Tags */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tag {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  background: var(--color-surface);
  color: var(--color-text-muted);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.tag:hover {
  background: var(--color-primary);
  color: white;
  text-decoration: none;
}

/* Post Navigation */
.post-nav {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-border);
  align-items: stretch;
}

.post-nav a {
  max-width: 48%;
  flex: 1 1 0;
  min-height: 3.5rem;
  padding: 0.875rem 1rem;
  text-decoration: none;
  line-height: 1.35;
  display: flex;
  align-items: center;
  transition: color 0.15s ease, transform 0.15s ease;
}

.post-nav a:hover {
  transform: translateY(-1px);
}

.post-nav .prev::before {
  content: '\2190 ';
}

.post-nav .next::after {
  content: ' \2192';
}

/* Feed / Post List */
.feed {
  max-width: var(--content-width);
  margin: 0 auto;
}

/* Feed wrapper styling */
section.feed,
div.feed {
  padding: var(--space-6) var(--space-8);
  border-radius: var(--radius-lg);
}

/* When background decorations are present, ensure feed content stands out */
body:has(.background-layer) section.feed,
body:has(.background-layer) div.feed,
body:has(.background-decoration) section.feed,
body:has(.background-decoration) div.feed {
  background: var(--article-bg, var(--color-background));
  backdrop-filter: var(--article-backdrop-filter, none);
}

.feed-header {
  margin-bottom: var(--space-8);
}

.feed-header h1 {
  margin-top: 0;
}

.feed-header p {
  color: var(--color-text-muted);
}

.posts,
.post-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

/* Card */
.card {
  padding: var(--space-6);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.card:hover {
  border-color: var(--color-primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.card h2 {
  margin-top: 0;
  margin-bottom: var(--space-2);
  font-size: var(--text-xl);
}

.card h2 a {
  color: var(--color-text);
}

.card h2 a:hover {
  color: var(--color-primary);
  text-decoration: none;
}

.card-description {
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
}

.card-meta {
  display: flex;
  gap: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.pagination-prev,
.pagination-next {
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-primary);
  text-decoration: none;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.pagination-prev:hover,
.pagination-next:hover {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: white;
  text-decoration: none;
}

.pagination-prev.disabled,
.pagination-next.disabled {
  color: var(--color-text-muted);
  background: var(--color-surface);
  border-color: var(--color-border);
  cursor: not-allowed;
  opacity: 0.5;
}

.pagination-pages {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  align-items: center;
  justify-content: center;
  max-width: 100%;
}

.pagination-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  user-select: none;
}

.pagination-page {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: var(--space-1) var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  text-decoration: none;
  font-size: var(--text-sm);
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.pagination-page:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  text-decoration: none;
}

.pagination-page.current {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
  font-weight: 600;
}

/* HTMX pagination loading state */
.pagination.htmx-request {
  opacity: 0.6;
  pointer-events: none;
}

/* Posts list for HTMX swapping */
.posts-list {
  min-height: 200px;
}

.posts-list.htmx-swapping {
  opacity: 0.5;
  transition: opacity 0.2s;
}

/* Infinite Scroll Pagination */
.pagination-infinite {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-8) 0;
  margin-top: var(--space-6);
}

.infinite-scroll-trigger {
  height: 1px;
  width: 100%;
}

.infinite-scroll-loading {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.infinite-scroll-loading.htmx-request {
  display: flex;
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.infinite-scroll-end {
  padding: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
  border-top: 1px solid var(--color-border);
  width: 100%;
  max-width: 300px;
}

/* Utility Classes */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ==========================================================================
   Plugin Styles
   ========================================================================== */


/* CSV Tables (csv_fence plugin) */
.csv-table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-6) 0;
  font-size: var(--text-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.csv-table th,
.csv-table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

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

.csv-table tbody tr:nth-child(even) {
  background: var(--color-surface);
}

.csv-table tbody tr:hover {
  background: var(--color-border);
}

/* Glossary Terms (glossary plugin) */
.glossary-term {
  color: var(--color-link, var(--color-primary));
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  cursor: help;
  transition: text-decoration-color 0.2s;
}

.glossary-term:hover {
  text-decoration-style: solid;
  text-decoration-color: var(--color-link-hover, var(--color-primary));
}

/* Mermaid Diagrams (mermaid plugin) */
.mermaid {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin: var(--space-6) 0;
  text-align: center;
  overflow-x: auto;
}

/* Wikilinks (wikilinks plugin) */
a.wikilink {
  color: var(--color-link, var(--color-primary));
}

a.wikilink.wikilink-missing {
  color: var(--color-error);
  text-decoration: underline;
  text-decoration-style: dashed;
}

/* Wikilink Tooltips */
.wikilink-tooltip {
  position: fixed;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 12px;
  max-width: 300px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 1000;
  animation: tooltipFadeIn 0.2s ease;
}

.tooltip-title { font-weight: 600; margin-bottom: 4px; }
.tooltip-desc { font-size: 0.9em; color: var(--color-text-muted); }
.tooltip-date { font-size: 0.8em; color: var(--color-text-muted); margin-top: 8px; }

@keyframes tooltipFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Reading Time (reading_time plugin) */
.reading-time {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* YouTube Embeds (youtube plugin) */
.youtube-embed {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
  height: 0;
  overflow: hidden;
  max-width: 100%;
  margin: var(--space-6) 0;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.youtube-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: var(--radius-lg);
}

/* Responsive */
@media (max-width: 768px) {
  html {
    font-size: 15px;
  }

  /* Prevent horizontal overflow - WCAG 2.1 SC 1.4.10 Reflow */
  body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* Container - reduce padding on mobile */
  .container {
    padding: 0 var(--space-3);
    max-width: 100%;
  }

  /* Reduce main padding on mobile */
  main {
    padding: var(--space-4) var(--space-3);
    max-width: 100%;
  }

  /* Header - wrap to multiple rows */
  .site-header {
    padding: var(--space-3);
    overflow-x: hidden;
  }

  .site-header .container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }

  /* Mobile header stacking: title, nav, then controls (search last) */
  .site-title {
    order: 1;
    align-self: center;
    margin: 0 auto;
    text-align: center;
  }

  .site-header .site-nav {
    order: 2;
    justify-content: flex-start;
    width: 100%;
  }

  .header-controls {
    order: 3;
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }

  .header-controls .theme-switcher {
    order: 1;
  }

  .header-controls .search-container--navbar,
  .header-controls .search--navbar {
    order: 2;
    width: 100%;
    margin-left: 0;
  }

  /* Nav wrapping for small screens */
  .site-nav {
    flex-wrap: wrap;
    gap: var(--space-3);
  }

  /* When the title/byline wrap, avoid oversized vertical gaps */
  .post-header__title-row {
    gap: var(--space-4);
  }

  /* Footer - full width, reduced padding */
  .site-footer {
    padding: var(--space-4) var(--space-3);
    max-width: 100%;
  }

  /* Responsive feed container - match specificity of base rule */
  .feed,
  section.feed,
  div.feed {
    max-width: 100%;
    padding: var(--space-4) var(--space-3);
    border-radius: var(--radius);
  }

  /* Scale down feed header */
  .feed-header h1 {
    font-size: var(--text-2xl);
  }

  /* Adapt card spacing and ensure no overflow */
  .card {
    padding: var(--space-4);
    max-width: 100%;
  }

  /* Ensure posts list doesn't overflow */
  .posts,
  .post-list {
    max-width: 100%;
    overflow-x: hidden;
  }

  .post {
    max-width: 100%;
  }

  /* Reduce article padding on mobile */
  article.post {
    padding: var(--space-4) 0;
  }

  .post-nav {
    flex-direction: column;
  }

  .post-nav a {
    max-width: 100%;
  }
}

/* Mid-sized mobile devices (375px - 480px, e.g., Moto G Power at 412px) */
@media (max-width: 480px) {
  /* Container - minimal padding */
  .container {
    padding: 0 var(--space-2);
  }

  /* Even tighter main padding */
  main {
    padding: var(--space-3) var(--space-2);
  }

  .site-header {
    padding: var(--space-2);
  }

  .site-footer {
    padding: var(--space-3) var(--space-2);
  }

  /* Remove left/right padding, use full width */
  .feed,
  section.feed,
  div.feed {
    padding: var(--space-3) var(--space-2);
    border-radius: 0;
  }

  .card {
    padding: var(--space-3);
    border-radius: var(--radius);
  }

  .posts,
  .post-list {
    gap: var(--space-4);
  }

  .post {
    max-width: 100%;
  }

  article.post {
    padding: var(--space-3) 0;
  }
}

/* Extra small devices (320px - 375px) */
@media (max-width: 375px) {
  /* Container - minimal */
  .container {
    padding: 0 var(--space-1);
  }

  /* Minimal padding for very small screens */
  main {
    padding: var(--space-2) var(--space-1);
  }

  .site-header {
    padding: var(--space-2) var(--space-1);
  }

  .site-footer {
    padding: var(--space-2) var(--space-1);
  }

  .feed,
  section.feed,
  div.feed {
    padding: var(--space-2) var(--space-1);
  }

  .card {
    padding: var(--space-2);
  }

  .post {
    max-width: 100%;
  }

  /* Smaller typography */
  .feed-header h1 {
    font-size: var(--text-xl);
  }

  article.post {
    padding: var(--space-2) 0;
  }
}

}
