:root {
  color-scheme: light dark;
  --bg: #fafaf9; --panel: #ffffff; --fg: #1c1917; --muted: #78716c; --line: #e7e5e4;
  --accent: #2563eb; --accent-soft: #dbeafe; --warn: #b45309; --warn-soft: #fef3c7;
  --danger: #b91c1c; --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 1px 1px rgb(0 0 0 / .04);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0a09; --panel: #1c1917; --fg: #f5f5f4; --muted: #a8a29e; --line: #292524;
    --accent: #60a5fa; --accent-soft: #1e3a5f; --warn: #fbbf24; --warn-soft: #422006;
    --danger: #f87171; --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
main { max-width: 56rem; margin: 0 auto; padding: 3rem 1rem 4rem; }
a { color: var(--accent); }

.masthead h1 { font-size: 2rem; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
.tagline { color: var(--muted); margin: .4rem 0 0; font-size: 1.1rem; }
.block { margin-top: 2.5rem; }
.block > h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 .75rem; font-weight: 600; }
.cat { margin-top: 1.5rem; }
.cat.depth-1:first-of-type { margin-top: 0; }
.cat h3 { font-size: 1.15rem; margin: 0 0 .6rem; }
.cat h4, .cat h5 { font-size: 1rem; margin: 0 0 .5rem; color: var(--muted); }
/* Subcategories: set in from their parent, with a rule tying them to it. */
.cat .cat { margin-top: 1.25rem; padding-left: 1rem; border-left: 2px solid var(--line); }
.empty { color: var(--muted); font-style: italic; }
.is-hidden { opacity: .6; }

.prose { max-width: 42rem; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose code { font-size: .9em; background: var(--line); padding: .1em .3em; border-radius: 4px; }

/* cards: a grid of tiles */
.cards { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.card { display: flex; gap: .75rem; align-items: flex-start; padding: .9rem 1rem; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  color: inherit; text-decoration: none; transition: border-color .15s, transform .15s; min-width: 0; }
.card:hover { border-color: var(--accent); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card .icon { font-size: 1.5rem; line-height: 1; }
.card .body { display: flex; flex-direction: column; min-width: 0; }
.card .title { font-weight: 600; }
.card .desc { color: var(--muted); font-size: .92rem; margin-top: .15rem; }
.card .host { color: var(--muted); font-size: .78rem; margin-top: .35rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* list: rows, like the generated index */
.cards.list { display: block; }
.cards.list .card { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; box-shadow: none; background: none; padding: .6rem 0; }
.cards.list .card .body { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 0 .75rem; width: 100%; }
.cards.list .card .title { color: var(--accent); }
.cards.list .card .desc { margin: 0; }
.cards.list .card .host { margin: 0 0 0 auto; }
.cards.list .card .icon { font-size: 1.1rem; }

/* compact: pills */
.cards.compact { display: flex; flex-wrap: wrap; gap: .5rem; }
.cards.compact .card { padding: .35rem .8rem; border-radius: 999px; align-items: center; gap: .4rem; }
.cards.compact .card .icon { font-size: 1rem; }
.cards.compact .card .desc, .cards.compact .card .host { display: none; }
.cards.compact .card .title { font-weight: 500; }

.badge { display: inline-block; font-size: .7rem; font-weight: 600; letter-spacing: .02em; vertical-align: middle;
  padding: .05rem .4rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: transparent; color: var(--danger); border: 1px solid currentColor; }

/* ---------------------------------------------------------------- private side */
.bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .5rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); font-size: .9rem; }
.bar .where { font-weight: 600; margin-right: auto; }
.bar > span:first-child { margin-right: auto; }
.bar .status { color: var(--muted); }
.bar .status.error { color: var(--danger); }
.btn { font: inherit; font-size: .88rem; padding: .3rem .75rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { font-size: .78rem; padding: .15rem .5rem; }
.btn:disabled { opacity: .45; cursor: default; }
.iconbtn { font: inherit; border: 0; background: none; color: var(--muted); cursor: pointer; padding: .15rem .3rem; border-radius: 6px; line-height: 1; }
.iconbtn:hover { color: var(--fg); background: var(--line); }
.iconbtn.on { color: var(--warn); }

/* ---------------------------------------------------------------- editor */
.ed { max-width: 72rem; margin: 0 auto; padding: 1.5rem 1rem 5rem; }
.ed-grid { display: grid; grid-template-columns: minmax(0, 1fr) 17rem; gap: 1.25rem; align-items: start; }
@media (max-width: 800px) { .ed-grid { grid-template-columns: 1fr; } .ed-tray { position: static !important; } }
.ed-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: 1rem; }
.ed-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .6rem 1rem; }
.ed label { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--muted); }
.ed input[type=text], .ed input[type=url], .ed textarea, .ed select, dialog input[type=text], dialog input[type=url], dialog textarea {
  font: inherit; font-size: .92rem; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: 7px; padding: .35rem .5rem; width: 100%; }
.ed textarea { min-height: 7rem; resize: vertical; font-family: ui-monospace, "Cascadia Code", monospace; font-size: .85rem; }
.ed input:focus, .ed textarea:focus, .ed select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.ed .check { flex-direction: row; align-items: center; gap: .35rem; color: var(--fg); font-size: .8rem; white-space: nowrap; }

.ed-block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
.ed-block-head { display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ed-block-head .kind { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.ed-block-head input[type=text] { flex: 1 1 10rem; width: auto; }
.ed-block-body { padding: .75rem; }
.grip { cursor: grab; color: var(--muted); user-select: none; touch-action: none; padding: 0 .2rem; font-size: 1rem; line-height: 1; }
.ed-hint { color: var(--muted); font-size: .8rem; margin: .5rem 0 0; }

.ed-cats { display: flex; flex-direction: column; gap: .6rem; min-height: .5rem; }
.ed-cats.root { min-height: 2rem; }
.ed-cat { border: 1px solid var(--line); border-radius: 9px; background: var(--bg); }
.ed-cat-head { display: flex; align-items: center; gap: .4rem; padding: .4rem .5rem; flex-wrap: wrap; }
.ed-cat-head input[type=text] { flex: 1 1 8rem; width: auto; font-weight: 600; }
.ed-cat-head select { width: auto; }
.ed-cat > .ed-items { margin: 0 .5rem .5rem; }
.ed-cat > .ed-cats { margin: 0 .5rem .5rem 1.25rem; }
.ed-cat > .ed-cats:empty { display: none; }
/* While a category is dragged, every category shows a slot to nest into. */
.dragging-cat .ed-cat > .ed-cats:empty { display: flex; min-height: 1.5rem; border: 1px dashed var(--line); border-radius: 7px; }

.ed-items { display: flex; flex-wrap: wrap; gap: .4rem; min-height: 2.4rem; padding: .35rem;
  border: 1px dashed var(--line); border-radius: 8px; align-content: flex-start; }
.ed-items:empty::after { content: attr(data-empty); color: var(--muted); font-size: .8rem; padding: .3rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; max-width: 100%; padding: .25rem .3rem .25rem .5rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font-size: .88rem; cursor: grab;
  user-select: none; }
.chip .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 14rem; }
.chip.missing { border-style: dashed; opacity: .75; }
.chip .badge { font-size: .62rem; }
.sortable-ghost { opacity: .35; }
.sortable-chosen .chip, .chip.sortable-chosen { border-color: var(--accent); }

.ed-tray { position: sticky; top: 3.5rem; }
.ed-tray h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 .5rem; }
.ed-tray .ed-items { flex-direction: column; align-items: stretch; flex-wrap: nowrap; }
.ed-tray .chip .t { max-width: none; flex: 1; }
.ed-add { display: flex; gap: .5rem; flex-wrap: wrap; margin: .5rem 0 0; }
.ed-banner { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; background: var(--warn-soft); color: var(--warn); display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.ed-banner pre { margin: .25rem 0 0; white-space: pre-wrap; font-size: .8rem; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--fg); padding: 1.1rem; width: min(30rem, calc(100vw - 2rem)); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h3 { margin: 0 0 .8rem; font-size: 1.05rem; }
dialog form { display: flex; flex-direction: column; gap: .6rem; }
dialog label { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--muted); }
dialog .check { flex-direction: row; align-items: center; gap: .4rem; color: var(--fg); }
dialog .note { font-size: .8rem; color: var(--muted); margin: 0; }
dialog .actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .4rem; }
dialog .actions .btn.danger { margin-right: auto; }
