/* ============================================================
   Loop Engineering — Shared Design System
   Modern, soft, professional. Light + dark aware.
   ============================================================ */

:root {
  /* Palette — warm off-white base, soft violet + coral accents */
  --bg: #f7f5f2;
  --bg-tint: #f1eee9;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --border: #e9e4dd;
  --border-strong: #ddd6cc;

  --text: #211f1c;
  --heading: #17150f;
  --muted: #6d675f;
  --faint: #948d83;

  --violet: #6c5ce7;
  --violet-soft: #efecfd;
  --violet-ink: #4635b8;
  --coral: #e07a52;
  --coral-soft: #fcefe7;
  --coral-ink: #b5501f;
  --teal: #2fa9a0;
  --teal-soft: #e4f5f3;
  --teal-ink: #1f7a73;
  --amber: #e0a53c;
  --amber-soft: #fbf1dd;
  --gold-ink: #a06e10;

  --grad-hero: radial-gradient(120% 120% at 15% 0%, #efe9ff 0%, #f7f5f2 42%, #fdf1ea 100%);
  --grad-accent: linear-gradient(120deg, #6c5ce7 0%, #8b6ff0 55%, #e07a52 130%);

  --shadow-sm: 0 1px 2px rgba(30, 24, 16, 0.05), 0 1px 3px rgba(30, 24, 16, 0.06);
  --shadow-md: 0 4px 14px rgba(40, 32, 22, 0.07), 0 2px 6px rgba(40, 32, 22, 0.05);
  --shadow-lg: 0 24px 60px -20px rgba(52, 42, 30, 0.22);

  --r-sm: 10px;
  --r: 16px;
  --r-lg: 24px;
  --r-xl: 32px;

  --maxw: 1120px;
  --font: "Segoe UI", "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "SFMono-Regular", "JetBrains Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
  --bg: #14130f;
  --bg-tint: #1b1915;
  --surface: #1d1b16;
  --surface-2: #232019;
  --border: #322e26;
  --border-strong: #423d32;

  --text: #ece7de;
  --heading: #fbf7ef;
  --muted: #a79f92;
  --faint: #7d7566;

  --violet: #9d8bff;
  --violet-soft: #262042;
  --violet-ink: #c3b6ff;
  --coral: #f0946b;
  --coral-soft: #3a2318;
  --coral-ink: #f6b795;
  --teal: #4fc8be;
  --teal-soft: #123330;
  --teal-ink: #7fe0d7;
  --amber: #e9b654;
  --amber-soft: #352a12;
  --gold-ink: #edc873;

  --grad-hero: radial-gradient(120% 120% at 15% 0%, #221c3c 0%, #14130f 45%, #2b1a12 100%);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 6px 18px rgba(0,0,0,0.4);
  --shadow-lg: 0 24px 60px -20px rgba(0,0,0,0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14130f;
    --bg-tint: #1b1915;
    --surface: #1d1b16;
    --surface-2: #232019;
    --border: #322e26;
    --border-strong: #423d32;
    --text: #ece7de;
    --heading: #fbf7ef;
    --muted: #a79f92;
    --faint: #7d7566;
    --violet: #9d8bff;
    --violet-soft: #262042;
    --violet-ink: #c3b6ff;
    --coral: #f0946b;
    --coral-soft: #3a2318;
    --coral-ink: #f6b795;
    --teal: #4fc8be;
    --teal-soft: #123330;
    --teal-ink: #7fe0d7;
    --amber: #e9b654;
    --amber-soft: #352a12;
    --gold-ink: #edc873;
    --grad-hero: radial-gradient(120% 120% at 15% 0%, #221c3c 0%, #14130f 45%, #2b1a12 100%);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 6px 18px rgba(0,0,0,0.4);
    --shadow-lg: 0 24px 60px -20px rgba(0,0,0,0.6);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 90px; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { color: var(--heading); line-height: 1.18; letter-spacing: -0.02em; margin: 0 0 .5em; }
h1 { font-size: clamp(2.1rem, 5vw, 3.4rem); font-weight: 800; }
h2 { font-size: clamp(1.6rem, 3.4vw, 2.3rem); font-weight: 750; }
h3 { font-size: 1.28rem; font-weight: 700; }
h4 { font-size: 1.02rem; font-weight: 700; }
p { margin: 0 0 1rem; }
a { color: var(--violet-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }
.narrow { max-width: 820px; }

/* ---------- Navbar ---------- */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}
.nav-inner { display: flex; align-items: center; gap: 20px; height: 66px; }
.brand { display: flex; align-items: center; gap: 11px; font-weight: 800; color: var(--heading); font-size: 1.06rem; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand .logo { width: 34px; height: 34px; flex: none; }
.nav-links { display: flex; gap: 2px; margin-left: auto; align-items: center; }
.nav-links a {
  color: var(--muted); font-weight: 600; font-size: .9rem;
  padding: 7px 11px; border-radius: 999px; transition: .18s; white-space: nowrap;
}
@media (max-width: 1140px) and (min-width: 901px) { .nav-links a { padding: 7px 8px; font-size: .84rem; } .brand { font-size: 1rem; } .nav-inner { gap: 12px; } }
.nav-links a:hover { color: var(--heading); background: var(--bg-tint); text-decoration: none; }
.nav-links a.active { color: var(--violet-ink); background: var(--violet-soft); }
.theme-btn {
  border: 1px solid var(--border-strong); background: var(--surface);
  width: 38px; height: 38px; border-radius: 999px; cursor: pointer;
  display: grid; place-items: center; color: var(--muted); transition: .18s; flex: none;
}
.theme-btn:hover { color: var(--heading); border-color: var(--faint); }
.theme-btn svg { width: 18px; height: 18px; }
.theme-btn .moon { display: none; }
:root[data-theme="dark"] .theme-btn .moon { display: block; }
:root[data-theme="dark"] .theme-btn .sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .moon { display: block; }
  :root:not([data-theme="light"]) .theme-btn .sun { display: none; }
}
.menu-btn { display: none; }

@media (max-width: 900px) {
  .nav-links {
    position: fixed; inset: 66px 0 auto 0; flex-direction: column; align-items: stretch;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px;
    gap: 2px; margin: 0; transform: translateY(-140%); transition: transform .28s ease; box-shadow: var(--shadow-md);
  }
  .nav-links.open { transform: translateY(0); }
  .nav-links a { padding: 12px 14px; border-radius: 12px; }
  .menu-btn {
    display: grid; place-items: center; margin-left: auto; width: 40px; height: 40px;
    border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; color: var(--heading);
  }
  .theme-btn { margin-left: 0; }
}

/* ---------- Layout primitives ---------- */
section { padding: 74px 0; }
.section-tight { padding: 46px 0; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: .76rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  color: var(--violet-ink); background: var(--violet-soft);
  padding: 6px 13px; border-radius: 999px; margin-bottom: 18px;
}
.eyebrow.coral { color: var(--coral-ink); background: var(--coral-soft); }
.eyebrow.teal { color: var(--teal-ink); background: var(--teal-soft); }
.lead { font-size: 1.16rem; color: var(--muted); max-width: 680px; }
.center { text-align: center; }
.center .lead, .center .eyebrow { margin-left: auto; margin-right: auto; }

.grid { display: grid; gap: 22px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .g3, .g4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 26px; box-shadow: var(--shadow-sm);
  transition: transform .22s ease, box-shadow .22s ease, border-color .22s;
}
.card.hover:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.card h3 { margin-bottom: .4em; }
.card p:last-child { margin-bottom: 0; }
.card .ico {
  width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center;
  margin-bottom: 16px; background: var(--violet-soft); color: var(--violet-ink);
}
.card .ico.coral { background: var(--coral-soft); color: var(--coral-ink); }
.card .ico.teal { background: var(--teal-soft); color: var(--teal-ink); }
.card .ico.amber { background: var(--amber-soft); color: var(--gold-ink); }
.card .ico svg { width: 24px; height: 24px; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); padding: clamp(24px, 4vw, 46px); box-shadow: var(--shadow-md);
}
.soft-panel { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); padding: clamp(20px,3vw,34px); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 9px; font-weight: 700; font-size: .96rem;
  padding: 12px 22px; border-radius: 999px; cursor: pointer; border: 1px solid transparent; transition: .2s;
}
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--grad-accent); color: #fff; box-shadow: 0 8px 22px -8px rgba(108,92,231,.7); }
.btn-primary:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 14px 30px -10px rgba(108,92,231,.8); }
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--heading); }
.btn-ghost:hover { text-decoration: none; border-color: var(--faint); background: var(--surface-2); }
.btn-row { display: flex; flex-wrap: wrap; gap: 14px; }

/* ---------- Badges / pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 7px; font-size: .8rem; font-weight: 700; padding: 5px 12px; border-radius: 999px; background: var(--bg-tint); color: var(--muted); border: 1px solid var(--border); }
.pill.v { background: var(--violet-soft); color: var(--violet-ink); border-color: transparent; }
.pill.c { background: var(--coral-soft); color: var(--coral-ink); border-color: transparent; }
.pill.t { background: var(--teal-soft); color: var(--teal-ink); border-color: transparent; }
.tag-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Steps / numbered ---------- */
.steps { display: grid; gap: 16px; counter-reset: s; }
.step {
  display: grid; grid-template-columns: 46px 1fr; gap: 18px; align-items: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 20px 22px; box-shadow: var(--shadow-sm);
}
.step .num {
  counter-increment: s; width: 46px; height: 46px; border-radius: 13px;
  background: var(--grad-accent); color: #fff; font-weight: 800; font-size: 1.15rem;
  display: grid; place-items: center;
}
.step .num::before { content: counter(s, decimal-leading-zero); }
.step h4 { margin-bottom: .25em; }
.step p { margin: 0; color: var(--muted); font-size: .96rem; }

/* ---------- Code ---------- */
.code {
  background: #1c1a24; color: #e7e3f5; border-radius: var(--r);
  padding: 20px 22px; overflow-x: auto; font-family: var(--mono); font-size: .86rem; line-height: 1.65;
  border: 1px solid #2a2735; box-shadow: var(--shadow-md); margin: 0 0 4px;
}
:root[data-theme="dark"] .code { background: #0f0e14; }
.code .c-key { color: #c3b6ff; }
.code .c-str { color: #e0a06f; }
.code .c-com { color: #7c7690; font-style: italic; }
.code .c-fn { color: #6fd3c9; }
.code .c-punc { color: #9a94b0; }
.code-cap { font-size: .82rem; color: var(--faint); margin: 8px 2px 0; }
code.inline { font-family: var(--mono); font-size: .86em; background: var(--bg-tint); padding: 2px 7px; border-radius: 6px; color: var(--coral-ink); border: 1px solid var(--border); }

/* ---------- Callouts ---------- */
.callout {
  border-radius: var(--r); padding: 18px 22px; border: 1px solid var(--border);
  background: var(--surface-2); display: grid; grid-template-columns: 26px 1fr; gap: 14px; align-items: start;
}
.callout .ico { color: var(--violet-ink); }
.callout.tip { background: var(--teal-soft); border-color: transparent; }
.callout.tip .ico { color: var(--teal-ink); }
.callout.note { background: var(--violet-soft); border-color: transparent; }
.callout.warn { background: var(--amber-soft); border-color: transparent; }
.callout.warn .ico { color: var(--gold-ink); }
.callout h4 { margin: 0 0 4px; }
.callout p { margin: 0; font-size: .95rem; color: var(--muted); }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); }
table { border-collapse: collapse; width: 100%; min-width: 560px; background: var(--surface); }
th, td { text-align: left; padding: 13px 18px; border-bottom: 1px solid var(--border); font-size: .92rem; vertical-align: top; }
th { background: var(--surface-2); font-weight: 700; color: var(--heading); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: none; }
td code { font-family: var(--mono); font-size: .85em; color: var(--coral-ink); }

/* ---------- Diagram helpers ---------- */
.figure { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: clamp(18px,3vw,34px); box-shadow: var(--shadow-md); }
.figure svg { width: 100%; height: auto; display: block; }
.figcap { text-align: center; color: var(--faint); font-size: .86rem; margin-top: 16px; }
.diagram-label { font: 600 13px var(--font); fill: var(--heading); }
.diagram-sub { font: 500 11px var(--font); fill: var(--muted); }

/* ---------- Progression rail (prompt->context->harness->loop) ---------- */
.rail { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; position: relative; }
.rail .stage { position: relative; padding: 0 12px; text-align: center; }
.rail .dot { width: 20px; height: 20px; border-radius: 50%; background: var(--surface); border: 3px solid var(--violet); margin: 0 auto 16px; position: relative; z-index: 2; }
.rail .stage:last-child .dot { background: var(--grad-accent); border-color: transparent; box-shadow: 0 0 0 6px var(--violet-soft); }
.rail::before { content: ""; position: absolute; top: 8px; left: 12%; right: 12%; height: 3px; background: linear-gradient(90deg, var(--border), var(--violet)); z-index: 1; }
.rail h4 { font-size: 1rem; }
.rail p { font-size: .85rem; color: var(--muted); }
@media (max-width: 700px) { .rail { grid-template-columns: 1fr; gap: 14px; } .rail::before { display: none; } .rail .stage { text-align: left; display: grid; grid-template-columns: 24px 1fr; gap: 12px; } .rail .dot { margin: 4px 0 0; } }

/* ---------- Stat row ---------- */
.stats { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
@media (max-width:700px){ .stats { grid-template-columns: repeat(2,1fr);} }
.stat { text-align: center; padding: 22px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.stat .n { font-size: 2rem; font-weight: 800; color: var(--violet-ink); letter-spacing: -.02em; }
.stat .l { font-size: .85rem; color: var(--muted); }

/* ---------- Hero ---------- */
.hero { background: var(--grad-hero); border-bottom: 1px solid var(--border); padding: 84px 0 74px; overflow: hidden; }
.hero .lead { font-size: 1.24rem; }
.hero-grid { display: grid; grid-template-columns: 1.05fr .95fr; gap: 48px; align-items: center; }
@media (max-width: 900px){ .hero-grid { grid-template-columns: 1fr; gap: 36px; } }

/* page hero (inner pages) */
.phead { background: var(--grad-hero); border-bottom: 1px solid var(--border); padding: 66px 0 48px; }

/* ---------- Reveal animation ---------- */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity .6s ease, transform .6s ease; }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .reveal { opacity: 1; transform: none; transition: none; } html { scroll-behavior: auto; } }

/* ---------- TOC (advanced) ---------- */
.toc { position: sticky; top: 90px; align-self: start; }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); }
.toc a { display: block; padding: 6px 16px; color: var(--muted); font-size: .9rem; font-weight: 600; margin-left: -2px; border-left: 2px solid transparent; }
.toc a:hover, .toc a.active { color: var(--violet-ink); border-left-color: var(--violet); text-decoration: none; }
.split { display: grid; grid-template-columns: 230px 1fr; gap: 48px; align-items: start; }
@media (max-width: 900px){ .split { grid-template-columns: 1fr; } .toc { display: none; } }

/* ---------- Footer ---------- */
.footer { background: var(--bg-tint); border-top: 1px solid var(--border); padding: 54px 0 34px; margin-top: 30px; }
.footer-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 36px; }
@media (max-width: 760px){ .footer-grid { grid-template-columns: 1fr; gap: 26px; } }
.footer h5 { font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--faint); margin: 0 0 14px; }
.footer a { display: block; color: var(--muted); font-size: .92rem; padding: 4px 0; }
.footer a:hover { color: var(--heading); }
.footer .copy { margin-top: 34px; padding-top: 20px; border-top: 1px solid var(--border); color: var(--faint); font-size: .84rem; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; }

/* ---------- misc ---------- */
.divider { height: 1px; background: var(--border); margin: 0; border: none; }
ul.check { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
ul.check li { display: grid; grid-template-columns: 24px 1fr; gap: 12px; align-items: start; color: var(--muted); }
ul.check li .tick { width: 24px; height: 24px; border-radius: 7px; background: var(--teal-soft); color: var(--teal-ink); display: grid; place-items: center; }
ul.check li .tick svg { width: 14px; height: 14px; }
ul.check li strong { color: var(--heading); }

/* ---------- Learning path (home) ---------- */
.path { display: grid; gap: 14px; }
.lesson {
  display: grid; grid-template-columns: 58px 1fr auto; gap: 20px; align-items: center;
  padding: 20px 24px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm); transition: transform .2s, box-shadow .2s, border-color .2s; color: inherit;
}
.lesson:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); text-decoration: none; }
.lesson .n { width: 56px; height: 56px; border-radius: 15px; background: var(--grad-accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.35rem; flex: none; }
.lesson .body h3 { margin: 0 0 4px; font-size: 1.16rem; }
.lesson .body p { margin: 0; color: var(--muted); font-size: .95rem; }
.lesson .body .meta { font-size: .76rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--violet-ink); margin-bottom: 6px; }
.lesson .go { color: var(--violet-ink); font-weight: 800; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.lesson .go svg { width: 16px; height: 16px; }
@media (max-width: 620px) { .lesson { grid-template-columns: 46px 1fr; gap: 16px; padding: 18px; } .lesson .n { width: 46px; height: 46px; font-size: 1.15rem; } .lesson .go { display: none; } }

/* ---------- Use-case cards (who / when / example) ---------- */
.uc-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.uc-head .ico { margin-bottom: 0; width: 42px; height: 42px; }
.uc-head h3 { margin: 0; font-size: 1.18rem; }
.uc-head h3 a { color: inherit; }
.uc-head h3 a:hover { color: var(--violet-ink); text-decoration: none; }
.uc { display: grid; gap: 11px; margin-top: 14px; }
.uc-row { display: grid; grid-template-columns: 104px 1fr; gap: 12px; align-items: start; font-size: .93rem; }
.uc-row .k { font-size: .7rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; padding-top: 3px; }
.uc-row .k.who { color: var(--violet-ink); }
.uc-row .k.when { color: var(--teal-ink); }
.uc-row .k.ex { color: var(--coral-ink); }
.uc-row .v { color: var(--muted); }
.uc-row .v strong { color: var(--heading); font-weight: 650; }
@media (max-width: 520px) { .uc-row { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- Pager (prev / next / home) ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.pager .pg { display: flex; flex-direction: column; gap: 5px; padding: 18px 22px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); box-shadow: var(--shadow-sm); transition: transform .2s, box-shadow .2s, border-color .2s; }
.pager .pg:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--border-strong); text-decoration: none; }
.pager .lbl { font-size: .74rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--violet-ink); }
.pager .ttl { font-weight: 750; color: var(--heading); font-size: 1.06rem; }
.pager .next { align-items: flex-end; text-align: right; }
.pager-home { text-align: center; margin-top: 18px; }
.pager-home a { display: inline-flex; gap: 8px; align-items: center; font-weight: 700; color: var(--muted); padding: 10px 22px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }
.pager-home a:hover { color: var(--heading); border-color: var(--faint); text-decoration: none; }
@media (max-width: 560px) { .pager { grid-template-columns: 1fr; } .pager .next { align-items: flex-start; text-align: left; } }

.kicker-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.section-head { max-width: 720px; margin-bottom: 44px; }
.section-head.center { margin-left: auto; margin-right: auto; }
