/* ==========================================================================
   Counterglow default theme — one file, no framework, no build step.
   Fluid type, light/dark, container queries, ~7 KB.
   ========================================================================== */

@layer reset, tokens, base, layout, components, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  }
  img, svg, video, iframe { display: block; max-width: 100%; height: auto; }
  input, button, textarea, select { font: inherit; color: inherit; }
  button { cursor: pointer; background: none; border: 0; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 0; }
}

@layer tokens {
  :root {
    color-scheme: light dark;

    --font-body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
    --font-display: var(--font-body);
    --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

    /* Danish palette: chalk, charcoal with a green cast, Dannebrog red.
       No pure black, no pure white. One accent, set per site in the panel. */
    --accent: #c8102e;

    --bg: #ece9e1;
    --bg-soft: #e0dcd0;
    --surface: #f3f0e8;
    --line: #c3bfb2;
    --text: #1b2320;
    --muted: #626861;

    --measure: 34rem;
    --gutter: clamp(1.15rem, 5vw, 2.5rem);
    --wide: 72rem;
    --radius: 0;
    --ease: cubic-bezier(0.32, 0.72, 0, 1);

    /* fluid type scale: 320px → 1400px */
    --step--1: clamp(0.83rem, 0.81rem + 0.1vw, 0.89rem);
    --step-0:  clamp(1rem, 0.96rem + 0.2vw, 1.125rem);
    --step-1:  clamp(1.2rem, 1.12rem + 0.4vw, 1.45rem);
    --step-2:  clamp(1.45rem, 1.3rem + 0.72vw, 1.95rem);
    --step-3:  clamp(1.75rem, 1.48rem + 1.35vw, 2.7rem);
    --step-4:  clamp(2.1rem, 1.6rem + 2.5vw, 3.9rem);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #171d1b;
      --bg-soft: #1f2725;
      --surface: #222b28;
      --line: #39433f;
      --text: #ece9e1;
      --muted: #9aa39d;
      --accent: #e8536b;
    }
  }
  :root[data-theme="dark"] {
    --bg: #171d1b;
    --bg-soft: #1f2725;
    --surface: #222b28;
    --line: #39433f;
    --text: #ece9e1;
    --muted: #9aa39d;
    --accent: #e8536b;
  }
}

@layer base {
  body {
    font-family: var(--font-body);
    font-size: var(--step-0);
    line-height: 1.65;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  h1, h2, h3, h4 {
    font-family: var(--font-display);
    line-height: 1.12;
    letter-spacing: -0.032em;
    font-weight: 640;
    text-wrap: balance;
  }
  h1 { font-size: var(--step-4); }
  h2 { font-size: var(--step-2); }
  h3 { font-size: var(--step-1); }

  p, li { text-wrap: pretty; }

  a { color: inherit; text-underline-offset: 0.18em; text-decoration-thickness: from-font; }
  a:hover { text-decoration-color: var(--accent); }

  ::selection { background: color-mix(in oklab, var(--accent) 28%, transparent); }

  hr { border: 0; height: 1px; background: var(--line); }

  code { font-family: var(--font-mono); font-size: 0.88em; }
}

@layer layout {
  .shell { display: grid; grid-template-rows: auto 1fr auto; min-height: 100dvh; }

  .container { width: min(100% - var(--gutter) * 2, var(--wide)); margin-inline: auto; }
  .container--narrow { width: min(100% - var(--gutter) * 2, 46rem); margin-inline: auto; }

  .stack > * + * { margin-top: var(--space, 1.5rem); }
  .section { padding-block: clamp(3rem, 8vw, 6.5rem); }
}

@layer components {
  /* --- header ------------------------------------------------------------ */
  .site-header {
    position: sticky; top: 0; z-index: 30;
    background: var(--bg);
    border-bottom: 1px solid transparent;
    transition: border-color 0.3s;
  }
  .site-header.is-stuck { border-bottom-color: var(--line); }
  .site-header__inner { display: flex; align-items: center; gap: 1rem; padding-block: 0.9rem; }

  .logo {
    display: inline-flex; align-items: center; gap: 0.55rem;
    font-weight: 660; letter-spacing: -0.03em; font-size: 1.3rem; text-decoration: none;
  }
  .logo__mark {
    width: 13px; height: 13px; background: var(--text);
    box-shadow: 20px 0 0 var(--accent);   /* second square, drawn not nested */
    margin-right: 20px;
  }

  .nav { display: flex; align-items: center; gap: 0.25rem; margin-left: auto; }
  .nav a {
    padding: 0.4rem 0.7rem; border-radius: 0; text-decoration: none;
    font-size: var(--step--1); font-weight: 520; color: var(--muted);
    transition: color 0.2s, background 0.2s;
  }
  .nav a:hover { color: var(--text); background: var(--bg-soft); }
  .nav a[aria-current="page"] { color: var(--text); background: var(--bg-soft); }

  /* --- mobile menu (mobile-first; inline nav switches on at 48rem) -------- */
  .nav-toggle {
    display: inline-flex; flex-direction: column; justify-content: center; gap: 5px;
    width: 2.5rem; height: 2.5rem; padding: 0.55rem; margin-left: 0.1rem;
    background: none; border: 0; border-radius: 0; cursor: pointer; color: inherit;
  }
  .nav-toggle span { display: block; height: 2px; width: 100%; background: currentColor; border-radius: 2px; transition: transform .28s var(--ease, ease), opacity .2s; }
  [data-nav-open] .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  [data-nav-open] .nav-toggle span:nth-child(2) { opacity: 0; }
  [data-nav-open] .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  .menu-links { display: none; }
  [data-nav-open] .menu-links {
    display: flex; flex-direction: column; align-items: stretch;
    position: absolute; top: 100%; left: 0; right: 0; z-index: 40;
    background: var(--bg, var(--surface, Canvas));
    border-block: 1px solid var(--line, color-mix(in oklab, currentColor 16%, transparent));
    padding: 0.4rem var(--gutter, 1.25rem) 1rem;
    animation: menu-drop .22s var(--ease, ease);
  }
  [data-nav-open] .menu-links a {
    padding: 0.85rem 0.2rem; font-size: 1.15rem;
    border-bottom: 1px solid var(--line, color-mix(in oklab, currentColor 12%, transparent));
  }
  [data-nav-open] .menu-links a:last-child { border-bottom: 0; }
  @keyframes menu-drop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

  @media (min-width: 48rem) {
    .nav-toggle { display: none; }
    .menu-links { display: flex; align-items: center; gap: 0.25rem; }
    [data-nav-open] .menu-links { position: static; background: none; border: 0; padding: 0; animation: none; }
    [data-nav-open] .menu-links a { padding: 0.4rem 0.7rem; font-size: inherit; border: 0; }
  }

  .icon-btn {
    display: grid; place-items: center; width: 2.1rem; height: 2.1rem;
    border-radius: 0; color: var(--muted);
  }
  .icon-btn:hover { background: var(--bg-soft); color: var(--text); }

  /* tight nav is the default; it loosens up when there is room */
  .nav { gap: 0; }
  .nav a { padding-inline: 0.5rem; }
  @media (min-width: 40rem) {
    .nav { gap: 0.25rem; }
    .nav a { padding-inline: 0.7rem; }
  }

  /* --- hero -------------------------------------------------------------- */
  .hero { padding-block: clamp(3.5rem, 11vw, 8rem) clamp(2.5rem, 7vw, 5rem); }
  .hero p.lead {
    font-size: var(--step-1); color: var(--muted); max-width: var(--measure);
    margin-top: 1.25rem; text-wrap: pretty;
  }
  .eyebrow {
    display: inline-flex; align-items: center; gap: 0.5rem;
    font-size: var(--step--1); font-weight: 580; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--accent); margin-bottom: 1rem;
  }
  .eyebrow::before { content: ""; width: 1.75rem; height: 1px; background: currentColor; }

  /* --- buttons ----------------------------------------------------------- */
  .button {
    display: inline-flex; align-items: center; gap: 0.5rem;
    padding: 0.65rem 1.25rem; border-radius: 0;
    font-size: var(--step--1); font-weight: 580; text-decoration: none;
    background: var(--text); color: var(--bg);
    transition: transform 0.18s var(--ease), opacity 0.18s;
  }
  .button:hover { transform: translateY(-1px); opacity: 0.9; }
  .button--ghost { background: none; color: var(--text); border: 1px solid var(--line); }
  .button--ghost:hover { border-color: var(--accent); }

  /* --- cards & grids ----------------------------------------------------- */
  .grid { display: grid; gap: clamp(1.25rem, 3vw, 2rem); }
  .grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr)); }
  .grid--3 { grid-template-columns: repeat(auto-fill, minmax(min(17rem, 100%), 1fr)); }

  .card {
    container-type: inline-size;
    display: grid; gap: 0.85rem;
    text-decoration: none;
    border-radius: var(--radius);
    transition: transform 0.35s var(--ease);
  }
  .card:hover { transform: translateY(-3px); }
  .card__media {
    position: relative; overflow: hidden; border-radius: var(--radius);
    background: var(--bg-soft); aspect-ratio: 4 / 3;
  }
  .card__media img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.6s var(--ease), filter 0.4s; }
  .card:hover .card__media img { transform: scale(1.035); }
  .card__title { font-size: var(--step-1); letter-spacing: -0.028em; font-weight: 620; line-height: 1.2; }
  .card__excerpt { color: var(--muted); font-size: var(--step--1); }
  .card__meta { display: flex; gap: 0.6rem; align-items: center; font-size: var(--step--1); color: var(--muted); }

  /* --- article list ------------------------------------------------------ */
  .entries { list-style: none; padding: 0; display: grid; }
  .entry {
    display: grid; gap: 0.35rem;
    padding-block: clamp(1.35rem, 3vw, 2rem);
    border-top: 1px solid var(--line);
  }
  .entry:last-child { border-bottom: 1px solid var(--line); }
  .entry a { text-decoration: none; }
  .entry__title { font-size: var(--step-2); letter-spacing: -0.03em; transition: color 0.2s; }
  .entry:hover .entry__title { color: var(--accent); }
  .entry__meta { display: flex; flex-wrap: wrap; gap: 0.75rem; font-size: var(--step--1); color: var(--muted); }
  .entry__excerpt { color: var(--muted); max-width: var(--measure); }

  /* --- prose ------------------------------------------------------------- */
  .prose { font-size: var(--step-0); }
  .prose > * + * { margin-top: 1.35em; }
  .prose > h2 { margin-top: 2.4em; font-size: var(--step-2); }
  .prose > h3 { margin-top: 2em; font-size: var(--step-1); }
  .prose > p, .prose > ul, .prose > ol, .prose > blockquote { max-width: var(--measure); }
  .prose ul, .prose ol { padding-left: 1.3em; display: grid; gap: 0.4em; }
  .prose li::marker { color: var(--accent); }
  .prose li.task { list-style: none; margin-left: -1.3em; }
  .prose a { text-decoration: underline; text-decoration-color: color-mix(in oklab, var(--accent) 55%, transparent); }
  .prose strong { font-weight: 650; }
  .prose blockquote {
    border-left: 2px solid var(--accent);
    padding-left: 1.25rem; font-size: var(--step-1); line-height: 1.5;
    letter-spacing: -0.015em; color: var(--text);
  }
  .prose blockquote p + p { margin-top: 0.6em; }
  .prose code { background: var(--bg-soft); padding: 0.15em 0.4em; border-radius: 0; }
  .prose pre {
    background: var(--bg-soft); border: 1px solid var(--line);
    padding: 1.1rem 1.25rem; border-radius: var(--radius); overflow-x: auto;
    font-size: 0.85rem; line-height: 1.6;
  }
  .prose pre code { background: none; padding: 0; }
  .prose figure { margin-block: 2.25em; }
  .prose figure img { width: 100%; border-radius: var(--radius); }
  .prose figcaption { margin-top: 0.7rem; font-size: var(--step--1); color: var(--muted); max-width: var(--measure); }
  .prose h2 a.anchor, .prose h3 a.anchor { opacity: 0; margin-left: 0.35em; color: var(--muted); text-decoration: none; }
  .prose h2:hover a.anchor, .prose h3:hover a.anchor { opacity: 1; }

  .prose .callout {
    border: 1px solid var(--line); border-left: 3px solid var(--accent);
    background: var(--bg-soft); padding: 1rem 1.25rem; border-radius: var(--radius);
    font-size: var(--step--1);
  }
  .prose .callout--warning { border-left-color: oklch(0.75 0.15 75); }
  .prose .callout--important { border-left-color: oklch(0.62 0.2 22); }

  .table-scroll { overflow-x: auto; }
  .prose table { border-collapse: collapse; width: 100%; font-size: var(--step--1); }
  .prose th, .prose td { text-align: left; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--line); }
  .prose th { font-weight: 620; }

  .gallery { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 0.75rem; margin-block: 2.25em; }
  .gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 0; }

  .embed { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: var(--bg-soft); }
  .embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

  .file-link {
    display: inline-flex; gap: 0.5rem; align-items: baseline;
    padding: 0.4rem 0.8rem; border: 1px solid var(--line); border-radius: 0;
    text-decoration: none; font-size: var(--step--1);
  }
  .file-link small { color: var(--muted); }

  /* --- article header ---------------------------------------------------- */
  .article-head { padding-block: clamp(2.5rem, 7vw, 5rem) clamp(1.5rem, 4vw, 2.5rem); }
  .article-head h1 { font-size: var(--step-3); max-width: 20ch; }
  .article-meta { display: flex; flex-wrap: wrap; gap: 0.85rem; color: var(--muted); font-size: var(--step--1); margin-top: 1.25rem; }
  .article-cover { margin-block: clamp(1.5rem, 4vw, 2.5rem); }
  .article-cover img { width: 100%; border-radius: var(--radius); }

  .tag {
    display: inline-block; padding: 0.15rem 0.6rem; border-radius: 0;
    border: 1px solid var(--line); font-size: var(--step--1); color: var(--muted); text-decoration: none;
  }
  .tag:hover { border-color: var(--accent); color: var(--text); }

  /* --- theme catalogue --------------------------------------------------- */
  .themes { align-items: start; margin-block: clamp(1.5rem, 4vw, 2.5rem); }
  .theme-card { border: 1px solid var(--line); background: var(--surface); display: grid; }
  .theme-card__accent { height: 0.5rem; }
  .theme-card__body { padding: clamp(1.1rem, 3vw, 1.6rem); display: grid; gap: 0.55rem; }
  .theme-card__head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
  .theme-card__name { font-size: var(--step-1); letter-spacing: -0.02em; line-height: 1.15; }
  .theme-card__desc { color: var(--muted); font-size: var(--step--1); max-width: 40ch; }
  .theme-card__tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }
  .theme-card__actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.5rem; }

  .theme-install { border-top: 1px solid var(--line); margin-top: clamp(2rem, 6vw, 4rem); padding-top: clamp(1.5rem, 4vw, 2.5rem); }
  .theme-install h2 { font-size: var(--step-1); letter-spacing: -0.02em; margin-bottom: 1rem; }
  .theme-install ol { padding-left: 1.2em; max-width: var(--measure); font-size: var(--step-0); }
  .theme-install li::marker { color: var(--accent); }
  .theme-install p { margin-top: 1rem; max-width: var(--measure); }

  /* --- landing sections -------------------------------------------------- */
  .landing-hero { padding-block: clamp(3rem, 9vw, 7rem) clamp(1.5rem, 4vw, 3rem); }
  .landing-hero h1 { font-size: var(--step-4); max-width: 16ch; }
  .landing-block { padding-block: clamp(1.5rem, 5vw, 3.5rem); }
  .landing-svg { padding-block: clamp(1rem, 3vw, 2rem); }
  .landing-cta { padding-block: clamp(2.5rem, 7vw, 5rem); }
  .landing-cta h2 { font-size: var(--step-3); }

  /* --- pager ------------------------------------------------------------- */
  .pager { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(16rem, 100%), 1fr)); margin-top: 3rem; }
  .pager a {
    display: grid; gap: 0.2rem; padding: 1.1rem 1.25rem;
    border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none;
    transition: border-color 0.2s, transform 0.25s var(--ease);
  }
  .pager a:hover { border-color: var(--accent); transform: translateY(-2px); }
  .pager span { font-size: var(--step--1); color: var(--muted); }
  .pager strong { font-weight: 600; letter-spacing: -0.02em; }
  .pager .next { text-align: right; }

  /* --- footer ------------------------------------------------------------ */
  .site-footer { border-top: 1px solid var(--line); padding-block: clamp(2.5rem, 6vw, 4rem); margin-top: clamp(3rem, 8vw, 6rem); }
  .site-footer__inner { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: baseline; }
  .site-footer a { color: var(--muted); text-decoration: none; font-size: var(--step--1); }
  .site-footer a:hover { color: var(--text); }
  .footer-nav { display: flex; flex-wrap: wrap; gap: 1rem; margin-left: auto; }

  /* --- search ------------------------------------------------------------ */
  dialog.search {
    width: min(36rem, 92vw); padding: 0; border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--surface); color: var(--text); margin-top: 12vh;
    box-shadow: none;
  }
  dialog.search::backdrop { background: color-mix(in oklab, var(--text) 45%, transparent); }
  dialog.search input { width: 100%; padding: 1rem 1.2rem; border: 0; border-bottom: 1px solid var(--line); background: none; font-size: 1.05rem; }
  dialog.search input:focus { outline: none; }
  dialog.search ul { list-style: none; margin: 0; padding: 0.4rem; max-height: 60vh; overflow-y: auto; }
  dialog.search a { display: grid; gap: 0.15rem; padding: 0.65rem 0.8rem; border-radius: 0; text-decoration: none; }
  dialog.search a:hover, dialog.search li.is-active a { background: var(--bg-soft); }
  dialog.search .r-title { font-weight: 580; }
  dialog.search .r-excerpt { font-size: var(--step--1); color: var(--muted); }
  dialog.search .hint { padding: 1.75rem; text-align: center; color: var(--muted); font-size: var(--step--1); }

  /* --- reveal on scroll -------------------------------------------------- */
  .js .reveal { opacity: 0; transform: translateY(0.9rem); transition: opacity 0.6s var(--ease), transform 0.6s var(--ease); }
  .reveal.is-in { opacity: 1; transform: none; }
  @media (prefers-reduced-motion: reduce) { .reveal { opacity: 1; transform: none; } }

  .skip {
    position: absolute; left: 0.5rem; top: -4rem; z-index: 100;
    padding: 0.6rem 1rem; background: var(--text); color: var(--bg); border-radius: 0;
    transition: top 0.2s;
  }
  .skip:focus { top: 0.5rem; }
}

@layer utilities {
  .muted { color: var(--muted); }
  .small { font-size: var(--step--1); }
  .mono { font-family: var(--font-mono); }
  .center { text-align: center; }
  .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .flow > * + * { margin-top: 1rem; }
}
