/* ============================================================
   SOFTWARE DEFECTS — a field guide to stateful bugs
   Design: "diagnostic console". Dark consoles + cool reading
   surfaces, monospace labels as structure, four meaningful
   category accents, code viewers as editor windows.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@400;500;600&family=Noto+Sans+Arabic:wght@400;500;600;700&family=JetBrains+Mono:ital,wght@0,400;0,700;1,400;1,700&display=swap');

:root {
  /* surfaces */
  --ink:         #0E1116;
  --ink-raised:  #161B22;
  --ink-code:    #10151C;
  --ink-line:    rgba(255,255,255,0.09);
  --paper:       #F1F3F6;
  --paper-raised:#FFFFFF;
  --line:        #E2E6EC;

  /* text */
  --text:          #161B22;
  --text-soft:     #515C6B;
  --text-faint:    #8B95A3;
  --on-dark:       #E7EBF0;
  --on-dark-soft:  #97A3B4;
  --on-dark-faint: #5C6776;

  /* category accents */
  --mutated:        #78A65A;  --mutated-deep:#4F7942;  --mutated-soft:#93C47D;
  --unstructured:   #3D85C6;  --unstructured-deep:#0B5394; --unstructured-soft:#6FA8DC;
  --shared:         #DD3333;  --shared-deep:#B91C1C;   --shared-soft:#F87171;
  --common:         #94A3B8;  --common-deep:#64748B;   --common-soft:#CBD5E1;
  --compound:       #C9A227;  --compound-deep:#8A6D1B; --compound-soft:#E6CF6A;
  --compound-nd:    #FFE599;  --compound-rt:#9FC5E8;   --compound-dc:#C27BA0;
  --danger:         #EF4444;
  --good:           #22C55E;

  /* type */
  --display: 'Space Grotesk', system-ui, sans-serif;
  --body:    'Inter', system-ui, sans-serif;
  --mono:    'JetBrains Mono', ui-monospace, 'Courier New', monospace;

  --wrap: 1120px;
  --radius: 14px;
}

*,*::before,*::after { box-sizing: border-box; margin:0; padding:0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--body);
  color: var(--text);
  background: var(--paper);
  line-height: 1.62;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img,svg { max-width: 100%; display: block; }
::selection { background: rgba(120,166,90,.24); }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 1.5rem; }

/* mono "diagnostic" label, the page's structural device */
.tag {
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 500;
}

/* ============================================================ HEADER */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(14,17,22,.86);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--ink-line);
}
.nav {
  max-width: var(--wrap); margin: 0 auto;
  display: flex; align-items: center; gap: 1.25rem;
  padding: .7rem 1.5rem;
}
.brand {
  display: flex; align-items: center; gap: .6rem;
  font-family: var(--display); font-weight: 700; font-size: 1.02rem;
  color: var(--on-dark); white-space: nowrap;
}
.brand .glyph { width: 26px; height: 26px; flex: none; }
.brand small {
  font-family: var(--mono); font-weight: 400; font-size: .62rem;
  color: var(--on-dark-faint); letter-spacing: .12em; text-transform: uppercase;
}
.nav-links {
  display: flex; list-style: none; gap: .15rem; margin-left: auto; align-items: center;
}
.nav-links a {
  display: block; padding: .4rem .7rem; border-radius: 8px;
  font-size: .85rem; font-weight: 500; color: var(--on-dark-soft);
  transition: color .15s, background .15s;
  border: 1px solid transparent;
}
.nav-links a::before {
  content: ""; display: inline-block; width: 7px; height: 7px;
  border-radius: 2px; margin-right: .5rem; vertical-align: middle;
  background: var(--c, var(--on-dark-faint)); opacity: .85;
}
.nav-links a:hover, .nav-links a[aria-current="page"] {
  color: var(--on-dark); background: rgba(255,255,255,.05);
}
.nav-links a[aria-current="page"] { border-color: var(--ink-line); }
.nav--mutated      { --c: var(--mutated); }
.nav--unstructured { --c: var(--unstructured); }
.nav--shared       { --c: var(--shared); }
.nav--common       { --c: var(--common); }
.nav--compound     { --c: var(--compound); }
/* the compound chip rotates through the full wheel of stateful + compound hues:
   green -> cyan -> blue -> magenta -> red -> yellow -> (loop). background is
   animatable (custom properties are not, without @property), so drive it here. */
.nav--compound::before { animation: compound-chip 6s linear infinite; }
@keyframes compound-chip {
  0%, 100% { background: var(--mutated); }       /* green   */
  17%      { background: var(--compound-rt); }   /* cyan    */
  33%      { background: var(--unstructured); }  /* blue    */
  50%      { background: var(--compound-dc); }   /* magenta */
  67%      { background: var(--shared); }         /* red     */
  83%      { background: var(--compound-nd); }   /* yellow  */
}
@media (prefers-reduced-motion: reduce) {
  .nav--compound::before { animation: none; }
}

.lang-select {
  font-family: var(--mono); font-size: .72rem; letter-spacing: .08em;
  background: transparent; color: var(--on-dark-soft);
  border: 1px solid var(--ink-line); border-radius: 8px;
  padding: .35rem .5rem; cursor: pointer; margin-left: .4rem;
}
.lang-select option { color: #000; }
.nav-toggle {
  display: none; margin-left: auto; background: transparent;
  border: 1px solid var(--ink-line); border-radius: 8px;
  color: var(--on-dark); width: 38px; height: 34px; cursor: pointer;
}

/* ============================================================ HERO (console) */
.console {
  background:
    radial-gradient(120% 80% at 80% -10%, rgba(168,85,247,.10), transparent 60%),
    radial-gradient(90% 70% at 0% 0%, rgba(59,130,246,.10), transparent 55%),
    var(--ink);
  color: var(--on-dark);
  position: relative; overflow: hidden;
  border-bottom: 1px solid var(--ink-line);
}
.console::after { /* faint scanline grid */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(var(--ink-line) 1px, transparent 1px);
  background-size: 100% 30px; opacity: .35; mask-image: linear-gradient(#000, transparent 75%);
}
.hero { padding: 5.5rem 0 4rem; position: relative; z-index: 1; }
.hero__eyebrow { color: var(--on-dark-faint); margin-bottom: 1.4rem; }
.hero__eyebrow b { color: var(--mutated-soft); font-weight: 500; }
.hero__title {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(2.5rem, 6.2vw, 4.6rem); line-height: 1.02;
  letter-spacing: -.02em; max-width: 16ch;
}
.hero__title .stink {
  background: linear-gradient(100deg, var(--mutated), var(--danger));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero__sub {
  margin-top: 1.4rem; max-width: 52ch; color: var(--on-dark-soft);
  font-size: 1.08rem;
}

/* cascade strip: smell -> defect -> vulnerability */
.cascade { margin-top: 3rem; display: grid; gap: 1px;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  background: var(--ink-line); border: 1px solid var(--ink-line);
  border-radius: var(--radius); overflow: hidden; }
.cascade__cell { background: var(--ink-raised); padding: 1.1rem 1.2rem; }
.cascade__cell h4 { font-family: var(--display); font-size: 1.02rem; font-weight: 600; }
.cascade__cell p { font-size: .82rem; color: var(--on-dark-soft); margin-top: .35rem; line-height: 1.5; }
.cascade__cell:nth-child(5) h4 { color: var(--danger); }
.cascade__arrow {
  background: var(--ink-raised); display: grid; place-items: center;
  color: var(--on-dark-faint); font-size: 1.1rem; padding: 0 .4rem;
}
.cascade__num { font-family: var(--mono); font-size: .68rem; color: var(--on-dark-faint); }

/* ============================================================ CATEGORY GRID */
.section { padding: 4.5rem 0; }
.section__head { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 2rem; }
.section__head .tag { color: var(--text-faint); }
.section__head h2 {
  font-family: var(--display); font-weight: 600; letter-spacing: -.01em;
  font-size: clamp(1.5rem, 3vw, 2.1rem);
}
.section--dark { background: var(--ink); color: var(--on-dark); }
.section--dark .section__head h2 { color: var(--on-dark); }

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.1rem; }
.card {
  position: relative; background: var(--paper-raised);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.5rem 1.5rem 1.3rem; overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s;
  display: flex; gap: 1.3rem; align-items: flex-start;
}
.card::before { /* category spine */
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--c);
}
.card:hover { transform: translateY(-3px); box-shadow: 0 14px 34px rgba(20,28,40,.12);
  border-color: color-mix(in srgb, var(--c) 45%, var(--line)); }
.card__glyph {
  flex: none; width: 92px; height: 92px; border-radius: 12px;
  background: color-mix(in srgb, var(--c) 9%, var(--paper-raised));
  border: 1px solid color-mix(in srgb, var(--c) 22%, var(--line));
}
.card__body { flex: 1; min-width: 0; }
.card__kicker { color: var(--cd); margin-bottom: .5rem; }
.card__title { font-family: var(--display); font-weight: 600; font-size: 1.28rem; letter-spacing: -.01em; }
.card__desc { color: var(--text-soft); font-size: .92rem; margin-top: .4rem; }
.card__symptoms { list-style: none; margin-top: .9rem; display: flex; flex-wrap: wrap; gap: .4rem; }
.card__symptoms li {
  font-family: var(--mono); font-size: .7rem; color: var(--text-soft);
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 99px; padding: .2rem .6rem;
}
.card__link {
  display: inline-flex; align-items: center; gap: .35rem; margin-top: 1.1rem;
  font-weight: 600; font-size: .9rem; color: var(--cd);
}
.card__link svg { width: 15px; height: 15px; transition: transform .15s; }
.card:hover .card__link svg { transform: translateX(3px); }

.card--mutated      { --c: var(--mutated); --cd: var(--mutated-deep); }
.card--unstructured { --c: var(--unstructured); --cd: var(--unstructured-deep); }
.card--shared       { --c: var(--shared); --cd: var(--shared-deep); }
.card--common       { --c: var(--common); --cd: var(--common-deep); }
.card--compound     { --c: var(--compound); --cd: var(--compound-deep); }

/* ============================================================ CONTEXT BAND */
.context p { max-width: 60ch; color: var(--on-dark-soft); font-size: 1.05rem; }
.context__grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 1px;
  margin-top: 2rem; background: var(--ink-line); border: 1px solid var(--ink-line);
  border-radius: var(--radius); overflow: hidden; }
.context__cell { background: var(--ink-raised); padding: 1.4rem; }
.context__cell .tag { color: var(--mutated-soft); }
.context__cell p { color: var(--on-dark); font-size: .95rem; margin-top: .6rem; max-width: none; }
.context__cell p strong { color: var(--danger); }

/* "two hard problems" easter egg strip */
.two-hard { padding: 2.5rem 0; background: var(--ink); color: var(--on-dark); border-top: 1px solid var(--ink-line); }
.two-hard__inner { display: flex; flex-wrap: wrap; align-items: baseline; gap: .4rem 1rem; }
.two-hard__lead { font-family: var(--mono); font-size: .8rem; color: var(--on-dark-faint); }
.two-hard__list { font-family: var(--display); font-size: clamp(1.05rem,2.4vw,1.5rem); font-weight: 500; }
.two-hard__list ol { list-style: none; display: inline; counter-reset: th; }
.two-hard__list li { display: inline; }
.two-hard__list li::before { counter-increment: th; content: counter(th) ". "; color: var(--mutated-soft); font-family: var(--mono); font-size: .8em; }
.two-hard__list li:not(:last-child)::after { content: ",  "; color: var(--on-dark-faint); }

/* ============================================================ DEFECT HERO */
.dhero { padding: 4.5rem 0 3.5rem; position: relative; z-index: 1; }
.dhero__grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 2.5rem; align-items: center; }
.dhero__kicker { color: var(--accent-soft); margin-bottom: 1rem; }
.dhero__title { font-family: var(--display); font-weight: 700; letter-spacing: -.02em;
  font-size: clamp(2.1rem, 4.5vw, 3.3rem); line-height: 1.04; }
.dhero__desc { margin-top: 1.1rem; color: var(--on-dark-soft); font-size: 1.06rem; max-width: 46ch; }
.dhero__essence {
  margin-top: 1.6rem; padding-left: 1rem; border-left: 3px solid var(--accent);
  font-family: var(--display); font-size: 1.12rem; font-weight: 500; color: var(--on-dark); max-width: 44ch;
}
.dhero__art {
  aspect-ratio: 1; border-radius: var(--radius);
  background:
    radial-gradient(80% 80% at 50% 40%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    var(--ink-raised);
  border: 1px solid var(--ink-line); display: grid; place-items: center;
}
.dhero__art .lottie-glyph { width: 78%; height: 78%; }

/* ============================================================ DEFECT BODY */
.defect-body { padding: 3.5rem 0 1rem; }
.block { margin-bottom: 3.2rem; }
.block__head { display: flex; align-items: center; gap: .7rem; margin-bottom: 1.2rem; }
.block__head .num { font-family: var(--mono); font-size: .72rem; color: var(--accent-deep);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line)); border-radius: 6px;
  padding: .15rem .45rem; background: color-mix(in srgb, var(--accent) 7%, var(--paper-raised)); }
.block__head h2 { font-family: var(--display); font-weight: 600; font-size: 1.4rem; letter-spacing: -.01em; }
.block__intro { color: var(--text-soft); max-width: 64ch; margin: -.4rem 0 1.3rem; }

/* symptoms */
.symptoms { list-style: none; display: grid; gap: .55rem; }
.symptoms li { display: flex; gap: .7rem; align-items: flex-start; font-size: 1rem; }
.symptoms li::before {
  content: ""; flex: none; width: 8px; height: 8px; margin-top: .55rem;
  border-radius: 2px; background: var(--accent); transform: rotate(45deg);
}

/* causes chips */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chips span {
  font-family: var(--mono); font-size: .8rem; color: var(--text);
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: 8px; padding: .4rem .7rem;
  border-left: 3px solid color-mix(in srgb, var(--accent) 55%, var(--line));
}

/* ============================================================ CODE VIEWER */
.example { margin-bottom: 1.8rem; }
.example__title { font-family: var(--display); font-weight: 600; font-size: 1.08rem; margin-bottom: .3rem; }
.example__intro { color: var(--text-soft); font-size: .92rem; margin-bottom: .8rem; max-width: 70ch; }
.code-viewer { border-radius: 12px; overflow: hidden; border: 1px solid var(--ink-line);
  background: var(--ink-code); box-shadow: 0 10px 30px rgba(16,21,28,.16); }
.code-window {
  display: flex; align-items: center; gap: .8rem;
  padding: .55rem .9rem; background: #0B0F15; border-bottom: 1px solid var(--ink-line);
}
.code-window .dots { display: flex; gap: 6px; }
.code-window .dots i { width: 11px; height: 11px; border-radius: 50%; display: block; }
.code-window .dots i:nth-child(1){ background:#FF5F57; }
.code-window .dots i:nth-child(2){ background:#FEBC2E; }
.code-window .dots i:nth-child(3){ background:#28C840; }
.lang-tabs { display: flex; gap: .15rem; overflow-x: auto; scrollbar-width: none; }
.lang-tabs::-webkit-scrollbar { display: none; }
.lang-tab {
  font-family: var(--mono); font-size: .76rem; color: var(--on-dark-faint);
  background: transparent; border: none; border-radius: 7px;
  padding: .3rem .65rem; cursor: pointer; white-space: nowrap;
  transition: color .12s, background .12s; border: 1px solid transparent;
}
.lang-tab:hover { color: var(--on-dark-soft); }
.lang-tab.is-active {
  color: var(--accent-soft);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-color: color-mix(in srgb, var(--accent) 36%, transparent);
}
.code-panel { display: none; }
.code-panel.is-active { display: block; }
.code-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: .45rem .9rem; border-bottom: 1px solid var(--ink-line);
}
.code-head .fname { font-family: var(--mono); font-size: .72rem; color: var(--on-dark-faint); }
.copy-btn {
  font-family: var(--mono); font-size: .68rem; letter-spacing: .06em;
  color: var(--on-dark-soft); background: rgba(255,255,255,.05);
  border: 1px solid var(--ink-line); border-radius: 6px;
  padding: .22rem .55rem; cursor: pointer; transition: all .12s;
}
.copy-btn:hover { color: var(--on-dark); background: rgba(255,255,255,.1); }
.copy-btn.is-copied { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.code-panel pre { margin: 0; padding: 1.1rem 1.2rem; overflow-x: auto;
  font-family: var(--mono); font-size: .82rem; line-height: 1.62; }
.code-panel pre code { font-family: inherit; }
.code-explain { padding: .9rem 1.2rem; border-top: 1px solid var(--ink-line);
  color: var(--on-dark-soft); font-size: .88rem; }
.code-out { padding: .8rem 1.2rem 1rem; border-top: 1px solid var(--ink-line);
  background: #0B0F15; }
.code-out .tag { color: var(--on-dark-faint); display: block; margin-bottom: .4rem; }
.code-out pre { padding: 0; font-size: .76rem; color: var(--on-dark-soft); background: none; }

/* ============================================================ SPECIAL BLOCKS */
/* pullquote */
.pullquote { border: 1px solid var(--line); border-left: 4px solid var(--accent);
  background: var(--paper-raised); border-radius: var(--radius); padding: 1.8rem 2rem; }
.pullquote q { font-family: var(--display); font-size: 1.3rem; font-weight: 500; line-height: 1.4; }
.pullquote q::before, .pullquote q::after { color: var(--accent); }
.pullquote cite { display: block; margin-top: .9rem; font-style: normal;
  font-family: var(--mono); font-size: .76rem; color: var(--text-faint); }

/* case study */
.casefile { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: var(--paper-raised); }
.casefile__head { padding: 1.3rem 1.6rem; background: var(--ink); color: var(--on-dark);
  display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .5rem; }
.casefile__head h3 { font-family: var(--display); font-size: 1.3rem; font-weight: 600; }
.casefile__head .meta { font-family: var(--mono); font-size: .76rem; color: var(--danger); }
.casefile__body { padding: 1.5rem 1.6rem; }
.casefile__body > p { color: var(--text-soft); }
.casefile__points { list-style: none; margin: 1.1rem 0; display: grid; gap: .55rem; }
.casefile__points li { display: flex; gap: .6rem; font-size: .94rem; }
.casefile__points li::before { content: "\2192"; color: var(--accent-deep); font-weight: 700; }
.casefile__kicker { font-family: var(--display); font-weight: 600; font-size: 1.05rem; }
.casefile__link { font-family: var(--mono); font-size: .74rem; color: var(--accent-deep); margin-top: .8rem; display: inline-block; }

/* rules of thumb */
.rules { display: grid; grid-template-columns: repeat(3,1fr); gap: 1rem; }
.rules__card { border: 1px solid var(--line); border-radius: 12px; background: var(--paper-raised);
  padding: 1.3rem; border-top: 3px solid var(--accent); }
.rules__card h4 { font-family: var(--mono); font-size: .9rem; letter-spacing: .04em; text-transform: uppercase;
  color: var(--accent-deep); margin-bottom: .6rem; }
.rules__card p { font-size: .9rem; color: var(--text-soft); }

/* comparison tables (analogy / deadlock / spectrum) */
.ctable { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--paper-raised); }
.ctable__cap { padding: .8rem 1.3rem; font-size: .88rem; color: var(--text-soft);
  border-bottom: 1px solid var(--line); background: var(--paper); }
.ctable__row { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 0;
  border-bottom: 1px solid var(--line); }
.ctable__row:last-child { border-bottom: none; }
.ctable__row > div { padding: 1rem 1.3rem; border-right: 1px solid var(--line); }
.ctable__row > div:last-child { border-right: none; }
.ctable__a { font-family: var(--display); font-weight: 600; color: var(--accent-deep); }
.ctable__b { font-family: var(--display); font-weight: 500; color: var(--text); }
.ctable__n { font-size: .88rem; color: var(--text-soft); }
.ctable__head { background: var(--ink); color: var(--on-dark); font-family: var(--mono);
  font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; }
.ctable__head > div { color: var(--on-dark-faint); padding: .6rem 1.3rem; border-right: 1px solid var(--ink-line); }

/* name qualities */
.qualities { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: .8rem; }
.qualities__item { border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.1rem; background: var(--paper-raised); }
.qualities__item b { font-family: var(--display); font-size: 1rem; }
.qualities__item span { display: block; font-size: .85rem; color: var(--text-soft); margin-top: .2rem; }
.qualities__rule { margin-top: 1.1rem; font-family: var(--mono); font-size: .82rem; color: var(--text-soft);
  border-left: 3px solid var(--accent); padding-left: .9rem; }

/* ============================================================ META GRID */
.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-top: 1rem; }
.meta-list { list-style: none; display: grid; gap: .5rem; }
.meta-list li code { font-family: var(--mono); font-size: .82rem; color: var(--text);
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: 7px;
  padding: .3rem .6rem; display: inline-block; }
.phil-list { list-style: none; display: grid; gap: .5rem; }
.phil-list a, .phil-list span { font-size: .95rem; display: inline-flex; align-items: center; gap: .4rem; }
.phil-list a { color: var(--accent-deep); font-weight: 500; }
.phil-list a::after { content: "\2197"; font-family: var(--mono); font-size: .85em; opacity: .7; }

.back { display: inline-flex; align-items: center; gap: .5rem; margin: 1rem 0 3rem;
  font-family: var(--mono); font-size: .82rem; color: var(--text-faint); }
.back:hover { color: var(--text); }

/* defect cross-nav */
.xnav { display: grid; grid-template-columns: repeat(3,1fr); gap: .8rem; margin: 1rem 0 3.5rem; }
.xnav a { border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.1rem;
  background: var(--paper-raised); border-left: 3px solid var(--c); transition: transform .15s; }
.xnav a:hover { transform: translateY(-2px); }
.xnav a .tag { color: var(--cd); }
.xnav a b { font-family: var(--display); display: block; margin-top: .25rem; }
.xnav--mutated{--c:var(--mutated);--cd:var(--mutated-deep);}
.xnav--unstructured{--c:var(--unstructured);--cd:var(--unstructured-deep);}
.xnav--shared{--c:var(--shared);--cd:var(--shared-deep);}
.xnav--common{--c:var(--common);--cd:var(--common-deep);}
.xnav--compound{--c:var(--compound);--cd:var(--compound-deep);}

/* ============================================================ COMPOUND RECIPE
   the "A x B" ingredient link pair + chained CWE chips above a compound
   defect's code example. Each ingredient is tinted by its source family. */
.recipe { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .7rem;
  margin: 0 0 1rem; padding: .7rem .9rem; border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 6%, var(--paper-raised)); }
.recipe__lbl { font-family: var(--mono); font-size: .68rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent-deep); }
.recipe__pair { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .5rem .7rem; }
/* each ingredient + the base CWE chips it carries travel together */
.recipe__group { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.recipe__ing { font-family: var(--display); font-weight: 600; font-size: .9rem;
  color: var(--ck, var(--ink)); text-decoration: none;
  border-bottom: 2px solid color-mix(in srgb, var(--ck, var(--accent)) 45%, transparent); }
.recipe__ing:hover { border-bottom-color: var(--ck, var(--accent)); }
.recipe__ing--mutated      { --ck: var(--mutated-deep); }
.recipe__ing--unstructured { --ck: var(--unstructured-deep); }
.recipe__ing--shared       { --ck: var(--shared-deep); }
.recipe__ing--common       { --ck: var(--common-deep); }
.recipe__ing-cwes { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
/* base chips are tinted by their originating bug's family, not the page accent */
.recipe__ing-cwes .recipe__cwe { color: var(--ck, var(--accent-deep));
  border-color: color-mix(in srgb, var(--ck, var(--accent)) 32%, var(--line));
  background: color-mix(in srgb, var(--ck, var(--accent)) 8%, transparent); }
.recipe__ing-cwes .recipe__cwe:hover { border-color: var(--ck, var(--accent)); }
.recipe__x { font-family: var(--mono); color: var(--text-faint); font-weight: 700; }
.recipe__cwes { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .35rem .5rem; }
.recipe__cwe-short { opacity: .7; font-weight: 500; }
.recipe__cwe-grp { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.recipe__cwe-lbl { font-family: var(--mono); font-size: .6rem; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-faint); }
.recipe__cwe-arrow { font-family: var(--mono); color: var(--text-faint); font-weight: 700; }
.recipe__cwe { font-family: var(--mono); font-size: .7rem; text-decoration: none;
  color: var(--accent-deep); padding: .12rem .4rem; border-radius: 5px;
  border: 1px solid color-mix(in srgb, var(--accent) 32%, var(--line));
  background: color-mix(in srgb, var(--accent) 8%, transparent); }
.recipe__cwe:hover { border-color: var(--accent); }
/* the emergent compound weakness reads as filled, distinct from its base parts */
.recipe__cwe--compound { color: var(--paper); border-color: var(--accent-deep);
  background: var(--accent-deep); font-weight: 600; }
.recipe__cwe--compound:hover { border-color: var(--accent-deep);
  background: color-mix(in srgb, var(--accent-deep) 85%, #000); }

/* ============================================================ FOOTER */
.site-footer { background: var(--ink); color: var(--on-dark-soft); padding: 3rem 0;
  border-top: 1px solid var(--ink-line); }
.site-footer__inner { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 1.5rem; align-items: flex-start; }
.site-footer p { max-width: 40ch; font-size: .92rem; }
.site-footer em { color: var(--mutated-soft); font-style: normal; }
.site-footer .flinks { display: flex; flex-wrap: wrap; gap: 1rem; font-family: var(--mono); font-size: .78rem; }
.site-footer .flinks a:hover { color: var(--on-dark); }

/* ============================================================ RESPONSIVE */
@media (max-width: 860px) {
  .dhero__grid { grid-template-columns: 1fr; }
  .dhero__art { max-width: 320px; }
  .cards, .context__grid, .rules, .meta-grid, .xnav { grid-template-columns: 1fr; }
  .cascade { grid-template-columns: 1fr; }
  .cascade__arrow { padding: .3rem; transform: rotate(90deg); }
  .ctable__row, .ctable__head { grid-template-columns: 1fr; }
  .ctable__row > div, .ctable__head > div { border-right: none; border-bottom: 1px solid var(--line); }
  .ctable__head { display: none; }
}
@media (max-width: 720px) {
  .nav-toggle { display: block; }
  .nav-links { display: none; position: absolute; left: 0; right: 0; top: 100%;
    flex-direction: column; align-items: stretch; gap: 0; padding: .5rem;
    background: var(--ink); border-bottom: 1px solid var(--ink-line); }
  .nav-links.is-open { display: flex; }
  .nav-links a { padding: .7rem .8rem; }
  .lang-select { margin: .4rem 0 0; }
  .card { flex-direction: column; }
  .card__glyph { width: 72px; height: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* keyboard focus */
a:focus-visible, button:focus-visible, select:focus-visible, .lang-tab:focus-visible {
  outline: 2px solid var(--mutated-soft); outline-offset: 2px; border-radius: 4px;
}

/* ============================================================ SUB-DEFECT HUB */
/* breadcrumb on a child-defect hero */
.dcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  margin-bottom: 1rem; color: var(--on-dark-faint); }
.dcrumb a { color: var(--accent-soft); }
.dcrumb a:hover { text-decoration: underline; }
.dcrumb span[aria-hidden] { opacity: .5; }

/* grid of child-defect cards on the family (hub) page */
.subgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: .4rem; }
.subcard {
  position: relative; display: flex; flex-direction: column; gap: .2rem;
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.3rem 1.3rem 1.15rem; overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s;
}
.subcard::before { /* category spine */
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--accent);
}
.subcard:hover { transform: translateY(-3px); box-shadow: 0 14px 34px rgba(20,28,40,.12);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.subcard__glyph {
  width: 100%; height: 96px; border-radius: 12px; margin-bottom: .9rem;
  background: color-mix(in srgb, var(--accent) 8%, var(--ink));
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--line));
}
.subcard__body { display: flex; flex-direction: column; min-width: 0; }
.subcard__kicker { color: var(--accent-deep); margin-bottom: .45rem; }
.subcard__title { font-family: var(--display); font-weight: 600; font-size: 1.1rem;
  letter-spacing: -.01em; line-height: 1.25; }
.subcard__essence { color: var(--text-soft); font-size: .88rem; margin-top: .4rem; }
.subcard .card__link { color: var(--accent-deep); margin-top: .9rem; }
.subcard .card__link svg { width: 15px; height: 15px; transition: transform .15s; }
.subcard:hover .card__link svg { transform: translateX(3px); }

@media (max-width: 900px) { .subgrid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .subgrid { grid-template-columns: 1fr; } }

/* named failure-vector category sub-headers on a compound smell hub */
.excat { margin-top: 1.6rem; }
.excat:first-child { margin-top: .2rem; }
.excat__title { font-family: var(--display); font-weight: 600; font-size: 1.05rem;
  letter-spacing: .01em; color: var(--accent-deep); margin: 0; }
.excat__core { font-size: .92rem; color: var(--text-soft); margin: .15rem 0 .2rem;
  border-left: 2px solid var(--accent); padding-left: .6rem; }

/* three category columns side by side, each stacking its worked-example cards */
.excat-cols { display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 1.6rem 1.25rem; align-items: start; }
.excat-cols .excat { margin-top: 0; }
.excat-cols .exgrid { grid-template-columns: 1fr; }
.excat-cols .excard { padding: 1.1rem 1.15rem 1rem; }

/* grid of worked-example cards on a compound smell hub */
.exgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin-top: .4rem; }
.excard { position: relative; display: flex; flex-direction: column; gap: .55rem;
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.3rem 1.3rem 1.15rem; overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s; }
.excard::before { /* smell-accent spine */
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.excard:hover { transform: translateY(-3px); box-shadow: 0 14px 34px rgba(20,28,40,.12);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.excard__title { font-family: var(--display); font-weight: 600; font-size: 1.1rem;
  letter-spacing: -.01em; line-height: 1.25; color: var(--ink); text-decoration: none; }
.excard__title:hover { color: var(--accent-deep); }
.excard__intro { color: var(--text-soft); font-size: .9rem; }
.excard .recipe { margin: .1rem 0 .2rem; }
.excard .card__link { color: var(--accent-deep); margin-top: auto; }
.excard .card__link svg { width: 15px; height: 15px; transition: transform .15s; }
.excard:hover .card__link svg { transform: translateX(3px); }
@media (max-width: 960px) {  /* tablet: stack the category columns, cards go 2-up */
  .excat-cols { grid-template-columns: 1fr; gap: 1.6rem; }
  .excat-cols .excat { margin-top: 1.6rem; }
  .excat-cols .excat:first-child { margin-top: 0; }
  .excat-cols .exgrid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) { .exgrid, .excat-cols .exgrid { grid-template-columns: 1fr; } }

/* "where this compounds" — from a stateful defect up to the compound smells it
   feeds; one card per smell, tab-colored by that smell (--c spine, --cd text) */
.compounds-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: .4rem; }
.compounds-card { position: relative; background: var(--paper-raised);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem 1rem 1.5rem; overflow: hidden; }
.compounds-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px; background: var(--c); }
.compounds-card__head { display: inline-block; font-family: var(--display); font-weight: 600;
  font-size: 1.05rem; margin-bottom: .55rem; color: var(--ink); text-decoration: none; }
.compounds-card__head:hover { color: var(--cd); }
.compounds-card__list { list-style: none; display: flex; flex-direction: column; gap: .45rem; }
.compounds-card__list a { color: var(--ink); font-weight: 500; text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--cd) 40%, transparent); }
.compounds-card__list a:hover { border-bottom-color: var(--cd); color: var(--cd); }
.compounds-card__x { color: var(--text-soft); font-size: .82rem; font-family: var(--mono); }
@media (max-width: 720px) { .compounds-grid { grid-template-columns: 1fr; } }

/* ============================================================ RTL (Arabic)
   Additive only — flips direction-sensitive layout for dir="rtl" pages while
   keeping code blocks left-to-right. No existing LTR rule is modified. */
[dir="rtl"] { --display: 'Noto Sans Arabic', system-ui, sans-serif;
  --body: 'Noto Sans Arabic', system-ui, sans-serif; }

/* nav + header auto-margins and ::before chips */
[dir="rtl"] .nav-links { margin-left: 0; margin-right: auto; }
[dir="rtl"] .nav-links a::before { margin-right: 0; margin-left: .5rem; }
[dir="rtl"] .lang-select,
[dir="rtl"] .nav-toggle { margin-left: 0; margin-right: .4rem; }

/* category spines: left:0 -> right:0 */
[dir="rtl"] .card::before,
[dir="rtl"] .subcard::before,
[dir="rtl"] .excard::before,
[dir="rtl"] .compounds-card::before { left: auto; right: 0; }

/* left-bordered callouts -> right-bordered */
[dir="rtl"] .dhero__essence,
[dir="rtl"] .qualities__rule { padding-left: 0; padding-right: 1rem;
  border-left: none; border-right: 3px solid var(--accent); }

/* hover arrows + link glyphs point the other way */
[dir="rtl"] .card__link svg { transform: scaleX(-1); }
[dir="rtl"] .card:hover .card__link svg,
[dir="rtl"] .subcard:hover .card__link svg { transform: scaleX(-1) translateX(3px); }
[dir="rtl"] .casefile__points li::before { content: "\2190"; }
[dir="rtl"] .phil-list a::after { content: "\2196"; }

/* CRITICAL: code is always left-to-right, even on RTL pages */
[dir="rtl"] .code-viewer,
[dir="rtl"] .code-window,
[dir="rtl"] .lang-tabs,
[dir="rtl"] .code-head,
[dir="rtl"] .code-panel,
[dir="rtl"] .code-out,
[dir="rtl"] .console,
[dir="rtl"] pre,
[dir="rtl"] code { direction: ltr; text-align: left; }
