/* ---------- Tokens ---------- */
:root {
  --bg: #F3F4F8;
  --surface: #FFFFFF;
  --surface-2: #E9EBF4;
  --ink: #1B1F3B;
  --ink-2: #4A4F72;
  --line: #D5D8E6;
  --accent: #5B4BDB;
  --accent-ink: #FFFFFF;
  --sprout: #23855A;
  --brass: #A56C06;
  --ember: #C73B2A;
  --code-bg: #1B1F3B;
  --code-ink: #E7E8F5;
  --shadow: 0 1px 2px rgb(27 31 59 / 6%), 0 8px 24px -12px rgb(27 31 59 / 18%);

  --font-display: "Familjen Grotesk", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;

  --radius: 12px;
  --gutter: clamp(16px, 4vw, 40px);
  --max: 1180px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12142A;
    --surface: #1A1D38;
    --surface-2: #242849;
    --ink: #E7E8F5;
    --ink-2: #A6AACB;
    --line: #2F345A;
    --accent: #9A8EFF;
    --accent-ink: #12142A;
    --sprout: #52C991;
    --brass: #E3AE42;
    --ember: #F2735F;
    --code-bg: #0C0E1F;
    --code-ink: #E7E8F5;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px -12px rgb(0 0 0 / 60%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #12142A;
  --surface: #1A1D38;
  --surface-2: #242849;
  --ink: #E7E8F5;
  --ink-2: #A6AACB;
  --line: #2F345A;
  --accent: #9A8EFF;
  --accent-ink: #12142A;
  --sprout: #52C991;
  --brass: #E3AE42;
  --ember: #F2735F;
  --code-bg: #0C0E1F;
  --code-ink: #E7E8F5;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px -12px rgb(0 0 0 / 60%);
  color-scheme: dark;
}

.lvl-beginner { --lvl: var(--sprout); }
.lvl-intermediate { --lvl: var(--brass); }
.lvl-challenge { --lvl: var(--ember); }
.lvl-start { --lvl: var(--accent); }

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.6 var(--font-body);
  overflow-x: hidden;
}

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.15; letter-spacing: -0.015em; }

code, pre, kbd { font-family: var(--font-mono); }

button { font: inherit; color: inherit; }

.skip {
  position: absolute; left: 8px; top: -60px; z-index: 50;
  background: var(--accent); color: var(--accent-ink);
  padding: 8px 14px; border-radius: 8px; text-decoration: none;
}
.skip:focus { top: 8px; }

main { outline: none; }

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

.loading, .error-box { max-width: var(--max); margin: 80px auto; padding: 0 var(--gutter); color: var(--ink-2); }
.error-box h1 { color: var(--ink); font-size: 1.6rem; }
.error-box code { background: var(--surface-2); padding: .1em .4em; border-radius: 4px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: var(--max); margin: 0 auto; padding: 10px var(--gutter);
  display: flex; align-items: center; gap: 20px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none;
  font: 700 1.05rem/1 var(--font-display); letter-spacing: -0.01em;
}
.brand svg { width: 28px; height: 28px; color: var(--accent); flex: none; }
.topnav { display: flex; gap: 4px; margin-left: auto; }
.topnav a {
  color: var(--ink-2); text-decoration: none; font-weight: 700; font-size: .95rem;
  padding: 6px 12px; border-radius: 8px;
}
.topnav a:hover { color: var(--ink); background: var(--surface-2); }
.topnav a[aria-current="page"] { color: var(--ink); background: var(--surface-2); }
.theme-toggle {
  width: 38px; height: 38px; display: grid; place-items: center; flex: none;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer;
}
.theme-toggle svg { width: 18px; height: 18px; }

@media (max-width: 560px) {
  .brand span { display: none; }
  .topnav { margin-left: 0; }
  .topnav a { padding: 6px 9px; }
  .theme-toggle { margin-left: auto; }
}

/* ---------- Hero ---------- */
.hero { padding-top: clamp(40px, 7vw, 88px); padding-bottom: clamp(32px, 5vw, 56px); }
.hero h1 {
  margin: 0; max-width: 16ch;
  font-size: clamp(2.5rem, 6.4vw, 4.6rem); font-weight: 700; letter-spacing: -0.035em; line-height: 1.02;
}
.hero h1 .push { color: var(--accent); }
.lede { max-width: 58ch; margin: 22px 0 0; font-size: 1.12rem; color: var(--ink-2); }

/* ---------- Journey rail (signature) ---------- */
.journey {
  margin-top: clamp(36px, 5vw, 56px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px clamp(16px, 3vw, 28px) 26px; box-shadow: var(--shadow);
}
.journey-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 20px; }
.journey-head h2 { margin: 0; font-size: 1.15rem; }
.journey-head p { margin: 0; color: var(--ink-2); font-size: .92rem; }
.journey-head code { font-size: .85em; }

.rail { list-style: none; margin: 22px 0 0; padding: 0; display: grid; grid-template-columns: repeat(8, 1fr); }
.rail li {
  position: relative; display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 10px; padding-top: 30px; min-width: 0;
}
.rail li::before {
  content: ""; position: absolute; top: calc(30px + 11px); left: 50%; width: 100%; height: 3px;
  background: var(--line); transition: background .3s;
}
.rail li:last-child::before { display: none; }
.rail li.done::before { background: var(--accent); }

.node {
  position: relative; z-index: 1; width: 25px; height: 25px; padding: 0; flex: none;
  border: 3px solid var(--accent); border-radius: 50%; background: var(--surface); cursor: pointer;
  transition: background .2s, transform .2s;
}
.node::before { content: ""; position: absolute; inset: -10px; border-radius: 50%; }
.node:hover { transform: scale(1.12); }
.done .node { background: var(--accent); }
.done .node::after {
  content: ""; position: absolute; left: 6px; top: 2px; width: 6px; height: 11px;
  border: solid var(--accent-ink); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
}

.step-label { font-size: .86rem; line-height: 1.3; color: var(--ink-2); padding: 0 4px; }
.step-label a { color: inherit; }
.done .step-label { color: var(--ink); }
.head-tag {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  font: 600 .68rem/1 var(--font-mono); letter-spacing: .04em;
  background: var(--accent); color: var(--accent-ink); padding: 4px 6px; border-radius: 4px; white-space: nowrap;
}
.head-tag::after {
  content: ""; position: absolute; left: 50%; bottom: -4px; margin-left: -4px;
  border: 4px solid transparent; border-bottom: 0; border-top-color: var(--accent);
}

@media (max-width: 820px) {
  .rail { grid-template-columns: 1fr; gap: 0; }
  .rail li { flex-direction: row; text-align: left; padding: 0 0 18px; gap: 14px; }
  .rail li::before { top: 12px; left: 11px; width: 3px; height: 100%; }
  .step-label { padding: 0; font-size: .95rem; }
  .head-tag { position: static; transform: none; margin-left: auto; }
  .head-tag::after { display: none; }
}

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

/* ---------- Board & filters ---------- */
.board { padding-bottom: 72px; }
.board-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 24px; margin-bottom: 18px; }
.board-head h2 { margin: 0; font-size: clamp(1.6rem, 3vw, 2.1rem); }
.tally { margin: 0; color: var(--ink-2); font-size: .95rem; }

.tracks { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 4px; }
.track-tab {
  display: grid; gap: 4px; text-align: left; cursor: pointer;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
}
.track-tab strong { font: 700 1.12rem/1.2 var(--font-display); }
.track-tab span { font-size: .88rem; color: var(--ink-2); line-height: 1.4; }
.track-tab:hover { border-color: var(--ink-2); }
.track-tab[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.track-tab[aria-pressed="true"] span { color: var(--bg); opacity: .8; }
@media (max-width: 560px) { .tracks { grid-template-columns: 1fr; } }

.filters {
  position: sticky; top: 59px; z-index: 10;
  display: grid; gap: 12px;
  background: var(--bg); padding: 14px 0; border-bottom: 1px solid var(--line);
}
.search {
  width: 100%; padding: 12px 14px 12px 42px;
  font: inherit; color: var(--ink);
  background: var(--surface) no-repeat 14px 50% / 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238A8FB3' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  border: 1px solid var(--line); border-radius: 10px;
}
.search::placeholder { color: var(--ink-2); opacity: .8; }
.filter-row { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  padding: 5px 11px; border-radius: 999px; cursor: pointer; font-size: .88rem; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { color: var(--ink); border-color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip.ext-chip { font-family: var(--font-mono); font-weight: 600; font-size: .82rem; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lvl); }
.filter-label { font-size: .78rem; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; margin-right: 2px; }
.filter-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.count { margin: 18px 0 0; color: var(--ink-2); font-size: .92rem; }

@media (max-width: 720px) {
  .filters { position: static; }
}

/* ---------- Cards ---------- */
.group { margin-top: 36px; }
.group-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.group-head h3 { margin: 0; font-size: 1.35rem; }
.group-head span { color: var(--ink-2); font-size: .9rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }

.card {
  position: relative; display: flex; flex-direction: column; gap: 10px;
  padding: 18px 18px 16px; min-height: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); text-decoration: none; box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card h4 { margin: 0; font-size: 1.22rem; }
.card p { margin: 0; color: var(--ink-2); font-size: .95rem; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card-top { display: flex; align-items: center; gap: 10px; }
.card-foot {
  margin-top: auto; padding-top: 12px; border-top: 1px dashed var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: .82rem; color: var(--ink-2);
}
.card-foot code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; }
.card-foot .time { white-space: nowrap; }

.ext {
  font: 600 .78rem/1 var(--font-mono); color: var(--ink);
  background: var(--surface-2); padding: 5px 7px; border-radius: 6px;
}
.level { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 700; color: var(--lvl); }
.level::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--lvl); }

.status {
  margin-left: auto; font-size: .74rem; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  border: 1px solid currentColor;
}
.status-building { color: var(--brass); }
.status-shipped { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }

.start-card {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 16px 28px;
  margin-top: 28px; padding: 22px 24px;
  background: var(--ink); color: var(--bg); border-radius: var(--radius); text-decoration: none;
}
.start-card h3 { margin: 4px 0 6px; font-size: 1.4rem; }
.start-card p { margin: 0; opacity: .8; max-width: 60ch; }
.start-card .kicker { font: 600 .75rem/1 var(--font-mono); letter-spacing: .05em; opacity: .75; }
.start-card .go {
  font-weight: 700; background: var(--accent); color: var(--accent-ink);
  padding: 10px 16px; border-radius: 10px; white-space: nowrap;
}
.start-card:hover .go { filter: brightness(1.08); }
@media (max-width: 620px) { .start-card { grid-template-columns: 1fr; } .start-card .go { justify-self: start; } }

.empty { margin: 40px 0; padding: 32px; text-align: center; border: 2px dashed var(--line); border-radius: var(--radius); color: var(--ink-2); }
.empty button { margin-top: 12px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 10px; font-weight: 700; font-size: .92rem; text-decoration: none;
}
.btn:hover { border-color: var(--ink-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }

/* ---------- Project detail ---------- */
.crumbs { padding-top: 28px; font-size: .9rem; color: var(--ink-2); }
.crumbs a { color: var(--ink-2); }
.crumbs span[aria-hidden] { margin: 0 6px; opacity: .6; }

.detail-head { padding: 18px 0 8px; }
.detail-head h1 { margin: 12px 0 0; font-size: clamp(2.2rem, 5vw, 3.4rem); letter-spacing: -0.03em; }
.tags { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; font-size: .9rem; color: var(--ink-2); }

.detail-grid {
  display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 48px; align-items: start;
  padding: 16px 0 40px;
}
.aside { position: sticky; top: 80px; display: grid; gap: 14px; }
@media (max-width: 960px) {
  .detail-grid { grid-template-columns: 1fr; gap: 28px; }
  .aside { position: static; }
}

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel h2 { margin: 0 0 12px; font-size: 1rem; letter-spacing: 0; }
.panel p { margin: 0 0 10px; font-size: .92rem; color: var(--ink-2); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 8px 6px; font-size: .85rem; font-weight: 700; color: var(--ink-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--ink); background: var(--surface-2); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.meter { margin-top: 14px; }
.meter-label { display: flex; justify-content: space-between; font-size: .85rem; color: var(--ink-2); margin-bottom: 6px; }
.meter-bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .3s; }

.username { display: grid; gap: 6px; margin-bottom: 10px; font-size: .85rem; font-weight: 700; color: var(--ink-2); }
.username input {
  font: 400 .92rem var(--font-mono); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}

.repo-name {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border-radius: 8px; padding: 8px 8px 8px 12px; margin-bottom: 14px;
}
.repo-name code { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: .86rem; }
.repo-name .you { color: var(--ink-2); }
.copy-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 4px 9px; font-size: .78rem; font-weight: 700; cursor: pointer; flex: none; }
.copy-btn:hover { border-color: var(--ink-2); }

.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 10px; font-size: .92rem; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 24px 1fr; gap: 8px; }
.steps li::before {
  content: counter(s); width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font: 600 .72rem/1 var(--font-mono);
  background: var(--surface-2); color: var(--ink);
}

.toolkit { font-size: .9rem; }
.toolkit p, .toolkit blockquote p { font-size: .9rem; }
.toolkit > :last-child { margin-bottom: 0; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 8px 0 72px; border-top: 1px solid var(--line); margin-top: 8px; }
.pager a {
  display: block; padding: 16px 18px; margin-top: 20px; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; color: var(--ink-2); font-size: .8rem; margin-bottom: 2px; }
.pager strong { font-family: var(--font-display); font-size: 1.1rem; }
.pager .next { text-align: right; grid-column: 2; }

/* ---------- Prose (rendered Markdown) ---------- */
.prose { min-width: 0; font-size: 1.02rem; }
.prose > :first-child { margin-top: 0; }
.prose :is(h1, h2, h3, h4) { scroll-margin-top: 84px; }
.prose h1 { font-size: clamp(2rem, 4.4vw, 2.8rem); letter-spacing: -0.03em; margin: 0 0 .5em; }
.prose h2 { font-size: 1.6rem; margin: 2em 0 .6em; padding-top: .6em; border-top: 1px solid var(--line); }
.prose h3 { font-size: 1.28rem; margin: 2em 0 .55em; }
.prose h4 { font-size: 1.05rem; margin: 1.6em 0 .4em; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose pre, .prose table, .prose details { margin: 0 0 1em; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: .3em 0; }
.prose li > ul, .prose li > ol { margin: .3em 0 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }
.prose strong { font-weight: 700; }
.prose code {
  font-size: .84em; background: var(--surface-2); padding: .12em .38em; border-radius: 5px;
  overflow-wrap: anywhere;
}
.prose pre {
  background: var(--code-bg); color: var(--code-ink); padding: 16px 18px; border-radius: 10px;
  overflow-x: auto; font-size: .86rem; line-height: 1.55;
}
.prose pre code { background: none; padding: 0; font-size: inherit; color: inherit; overflow-wrap: normal; }
.prose blockquote {
  margin-left: 0; padding: 12px 16px; border-left: 4px solid var(--accent);
  background: var(--surface); border-radius: 0 10px 10px 0;
}
.prose blockquote > :last-child { margin-bottom: 0; }
.prose table { display: block; overflow-x: auto; border-collapse: collapse; font-size: .92rem; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); }
.prose img { max-width: 100%; }

.prose li.task { list-style: none; margin-left: -1.4em; }
.prose li.task > label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.prose li.task input { width: 1.1em; height: 1.1em; margin: .28em 0 0; flex: none; accent-color: var(--accent); cursor: pointer; }
.prose li.task input:disabled { cursor: default; }
.prose li.task.checked > label > span { color: var(--ink-2); text-decoration: line-through; text-decoration-color: var(--line); }
.prose li.task > ul { margin-left: 2.2em; }

.prose details {
  border: 1px dashed var(--line); border-radius: 10px; padding: 0 16px; background: var(--surface);
}
.prose details + details { margin-top: -4px; }
.prose summary { cursor: pointer; font-weight: 700; padding: 12px 0; list-style-position: inside; }
.prose summary:hover { color: var(--accent); }
.prose details[open] { border-style: solid; }
.prose details[open] summary { border-bottom: 1px dashed var(--line); margin-bottom: 12px; }

.doc { max-width: 820px; padding-top: 32px; padding-bottom: 72px; }

.footer { border-top: 1px solid var(--line); }
.footer-inner { max-width: var(--max); margin: 0 auto; padding: 24px var(--gutter) 40px; color: var(--ink-2); font-size: .9rem; }
.footer-inner p { margin: 0 0 6px; }
