/* KM Pages — self-hosted fonts (no external requests, GDPR-friendly) */
@font-face {
  font-family: "Bricolage";
  src: url("fonts/bricolage.woff2") format("woff2");
  font-weight: 200 800; font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/jetbrains-mono.woff2") format("woff2");
  font-weight: 500; font-display: swap;
}

:root {
  --paper: #eef1f6;
  --surface: #ffffff;
  --ink: #16213a;
  --muted: #5b6884;
  --line: #d8dee9;
  --accent: #2f4bff;
  --accent-ink: #ffffff;
  --accent-soft: #e3e8ff;
  --ok: #0e7a55;
  --ok-soft: #dcf3e9;
  --danger: #b42318;
  --danger-soft: #fde7e4;
  --sans: "Bricolage", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r-sm: 6px;
  --r-lg: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0d1322;
    --surface: #151d31;
    --ink: #e6eaf4;
    --muted: #93a0bd;
    --line: #26304a;
    --accent: #8597ff;
    --accent-ink: #0d1322;
    --accent-soft: #1e2850;
    --ok: #5fd3a1;
    --ok-soft: #12342a;
    --danger: #ff8a7a;
    --danger-soft: #3a1c1c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 16px/1.55 var(--sans);
  font-variation-settings: "wdth" 100;
}
a { color: var(--accent); text-underline-offset: 3px; }
code, .mono { font-family: var(--mono); font-size: .88em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar ---------- */
.bar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { white-space: nowrap; display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  display: grid; place-items: center; color: var(--accent-ink); font-weight: 800; font-size: 15px;
}
.bar .host { color: var(--muted); font-family: var(--mono); font-size: 13px; }
.bar .spacer { flex: 1; }
.bar form { margin: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px; border-radius: var(--r-sm);
  border: 1px solid transparent; background: var(--accent); color: var(--accent-ink);
  font: 600 15px/1 var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn.quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.quiet:hover { background: var(--paper); filter: none; }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13.5px; font-weight: 500; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.danger:hover { background: var(--danger-soft); filter: none; }
.btn svg { width: 15px; height: 15px; flex: none; }

/* ---------- layout ---------- */
.wrap { max-width: 960px; margin: 0 auto; padding: clamp(24px, 5vw, 48px) clamp(16px, 4vw, 32px) 80px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
h1, h2 { margin: 0; letter-spacing: -.01em; line-height: 1.2; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 650; }
.lede { color: var(--muted); margin: 6px 0 0; max-width: 60ch; }

/* ---------- flash / toast ---------- */
.toasts { display: grid; gap: 8px; margin-bottom: 20px; }
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--r-sm); font-weight: 500;
}
.toast.success { background: var(--ok-soft); color: var(--ok); }
.toast.error { background: var(--danger-soft); color: var(--danger); }
.toast svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }

/* ---------- publish: the URL composer (the one bold thing) ---------- */
.publish { padding: clamp(20px, 4vw, 36px); }
.publish-head { display: flex; justify-content: space-between; gap: 16px; align-items: baseline; flex-wrap: wrap; }
.composer { margin: 28px 0 8px; }
.composer label { display: block; color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.url {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 0;
  font-size: clamp(1.6rem, 5vw, 2.8rem); font-weight: 700; letter-spacing: -.025em; line-height: 1.15;
}
.url .host-part { color: var(--muted); font-weight: 400; }
.url input {
  flex: 0 1 auto; min-width: 4ch; max-width: 100%; field-sizing: content; border: 0; padding: 0 0 4px; margin: 0;
  font: inherit; letter-spacing: inherit; color: var(--accent); background: transparent;
  border-bottom: 3px solid var(--accent); border-radius: 0;
}
.url input::placeholder { color: var(--accent); opacity: .35; }
.url input:focus { outline: none; }
.url input:focus-visible { outline: none; border-bottom-color: var(--ink); }
.url .slash { color: var(--muted); font-weight: 400; }
.composer .hint { margin-top: 10px; }
.hint { color: var(--muted); font-size: 14px; }
.hint.bad { color: var(--danger); }
.hint.warn { color: var(--danger); }

.drop {
  margin-top: 24px; position: relative;
  border: 1.5px dashed var(--line); border-radius: var(--r-lg);
  padding: 28px 20px; text-align: center; background: var(--paper);
  transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop strong { display: block; font-size: 1.05rem; }
.drop .hint { margin: 4px 0 0; }
.drop svg { width: 28px; height: 28px; color: var(--accent); margin-bottom: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  display: inline-flex; gap: 8px; align-items: center;
  padding: 5px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--ink);
  font-size: 13.5px;
}
.chip .mono { font-size: 12.5px; color: var(--muted); }

.actions { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-top: 24px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px; background: var(--paper); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { padding: 6px 12px; border-radius: 4px; font-size: 14px; cursor: pointer; color: var(--muted); }
.seg input:checked + label { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--line); }
.seg input:focus-visible + label { outline: 2px solid var(--accent); }

.progress { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 18px; display: none; }
.progress.on { display: block; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---------- sites list ---------- */
.sites { margin-top: 40px; }
.sites-head { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 14px; }
.sites-head .count { color: var(--muted); font-size: 14px; margin-top: 2px; }
.search {
  height: 38px; width: min(260px, 100%); padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface);
  color: var(--ink); font: inherit; font-size: 14.5px;
}
.list { list-style: none; margin: 0; padding: 0; }
.site {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 20px; align-items: center;
  padding: 16px 20px; border-top: 1px solid var(--line);
}
.site:first-child { border-top: 0; }
.site.fresh { background: var(--accent-soft); }
.site-path { font-family: var(--mono); font-size: 15px; font-weight: 500; color: var(--ink); text-decoration: none; }
.site-path:hover { color: var(--accent); }
.site-title { color: var(--ink); margin-left: 10px; }
.site-meta { grid-column: 1; color: var(--muted); font-size: 13.5px; display: flex; gap: 14px; flex-wrap: wrap; }
.site-meta .warn { color: var(--danger); font-weight: 500; }
.site-actions { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.site-actions form { margin: 0; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }

@media (max-width: 640px) {
  .site { grid-template-columns: 1fr; }
  .site-actions { grid-column: 1; grid-row: auto; justify-content: flex-start; }
  .site-title { display: block; margin: 2px 0 0; }
  .bar .host, .bar .hide-sm { display: none; }
  .actions .btn { width: 100%; }
  .seg { width: 100%; }
  .seg label { flex: 1; text-align: center; }
  .search { width: 100%; }
}

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .panel { width: min(400px, 100%); padding: 32px; }
.auth h1 { margin: 22px 0 4px; }
.field { margin-top: 18px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field input {
  width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--paper); color: var(--ink); font: inherit;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.auth .btn { width: 100%; margin-top: 24px; height: 44px; }
.auth .toasts { margin: 18px 0 0; }

/* ---------- public start page ---------- */
.home { min-height: 100vh; display: flex; flex-direction: column; }
.home-main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: clamp(48px, 12vh, 140px) clamp(16px, 5vw, 48px) 48px; }
.home-host {
  font-size: clamp(2.4rem, 9vw, 6.2rem); font-weight: 800; letter-spacing: -.045em; line-height: .95;
  margin: 0; overflow-wrap: anywhere;
}
.home-host span { color: var(--accent); }
.home-lede { font-size: clamp(1.05rem, 2vw, 1.25rem); color: var(--muted); max-width: 52ch; margin: 24px 0 0; }
.dir { margin-top: clamp(40px, 8vh, 80px); }
.dir h2 { font-size: 1rem; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.dir ul { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.dir li { border-bottom: 1px solid var(--line); }
.dir a {
  display: flex; gap: 20px; align-items: baseline; justify-content: space-between;
  padding: 18px 4px; color: var(--ink); text-decoration: none;
}
.dir a:hover .dir-path { color: var(--accent); }
.dir-path { font-family: var(--mono); font-size: clamp(1rem, 2.4vw, 1.3rem); font-weight: 500; }
.dir-title { color: var(--muted); text-align: right; }
.home-foot {
  max-width: 1040px; width: 100%; margin: 0 auto; padding: 24px clamp(16px, 5vw, 48px) 32px;
  display: flex; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 14px; flex-wrap: wrap;
}
.home-foot a { color: var(--muted); }

/* ---------- 404 ---------- */
.nf .home-host { font-size: clamp(2rem, 7vw, 4.4rem); }

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

.sites .panel { overflow: hidden; }
