/* ==========================================================================
   site.css — dense, quiet design system for the index and tag pages.

   Self-contained: defines its own tokens and base styles so these pages
   only need this file (plus pwa.css for offline indicators).

   Accessibility notes:
   - All text colors meet WCAG 2.2 AA contrast against the page background.
   - Interactive targets are at least 24x24 CSS px (2.5.8), most are 44px.
   - Focus is always visible via :focus-visible outlines (2.4.7 / 2.4.13).
   - Motion is disabled under prefers-reduced-motion (2.3.3).
   ========================================================================== */

/* --------------------------------------------------------------------------
   Tokens
   -------------------------------------------------------------------------- */

:root {
  --paper: #fffef9;
  --ink: #1c1917;
  /* 7.6:1 on --paper — safe for small meta text */
  --muted: #57534e;
  --accent: #0f766e;
  --accent-strong: #134e4a;
  --border: rgba(28, 25, 23, 0.14);
  --border-strong: rgba(28, 25, 23, 0.3);
  --tile-bg: #eceae4;
  --badge-bg: rgba(28, 25, 23, 0.78);
  --badge-ink: #fffef9;

  --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-sans:
    Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, Menlo, monospace;

  --measure: 46rem;
  --page-max: 72rem;
  --page-pad: clamp(1rem, 4vw, 2rem);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --paper: #0c0a09;
    --ink: #fafaf9;
    --muted: #b3ada7;
    --accent: #5eead4;
    --accent-strong: #99f6e4;
    --border: rgba(250, 250, 249, 0.16);
    --border-strong: rgba(250, 250, 249, 0.35);
    --tile-bg: #1c1917;
    --badge-bg: rgba(12, 10, 9, 0.8);
    --badge-ink: #fafaf9;
  }
}

[data-theme='dark'] {
  --paper: #0c0a09;
  --ink: #fafaf9;
  --muted: #b3ada7;
  --accent: #5eead4;
  --accent-strong: #99f6e4;
  --border: rgba(250, 250, 249, 0.16);
  --border-strong: rgba(250, 250, 249, 0.35);
  --tile-bg: #1c1917;
  --badge-bg: rgba(12, 10, 9, 0.8);
  --badge-ink: #fafaf9;
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
}

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

a {
  color: inherit;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}

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

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

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

.skip-link {
  position: absolute;
  left: var(--page-pad);
  top: -100px;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 6px 6px;
}

.skip-link:focus {
  top: 0;
}

/* --------------------------------------------------------------------------
   Layout shell
   -------------------------------------------------------------------------- */

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--page-pad);
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */

.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.25rem 0 1rem;
  border-bottom: 1px solid var(--border);
}

.site-name {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: inherit;
}

.site-name a {
  text-decoration: none;
  color: var(--ink);
}

.tag-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem 1.1rem;
  flex-wrap: wrap;
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
}

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

.site-nav a[aria-current='page'] {
  text-decoration: underline;
  text-underline-offset: 0.35em;
}

/* --------------------------------------------------------------------------
   Intro (h-card)
   -------------------------------------------------------------------------- */

.intro {
  padding: 1.75rem 0 0.5rem;
  max-width: var(--measure);
}

.intro p {
  margin: 0;
  font-size: 1.05rem;
  color: var(--ink);
}

.intro .intro-links {
  margin-top: 0.5rem;
  font-size: 0.92rem;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Sections
   -------------------------------------------------------------------------- */

.section {
  padding: 1.75rem 0 2.25rem;
}

.section + .section {
  border-top: 1px solid var(--border);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-head h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.section-head .section-note {
  font-size: 0.85rem;
  color: var(--muted);
}

.section-head .section-note a {
  color: inherit;
}

/* --------------------------------------------------------------------------
   Photo grid — dense tiles
   -------------------------------------------------------------------------- */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  grid-auto-rows: 150px;
  grid-auto-flow: dense;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}

@media (min-width: 700px) {
  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    grid-auto-rows: 170px;
  }
}

.photo-grid li {
  margin: 0;
}

/* Wide photos (landscape) span two columns; tall crops stay 1x1 */
.photo-grid .tile-wide {
  grid-column: span 2;
}

.tile {
  position: relative;
  display: block;
  height: 100%;
  overflow: hidden;
  border-radius: 4px;
  background: var(--tile-bg);
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.tile:hover img,
.tile:focus-visible img {
  transform: scale(1.03);
}

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

.tile-caption {
  position: absolute;
  inset: auto 0 0 0;
  padding: 1.5rem 0.6rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.tile:hover .tile-caption,
.tile:focus-visible .tile-caption {
  opacity: 1;
}

.tile-badge {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.15rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--badge-ink);
  background: var(--badge-bg);
  border-radius: 999px;
}

/* --------------------------------------------------------------------------
   Projects
   -------------------------------------------------------------------------- */

.project-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: var(--measure);
}

.project-list li {
  padding: 0.85rem 0;
}

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

.project-name {
  font-weight: 600;
  font-size: 1rem;
}

.project-desc {
  margin: 0.15rem 0 0;
  font-size: 0.92rem;
  color: var(--muted);
}

.project-meta {
  margin-top: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Writing — dense archive list grouped by year
   -------------------------------------------------------------------------- */

.writing-year {
  margin: 1.25rem 0 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.writing-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: var(--measure);
}

.writing-list li {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.4rem 0;
}

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

.writing-list time {
  flex: none;
  width: 7ch;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
}

.writing-list a {
  font-size: 0.98rem;
  text-decoration: none;
}

.writing-list a:hover {
  text-decoration: underline;
}

.writing-list .ext {
  color: var(--muted);
  font-size: 0.85em;
}

@media (max-width: 480px) {
  .writing-list li {
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.55rem 0;
  }

  .writing-list time {
    width: auto;
  }
}

/* --------------------------------------------------------------------------
   Load more
   -------------------------------------------------------------------------- */

.load-more-container {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  padding: 1rem 0 0;
}

.load-more-btn {
  min-height: 44px;
  padding: 0.55rem 1.4rem;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
}

.load-more-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */

.site-footer {
  margin-top: 1rem;
  padding: 1.5rem 0 2.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--muted);
}

.site-footer p {
  margin: 0.35rem 0;
}

.site-footer a {
  color: inherit;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
}

.footer-links a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  text-decoration: none;
  font-weight: 500;
}

.footer-links a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Theme toggle (fixed, bottom-right)
   -------------------------------------------------------------------------- */

.theme-toggle {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 50;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

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

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

/* --------------------------------------------------------------------------
   Motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .tile:hover img,
  .tile:focus-visible img {
    transform: none;
  }
}
