/* ==========================================================================
   Tolicus design system — adapted from DESIGN.md (Raycast-style dark surface).
   Dark is the brand-first default; a light theme is provided as an alternate.
   Elevation comes from the surface ladder, never shadows.

   Theming model:
     :root                              -> dark tokens (default / brand-first)
     :root[data-theme="light"]          -> explicit light (set by toggle / JS)
     @media (prefers-color-scheme:light):root:not([data-theme]) -> device default (no-JS)
   The early /js/theme.js sets data-theme before paint, so JS users always get an
   explicit value; the media query is the progressive-enhancement fallback.
   ========================================================================== */

/* ---- Fonts (self-hosted Inter variable; ss03 is part of the brand voice) ---- */
@font-face {
  font-family: "InterVariable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("/fonts/InterVariable.woff2") format("woff2");
}
@font-face {
  font-family: "InterVariable";
  font-style: italic;
  font-display: swap;
  font-weight: 100 900;
  src: url("/fonts/InterVariable-Italic.woff2") format("woff2");
}

/* ---- Tokens ---- */
:root {
  --canvas: #07080a;
  --surface: #0d0d0d;
  --surface-elevated: #101111;
  --surface-card: #121212;
  --hairline: #242728;
  --hairline-soft: rgba(255, 255, 255, 0.08);
  --hairline-strong: rgba(255, 255, 255, 0.16);

  --primary: #ffffff;
  --primary-pressed: #e8e8e8;
  --on-primary: #000000;

  --ink: #f4f4f6;
  --body: #cdcdcd;
  --mute: #9c9c9d;
  --ash: #6a6b6c;
  --stone: #434345;
  --on-dark-mute: rgba(255, 255, 255, 0.72);

  --accent-blue: #57c1ff;
  --accent-red: #ff6161;
  --accent-green: #59d499;
  --accent-yellow: #ffc533;
  --hero-stripe-start: #ff5757;
  --hero-stripe-end: #a1131a;

  /* Theme-dependent surfaces (flip in light mode) */
  --nav-bg: rgba(7, 8, 10, 0.82);
  --hero-fade: rgba(7, 8, 10, 0.55);
  /* Code blocks stay dark-surfaced in both themes (match highlight.js github-dark). */
  --code-surface: #0d1117;
  --code-border: #1e2430;

  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 16px;
  --r-full: 9999px;

  --s-xxs: 2px;
  --s-xs: 4px;
  --s-sm: 8px;
  --s-md: 12px;
  --s-lg: 16px;
  --s-xl: 24px;
  --s-xxl: 32px;
  --s-section: 96px;

  --container: 1240px;
  --font-sans: "InterVariable", "Inter Fallback", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

/* ---- Light theme tokens ----
   Declared once here, then bound to the explicit selector and the device-default
   media query below so JS and no-JS users both get them. */
:root[data-theme="light"] {
  --canvas: #f7f8fa;
  --surface: #ffffff;
  --surface-elevated: #f1f2f4;
  --surface-card: #ffffff;
  --hairline: #e4e6ea;
  --hairline-soft: rgba(15, 17, 21, 0.07);
  --hairline-strong: rgba(15, 17, 21, 0.16);

  --primary: #16181d;
  --primary-pressed: #2c2f37;
  --on-primary: #ffffff;

  --ink: #0f1115;
  --body: #3c4047;
  --mute: #686d76;
  --ash: #878c95;
  --stone: #c2c6cd;
  --on-dark-mute: rgba(15, 17, 21, 0.64);

  --accent-blue: #1d7fc4;
  --accent-red: #cf3a3a;
  --accent-green: #1f9d57;
  --accent-yellow: #9a6a13;

  --nav-bg: rgba(247, 248, 250, 0.82);
  --hero-fade: rgba(247, 248, 250, 0.62);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --canvas: #f7f8fa;
    --surface: #ffffff;
    --surface-elevated: #f1f2f4;
    --surface-card: #ffffff;
    --hairline: #e4e6ea;
    --hairline-soft: rgba(15, 17, 21, 0.07);
    --hairline-strong: rgba(15, 17, 21, 0.16);

    --primary: #16181d;
    --primary-pressed: #2c2f37;
    --on-primary: #ffffff;

    --ink: #0f1115;
    --body: #3c4047;
    --mute: #686d76;
    --ash: #878c95;
    --stone: #c2c6cd;
    --on-dark-mute: rgba(15, 17, 21, 0.64);

    --accent-blue: #1d7fc4;
    --accent-red: #cf3a3a;
    --accent-green: #1f9d57;
    --accent-yellow: #9a6a13;

    --nav-bg: rgba(247, 248, 250, 0.82);
    --hero-fade: rgba(247, 248, 250, 0.62);
  }
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--body);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  font-feature-settings: "calt", "kern", "liga", "ss03";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
}

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

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

a { color: var(--ink); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4, h5, h6 { color: var(--ink); margin: 0; line-height: 1.2; font-weight: 600; }

:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

::selection { background: var(--accent-blue); color: var(--on-primary); }

/* ---- Layout primitives ---- */
.container { width: 100%; max-width: var(--container); margin-inline: auto; padding-inline: var(--s-xl); }

main { flex: 1 0 auto; }

.section { padding-block: var(--s-section); }
.section--tight { padding-block: var(--s-xxl); }

.skip-link {
  position: absolute;
  left: var(--s-md);
  top: -64px;
  background: var(--primary);
  color: var(--on-primary);
  padding: var(--s-sm) var(--s-lg);
  border-radius: var(--r-md);
  font-weight: 500;
  z-index: 100;
  transition: top 0.15s ease;
}
.skip-link:focus { top: var(--s-md); text-decoration: none; }

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
  font-weight: 500;
  color: var(--mute);
}

.lead { font-size: 18px; color: var(--body); }

.muted { color: var(--mute); }

/* ---- Top nav ---- */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--nav-bg);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--hairline);
}
.nav__inner {
  display: flex;
  align-items: center;
  gap: var(--s-xl);
  height: 60px;
}
.nav__brand { display: flex; align-items: center; gap: var(--s-sm); }
.nav__brand img { height: 26px; width: auto; }
.nav__brand:hover { text-decoration: none; }
.nav__links { display: flex; align-items: center; gap: var(--s-xl); margin-left: auto; }
.nav__link { color: var(--body); font-size: 14px; font-weight: 500; letter-spacing: 0.2px; }
.nav__link:hover { color: var(--ink); text-decoration: none; }
.nav__link--current { color: var(--ink); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.2px;
  line-height: 1;
  padding: 11px 16px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn--primary { background: var(--primary); color: var(--on-primary); }
.btn--primary:hover { background: var(--primary-pressed); }
.btn--secondary { background: transparent; color: var(--ink); }
.btn--secondary:hover { color: var(--ink); }
.btn--tertiary { background: var(--surface-elevated); color: var(--ink); border-color: var(--hairline); }
.btn--tertiary:hover { border-color: var(--hairline-strong); }
.btn--outline { background: transparent; color: var(--ink); border-color: var(--hairline-strong); }
.btn--danger { background: transparent; color: var(--accent-red); border-color: var(--hairline-strong); }
.btn--danger:hover { border-color: var(--accent-red); }
.btn--block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--surface-elevated); color: var(--ash); cursor: not-allowed; }

/* ---- Chips / badges ---- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-xs);
  font-size: 13px;
  padding: 4px 10px;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--body);
  border: 1px solid var(--hairline);
}
.chip:hover { color: var(--ink); text-decoration: none; border-color: var(--hairline-strong); }
.chip--active { background: var(--surface-elevated); color: var(--ink); border-color: var(--hairline-strong); }

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.4px;
  padding: 2px 8px;
  border-radius: var(--r-xs);
  background: var(--surface-elevated);
  color: var(--on-dark-mute);
  border: 1px solid var(--hairline);
}
.badge--published { color: var(--accent-green); }
.badge--scheduled { color: var(--accent-yellow); }
.badge--hidden { color: var(--accent-red); }
.badge--draft { color: var(--mute); }
.badge--info { background: rgba(87, 193, 255, 0.15); color: var(--accent-blue); border-color: transparent; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: var(--s-xl);
}
.card--elevated { background: var(--surface-elevated); }

/* ---- Hero ---- */
.hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--hairline); }
.hero::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 320px;
  background:
    repeating-linear-gradient(
      115deg,
      var(--hero-stripe-start) 0,
      var(--hero-stripe-start) 2px,
      transparent 2px,
      transparent 46px
    );
  -webkit-mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.55), transparent 78%);
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.55), transparent 78%);
  opacity: 0.6;
  pointer-events: none;
}
.hero::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 320px;
  background: linear-gradient(125deg, rgba(161, 19, 26, 0.35), transparent 60%);
  pointer-events: none;
}
.hero__inner {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: var(--s-section);
  align-items: center;
  padding-block: var(--s-section);
}
.hero__title {
  font-size: 64px;
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--ink);
  margin-bottom: var(--s-xl);
}
.hero__subtitle { font-size: 18px; color: var(--body); max-width: 46ch; margin-bottom: var(--s-xxl); }
.hero__actions { display: flex; gap: var(--s-md); flex-wrap: wrap; }
.hero__art {
  position: relative;
  border: 1px solid var(--hairline);
  border-radius: var(--r-xl);
  overflow: hidden;
  background: var(--surface);
}
.hero__art img { width: 100%; height: 100%; object-fit: cover; aspect-ratio: 4 / 3; }
.hero__art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 55%, var(--hero-fade));
}

/* ---- Section headers ---- */
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-lg); margin-bottom: var(--s-xxl); }
.section-head h2 { font-size: 40px; font-weight: 500; letter-spacing: 0.2px; }
.section-head p { margin: var(--s-sm) 0 0; color: var(--mute); }

/* ---- Post grid + cards ---- */
.post-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-lg); }
.post-grid--two { grid-template-columns: repeat(2, 1fr); }

.post-card {
  display: flex;
  flex-direction: column;
  gap: var(--s-md);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: var(--s-xl);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.post-card:hover { border-color: var(--hairline-strong); transform: translateY(-2px); text-decoration: none; }
.post-card__meta { display: flex; align-items: center; gap: var(--s-sm); font-size: 13px; color: var(--mute); }
.post-card__title { font-size: 20px; font-weight: 500; color: var(--ink); }
.post-card__summary { color: var(--body); font-size: 15px; margin: 0; flex: 1; }
.post-card__tags { display: flex; flex-wrap: wrap; gap: var(--s-xs); }

.dot { width: 3px; height: 3px; border-radius: var(--r-full); background: var(--ash); display: inline-block; }

/* ---- Article (single post) ---- */
.article { max-width: 760px; margin-inline: auto; }
.article__header { margin-bottom: var(--s-xxl); }
.article__title { font-size: 48px; line-height: 1.1; font-weight: 600; letter-spacing: -0.4px; margin-bottom: var(--s-lg); }
.article__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-sm); color: var(--mute); font-size: 14px; }
.article__cover { margin: var(--s-xxl) 0; border: 1px solid var(--hairline); border-radius: var(--r-xl); overflow: hidden; }

/* ---- Prose (rendered markdown) ---- */
.prose { color: var(--body); font-size: 17px; line-height: 1.7; }
.prose > * + * { margin-top: var(--s-xl); }
.prose h2 { font-size: 28px; font-weight: 600; margin-top: var(--s-xxl); letter-spacing: -0.2px; }
.prose h3 { font-size: 22px; font-weight: 600; margin-top: var(--s-xl); }
.prose h4 { font-size: 18px; font-weight: 600; }
.prose p { margin: 0; }
.prose a { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--ash); }
.prose a:hover { text-decoration-color: var(--ink); }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0; }
.prose li + li { margin-top: var(--s-sm); }
.prose strong { color: var(--ink); font-weight: 600; }
.prose blockquote {
  border-left: 2px solid var(--hairline-strong);
  padding-left: var(--s-lg);
  color: var(--mute);
  font-style: italic;
}
.prose img { border-radius: var(--r-lg); border: 1px solid var(--hairline); margin-inline: auto; }
.prose code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--surface-card);
  border: 1px solid var(--hairline);
  border-radius: var(--r-xs);
  padding: 1px 6px;
}
.prose pre {
  background: var(--code-surface);
  border: 1px solid var(--code-border);
  border-radius: var(--r-lg);
  padding: var(--s-lg);
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.6;
}
.prose pre code { background: none; border: none; padding: 0; font-size: inherit; }
.prose table { width: 100%; border-collapse: collapse; font-size: 15px; }
.prose th, .prose td { text-align: left; padding: var(--s-sm) var(--s-md); border-bottom: 1px solid var(--hairline); }
.prose th { color: var(--ink); font-weight: 600; }
.prose hr { border: none; border-top: 1px solid var(--hairline); }

/* ---- Footer ---- */
.footer { border-top: 1px solid var(--hairline); background: var(--canvas); padding-block: var(--s-xxl); margin-top: var(--s-section); }
.footer__inner { display: flex; align-items: center; justify-content: space-between; gap: var(--s-lg); flex-wrap: wrap; }
.footer__brand { display: flex; align-items: center; gap: var(--s-sm); }
.footer__brand img { height: 22px; }
.footer__links { display: flex; gap: var(--s-xl); flex-wrap: wrap; }
.footer__links a { color: var(--mute); font-size: 14px; }
.footer__links a:hover { color: var(--ink); }
.footer small { color: var(--ash); }

/* ---- Empty / utility states ---- */
.empty { text-align: center; padding: var(--s-section) var(--s-lg); color: var(--mute); }
.tag-filter { display: flex; flex-wrap: wrap; gap: var(--s-sm); margin-bottom: var(--s-xxl); }

/* ---- Error pages ---- */
.error-page { text-align: center; padding-block: var(--s-section); }
.error-page__code { font-size: 96px; font-weight: 600; color: var(--ink); line-height: 1; letter-spacing: -2px; }
.error-page__msg { color: var(--mute); margin: var(--s-md) 0 var(--s-xl); font-size: 18px; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1024px) {
  .post-grid { grid-template-columns: repeat(2, 1fr); }
  .hero__title { font-size: 56px; }
}
@media (max-width: 768px) {
  :root { --s-section: 64px; }
  .hero__inner { grid-template-columns: 1fr; gap: var(--s-xxl); }
  .hero__art { order: -1; }
  .hero__title { font-size: 44px; }
  .article__title { font-size: 36px; }
  .nav__links { gap: var(--s-md); }
  .nav__links .nav__link { display: none; }
  .nav__links .nav__link--keep { display: inline; }
  .section-head { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 560px) {
  :root { --s-section: 48px; }
  .container { padding-inline: var(--s-lg); }
  .post-grid, .post-grid--two { grid-template-columns: 1fr; }
  .hero__title { font-size: 36px; }
  .footer__inner { flex-direction: column; align-items: flex-start; }
}

/* ---- Theme toggle ---- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--r-full);
  background: var(--surface-elevated);
  color: var(--body);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--hairline-strong); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.theme-toggle .icon { width: 18px; height: 18px; display: block; }
/* Dark theme (default): offer the sun (switch to light). Hide the moon. */
.theme-toggle .icon-sun { display: block; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme]) .theme-toggle .icon-moon { display: block; }
}

/* ---- Theme-aware logo swap ---- */
.logo--dark { display: none; }
:root[data-theme="light"] .logo--light { display: none; }
:root[data-theme="light"] .logo--dark { display: block; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .logo--light { display: none; }
  :root:not([data-theme]) .logo--dark { display: block; }
}
