:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-2: #f3efe8;
  --border: #e6e0d6;
  --border-strong: #d4ccbf;
  --text: #1d1b18;
  --muted: #6c655c;
  --accent: #c2572c;
  --accent-soft: #f6e4da;
  --accent-text: #ffffff;
  --code-bg: #f3efe8;
  --shadow: 0 1px 2px rgb(40 30 20 / 0.05), 0 6px 20px -8px rgb(40 30 20 / 0.12);
  --radius: 14px;
  --font-display: 'Bricolage Grotesque', ui-sans-serif, system-ui, sans-serif;
  --font-body: 'Geist', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12110f;
    --surface: #1a1916;
    --surface-2: #22201c;
    --border: #2c2925;
    --border-strong: #3d3933;
    --text: #ede8e0;
    --muted: #9b938a;
    --accent: #e6865d;
    --accent-soft: #3a261c;
    --accent-text: #1a1210;
    --code-bg: #201e1a;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px -10px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #12110f;
  --surface: #1a1916;
  --surface-2: #22201c;
  --border: #2c2925;
  --border-strong: #3d3933;
  --text: #ede8e0;
  --muted: #9b938a;
  --accent: #e6865d;
  --accent-soft: #3a261c;
  --accent-text: #1a1210;
  --code-bg: #201e1a;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px -10px rgb(0 0 0 / 0.5);
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--font-body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

main { flex: 1; }

a { color: inherit; }
code, kbd, pre { font-family: var(--font-mono); }
[hidden] { display: none !important; }

.wrap { width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 32px; } }

.muted { color: var(--muted); }

/* ---------- top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font: 700 17px/1 var(--font-display); letter-spacing: -0.01em; white-space: nowrap; }
.brand-mark { width: 26px; height: 26px; color: var(--accent); flex: none; }
.topnav { display: flex; align-items: center; gap: 4px; }
.topnav a { text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 500; padding: 6px 10px; border-radius: 8px; }
.topnav a:hover { color: var(--text); background: var(--surface-2); }

.icon-btn {
  display: grid; place-items: center;
  width: 36px; height: 36px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { border-color: var(--border-strong); }

/* ---------- hero */

.hero { padding: 64px 16px 36px; }
@media (min-width: 720px) { .hero { padding: 96px 32px 48px; } }
.eyebrow { margin: 0 0 14px; font: 500 13px/1 var(--font-mono); color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em; }
.hero h1 {
  margin: 0;
  font: 800 clamp(38px, 7vw, 76px)/0.98 var(--font-display);
  letter-spacing: -0.035em;
  max-width: 14ch;
  text-wrap: balance;
}
.muted-h { color: var(--muted); font-weight: 700; }
.tagline { margin: 22px 0 0; max-width: 56ch; font-size: 18px; color: var(--muted); text-wrap: pretty; }
.stats { display: flex; flex-wrap: wrap; gap: 28px; margin-top: 36px; }
.stat b { display: block; font: 700 28px/1 var(--font-display); letter-spacing: -0.02em; }
.stat span { font-size: 13px; color: var(--muted); }

/* ---------- toolbar */

.toolbar { display: flex; flex-direction: column; gap: 14px; padding: 8px 0 22px; border-top: 1px solid var(--border); padding-top: 24px; }
@media (min-width: 860px) { .toolbar { flex-direction: row; align-items: center; } }
.search {
  position: relative; display: flex; align-items: center;
  flex: none; width: 100%;
}
@media (min-width: 860px) { .search { width: 320px; } }
.search svg { position: absolute; left: 13px; width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.search input {
  width: 100%; height: 42px; padding: 0 40px 0 38px;
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 15px;
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input::-webkit-search-cancel-button { display: none; }
.search kbd {
  position: absolute; right: 10px; font-size: 12px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; background: var(--surface-2);
}

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  font: 500 13px/1 var(--font-body); padding: 7px 11px; border-radius: 999px; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.tag { display: inline-block; font: 500 12px/1 var(--font-mono); color: var(--muted); background: var(--surface-2); padding: 5px 8px; border-radius: 6px; }

/* ---------- grid + cards */

.grid { display: grid; gap: 16px; grid-template-columns: 1fr; padding-bottom: 80px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.card {
  position: relative;
  display: flex; flex-direction: column; gap: 14px;
  padding: 20px; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.card:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.glyph {
  flex: none; display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 11px;
  font: 700 15px/1 var(--font-display); letter-spacing: -0.02em;
  color: hsl(var(--h) 55% 30%); background: hsl(var(--h) 70% 90%);
}
:root[data-theme="dark"] .glyph { color: hsl(var(--h) 75% 78%); background: hsl(var(--h) 35% 20%); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .glyph { color: hsl(var(--h) 75% 78%); background: hsl(var(--h) 35% 20%); }
}
.card h3 { margin: 0; font: 600 16px/1.3 var(--font-mono); overflow-wrap: anywhere; }
.card h3 a { text-decoration: none; }
.card h3 a::after { content: ''; position: absolute; inset: 0; border-radius: inherit; }
.card p {
  margin: 0; color: var(--muted); font-size: 14.5px; line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.card .tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.card-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 14px; border-top: 1px dashed var(--border); font-size: 13px; color: var(--muted); }
.card-foot .btn { position: relative; z-index: 1; }

.empty { grid-column: 1 / -1; padding: 56px 24px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--muted); }
.empty h3 { margin: 0 0 6px; color: var(--text); font: 700 20px/1.2 var(--font-display); }
.empty code { background: var(--code-bg); padding: 2px 6px; border-radius: 5px; font-size: 13px; }

/* ---------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 13px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: 500 13.5px/1 var(--font-body); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); filter: brightness(1.07); }
.btn-lg { height: 44px; padding: 0 18px; font-size: 15px; border-radius: 11px; width: 100%; }

/* ---------- detail */

.back { display: inline-block; margin: 28px 0 20px; font-size: 14px; color: var(--muted); text-decoration: none; }
.back:hover { color: var(--text); }

.detail { display: grid; gap: 28px; grid-template-columns: minmax(0, 1fr); padding-bottom: 80px; }
@media (min-width: 960px) { .detail { grid-template-columns: minmax(0, 1fr) 340px; gap: 40px; } }

.detail-head { grid-column: 1 / -1; display: flex; gap: 18px; align-items: flex-start; }
.detail-head .glyph { width: 56px; height: 56px; border-radius: 15px; font-size: 20px; }
.detail-head h1 { margin: 0; font: 700 clamp(26px, 4.5vw, 40px)/1.1 var(--font-mono); letter-spacing: -0.03em; overflow-wrap: anywhere; }
.detail-head p { margin: 10px 0 0; color: var(--muted); max-width: 72ch; text-wrap: pretty; }
.detail-head .tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.desc.clamped { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.more { margin-top: 6px; padding: 0; border: 0; background: none; color: var(--accent); font: 500 14px/1.4 var(--font-body); cursor: pointer; }
.more:hover { text-decoration: underline; }

@media (max-width: 959px) {
  .detail .side { order: 1; }
  .detail #doc { order: 2; }
}

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.side { display: flex; flex-direction: column; gap: 16px; }
@media (min-width: 960px) { .side { position: sticky; top: 84px; align-self: start; } }
.side .panel { padding: 18px; }
.panel h2 { margin: 0 0 12px; font: 600 13px/1 var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.seg { display: flex; gap: 4px; padding: 3px; background: var(--surface-2); border-radius: 9px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); font: 500 13px/1 var(--font-body); padding: 7px 6px; border-radius: 7px; cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }

.cmd { position: relative; }
.cmd pre {
  margin: 0; padding: 12px 44px 12px 12px; background: var(--code-bg); border-radius: 9px;
  font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-all;
}
.cmd .copy { position: absolute; top: 7px; right: 7px; height: 28px; width: 28px; padding: 0; }
.hint { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.copy-skill { width: 100%; margin-top: 12px; }

.meta { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; font-size: 14px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

.files { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow: auto; }
.files li + li { border-top: 1px solid var(--border); }
.files button {
  display: flex; width: 100%; justify-content: space-between; gap: 10px;
  border: 0; background: none; color: var(--text); cursor: pointer; text-align: left;
  padding: 8px 4px; font: 13px/1.4 var(--font-mono);
}
.files button:hover, .files button[aria-current="true"] { color: var(--accent); }
.files button span:first-child { overflow-wrap: anywhere; }
.files button span:last-child { color: var(--muted); flex: none; }

.doc { padding: 28px 22px; min-width: 0; }
@media (min-width: 720px) { .doc { padding: 36px 40px; } }
.doc-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); font: 13px/1 var(--font-mono); color: var(--muted); }
.doc-bar a { color: var(--muted); }
.raw { margin: 0; padding: 20px; overflow: auto; font-size: 13px; line-height: 1.6; background: var(--code-bg); border-radius: 0 0 var(--radius) var(--radius); white-space: pre; }

/* ---------- prose (rendered markdown + install page) */

.prose-wrap { max-width: 780px; padding-bottom: 80px; }
.prose { font-size: 16px; line-height: 1.7; overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { font-family: var(--font-display); letter-spacing: -0.02em; line-height: 1.2; margin: 1.8em 0 0.6em; }
.prose h1 { font-size: 34px; font-weight: 800; }
.prose h2 { font-size: 24px; font-weight: 700; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 19px; font-weight: 700; }
.prose p, .prose ul, .prose ol { margin: 0 0 1em; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: 0.3em; }
.prose a { color: var(--accent); }
.prose code { background: var(--code-bg); padding: 2px 6px; border-radius: 5px; font-size: 0.86em; }
.prose pre { background: var(--code-bg); padding: 16px 18px; border-radius: 10px; overflow-x: auto; font-size: 13.5px; line-height: 1.6; }
.prose pre code { background: none; padding: 0; font-size: inherit; }
.prose blockquote { margin: 0 0 1em; padding: 4px 18px; border-left: 3px solid var(--accent); color: var(--muted); }
.prose table { width: 100%; border-collapse: collapse; margin: 0 0 1em; font-size: 14.5px; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.prose th { background: var(--surface-2); }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.prose img { max-width: 100%; border-radius: 8px; }

/* ---------- admin */

.admin-wrap { max-width: 820px; padding-bottom: 80px; }
.admin-title { margin: 0 0 24px; font: 800 clamp(30px, 5vw, 44px)/1.05 var(--font-display); letter-spacing: -0.03em; }
.admin-card { padding: 22px; margin-bottom: 18px; }
.admin-card > p { margin: 0 0 14px; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.admin-head h2 { margin: 0; }
.admin-head .muted { font: 12.5px/1.3 var(--font-mono); overflow-wrap: anywhere; text-align: right; }
.row { display: flex; gap: 8px; }
.row .btn { height: 42px; padding: 0 18px; font-size: 14.5px; }
.field {
  flex: 1; min-width: 0; height: 42px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit;
}
.field:focus, .slug-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { margin: 10px 0 0; color: #c0392b; font-size: 14px; }
.form-error:empty, .form-ok:empty { display: none; }
.form-ok { margin: 12px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
:root[data-theme="dark"] .form-error { color: #ff8a7a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .form-error { color: #ff8a7a; } }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 34px 18px; border: 1.5px dashed var(--border-strong); border-radius: 12px; background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop svg { width: 30px; height: 30px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 4px; }
.drop b { font-size: 16px; }
.drop .muted { font-size: 13.5px; max-width: 46ch; }
.drop-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 10px; }

.staged-item { display: flex; gap: 12px; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid var(--border); }
.staged-item:first-child { margin-top: 8px; }
.staged-main { flex: 1; min-width: 0; }
.staged-main p { margin: 6px 0; font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.slug-field { display: inline-flex; align-items: center; max-width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); font: 14px/1 var(--font-mono); overflow: hidden; }
.slug-field span { padding: 0 2px 0 10px; color: var(--muted); }
.slug-field input { min-width: 0; width: 26ch; height: 32px; border: 0; background: transparent; color: var(--text); font: inherit; padding: 0 10px 0 0; border-radius: 8px; }
.slug-field input.invalid { color: #c0392b; }
.staged-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.badge { font: 500 12px/1 var(--font-body); padding: 4px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.badge.warn { background: var(--accent-soft); color: var(--accent); }
.badge.bad { background: #c0392b; color: #fff; }

.upload-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 16px; }
.upload-bar #progress-text { flex: 1; min-width: 0; font: 12.5px/1.3 var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { flex-basis: 100%; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.manage { list-style: none; margin: 0; padding: 0; }
.manage li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); font: 14px/1.4 var(--font-mono); }
.manage li:first-child { border-top: 0; }
.manage a { text-decoration: none; overflow-wrap: anywhere; }
.manage a:hover { color: var(--accent); }
.btn-danger:hover { border-color: #c0392b; color: #c0392b; background: transparent; }

.footer a { color: inherit; }

/* ---------- footer, toast */

.footer { border-top: 1px solid var(--border); padding: 24px 0; font-size: 14px; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.skeleton { height: 210px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border: 1px solid var(--border); }
@keyframes shimmer { to { background-position: -200% 0; } }

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

@media (max-width: 480px) {
  .topnav a[href="#/install"] { display: none; }
}
