/* zapolskii.com — Direction B, "Quant terminal".
   System fonts only, no external requests, no build step. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;

  --bg: #f6f2ed;
  --bg-2: #efe9e1;
  --ink: #121b3a;
  --ink-2: #424b65;
  --ink-3: #5a6379;
  --rule: #ddd4c9;
  --rule-2: #bfb4a6;
  --accent: #94540c;
  --accent-hover: #7a4508;
  --accent-ink: #ffffff;
  --accent-soft: rgb(148 84 12 / .07);
  --header-bg: rgb(246 242 237 / .86);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  /* 4px-based spacing scale */
  --s1: .25rem;
  --s2: .5rem;
  --s3: .75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;
  --s8: 4rem;

  --gutter: clamp(1rem, 4.5vw, 3rem);
  --max: 76rem;
  --section-y: clamp(4rem, 2.5rem + 6vw, 8.5rem);
  --header-h: 4.25rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --bg-2: #0f1528;
    --ink: #ece6df;
    --ink-2: #aeb5c4;
    --ink-3: #8a93a7;
    --rule: #20293f;
    --rule-2: #38445f;
    --accent: #e8aa5a;
    --accent-hover: #f2c07e;
    --accent-ink: #140d04;
    --accent-soft: rgb(232 170 90 / .07);
    --header-bg: rgb(11 16 32 / .82);
  }
}

/* ---------- 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(--ink);
  font: 400 1.0625rem/1.65 var(--sans);
  overflow-wrap: break-word;
  text-rendering: optimizeLegibility;
}

@media (prefers-color-scheme: dark) {
  body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
}

img, svg { display: block; max-width: 100%; }
h1, h2, h3, p, ol, ul, figure { margin: 0; }
ol[role="list"], ul[role="list"] { list-style: none; padding: 0; }

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: .22em;
}

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

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

.sr-only {
  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;
  top: var(--s3);
  left: var(--gutter);
  z-index: 100;
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: var(--s3) var(--s4);
  background: var(--accent);
  color: var(--accent-ink);
  font: 600 .875rem/1 var(--mono);
  text-decoration: none;
  transform: translateY(-200%);
}
.skip:focus { transform: none; }

.wrap {
  width: 100%;
  max-width: calc(var(--max) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Shared mono metadata voice */
.eyebrow, .index, .nav a, .brand-mark, .brand-tag, .stat-k, .stat-v, figcaption,
.service-i, .keys, .log-head, .log-date, .log-pub, .tags, .log-foot, .btn, .foot {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* ---------- Header ---------- */
.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  column-gap: var(--s6);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s3);
  min-height: 3.75rem;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .02em;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-size: .9375rem; font-weight: 600; }
.brand-tag { display: none; font-size: .6875rem; color: var(--ink-3); letter-spacing: .02em; }

.nav {
  flex: 1 0 calc(100% + 2 * var(--gutter));
  margin-inline: calc(-1 * var(--gutter));
  border-top: 1px solid var(--rule);
}
.nav ul { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.nav li + li { border-left: 1px solid var(--rule); }

.nav a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 2.875rem;
  padding-inline: var(--s1);
  color: var(--ink-2);
  font-size: .6875rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-decoration: none;
  transition: color .15s ease, background-color .15s ease;
}
.nav a:hover { color: var(--ink); background: var(--accent-soft); }
.nav-i { display: none; color: var(--accent); }

@media (min-width: 720px) {
  .site-header { position: sticky; top: 0; z-index: 50; }
  @supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .site-header {
      background: var(--header-bg);
      -webkit-backdrop-filter: saturate(1.4) blur(12px);
      backdrop-filter: saturate(1.4) blur(12px);
    }
  }
  .bar { flex-wrap: nowrap; }
  .brand { min-height: var(--header-h); }
  .nav { flex: 0 1 auto; margin: 0; border: 0; }
  .nav ul { display: flex; gap: var(--s1); }
  .nav li + li { border: 0; }
  .nav a { min-height: 2.75rem; padding-inline: var(--s3); font-size: .75rem; }
  .nav-i { display: inline; }
  [id] { scroll-margin-top: calc(var(--header-h) + var(--s4)); }
}

@media (min-width: 1100px) {
  .brand-tag { display: block; }
}

/* ---------- Buttons ---------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  margin-top: var(--s6);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .625rem;
  min-height: 3rem;
  padding: var(--s3) 1.25rem;
  border: 1px solid transparent;
  border-radius: 2px;
  font-size: .875rem;
  font-weight: 500;
  line-height: 1.25;
  text-decoration: none;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { border-color: var(--ink-3); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink); background: var(--accent-soft); }

.btn-arrow { display: inline-block; transition: transform .2s ease; }
.btn-primary:hover .btn-arrow { transform: translateX(3px); }
.btn-ghost:hover .btn-arrow { transform: translateY(2px); }
.btn-mail span { overflow-wrap: anywhere; }

.icon {
  flex: none;
  width: 1.125rem;
  height: 1.125rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linejoin: round;
}
.icon-fill { fill: currentColor; stroke: none; }

@media (max-width: 479px) {
  .actions .btn { width: 100%; }
}

/* ---------- Hero ---------- */
.hero {
  padding-block: clamp(3rem, 1.5rem + 6vw, 7.5rem) clamp(3.5rem, 2rem + 5vw, 6.5rem);
}

.hero-grid {
  display: grid;
  gap: clamp(2.5rem, 6vw, 5rem);
}

.eyebrow {
  color: var(--ink-2);
  font-size: .75rem;
  letter-spacing: .08em;
  line-height: 1.6;
  text-transform: uppercase;
}
.prompt { margin-right: .35em; color: var(--accent); font-weight: 700; letter-spacing: 0; }

h1 {
  margin-top: var(--s5);
  font-size: clamp(2.375rem, 1.35rem + 4.2vw, 4.5rem);
  font-weight: 600;
  line-height: 1.03;
  letter-spacing: -.032em;
  text-wrap: balance;
}

.hero-sub {
  max-width: 36rem;
  margin-top: var(--s5);
  color: var(--ink-2);
  font-size: clamp(1.0625rem, 1rem + .35vw, 1.25rem);
  line-height: 1.6;
}

.portrait { width: 100%; max-width: 22rem; }

/* Photo framed with registration ticks at the four corners */
.frame {
  --t: 14px;
  --c: var(--accent);
  padding: var(--s3);
  background:
    linear-gradient(var(--c), var(--c)) 0 0 / var(--t) 1px,
    linear-gradient(var(--c), var(--c)) 0 0 / 1px var(--t),
    linear-gradient(var(--c), var(--c)) 100% 0 / var(--t) 1px,
    linear-gradient(var(--c), var(--c)) 100% 0 / 1px var(--t),
    linear-gradient(var(--c), var(--c)) 0 100% / var(--t) 1px,
    linear-gradient(var(--c), var(--c)) 0 100% / 1px var(--t),
    linear-gradient(var(--c), var(--c)) 100% 100% / var(--t) 1px,
    linear-gradient(var(--c), var(--c)) 100% 100% / 1px var(--t);
  background-repeat: no-repeat;
}
.frame img {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--bg-2);
  box-shadow: 0 0 0 1px var(--rule-2);
}

.portrait figcaption {
  display: flex;
  justify-content: space-between;
  gap: var(--s4);
  margin-top: var(--s2);
  padding-inline: var(--s3);
  color: var(--ink-3);
  font-size: .6875rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.fig-k { color: var(--accent); letter-spacing: .08em; text-transform: uppercase; }

@media (min-width: 800px) {
  .hero-grid {
    grid-template-columns: minmax(0, 7fr) minmax(0, 4fr);
    align-items: end;
  }
  .portrait { max-width: 25rem; justify-self: end; }
}

/* ---------- Stats strip ---------- */
.stats {
  background: var(--bg-2);
  border-block: 1px solid var(--rule);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--rule);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  padding: clamp(1.5rem, 1rem + 2vw, 2.5rem) clamp(.875rem, 2.5vw, 2rem);
  background: var(--bg-2);
}
.stat:nth-child(odd) { padding-left: 0; }

.stat-k {
  color: var(--ink-3);
  font-size: .6875rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.stat-v {
  margin-top: var(--s2);
  color: var(--ink);
  font-size: clamp(2.75rem, 1.6rem + 4.4vw, 5rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -.05em;
}
.stat-u { margin-left: .04em; color: var(--accent); }
.stat-l {
  max-width: 22ch;
  color: var(--ink-2);
  font-size: .9375rem;
  line-height: 1.45;
}

@media (min-width: 960px) {
  .stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat:nth-child(odd) { padding-left: clamp(.875rem, 2.5vw, 2rem); }
  .stat:first-child { padding-left: 0; }
}

/* ---------- Sections ---------- */
.section {
  padding-block: var(--section-y);
  border-top: 1px solid var(--rule);
}
.stats + .section { border-top: 0; }

.section-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  row-gap: var(--s5);
}

.index {
  display: flex;
  align-items: center;
  gap: var(--s3);
  color: var(--ink-2);
  font-size: .75rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.index::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.index-n { color: var(--accent); }

h2 {
  max-width: 24ch;
  font-size: clamp(1.75rem, 1.15rem + 2.4vw, 3rem);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -.025em;
  text-wrap: balance;
}

.lede {
  max-width: 60ch;
  margin-top: var(--s4);
  color: var(--ink-2);
  font-size: clamp(1.0625rem, 1rem + .3vw, 1.1875rem);
}

.prose {
  display: grid;
  gap: 1.25rem;
  max-width: 64ch;
  margin-top: var(--s6);
  color: var(--ink-2);
  font-size: clamp(1.0625rem, 1rem + .25vw, 1.15rem);
}
.prose a { color: var(--ink); text-decoration-color: var(--accent); }
.prose a:hover { color: var(--accent); }
.note { padding-left: var(--s4); border-left: 2px solid var(--accent); }

@media (min-width: 960px) {
  .section-grid {
    grid-template-columns: minmax(0, 3fr) minmax(0, 9fr);
    column-gap: clamp(2.5rem, 5vw, 5rem);
    row-gap: clamp(2.5rem, 4vw, 4rem);
  }
  .index { grid-column: 1; grid-row: 1; align-self: baseline; }
  .body { grid-column: 2; grid-row: 1; align-self: baseline; }
  .log-wrap { grid-column: 1 / -1; }

  .section-grid--fig { grid-template-rows: auto 1fr; }
  .section-grid--fig .body { grid-row: 1 / span 2; }
  .section-grid--fig .tail { grid-column: 1; grid-row: 2; align-self: end; margin: 0; }
}

/* ---------- About: left-tail figure ---------- */
.tail { max-width: 20rem; margin-top: var(--s5); }
.tail svg { width: 100%; height: auto; overflow: visible; }
.tail path { fill: none; vector-effect: non-scaling-stroke; }
.tail .tail-area { fill: var(--accent); opacity: .28; }
.tail-axis { stroke: var(--rule-2); stroke-width: 1; }
.tail-mean { stroke: var(--rule-2); stroke-dasharray: 2 4; }
.tail-curve { stroke: var(--ink); stroke-width: 1.5; stroke-linejoin: round; }
.tail-cut { stroke: var(--accent); stroke-dasharray: 3 3; }
.tail-dot { fill: var(--accent); }
.tail figcaption {
  margin-top: var(--s4);
  color: var(--ink-3);
  font-size: .75rem;
  line-height: 1.55;
}

/* ---------- Services ---------- */
.services {
  display: grid;
  margin-top: clamp(2rem, 4vw, 3rem);
  border-top: 1px solid var(--rule);
}

.service {
  display: flex;
  flex-direction: column;
  gap: .625rem;
  padding-block: 1.75rem;
  border-bottom: 1px solid var(--rule);
}
.service-i { color: var(--accent); font-size: .75rem; letter-spacing: .06em; }
.service h3 {
  font-size: 1.1875rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -.01em;
}
.service p { color: var(--ink-2); }
.service .keys {
  margin-top: auto;
  padding-top: var(--s2);
  color: var(--ink-3);
  font-size: .75rem;
  letter-spacing: .02em;
}

@media (min-width: 640px) {
  .services { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .service { padding: var(--s6) var(--s6) 2.25rem 0; }
  .service:nth-child(even) { padding-inline: var(--s6) 0; border-left: 1px solid var(--rule); }
}

/* ---------- Writing log ---------- */
.log-head { display: none; }
.log { border-top: 1px solid var(--rule-2); }

.log-row {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "date pub"
    "title title"
    "tags tags";
  gap: var(--s2) var(--s4);
  align-items: baseline;
  padding-block: 1.25rem;
  border-bottom: 1px solid var(--rule);
  transition: background-color .15s ease;
}

.log-date {
  grid-area: date;
  color: var(--ink-3);
  font-size: .75rem;
  letter-spacing: .02em;
}
.log-pub {
  grid-area: pub;
  justify-self: end;
  color: var(--ink-2);
  font-size: .75rem;
}

.log-title {
  grid-area: title;
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: -.005em;
  text-wrap: pretty;
}
.log-title a { text-decoration: none; transition: color .15s ease; }
.log-title a::after { content: ""; position: absolute; inset: 0; }
.log-title a:focus-visible { outline: none; }
.log-title a:focus-visible::after { outline: 2px solid var(--accent); outline-offset: -2px; }
.log-row:hover { background: var(--accent-soft); }
.log-row:hover .log-title a { color: var(--accent); }

.tags {
  grid-area: tags;
  display: flex;
  flex-wrap: wrap;
  gap: .375rem;
}
.tags li {
  padding: .3125rem .5rem;
  border: 1px solid var(--rule-2);
  border-radius: 2px;
  color: var(--ink-2);
  font-size: .75rem;
  line-height: 1;
  white-space: nowrap;
}

.log-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2) var(--s5);
  margin-top: var(--s3);
  color: var(--ink-3);
  font-size: .75rem;
}
.log-count { letter-spacing: .1em; text-transform: uppercase; }
.more {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 2.75rem;
  color: var(--ink);
  font-size: .8125rem;
  text-decoration: underline;
  text-decoration-color: var(--accent);
}
.more:hover { color: var(--accent); }

@media (min-width: 640px) {
  .log-row {
    grid-template-columns: 6.5rem auto minmax(0, 1fr);
    grid-template-areas:
      "date title title"
      ". pub tags";
    column-gap: var(--s5);
    padding-inline: var(--s3);
  }
  .log-pub { justify-self: start; }
  .log-foot { padding-inline: var(--s3); }
}

@media (min-width: 1180px) {
  .log-head,
  .log-row {
    grid-template-columns: 6.5rem minmax(0, 1fr) 10rem 15rem;
    column-gap: var(--s5);
    padding-inline: var(--s3) 2.75rem;
  }
  .log-head {
    display: grid;
    padding-block: var(--s3);
    color: var(--ink-3);
    font-size: .6875rem;
    letter-spacing: .1em;
    text-transform: uppercase;
  }
  .log-row {
    grid-template-areas: "date title pub tags";
    padding-block: 1.125rem;
  }
  .log-date { font-size: .8125rem; }
  .log-pub { font-size: .8125rem; }
  .log-row::after {
    content: "↗";
    content: "↗" / "";
    position: absolute;
    pointer-events: none;
    top: 1.1rem;
    right: var(--s4);
    color: var(--accent);
    font-family: var(--mono);
    opacity: 0;
    transform: translate(-3px, 3px);
    transition: opacity .15s ease, transform .2s ease;
  }
  .log-row:hover::after,
  .log-row:focus-within::after { opacity: 1; transform: none; }
}

@media (min-width: 1320px) {
  .log-head,
  .log-row { grid-template-columns: 6.5rem minmax(0, 1fr) 10rem 17rem; }
}

/* ---------- Contact ---------- */
.contact { background: var(--bg-2); }

.display {
  max-width: none;
  font-size: clamp(2.75rem, 1.4rem + 6vw, 6rem);
  line-height: .98;
  letter-spacing: -.045em;
}
.cursor {
  display: inline-block;
  width: .36em;
  height: .72em;
  margin-left: .1em;
  background: var(--accent);
}
.contact .lede { max-width: 42rem; margin-top: var(--s5); }

/* ---------- Footer ---------- */
.site-footer {
  background: var(--bg-2);
  border-top: 1px solid var(--rule);
}

.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4) var(--s6);
  padding-block: var(--s5);
  color: var(--ink-3);
  font-size: .75rem;
  letter-spacing: .02em;
}

.social { display: flex; align-items: center; gap: var(--s1); }
.social a {
  display: grid;
  place-items: center;
  min-width: 2.75rem;
  height: 2.75rem;
  border: 1px solid transparent;
  color: var(--ink-2);
  text-decoration: none;
  transition: color .15s ease, border-color .15s ease;
}
.social a:hover { color: var(--accent); border-color: var(--rule-2); }
.social svg { width: 1.125rem; height: 1.125rem; fill: currentColor; }
.social .to-top {
  display: inline-flex;
  gap: .375rem;
  margin-left: var(--s2);
  padding-inline: var(--s3);
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* ---------- Motion & print ---------- */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media print {
  .site-header, .skip, .actions, .social { display: none; }
  body, .stats, .contact, .site-footer { background: #fff; color: #000; }
  .section { padding-block: 2rem; }
}
