/* ============================================================
   base.css — "ledger meets terminal" design system
   Shared foundation for the main site (stanleylutka.com)
   Dark: ink-navy (#0b1020 family) · Light: warm paper
   Accent: sky-blue signature gradient · mono figures
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  /* Light theme — warm editorial paper */
  --bg: #f7f5f0;
  --bg-2: #efece4;
  --fg: #16203a;
  --fg-soft: #34405e;
  --muted: #5a6783;
  --card: #fffdf9;
  --card-2: #fbf9f3;
  --border: #e1dccf;
  --border-strong: #cfc8b6;
  --link: #0e7fb8;
  --accent: #0a8ec9;
  --accent-2: #2563eb;
  --accent-3: #7c3aed;
  --accent-ink: #064a6e;
  --good: #15803d;
  --good-soft: #16a34a;
  --warn: #b45309;
  --danger: #dc2626;
  --ring: rgba(10, 142, 201, 0.35);
  --grid-line: rgba(22, 32, 58, 0.045);
  --glow: rgba(10, 142, 201, 0.18);
  --shadow-card: 0 1px 0 rgba(255,255,255,0.6) inset, 0 18px 40px -28px rgba(22, 32, 58, 0.45);
  --shadow-lift: 0 1px 0 rgba(255,255,255,0.6) inset, 0 28px 60px -30px rgba(22, 32, 58, 0.55);
  --noise-opacity: 0.5;

  /* Signature gradient */
  --grad: linear-gradient(120deg, #0a8ec9 0%, #2563eb 52%, #7c3aed 100%);
  --grad-soft: linear-gradient(120deg, rgba(10,142,201,0.16), rgba(124,58,237,0.14));

  /* Typography */
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Newsreader", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius: 16px;
  --radius-sm: 11px;
  --radius-lg: 22px;
  --maxw: 1200px;
}

html[data-theme="dark"] {
  /* Dark theme — deep ink-navy terminal */
  --bg: #0b1020;
  --bg-2: #080c19;
  --fg: #e9edf7;
  --fg-soft: #c4cce0;
  --muted: #8a98b8;
  --card: #11172b;
  --card-2: #0d1426;
  --border: #1e2840;
  --border-strong: #2c3a5c;
  --link: #56c5f5;
  --accent: #38bdf8;
  --accent-2: #60a5fa;
  --accent-3: #a78bfa;
  --accent-ink: #bfe6fb;
  --good: #4ade80;
  --good-soft: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --ring: rgba(56, 189, 248, 0.5);
  --grid-line: rgba(120, 160, 220, 0.06);
  --glow: rgba(56, 189, 248, 0.3);
  --shadow-card: 0 1px 0 rgba(255,255,255,0.03) inset, 0 24px 60px -30px rgba(0,0,0,0.85);
  --shadow-lift: 0 1px 0 rgba(255,255,255,0.05) inset, 0 34px 80px -34px rgba(0,0,0,0.9);
  --noise-opacity: 0.85;

  --grad: linear-gradient(120deg, #38bdf8 0%, #60a5fa 50%, #a78bfa 100%);
  --grad-soft: linear-gradient(120deg, rgba(56,189,248,0.14), rgba(167,139,250,0.12));
}

/* Honour OS preference before JS runs (bootstrap sets data-theme, this is a fallback) */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --bg: #0b1020; --bg-2: #080c19; --fg: #e9edf7; --fg-soft: #c4cce0;
    --muted: #8a98b8; --card: #11172b; --card-2: #0d1426; --border: #1e2840;
    --border-strong: #2c3a5c; --link: #56c5f5; --accent: #38bdf8; --accent-2: #60a5fa;
    --accent-3: #a78bfa; --accent-ink: #bfe6fb; --ring: rgba(56,189,248,0.5);
    --grid-line: rgba(120,160,220,0.06); --glow: rgba(56,189,248,0.3);
    --grad: linear-gradient(120deg, #38bdf8 0%, #60a5fa 50%, #a78bfa 100%);
  }
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  transition: background-color 0.4s ease, color 0.4s ease;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
  font-weight: 380;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  position: relative;
  overflow-x: hidden;
}

/* ---------- Atmospheric background: graph paper + radial glows ---------- */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: center top;
  mask-image: radial-gradient(ellipse 120% 90% at 50% 0%, #000 35%, transparent 88%);
  -webkit-mask-image: radial-gradient(ellipse 120% 90% at 50% 0%, #000 35%, transparent 88%);
  pointer-events: none;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -3;
  background:
    radial-gradient(48rem 30rem at 12% -6%, var(--glow), transparent 60%),
    radial-gradient(42rem 28rem at 96% 4%, rgba(124,58,237,0.10), transparent 62%),
    radial-gradient(50rem 34rem at 60% 108%, rgba(37,99,235,0.08), transparent 60%);
  pointer-events: none;
}

img { max-width: 100%; height: auto; }

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

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

/* ---------- Layout shell ---------- */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 22px clamp(16px, 4vw, 40px) 56px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0 22px;
  position: sticky;
  top: 0;
  z-index: 40;
  background: linear-gradient(var(--bg) 62%, transparent);
  backdrop-filter: blur(2px);
}

.wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.02em;
}
.wordmark .dot {
  width: 9px; height: 9px; border-radius: 2px;
  background: var(--grad);
  box-shadow: 0 0 14px var(--glow);
  transform: translateY(-1px);
}
.wordmark b { font-weight: 700; }
.wordmark .slash { color: var(--muted); }
.wordmark:hover .dot { box-shadow: 0 0 22px var(--glow); }

/* ---------- Theme toggle ---------- */
button.theme {
  border: 1px solid var(--border-strong);
  background: var(--card);
  color: var(--fg);
  border-radius: 999px;
  padding: 8px 15px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
button.theme:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring);
  transform: translateY(-1px);
}
button.theme:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring);
}

/* ---------- Typography primitives ---------- */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 560;
  line-height: 1.12;
  letter-spacing: -0.012em;
  margin: 0 0 12px;
  font-optical-sizing: auto;
}

.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums lining-nums; }

/* eyebrow / section kicker */
.kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 12px;
}
.kicker::before {
  content: "";
  width: 22px; height: 1px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--glow);
}

/* gradient text accent */
.grad-text {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Cards ---------- */
.card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, var(--card), var(--card-2));
  padding: clamp(18px, 2.5vw, 26px);
  box-shadow: var(--shadow-card);
}

.card.glow::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: var(--grad);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0.45;
  pointer-events: none;
}

/* ---------- Buttons / pills ---------- */
.btn {
  --b: var(--fg);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-strong);
  background: var(--card);
  color: var(--fg);
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.btn:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring); }
.btn:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring); }

.btn.primary {
  border: none;
  color: #05111f;
  background: var(--grad);
  background-size: 160% 160%;
  font-weight: 600;
  box-shadow: 0 10px 30px -12px var(--glow);
}
html[data-theme="dark"] .btn.primary { color: #05111f; }
.btn.primary:hover { box-shadow: 0 16px 38px -12px var(--glow); transform: translateY(-2px); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
}
.pill .led { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }
.pill.live { color: var(--good); border-color: color-mix(in srgb, var(--good) 45%, var(--border)); }
.pill.wip { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

/* ---------- Chips (stack tags) ---------- */
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.01em;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--grad-soft);
  color: var(--fg-soft);
}

/* ---------- Progress bars (glowing, animated) ---------- */
.progress {
  position: relative;
  height: 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 22%, transparent);
  overflow: hidden;
}
.progress > span {
  position: relative;
  display: block;
  height: 100%;
  width: 100%;
  /* Fill amount is a horizontal scale (--p is a 0–1 fraction set by JS).
     Using transform avoids percentage-width resolution issues when the track
     is a flex/grid item, and animates on the GPU. The resting value is correct
     even if JS never runs (CSS default keeps it collapsed until set). */
  transform: scaleX(var(--p, 0));
  transform-origin: left center;
  border-radius: inherit;
  background: var(--grad);
  background-size: 200% 100%;
  box-shadow: 0 0 12px var(--glow);
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 54px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  justify-content: space-between;
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }
.site-footer .mono { font-size: 12.5px; }

/* ---------- Theme-aware social icon swap ---------- */
[data-theme="light"] .icon-dark { display: inline; }
[data-theme="light"] .icon-light { display: none; }
[data-theme="dark"] .icon-dark { display: none; }
[data-theme="dark"] .icon-light { display: inline; }

.hidden { display: none !important; }

/* ---------- Reveal-on-load animation system ---------- */
@media (prefers-reduced-motion: no-preference) {
  .reveal {
    opacity: 0;
    transform: translateY(16px);
    animation: reveal-in 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    animation-delay: var(--d, 0ms);
  }
  @keyframes reveal-in {
    to { opacity: 1; transform: none; }
  }
  /* Grow on load: reveal the (already correctly scaled) bar left-to-right via
     clip-path. The keyframe references no custom property, so it can't break the
     resting fill — scaleX(var(--p)) stays correct throughout. */
  .progress > span.animate-bar {
    animation: bar-reveal 1.1s cubic-bezier(0.16, 1, 0.3, 1) both;
  }
  @keyframes bar-reveal {
    from { clip-path: inset(0 100% 0 0); }
    to   { clip-path: inset(0 0 0 0); }
  }
  /* Gentle shimmer sweep across the filled bar. */
  .progress > span.animate-bar::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.28), transparent);
    background-size: 200% 100%;
    animation: bar-shimmer 2.6s ease-in-out 1.1s infinite;
  }
  @keyframes bar-shimmer {
    0% { background-position: 120% 50%; }
    100% { background-position: -120% 50%; }
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* ---------- Focus baseline ---------- */
:where(a, button, input, select, textarea, summary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
