/* AI Foundry Marketplace: one stylesheet, light and dark via prefers-color-scheme. */

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #d5dde7;
  --border-strong: #b5c2d1;
  --text: #121c28;
  --muted: #4a5869;
  --accent: #002e5d;          /* navy */
  --accent-ink: #ffffff;
  --link: #0a4a8f;
  --focus: #1d6fd6;
  --code-bg: #0f1b2a;
  --code-text: #e7eef7;
  --hero-bg: #002e5d;
  --hero-text: #ffffff;
  --hero-muted: #c9d8ea;

  --proven-bg: #def3e6;  --proven-text: #11502b;  --proven-border: #a6d9b9;
  --new-bg: #fff0d1;     --new-text: #6b4100;     --new-border: #ebc97d;
  --beta-bg: #e1ecfb;    --beta-text: #123f78;    --beta-border: #a9c4ea;
  --unl-bg: #eceff3;     --unl-text: #3f4b59;     --unl-border: #c6ced8;
  --ext-bg: #e9e6fb;     --ext-text: #3b2f86;     --ext-border: #bdb4ee;

  --t-skill: #1f5fbf;
  --t-agent: #7a3fb8;
  --t-hook: #b23a3a;
  --t-template: #3d7a34;
  --t-plugin: #5b6575;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 28, 44, .06), 0 2px 8px rgba(16, 28, 44, .05);
  --shadow-hover: 0 2px 4px rgba(16, 28, 44, .08), 0 8px 22px rgba(16, 28, 44, .10);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b121a;
    --surface: #121c27;
    --surface-2: #192634;
    --border: #263546;
    --border-strong: #3a4d63;
    --text: #e5ecf3;
    --muted: #a3b2c3;
    --accent: #7fb0ff;
    --accent-ink: #06182c;
    --link: #8dbdff;
    --focus: #8dbdff;
    --code-bg: #08101a;
    --code-text: #e1e9f2;
    --hero-bg: #0e2440;
    --hero-text: #f2f6fb;
    --hero-muted: #b9cbe0;

    --proven-bg: #10301e;  --proven-text: #9be2b6;  --proven-border: #24583a;
    --new-bg: #33260b;     --new-text: #f6cf7d;     --new-border: #6a5020;
    --beta-bg: #12253d;    --beta-text: #a9cbff;    --beta-border: #2c4a70;
    --unl-bg: #1e2833;     --unl-text: #c2cdd9;     --unl-border: #3a4859;
    --ext-bg: #231f45;     --ext-text: #c9c1ff;     --ext-border: #463e85;

    --t-skill: #78aaff;
    --t-agent: #c49bf2;
    --t-hook: #ff8e8e;
    --t-template: #8fd17f;
    --t-plugin: #aab4c2;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-hover: 0 4px 18px rgba(0, 0, 0, .45);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; outline: none; }
img { max-width: 100%; }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.5rem); }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
code, pre, kbd { font-family: var(--mono); font-size: .9em; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 28px; } }

.skip {
  position: absolute; left: 8px; top: -60px; z-index: 50;
  background: var(--surface); color: var(--text); padding: 8px 14px;
  border: 2px solid var(--focus); border-radius: var(--radius-sm);
}
.skip:focus { top: 8px; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; }
.brand-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  background: #002e5d; color: #fff; font-weight: 800; font-size: 17px;
}
@media (prefers-color-scheme: dark) { .brand-mark { background: #1d4f86; } }
.brand-text { font-size: 1.02rem; white-space: nowrap; }
.brand-sub { font-weight: 500; color: var(--muted); }
.nav { list-style: none; display: flex; gap: 2px; margin: 0; padding: 0; }
.nav a {
  display: block; padding: 8px 11px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-weight: 550; font-size: .95rem;
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--link); }
@media (max-width: 560px) {
  .brand-sub { display: none; }
  .nav-gh { display: none; }
  .nav a { padding: 8px 8px; }
}
@media (max-width: 400px) {
  .header-inner { gap: 6px; }
  .nav a { padding: 8px 6px; font-size: .9rem; }
}

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--border); margin-top: 64px; padding: 28px 0 36px; color: var(--muted); font-size: .92rem; }
.footer-inner p { max-width: 760px; }

/* ---------- generic ---------- */
.section { margin-top: 48px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head h2 { margin: 0; }
.lede { font-size: 1.1rem; color: var(--muted); max-width: 760px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.loading { padding: 64px 16px; color: var(--muted); }
.error-box { margin: 40px auto; padding: 18px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 8px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: #ffffff; color: #002e5d; }
.btn-primary:hover { background: #e8eff8; }
.btn-ghost { background: transparent; color: var(--hero-text); border-color: rgba(255,255,255,.45); }
.btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-plain { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-plain:hover { background: var(--surface-2); }

/* ---------- hero ---------- */
.hero { background: var(--hero-bg); color: var(--hero-text); padding: 52px 0 46px; }
.hero h1 { color: var(--hero-text); max-width: 820px; }
.hero p { color: var(--hero-muted); font-size: 1.1rem; max-width: 760px; }
.hero .actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.hero .stats { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 26px; color: var(--hero-muted); font-size: .95rem; }
.hero .stats strong { color: var(--hero-text); font-size: 1.15rem; margin-right: 4px; }
.hero :focus-visible { outline-color: #9cc6ff; }

/* ---------- badges ---------- */
.badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .74rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border); line-height: 1.3;
  white-space: nowrap;
}
.badge-type { background: var(--surface); color: var(--text); }
.badge-type::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--tc, var(--t-plugin)); }
.badge-type.t-skill { --tc: var(--t-skill); }
.badge-type.t-agent { --tc: var(--t-agent); }
.badge-type.t-hook { --tc: var(--t-hook); }
.badge-type.t-template { --tc: var(--t-template); }
.badge-type.t-plugin { --tc: var(--t-plugin); }
.m-proven, .m-verified { background: var(--proven-bg); color: var(--proven-text); border-color: var(--proven-border); }
.m-beta { background: var(--beta-bg); color: var(--beta-text); border-color: var(--beta-border); }
.m-new { background: var(--new-bg); color: var(--new-text); border-color: var(--new-border); }
.m-unlabeled { background: var(--unl-bg); color: var(--unl-text); border-color: var(--unl-border); }
.m-external { background: var(--ext-bg); color: var(--ext-text); border-color: var(--ext-border); }
.m-mixed { background: var(--surface-2); color: var(--text); }
.badge-starter { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- cards ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  position: relative; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; color: var(--text); text-decoration: none; box-shadow: var(--shadow);
  transition: box-shadow .15s ease, border-color .15s ease, transform .15s ease;
  min-width: 0;
}
a.card:hover { box-shadow: var(--shadow-hover); border-color: var(--border-strong); transform: translateY(-1px); }
.card h3 { margin: 0; font-family: var(--mono); font-size: 1rem; font-weight: 700; overflow-wrap: anywhere; }
.card .desc {
  color: var(--muted); font-size: .93rem; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card .meta { margin-top: auto; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .84rem; color: var(--muted); }
.card .meta span { white-space: nowrap; }
.card-plugin h3 { font-size: 1.08rem; }
.card-plugin .counts { font-size: .86rem; color: var(--muted); }
.card .install-mini { margin-top: 4px; }
@media (prefers-reduced-motion: reduce) { .card { transition: none; } a.card:hover { transform: none; } }

/* ---------- code + copy ---------- */
.cmd {
  background: var(--code-bg); color: var(--code-text);
  border-radius: var(--radius-sm); margin: 0 0 10px; border: 1px solid var(--border); overflow: hidden;
}
.cmd-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 6px 0 14px; }
.cmd .label { font-size: .74rem; color: #a9bbcf; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.cmd pre { margin: 0; padding: 6px 14px 12px; overflow-x: auto; white-space: pre; font-size: .86rem; line-height: 1.55; }
.cmd code { font-size: inherit; color: inherit; background: none; padding: 0; }
.copy {
  min-height: 34px; min-width: 76px; padding: 0 12px; border-radius: 6px; cursor: pointer;
  font: 600 .82rem var(--font); background: #23344a; color: #f1f5fa; border: 1px solid #3c5170;
}
.copy:hover { background: #2d4360; }
.copy.done { background: #1e5a36; border-color: #2f7d4f; }
.copy:focus-visible { outline-color: #9cc6ff; }

/* ---------- home ---------- */
.layers { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.layer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.layer h3 { display: flex; align-items: center; gap: 8px; }
.layer h3 .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--tc, var(--t-plugin)); flex: none; }
.layer p { color: var(--muted); font-size: .95rem; margin-bottom: .6em; }
.layer .when { color: var(--text); font-size: .92rem; margin: 0; }
.callout { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 18px; }
.callout h2 { font-size: 1.2rem; }
.two-col { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .two-col { grid-template-columns: 1fr 1fr; } }

/* ---------- browse ---------- */
.browse { display: grid; gap: 24px; grid-template-columns: 1fr; margin-top: 28px; }
@media (min-width: 900px) { .browse { grid-template-columns: 250px 1fr; } }
.search { position: relative; margin-bottom: 14px; }
.search input {
  width: 100%; min-height: 46px; padding: 0 14px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
}
.search input::placeholder { color: var(--muted); opacity: 1; }
.filters { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.filters > summary {
  list-style: none; cursor: pointer; padding: 12px 14px; font-weight: 650;
  display: flex; justify-content: space-between; align-items: center; min-height: 44px;
}
.filters > summary::-webkit-details-marker { display: none; }
.filters > summary::after { content: "+"; font-size: 1.2rem; color: var(--muted); }
.filters[open] > summary::after { content: "\2212"; }
@media (min-width: 900px) {
  .filters > summary { display: none; }
  .filters { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow: auto; }
}
.filter-body { padding: 4px 14px 14px; }
fieldset { border: 0; margin: 0 0 14px; padding: 0; min-width: 0; }
legend { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--muted); margin-bottom: 4px; padding: 0; }
.check { display: flex; align-items: center; gap: 9px; padding: 5px 2px; cursor: pointer; font-size: .93rem; border-radius: 4px; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }
.check .n { margin-left: auto; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.check:hover { background: var(--surface-2); }
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.results-head p { margin: 0; color: var(--muted); }
.link-btn { background: none; border: 0; color: var(--link); font: inherit; cursor: pointer; text-decoration: underline; padding: 6px 2px; min-height: 32px; }
.empty { padding: 30px; text-align: center; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--muted); }

/* ---------- detail ---------- */
.crumbs { font-size: .9rem; color: var(--muted); margin: 24px 0 12px; overflow-wrap: anywhere; }
.crumbs a { color: var(--muted); }
.detail-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.detail-head h1 { font-family: var(--mono); font-size: clamp(1.5rem, 4vw, 2.1rem); overflow-wrap: anywhere; margin: 0; }
.detail-head .desc { font-size: 1.08rem; color: var(--muted); max-width: 820px; margin: 0; }
.detail { display: grid; gap: 28px; grid-template-columns: 1fr; }
@media (min-width: 1000px) { .detail { grid-template-columns: minmax(0, 1fr) 320px; } }
.detail > * { min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 20px; }
.panel h2 { font-size: 1.15rem; }
.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: .94rem; }
.facts dt { color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.notice { border-radius: var(--radius-sm); padding: 12px 14px; margin: 0 0 14px; font-size: .94rem; border: 1px solid; }
.notice-new { background: var(--new-bg); color: var(--new-text); border-color: var(--new-border); }
.notice-info { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.notice p:last-child { margin-bottom: 0; }
.labels { margin: 14px 0 0; display: grid; gap: 8px; font-size: .9rem; }
.label-row { display: grid; grid-template-columns: 5.5rem 1fr; gap: 10px; align-items: baseline; padding: 6px 8px; border-radius: var(--radius-sm); }
.label-row dt, .label-row dd { margin: 0; }
.label-row dd { color: var(--muted); }
.label-row.is-current { background: var(--surface-2); }
.label-row.is-current dd { color: var(--text); }
.notice code { background: rgba(127,127,127,.15); padding: 1px 4px; border-radius: 4px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tab {
  background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted);
  font: 600 .95rem var(--font); padding: 10px 12px; cursor: pointer; white-space: nowrap; min-height: 44px;
}
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }
.tabpanel > p { font-size: .95rem; }
.scope { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; border: 0; padding: 0; }
.scope legend { width: 100%; }
.scope label {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: 40px;
  border: 1px solid var(--border-strong); border-radius: 8px; cursor: pointer; font-size: .92rem;
}
.scope label:has(input:checked) { border-color: var(--accent); background: var(--surface-2); }
.scope input { accent-color: var(--accent); margin: 0; }

.md { overflow-wrap: break-word; }
.md h1 { font-size: 1.6rem; margin-top: 1.2em; }
.md h2 { font-size: 1.3rem; margin-top: 1.4em; padding-top: .3em; border-top: 1px solid var(--border); }
.md h3 { font-size: 1.1rem; margin-top: 1.3em; }
.md > :first-child { margin-top: 0; border-top: 0; padding-top: 0; }
.md pre { background: var(--code-bg); color: var(--code-text); padding: 12px 14px; border-radius: var(--radius-sm); overflow-x: auto; font-size: .85rem; }
.md :not(pre) > code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: .9rem; margin: 0 0 1em; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 9px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md blockquote { margin: 0 0 1em; padding: 4px 14px; border-left: 4px solid var(--border-strong); color: var(--muted); }
.md ul, .md ol { padding-left: 1.4em; }
.md li { margin: .2em 0; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.md img { max-width: 100%; height: auto; }

.file-list { list-style: none; padding: 0; margin: 0; font-size: .88rem; }
.file-list li { padding: 4px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.file-list li:last-child { border-bottom: 0; }
.related { display: grid; gap: 10px; }
.related .card { padding: 12px; }

/* ---------- sdlc ---------- */
.stages { list-style: none; margin: 24px 0 0; padding: 0; display: grid; gap: 14px; }
.stage { display: grid; grid-template-columns: 52px 1fr; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stage-num {
  width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center;
  background: #002e5d; color: #fff; font-weight: 800; font-size: 1.2rem;
}
@media (prefers-color-scheme: dark) { .stage-num { background: #1d4f86; } }
.stage h2 { font-size: 1.2rem; margin: 0 0 6px; }
.stage .goal { margin: 0 0 4px; }
.stage .gate { margin: 0 0 10px; color: var(--muted); font-size: .93rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: 600 .85rem var(--mono); text-decoration: none; min-height: 34px;
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--tc, var(--t-plugin)); }
.chip:hover { border-color: var(--accent); background: var(--surface-2); }
.chip.t-skill { --tc: var(--t-skill); } .chip.t-agent { --tc: var(--t-agent); }
.chip.t-hook { --tc: var(--t-hook); } .chip.t-template { --tc: var(--t-template); }
.chip .chip-new { font: 700 .66rem var(--font); text-transform: uppercase; letter-spacing: .05em; color: var(--new-text); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: .88rem; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
@media (max-width: 520px) {
  .stage { grid-template-columns: 1fr; }
}

/* ---------- contribute ---------- */
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.steps li { counter-increment: step; position: relative; padding: 14px 14px 14px 54px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.steps li::before {
  content: counter(step); position: absolute; left: 14px; top: 13px; width: 28px; height: 28px;
  border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-weight: 700;
}
.prose { max-width: 820px; }

/* ---------- fixes after visual QA ---------- */
h1[tabindex="-1"]:focus:not(:focus-visible), h1[tabindex="-1"]:focus { outline: none; }
.cmd.wrap pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.tabs { flex-wrap: wrap; overflow-x: visible; }
@media (max-width: 560px) { .tab { padding: 10px 9px; font-size: .9rem; } }
