/* shared chrome: reset, paper grain, type, nav, footer, buttons, cards, the
   terminal window, and motion. everything is drawn with a 2px ink line. */

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

html {
  background: var(--canvas);
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: clip;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  color: var(--body);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color var(--duration-normal) ease, color var(--duration-normal) ease;
}

/* paper grain: one fixed, click-through layer. never on a scrolling box. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: var(--z-grain);
  pointer-events: none;
  opacity: 0.35;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.10 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

[data-theme='dark'] body::after {
  opacity: 0.5;
  mix-blend-mode: screen;
}

::selection {
  background: var(--selection-bg);
  color: var(--selection-fg);
}

:focus-visible {
  outline: 3px solid var(--accent-deep);
  outline-offset: 3px;
  border-radius: var(--radius-inline);
}

img,
svg {
  max-width: 100%;
  display: block;
}

/* ---- skip link ---- */
.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: calc(var(--z-grain) + 1);
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--on-accent);
  border: var(--stroke) solid var(--line);
  border-radius: var(--radius-control);
  font-weight: 600;
  font-size: var(--text-sm);
  transform: translateY(-200%);
  transition: transform var(--duration-fast) ease;
}

.skip-link:focus {
  transform: none;
}

/* ---- layout ---- */
.container {
  width: min(100% - 2 * clamp(1rem, 4vw, 2.5rem), var(--container));
  margin-inline: auto;
}

/* ---- typography ---- */
h1,
h2,
h3 {
  margin: 0;
  color: var(--ink);
  font-weight: 700;
  text-wrap: balance;
}

h1 {
  font-size: var(--display-lg);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-display);
  font-weight: 800;
}

h2 {
  font-size: var(--display-md);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-heading);
}

h3 {
  font-size: var(--text-lg);
  line-height: var(--leading-snug);
  font-weight: 700;
}

p {
  margin: 0;
  max-width: var(--measure);
  text-wrap: pretty;
}

p + p {
  margin-top: var(--space-4);
}

b,
strong {
  font-weight: 700;
  color: var(--ink);
}

.lede {
  font-size: var(--text-lg);
  color: var(--muted);
}

/* handwriting: annotations, labels, the "now" flag. never body copy. */
.hand {
  font-family: var(--font-hand);
  font-size: var(--text-hand);
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
}

.mono {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-mono);
  font-variant-numeric: tabular-nums;
}

.mono-label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--muted);
  letter-spacing: var(--tracking-mono);
}

/* yellow marker run behind a phrase. slightly skewed so it looks swiped by hand. */
.mark {
  position: relative;
  display: inline;
  isolation: isolate;
  background: none;
  color: inherit;
  padding: 0 0.08em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  background-image: linear-gradient(104deg, transparent 0.4%, var(--accent) 1.6%, var(--accent) 96%, transparent 97.5%);
  background-repeat: no-repeat;
  background-size: 100% 0.62em;
  background-position: 0 78%;
}

[data-theme='dark'] .mark {
  background-size: 100% 0.32em;
  background-position: 0 96%;
}

/* ---- inline links: ink with a hand-drawn squiggle on hover ---- */
a {
  color: var(--ink);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--line-soft);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.18em;
  transition: color var(--duration-fast) ease, text-decoration-color var(--duration-fast) ease;
}

a:hover,
a:focus-visible {
  color: var(--ink);
  text-decoration-color: var(--accent-deep);
  text-decoration-style: wavy;
}

/* ---- inline code ---- */
code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--ink);
  background: var(--surface-2);
  border: 1.5px solid var(--line-soft);
  border-radius: var(--radius-inline);
  padding: 0.05em 0.4em;
}

/* ---- nav ---- */
.site-nav {
  position: relative;
  z-index: var(--z-nav);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: var(--nav-height);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: 800;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.brand__badge {
  display: inline-grid;
  place-items: center;
  width: 2.125rem;
  height: 2.125rem;
  border: var(--stroke) solid var(--line);
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-hand);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: var(--shadow-1);
  transition: transform var(--duration-normal) var(--ease-bounce), box-shadow var(--duration-fast) ease;
}

.brand:hover .brand__badge,
.brand:focus-visible .brand__badge {
  transform: rotate(-12deg) translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--shadow-ink);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-links a {
  position: relative;
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  padding-block: var(--space-2);
  transition: color var(--duration-fast) ease;
}

.nav-links a:hover,
.nav-links a:focus-visible {
  color: var(--ink);
}

/* the current page gets a hand-drawn squiggle */
.nav-links a[aria-current='page'] {
  color: var(--ink);
}

.nav-links a[aria-current='page']::after {
  content: '';
  position: absolute;
  left: -2px;
  right: -2px;
  bottom: -1px;
  height: 8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 8' preserveAspectRatio='none'%3E%3Cpath d='M1 5.5c6-4 10-4 15 0s10 4 15 0 10-4 15 0 9 3 13 .5' fill='none' stroke='%23e0a72a' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
}

@media (max-width: 30rem) {
  .site-nav {
    flex-wrap: wrap;
    padding-block: var(--space-3);
  }

  .nav-links {
    width: 100%;
    justify-content: space-between;
    gap: var(--space-3);
  }

  .brand__text {
    display: none;
  }
}

/* theme toggle: a little sun that becomes a moon. drawn in css, no icon font. */
.theme-toggle {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 2.375rem;
  height: 2.375rem;
  padding: 0;
  border: var(--stroke) solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: transform var(--duration-fast) ease, box-shadow var(--duration-fast) ease, background-color var(--duration-fast) ease;
}

.theme-toggle:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--shadow-ink);
}

.theme-toggle:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 var(--shadow-ink);
}

.theme-toggle__disc {
  position: relative;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid currentColor;
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 4.5px currentColor;
  transition: transform var(--duration-normal) var(--ease-bounce), box-shadow var(--duration-normal) ease, background-color var(--duration-normal) ease;
}

[data-theme='dark'] .theme-toggle__disc {
  background: var(--surface);
  box-shadow: inset 4px -3px 0 0 var(--ink);
  transform: rotate(-30deg);
}

/* ---- buttons: pills with a 2px line and a hard shadow that presses flat ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 2.75rem;
  padding: 0 var(--space-5);
  border-radius: var(--radius-control);
  border: var(--stroke) solid var(--line);
  font: inherit;
  font-size: var(--text-base);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow-2);
  transition: transform var(--duration-fast) ease, box-shadow var(--duration-fast) ease, background-color var(--duration-fast) ease;
}

.btn:hover,
.btn:focus-visible {
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0 var(--shadow-ink);
}

.btn:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 var(--shadow-ink);
}

.btn--primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn--primary:hover,
.btn--primary:focus-visible {
  background: var(--accent-deep);
  color: var(--on-accent);
}

.btn--secondary {
  background: var(--surface);
  color: var(--ink);
}

.btn--secondary:hover,
.btn--secondary:focus-visible {
  background: var(--surface-2);
  color: var(--ink);
}

.btn--sm {
  height: 2.25rem;
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-1);
}

.btn--sm:hover,
.btn--sm:focus-visible {
  box-shadow: 3px 3px 0 var(--shadow-ink);
}

/* ---- sketched card: the one container pattern ---- */
.card {
  position: relative;
  background: var(--surface);
  border: var(--stroke) solid var(--line);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-2);
}

.card--yellow,
.card--sky,
.card--coral {
  --ink: #1d1b17;
  --body: #3d3a33;
  --muted: #5c5749;
  --on-accent: #1d1b17;
  --line-soft: rgba(29, 27, 23, 0.35);
  color: var(--body);
}

.card--yellow {
  background: var(--accent);
}

.card--sky {
  background: var(--sky);
}

.card--coral {
  background: var(--coral);
}

.card--paper {
  background: var(--surface-2);
}

/* ---- sections ---- */
.section {
  padding-block: var(--space-section);
}

.section + .section {
  border-top: var(--stroke) dashed var(--line-soft);
}

.section__title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

/* a little three-star sparkle, like a doodle in a margin */
.sparkle {
  flex: none;
  width: 2.25rem;
  height: 1.5rem;
  color: var(--accent-deep);
}

/* ---- terminal: a sketched window with a dark inside. same in both themes. ---- */
.term {
  position: relative;
  background: var(--surface-code);
  border: var(--stroke) solid var(--line);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-3);
  overflow: hidden;
}

.term__bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--stroke) solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

.term__bar span:last-child {
  margin-left: auto;
  font-family: var(--font-hand);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ink);
}

.term__dots {
  display: inline-flex;
  gap: 6px;
}

.term__dots i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--coral);
}

.term__dots i:nth-child(2) {
  background: var(--accent);
}

.term__dots i:nth-child(3) {
  background: var(--leaf);
}

.term pre {
  margin: 0;
  padding: var(--space-4) var(--space-4) var(--space-5);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.75;
  color: var(--code-text);
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.term .prompt {
  color: var(--accent);
  font-weight: 700;
  user-select: none;
}

.term .comment {
  color: var(--code-muted);
}

.term .out {
  color: var(--sky);
  font-weight: 500;
}

/* ---- footer: a cream band with an ink line on top ---- */
.site-footer {
  position: relative;
  isolation: isolate;
  margin-top: var(--space-section);
  padding-block: var(--space-7) var(--space-8);
  display: grid;
  gap: var(--space-5);
  font-size: var(--text-sm);
  color: var(--muted);
}

/* bleed the band to the viewport edges without leaving the container */
.site-footer::before {
  content: '';
  position: absolute;
  inset: 0 -50vw;
  z-index: -1;
  background: var(--canvas-2);
  border-top: var(--stroke) solid var(--line);
}

.site-footer__contact {
  color: var(--body);
  font-size: var(--text-base);
  max-width: 40ch;
}

.site-footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-footer__links a {
  display: inline-flex;
  align-items: center;
  height: 2.25rem;
  padding: 0 var(--space-4);
  border: var(--stroke) solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  box-shadow: var(--shadow-1);
  transition: transform var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

.site-footer__links a:hover,
.site-footer__links a:focus-visible {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--shadow-ink);
}

.site-footer__links a:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.site-footer__tagline {
  font-family: var(--font-hand);
  font-size: var(--text-hand);
  font-weight: 500;
  color: var(--muted);
}

@media (min-width: 40rem) {
  .site-footer {
    grid-template-columns: 1fr auto;
    align-items: start;
  }

  .site-footer__tagline {
    grid-column: 1 / -1;
  }
}

/* ---- motion ---- */
@media (prefers-reduced-motion: no-preference) {
  @keyframes rise {
    from {
      opacity: 0;
      transform: translateY(14px) rotate(-0.4deg);
    }
  }

  @keyframes twinkle {
    0%,
    100% {
      transform: scale(1);
    }

    50% {
      transform: scale(0.8) rotate(8deg);
    }
  }

  /* hero elements cascade in; --i sets order */
  .rise {
    animation: rise var(--duration-slow) var(--ease-out-expo) both;
    animation-delay: calc(var(--i, 0) * 70ms);
  }

  /* below-fold sections reveal once on scroll */
  .reveal {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity var(--duration-slow) ease, transform var(--duration-slow) var(--ease-out-expo);
  }

  .reveal.in {
    opacity: 1;
    transform: none;
  }

  .reveal.in .sparkle {
    transform-origin: center;
    animation: twinkle 700ms var(--ease-bounce) 1;
  }
}

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