/* =========================================================================
   faisal.nyc — "Speed Yellow"
   Design: Porsche Speedgelb as the identity + interaction color, held over a
   quiet warm-paper canvas with near-black ink — the Marco.org reading
   discipline (huge legible serif, generous air, a single confident accent),
   given a louder, more design-literate voice.

   Type:  Space Grotesk (display) · Newsreader (body) · JetBrains Mono (code)
   ========================================================================= */

:root {
  color-scheme: light;

  /* --- Core canvas --- */
  --paper: #fbfaf6;          /* warm off-white, not clinical white */
  --paper-raised: #f4f1e8;   /* faint warm panel */
  --ink: #16140d;            /* warm near-black */
  --ink-soft: #3a362b;       /* body-adjacent */
  --muted: #6b6555;          /* metadata, captions */
  --rule: #e7e1cf;           /* hairline rules */
  --rule-strong: #d8d0b7;

  /* --- Speed Yellow system (Porsche Speedgelb family) --- */
  --speed: #f4d000;          /* primary */
  --speed-bright: #ffdf1f;   /* hover / glow */
  --speed-deep: #b8950a;     /* yellow text on light (AA-safe accent) */
  --speed-ink: #2a2100;      /* ink to sit ON yellow */

  /* --- Complement: desaturated blue-violet (yellow's true opposite) --- */
  --violet: #2e2a4a;         /* visited / secondary structure */
  --violet-soft: #5b5680;
  --violet-tint: #ecebf4;

  /* --- Effects --- */
  --shadow: 0 18px 48px rgba(28, 24, 8, 0.14);
  --shadow-soft: 0 8px 26px rgba(28, 24, 8, 0.10);

  /* --- Type --- */
  --display: "Space Grotesk", "Helvetica Neue", Arial, sans-serif;
  --body: "Newsreader", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --measure: 38rem;          /* reading column */
}

* { box-sizing: border-box; }

html {
  font-size: 19px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

#top { scroll-margin-top: 0; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink-soft);
  font-family: var(--body);
  font-optical-sizing: auto;
  line-height: 1.66;
  font-size: 1.06rem;
  /* subtle warm vignette so the page feels like paper, not a screen */
  background-image:
    radial-gradient(120% 60% at 50% -10%, rgba(244, 208, 0, 0.06), transparent 60%);
  background-repeat: no-repeat;
}

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

/* ---------------------------------------------------------------- Links */
a {
  color: var(--ink);
  text-decoration: none;
  background-image: linear-gradient(var(--speed), var(--speed));
  background-repeat: no-repeat;
  background-position: 0 88%;
  background-size: 100% 0.18em;   /* the yellow "marker" underline */
  transition: background-size 0.18s ease, color 0.18s ease;
}

a:hover,
a:focus-visible {
  color: var(--ink);
  background-size: 100% 0.95em;   /* fills like a highlighter on hover */
  background-position: 0 80%;
}

.post-body a:visited { color: var(--violet); }

/* ------------------------------------------------ Layout & containers */
.site-header,
main {
  width: min(var(--measure), calc(100% - 2.6rem));
  margin-inline: auto;
}

main { padding-bottom: 3.5rem; }

/* ----------------------------------------------------------- Masthead */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem 1.4rem;
  padding: 3.2rem 0 1.6rem;
  margin-bottom: 1.6rem;
  border-bottom: 1px solid var(--rule-strong);
}

.site-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
  background-image: linear-gradient(var(--speed), var(--speed));
  background-repeat: no-repeat;
  background-position: 0 98%;
  background-size: 100% 0.12em;      /* subtle: thin yellow underline mark */
  transition: background-size 0.18s ease;
}

.site-title:hover,
.site-title:focus-visible {
  background-size: 100% 0.35em;
}

nav {
  display: flex;
  align-items: center;
  gap: 1.3rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.site-title::before {
  /* small speed-yellow dot mark, the new subtle wordmark cue */
  content: "";
  display: inline-block;
  width: 0.42rem;
  height: 0.42rem;
  margin-right: 0.5rem;
  vertical-align: 0.12em;
  background: var(--speed);
  border-radius: 50%;
}

nav a {
  color: var(--muted);
  background-size: 100% 0.1em;
  background-position: 0 100%;
  padding-bottom: 0.15em;
}

nav a:hover,
nav a:focus-visible {
  color: var(--ink);
  background-size: 100% 0.55em;
}

/* ----------------------------------------------------------- Headings */
h1, h2, h3 {
  font-family: var(--display);
  color: var(--ink);
  letter-spacing: -0.015em;
  line-height: 1.12;
  font-weight: 560;
}

.post-header h1,
.archive h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.65rem, 1.1rem + 2.4vw, 2.35rem);
}

.post-header h1 a {
  color: var(--ink);
  background-size: 100% 0;          /* title links stay clean until hover */
}

.post-header h1 a:hover,
.post-header h1 a:focus-visible {
  background-size: 100% 0.14em;
  background-position: 0 92%;
}

.post-body h2 { font-size: 1.5rem; margin: 2.2rem 0 0.6rem; }
.post-body h3 { font-size: 1.2rem; margin: 1.8rem 0 0.5rem; }

/* --------------------------------------------------------------- Time */
time {
  display: block;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-style: normal;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ----------------------------------------------------- Post / stream */
.post {
  padding: 1.6rem 0 1.7rem;
  border-bottom: 1px solid var(--rule);
}
.post:last-of-type { border-bottom: none; }

/* the title carries enough presence on its own; trim the leading space its
   large grotesk line-box adds above the first line */
.stream-post .post-header h1,
.single-post .post-header h1 { margin-top: 0; }

.single-post,
.page,
.archive { padding: 0.6rem 0 2.8rem; }

.page h1,
.not-found h1 {
  margin: 0 0 1.2rem;
  font-size: clamp(1.65rem, 1.1rem + 2.4vw, 2.35rem);
}

.post-body { margin-top: 1.4rem; }

.post-body > p:first-of-type {
  /* a gentle lede: slightly larger opening paragraph */
  font-size: 1.12rem;
  color: var(--ink-soft);
}

.post-body p,
.post-body blockquote,
.post-body figure,
.post-body ul,
.post-body ol,
.post-body pre {
  margin: 0 0 1.25rem;
}

.post-body ul,
.post-body ol { padding-left: 1.3rem; }
.post-body li { margin-bottom: 0.4rem; }

/* --------------------------------------------------------- Blockquote */
blockquote {
  margin-inline: 0;
  padding: 0.1rem 0 0.1rem 1.3rem;
  border-left: 3px solid var(--speed);
  color: var(--muted);
  font-family: var(--body);
  font-size: 0.9rem;
  font-style: normal;
  line-height: 1.55;
}

blockquote p:last-child { margin-bottom: 0; }

/* --------------------------------------------------------------- Code */
code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--violet-tint);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

pre {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.55;
  background: var(--ink);
  color: #f4f1e8;
  padding: 1.1rem 1.2rem;
  border-radius: 8px;
  border-left: 4px solid var(--speed);
  overflow-x: auto;
}
pre code { background: none; padding: 0; color: inherit; }

/* --------------------------------------------------------------- Media */
img { max-width: 100%; height: auto; }

figure { margin-inline: 0; }

.feature-image {
  margin: 1.6rem 0 1.8rem;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  position: relative;
}

.feature-image::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 4px;
  background: var(--speed);
}

.feature-image img {
  display: block;
  width: 100%;
  max-height: 380px;
  object-fit: cover;
}

.image-text-link {
  display: inline;
  cursor: zoom-in;
}

/* ----------------------------------------------------------- Lightbox */
.has-image-lightbox { overflow: hidden; }

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1.8rem;
  background: rgba(22, 20, 13, 0.86);
  backdrop-filter: blur(3px);
}

.image-lightbox-frame {
  width: min(940px, 100%);
  max-height: calc(100vh - 3.5rem);
  margin: 0;
  display: grid;
  gap: 0.6rem;
}

.image-lightbox-frame img {
  display: block;
  max-height: calc(100vh - 7.5rem);
  margin-inline: auto;
  border-radius: 6px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.image-lightbox-frame figcaption {
  color: #f4f1e8;
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.4;
  text-align: center;
}

.image-lightbox-frame figcaption a {
  color: var(--speed-bright);
  background: none;
}

.image-lightbox-close {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 2.3rem;
  height: 2.3rem;
  border: none;
  border-radius: 50%;
  background: var(--speed);
  color: var(--speed-ink);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 1.1rem;
  line-height: 1;
  box-shadow: 2px 2px 0 #000;
  transition: transform 0.12s ease;
}
.image-lightbox-close:hover,
.image-lightbox-close:focus-visible {
  transform: translate(-1px, -1px);
  background: var(--speed-bright);
}

/* -------------------------------------------------------- Footnotes */
.footnote-ref,
.footnote-ref-link {
  position: relative;
  top: -0.4em;                 /* lift cleanly without inflating line box */
  font-family: var(--mono);
  font-size: 0.66em;
  font-weight: 600;
  line-height: 0;
  color: var(--speed-deep);
  background: none;
  vertical-align: baseline;
}

.footnote-ref-link {
  margin-left: 0.12em;
  padding: 0.1em 0.32em;
  border-radius: 4px;
  background: var(--violet-tint);
  color: var(--violet);
}

.footnote-ref-link:hover,
.footnote-ref-link:focus-visible {
  background: var(--speed);
  color: var(--speed-ink);
}

.footnote-popover {
  position: absolute;
  z-index: 20;
  max-width: calc(100vw - 1.8rem);
  box-sizing: border-box;
  padding: 0.85rem 1rem 0.9rem;
  border: 1px solid var(--rule-strong);
  border-top: 4px solid var(--speed);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  color: var(--ink-soft);
  font-size: 0.86rem;
  line-height: 1.5;
}

.footnote-popover[aria-hidden="true"] { display: none; }
.footnote-popover p,
.footnote-popover ol,
.footnote-popover ul { margin: 0; }
.footnote-popover a,
.footnotes a {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.footnotes-sep {
  width: 2.2rem;
  margin: 1.8rem 0 0.9rem;
  border: none;
  border-top: 2px solid var(--speed);
}

.footnotes {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.5;
}

.footnotes-list {
  margin: 0;
  padding-left: 1.4rem;
}

/* the footnotes section is the last child of .post-body: kill its trailing
   margin so it doesn't stack with the article's bottom padding */
.post-body > .footnotes:last-child,
.post-body > .footnotes:last-child .footnotes-list,
.post-body > .footnotes:last-child .footnote-item:last-child,
.post-body > .footnotes:last-child .footnote-item:last-child p {
  margin-bottom: 0;
}

.footnote-item {
  margin: 0 0 0.3rem;
  padding-left: 0.2rem;
}

.footnote-item::marker {
  color: var(--speed-deep);
}

.footnote-item p {
  margin: 0;
  overflow-wrap: anywhere;
}

.footnote-backref {
  margin-left: 0.3em;
  color: var(--speed-deep);
  background: none;
  text-decoration: none;
}

.footnote-backref:hover,
.footnote-backref:focus-visible {
  color: var(--ink);
  background: none;
}

.post-footer {
  margin-top: 1.8rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}

.post-top-link {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1;
  color: var(--speed-deep);
  background: none;
  text-decoration: none;
}

.post-top-link-ico {
  flex: 0 0 auto;
  font-style: normal;
  line-height: 1;
}

.post-top-link:hover,
.post-top-link:focus-visible {
  color: var(--ink);
  background: none;
}

/* ----------------------------------------------------------- Archive */
.archive h1 { margin-bottom: 1.4rem; }

.archive ol {
  list-style: none;
  padding: 0;
  margin: 1.6rem 0 0;
}

.archive li {
  display: grid;
  grid-template-columns: 9.5rem 1fr;
  align-items: baseline;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--rule);
}

.archive li time { font-size: 0.7rem; }

.archive li a {
  font-family: var(--display);
  font-size: 1.05rem;
  color: var(--ink);
  background-size: 100% 0;
}
.archive li a:hover,
.archive li a:focus-visible {
  background-size: 100% 0.55em;
}

/* ----------------------------------------------------- Back to top */
/* A continuous blog never shows a footer. Instead, each article ends with a
   small inline up-arrow sitting right after the final sentence's period,
   styled to match the footnote reference glyph: "...lastword. ↑" */
.to-top {
  /* compact end-cap chip: an intentional typographic fin closing the article,
     held to text height and sitting on the baseline */
  /* a clean stroked chevron end-mark: hairline weight to match the serifs,
     Speed-Yellow expressed in the stroke (no heavy fill block), with a
     generous invisible hit-area for tapping */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.85em;
  height: 0.62em;                 /* short: a chevron head occupies the cap zone */
  margin-left: 0.16em;
  vertical-align: baseline;
  position: relative;
  top: -0.04em;                   /* lift onto the cap line */
  color: var(--speed-deep);
  background: none;
  text-decoration: none;
  transition: top 0.16s ease, color 0.16s ease;
}

.to-top-ico {
  display: block;
  width: 0.72em;
  height: 0.48em;
}

.to-top:hover,
.to-top:focus-visible {
  color: var(--ink);
  background: none;
  top: -0.16em;                   /* gentle lift, no chrome */
}

/* ------------------------------------------------------ Responsive */
@media (max-width: 560px) {
  html { font-size: 18px; }

  .footnote-popover {
    position: fixed;
    left: max(0.85rem, env(safe-area-inset-left));
    right: max(0.85rem, env(safe-area-inset-right));
    bottom: calc(0.85rem + env(safe-area-inset-bottom));
    top: auto;
    width: auto;
    max-width: none;
    max-height: min(42vh, 18rem);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 100;
    font-size: 0.82rem;
    line-height: 1.45;
  }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    padding-top: 2.4rem;
  }

  nav { gap: 1rem; }

  .archive li {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }

  .image-lightbox { padding: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
