/* ============================================================
   BASE.CSS — Reset, Design Tokens, Typography & Element Baseline
   Thoughts in Tremolo — CSS Foundation Layer
   ============================================================ */

/* --- Modern CSS Reset (adapted from Andy Bell / Josh Comeau) --- */
*, *::before, *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}

html {
font-size: 16px;
scroll-behavior: smooth;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
hanging-punctuation: first last;
-webkit-text-size-adjust: 100%;
text-size-adjust: 100%;
overflow-x: hidden;
}

nav ol, nav ul { list-style: none; }

/* Core body baseline */
body {
  font-family: var(--font-body, 'Source Serif 4', Georgia, serif);
  font-weight: 400;
  line-height: var(--line-height-body, 1.7);
  color: var(--c-text);
  background-color: var(--c-bg);
  transition: color var(--transition-theme), background-color var(--transition-theme);
  overflow-x: hidden;
  cursor: default;
  min-height: 100dvh;
}

/* Focus-visible for keyboard users (accessibility) */
:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* Reduce motion for users who prefer it */
@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;
  }
}

/* --- Design Tokens --- */
:root {
  /* Typography */
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Courier Prime', 'Courier New', monospace;
  --font-mono: 'JetBrains Mono', Consolas, monospace;

  /* Line Heights (typographic scale) */
  --line-height-tight: 1.1;
  --line-height-snug: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.65;
  --line-height-body: 1.7;
  --line-height-loose: 1.75;

  /* Font Sizes (modular scale ~1.25 ratio, mobile-first) */
  --text-xs: 0.68rem;
  --text-sm: 0.78rem;
  --text-base: 1rem;
  --text-md: 1.05rem;
  --text-lg: 1.15rem;
  --text-xl: 1.35rem;
  --text-2xl: 1.6rem;
  --text-3xl: 2rem;
  --text-4xl: 2.5rem;
  --text-5xl: 3.5rem;

  /* Colors — Light Theme */
  --c-bg: #f6f4f0;
  --c-bg-secondary: #eeece7;
  --c-bg-tertiary: #e4e1da;
  --c-surface: #ffffff;
  --c-surface-elevated: #faf9f7;
  --c-text: #1a1815;
  --c-text-secondary: #5c5650;
  --c-text-tertiary: #8a847d;
  --c-accent: #c45d3e;
  --c-accent-hover: #a84d32;
  --c-accent-subtle: rgba(196, 93, 62, 0.08);
  --c-accent-muted: rgba(196, 93, 62, 0.15);
  --c-border: rgba(26, 24, 21, 0.1);
  --c-border-strong: rgba(26, 24, 21, 0.2);
  --c-shadow: rgba(26, 24, 21, 0.06);
  --c-shadow-strong: rgba(26, 24, 21, 0.12);
  --c-overlay: rgba(246, 244, 240, 0.85);
  --c-grain: rgba(26, 24, 21, 0.03);

  /* Spacing Scale (4px base) */
  --space-2xs: 0.125rem;  /* 2px */
  --space-xs: 0.25rem;    /* 4px */
  --space-sm: 0.5rem;     /* 8px */
  --space-md: 1rem;       /* 16px */
  --space-lg: 1.5rem;     /* 24px */
  --space-xl: 2rem;       /* 32px */
  --space-2xl: 2.5rem;    /* 40px */
  --space-3xl: 4rem;      /* 64px */
  --space-4xl: 6rem;      /* 96px */
  --space-5xl: 8rem;      /* 128px */

  /* Measure (reading width) */
  --measure: 38rem;
  --measure-wide: 54rem;
  --measure-narrow: 28rem;

  /* Radii */
  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 8px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-base: 250ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-slow: 500ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-theme: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Z-index scale */
  --z-base: 1;
  --z-dropdown: 50;
  --z-sticky: 100;
  --z-overlay: 200;
  --z-modal: 9999;
}

/* --- Dark Theme Tokens --- */
[data-theme="dark"] {
  --c-bg: #141210;
  --c-bg-secondary: #1c1a17;
  --c-bg-tertiary: #252320;
  --c-surface: #1c1a17;
  --c-surface-elevated: #222019;
  --c-text: #e8e4de;
  --c-text-secondary: #a39e96;
  --c-text-tertiary: #706b64;
  --c-accent: #e07a5f;
  --c-accent-hover: #e8937c;
  --c-accent-subtle: rgba(224, 122, 95, 0.1);
  --c-accent-muted: rgba(224, 122, 95, 0.18);
  --c-border: rgba(232, 228, 222, 0.08);
  --c-border-strong: rgba(232, 228, 222, 0.15);
  --c-shadow: rgba(0, 0, 0, 0.2);
  --c-shadow-strong: rgba(0, 0, 0, 0.35);
  --c-overlay: rgba(20, 18, 16, 0.88);
  --c-grain: rgba(232, 228, 222, 0.02);
}

/* --- Typography Baseline --- */
h1, h2, h3, h4, h5, h6 {
font-family: var(--font-display);
font-weight: 600;
line-height: var(--line-height-tight);
color: var(--c-text);
letter-spacing: -0.01em;
text-wrap: balance;
overflow-wrap: break-word;
word-wrap: break-word;
}

h1 {
  font-weight: 700;
  font-size: clamp(var(--text-3xl), 6vw, var(--text-5xl));
  letter-spacing: -0.03em;
}

h2 {
  font-weight: 700;
  font-size: clamp(var(--text-xl), 3.5vw, var(--text-4xl));
}

h3 {
  font-size: clamp(var(--text-lg), 2.5vw, var(--text-2xl));
}

h4 {
  font-size: var(--text-xl);
}

p {
max-width: var(--measure);
margin-bottom: var(--space-lg);
text-wrap: pretty;
overflow-wrap: break-word;
word-wrap: break-word;
}

/* --- Element Baseline --- */
::selection {
  background-color: var(--c-accent-muted);
  color: var(--c-text);
}

a {
  color: var(--c-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
  cursor: pointer;
}

a:hover {
  color: var(--c-accent-hover);
}

img, video, svg {
  max-width: 100%;
  height: auto;
  display: block;
}

blockquote {
  border-left: 2px solid var(--c-accent);
  padding-left: var(--space-lg);
  margin: var(--space-xl) 0;
  margin-left: 0;
  font-style: italic;
  color: var(--c-text-secondary);
  max-width: var(--measure);
}

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

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background-color: var(--c-bg-secondary);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  color: var(--c-accent);
}

pre {
  background-color: var(--c-bg-secondary);
  padding: var(--space-lg);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: var(--space-xl) 0;
  border: 1px solid var(--c-border);
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
  color: var(--c-text);
}

hr {
  border: none;
  height: 1px;
  background-color: var(--c-border);
  margin: var(--space-3xl) auto;
  max-width: var(--measure-narrow);
}

ul, ol {
  padding-left: var(--space-lg);
  margin-bottom: var(--space-lg);
  max-width: var(--measure);
}

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

.table-wrapper {
overflow-x: auto;
-webkit-overflow-scrolling: touch;
margin: var(--space-xl) 0;
}

table {
width: 100%;
border-collapse: collapse;
margin: var(--space-xl) 0;
font-size: 0.95em;
}

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

th {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--c-text);
}

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

figcaption {
  font-size: 0.85em;
  color: var(--c-text-tertiary);
  margin-top: var(--space-sm);
  font-style: italic;
  text-align: center;
}

/* --- Grain Overlay (global texture) --- */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: var(--z-modal);
  opacity: 0.4;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 200px 200px;
  mix-blend-mode: overlay;
}

/* --- Lightbox Overlay (shared across site) --- */
.lightbox-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.96);
display: flex;
align-items: center;
justify-content: center;
z-index: var(--z-modal);
cursor: zoom-out;
opacity: 0;
animation: fadeIn 0.3s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
transition: background-color 0.3s ease;
}

.lightbox-overlay::before {
content: '';
position: absolute;
top: var(--space-md);
right: var(--space-md);
width: 32px;
height: 32px;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'%3E%3C/line%3E%3Cline x1='6' y1='6' x2='18' y2='18'%3E%3C/line%3E%3C/svg%3E");
background-size: contain;
background-repeat: no-repeat;
opacity: 0.7;
transition: opacity 0.2s ease;
}

.lightbox-overlay:hover::before {
opacity: 1;
}

.lightbox-overlay__image-wrapper {
position: relative;
display: flex;
align-items: center;
justify-content: center;
max-width: 90vw;
max-height: 85vh;
}

.lightbox-overlay img {
max-width: 90vw;
max-height: 85vh;
object-fit: contain;
border-radius: var(--radius-md);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
transform: scale(0.9);
opacity: 0;
animation: zoomIn 0.4s cubic-bezier(0.25, 0.1, 0.25, 1) 0.1s forwards;
transition: transform 0.3s ease;
}

.lightbox-overlay__caption {
position: absolute;
bottom: -40px;
left: 0;
right: 0;
text-align: center;
color: rgba(255, 255, 255, 0.9);
font-size: var(--text-sm);
font-family: var(--font-body);
padding: var(--space-sm) var(--space-md);
max-width: 100%;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}

@keyframes zoomIn {
from {
transform: scale(0.9);
opacity: 0;
}
to {
transform: scale(1);
opacity: 1;
}
}

/* --- Responsive Image Scaling --- */
.post-card__image img,
.post-header__image img,
.post-content .gallery img,
.post-content .media-attachment img,
.hero-visual img {
  width: 100%;
  height: auto;
  object-fit: contain;
  transition: transform var(--transition-slow);
}

/* Ensure lightboxable images have cursor hint */
img.lightboxable {
  cursor: zoom-in;
}

/* --- Accessible Skip Link (screen reader + keyboard) --- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--c-accent);
  color: var(--c-bg);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  z-index: calc(var(--z-modal) + 1);
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: var(--space-md);
}
