/* Shared by ktesio.dev and hekma.ktesio.dev: fonts, layout and the
   components both sites use (the intersection). A component only one site
   renders lives in that site's own css. Source of truth:
   shared/css/base.css. scripts/sync.py copies it into each site's
   static/css/base.css; edit the source, then run the sync.

   It uses colour tokens only. Each site defines its own palette (--bg, --fg,
   --accent, …) in its static/css/site.css, which loads after this file. */

/* ---------------------------------------------------------------- fonts */
@font-face {
  font-family: "Source Serif 4";
  src: url("/fonts/source-serif-4.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Source Serif 4";
  src: url("/fonts/source-serif-4-italic.woff2") format("woff2");
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Source Code Pro";
  src: url("/fonts/source-code-pro.woff2") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}
/* Fallbacks sized to the web fonts, so the swap barely moves the layout. */
@font-face {
  font-family: "Serif Fallback";
  src: local("Georgia Bold"), local("Georgia-Bold"), local("Georgia");
  font-weight: 700;
  size-adjust: 98%;
  ascent-override: 104%;
  descent-override: 34%;
  line-gap-override: 0%;
}
@font-face {
  font-family: "Mono Fallback";
  src: local("Menlo"), local("DejaVu Sans Mono"), local("Consolas");
  size-adjust: 100%;
  ascent-override: 98%;
  descent-override: 27%;
  line-gap-override: 0%;
}

/* ---------------------------------------------------------------- type tokens */
:root {
  --serif: "Source Serif 4", "Serif Fallback", Georgia, "Times New Roman", serif;
  --mono: "Source Code Pro", "Mono Fallback", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pad: clamp(16px, 4vw, 44px);
  /* The heading ramp: every heading consumes one of these steps (or the
     hero/page clamps), never a fresh size. Declared exceptions:
     .essays--compact titles sit a step down at 1.45rem (essays rules),
     and the docs prose scale (.prose h1/h3–h6 in hekma's docs.css) is
     its own ramp. --r-term is the radius of every terminal surface. */
  --h-card: 1.55rem;
  --h-section: 1.9rem;
  --r-term: 4px;
}

/* ---------------------------------------------------------------- base */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg-2);
  font: 400 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a {
  color: inherit;
}
p {
  margin: 0;
}
code {
  font-family: var(--mono);
}
/* One inline-code treatment, everywhere: the chip. Code inside a <pre> is a
   block and is left alone; the one documented exception is the meta line
   (.meta code), where a chip inside a mono line would be noise. */
:not(pre) > code {
  padding: 0.1em 0.35em;
  border-radius: 3px;
  background: var(--bg-3);
  color: var(--fg);
  font-size: 0.86em;
  overflow-wrap: anywhere;
}
::selection {
  background: color-mix(in srgb, var(--accent) 32%, transparent);
  color: var(--fg);
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.skip {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 10;
  padding: 10px 14px;
  background: var(--fg);
  color: var(--bg);
  font: 600 13px/1 var(--mono);
  text-decoration: none;
}
.skip:focus {
  top: 8px;
}
html:not(.js) .js-only {
  display: none !important;
}

/* ---------------------------------------------------------------- frame */
.frame {
  max-width: 1240px;
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
main {
  flex: 1;
}
/* main is the skip link's programmatic target, not a control: taking
   focus there must not draw a ring around the whole region. */
main:focus-visible {
  outline: none;
}
@media (min-width: 1000px) {
  .frame {
    border-inline: 1px solid var(--line);
  }
}

/* ---------------------------------------------------------------- nav */
.nav {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 22px;
  height: 60px;
  padding: 0 var(--pad);
  border-bottom: 1px solid var(--line);
}
.brand {
  color: var(--fg);
  text-decoration: none;
}
.nav-links {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 22px;
  font: 500 13px/1 var(--mono);
  text-transform: lowercase;
}
.nav-links a {
  color: var(--muted);
  text-decoration: none;
}
.nav-links a:hover,
.nav-links a[aria-current] {
  color: var(--fg);
}
.gh {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
}
.gh .ic {
  color: var(--fg-2);
}
.theme {
  display: flex;
  flex: none;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  overflow: hidden;
}
html:not(.js) .theme {
  display: none;
}
.theme button {
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 500 11.5px/1 var(--mono);
  cursor: pointer;
}
.theme button:hover {
  color: var(--fg);
}
.theme button[aria-pressed="true"] {
  background: var(--fg);
  color: var(--bg);
}
.menu {
  display: none;
}
@media (max-width: 760px) {
  .nav {
    gap: 12px;
  }
  .nav-links {
    display: none;
  }
  .theme {
    margin-left: auto;
  }
  .menu {
    display: block;
    position: relative;
  }
  .menu summary {
    display: grid;
    place-items: center;
    width: 38px;
    height: 34px;
    border: 1px solid var(--line-2);
    border-radius: 4px;
    cursor: pointer;
    list-style: none;
  }
  .menu summary::-webkit-details-marker {
    display: none;
  }
  .menu-bars,
  .menu-bars::before,
  .menu-bars::after {
    display: block;
    width: 16px;
    height: 1.5px;
    background: var(--fg-2);
  }
  .menu-bars {
    position: relative;
  }
  .menu-bars::before,
  .menu-bars::after {
    content: "";
    position: absolute;
    left: 0;
  }
  .menu-bars::before {
    top: -5px;
  }
  .menu-bars::after {
    top: 5px;
  }
  .menu-sheet {
    position: absolute;
    right: 0;
    top: 44px;
    display: flex;
    flex-direction: column;
    min-width: 200px;
    padding: 6px;
    border: 1px solid var(--line-2);
    border-radius: 4px;
    background: var(--bg-2);
    font: 500 14px/1 var(--mono);
  }
  .menu-sheet a {
    padding: 12px 12px;
    color: var(--fg-2);
    text-decoration: none;
    text-transform: lowercase;
  }
  .menu-sheet a:hover,
  .menu-sheet a[aria-current] {
    color: var(--fg);
    background: var(--bg-3);
  }
}

/* ---------------------------------------------------------------- hero */
.hero {
  position: relative;
  overflow: hidden;
  padding: clamp(36px, 6.5vw, 84px) var(--pad) clamp(44px, 6vw, 72px);
  border-bottom: 1px solid var(--line);
}
.hero-in {
  position: relative;
}
.eyebrow {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 18px;
  color: var(--accent);
  font: 500 12.5px/1 var(--mono);
  letter-spacing: 0.14em;
}
.eyebrow-rule {
  width: 32px;
  height: 1px;
  background: currentColor;
}
h1 {
  margin: 0 0 24px;
  color: var(--fg);
  font: 700 clamp(2.35rem, 5.15vw, 4rem)/1.03 var(--serif);
  letter-spacing: -0.021em;
  font-optical-sizing: auto;
}
h1 em {
  color: var(--accent);
  font-style: italic;
  letter-spacing: -0.012em;
}
.lede {
  max-width: 37rem;
  margin: 0 0 32px;
  font-size: 1.075rem;
}
.lede strong {
  color: var(--fg);
  font-weight: 600;
}
.lede a,
.page a {
  color: var(--accent);
  text-underline-offset: 3px;
}
.cmd {
  display: inline-flex;
  align-items: stretch;
  max-width: 100%;
  border: 1px solid var(--line-2);
  border-radius: var(--r-term);
  background: var(--term);
}
.cmd code {
  min-width: 0;
  padding: 16px 18px;
  overflow-x: auto;
  background: transparent;
  color: var(--fg);
  font: 400 14.5px/1.1 var(--mono);
  white-space: nowrap;
  user-select: all;
  scrollbar-width: thin;
}
.cmd-p {
  color: var(--accent);
  user-select: none;
}
.copy {
  flex: none;
  padding: 0 16px;
  /* The widest label ("copied"/"failed": 6 chars, each trailed by
     0.14em of tracking) plus the rail padding and the 1px border sets
     the floor, so flipping the label never changes the width of the
     install box. */
  min-width: calc(6ch + 0.84em + 33px);
  border: 0;
  border-left: 1px solid var(--line-2);
  background: transparent;
  color: var(--muted);
  font: 600 11px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
}
.copy:hover {
  color: var(--fg);
}
.copy.done {
  color: var(--ok);
}
.copy.err {
  color: var(--bad);
}
html:not(.js) .copy {
  display: none;
}
.meta {
  margin: 16px 0 0;
  color: var(--muted);
  font: 400 12.5px/1.7 var(--mono);
}
.meta a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  text-underline-offset: 3px;
}
.meta a:hover {
  text-decoration-color: currentColor;
}
.meta-dash {
  margin: 0 4px;
}
@media (max-width: 560px) {
  .cmd code {
    padding: 14px 14px;
    font-size: 13px;
    line-height: 1.5;
    white-space: normal;
    overflow-wrap: break-word;
  }
  .copy {
    padding: 0 12px;
  }
}
.meta code {
  background: none;
  padding: 0;
  color: var(--fg-2);
  font-size: 1em;
}

/* ---------------------------------------------------------------- stat strip */
.strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 26px var(--pad) 22px;
  border-right: 1px solid var(--line);
  text-decoration: none;
}
.stat:last-child {
  border-right: 0;
}
.stat:hover {
  background: var(--bg-2);
}
.stat b {
  color: var(--fg);
  font: 700 clamp(1.55rem, 2.5vw, 2.15rem)/1 var(--serif);
  letter-spacing: -0.01em;
}
/* Word-valued cells ("MIT · Apache-2.0", "bite 0.5.0") keep the facts on one
   line; numeric cells take the full clamp above. */
.stat--text b {
  font-size: clamp(1.35rem, 2.1vw, 1.85rem);
}
.stat span {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font: 500 11.5px/1.3 var(--mono);
  letter-spacing: 0.08em;
}
.ic {
  flex: none;
  width: 14px;
  height: 14px;
  color: var(--accent);
}
@media (max-width: 860px) {
  .strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stat:nth-child(2n) {
    border-right: 0;
  }
  .stat:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }
}

/* ---------------------------------------------------------------- section labels */
/* The hoisted micro-label every section head uses (.sec-head on ktesio.dev,
   .fig-head on hekma); a site keeps only its spacing delta. */
.label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font: 500 11.5px/1.3 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ---------------------------------------------------------------- feature cards */
.caps {
  border-bottom: 1px solid var(--line);
}
.cap {
  position: relative;
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) minmax(0, 432px);
  gap: 20px 44px;
  padding: 38px var(--pad);
  border-top: 1px solid var(--line);
}
.cap:first-child {
  border-top: 0;
}
.cap:hover {
  background: var(--bg-2);
}
.cap-n {
  color: var(--num);
  font: 700 3rem/0.9 var(--serif);
  letter-spacing: -0.02em;
}
.cap h2 {
  margin: 0 0 12px;
  color: var(--fg);
  font: 700 var(--h-card)/1.2 var(--serif);
  letter-spacing: -0.01em;
}
.cap h2 a {
  text-decoration: none;
}
.cap h2 a::after {
  content: "";
  position: absolute;
  inset: 0;
}
.cap h2 a:focus-visible {
  outline: none;
}
.cap h2 a:focus-visible::after {
  outline: 2px solid var(--focus);
  outline-offset: -4px;
}
.cap-arrow {
  display: inline-block;
  color: var(--accent);
  transition: transform 0.2s ease;
}
.cap:hover .cap-arrow {
  transform: translateX(4px);
}
.cap p {
  max-width: 36rem;
  margin: 0 0 12px;
}
.cap-note {
  color: var(--muted);
  font-size: 0.93rem;
}
@media (max-width: 980px) {
  .cap {
    grid-template-columns: 64px minmax(0, 1fr);
  }
  .cap-n {
    font-size: 2.2rem;
  }
}
@media (max-width: 600px) {
  .cap {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }
}

/* ---------------------------------------------------------------- footer */
.foot {
  padding: 28px var(--pad) 34px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font: 400 12.5px/1.6 var(--mono);
}
.foot-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 26px;
}
.attrib {
  color: var(--fg-2);
}
.foot-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin-left: auto;
}
.foot-links a {
  color: var(--muted);
  text-decoration: none;
}
.foot-links a:hover {
  color: var(--fg);
}
.fine {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 24px;
  margin-top: 18px;
  color: var(--dim);
  font-size: 11.5px;
}
.fine a {
  color: var(--muted);
}
@media (max-width: 760px) {
  .foot-links {
    margin-left: 0;
  }
}

/* ---------------------------------------------------------------- writing, 404 */
.page {
  min-height: 60vh;
  padding: clamp(36px, 6.5vw, 84px) var(--pad) clamp(48px, 7vw, 96px);
}
.page h1 {
  max-width: 19ch;
  font-size: clamp(2.2rem, 4.8vw, 3.5rem);
}
.essays {
  margin: 44px 0 0;
  padding: 0;
  border-top: 1px solid var(--line);
  list-style: none;
}
.essays li {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 8px 32px;
  padding: 28px 0;
  border-bottom: 1px solid var(--line);
}
.essays time {
  grid-row: span 3;
  color: var(--muted);
  font: 500 12.5px/2 var(--mono);
}
.essays h2,
.essays h3 {
  margin: 0;
  color: var(--fg);
  font: 700 var(--h-card)/1.2 var(--serif);
}
.essays h2 a,
.essays h3 a {
  color: var(--fg);
  text-decoration: none;
}
.essays h2 a:hover,
.essays h3 a:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
}
.essays h2 span,
.essays h3 span {
  color: var(--accent);
}
/* The home section lists its essays one level under a section h2, so the
   titles sit one size step down: the one heading-ramp exception (see the
   type tokens). */
.essays--compact h2,
.essays--compact h3 {
  font-size: 1.45rem;
}
.essays p {
  max-width: 40rem;
}
.essay-by {
  color: var(--dim);
  font: 400 12.5px/1.6 var(--mono);
}
@media (max-width: 700px) {
  .essays li {
    grid-template-columns: minmax(0, 1fr);
  }
  .essays time {
    grid-row: auto;
  }
}

/* The placeholder chip rendered by the shared ph/email_link components. */
.ph {
  padding: 0 0.3em;
  border: 1px dashed var(--line-2);
  border-radius: 3px;
  color: var(--muted);
  font: 500 0.88em/1.6 var(--mono);
}

/* ---------------------------------------------------------------- phones */
/* Nothing under 12px on a phone. Each site's css extends this block with
   the classes only it renders. */
@media (max-width: 600px) {
  .fine,
  .foot,
  .stat span,
  .label-row,
  .meta,
  .copy,
  .theme button,
  .essays time,
  .essay-by {
    font-size: 12px;
  }
}

/* ---------------------------------------------------------------- forced colors */
/* Windows forced-colors mode replaces the palette with system colours:
   keep the focus ring's outline and give it a fallback colour, and mark
   the pressed theme button with a border and weight -- the inverted fill
   that marks it elsewhere disappears in this mode. */
@media (forced-colors: active) {
  :focus-visible {
    outline-color: Highlight;
  }
  .theme button[aria-pressed="true"] {
    border: 1px solid CanvasText;
    padding: 7px 9px;
    font-weight: 600;
  }
}

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