/* ericr.org — listing paper, navy ink, and one Commodore 64. */

/* ------------------------------------------------------------ tokens */

:root {
  --paper: #eef1ea;
  --paper-raised: #f7f9f3;
  --ink: #1a2038;
  --ink-soft: #505774;
  --rule: #cbd2c5;
  --accent: #3b30a6;          /* Commodore blue, for links and small signals */
  --number: #9a3b22;

  --bar-green: #d8e7d0;       /* green-bar listing paper */
  --bar-white: #f6f8f1;
  --string: #2c6a3c;

  --c64-bezel: #2a2b34;
  --c64-border: #7c70da;
  --c64-screen: #40318d;
  --c64-text: #aaa1f3;

  --font-display: "Archivo", "Helvetica Neue", Helvetica, sans-serif;
  --font-body: "Newsreader", "Iowan Old Style", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", monospace;
  --font-pixel: "Press Start 2P", "IBM Plex Mono", monospace;

  --measure: 41rem;
  --wide: 72rem;
  --gutter: clamp(1rem, 4vw, 2.5rem);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #131729;
    --paper-raised: #1a1f36;
    --ink: #e3e5ef;
    --ink-soft: #a2a7c2;
    --rule: #2c3252;
    --accent: #b1a8ff;
    --number: #f0a07f;
    --bar-green: #1b2a27;
    --bar-white: #182032;
    --string: #97d7a6;
    --c64-bezel: #0b0d18;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #131729;
  --paper-raised: #1a1f36;
  --ink: #e3e5ef;
  --ink-soft: #a2a7c2;
  --rule: #2c3252;
  --accent: #b1a8ff;
  --number: #f0a07f;
  --bar-green: #1b2a27;
  --bar-white: #182032;
  --string: #97d7a6;
  --c64-bezel: #0b0d18;
  color-scheme: dark;
}

/* ------------------------------------------------------------ base */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.1875rem;
  line-height: 1.6;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; display: block; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

.skip-link {
  position: absolute; left: 1rem; top: -4rem;
  background: var(--ink); color: var(--paper);
  padding: 0.5rem 1rem; font-family: var(--font-display); z-index: 10;
}
.skip-link:focus { top: 1rem; }

main, .site-header, .site-footer {
  width: min(100% - 2 * var(--gutter), var(--wide));
  margin-inline: auto;
}

/* ------------------------------------------------------------ header */

.site-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1.4rem 1.6rem;
  margin-bottom: clamp(1.5rem, 4vw, 3rem);
}

/* A row of tractor-feed holes under the masthead. */
.site-header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 10px;
  background: radial-gradient(circle, var(--rule) 0 2.6px, transparent 3.1px) 0 50% / 16px 10px repeat-x;
}

.wordmark {
  font-family: var(--font-display);
  font-stretch: 125%;
  font-weight: 900;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: clamp(0.75rem, 2.5vw, 1.75rem);
  font-family: var(--font-display);
  font-stretch: 105%;
  font-weight: 550;
  font-size: 0.98rem;
}
.site-nav a { color: var(--ink); text-decoration: none; padding-block: 0.25rem; }
.site-nav a:hover,
.site-nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--accent); }

.theme-toggle {
  display: grid; place-items: center;
  width: 2.1rem; height: 2.1rem;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper-raised);
  color: var(--ink);
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--ink-soft); }
.theme-toggle svg { width: 16px; height: 16px; fill: currentColor; shape-rendering: crispEdges; }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

/* ------------------------------------------------------------ shared type */

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.section-heading {
  margin: 0 0 1.5rem;
  padding-top: 0.6rem;
  border-top: 2px solid var(--ink);
  font-family: var(--font-display);
  font-stretch: 112%;
  font-weight: 650;
  font-size: 1rem;
  color: var(--ink);
}

.button {
  display: inline-block;
  padding: 0.6rem 1.1rem;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-display);
  font-stretch: 108%;
  font-weight: 650;
  font-size: 0.95rem;
  text-decoration: none;
  border-radius: 3px;
}
.button:hover { background: var(--accent); color: #fff; }

/* ------------------------------------------------------------ the Commodore 64 */

.c64 {
  container-type: inline-size;
  padding: clamp(0.6rem, 2.2cqi, 1.1rem);
  background: var(--c64-bezel);
  border-radius: 1.4rem;
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.08),
    0 1.5rem 3rem -1.5rem rgb(20 20 50 / 0.55);
}

.c64-screen {
  position: relative;
  overflow: hidden;
  padding: 1.2cqi 0;
  background: var(--c64-screen);
  border: solid var(--c64-border);
  border-width: 5.5cqi 6cqi;
  border-radius: 0.9rem;
  color: var(--c64-text);
  font-family: var(--font-pixel);
  font-size: max(2.05cqi, 6.5px);
  line-height: 1.3;
  text-transform: uppercase;
  box-shadow: inset 0 0 4cqi rgb(10 5 40 / 0.55);
}

/* Scanlines and a little CRT glow. */
.c64-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 45%, rgb(255 255 255 / 0.07), transparent 65%),
    repeating-linear-gradient(to bottom, transparent 0 2px, rgb(0 0 0 / 0.09) 2px 3px);
}

.c64-line {
  display: block;
  min-height: 1.3em;
  padding-inline: 0.2em;
  white-space: pre;
  overflow: hidden;
  color: inherit;
  text-decoration: none;
}

.c64-rev { background: var(--c64-text); color: var(--c64-screen); box-shadow: 0 0.15em 0 var(--c64-text), 0 -0.15em 0 var(--c64-text); }

a.c64-file { cursor: pointer; }
a.c64-file:hover,
a.c64-file:focus-visible {
  background: var(--c64-text);
  color: var(--c64-screen);
  outline: none;
}

.c64-cursor {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: top;
  background: currentColor;
  animation: blink 1.1s steps(1) infinite;
}

.c64-caption {
  margin: 0.8rem 0.4rem 0;
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: #b9bccb;
}

@keyframes blink { 50% { opacity: 0; } }
@keyframes appear { from { opacity: 0; } }
@keyframes type { from { max-width: 0; } to { max-width: calc(var(--n) * 1em); } }

@media (prefers-reduced-motion: no-preference) {
  html:not(.booted) .c64-screen .c64-line { animation: appear 1ms linear var(--t, 0ms) both; }
  .c64-typed span { display: inline-block; overflow: hidden; vertical-align: top; }
  html:not(.booted) .c64-typed span { animation: type var(--d) steps(var(--n), end) var(--t) backwards; }
}

@media (prefers-reduced-motion: reduce) {
  .c64-cursor { animation: none; }
}

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

.home-top {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 4rem);
  align-items: center;
  margin-bottom: clamp(3rem, 7vw, 5.5rem);
}

.intro-avatar {
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 50%;
  margin-bottom: 1.25rem;
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--c64-border);
}

.intro-title {
  margin: 0 0 0.9rem;
  font-family: var(--font-display);
  font-stretch: 122%;
  font-weight: 850;
  font-size: clamp(2.2rem, 4.2vw, 3.2rem);
  line-height: 1;
  letter-spacing: -0.025em;
}

.intro p { margin: 0 0 0.9rem; color: var(--ink); }
.intro p:last-child { margin-bottom: 0; }

.latest { margin-bottom: clamp(3rem, 7vw, 5rem); }

.feature {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: center;
}

.feature .hero img { border-radius: 4px; }

.feature-title {
  margin: 0.6rem 0 0.9rem;
  font-family: var(--font-display);
  font-stretch: 115%;
  font-weight: 800;
  font-size: clamp(1.8rem, 3.4vw, 2.7rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.feature-title a, .entry-title a { color: var(--ink); text-decoration: none; }
.feature-title a:hover, .entry-title a:hover { text-decoration: underline; text-decoration-color: var(--accent); }

.feature-summary { margin: 0 0 1.4rem; font-size: 1.15rem; color: var(--ink-soft); }

.entries { list-style: none; margin: 0; padding: 0; }

.entry {
  display: grid;
  grid-template-columns: 9.5rem minmax(0, 1fr) 12rem;
  gap: 1.5rem;
  align-items: start;
  padding-block: 1.6rem;
  border-top: 1px solid var(--rule);
}
.entry:first-child { border-top: 0; padding-top: 0; }

.entry-date {
  padding-top: 0.3rem;
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.entry-title {
  margin: 0 0 0.4rem;
  font-family: var(--font-display);
  font-stretch: 110%;
  font-weight: 720;
  font-size: 1.4rem;
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.entry-summary { margin: 0 0 0.35rem; color: var(--ink-soft); font-size: 1.05rem; line-height: 1.5; }
.entry-reading { margin: 0; font-family: var(--font-display); font-size: 0.85rem; color: var(--ink-soft); }
.entry-thumb { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 3px; }

/* ------------------------------------------------------------ article */

.post, .page, .tag-page, .not-found {
  display: grid;
  grid-template-columns: minmax(0, var(--measure));
  justify-content: center;
}

.post-header { margin-bottom: 2rem; }

.post-dirline {
  margin: 0 0 1.4rem;
  font-family: var(--font-pixel);
  font-size: 0.66rem;
  line-height: 1.6;
  color: var(--accent);
  white-space: nowrap;
}

.post-title {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-stretch: 118%;
  font-weight: 830;
  font-size: clamp(2.3rem, 6vw, 4rem);
  line-height: 0.98;
  letter-spacing: -0.028em;
  text-wrap: balance;
}

.post-dek {
  margin: 0 0 1.3rem;
  font-size: 1.35rem;
  line-height: 1.45;
  font-style: italic;
  color: var(--ink-soft);
}

.post .hero {
  width: min(100vw - 2 * var(--gutter), var(--wide));
  justify-self: center;
  margin: 0 0 clamp(2rem, 5vw, 3.5rem);
}
.post .hero img { width: 100%; border-radius: 4px; }

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

.prose > * { margin-top: 0; }
.prose p { margin-bottom: 1.2em; }
.prose > p:first-child::first-letter {
  float: left;
  margin: 0.06em 0.1em 0 0;
  font-family: var(--font-display);
  font-stretch: 125%;
  font-weight: 900;
  font-size: 4.1em;
  line-height: 0.8;
  color: var(--accent);
}
.page .prose > p:first-child::first-letter { all: unset; }

.prose h2, .prose h3 {
  font-family: var(--font-display);
  font-stretch: 112%;
  line-height: 1.15;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.prose h2 { margin: 2.2em 0 0.7em; font-size: 1.65rem; font-weight: 760; }
.prose h3 { margin: 1.8em 0 0.5em; font-size: 1.25rem; font-weight: 700; }

.prose ul, .prose ol { padding-left: 1.3em; margin-bottom: 1.3em; }
.prose li { margin-bottom: 0.45em; }
.prose li::marker { color: var(--accent); }
.prose ul li::marker { content: "▪  "; font-size: 0.9em; }

.prose strong { font-weight: 650; }

.prose blockquote {
  margin: 1.8em 0;
  padding-left: 1.2em;
  border-left: 3px solid var(--c64-border);
  font-style: italic;
  color: var(--ink-soft);
}

.prose img { border-radius: 4px; margin-block: 1.8em; }
.prose p > img:only-child { margin-block: 0.4em; }

.prose .video { margin: 1.8em 0; }
.prose .video video {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4px;
  background: var(--c64-bezel);
}
.prose .video figcaption {
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.prose :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  padding: 0.08em 0.32em;
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  overflow-wrap: anywhere;
}

.prose table {
  width: 100%;
  margin: 1.6em 0;
  border-collapse: collapse;
  font-family: var(--font-display);
  font-size: 0.95rem;
  line-height: 1.4;
}
.prose th, .prose td { text-align: left; padding: 0.6rem 0.8rem 0.6rem 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.prose th { font-weight: 650; border-bottom: 2px solid var(--ink); }
.prose td code { font-size: 0.9em; }

/* ------------------------------------------------------------ green-bar listings */

.listing { margin: 2em -1.25rem; }

.listing figcaption {
  margin: 0 0 0.4rem 2.6rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.listing-paper {
  --lh: 1.6rem;
  position: relative;
  padding: var(--lh) 2.6rem;
  background: repeating-linear-gradient(
    to bottom,
    var(--bar-green) 0 calc(var(--lh) * 2),
    var(--bar-white) calc(var(--lh) * 2) calc(var(--lh) * 4)
  );
  border-radius: 2px;
  box-shadow: 0 1px 0 var(--rule), 0 14px 24px -20px rgb(20 24 48 / 0.45);
}

/* Sprocket holes and perforations down each edge. */
.listing-paper::before,
.listing-paper::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1.7rem;
  background: radial-gradient(circle, var(--paper) 0 0.28rem, transparent 0.3rem) 50% calc(var(--lh) / 2) / 100% var(--lh) repeat-y;
}
.listing-paper::before { left: 0; border-right: 1px dashed color-mix(in srgb, var(--ink) 18%, transparent); }
.listing-paper::after { right: 0; border-left: 1px dashed color-mix(in srgb, var(--ink) 18%, transparent); }

.listing pre {
  margin: 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: var(--lh);
  tab-size: 4;
  color: var(--ink);
  scrollbar-width: thin;
}
.listing code { font: inherit; background: none; padding: 0; }

/* Syntax colors: mostly ribbon ink, with weight doing most of the work. */
.hljs-keyword, .hljs-built_in, .hljs-type, .hljs-meta .hljs-keyword { color: var(--accent); font-weight: 600; }
.hljs-title, .hljs-title.function_, .hljs-title.class_ { font-weight: 600; }
.hljs-string, .hljs-regexp, .hljs-char { color: var(--string); }
.hljs-number, .hljs-literal, .hljs-symbol { color: var(--number); }
.hljs-comment, .hljs-quote { color: var(--ink-soft); font-style: italic; }
.hljs-attr, .hljs-variable, .hljs-params { color: var(--ink); }
.hljs-meta { color: var(--ink-soft); }

/* ------------------------------------------------------------ timeline */

.timeline { list-style: none; margin: 1.5em 0 2em; padding: 0; }

.timeline li {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr);
  gap: 0 1.25rem;
}

.timeline-year {
  padding-top: 0.15rem;
  font-family: var(--font-display);
  font-stretch: 115%;
  font-weight: 750;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-align: right;
}

.timeline li p {
  position: relative;
  margin: 0 !important;
  padding: 0 0 1.3rem 1.4rem;
  border-left: 2px solid var(--rule);
  font-size: 1.05rem;
  line-height: 1.5;
}
.timeline li:last-child p { border-left-color: transparent; }

/* A single square pixel marks each year. */
.timeline li p::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 0.45rem;
  width: 10px;
  height: 10px;
  background: var(--c64-border);
}
.timeline li:last-child p::before { background: var(--accent); }

.about-photo {
  float: right;
  width: 44%;
  margin: 0.35rem 0 1rem 1.75rem !important;
  border-radius: 4px;
}

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

.post-footer { margin-top: 2.5rem; }

.tag-list { list-style: none; display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0; margin: 0 0 2.5rem; }
.tag-list a {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--ink-soft);
  text-decoration: none;
}
.tag-list a:hover { border-color: var(--accent); color: var(--accent); }

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  padding-top: 1.25rem;
  border-top: 2px solid var(--ink);
}
.post-nav a {
  display: block;
  font-family: var(--font-display);
  font-stretch: 108%;
  font-weight: 650;
  font-size: 1.05rem;
  line-height: 1.25;
  color: var(--ink);
  text-decoration: none;
}
.post-nav a:hover { color: var(--accent); }
.post-nav span { display: block; margin-bottom: 0.3rem; font-weight: 450; font-size: 0.85rem; color: var(--ink-soft); }
.post-nav-newer { grid-column: 2; text-align: right; }

/* ------------------------------------------------------------ 404 */

.not-found .c64 { margin-bottom: 2rem; }
.not-found .c64-screen { font-size: max(3.2cqi, 8px); }

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

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 1rem 2.5rem;
  margin-top: clamp(4rem, 9vw, 7rem);
  padding-block: 2rem 3rem;
  border-top: 2px solid var(--ink);
  font-family: var(--font-display);
  font-size: 0.88rem;
  color: var(--ink-soft);
}
.footer-ready {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 0.75rem;
  line-height: 1;
  color: var(--accent);
}
.footer-ready .c64-cursor { margin-left: 0.2em; }
.footer-text { flex: 1 1 24rem; }
.footer-text p { margin: 0 0 0.5rem; max-width: 40rem; }
.footer-text a { color: var(--ink); margin-right: 1.1rem; }

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

@media (max-width: 60rem) {
  .home-top { grid-template-columns: minmax(0, 1fr); }
  .intro { order: -1; }
  .intro-avatar { float: left; width: 4.25rem; height: 4.25rem; margin: 0 1rem 0.5rem 0; }
  .feature { grid-template-columns: minmax(0, 1fr); }
  .entry { grid-template-columns: minmax(0, 1fr) 9rem; gap: 0.35rem 1.25rem; }
  .entry-date { grid-column: 1 / -1; padding-top: 0; }
}

@media (max-width: 36rem) {
  body { font-size: 1.125rem; }
  .site-nav a[href="/feed.xml"] { display: none; }
  .entry { grid-template-columns: minmax(0, 1fr); }
  .entry-thumb { display: none; }
  .listing { margin-inline: calc(-1 * var(--gutter)); }
  .listing-paper { padding-inline: 2.1rem; border-radius: 0; }
  .listing-paper::before, .listing-paper::after { width: 1.3rem; }
  .listing figcaption { margin-left: 2.1rem; }
  .about-photo { float: none; width: 100%; margin: 0 0 1.5rem !important; }
  .timeline li { grid-template-columns: 4.75rem minmax(0, 1fr); gap: 0 1rem; }
  .timeline-year { font-size: 0.9rem; }
  .post-nav { grid-template-columns: 1fr; }
  .post-nav-newer { grid-column: 1; text-align: left; }
}
