/* ==========================================================================
   SolBack Guides — shared foundation stylesheet
   --------------------------------------------------------------------------
   Consumed by every static page under /guides/. No JavaScript anywhere.

   Palette mirrors the main app's design tokens (src/index.css): light oklch
   canvas, violet accent, Space Grotesk for display type. Both the light and
   the dark palette are defined in full; body background is always explicit.

   Class contract (guide pages use exactly these):
     .g-nav .g-wrap .g-hero .g-meta .g-note .g-cta .g-faq .g-related
     .g-footer .g-scroll
   Plus bare h2/h3/p/ul/ol/table/code styling inside .g-wrap.
   Structural helpers: .g-nav-inner, .g-footer-inner (inner width columns),
   .g-cards / .g-card (directory page only).
   ========================================================================== */

/* ---------- Fonts ---------- */

@font-face {
  font-family: 'Space Grotesk';
  src: url('/fonts/SpaceGrotesk/SpaceGrotesk-Regular.woff2') format('woff2'),
         url('/fonts/SpaceGrotesk/SpaceGrotesk-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Space Grotesk';
  src: url('/fonts/SpaceGrotesk/SpaceGrotesk-Bold.woff2') format('woff2'),
         url('/fonts/SpaceGrotesk/SpaceGrotesk-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens: light (default) ---------- */

:root {
  color-scheme: light;

  --g-font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --g-font-display: 'Space Grotesk', -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  --g-font-mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --g-canvas: oklch(97.2% 0.008 292);
  --g-surface: oklch(99.6% 0.002 290);
  --g-surface-2: oklch(96.4% 0.009 292);
  --g-surface-3: oklch(93.2% 0.015 292);
  --g-text: oklch(26% 0.035 294);
  --g-text-secondary: oklch(45% 0.028 292);
  --g-text-tertiary: oklch(58% 0.022 292);
  --g-border: oklch(88% 0.014 292);
  --g-border-subtle: oklch(92.8% 0.009 292);
  --g-accent: oklch(61% 0.09 294);
  --g-accent-strong: oklch(49% 0.095 294);
  --g-accent-hover: oklch(45% 0.1 294);
  --g-accent-soft: oklch(95.8% 0.021 294);
  --g-cta-fg: oklch(99.6% 0.002 290);
  --g-warning: oklch(48% 0.11 76);
  --g-warning-soft: oklch(95% 0.045 76);
  --g-warning-line: oklch(80% 0.09 76);

  --g-nav-bg: oklch(99.6% 0.002 290 / 82%);
  --g-shadow-card: 0 20px 48px -34px oklch(30% 0.05 294 / 28%), 0 2px 8px oklch(30% 0.04 294 / 5%);
  --g-hairline-top: inset 0 1px 0 oklch(100% 0 0 / 72%);

  --g-measure: 720px;
  --g-gutter: clamp(1.15rem, 5vw, 2rem);
  --g-r-sm: 10px;
  --g-r-md: 14px;
  --g-r-lg: 20px;
  --g-r-pill: 999px;
  --g-ease: cubic-bezier(.22, 1, .36, 1);
  --g-dur: 150ms;
}

/* ---------- Tokens: dark (system preference) ---------- */

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --g-canvas: oklch(17.5% 0.014 292);
    --g-surface: oklch(21% 0.017 292);
    --g-surface-2: oklch(24.5% 0.019 292);
    --g-surface-3: oklch(29% 0.021 292);
    --g-text: oklch(95% 0.008 292);
    --g-text-secondary: oklch(79% 0.014 292);
    --g-text-tertiary: oklch(65% 0.017 292);
    --g-border: oklch(32% 0.02 292);
    --g-border-subtle: oklch(27% 0.017 292);
    --g-accent: oklch(72% 0.1 294);
    --g-accent-strong: oklch(78% 0.115 294);
    --g-accent-hover: oklch(86% 0.09 294);
    --g-accent-soft: oklch(28% 0.045 294);
    --g-cta-fg: oklch(17.5% 0.03 294);
    --g-warning: oklch(84% 0.1 76);
    --g-warning-soft: oklch(28% 0.045 76);
    --g-warning-line: oklch(45% 0.08 76);

    --g-nav-bg: oklch(19% 0.016 292 / 84%);
    --g-shadow-card: 0 20px 48px -34px oklch(4% 0.02 294 / 72%), 0 2px 8px oklch(4% 0.02 294 / 32%);
    --g-hairline-top: inset 0 1px 0 oklch(100% 0 0 / 6%);
  }
}

/* ---------- Reset & page frame ---------- */

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

html,
body {
  margin: 0;
  width: 100%;
  min-width: 320px;
  min-height: 100%;
  overflow-x: clip;
}

html {
  background: var(--g-canvas);
  scrollbar-gutter: stable;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--g-canvas);
  color: var(--g-text);
  font-family: var(--g-font-sans);
  font-size: 1.0625rem;
  line-height: 1.7;
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

a {
  color: var(--g-accent-strong);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in oklch, var(--g-accent) 42%, transparent);
  text-underline-offset: 3px;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--g-dur) var(--g-ease),
              text-decoration-color var(--g-dur) var(--g-ease);
}

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

a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--g-accent);
  outline-offset: 3px;
  border-radius: 4px;
}

::selection {
  color: var(--g-cta-fg);
  background: var(--g-accent-strong);
}

/* ---------- .g-nav — top bar ---------- */

.g-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  width: 100%;
  border-bottom: 1px solid var(--g-border-subtle);
  background: var(--g-nav-bg);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
}

.g-nav-inner {
  width: min(100% - var(--g-gutter) * 2, var(--g-measure));
  min-height: 58px;
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.g-nav a {
  text-decoration: none;
}

/* wordmark → https://solback.app */
.g-nav a:first-child {
  color: var(--g-text);
  font-family: var(--g-font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.g-nav a:first-child:hover {
  color: var(--g-accent-strong);
}

/* "All guides" → /guides/ */
.g-nav a + a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding-inline: 0.85rem;
  border-radius: var(--g-r-pill);
  color: var(--g-text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  transition: color var(--g-dur) var(--g-ease),
              background-color var(--g-dur) var(--g-ease);
}

.g-nav a + a:hover,
.g-nav a + a[aria-current="page"] {
  color: var(--g-accent-strong);
  background: var(--g-accent-soft);
}

/* ---------- .g-wrap — content column ---------- */

.g-wrap {
  width: min(100% - var(--g-gutter) * 2, var(--g-measure));
  margin-inline: auto;
  padding-block: clamp(2rem, 6vw, 3.25rem) clamp(3rem, 8vw, 4.5rem);
}

/* ---------- .g-hero — h1 + standfirst ---------- */

.g-hero {
  margin-bottom: 2rem;
}

.g-hero h1 {
  margin: 0;
  font-family: var(--g-font-display);
  font-size: clamp(1.95rem, 1.35rem + 2.2vw, 2.85rem);
  font-weight: 700;
  line-height: 1.13;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

/* the standfirst: the bare <p> only, so a nested .g-meta keeps its own look */
.g-hero p:not([class]) {
  max-width: 60ch;
  margin: 0.9rem 0 0;
  color: var(--g-text-secondary);
  font-size: 1.1875rem;
  line-height: 1.6;
  text-wrap: pretty;
}

/* ---------- .g-meta — updated date + reading time ---------- */

.g-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.75rem;
  margin: 1.25rem 0 0;
  padding-top: 1.1rem;
  border-top: 1px solid var(--g-border-subtle);
  color: var(--g-text-tertiary);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.005em;
}

.g-meta > * + *::before {
  content: "·";
  margin-right: 0.75rem;
  color: var(--g-border);
}

/* ---------- Article body — bare elements inside .g-wrap ----------
   Selectors are written as :where(.g-wrap) el so they carry element-level
   specificity only. Any component class below (.g-meta, .g-note, .g-cta,
   .g-faq, .g-related, .g-card) therefore wins regardless of source order. */

:where(.g-wrap) h2,
:where(.g-wrap) h3 {
  font-family: var(--g-font-display);
  font-weight: 700;
  color: var(--g-text);
  letter-spacing: -0.03em;
  line-height: 1.22;
  scroll-margin-top: 5rem;
  text-wrap: balance;
}

:where(.g-wrap) h2 {
  margin: 2.75rem 0 0.85rem;
  font-size: clamp(1.4rem, 1.15rem + 1vw, 1.75rem);
}

:where(.g-wrap) h3 {
  margin: 2rem 0 0.6rem;
  font-size: 1.1875rem;
  letter-spacing: -0.025em;
}

:where(.g-wrap) p {
  margin: 0 0 1.15rem;
  text-wrap: pretty;
}

:where(.g-wrap) ul,
:where(.g-wrap) ol {
  margin: 0 0 1.15rem;
  padding-left: 1.35rem;
}

:where(.g-wrap) li {
  margin-bottom: 0.5rem;
  padding-left: 0.15rem;
}

:where(.g-wrap) li::marker {
  color: var(--g-text-tertiary);
}

:where(.g-wrap) li > ul,
:where(.g-wrap) li > ol {
  margin: 0.5rem 0 0;
}

:where(.g-wrap) strong {
  font-weight: 650;
  color: var(--g-text);
}

:where(.g-wrap) hr {
  height: 1px;
  margin: 2.5rem 0;
  border: 0;
  background: var(--g-border-subtle);
}

:where(.g-wrap) blockquote {
  margin: 1.5rem 0;
  padding-left: 1.1rem;
  border-left: 3px solid var(--g-border);
  color: var(--g-text-secondary);
}

/* Tables — always inside .g-scroll so the page itself never scrolls sideways */
:where(.g-wrap) table {
  width: 100%;
  min-width: 32rem;
  border-collapse: collapse;
  font-size: 0.9375rem;
  line-height: 1.55;
}

:where(.g-wrap) th,
:where(.g-wrap) td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--g-border-subtle);
  text-align: left;
  vertical-align: top;
}

:where(.g-wrap) thead th {
  border-bottom: 1px solid var(--g-border);
  background: var(--g-surface-2);
  color: var(--g-text-secondary);
  font-size: 0.8125rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

:where(.g-wrap) tbody tr:last-child td {
  border-bottom: 0;
}

/* Code */
:where(.g-wrap) code {
  padding: 0.12em 0.4em;
  border: 1px solid var(--g-border-subtle);
  border-radius: 6px;
  background: var(--g-surface-2);
  color: var(--g-text);
  font-family: var(--g-font-mono);
  font-size: 0.875em;
  overflow-wrap: anywhere;
}

:where(.g-wrap) pre {
  margin: 0 0 1.15rem;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  border: 1px solid var(--g-border-subtle);
  border-radius: var(--g-r-md);
  background: var(--g-surface-2);
  font-size: 0.875rem;
  line-height: 1.6;
}

:where(.g-wrap) pre code {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  font-size: inherit;
  overflow-wrap: normal;
}

/* ---------- .g-scroll — horizontal scroll container for tables ---------- */

.g-scroll {
  width: 100%;
  max-width: 100%;
  margin: 0 0 1.5rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border: 1px solid var(--g-border);
  border-radius: var(--g-r-md);
  background: var(--g-surface);
  -webkit-overflow-scrolling: touch;
}

.g-scroll > table {
  margin: 0;
}

/* ---------- .g-note — callout ---------- */

.g-note {
  margin: 1.6rem 0;
  padding: 1rem 1.15rem;
  border: 1px solid color-mix(in oklch, var(--g-accent) 26%, var(--g-border));
  border-radius: var(--g-r-md);
  background: var(--g-accent-soft);
  color: var(--g-text);
  font-size: 0.9375rem;
  line-height: 1.65;
}

.g-note > :first-child {
  margin-top: 0;
}

.g-note > :last-child {
  margin-bottom: 0;
}

.g-note p {
  margin-bottom: 0.6rem;
}

.g-note strong {
  color: var(--g-accent-strong);
}

/* optional variant for "this cannot be undone" style warnings */
.g-note.is-warning {
  border-color: var(--g-warning-line);
  background: var(--g-warning-soft);
}

.g-note.is-warning strong {
  color: var(--g-warning);
}

/* ---------- .g-cta — tool call-to-action box ---------- */

.g-cta {
  margin: 2.25rem 0;
  padding: clamp(1.25rem, 4vw, 1.75rem);
  border: 1px solid var(--g-border);
  border-radius: var(--g-r-lg);
  background: var(--g-surface);
  box-shadow: var(--g-shadow-card), var(--g-hairline-top);
  text-align: left;
}

.g-cta > :first-child {
  margin-top: 0;
}

.g-cta h2,
.g-cta h3,
.g-cta p strong {
  margin-top: 0;
}

.g-cta h2,
.g-cta h3 {
  margin-bottom: 0.5rem;
  font-family: var(--g-font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.25;
}

.g-cta p {
  max-width: 52ch;
  margin-bottom: 1.15rem;
  color: var(--g-text-secondary);
  font-size: 0.9375rem;
}

.g-cta p:last-of-type {
  margin-bottom: 1.25rem;
}

/* the button-styled link */
.g-cta a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding-inline: 1.5rem;
  border: 1px solid color-mix(in oklch, var(--g-accent-strong) 52%, var(--g-border));
  border-radius: var(--g-r-pill);
  background: var(--g-accent-strong);
  color: var(--g-cta-fg);
  font-size: 0.9375rem;
  font-weight: 650;
  letter-spacing: -0.005em;
  text-decoration: none;
  transition: background-color var(--g-dur) var(--g-ease),
              transform var(--g-dur) var(--g-ease);
}

.g-cta a:hover {
  background: var(--g-accent-hover);
  color: var(--g-cta-fg);
  transform: scale(.985);
}

.g-cta a + a {
  margin-left: 0.6rem;
}

.g-cta small {
  display: block;
  margin-top: 0.9rem;
  color: var(--g-text-tertiary);
  font-size: 0.8125rem;
  line-height: 1.55;
}

/* ---------- .g-faq — h2 + dl of dt/dd ---------- */

.g-faq {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--g-border-subtle);
}

.g-faq > h2 {
  margin-top: 0;
}

.g-faq dl {
  margin: 0;
}

.g-faq dt {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--g-border-subtle);
  color: var(--g-text);
  font-size: 1.0625rem;
  font-weight: 650;
  line-height: 1.45;
  letter-spacing: -0.015em;
  text-wrap: pretty;
}

.g-faq dt:first-of-type {
  margin-top: 0.5rem;
  padding-top: 0;
  border-top: 0;
}

.g-faq dd {
  margin: 0.55rem 0 0;
  color: var(--g-text-secondary);
  font-size: 0.9375rem;
  line-height: 1.7;
  text-wrap: pretty;
}

.g-faq dd > :first-child {
  margin-top: 0;
}

.g-faq dd > :last-child {
  margin-bottom: 0;
}

/* ---------- .g-related — related guides ---------- */

.g-related {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--g-border-subtle);
}

.g-related > h2 {
  margin-top: 0;
  font-size: 1.1875rem;
}

.g-related ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.5rem;
}

.g-related li {
  margin: 0;
  padding: 0;
}

.g-related a {
  display: block;
  padding: 0.85rem 1rem;
  border: 1px solid var(--g-border-subtle);
  border-radius: var(--g-r-md);
  background: var(--g-surface);
  color: var(--g-text);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.45;
  text-decoration: none;
  text-wrap: pretty;
  transition: border-color var(--g-dur) var(--g-ease),
              background-color var(--g-dur) var(--g-ease),
              color var(--g-dur) var(--g-ease);
}

.g-related a:hover {
  border-color: color-mix(in oklch, var(--g-accent) 34%, var(--g-border));
  background: var(--g-accent-soft);
  color: var(--g-accent-strong);
}

/* ---------- .g-cards / .g-card — directory page list ---------- */

.g-cards {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.85rem;
}

.g-cards > li {
  margin: 0;
  padding: 0;
}

.g-card {
  display: block;
  padding: clamp(1.1rem, 3.5vw, 1.5rem);
  border: 1px solid var(--g-border);
  border-radius: var(--g-r-lg);
  background: var(--g-surface);
  color: var(--g-text);
  text-decoration: none;
  box-shadow: var(--g-hairline-top);
  transition: border-color var(--g-dur) var(--g-ease),
              background-color var(--g-dur) var(--g-ease),
              box-shadow var(--g-dur) var(--g-ease),
              transform var(--g-dur) var(--g-ease);
}

.g-card:hover {
  border-color: color-mix(in oklch, var(--g-accent) 38%, var(--g-border));
  box-shadow: var(--g-shadow-card), var(--g-hairline-top);
  transform: translateY(-1px);
}

.g-card h2 {
  margin: 0;
  font-family: var(--g-font-display);
  font-size: 1.1875rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.028em;
  color: var(--g-text);
  text-wrap: pretty;
  transition: color var(--g-dur) var(--g-ease);
}

.g-card:hover h2 {
  color: var(--g-accent-strong);
}

.g-card p {
  margin: 0.5rem 0 0;
  color: var(--g-text-secondary);
  font-size: 0.9375rem;
  line-height: 1.6;
  text-wrap: pretty;
}

/* ---------- .g-footer ---------- */

.g-footer {
  border-top: 1px solid var(--g-border-subtle);
  background: var(--g-surface-2);
  color: var(--g-text-tertiary);
  font-size: 0.875rem;
}

.g-footer-inner {
  width: min(100% - var(--g-gutter) * 2, var(--g-measure));
  margin-inline: auto;
  padding-block: 1.75rem 2.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
}

.g-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
}

.g-footer a {
  color: var(--g-text-secondary);
  font-weight: 500;
  text-decoration: none;
}

.g-footer a:hover {
  color: var(--g-accent-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.g-footer p {
  margin: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 560px) {
  body {
    font-size: 1rem;
  }

  .g-nav-inner {
    min-height: 54px;
  }

  .g-hero p:not([class]) {
    font-size: 1.0625rem;
  }

  .g-footer-inner {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (pointer: coarse) {
  .g-nav a,
  .g-footer a {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }
}

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