/* ---------------------------------------------------------------------------
   Andrew Cooper Online — theme
   Light is the default; dark is applied by prefers-color-scheme and can be
   overridden either way by [data-theme] set from the toggle.
--------------------------------------------------------------------------- */

:root {
  --bg:          #faf8f5;
  --bg-raised:   #ffffff;
  --bg-sunken:   #f1ede6;
  --ink:         #22201d;
  --ink-soft:    #5d574e;
  --ink-faint:   #8b8378;
  --rule:        #e0d9cd;
  --accent:      #8a2f2f;
  --accent-soft: #b45c4a;
  --shadow:      0 1px 2px rgb(34 32 29 / .06), 0 8px 24px rgb(34 32 29 / .06);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans:  ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono:  ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --measure: 40rem;   /* comfortable line length for prose */
  --wrap:    72rem;
  --radius:  8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #16151a;
    --bg-raised:   #1e1d23;
    --bg-sunken:   #121116;
    --ink:         #e8e4dd;
    --ink-soft:    #a9a299;
    --ink-faint:   #7c756c;
    --rule:        #33313a;
    --accent:      #e08b7a;
    --accent-soft: #f0a998;
    --shadow:      0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .3);
  }
}

:root[data-theme="dark"] {
  --bg:          #16151a;
  --bg-raised:   #1e1d23;
  --bg-sunken:   #121116;
  --ink:         #e8e4dd;
  --ink-soft:    #a9a299;
  --ink-faint:   #7c756c;
  --rule:        #33313a;
  --accent:      #e08b7a;
  --accent-soft: #f0a998;
  --shadow:      0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .3);
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-soft); }

.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: 1.25rem; }

.skip {
  position: absolute; left: -9999px;
  background: var(--accent); color: #fff; padding: .6rem 1rem; border-radius: var(--radius);
}
.skip:focus { left: 1rem; top: 1rem; z-index: 100; }

/* --- masthead ------------------------------------------------------------ */

.masthead {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.masthead-inner {
  display: flex; align-items: center; gap: 1.5rem;
  min-height: 4rem; flex-wrap: wrap;
}

.brand { display: flex; flex-direction: column; text-decoration: none; color: inherit; margin-right: auto; }
.brand-name { font-family: var(--serif); font-size: 1.35rem; font-weight: 600; letter-spacing: -.01em; }
.brand-tagline { font-size: .74rem; color: var(--ink-faint); letter-spacing: .04em; text-transform: uppercase; }

.site-nav { display: flex; align-items: center; gap: 1.25rem; }
.site-nav ul { display: flex; gap: 1.1rem; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.site-nav a {
  color: var(--ink-soft); text-decoration: none; font-size: .92rem;
  padding: .35rem 0; border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: var(--ink); }
.site-nav .current > a { color: var(--ink); border-bottom-color: var(--accent); }

.search input {
  font: inherit; font-size: .88rem;
  padding: .38rem .7rem; width: 9rem;
  color: var(--ink); background: var(--bg-sunken);
  border: 1px solid var(--rule); border-radius: 999px;
  transition: width .18s ease;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; width: 12rem; }

.theme-toggle {
  width: 2rem; height: 2rem; padding: 0; cursor: pointer;
  background: none; border: 1px solid var(--rule); border-radius: 999px;
  color: var(--ink-soft); font-size: .95rem; line-height: 1;
  display: grid; place-items: center;
}
.theme-toggle::before { content: "◐"; }
.theme-toggle:hover { color: var(--ink); border-color: var(--ink-faint); }

.nav-toggle { display: none; }

/* --- layout -------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: 16rem minmax(0, 1fr);
  gap: 3rem;
  align-items: start;
  padding-block: 2.5rem 4rem;
}
.layout-solo { grid-template-columns: minmax(0, 1fr); max-width: calc(var(--measure) + 8rem); }

.sidebar { position: sticky; top: 5.25rem; font-size: .9rem; }
.sidebar-title { margin: 0 0 .6rem; font-weight: 600; font-family: var(--serif); font-size: 1.02rem; }
.sidebar-title a { color: inherit; text-decoration: none; }
.sidebar ul { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--rule); }
.sidebar li a {
  display: block; padding: .3rem 0 .3rem .85rem; margin-left: -2px;
  border-left: 2px solid transparent;
  color: var(--ink-soft); text-decoration: none; line-height: 1.35;
}
.sidebar li a:hover { color: var(--ink); background: var(--bg-sunken); }
.sidebar li.current a { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }

.article { min-width: 0; }
.crumbs { font-size: .82rem; color: var(--ink-faint); margin-bottom: 1rem; }
.crumbs a { color: var(--ink-faint); text-decoration: none; }
.crumbs a:hover { color: var(--accent); text-decoration: underline; }
.crumbs span { margin-inline: .4rem; }

.article-title {
  font-family: var(--serif); font-weight: 600;
  font-size: clamp(1.9rem, 1.3rem + 2.4vw, 2.8rem);
  line-height: 1.12; letter-spacing: -.02em;
  margin: 0 0 .5rem; max-width: var(--measure);
}
.article-date { color: var(--ink-faint); font-size: .85rem; margin: 0 0 1.5rem; }

/* --- prose --------------------------------------------------------------- */

.prose {
  font-family: var(--serif);
  font-size: 1.12rem;
  line-height: 1.72;
  max-width: var(--measure);
}
.prose > * { max-width: var(--measure); }
.prose p { margin: 0 0 1.35em; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--serif); font-weight: 600; line-height: 1.25;
  letter-spacing: -.015em; margin: 2.2em 0 .6em; scroll-margin-top: 5.5rem;
}
.prose h1 { font-size: 1.9rem; }
.prose h2 { font-size: 1.55rem; }
.prose h3 { font-size: 1.28rem; }
.prose h4 { font-size: 1.1rem; }
.prose > :first-child { margin-top: 0; }
.prose ul, .prose ol { margin: 0 0 1.35em; padding-left: 1.4em; }
.prose li { margin-bottom: .4em; }
.prose blockquote {
  margin: 1.6em 0; padding: .2em 0 .2em 1.2em;
  border-left: 3px solid var(--accent); color: var(--ink-soft); font-style: italic;
}
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5em auto; max-width: 8rem; }
.prose code { font-family: var(--mono); font-size: .88em; background: var(--bg-sunken); padding: .12em .35em; border-radius: 4px; }
.prose pre { background: var(--bg-sunken); padding: 1rem; border-radius: var(--radius); overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose table { width: 100%; border-collapse: collapse; margin: 1.6em 0; font-size: .95em; }
.prose th, .prose td { text-align: left; padding: .5em .7em; border-bottom: 1px solid var(--rule); }

.prose img { border-radius: var(--radius); display: block; margin: 1.8em auto; box-shadow: var(--shadow); }
.prose img.align-right,
.prose img.align-left {
  width: 13.5rem; margin: .35rem 0 1rem;
  border: 1px solid var(--rule);
}
.prose img.align-right { float: right; margin-left: 1.6rem; shape-outside: margin-box; }
.prose img.align-left  { float: left;  margin-right: 1.6rem; shape-outside: margin-box; }
.prose img.align-full  { width: 100%; }
.prose p::after { content: ""; display: table; clear: both; }

/* --- home ---------------------------------------------------------------- */

.home { padding-block: 2rem 4rem; }
.hero {
  display: block; width: 100%; border-radius: var(--radius);
  margin-bottom: 3rem; box-shadow: var(--shadow);
}
/* The home page is a gallery, not an article, so it ignores the reading measure. */
.home .prose,
.home .prose > * { max-width: none; }
.home .prose h2 {
  font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.1rem);
  text-align: center; margin: 3.5rem 0 1.75rem;
}
.home .prose > h2:first-child { margin-top: 0; }

.cards {
  display: grid;
  /* auto-fill, not auto-fit: empty tracks are kept, so a row of two cards is
     the same size as a row of four instead of stretching to fill. */
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1.5rem;
  margin-bottom: 1rem;
}
/* Markdown wraps the card links in a single paragraph; make that paragraph
   transparent so the links themselves become the grid items. */
.cards p { display: contents; }
.cards a {
  display: block; border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); background: var(--bg-raised);
  transition: transform .18s ease, box-shadow .18s ease;
}
.cards a:hover { transform: translateY(-3px); box-shadow: 0 6px 12px rgb(0 0 0 / .1), 0 16px 40px rgb(0 0 0 / .14); }
.cards img { display: block; width: 100%; margin: 0; border-radius: 0; box-shadow: none; aspect-ratio: 1; object-fit: cover; }

@media (prefers-reduced-motion: reduce) { .cards a:hover { transform: none; } }

/* --- pager --------------------------------------------------------------- */

.pager {
  display: flex; justify-content: space-between; gap: 1rem;
  margin-top: 4rem; padding-top: 1.5rem; border-top: 1px solid var(--rule);
  max-width: var(--measure);
}
.pager a {
  display: flex; flex-direction: column; gap: .15rem; max-width: 48%;
  text-decoration: none; color: var(--ink);
  padding: .75rem 1rem; border: 1px solid var(--rule); border-radius: var(--radius);
}
.pager a:hover { border-color: var(--accent); }
.pager span { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-faint); }
.pager strong { font-weight: 500; font-size: .95rem; line-height: 1.3; }
.pager-next { text-align: right; margin-left: auto; }

/* --- search results ------------------------------------------------------ */

.search-page { display: flex; gap: .6rem; margin: 1.5rem 0 2rem; }
.search-page input { flex: 1; width: auto; border-radius: var(--radius); padding: .6rem .9rem; }
.search-page button {
  font: inherit; padding: .6rem 1.1rem; cursor: pointer;
  background: var(--accent); color: #fff; border: 0; border-radius: var(--radius);
}
.muted { color: var(--ink-faint); font-size: .92rem; }
.results { list-style: none; margin: 1.5rem 0 0; padding: 0; }
.results li { padding: 1.1rem 0; border-top: 1px solid var(--rule); }
.results li > a { font-family: var(--serif); font-size: 1.15rem; font-weight: 600; text-decoration: none; }
.results li > a:hover { text-decoration: underline; }
.results p { margin: .35rem 0 0; color: var(--ink-soft); font-size: .92rem; line-height: 1.55; }

/* --- footer -------------------------------------------------------------- */

.footer {
  border-top: 1px solid var(--rule);
  background: var(--bg-sunken);
  padding-block: 2.5rem;
  font-size: .9rem; color: var(--ink-soft);
}
.footer p { margin: 0 0 .4rem; }
.colophon { color: var(--ink-faint); font-size: .84rem; }

/* --- small screens ------------------------------------------------------- */

@media (max-width: 60rem) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 2rem; }
  .sidebar {
    position: static; order: 2;
    border-top: 1px solid var(--rule); padding-top: 1.5rem;
  }
  .article { order: 1; }
}

@media (max-width: 48rem) {
  .masthead-inner { min-height: 3.5rem; }

  .nav-toggle {
    display: grid; gap: 4px; place-content: center;
    width: 2.5rem; height: 2.5rem; padding: 0; cursor: pointer;
    background: none; border: 1px solid var(--rule); border-radius: var(--radius);
  }
  .nav-toggle span { display: block; width: 1.05rem; height: 2px; background: var(--ink); border-radius: 2px; }

  .site-nav {
    display: none; order: 3;
    width: 100%; flex-direction: column; align-items: stretch; gap: .75rem;
    padding-bottom: 1rem;
  }
  .site-nav.open { display: flex; }
  .site-nav ul { flex-direction: column; gap: 0; }
  .site-nav li a { display: block; padding: .55rem 0; border-bottom: 1px solid var(--rule); }
  .site-nav .current > a { border-bottom-color: var(--accent); }
  .search input { width: 100%; border-radius: var(--radius); }
  .search input:focus { width: 100%; }
  .theme-toggle { align-self: flex-start; }

  .prose { font-size: 1.06rem; }
  .prose img.align-right, .prose img.align-left {
    float: none; width: 100%; max-width: 18rem;
    margin: 1.5em auto; display: block;
  }
  .pager { flex-direction: column; }
  .pager a { max-width: none; }
  .pager-next { text-align: left; margin-left: 0; }
}
