/* Shared structure and behaviour. Visual tokens live in themes/<name>.css.
   Theme rules can override these layers without changing HTML or JavaScript.
   The final print layer keeps printed articles readable regardless of theme. */
@layer reset, base, layout, components, article, responsive, theme, print;
/* Small browser reset: predictable sizing without a CSS framework. */
@layer reset {
  *,*::before,*::after {
    box-sizing:border-box;
  }
  body,h1,h2,h3,p {
    margin:0;
  }
  img {
    display:block;
    max-width:100%;
    height:auto;
  }
  button,input,textarea {
    font:inherit;
  }
  a {
    color:inherit;
  }
  html {
    scroll-padding-top:2rem;
  }
  body {
    overflow-wrap:break-word;
  }
}
/* Shared tokens, typography, focus states and utility classes used by all templates. */
@layer base {
  /* Shared layout defaults; a theme may override these too. */
  :root {
    --width:1180px;
    --gutter:clamp(22px,5vw,72px);
  }
  body {
    background:var(--background);
    color:var(--text);
    font-family:var(--font);
    font-size:16px;
    line-height:1.6;
    -webkit-font-smoothing:antialiased;
  }
  a {
    text-decoration:none;
  }
  a:hover {
    color:var(--accent);
  }
  a:focus-visible,summary:focus-visible {
    outline:3px solid var(--accent);
    outline-offset:5px;
  }
  ::selection {
    background:var(--selection-background);
    color:var(--selection-text);
  }
  h1,h2,h3 {
    font-weight:550;
    line-height:1.15;
    letter-spacing:-.045em;
  }
  time,.eyebrow {
    font-variant-numeric:tabular-nums;
  }
  .accent {
    color:var(--accent);
  }
  .wrap {
    width:min(var(--width),calc(100% - var(--gutter)*2));
    margin-inline:auto;
  }
  .eyebrow {
    font-size:11px;
    font-weight:650;
    letter-spacing:.14em;
    text-transform:uppercase;
  }
  .text-link {
    display:inline-flex;
    gap:20px;
    align-items:center;
    font-size:13px;
    font-weight:650;
  }
  .text-link span {
    font-size:20px;
    font-weight:400;
  }
  .skip-link {
    position:absolute;
    left:1rem;
    top:-10rem;
    background:var(--notice-background);
    color:var(--notice-text);
    padding:1rem;
    z-index:10;
  }
  .skip-link:focus {
    top:1rem;
  }
  .preview-banner {
    background:var(--notice-background);
    color:var(--notice-text);
    text-align:center;
    padding:5px;
    font-size:11px;
    letter-spacing:.04em;
  }
}
/* Site shell and homepage: header/footer, introduction, section spacing and grids. */
@layer layout {
  .site-header {
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:24px;
    min-height:104px;
    border-bottom:1px solid var(--border);
  }
  .wordmark {
    font-size:24px;
    font-weight:750;
    letter-spacing:-1.1px;
  }
  .wordmark-dot {
    color:var(--accent);
  }
  .wordmark-suffix {
    font-weight:400;
  }
  .site-header nav {
    display:flex;
    gap:32px;
    font-size:13px;
    font-weight:550;
  }
  .header-contact {
    font-size:13px;
  }
  .header-contact span {
    margin-left:16px;
  }
  .hero {
    display:grid;
    grid-template-columns:1fr 260px;
    align-items:center;
    gap:50px;
    padding:76px 0 82px;
  }
  .hero .eyebrow {
    display:flex;
    align-items:center;
    gap:9px;
    color:var(--text-muted);
    margin-bottom:24px;
  }
  .status-dot {
    width:7px;
    height:7px;
    background:var(--accent);
    border-radius:50%;
  }
  .hero h1 {
    font-size:clamp(40px,5.6vw,72px);
    font-weight:550;
    line-height:1.08;
    letter-spacing:-.06em;
  }
  .serif-accent {
    font-family:var(--serif);
    font-style:italic;
    font-weight:400;
    letter-spacing:-.065em;
  }
  .hero-description {
    max-width:510px;
    font-size:16px;
    color:var(--text-muted);
    line-height:1.8;
    margin:24px 0 20px;
  }
  .hero-aside {
    justify-self:end;
    display:grid;
    justify-items:center;
    gap:20px;
    transform:rotate(5deg);
    margin-right:20px;
  }
  .monogram {
    display:grid;
    place-content:center;
    width:180px;
    height:180px;
    border:1px solid var(--illustration-border);
    border-radius:24px;
    background:var(--surface-accent);
    font-family:ui-monospace,monospace;
    font-size:66px;
    font-weight:500;
    letter-spacing:-.1em;
    box-shadow:9px 9px 0 var(--illustration-shadow);
    position:relative;
  }
  .monogram span {
    position:absolute;
    right:33px;
    bottom:20px;
    color:var(--accent);
    font-size:40px;
  }
  .aside-caption {
    font-size:9px;
    font-family:ui-monospace,monospace;
    letter-spacing:.16em;
    color:var(--text-muted);
  }
  .home-intro {
    margin:24px 0;
    font-size:16px;
    font-weight:400;
    line-height:1.6;
    letter-spacing:normal;
    color:var(--text-muted);
  }
  .home-section {
    border-top:1px solid var(--border);
    padding:40px 0 56px;
  }
  .section-heading {
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:24px;
    margin-bottom:28px;
  }
  .section-heading .eyebrow {
    color:var(--text-muted);
    margin-bottom:10px;
  }
  .section-heading h2 {
    font-size:34px;
    font-weight:600;
    letter-spacing:-.045em;
  }
  .section-heading p:not(.eyebrow) {
    margin-top:10px;
    font-size:14px;
    color:var(--text-muted);
  }
  .card-grid {
    display:grid;
    grid-template-columns:repeat(2,minmax(0,1fr));
    gap:22px;
  }
  .visual .card-grid {
    grid-template-columns:repeat(3,minmax(0,1fr));
    gap:34px 24px;
  }
  .archive-callout {
    border-top:1px solid var(--border);
    padding:32px 0 54px;
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:24px;
  }
  .archive-callout p {
    font-family:var(--serif);
    font-size:25px;
    letter-spacing:-.04em;
  }
  .site-footer {
    display:flex;
    flex-wrap:wrap;
    align-items:start;
    justify-content:space-between;
    gap:28px;
    border-top:1px solid var(--border);
    padding:35px 0 30px;
  }
  .site-footer .wordmark {
    font-size:20px;
  }
  .site-footer p {
    font-size:12px;
    color:var(--text-muted);
    margin-top:8px;
  }
  .site-footer nav {
    display:flex;
    flex-wrap:wrap;
    gap:22px;
    font-size:12px;
    padding-top:7px;
  }
  .site-footer small {
    flex-basis:100%;
    font-size:11px;
    color:var(--text-muted);
  }
}
/* Reusable cards, the series banner, archive lists, taxonomy links and 404 layout. */
@layer components {
  .tech-card {
    background:var(--surface);
    border:1px solid var(--border);
    border-radius:7px;
    padding:26px 28px 22px;
    display:flex;
    flex-direction:column;
    transition:border-color .15s;
  }
  .tech-card:hover {
    border-color:var(--border-hover);
  }
  .tech-card-top {
    display:flex;
    align-items:center;
    gap:14px;
    margin-bottom:30px;
  }
  .code-symbol {
    display:grid;
    place-content:center;
    background:var(--surface-accent);
    width:42px;
    height:42px;
    border-radius:8px;
    font-family:ui-monospace,monospace;
    font-size:20px;
    letter-spacing:-.1em;
    color:var(--icon-text);
  }
  .tech-card-top .eyebrow {
    font-size:9px;
    color:var(--text-muted);
  }
  .card-arrow {
    margin-left:auto;
    font-size:22px;
  }
  .card-copy {
    display:flex;
    flex-direction:column;
    flex:1;
  }
  .post-meta {
    display:flex;
    gap:15px;
    align-items:center;
    color:var(--text-muted);
    font-size:10px;
    letter-spacing:.02em;
  }
  .post-meta span::before {
    content:"·";
    margin-right:15px;
  }
  .post-card h2,
  .post-card h3 {
    font-size:24px;
    letter-spacing:-.035em;
    line-height:1.3;
    margin-top:10px;
  }
  .card-description {
    font-size:13px;
    color:var(--text-muted);
    line-height:1.75;
    margin-top:12px;
  }
  .series-pagination {
    display:flex;
    flex-wrap:wrap;
    justify-content:center;
    align-items:center;
    gap:24px;
    margin-top:40px;
  }
  .card-bottom {
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:15px;
    margin-top:auto;
    padding-top:26px;
  }
  .chips {
    display:flex;
    flex-wrap:wrap;
    gap:7px;
  }
  .chips span {
    border:1px solid var(--border);
    border-radius:4px;
    font-size:10px;
    padding:3px 8px;
    color:var(--text-muted);
  }
  .series-strip {
    display:flex;
    align-items:center;
    gap:14px;
    background:var(--surface-accent);
    border-radius:5px;
    padding:16px 20px;
    margin-bottom:28px;
  }
  .series-icon {
    width:34px;
    height:34px;
    border:1px solid var(--icon-border);
    border-radius:50%;
    display:grid;
    place-content:center;
    font-size:12px;
    color:var(--series-icon-text);
  }
  .series-strip strong {
    display:block;
    font-size:13px;
    font-weight:600;
  }
  .series-strip div>span {
    display:block;
    font-size:11px;
    color:var(--text-muted);
  }
  .series-strip a {
    font-size:12px;
    margin-left:auto;
  }
  .series-strip a span {
    margin-left:18px;
  }
  .card-image {
    display:block;
    border-radius:5px;
    overflow:hidden;
    aspect-ratio:1.6;
    background:var(--image-placeholder);
    margin-bottom:17px;
  }
  .card-image img {
    width:100%;
    height:100%;
    object-fit:cover;
    transition:transform .25s;
  }
  .card-image:hover img {
    transform:scale(1.025);
  }
  .game-card h2,
  .game-card h3 {
    font-size:19px;
    line-height:1.4;
    letter-spacing:-.025em;
  }
  .game-card .card-description {
    font-size:12px;
    margin-top:9px;
  }
  .page-heading {
    padding:60px 0 32px;
  }
  .page-heading .eyebrow {
    color:var(--text-muted);
    margin-bottom:20px;
  }
  .page-heading h1 {
    font-size:clamp(38px,5vw,64px);
  }
  .page-heading p:not(.eyebrow) {
    color:var(--text-muted);
    margin-top:18px;
  }
  .listing {
    padding-bottom:70px;
    min-height:65vh;
  }
  .archive-nav {
    display:flex;
    gap:24px;
    flex-wrap:wrap;
    font-size:12px;
    border-bottom:1px solid var(--border);
    padding-bottom:24px;
  }
  .post-list article {
    display:grid;
    grid-template-columns:120px 1fr 20px;
    gap:26px;
    padding:28px 0;
    border-bottom:1px solid var(--border);
  }
  .post-list time {
    font-size:12px;
    color:var(--text-muted);
    padding-top:4px;
  }
  .post-list h2 {
    font-size:23px;
    line-height:1.35;
    letter-spacing:-.03em;
  }
  .post-list p {
    font-size:13px;
    margin-top:9px;
    color:var(--text-muted);
  }
  .taxonomy-list {
    display:flex;
    flex-wrap:wrap;
    gap:12px;
  }
  .taxonomy-list a {
    padding:12px 16px;
    border:1px solid var(--border);
    border-radius:5px;
    font-size:14px;
  }
  .taxonomy-list span {
    color:var(--text-muted);
    margin-left:14px;
  }
  .not-found {
    padding-block:100px;
    min-height:65vh;
  }
  .not-found h1 {
    font-size:60px;
    margin:20px 0;
  }
  .not-found p {
    margin-bottom:20px;
  }
}
/* Markdown output lives under .prose. Scope article rules here so cards are unaffected.
   Images keep authored widths up to the available space; code scrolls inside its block. */
@layer article {
  .article-header {
    max-width:920px;
    padding:52px 0 40px;
  }
  .back-link {
    color:var(--text-muted);
  }
  .article-header h1 {
    font-size:clamp(34px,4.4vw,58px);
    line-height:1.12;
    margin:26px 0 20px;
    letter-spacing:-.045em;
  }
  .article-description {
    font-size:19px;
    color:var(--text-muted);
    max-width:760px;
    line-height:1.65;
  }
  .article-byline {
    display:flex;
    flex-wrap:wrap;
    align-items:center;
    gap:13px;
    font-size:12px;
    color:var(--text-muted);
    margin-top:28px;
  }
  .article-byline img {
    border-radius:50%;
  }
  .article-byline strong {
    color:var(--accent);
  }
  .article-grid {
    display:grid;
    grid-template-columns:minmax(0,760px) minmax(150px,1fr);
    gap:clamp(30px,6vw,88px);
    border-top:1px solid var(--border);
    padding-top:42px;
  }
  .prose {
    font-size:17px;
    line-height:1.85;
    min-width:0;
    overflow-wrap:anywhere;
  }
  .prose p,.prose ul,.prose ol,.prose blockquote,.prose pre,.prose table {
    margin:0 0 1.5em;
  }
  .prose h1,.prose h2,.prose h3,.prose h4 {
    margin:1.7em 0 .7em;
    line-height:1.3;
    letter-spacing:-.03em;
  }
  .prose h2 {
    font-size:29px;
  }
  .prose h3 {
    font-size:23px;
  }
  .prose h4 {
    font-size:19px;
  }
  .prose>:first-child {
    margin-top:0;
  }
  .prose a {
    text-decoration:underline;
    text-decoration-color:var(--link-underline);
    text-underline-offset:3px;
  }
  .prose img {
    margin:28px auto 10px;
    border-radius:3px;
  }
  /* Captions follow an image inside the same Markdown paragraph.
     Do not select paragraphs by em:only-child: it ignores surrounding text nodes,
     so a normal paragraph with one italic phrase would also match. */
  .prose img+em,.prose .image-zoom+em {
    display:block;
    font-size:13px;
    line-height:1.6;
    color:var(--text-muted);
    text-align:center;
    margin-bottom:28px;
  }
  .prose blockquote {
    border-left:3px solid var(--accent);
    padding:8px 22px;
    color:var(--text-muted);
  }
  .prose blockquote p:last-child {
    margin-bottom:0;
  }
  .prose pre {
    background:var(--code-background);
    color:var(--code-text);
    padding:22px;
    border-radius:5px;
    overflow:auto;
    font-size:13px;
    line-height:1.7;
    tab-size:4;
  }
  .prose code {
    font-family:ui-monospace,SFMono-Regular,Consolas,monospace;
    font-size:.85em;
  }
  .prose pre code {
    font-size:inherit;
  }
  .prose :not(pre)>code {
    background:var(--surface-accent);
    padding:2px 5px;
    border-radius:3px;
    box-decoration-break:clone;
  }
  .prose table {
    display:block;
    max-width:100%;
    overflow:auto;
    border-collapse:collapse;
    font-size:14px;
  }
  .prose th,.prose td {
    border:1px solid var(--border);
    padding:8px 14px;
  }
  .prose hr {
    border:0;
    border-top:1px solid var(--border);
    margin:32px 0;
  }
  .prose .right {
    float:right;
    width:min(45%,320px);
    margin:0 0 24px 24px;
  }
  /* Sticky contents list for long desktop articles; responsive rules make it ordinary flow. */
  .article-sidebar {
    align-self:start;
    position:sticky;
    top:30px;
    font-size:12px;
  }
  .toc summary {
    font-size:11px;
    font-weight:650;
    letter-spacing:.08em;
    text-transform:uppercase;
    cursor:pointer;
  }
  .toc nav {
    display:flex;
    flex-direction:column;
    gap:10px;
    border-left:1px solid var(--border);
    padding:0 0 0 16px;
    margin-top:20px;
    max-height:55vh;
    overflow:auto;
  }
  .toc nav a {
    color:var(--text-muted);
    line-height:1.5;
  }
  .toc nav a:hover {
    color:var(--accent);
  }
  .toc .toc-h3 {
    padding-left:10px;
  }
  .toc .toc-h4 {
    padding-left:20px;
  }
  .sidebar-note {
    margin-top:36px;
    border-top:1px solid var(--border);
    padding-top:22px;
  }
  .sidebar-note .eyebrow {
    font-size:9px;
    color:var(--text-muted);
  }
  .sidebar-note p {
    margin:12px 0 6px;
  }
  .sidebar-note a {
    text-decoration:underline;
    text-underline-offset:3px;
  }
  .article-end {
    display:flex;
    flex-wrap:wrap;
    justify-content:space-between;
    gap:24px;
    padding:36px 0 48px;
    margin-top:38px;
    border-top:1px solid var(--border);
  }
  .related {
    border-top:1px solid var(--border);
    padding:30px 0 60px;
  }
  .related>.eyebrow {
    color:var(--text-muted);
    margin-bottom:24px;
  }
  .related-grid {
    display:grid;
    grid-template-columns:repeat(3,minmax(0,1fr));
    gap:30px;
  }
  .related time {
    font-size:11px;
    color:var(--text-muted);
  }
  .related h2 {
    font-size:18px;
    line-height:1.4;
    margin-top:10px;
    letter-spacing:-.02em;
  }
  .about {
    max-width:850px;
    padding-bottom:70px;
  }
  .about>.text-link {
    margin-top:24px;
  }
  .about .prose::after {
    content:"";
    display:table;
    clear:both;
  }
}
/* Viewport overrides: sidebar stacks below 900px; cards become a single column below 600px.
   Print and reduced-motion preferences are handled here too. */
@layer responsive {
  @media(min-width:1500px) {
    .hero {
      padding-block:95px;
    }
    .hero h1 {
      font-size:76px;
    }
  }
  @media(max-width:900px) {
    .hero {
      grid-template-columns:1fr 170px;
      gap:25px;
    }
    .monogram {
      width:140px;
      height:140px;
      font-size:52px;
    }
    .monogram span {
      right:25px;
      bottom:12px;
    }
    .hero-aside {
      margin-right:5px;
    }
    .visual .card-grid {
      grid-template-columns:repeat(2,minmax(0,1fr));
    }
    .article-grid {
      grid-template-columns:minmax(0,1fr);
    }
    .article-sidebar {
      position:static;
      grid-row:1;
    }
    .toc nav {
      display:grid;
      grid-template-columns:1fr 1fr;
      max-height:220px;
    }
    .sidebar-note {
      display:none;
    }
    .header-contact {
      display:none;
    }
    .article-header {
      padding-top:38px;
    }
  }
  @media(max-width:600px) {
    .site-header {
      min-height:100px;
      flex-wrap:wrap;
      justify-content:center;
      gap:10px;
      padding:18px 0;
    }
    .site-header .wordmark {
      font-size:22px;
    }
    .site-header nav {
      justify-content:center;
      gap:25px;
      font-size:12px;
      flex-basis:100%;
    }
    .hero {
      display:block;
      padding:44px 0 46px;
    }
    .hero h1 {
      font-size:44px;
    }
    .hero .eyebrow {
      font-size:9px;
      letter-spacing:.11em;
      margin-bottom:20px;
    }
    .hero-aside {
      display:none;
    }
    .hero-description {
      font-size:14px;
      margin-block:20px;
    }
    .section-heading {
      align-items:flex-start;
      flex-direction:column;
      gap:16px;
    }
    .section-heading h2 {
      font-size:30px;
    }
    .section-heading p:not(.eyebrow) {
      font-size:13px;
    }
    .section-heading .text-link {
      font-size:12px;
    }
    .home-section {
      padding:28px 0 36px;
    }
    .card-grid,.visual .card-grid {
      grid-template-columns:1fr;
      gap:24px;
    }
    .tech-card {
      padding:22px;
    }
    .tech-card-top {
      margin-bottom:24px;
    }
    .post-card h3 {
      font-size:23px;
    }
    .game-card h2,
    .game-card h3 {
      font-size:21px;
    }
    .series-strip {
      padding:14px;
      gap:10px;
      flex-wrap:wrap;
    }
    .series-strip a {
      margin-left:44px;
      font-size:11px;
    }
    .series-strip strong {
      font-size:12px;
    }
    .archive-callout {
      flex-direction:column;
      align-items:start;
      gap:14px;
      padding-bottom:38px;
    }
    .archive-callout p {
      font-size:23px;
    }
    .site-footer {
      gap:22px;
    }
    .site-footer nav {
      gap:18px;
    }
    .page-heading {
      padding-top:38px;
    }
    .post-list article {
      grid-template-columns:1fr 18px;
      gap:8px;
    }
    .post-list time {
      grid-column:1/-1;
    }
    .post-list h2 {
      font-size:20px;
    }
    .archive-nav {
      gap:18px;
    }
    .article-description {
      font-size:16px;
    }
    .article-byline {
      gap:10px;
      font-size:11px;
    }
    .article-grid {
      padding-top:26px;
      gap:30px;
    }
    .prose {
      font-size:16px;
      line-height:1.85;
    }
    .prose h2 {
      font-size:26px;
    }
    .prose pre {
      padding:16px;
      font-size:12px;
    }
    .prose .right {
      float:none;
      width:100%;
      margin:0 auto 24px;
    }
    .toc nav {
      grid-template-columns:1fr;
    }
    .related-grid {
      grid-template-columns:1fr;
      gap:22px;
    }
    .related-grid article+article {
      border-top:1px solid var(--border);
      padding-top:18px;
    }
  }
  @media(prefers-reduced-motion:reduce) {
    *,*::before,*::after {
      transition:none!important;
      scroll-behavior:auto!important;
    }
  }
  @media print {
    .site-header,.site-footer,.article-sidebar,.related,.preview-banner,.article-end {
      display:none;
    }
    .wrap {
      width:100%;
    }
    .article-grid {
      display:block;
    }
    .prose {
      font-size:11pt;
    }
    body {
      background:white;
      color:black;
    }
    .prose pre {
      white-space:pre-wrap;
    }
    .article-header h1 {
      font-size:28pt;
    }
  }
}

@layer article {
  /* The viewer wraps images only after JS loads. Keep the authored image sizing
     and image-adjacent caption styling identical before and after enhancement. */
  .prose .image-zoom {
    display: block;
    max-width: 100%;
    margin: 28px auto 10px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: zoom-in;
  }
  .prose .image-zoom img { margin: 0; }
  .image-zoom:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 5px;
  }
  html.image-viewer-open { overflow: hidden; }
  .image-viewer {
    max-width: calc(100vw - 32px);
    max-height: calc(100dvh - 32px);
    margin: auto;
    padding: 12px;
    border: 0;
    border-radius: 8px;
    background: var(--viewer-background);
    color: var(--viewer-text);
    box-shadow: 0 12px 60px var(--viewer-shadow);
  }
  .image-viewer::backdrop {
    background: var(--viewer-backdrop);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
  .image-viewer-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 12px;
    font-size: 13px;
  }
  .image-viewer-controls a { color: var(--viewer-text); text-decoration: underline; }
  .image-viewer-controls button {
    min-height: 44px;
    padding: 8px 14px;
    border: 1px solid var(--viewer-border);
    border-radius: 4px;
    background: transparent;
    color: var(--viewer-text);
    cursor: pointer;
  }
  .image-viewer-controls :focus-visible { outline: 3px solid var(--viewer-text); outline-offset: 3px; }
  .image-viewer-image {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: calc(100dvh - 180px);
    margin: auto;
    object-fit: contain;
  }
  .image-viewer-caption {
    max-width: 75ch;
    margin: 12px auto 0;
    font-size: 13px;
    text-align: center;
    white-space: normal;
  }
}

/* Printing is intentionally independent of the active screen theme. */
@layer print {
  @media print {
    :root {
      color-scheme: light;
      --background: #fff;
      --surface: #fff;
      --surface-accent: #eee;
      --text: #000;
      --text-muted: #444;
      --border: #bbb;
      --accent: #000;
      --link-underline: #555;
      --code-background: #eee;
      --code-text: #000;
    }
    .image-viewer { display: none; }
  }
}
