/* ============================================================
   BackTheme — Base
   Load order: 1 tokens > [2 base] > 3 components > 4 mockups > 5 sections

   Reset, global element defaults, the typographic scale and the
   layout primitives every section is built from.

   Contents
     1. Reset & document defaults
     2. Focus & scrollbar
     3. Typography (.backtheme-serif, .backtheme-eyebrow, .backtheme-lead …)
     4. Layout primitives (.backtheme-container, .backtheme-section,
        .backtheme-section-header, .backtheme-stack, .backtheme-cluster)
     5. Decorative layers (.backtheme-glow, .backtheme-grid-backdrop,
        .backtheme-grain)
     6. Scroll reveal (.backtheme-reveal)
     7. Utilities

   Naming: every class is `backtheme-block__element--modifier`. The only
   un-prefixed classes in this project are the shared state flags
   (`is-*`, `has-*`, `no-js`), which are toggled by JavaScript and are
   always used compounded onto a namespaced block.
   ============================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--backtheme-header-h) + var(--backtheme-space-m));
  -moz-tab-size: 4;
  tab-size: 4;
}

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

body {
  background: var(--backtheme-bg);
  color: var(--backtheme-fg);
  font-family: var(--backtheme-font-sans);
  font-size: var(--backtheme-step-0);
  line-height: var(--backtheme-lh-normal);
  letter-spacing: var(--backtheme-tracking-normal);
  font-synthesis-weight: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv02' 1, 'cv03' 1, 'cv04' 1, 'ss01' 1;
  min-height: 100svh;
  overflow-x: hidden;
  transition: background-color var(--backtheme-dur-base) var(--backtheme-ease-out);
}

body.is-locked { overflow: hidden; }

img, svg, video, canvas, picture { display: block; max-width: 100%; height: auto; }
input, button, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { background: none; border: 0; cursor: pointer; }
p, h1, h2, h3, h4, h5, h6, li { overflow-wrap: break-word; }
ul, ol { list-style: none; padding: 0; }
a { color: inherit; text-decoration: none; }

::selection { background: var(--backtheme-brand-500); color: var(--backtheme-on-brand); }

/* ---------- Focus ---------- */
:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--backtheme-brand-500);
  outline-offset: 3px;
  border-radius: var(--backtheme-r-xs);
}

/* ---------- Scrollbar ---------- */
@supports selector(::-webkit-scrollbar) {
  ::-webkit-scrollbar { width: 11px; height: 11px; }
  ::-webkit-scrollbar-track { background: var(--backtheme-bg); }
  ::-webkit-scrollbar-thumb {
    background: var(--backtheme-surface-4);
    border-radius: var(--backtheme-r-full);
    border: 3px solid var(--backtheme-bg);
  }
  ::-webkit-scrollbar-thumb:hover { background: var(--backtheme-fg-subtle); }
}

html { scrollbar-color: var(--backtheme-surface-4) var(--backtheme-bg); }

/* ============================================================
   Typography
   ============================================================ */

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: var(--backtheme-lh-heading);
  letter-spacing: var(--backtheme-tracking-tight);
  text-wrap: balance;
}

h1 { font-size: var(--backtheme-step-6); line-height: var(--backtheme-lh-tight); letter-spacing: var(--backtheme-tracking-tighter); }
h2 { font-size: var(--backtheme-step-5); line-height: var(--backtheme-lh-snug); letter-spacing: var(--backtheme-tracking-tighter); }
h3 { font-size: var(--backtheme-step-3); }
h4 { font-size: var(--backtheme-step-2); }
h5 { font-size: var(--backtheme-step-1); }
h6 { font-size: var(--backtheme-step-0); }

p { text-wrap: pretty; }
strong, b { font-weight: 600; color: var(--backtheme-fg); }

/* Editorial serif accent — the one flourish in the type system. */
.backtheme-serif {
  font-family: var(--backtheme-font-serif);
  font-style: italic;
  font-weight: 400;
  letter-spacing: -0.012em;
}

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

.backtheme-brand-text { color: var(--backtheme-brand-ink); }

/* Two-tone heading: the continuation drops to muted, so a long
   headline reads as statement + elaboration rather than one block. */
.backtheme-dim { color: var(--backtheme-fg-muted); }

/* Mono label for eyebrows and step numbers. */
.backtheme-eyebrow {
  display: inline-flex;
  /* flex-start, not center: when the label wraps to two lines the dot must
     stay beside the FIRST line rather than floating at the block's midpoint. */
  align-items: flex-start;
  gap: var(--backtheme-space-2xs);
  font-family: var(--backtheme-font-mono);
  font-size: var(--backtheme-step--1);
  font-weight: 500;
  letter-spacing: var(--backtheme-tracking-wide);
  color: var(--backtheme-brand-ink);
}

.backtheme-eyebrow::before {
  content: '';
  width: 6px;
  height: 6px;
  margin-top: .58em;   /* optically centres the dot on the first line */
  border-radius: var(--backtheme-r-full);
  background: var(--backtheme-brand-500);
  box-shadow: 0 0 0 4px light-dark(rgba(0,163,255,.13), rgba(0, 163, 255, .16));
  flex: none;
}

.backtheme-eyebrow--plain::before { display: none; }

.backtheme-lead {
  font-size: var(--backtheme-step-1);
  line-height: var(--backtheme-lh-relaxed);
  color: var(--backtheme-fg-muted);
  max-width: 62ch;
}

.backtheme-muted { color: var(--backtheme-fg-muted); }
.backtheme-subtle { color: var(--backtheme-fg-subtle); }

/* ============================================================
   Layout primitives
   ============================================================ */

.backtheme-container {
  width: 100%;
  max-width: var(--backtheme-container);
  margin-inline: auto;
  padding-inline: var(--backtheme-gutter);
}

.backtheme-container--wide { max-width: var(--backtheme-container-wide); }
.backtheme-container--narrow { max-width: 880px; }

.backtheme-section { padding-block: var(--backtheme-section-y); position: relative; }
.backtheme-section--tight { padding-block: clamp(3rem, 2.2rem + 4vw, 5.5rem); }
.backtheme-section--flush-top { padding-top: 0; }
.backtheme-section--alt { background: var(--backtheme-bg-subtle); border-block: 1px solid var(--backtheme-line); }

/* ---------- Section heading block ----------
   Left-aligned by default. Centering every section head is the single
   fastest way to make a page look templated. */
.backtheme-section-header {
  display: flex;
  flex-direction: column;
  gap: var(--backtheme-space-s);
  max-width: 62ch;
  margin-bottom: var(--backtheme-space-2xl);
}

.backtheme-section-header--center {
  align-items: center;
  text-align: center;
  margin-inline: auto;
}

/* Heading on the left, an accessory (link, button, note) on the right. */
.backtheme-section-header--split {
  max-width: none;
  flex-direction: column;
  /* stretch, not flex-start: a shrink-to-fit child (the portfolio filter
     bar is ~650px of tabs) would otherwise size the column to its own
     content and push the whole mobile layout wider than the device. */
  align-items: stretch;
  gap: var(--backtheme-space-m);
}

.backtheme-section-header__aside { max-width: 100%; min-width: 0; }

.backtheme-section-header--split .backtheme-section-header__main {
  display: flex;
  flex-direction: column;
  gap: var(--backtheme-space-s);
  max-width: 62ch;
}

/* 1200px, not 900px. The portfolio's filter bar is ~670px wide; beside
   a heading at 900px it left the title 178px and pushed the bar past the
   content edge. Below this width the aside takes its own full-width row. */
@media (min-width: 1200px) {
  .backtheme-section-header--split {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--backtheme-space-l);
  }
  .backtheme-section-header--split .backtheme-section-header__aside {
    padding-bottom: 6px;
    flex: 0 1 auto;
    min-width: 0;
    display: flex;
    justify-content: flex-end;
  }
}

.backtheme-section-header__title { font-size: var(--backtheme-step-5); }

.backtheme-stack { display: flex; flex-direction: column; }
.backtheme-stack > * + * { margin-top: var(--flow, var(--backtheme-space-s)); }
.backtheme-grid { display: grid; gap: var(--backtheme-space-m); }
.backtheme-cluster { display: flex; flex-wrap: wrap; gap: var(--backtheme-space-xs); align-items: center; }

.backtheme-rule { height: 1px; border: 0; background: var(--backtheme-grad-line); margin: 0; }

/* ============================================================
   Decorative background layers
   ============================================================ */

.backtheme-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  opacity: var(--backtheme-glow-opacity);
  z-index: 0;
}

.backtheme-glow--brand  { background: radial-gradient(circle, var(--backtheme-glow-brand) 0%, transparent 70%); }
.backtheme-glow--accent { background: radial-gradient(circle, var(--backtheme-glow-accent) 0%, transparent 70%); }

/* Faint technical grid. */
.backtheme-grid-backdrop {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(to right, var(--backtheme-grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--backtheme-grid-line) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse 80% 62% at 50% 0%, #000 30%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse 80% 62% at 50% 0%, #000 30%, transparent 78%);
}

/* Film grain — keeps large flat areas from banding. */
.backtheme-grain::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: var(--backtheme-grain-opacity);
  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='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ============================================================
   Scroll reveal
   ============================================================ */

.backtheme-reveal {
  opacity: 0;
  transform: translate3d(0, 22px, 0);
  transition:
    opacity var(--backtheme-dur-slower) var(--backtheme-ease-out),
    transform var(--backtheme-dur-slower) var(--backtheme-ease-out);
  transition-delay: var(--reveal-delay, 0ms);
  will-change: opacity, transform;
}

.backtheme-reveal.is-visible { opacity: 1; transform: translate3d(0, 0, 0); }

/* If JS never runs, nothing should stay invisible. */
.no-js .backtheme-reveal { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .backtheme-reveal { opacity: 1; transform: none; transition: none; }
}

/* ============================================================
   Utilities
   ============================================================ */

.backtheme-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.backtheme-skip-link {
  position: absolute;
  top: var(--backtheme-space-s);
  left: var(--backtheme-space-s);
  z-index: var(--backtheme-z-toast);
  padding: var(--backtheme-space-2xs) var(--backtheme-space-s);
  background: var(--backtheme-brand-500);
  color: var(--backtheme-on-brand);
  font-weight: 600;
  border-radius: var(--backtheme-r-sm);
  transform: translateY(-160%);
  transition: transform var(--backtheme-dur-base) var(--backtheme-ease-out);
}

.backtheme-skip-link:focus-visible { transform: translateY(0); }

.backtheme-relative { position: relative; }
.backtheme-z-raised { position: relative; z-index: var(--backtheme-z-raised); }
.backtheme-text-center { text-align: center; }
.backtheme-mx-auto { margin-inline: auto; }
