/*
 * patshead theme
 * Palette is light by default and solarized-dark when the reader asks for a
 * dark scheme. Every token is declared once through light-dark() and resolved
 * by the root color-scheme, so there is no second copy of the dark palette to
 * keep in sync. `data-theme` on <html> is the manual override; without it the
 * OS preference wins.
 */
:root {
  color-scheme: light dark;
  --bg: light-dark(#ffffff, #002b36);
  --surface: light-dark(#ffffff, #073642);
  --well: light-dark(#f3f4f6, #073642);
  --code-bg: light-dark(#f6f7f9, #073642);
  --ink: light-dark(#1c1e21, #93a1a1);
  --heading: light-dark(#1c1e21, #eee8d5);
  --summary: light-dark(#3c4043, #839496);
  --muted: light-dark(#5f6368, #657b83);
  --accent: light-dark(#0b5fff, #268bd2);
  --rule: light-dark(#e3e5e8, #073642);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { background: var(--rule); }

/* ---------- site header ---------- */
header.site {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
header.site .masthead { display: flex; align-items: center; gap: .9rem; }
header.site h1 { margin: 0; font-size: 1.9rem; letter-spacing: -0.02em; }
header.site h1 a { color: var(--heading); }
header.site p { margin: .35rem 0 0; color: var(--muted); }
/* Both head variants exist because the header toggle can disagree with the OS
   scheme, and a <picture> media query only sees the OS. */
.site-head { display: none; }
.site-head--light { display: block; }
:root[data-theme="dark"] .site-head--light { display: none; }
:root[data-theme="dark"] .site-head--dark { display: block; }
/* readers without JavaScript never get data-theme, so the OS preference still has to pick */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .site-head--light { display: none; }
  :root:not([data-theme="light"]) .site-head--dark { display: block; }
}
.site-head img { display: block; width: auto; height: 72px; }
header.site .iconrow { display: flex; align-items: center; gap: 1.1rem; }
.iconrow a, .iconrow button { display: block; color: var(--muted); }
.iconrow a:hover, .iconrow button:hover { color: var(--accent); }
.iconrow svg { width: 24px; height: 24px; fill: currentColor; display: block; }
.theme-toggle { padding: 0; border: 0; background: none; cursor: pointer; }
/* only one of the two icons is ever shown; the class pair outranks `.iconrow svg` */
.iconrow .icon-sun { display: none; }
:root[data-theme="dark"] .iconrow .icon-sun { display: block; }
:root[data-theme="dark"] .iconrow .icon-moon { display: none; }

/* the hamburger only exists below the desktop breakpoint; the sidebar is always open on desktop */
.nav-toggle { display: none; }

/* ---------- page frame ---------- */
.layout { display: flex; gap: 2.5rem; max-width: 1200px; margin: 0 auto; padding: 0 1.5rem 3rem; }
.content { flex: 1; min-width: 0; }

/* ---------- sidebar ---------- */
aside.sidebar { flex: 0 0 280px; }
.sidebar section {
  border: 1px solid var(--rule);
  background: var(--surface);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  margin-bottom: 1.25rem;
}
.sidebar h2 {
  margin: 0 0 .6rem;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { margin: .45rem 0; font-size: .9rem; line-height: 1.35; }
.sidebar li.current a { color: var(--heading); font-weight: 600; }

/* ---------- landing page: alternating photo/summary rows ---------- */
article.post {
  display: flex;
  gap: 1.75rem;
  align-items: center;
  padding: 1.6rem 0;
  border-bottom: 1px solid var(--rule);
}
article.post:first-child { padding-top: 0; }
article.post:last-child { border-bottom: 0; }
/* alternating rows, but only when there is a thumbnail to alternate with */
article.post:nth-child(even):not(.no-thumb) { flex-direction: row-reverse; }

.post .thumb { flex: 0 0 36%; margin: 0; }
/* letterbox instead of cover: screenshots center-crop into mush at thumbnail size */
.post .thumb img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: contain;
  background: var(--well);
  border-radius: 10px;
  display: block;
}
/* a dedicated thumbnail image is composed for the slot, so it may fill it */
.post .thumb--exact img { object-fit: cover; }
.post .body { min-width: 0; }
.post.no-thumb .body { max-width: 720px; }
.post .date { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.post h2 { margin: .25rem 0 .45rem; font-size: 1.35rem; line-height: 1.25; letter-spacing: -0.01em; }
.post h2 a { color: var(--heading); }
.post .summary { margin: 0 0 .75rem; color: var(--summary); font-size: .95rem; }
.post a.more { font-weight: 600; font-size: .95rem; }

/* ---------- pagination ---------- */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  font-size: .9rem;
}
.pagination .pages { color: var(--muted); }
/* hidden rather than absent, so the row does not jump between pages */
.pagination .disabled { visibility: hidden; }

/* ---------- post and page body ---------- */
/* measure capped for readability: ~72ch beats filling the whole content column */
.entry { max-width: 720px; }
.entry-header { padding: 1.5rem 0 1.75rem; }
.entry-header .date { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.entry-header h1 { margin: .4rem 0 0; font-size: 2.1rem; line-height: 1.2; letter-spacing: -0.02em; }
/* headings are self-links so readers can copy a URL pointing at a section */
.entry-header h1 a, .entry-content h1 a, .entry-content h2 a, .entry-content h3 a, .entry-content h4 a { color: var(--heading); }
.entry-header h1 a:hover, .entry-content h1 a:hover, .entry-content h2 a:hover,
.entry-content h3 a:hover, .entry-content h4 a:hover { color: var(--accent); text-decoration: none; }
.entry-content { font-size: 1.02rem; line-height: 1.65; }
.entry-content p { margin: 0 0 1.2rem; }
.entry-content h1, .entry-content h2 { margin: 2.5rem 0 1rem; font-size: 1.45rem; letter-spacing: -0.01em; color: var(--heading); }
.entry-content h3 { margin: 2rem 0 .85rem; font-size: 1.2rem; color: var(--heading); }
.entry-content h4 { margin: 1.75rem 0 .75rem; font-size: 1.05rem; color: var(--heading); }
.entry-content ul, .entry-content ol { padding-left: 1.4rem; margin: 0 0 1.2rem; }
.entry-content li { margin: .35rem 0; }
.entry-content hr { border: 0; border-top: 1px solid var(--rule); margin: 2rem 0; }
.entry-content strong { color: var(--heading); }

/* images read better slightly narrower than the text measure */
.entry-content img { max-width: 100%; height: auto; }
/* the figure carries the width so the caption's edges line up with the photo
   instead of with the text column */
.entry-content figure { width: 94%; margin: 0 auto 1.75rem; }
.entry-content figure img { width: 100%; display: block; border-radius: 10px; background: var(--rule); }
.entry-content figure a { display: block; }
/* images that never became a figure keep their intrinsic size, capped above */
.entry-content figcaption {
  margin: .5rem auto 0;
  max-width: 60ch;
  font-size: .84rem;
  line-height: 1.45;
  color: var(--muted);
  text-align: center;
  text-wrap: balance;
}
.entry-content a img:hover { opacity: .92; }

/* ---------- legacy photo galleries (the Octopress `div.images` blocks) ---------- */
/* a grid, because eight stacked photos of the same monitor stand read as a wall */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .5rem;
}
.gallery-item {
  display: block;
  overflow: hidden;
  border-radius: 8px;
  background: var(--well);
}
.entry-content .gallery-item img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 0;
  display: block;
}
.gallery-item:hover img { opacity: .88; }

/* ---------- photo viewer: one dialog, filled in by patshead.js ---------- */
.lightbox {
  width: 100vw;
  /* dvh keeps the photo clear of the browser chrome on phones */
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #eee8d5;
  overflow: hidden;
}
/* solid, not dimmed: at .9 the page text behind reads through the caption */
.lightbox::backdrop { background: #002b36; }
.lightbox-image {
  position: absolute;
  top: 3rem;
  left: 3.5rem;
  width: calc(100% - 7rem);
  height: calc(100% - 7.5rem);
  margin: 0;
  /* the letterbox bands must show the backdrop, not the global img background */
  background: transparent;
  object-fit: contain;
}
.lightbox-bar {
  position: absolute;
  top: .75rem;
  right: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: .85rem;
}
.lightbox-count { color: #839496; font-variant-numeric: tabular-nums; }
.lightbox-close,
.lightbox-prev,
.lightbox-next {
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, .45);
  color: #eee8d5;
  cursor: pointer;
  line-height: 1;
}
.lightbox-close { width: 2rem; height: 2rem; font-size: 1.4rem; }
.lightbox-prev,
.lightbox-next {
  position: absolute;
  top: 50%;
  width: 3rem;
  height: 3rem;
  font-size: 1.8rem;
  transform: translateY(-50%);
}
.lightbox-prev { left: .75rem; }
.lightbox-next { right: .75rem; }
.lightbox-caption {
  position: absolute;
  right: 0;
  bottom: 1.1rem;
  left: 0;
  margin: 0;
  padding: 0 3rem;
  font-size: .85rem;
  text-align: center;
  color: #93a1a1;
}
.lightbox.single .lightbox-prev,
.lightbox.single .lightbox-next { display: none; }

/* inline code */
.entry-content code {
  background: var(--well);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: .1em .35em;
  font-size: .9em;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* terminal output and code are everywhere in these posts; scroll, never wrap */
.entry-content pre {
  margin: 0 0 1.5rem;
  padding: .9rem 1.1rem;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  font-size: .85rem;
  line-height: 1.5;
}
/* titles above code blocks, emitted by _plugins/patshead_code_fences.rb for the
   posts that used a multi-word fence info string */
.entry-content .code-caption {
  margin: 0 0 .35rem;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .78rem;
  color: var(--muted);
}
.entry-content .code-caption code { font-size: inherit; }
.entry-content .highlight { margin: 0 0 1.5rem; }
.entry-content .highlight pre { margin: 0; }
.entry-content pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
  font-family: inherit;
  white-space: pre;
}

/* rouge tokens, mapped onto the solarized accents for both schemes */
.entry-content .highlight .c, .entry-content .highlight .c1, .entry-content .highlight .cm,
.entry-content .highlight .c9 { color: light-dark(#8b949e, #586e75); font-style: italic; }
.entry-content .highlight .k, .entry-content .highlight .kd, .entry-content .highlight .kn,
.entry-content .highlight .kr { color: light-dark(#0a7d3e, #859900); }
.entry-content .highlight .s, .entry-content .highlight .s1, .entry-content .highlight .s2,
.entry-content .highlight .sb, .entry-content .highlight .se, .entry-content .highlight .sh,
.entry-content .highlight .sx { color: light-dark(#1a7f74, #2aa198); }
.entry-content .highlight .m, .entry-content .highlight .mi, .entry-content .highlight .mf,
.entry-content .highlight .mh, .entry-content .highlight .il { color: light-dark(#b9308a, #d33682); }
.entry-content .highlight .nf, .entry-content .highlight .nc, .entry-content .highlight .nn { color: light-dark(#0b5fff, #268bd2); }
.entry-content .highlight .nb, .entry-content .highlight .bp { color: light-dark(#7a5c00, #b58900); }
.entry-content .highlight .nt, .entry-content .highlight .na { color: light-dark(#0b5fff, #268bd2); }
.entry-content .highlight .err { color: light-dark(#c9252d, #dc322f); }

/* blockquotes */
.entry-content blockquote {
  margin: 0 0 1.5rem;
  padding: .25rem 0 .25rem 1.1rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.entry-content blockquote p:last-child { margin-bottom: 0; }

/* footnote references and the trailing footnote list */
.entry-content sup { font-size: .75em; line-height: 0; }
.entry-content a.reversefootnote { margin-left: .35rem; text-decoration: none; }
.entry-content .footnotes {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: .9rem;
  color: var(--muted);
}
.entry-content .footnotes ol { margin-bottom: 0; }
.entry-content .footnotes li { margin-bottom: .6rem; }

/* tables: specs and comparisons, wrapped for horizontal scroll by patshead.js */
.table-scroll { overflow-x: auto; margin-bottom: 1.5rem; }
.entry-content table { border-collapse: collapse; font-size: .9rem; min-width: 520px; width: 100%; }
.entry-content th, .entry-content td { border: 1px solid var(--rule); padding: .5rem .75rem; text-align: left; vertical-align: top; }
.entry-content th { background: var(--well); color: var(--heading); }

/* embedded players and demos */
.entry-content iframe { width: 100%; max-width: 100%; border: 1px solid var(--rule); border-radius: 10px; }
.entry-content iframe.embed { height: 600px; margin-bottom: .25rem; background: #fff; }

.entry-content ul.related li { margin: .4rem 0; }

/* ---------- previous/next post ---------- */
.post-nav { display: flex; gap: 1rem; margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
.post-nav a {
  flex: 1 1 0;
  display: block;
  padding: .85rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--surface);
}
.post-nav a.next { text-align: right; }
.post-nav .label {
  display: block;
  margin-bottom: .25rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}
.post-nav .title { display: block; font-weight: 600; line-height: 1.3; color: var(--heading); }

/* ---------- related posts ---------- */
.related-posts { margin-top: 2rem; }
.related-posts h2 { margin: 0 0 .6rem; font-size: 1.1rem; color: var(--heading); }
.related-posts ul.related { margin: 0; padding-left: 1.15rem; }
.related-posts ul.related li { margin: .35rem 0; line-height: 1.4; }
.related-more { margin-top: .7rem; }
.related-more summary {
  cursor: pointer;
  font-size: .9rem;
  font-weight: 600;
  color: var(--muted);
}
.related-more summary:hover { color: var(--ink); }

/* ---------- archives ---------- */
.archive-year h2 { margin: 2rem 0 .75rem; }
.archive-year h2:first-child { margin-top: 0; }
.archive-year ul { list-style: none; margin: 0; padding: 0; }
.archive-year li { display: flex; gap: .75rem; margin: .35rem 0; line-height: 1.4; }
.archive-year .date { flex: 0 0 3.2rem; padding-top: .1em; font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

/* ---------- footer ---------- */
footer.site {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  border-top: 1px solid var(--rule);
  text-align: center;
  font-size: .85rem;
  color: var(--muted);
}

/* ---------- tablet: sidebar collapses behind a hamburger, rows stay side-by-side ---------- */
@media (max-width: 1100px) {
  .nav-toggle {
    display: block;
    margin: 0 1.5rem 1rem;
    padding: .55rem 1rem;
    font: inherit;
    font-weight: 600;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: 8px;
    cursor: pointer;
  }
  /* column layout with order:-1 so the opened menu lands right under the hamburger, not after all the posts */
  .layout { display: flex; flex-direction: column; }
  aside.sidebar { display: none; order: -1; padding: 0 1.5rem; margin-bottom: 1.5rem; }
  aside.sidebar.open { display: block; }
  .sidebar section { max-width: 560px; }
  article.post { gap: 1.5rem; }
  .post h2 { font-size: 1.2rem; }
}

/* ---------- phone: rows condense into single-column cards ---------- */
@media (max-width: 700px) {
  header.site { padding-top: 1.75rem; }
  .content { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
  article.post, article.post:nth-child(even):not(.no-thumb) {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0 0 1.25rem;
    border: 1px solid var(--rule);
    border-radius: 12px;
    overflow: hidden;
    background: var(--surface);
  }
  .post .thumb img { border-radius: 0; }
  .post .body { padding: 1rem 1.25rem 0; }
  .post.no-thumb .body { max-width: none; }
  .post a.more { display: inline-block; margin-bottom: .25rem; }
  /* the phone menu keeps Recent Posts and Categories; the link sections are desktop/tablet */
  .sidebar .sidebar-extra { display: none; }
  .site-head img { height: 56px; }
  .entry-header h1 { font-size: 1.6rem; }
  .entry-content iframe.embed { height: 420px; }
  .post-nav { flex-direction: column; }
  .post-nav a.next { text-align: left; }
  .lightbox-image { top: 3rem; left: .75rem; width: calc(100% - 1.5rem); height: calc(100% - 7.5rem); }
  .lightbox-prev,
  .lightbox-next { width: 2.5rem; height: 2.5rem; font-size: 1.4rem; }
  .lightbox-caption { padding: 0 1rem; }
}
