/* dotcom — Base Styles
   Spacing directly from The Monospace Web (owickstrom.github.io/the-monospace-web).
   Polished with make-interfaces-feel-better principles.
   Drop into src/styles/global.css when scaffolding Astro.
   Requires tokens.css to be imported first.
*/

/* ─────────────────────────────────────────────────────────
   FONT — loaded here so every page gets IBM Plex Mono just by
   linking base.css. Do not add per-page Google Fonts <link> tags.
   ───────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;1,400&display=swap');

/* ─────────────────────────────────────────────────────────
   DESIGN TOKENS (non-color)
   ───────────────────────────────────────────────────────── */
:root {
  /* Vertical grid unit — ALL vertical spacing is a multiple of this. */
  --line-height: 1.2rem;

  /* Border — single source of truth for all structural borders */
  --border-thickness: 2px;

  /* Border radius — monospace aesthetic: tight, almost square */
  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 6px;

  /* Animation */
  --duration-fast: 150ms;
  --duration-base: 200ms;
  --ease-default: cubic-bezier(0.2, 0, 0, 1);

  /* Typography scale */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem; /* h1 — matches Monospace Web exactly */
}

/* ─────────────────────────────────────────────────────────
   SELECTION
   ───────────────────────────────────────────────────────── */
::selection {
  background-color: oklch(0.8701 0.2006 122.65);
  color: oklch(0 0 0);
}

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

/* The Monospace Web owl selector — every element after another gets one line-height gap.
   This is the core of their spacing system: no ad-hoc margins, just a consistent rhythm. */
* + * {
  margin-top: var(--line-height);
}

/* ─────────────────────────────────────────────────────────
   ROOT
   ───────────────────────────────────────────────────────── */
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizelegibility;
  font-variant-numeric: tabular-nums lining-nums;

  font-family: 'IBM Plex Mono', Menlo, 'Courier New', monospace;
  font-size: 16px;
  line-height: var(--line-height);
  background-color: var(--bg-page);
  color: var(--text-body);
  tab-size: 2;

  display: flex;
  width: 100%;
  margin: 0;
  padding: 0;
  flex-direction: column;
  align-items: center;
}

body {
  position: relative;
  width: 100%;
  margin: 0;
  padding: var(--line-height) 2ch;
  max-width: calc(min(80ch, round(down, 100%, 1ch)));
  line-height: var(--line-height);
  overflow-x: hidden;
}

/* ─────────────────────────────────────────────────────────
   TYPOGRAPHY
   ───────────────────────────────────────────────────────── */
h1,
h2,
h3,
h4,
h5,
h6 {
  color: var(--text-heading);
  text-wrap: balance;
  font-weight: 700;
  /* Monospace Web: 2× line-height top, 1× bottom — overrides owl selector */
  margin: calc(var(--line-height) * 2) 0 var(--line-height);
  line-height: var(--line-height);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* h1: 2rem with a two-line line-height — exact Monospace Web values */
h1 {
  font-size: 2rem;
  line-height: calc(2 * var(--line-height));
  margin-bottom: calc(var(--line-height) * 2);
  letter-spacing: 0.04em;
}

/* h2: 1rem — same as body text, CAPS is the only differentiator */
h2 {
  font-size: 1rem;
}
h3 {
  font-size: 1rem;
}
h4 {
  font-size: 1rem;
}

p {
  text-wrap: pretty;
  margin: 0 0 var(--line-height);
}

/* Tabular + lining numbers */
time,
.tabular {
  font-variant-numeric: tabular-nums lining-nums;
}

a {
  color: var(--text-link);
  text-decoration-line: underline;
  text-decoration-thickness: var(--border-thickness);
  text-decoration-color: oklch(from var(--color-accent) l c h / 0.4);
  text-underline-offset: 3px;
  transition-property: color, text-decoration-color;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease-default);
}

a:hover {
  color: var(--text-link-hover);
  text-decoration-color: var(--color-accent);
}

strong {
  font-weight: 800;
}
em {
  font-style: italic;
}

/* ─────────────────────────────────────────────────────────
   HORIZONTAL RULE
   Monospace Web approach: pseudo-element, vertically grid-centered,
   with 3× border-thickness double = visually thick double line.
   ───────────────────────────────────────────────────────── */
hr {
  position: relative;
  display: block;
  height: var(--line-height);
  margin: calc(var(--line-height) * 1.5) 0;
  border: none;
}

hr::after {
  display: block;
  content: '';
  position: absolute;
  top: calc(var(--line-height) / 2 - var(--border-thickness));
  left: 0;
  width: 100%;
  border-top: calc(var(--border-thickness) * 3) double var(--border-strong);
  height: 0;
}

/* ─────────────────────────────────────────────────────────
   LISTS — native square bullets, Monospace Web style
   ───────────────────────────────────────────────────────── */
ul {
  list-style-type: square;
  padding: 0 0 0 2ch;
  margin: 0 0 var(--line-height);
}

ol {
  list-style-type: none;
  counter-reset: item;
  padding: 0;
  margin: 0 0 var(--line-height);
}

ol li::before {
  content: counters(item, '.') '. ';
  counter-increment: item;
  font-weight: 600;
}

li {
  /* Reset the owl selector top margin — list items are tight by default */
  margin: 0;
  padding: 0;
}

/* ─────────────────────────────────────────────────────────
   CODE
   ───────────────────────────────────────────────────────── */
code {
  font-family: inherit;
  font-size: 0.9em;
  background-color: var(--bg-code);
  color: var(--color-accent);
  padding: 0.05em 0.3em;
  border-radius: var(--radius-sm);
  /* Lamp ring — outline draws inside the box (negative offset) so it never bleeds into adjacent lines */
  outline: 1px solid oklch(from var(--color-accent) l c h / 0.4);
  outline-offset: -1px;
}

:root.light code {
  outline: none;
}

pre code {
  background: none;
  padding: 0;
  font-size: inherit;
  border-radius: 0;
  color: inherit;
  box-shadow: none;
  outline: none;
}

pre {
  background-color: var(--bg-elevated);
  border: var(--border-thickness) solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--line-height) 2ch;
  overflow-x: auto;
  font-size: var(--text-sm);
  line-height: var(--line-height);
  margin: var(--line-height) 0;
  /* Reset owl — pre handles its own vertical rhythm */
  margin-top: var(--line-height);
}

/* ─────────────────────────────────────────────────────────
   TREE — directory-style nested list (from The Monospace Web)
   ───────────────────────────────────────────────────────── */
.tree,
.tree ul {
  position: relative;
  padding-left: 0;
  list-style-type: none;
  line-height: var(--line-height);
  margin: 0;
}

.tree ul li {
  position: relative;
  padding-left: 1.5ch;
  margin-left: 1.5ch;
  border-left: var(--border-thickness) solid var(--border-default);
  margin-top: 0;
}

.tree ul li::before {
  position: absolute;
  display: block;
  top: calc(var(--line-height) / 2);
  left: 0;
  content: '';
  width: 1ch;
  border-bottom: var(--border-thickness) solid var(--border-default);
}

.tree ul li:last-child {
  border-left: none;
}

.tree ul li:last-child::after {
  position: absolute;
  display: block;
  top: 0;
  left: 0;
  content: '';
  height: calc(var(--line-height) / 2);
  border-left: var(--border-thickness) solid var(--border-default);
}

/* ─────────────────────────────────────────────────────────
   GRID — character-unit flex grid (from The Monospace Web)
   ───────────────────────────────────────────────────────── */
.grid {
  display: flex;
  gap: 1ch;
  width: 100%;
  margin-bottom: var(--line-height);
}

.grid > * {
  flex: 1;
  /* Suppress owl inside grid — grid handles its own spacing */
  margin-top: 0;
}

/* Suppress owl selector for horizontal layout containers.
   The owl adds margin-top to every sibling; flex row children don't want that. */
nav li,
nav a,
.tags > *,
.post-meta > *,
.post-item > *,
.site-header > *,
.swatches > *,
.site-footer > * {
  margin-top: 0;
}

/* ─────────────────────────────────────────────────────────
   INTERACTIVE ELEMENTS
   ───────────────────────────────────────────────────────── */
button,
[role='button'] {
  cursor: pointer;
  font-family: inherit;
  border-radius: var(--radius-md);
  min-height: 40px;
  min-width: 40px;
  transition-property: scale, background-color, color, border-color;
  transition-duration: var(--duration-fast);
  transition-timing-function: var(--ease-default);
}

button:active,
[role='button']:active {
  scale: 0.96;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ─────────────────────────────────────────────────────────
   IMAGES
   ───────────────────────────────────────────────────────── */
img {
  display: block;
  width: 100%;
  object-fit: contain;
  outline: var(--border-thickness) solid rgb(255 255 255 / 0.1);
  border-radius: var(--radius-sm);
}

:root.light img {
  outline-color: rgb(0 0 0 / 0.1);
}

/* ─────────────────────────────────────────────────────────
   GRAIN OVERLAY — dark mode only
   SVG feTurbulence noise tile, fixed over the page.
   mix-blend-mode: soft-light gives a paper/film texture
   without washing out the dark background.
   ───────────────────────────────────────────────────────── */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.09;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

/* Remove grain in light mode — paper feel works on dark, not needed on light */
:root.light body::after {
  opacity: 0;
}

/* ─────────────────────────────────────────────────────────
   DEBUG GRID OVERLAY (dev only)
   Add .debug-grid to <html> to visualize the character grid.
   ───────────────────────────────────────────────────────── */
.debug-grid {
  background-image:
    repeating-linear-gradient(
      to right,
      oklch(0.5 0.1 200 / 0.07) 0,
      oklch(0.5 0.1 200 / 0.07) 1px,
      transparent 1px,
      transparent 1ch
    ),
    repeating-linear-gradient(
      to bottom,
      oklch(0.5 0.1 200 / 0.07) 0,
      oklch(0.5 0.1 200 / 0.07) 1px,
      transparent 1px,
      transparent var(--line-height)
    );
}
