/* =====================================================================
   maneet.dev — "The Margin"
   One stylesheet for every page. Hand-written, no framework.

   The one rule behind the layout: everything vertical is a multiple of
   one grid square (--square, 24px). Text lines, headings, margins and
   drawings all land on the ruled lines of the paper.
   ===================================================================== */


/* ---------- 1. TOKENS: every colour, size and spacing value lives here ---------- */
:root {
  /* paper and ink */
  --paper: #f7f2e5;          /* warm off-white page */
  --ink: #1c1b18;            /* near-black body text */
  --ink-soft: #5a564b;       /* captions and small labels */
  --rust: #a8391f;           /* marks only: margin rule, numbers, one underline, dots */

  /* the grid lines (pale blue, drawn behind the text) */
  --grid-minor: rgba(70, 120, 170, 0.16);
  --grid-major: rgba(70, 120, 170, 0.34);

  /* the grid itself */
  --square: 24px;            /* one small square; all vertical rhythm is a multiple of this */
  --major: 120px;            /* a heavy line every 5 squares */
  --line-offset: 18px;       /* pushes the ruled lines down so text sits ON them, not between */

  /* where the margin rule and the text column start (changed for small screens below) */
  --rule-x: 96px;            /* position of the rust margin rule */
  --column-left: 144px;      /* left edge of the text column */
  --gutter: 24px;            /* space kept free on the right */
  --column-width: 624px;     /* widest the text column gets */

  /* type: two system font stacks, nothing downloaded */
  --font-draft: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --font-body: "Iowan Old Style", Charter, Georgia, "DejaVu Serif", serif;
}

/* Small screens: pull the rule and the text close to the left edge. */
@media (max-width: 720px) {
  :root {
    --rule-x: 24px;
    --column-left: 48px;
  }
}


/* ---------- 2. BASE: reset and body text ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: var(--square);    /* one line of text = one grid square */
}

p {
  margin: 0 0 var(--square);
  max-width: 65ch;               /* keeps lines short so the grid shows either side */
}

a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  text-decoration-thickness: 2px;
}

/* Keyboard focus: a thick, high-contrast outline on everything focusable. */
a:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}


/* ---------- 3. PAPER: the grid and the rust margin rule ---------- */
/* .page wraps the whole site. It is the sheet of paper. */
.page {
  position: relative;
  isolation: isolate;            /* keeps the grid and rule safely behind the content */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* The grid: two weights of line (small squares and heavy lines), drawn with gradients. */
.page::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(to right, var(--grid-major) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-major) 1px, transparent 1px),
    linear-gradient(to right, var(--grid-minor) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-minor) 1px, transparent 1px);
  background-size:
    var(--major) var(--major),
    var(--major) var(--major),
    var(--square) var(--square),
    var(--square) var(--square);
  background-position: 0 var(--line-offset);
}

/* The margin rule: one vertical rust line down the left, like an exercise book. */
.page::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--rule-x);
  width: 2px;
  background: var(--rust);
}

/* Content sits above the rule so a heading can cross it. */
.site-header,
.site-main,
.site-footer {
  position: relative;
  z-index: 1;
}

.site-main {
  flex: 1;
}

/* The text column. Everything readable lives in one of these. */
.column {
  margin-left: var(--column-left);
  margin-right: var(--gutter);
  max-width: var(--column-width);
}

/* Once per page load, the grid fades in. Skipped for reduced motion. */
@keyframes grid-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  .page::before {
    animation: grid-in 0.8s ease-out both;
  }
}


/* ---------- 4. HEADER AND NAV: one nav, same on every page ---------- */
.site-header {
  padding-top: var(--square);
  height: calc(var(--square) * 3);          /* 72px = 3 squares */
}

.site-header-inner {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
}

.wordmark {
  font-family: var(--font-draft);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.02em;
}

/* Logo: one grid square (24px), sitting on the same line as the wordmark text. */
.logo {
  vertical-align: middle;
  margin-right: 8px;
}

.nav-list {
  display: flex;
  gap: 0 18px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-list a {
  display: block;                           /* gives each link a full 24px-high target */
  font-family: var(--font-draft);
  font-size: 14px;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  line-height: 22px;
}

.nav-list a:hover {
  border-bottom-color: var(--ink-soft);
}

/* The page you are on gets a solid ink underline and bold text. */
.nav-list a[aria-current="page"] {
  font-weight: 700;
  border-bottom-color: var(--ink);
}

/* Narrow screens: wordmark on one row, links on the next (two rows = 4 squares). */
@media (max-width: 560px) {
  .site-header {
    height: calc(var(--square) * 4);
  }
  .site-header-inner {
    display: block;
  }
}

/* Skip link: invisible until a keyboard user tabs to it first. */
.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 10;
  padding: 0 12px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-draft);
  font-size: 14px;
}

.skip-link:focus {
  top: 8px;
}


/* ---------- 5. HERO: the top block of each page ---------- */
.hero {
  position: relative;
  padding-top: calc(var(--square) * 3);
  padding-bottom: var(--square);
}

/* The page title. On wide screens it steps left across the margin rule:
   the one deliberate "look at me" move on the site. */
.hero-title {
  margin: 0;
  font-family: var(--font-draft);
  font-size: 48px;
  line-height: calc(var(--square) * 2);
  font-weight: 700;
  letter-spacing: -0.03em;
}

@media (min-width: 900px) {
  .hero-title {
    margin-left: calc(var(--square) * -3);
  }
}

@media (max-width: 720px) {
  .hero-title {
    font-size: 36px;
  }
}

/* The role line under the name, with the only rust underline on the page. */
.hero-role {
  display: inline-block;
  margin: 0 0 var(--square);
  font-family: var(--font-draft);
  font-size: 15px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-bottom: 2px solid var(--rust);
  line-height: 22px;
}

/* A short line set large, two grid lines per row of text. */
.pull {
  margin: 0 0 var(--square);
  font-size: 24px;
  font-style: italic;
  line-height: calc(var(--square) * 2);
}

@media (max-width: 720px) {
  .pull {
    font-size: 20px;
    line-height: var(--square);
  }
}


/* ---------- 6. ENTRIES: the numbered sections ---------- */
.entry {
  position: relative;
  margin-top: calc(var(--square) * 3);
}

/* Section heading: small drafting type, capitals. */
.entry-title {
  margin: 0 0 var(--square);
  font-family: var(--font-draft);
  font-size: 15px;
  line-height: var(--square);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* The bracketed number [1] [2] [3]: hangs in the margin, left of the rust rule. */
.entry-number {
  position: absolute;
  left: calc(var(--square) * -5.5);
  width: calc(var(--square) * 3);
  text-align: right;
  color: var(--rust);
}

/* On small screens there is no room in the margin, so the number sits inline. */
@media (max-width: 720px) {
  .entry-number {
    position: static;
    display: inline-block;
    width: auto;
    margin-right: 0.6em;
    text-align: left;
  }
}

/* A small label inside a section (a project name, for example). */
.entry-label {
  margin: 0 0 0;
  font-family: var(--font-draft);
  font-size: 13px;
  line-height: var(--square);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* Where a line came from (journal post and date). */
.source {
  margin: calc(var(--square) * -0.5) 0 var(--square);
  font-family: var(--font-draft);
  font-size: 12px;
  line-height: var(--square);
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

/* Links set in the drafting face (live site, contact). */
.link-line {
  font-family: var(--font-draft);
  font-size: 15px;
}

.devacademy-subtitle {
  margin: 0 0 var(--square);
  font-family: var(--font-draft);
  font-size: 15px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}


/* ---------- 7. FIGURES: ruler-and-compass drawings ---------- */
/* Each drawing is an inline SVG whose lines sit on grid crossings.
   Its height is a multiple of 24px and it is nudged 6px up so
   the drawn corners land on the ruled lines. */
.figure {
  display: block;
  width: 240px;
  height: 240px;
  margin: 18px 0 30px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}

.figure--wide {
  width: 288px;
  height: 288px;
  margin: 18px 0 30px;
}

/* Small solid dots (circle centres, plotted points). */
.figure .dot {
  fill: var(--rust);
  stroke: none;
}

/* Dashed construction lines. */
.figure .guide {
  stroke-dasharray: 3 5;
  stroke-width: 1;
}

/* Wide screens: the drawing moves out beside the text, on the grid, no longer in the flow. */
@media (min-width: 1128px) {
  .figure {
    position: absolute;
    top: -6px;
    left: calc(var(--square) * 29);        /* 696px from the text column's left edge */
    margin: 0;
  }
}

/* Each figure builds itself once, as it scrolls into view. The file draw.js adds
   .js-draw (only when motion is allowed) and .is-drawn (when the figure is seen).
   Without that script, or with reduced motion, the drawing is simply finished. */
.js-draw .figure .draw {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 1.1s ease-out;
}

.js-draw .figure.is-drawn .draw {
  stroke-dashoffset: 0;
}

.js-draw .figure .draw:nth-child(2) { transition-delay: 0.15s; }
.js-draw .figure .draw:nth-child(3) { transition-delay: 0.3s; }
.js-draw .figure .draw:nth-child(4) { transition-delay: 0.45s; }
.js-draw .figure .draw:nth-child(5) { transition-delay: 0.6s; }
.js-draw .figure .draw:nth-child(6) { transition-delay: 0.75s; }

.js-draw .figure .dot {
  opacity: 0;
  transition: opacity 0.3s ease-out 1.1s;
}

.js-draw .figure.is-drawn .dot {
  opacity: 1;
}


/* ---------- 8. FOOTER ---------- */
.site-footer {
  margin-top: calc(var(--square) * 3);
  padding-bottom: calc(var(--square) * 3);
}

.site-footer p {
  margin: 0;
  font-family: var(--font-draft);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

/* Closing block on the Dev Academy page. */
.closing {
  margin-top: calc(var(--square) * 3);
}


/* ---------- 9. PRINT: plain black on white, no grid ---------- */
@media print {
  .page::before,
  .page::after,
  .figure {
    display: none;
  }
  .column {
    margin-left: 0;
  }
}
