/* ============================================================
   aryem.dev — Swiss System (International Typographic Style)
   12-column grid, index rails, hairline registers, one red signal.
   ============================================================ */

@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #ffffff;
  --ink: #0a0a0a;
  --body: #222222;
  --muted: #5e5e5e;
  --hair: #e4e4e4;
  --signal: #e0231c;
  --signal-hover: #a8160f;
  --code-bg: #f5f5f5;
  --select: var(--signal);
  --select-ink: #ffffff;

  --font-sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-display: "Archivo", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;

  --shell: 78rem;
  --pad: 2.5rem;
  --gap: 1.5rem;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --paper: #161615;
  --ink: #f5f3ec;
  --body: #d6d4cc;
  --muted: #9a988f;
  --hair: #2e2e2c;
  --signal: #ff4438;
  --signal-hover: #ff6b61;
  --code-bg: #1f1f1d;
  --select-ink: #161615;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--body);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "kern", "liga";
}

::selection { background: var(--select); color: var(--select-ink); }

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.12;
  margin: 2.4rem 0 0.9rem;
}
h1 { font-size: 2.35rem; letter-spacing: -0.035em; line-height: 1.03; margin-top: 0; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.25rem; }
h4, h5, h6 { font-size: 1.05rem; }

/* grotesk display face on labels & wordmark too */
.wordmark, .nav, .rail-label, .content-meta, .post-year,
.tag-link, .pn-label, .site-footer, .toc h3 {
  font-family: var(--font-display);
}

p { margin: 0 0 1rem; }

a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--signal);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 2.5px;
  transition: color 0.15s ease;
}
a:hover { color: var(--signal); }

strong { font-weight: 700; color: var(--ink); }
ul, ol { padding-left: 1.2rem; margin: 0 0 1rem; }
li { margin: 0.15rem 0; }

.content-meta, table, td, th, time, .post-list, .rail-meta {
  font-variant-numeric: tabular-nums;
}

.anchor {
  margin-left: 0.4rem;
  color: var(--muted);
  text-decoration: none;
  opacity: 0;
  font-weight: 400;
  transition: opacity 0.15s ease;
}
h1:hover .anchor, h2:hover .anchor, h3:hover .anchor,
h4:hover .anchor, h5:hover .anchor, h6:hover .anchor { opacity: 1; }

.broken {
  color: var(--muted);
  border-bottom: 1px dotted var(--muted);
  cursor: help;
}

/* ---------- Shared label device (red tick + tracked caps) ---------- */
.rail-label,
.toc-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 700;
  color: var(--ink);
}
.rail-label::before {
  content: "";
  display: block;
  width: 1.6rem;
  height: 2px;
  background: var(--signal);
  margin-bottom: 0.5rem;
}

/* ---------- Masthead (grid-aligned) ---------- */
.masthead {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  align-items: baseline;
  column-gap: var(--gap);
  max-width: var(--shell);
  margin: 0 auto;
  padding: 1.6rem var(--pad) 1.1rem;
  border-bottom: 2px solid var(--ink);
}
.masthead a { text-decoration: none; color: var(--ink); }
.wordmark {
  grid-column: 1 / 4;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.04em;
}
.wordmark:hover { color: var(--signal); }

.nav { grid-column: 4 / 10; display: flex; gap: 1.2rem; }
.nav a {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-weight: 600;
  color: var(--muted);
}
.nav a:hover { color: var(--signal); }

.tools {
  grid-column: 10 / 13;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.search { position: relative; }
.search input {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 0.3rem 0.5rem;
  width: 9rem;
  outline: none;
}
.search input:focus { border-color: var(--signal); }

#search-results {
  position: absolute;
  right: 0;
  top: 2.1rem;
  width: 22rem;
  max-width: 80vw;
  max-height: 24rem;
  overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--ink);
  z-index: 20;
}
#search-results a {
  display: block;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--hair);
  text-decoration: none;
  color: var(--ink);
}
#search-results a:last-child { border-bottom: none; }
#search-results a:hover { background: var(--code-bg); }
#search-results .r-title { font-weight: 600; font-size: 0.9rem; }
#search-results .r-tags {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-top: 0.15rem;
}
#search-results .r-empty { padding: 0.7rem; color: var(--muted); font-size: 0.85rem; }

#theme-toggle {
  font-family: var(--font-sans);
  font-size: 1.1rem;
  line-height: 1;
  background: none;
  border: none;
  color: var(--ink);
  cursor: pointer;
  padding: 0.1rem 0.2rem;
}
#theme-toggle:hover { color: var(--signal); }

/* ---------- Layout grid ---------- */
.layout {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  column-gap: var(--gap);
  max-width: var(--shell);
  margin: 0 auto;
  padding: 3rem var(--pad) 5rem;
}
.layout.article .rail { grid-column: 1 / 4; }
.layout.article .content { grid-column: 4 / 11; }   /* offset, ragged right margin */
.layout.page .content { grid-column: 1 / 9; }        /* left-anchored, asymmetric whitespace */
.content { min-width: 0; }

/* ---------- Index rail ---------- */
.rail {
  position: sticky;
  top: 2rem;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
  padding-top: 0.4rem;
}
.rail-meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--body);
}
.rail-toc ul { list-style: none; padding: 0; margin: 0; font-size: 0.8rem; }
.rail-toc li { margin: 0.25rem 0; }
.rail-toc a { color: var(--muted); text-decoration: none; }
.rail-toc a:hover { color: var(--signal); }
.rail-toc .toc-l3 { padding-left: 0.8rem; }
.rail .tags { margin-top: 0; }

/* ---------- Article metadata ---------- */
.content-meta {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 0.4rem;
}

/* ---------- Tags ---------- */
ul.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  list-style: none;
  padding: 0;
  margin: 0;
}
ul.tags li { margin: 0; }
.tag-link {
  display: inline-block;
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
  color: var(--body);
  border: 1px solid var(--hair);
  padding: 0.16rem 0.5rem;
  text-decoration: none;
}
.tag-link:hover { color: var(--signal); border-color: var(--signal); }
.content > ul.tags { margin-top: 2.5rem; }

/* ---------- Columnar register (generated listings) ---------- */
.post-list {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0 0;
  border-top: 2px solid var(--ink);
}
.post-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1.5rem;
  align-items: baseline;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--hair);
}
.post-list a { font-weight: 600; text-decoration: none; }
.post-list a:hover { color: var(--signal); }
.post-list .content-meta { margin: 0; white-space: nowrap; }

/* ---------- Hand-authored listing pages: ruled register ---------- */
.register h2 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  border-bottom: 2px solid var(--ink);
  padding-bottom: 0.4rem;
  margin: 2.4rem 0 0;
}
.register h2:first-of-type { margin-top: 1.5rem; }
.register > ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.register > ul > li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--hair);
  margin: 0;
}
.register > ul > li a { text-decoration: none; font-weight: 600; }
.register > ul > li a:hover { color: var(--signal); }

/* ---------- Code ---------- */
code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--code-bg);
  padding: 0.1rem 0.3rem;
  border-radius: 0;
}
pre {
  font-family: var(--font-mono);
  background: var(--code-bg);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  line-height: 1.5;
  margin: 1.2rem 0;
}
pre code { background: none; padding: 0; font-size: 0.84rem; }

/* ---------- Tables ---------- */
.table-container, table { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; margin: 1.2rem 0; font-size: 0.92rem; }
th { text-align: left; font-weight: 700; color: var(--ink); border-bottom: 2px solid var(--ink); padding: 0.4rem 0.7rem; }
td { padding: 0.35rem 0.7rem; border-bottom: 1px solid var(--hair); }
tr:last-child td { border-bottom: none; }

/* ---------- Rules, quotes, media ---------- */
hr { border: none; height: 1px; background: var(--ink); opacity: 0.8; margin: 2.4rem 0; }
blockquote {
  margin: 1.2rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--signal);
  color: var(--body);
}
img, video { max-width: 100%; height: auto; border-radius: 0; margin: 1rem 0; }

/* ---------- Footnotes ---------- */
.footnotes { margin-top: 3rem; border-top: 1px solid var(--hair); font-size: 0.9rem; color: var(--muted); }

/* ---------- Footer ---------- */
.site-footer {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 1.5rem var(--pad) 3rem;
  border-top: 1px solid var(--hair);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--muted);
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  :root { --pad: 1.25rem; }
  .masthead {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem 1.1rem;
  }
  .nav { order: 3; flex: 1 1 100%; }
  .layout { display: block; }
  .rail {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 1.2rem 2rem;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--hair);
  }
  .rail-toc { display: none; }
  .search input { width: 7rem; }
  .post-nav a { max-width: 100%; }
}

/* ---------- Skip link & focus ---------- */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  z-index: 100;
  background: var(--ink);
  color: var(--paper);
  padding: 0.5rem 0.9rem;
  text-decoration: none;
  font-size: 0.8rem;
}
.skip-link:focus { left: 0; }

a:focus-visible,
button:focus-visible,
input:focus-visible,
.tag-link:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

/* ---------- Reading progress ---------- */
.progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--signal);
  z-index: 50;
  transition: width 0.05s linear;
}

/* ---------- Active nav ---------- */
.nav a.active {
  color: var(--ink);
  border-bottom: 2px solid var(--signal);
  padding-bottom: 1px;
}

/* ---------- Auto-generated post register ---------- */
.post-register { margin-top: 1.5rem; }
.post-year {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  border-bottom: 2px solid var(--ink);
  padding-bottom: 0.4rem;
  margin: 2.2rem 0 0;
}
.post-register .post-list { margin-top: 0; border-top: none; }

/* ---------- Prev / next ---------- */
.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  margin-top: 3rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--hair);
}
.post-nav a { text-decoration: none; max-width: 48%; }
.post-nav .next { margin-left: auto; text-align: right; }
.pn-label {
  display: block;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.pn-title { font-weight: 600; color: var(--ink); }
.post-nav a:hover .pn-title { color: var(--signal); }

/* ---------- Fuller footer ---------- */
.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
}
.footer-nav { display: flex; gap: 1.1rem; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--signal); }

/* ---------- Lead paragraph ---------- */
.layout.article .content > h1 + p {
  font-size: 1.2rem;
  line-height: 1.55;
  color: var(--body);
  margin-bottom: 1.6rem;
}

/* ---------- Code blocks: header bar with lang + copy ---------- */
.code-wrap { margin: 1.2rem 0; border: 1px solid var(--hair); }
.code-wrap pre { margin: 0; border: none; }
.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0.7rem;
  background: var(--code-bg);
  border-bottom: 1px solid var(--hair);
}
.code-lang,
.code-copy {
  font-family: var(--font-display);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.code-copy { background: none; border: none; cursor: pointer; }
.code-copy:hover,
.code-copy.copied { color: var(--signal); }

/* ---------- Related posts ---------- */
.related { margin-top: 2.8rem; }
.related .rail-label { margin-bottom: 0.4rem; }
.related .post-list { border-top: 2px solid var(--ink); margin-top: 0; }

/* ---------- Search keyboard selection ---------- */
#search-results a.sel { background: var(--code-bg); }
#search-results a.sel .r-title { color: var(--signal); }

/* ---------- Photo gallery (contact sheet) ---------- */
.layout.page .content.wide { grid-column: 1 / 13; }

.gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 1.6rem 0;
}
/* absorbs leftover space on the last row so it isn't stretched */
.gallery::after { content: ""; flex-grow: 9999; }
.shot {
  flex-grow: var(--r, 1);
  flex-basis: calc(var(--r, 1) * 240px);
  overflow: hidden;
  background: var(--code-bg);
}
.shot img {
  display: block;
  width: 100%;
  height: auto;          /* keep aspect ratio — no crop */
  margin: 0;
  vertical-align: bottom;
  transition: opacity 0.2s ease;
}
.shot:hover img { opacity: 0.85; }
.gallery-empty { color: var(--muted); }

@media (max-width: 600px) {
  .shot { flex-basis: calc(var(--r, 1) * 150px); }
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(10, 10, 10, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox[hidden] { display: none; }
.lightbox figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.lightbox img { max-width: 92vw; max-height: 86vh; object-fit: contain; margin: 0; }
.lightbox figcaption {
  margin-top: 0.8rem;
  color: #b8b6ad;
  font-family: var(--font-display);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}
.lightbox button {
  position: absolute;
  background: none;
  border: none;
  color: #f5f3ec;
  cursor: pointer;
  font-size: 2.4rem;
  line-height: 1;
  padding: 0.3rem 0.8rem;
}
.lightbox button:hover { color: var(--signal); }
.lb-close { top: 0.4rem; right: 0.8rem; }
.lb-prev { left: 0.4rem; top: 50%; transform: translateY(-50%); }
.lb-next { right: 0.4rem; top: 50%; transform: translateY(-50%); }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

/* build marker — edit to force a fresh CSS response through the CDN: rev 2 */
