/* Campaign Wiki — Phase 3 theme system. Vanilla CSS, no framework.
   EVERY color goes through a CSS var (Worker C's pages consume the same
   contract). The worker injects data-theme (+ optional --accent) on <html>;
   light is the default look and stays pixel-identical to Phase 2.1. */

:root, [data-theme="light"] {
  --bg: #e9ebf0;             /* light gray content background */
  --bg-soft: #f4f5f8;        /* subtle fills, editor chrome */
  --card: #ffffff;
  --input-bg: #ffffff;
  --ink: #1f2430;
  --ink-dim: #5f6673;
  --faint: #9aa1ad;
  --line: #dde1e8;
  --accent: #4f46e5;         /* indigo primary; inline --accent overrides it */
  --accent-dark: color-mix(in srgb, var(--accent), black 15%);
  --accent-soft: color-mix(in srgb, var(--accent), transparent 88%);
  --on-accent: #ffffff;      /* text on accent fills: buttons, chips, pills */
  --warm: #d97706;           /* warm accent */
  --bookmark-gold: #fbbf24;  /* saved-bookmark star on dark scrims, both themes */
  --link: #1d4ed8;           /* readable blue in-text links */
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --sidebar-bg: #20242e;     /* charcoal/navy; stays dark in every theme */
  --sidebar-ink: #c9ced9;
  --sidebar-dim: #8b93a3;
  --sidebar-active: #2e3444;
  --on-dark: #ffffff;        /* text on the charcoal sidebar / banner scrim */
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --badge-hidden-bg: #fef2f2;
  --badge-hidden-border: #fecaca;
  --badge-hidden-fg: #b91c1c;
  --tint-npc-bg: #fef3e2; --tint-npc-fg: #92400e;
  --tint-location-bg: #e9f7ec; --tint-location-fg: #2f7a3d;
  --tint-faction-bg: #f1eafc; --tint-faction-fg: #6d3fc0;
  --tint-item-bg: #e7f3fd; --tint-item-fg: #1d5fa8;
  --tint-session-bg: #fdecea; --tint-session-fg: #b23a2a;
  --tint-rule-bg: #eef1f4; --tint-rule-fg: #55606e;
  --tint-note-bg: #e6f7f4; --tint-note-fg: #0f766e;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 24, 40, 0.08);
  --shadow-lg: 0 8px 24px rgba(20, 24, 40, 0.12);
  --content-max: 1280px;
  --sidebar-w: 240px;
}

[data-theme="dark"] {
  --bg: #14171f;
  --bg-soft: #1a2030;
  --card: #1e2330;
  --input-bg: #1e2330;
  --ink: #e8eaf0;
  --ink-dim: #a7adba;
  --faint: #6b7280;
  --line: #2e3444;
  --accent: #4f46e5;
  --accent-dark: color-mix(in srgb, var(--accent), black 15%);
  --accent-soft: color-mix(in srgb, var(--accent), transparent 88%);
  --on-accent: #ffffff;
  --warm: #e8a13c;
  --link: #93b4fd;
  --danger: #e5484d;
  --danger-dark: #c23338;
  --sidebar-bg: #171b25;     /* charcoal, slightly deepened */
  --sidebar-ink: #c9ced9;
  --sidebar-dim: #8b93a3;
  --sidebar-active: #262c3d;
  --on-dark: #ffffff;
  --topbar-bg: rgba(30, 35, 48, 0.92);
  --badge-hidden-bg: #3a2226;
  --badge-hidden-border: #5c3036;
  --badge-hidden-fg: #f09595;
  --tint-npc-bg: #3a2b14; --tint-npc-fg: #f0c46c;
  --tint-location-bg: #123322; --tint-location-fg: #7fd79a;
  --tint-faction-bg: #2c2145; --tint-faction-fg: #c4a8f0;
  --tint-item-bg: #12283d; --tint-item-fg: #7fb8ec;
  --tint-session-bg: #3d1f1a; --tint-session-fg: #f0977f;
  --tint-rule-bg: #2a2f3a; --tint-rule-fg: #b9c2d0;
  --tint-note-bg: #12332f; --tint-note-fg: #6fd6c9;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* "auto" carries no vars itself; the OS dark preference applies the dark
   palette to it. */
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #14171f;
    --bg-soft: #1a2030;
    --card: #1e2330;
    --input-bg: #1e2330;
    --ink: #e8eaf0;
    --ink-dim: #a7adba;
    --faint: #6b7280;
    --line: #2e3444;
    --accent: #4f46e5;
    --accent-dark: color-mix(in srgb, var(--accent), black 15%);
    --accent-soft: color-mix(in srgb, var(--accent), transparent 88%);
    --on-accent: #ffffff;
    --warm: #e8a13c;
    --link: #93b4fd;
    --danger: #e5484d;
    --danger-dark: #c23338;
    --sidebar-bg: #171b25;
    --sidebar-ink: #c9ced9;
    --sidebar-dim: #8b93a3;
    --sidebar-active: #262c3d;
    --on-dark: #ffffff;
    --topbar-bg: rgba(30, 35, 48, 0.92);
    --badge-hidden-bg: #3a2226;
    --badge-hidden-border: #5c3036;
    --badge-hidden-fg: #f09595;
    --tint-npc-bg: #3a2b14; --tint-npc-fg: #f0c46c;
    --tint-location-bg: #123322; --tint-location-fg: #7fd79a;
    --tint-faction-bg: #2c2145; --tint-faction-fg: #c4a8f0;
    --tint-item-bg: #12283d; --tint-item-fg: #7fb8ec;
    --tint-session-bg: #3d1f1a; --tint-session-fg: #f0977f;
    --tint-rule-bg: #2a2f3a; --tint-rule-fg: #b9c2d0;
    --tint-note-bg: #12332f; --tint-note-fg: #6fd6c9;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); }

/* ---------------- App shell ---------------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  z-index: 60;
}

.side-brand {
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.side-brand a {
  color: var(--on-dark);
  text-decoration: none;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.side-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sidebar-dim);
  padding: 0.75rem 0.75rem 0.35rem;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: var(--sidebar-ink);
  text-decoration: none;
  font-size: 0.95rem;
}

.side-link svg {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  opacity: 0.85;
}

.side-link:hover { background: rgba(255, 255, 255, 0.06); color: var(--on-dark); }

.side-link.active {
  background: var(--accent);
  color: var(--on-dark);
}

.side-link.active svg { opacity: 1; }

.side-count {
  margin-left: auto;
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.1);
  color: var(--sidebar-dim);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  min-width: 1.75rem;
  text-align: center;
}

.side-link.active .side-count { background: rgba(255, 255, 255, 0.22); color: var(--on-dark); }

.side-foot {
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.content {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--topbar-bg);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.5rem;
}

.top-search { flex: 1; max-width: 560px; }

.top-search input {
  font: inherit;
  width: 100%;
  background: var(--bg-soft);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.5rem 1rem 0.5rem 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%239aa1ad' stroke-width='1.8'%3E%3Ccircle cx='7' cy='7' r='4.5'/%3E%3Cpath d='M10.5 10.5L14 14'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.7rem center;
  background-size: 16px 16px;
}

.top-search input:focus { outline: none; border-color: var(--accent); }

.top-actions {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.icon-btn {
  display: none;
  font: inherit;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 0.4rem 0.65rem;
  cursor: pointer;
  line-height: 1;
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 26, 0.5);
  z-index: 55;
}

.page {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 1.75rem 1.5rem 4rem;
}

/* ---------------- Buttons, badges, cards ---------------- */

.btn {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn-accent:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: var(--on-accent); }

.btn-ghost { background: transparent; }

.btn-block { display: flex; justify-content: center; width: 100%; }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--on-accent);
}

.btn-danger:hover { background: var(--danger-dark); border-color: var(--danger-dark); color: var(--on-accent); }

.btn:disabled { opacity: 0.6; cursor: default; }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-hidden {
  background: var(--badge-hidden-bg);
  border-color: var(--badge-hidden-border);
  color: var(--badge-hidden-fg);
}

/* Per-type badge tints (light theme). listing.js/article.js emit
   "badge-<type>"; the "badge-type-<type>" aliases are used by new markup. */
.badge-npc, .badge-type-npc { background: var(--tint-npc-bg); color: var(--tint-npc-fg); }
.badge-location, .badge-type-location { background: var(--tint-location-bg); color: var(--tint-location-fg); }
.badge-faction, .badge-type-faction { background: var(--tint-faction-bg); color: var(--tint-faction-fg); }
.badge-item, .badge-type-item { background: var(--tint-item-bg); color: var(--tint-item-fg); }
.badge-session, .badge-type-session { background: var(--tint-session-bg); color: var(--tint-session-fg); }
.badge-rule, .badge-type-rule { background: var(--tint-rule-bg); color: var(--tint-rule-fg); }
.badge-note, .badge-type-note { background: var(--tint-note-bg); color: var(--tint-note-fg); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
}

.card h2 {
  font-size: 1.05rem;
  margin: 0 0 0.9rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
}

.empty {
  color: var(--ink-dim);
  font-style: italic;
  margin: 0.5rem 0;
}

/* ---------------- Sidebar header (config-driven) ---------------- */

.side-head { border-bottom: 1px solid rgba(255, 255, 255, 0.08); }

.side-head-img {
  display: block;
  aspect-ratio: 16 / 7;
  overflow: hidden;
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--accent), black 35%),
    color-mix(in srgb, var(--accent), black 62%));
}

.side-head-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.side-head-body { padding: 0.9rem 1.25rem 1rem; }

.side-head-title {
  color: var(--on-dark);
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  display: block;
  overflow-wrap: anywhere;
}

.side-head-title:hover { color: var(--on-dark); text-decoration: underline; }

.side-head-tagline {
  color: var(--sidebar-dim);
  font-size: 0.85rem;
  margin: 0.3rem 0 0;
  line-height: 1.45;
}

.side-head-updated {
  color: var(--sidebar-dim);
  font-size: 0.75rem;
  margin: 0.4rem 0 0;
}

.side-gm {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin-top: 0.5rem;
  padding-top: 0.35rem;
}

/* ---------------- Dashboard (Phase 3) ---------------- */

.dash-banner {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 220px;
  display: flex;
  align-items: flex-end;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  margin-bottom: 1.75rem;
}

.dash-banner-bg { position: absolute; inset: 0; }

.dash-banner-bg img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.dash-banner-blank {
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg,
    color-mix(in srgb, var(--accent), black 25%),
    color-mix(in srgb, var(--accent), black 58%) 70%,
    color-mix(in srgb, var(--accent), black 78%));
}

.dash-banner-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top,
    rgba(10, 12, 18, 0.78) 0%,
    rgba(10, 12, 18, 0.25) 55%,
    rgba(10, 12, 18, 0.05) 100%);
}

.dash-banner-body {
  position: relative;
  padding: 1.5rem 1.75rem;
  color: var(--on-dark);
  min-width: 0;
}

.dash-banner-title {
  margin: 0 0 0.25rem;
  font-size: 2rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.dash-banner-tagline {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  color: rgba(255, 255, 255, 0.85);
}

.dash-stats {
  margin: 0;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.75);
}

.dash-section { margin-bottom: 2rem; }

.dash-section > h2 {
  font-size: 1.25rem;
  margin: 0 0 0.8rem;
  letter-spacing: -0.01em;
}

.featured { margin-bottom: 2rem; }

.featured-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  font-weight: 700;
  margin: 0 0 0.6rem;
}

/* Entity cards: image on top, title, short excerpt (spec §4.2). */

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

.entity-card {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  text-decoration: none;
  color: var(--ink);
  min-width: 0;
}

.entity-card:hover { border-color: var(--accent); box-shadow: var(--shadow-lg); }

.entity-card-img {
  display: block;
  aspect-ratio: 16 / 9;
  background: var(--bg-soft);
  overflow: hidden;
  flex: 0 0 auto;
}

.entity-card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.entity-card-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

.entity-card-placeholder svg { width: 40px; height: 40px; opacity: 0.75; }

.tint-npc { background: var(--tint-npc-bg); color: var(--tint-npc-fg); }
.tint-location { background: var(--tint-location-bg); color: var(--tint-location-fg); }
.tint-faction { background: var(--tint-faction-bg); color: var(--tint-faction-fg); }
.tint-item { background: var(--tint-item-bg); color: var(--tint-item-fg); }
.tint-session { background: var(--tint-session-bg); color: var(--tint-session-fg); }
.tint-rule { background: var(--tint-rule-bg); color: var(--tint-rule-fg); }
.tint-note { background: var(--tint-note-bg); color: var(--tint-note-fg); }
.tint-map { background: var(--accent-soft); color: var(--accent-dark); }

.entity-card-body {
  padding: 0.8rem 1rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.entity-card-title {
  font-weight: 650;
  font-size: 1rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.entity-card:hover .entity-card-title { color: var(--accent); }

.entity-card-excerpt {
  color: var(--ink-dim);
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.entity-card-badges {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 0.15rem;
}

@media (min-width: 700px) {
  .entity-card-featured { flex-direction: row; }
  .entity-card-featured .entity-card-img {
    width: 42%;
    flex-basis: 42%;
    aspect-ratio: auto;
    min-height: 220px;
  }
  .entity-card-featured .entity-card-body { justify-content: center; padding: 1.5rem; }
  .entity-card-featured .entity-card-title { font-size: 1.35rem; }
}

/* Explore rows: one per visible sidebar category. */

.explore-row { margin-bottom: 2rem; }

.explore-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.explore-head h2 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}

.view-all {
  margin-left: auto;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.tags-card { margin-top: 0; }
.tags-card h2 { margin-top: 0; }

.browse { margin-top: 0; }

.browse h2 { margin-top: 0; }

/* ---------------- Search, chips, tag cloud ---------------- */

.search-wrap {
  position: relative;
  margin: 1rem 0;
}

.search-box {
  font: inherit;
  width: 100%;
  background: var(--input-bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 2.25rem 0.65rem 0.9rem;
  box-shadow: var(--shadow);
}

.search-box:focus { outline: none; border-color: var(--accent); }

.search-clear {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  color: var(--ink-dim);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem;
}

.search-clear:hover { color: var(--ink); }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 1rem;
}

.chip {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 550;
  cursor: pointer;
  background: var(--card);
  color: var(--ink-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
}

.chip:hover { color: var(--accent); border-color: var(--accent); }

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}

/* Tag "bubbles": first-letter chip + name + count, Kanka-style. */
.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  text-decoration: none;
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.28rem 0.8rem 0.28rem 0.35rem;
  line-height: 1.4;
}

.tag-pill:hover { border-color: var(--accent); }

.tag-pill .bubble {
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.8rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}

.tag-pill .count {
  color: var(--faint);
  font-size: 0.8em;
}

.filter-note {
  color: var(--ink-dim);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

/* Small tag chips on article rows and in the profile sidebar. */

.tag-chip {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 550;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.12rem 0.6rem;
  text-decoration: none;
  margin: 0.1rem 0.25rem 0.1rem 0;
  line-height: 1.5;
}

.tag-chip:hover { background: var(--accent); color: var(--on-accent); }

.article-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.article-list li {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--line);
}

.article-list li:last-child { border-bottom: 0; }

.article-list a { color: var(--ink); text-decoration: none; font-size: 1.05rem; font-weight: 550; }
.article-list a:hover { color: var(--accent); }

.article-list .meta { color: var(--ink-dim); font-size: 0.85rem; margin-left: 0.5rem; }
.article-list .row-tags { margin-left: 0.5rem; }

/* ---------------- Article page ---------------- */

.crumbs {
  font-size: 0.88rem;
  margin: 0 0 1rem;
  color: var(--ink-dim);
}

.crumbs a { color: var(--ink-dim); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }

.crumbs .crumb-sep { margin: 0 0.35rem; color: var(--faint); }

.article-head h1 {
  margin: 0 0 0.35rem;
  font-size: 2rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.article-title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.article-meta {
  color: var(--ink-dim);
  font-size: 0.9rem;
  padding-bottom: 1rem;
  margin: 0.25rem 0 0;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

/* Tab strip: Overview | Linked from (N) */

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid var(--line);
  margin: 1.25rem 0 1.5rem;
}

.tab-btn {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--ink-dim);
  padding: 0.6rem 1rem;
  cursor: pointer;
}

.tab-btn:hover { color: var(--ink); }

.tab-btn.active {
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
}

.tab-count {
  font-size: 0.78rem;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  margin-left: 0.25rem;
}

.tab-btn.active .tab-count { background: var(--accent); color: var(--on-accent); }

.tab-panel[hidden] { display: none; }

/* Overview tab: body + REAL side profile column (~300px) */

.article-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1.75rem;
  align-items: start;
}

.article-main { min-width: 0; }

.article-body {
  font-size: 1.03rem;
  line-height: 1.65;
}

.article-body .tiptap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem 1.75rem;
}

.article-sidebar {
  position: sticky;
  top: 4.5rem;
}

.sidebar-section { margin-bottom: 1.25rem; }
.sidebar-section:last-child { margin-bottom: 0; }

.sidebar-section h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  margin: 0 0 0.5rem;
}

.sidebar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-list li { margin-bottom: 0.35rem; }

.sidebar-list a, .sidebar-section a { color: var(--link); text-decoration: none; }
.sidebar-list a:hover, .sidebar-section a:hover { text-decoration: underline; }

.sidebar-section .empty { margin: 0; }

.backlinks ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.backlinks li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.backlinks li:last-child { border-bottom: 0; }

.backlinks li a { color: var(--ink); text-decoration: none; font-weight: 550; }
.backlinks li a:hover { color: var(--accent); }

/* ---------------- Listing page (/type/*, /tag/*) ---------------- */

.listing-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.listing-title {
  margin: 0;
  font-size: 1.8rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.listing-count {
  color: var(--ink-dim);
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
}

.listing-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.view-toggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
}

.view-toggle button {
  font: inherit;
  background: transparent;
  color: var(--ink-dim);
  border: 0;
  border-right: 1px solid var(--line);
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.view-toggle button:last-child { border-right: 0; }
.view-toggle button:hover { color: var(--ink); background: var(--bg-soft); }
.view-toggle button.active { color: var(--accent-dark); background: var(--accent-soft); }
.view-toggle svg { width: 18px; height: 18px; display: block; }

.seg-toggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.85rem;
  background: var(--card);
}

.seg-toggle button {
  font: inherit;
  background: transparent;
  color: var(--ink-dim);
  border: 0;
  border-right: 1px solid var(--line);
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}

.seg-toggle button:last-child { border-right: 0; }
.seg-toggle button:hover { color: var(--ink); }
.seg-toggle button.active { color: var(--on-accent); background: var(--accent); }

/* Stacked (nested) view */

.stack-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem 1rem;
  margin-bottom: 0.65rem;
}

.stack-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.stack-title {
  color: var(--ink);
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 600;
}

.stack-title:hover { color: var(--accent); }

.stack-tags { display: inline-flex; gap: 0.15rem; flex-wrap: wrap; }

.stack-children {
  margin: 0.6rem 0 0.1rem;
  padding-left: 1rem;
  border-left: 2px solid var(--line);
}

.stack-children .stack-card { margin-bottom: 0.5rem; box-shadow: none; }
.stack-children .stack-card:last-child { margin-bottom: 0.1rem; }

.child-pill {
  position: relative;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.32rem 0.6rem;
  cursor: pointer;
  margin-left: auto;
}

.child-pill:hover { background: var(--accent); color: var(--on-accent); }

.child-pill::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  width: max-content;
  max-width: 260px;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 0.5rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.5;
  text-align: left;
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
  z-index: 20;
}

.child-pill:hover::after,
.child-pill:focus-visible::after { opacity: 1; }

/* Flattened view: Kanka-style card grid (title, type badge, excerpt, date) */

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

.flat-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.flat-card:hover { border-color: var(--accent); box-shadow: var(--shadow-lg); }

.flat-link::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
}

.flat-name {
  font-size: 1.1rem;
  font-weight: 650;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.flat-meta-row {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

.flat-excerpt {
  color: var(--ink-dim);
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.flat-date {
  color: var(--faint);
  font-size: 0.8rem;
  margin-top: auto;
}

/* Table view */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.listing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  min-width: 640px;
}

.listing-table th,
.listing-table td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.listing-table thead th {
  background: var(--bg-soft);
  padding: 0.3rem 0.4rem;
  white-space: nowrap;
}

.listing-table tbody tr:last-child td { border-bottom: 0; }
.listing-table tbody tr:hover { background: var(--bg-soft); }

.listing-table a { color: var(--ink); text-decoration: none; font-weight: 550; }
.listing-table a:hover { color: var(--accent); }

.listing-table .dim { color: var(--ink-dim); }
.listing-table .nowrap { white-space: nowrap; }

.sort-btn {
  font: inherit;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: transparent;
  border: 0;
  color: var(--ink-dim);
  cursor: pointer;
  padding: 0.35rem 0.4rem;
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
}

.sort-btn:hover { color: var(--ink); }
.sort-btn.sorted { color: var(--accent-dark); }
.sort-arrow { font-size: 0.7rem; }

/* ---------------- Editor + forms (edit.html inner ids intact) ---------------- */

.gate {
  text-align: center;
  padding: 3rem 1rem;
}

.gate p { color: var(--ink-dim); }

.form-row { margin-bottom: 1rem; }

.form-row > label {
  display: block;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.form-row-inline {
  display: flex;
  gap: 2rem;
  align-items: flex-end;
}

.form-row input[type="text"],
.form-row select {
  font: inherit;
  width: 100%;
  background: var(--input-bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
}

.form-row input[type="text"]:focus,
.form-row select:focus { outline: none; border-color: var(--accent); }

.form-row select { width: auto; }

.check {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-size: 1rem !important;
  color: var(--ink) !important;
  cursor: pointer;
}

.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

.status { color: var(--ink-dim); font-size: 0.9rem; }
.hint { color: var(--ink-dim); font-size: 0.85rem; margin-top: 0.5rem; }

/* Editor toolbar */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0.4rem;
  position: sticky;
  top: 60px;
  z-index: 5;
}

.toolbar button {
  font: inherit;
  font-size: 0.9rem;
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  min-width: 2rem;
}

.toolbar button:hover { color: var(--ink); border-color: var(--line); }
.toolbar button.active { color: var(--accent-dark); border-color: var(--accent); }

.toolbar-sep {
  width: 1px;
  background: var(--line);
  margin: 0.25rem 0.15rem;
}

/* TipTap editing surface + read-only article body share prose styles */

.editor,
.article-body .tiptap { color: var(--ink); }

.editor {
  border: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 1rem 1.25rem;
  min-height: 320px;
  background: var(--card);
}

.ProseMirror { outline: none; min-height: 280px; }

.ProseMirror p,
.tiptap p { margin: 0 0 1rem; }

.ProseMirror h1, .ProseMirror h2, .ProseMirror h3,
.tiptap h1, .tiptap h2, .tiptap h3 {
  line-height: 1.3;
  margin: 1.5rem 0 0.75rem;
  color: var(--ink);
}

.ProseMirror h1, .tiptap h1 { font-size: 1.6rem; }
.ProseMirror h2, .tiptap h2 { font-size: 1.35rem; }
.ProseMirror h3, .tiptap h3 { font-size: 1.15rem; }

.ProseMirror ul, .ProseMirror ol,
.tiptap ul, .tiptap ol { padding-left: 1.5rem; margin: 0 0 1rem; }

.ProseMirror blockquote, .tiptap blockquote {
  border-left: 3px solid var(--accent);
  margin: 0 0 1rem;
  padding: 0.25rem 0 0.25rem 1rem;
  color: var(--ink-dim);
}

.ProseMirror a, .tiptap a { color: var(--link); }

.ProseMirror img, .tiptap img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  display: block;
  margin: 1rem auto;
}

.ProseMirror p.is-editor-empty:first-child::before {
  content: 'Start writing…';
  color: var(--faint);
  font-style: italic;
  float: left;
  height: 0;
  pointer-events: none;
}

/* ---------------- Responsive ---------------- */

@media (max-width: 1024px) {
  .article-layout { grid-template-columns: minmax(0, 1fr) 260px; }
}

@media (max-width: 860px) {
  /* Sidebar becomes a hamburger drawer; content full-width. */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: min(var(--sidebar-w), 84vw);
    flex-basis: auto;
  }
  body.nav-open .sidebar { transform: none; }
  .content { margin-left: 0; }
  .icon-btn { display: inline-flex; }
  .article-sidebar { position: static; }
}

@media (max-width: 800px) {
  /* Article profile sidebar stacks below the body. */
  .article-layout { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { padding: 0.6rem 1rem; }
  .page { padding: 1.25rem 1rem 3rem; }
  .top-actions .btn { padding: 0.45rem 0.7rem; font-size: 0.85rem; }
  .listing-head { flex-direction: column; }
  .stack-children { padding-left: 0.6rem; }
  .listing-title { font-size: 1.5rem; }
  .dash-banner-title { font-size: 1.6rem; }
  .dash-banner { min-height: 170px; }
  .article-head h1 { font-size: 1.6rem; }
  .form-row-inline { flex-direction: column; align-items: stretch; gap: 1rem; }
  .toolbar { position: static; }
  .editor { padding: 0.75rem; }
  .article-body .tiptap { padding: 1rem 1.1rem; }
}

/* Phase 3.2: collapsible sidebar groups, bookmarks, listing card grid. */

/* Collapsible sidebar groups (Kanka-style). */
.side-group { margin: 1px 0; }

.side-group-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--sidebar-ink);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  cursor: pointer;
  text-align: left;
}

.side-group-head > svg { width: 16px; height: 16px; flex: 0 0 16px; opacity: 0.8; }

.side-group-head:hover { background: rgba(255, 255, 255, 0.06); color: var(--on-dark); }

.side-group-head .side-chev {
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
  margin-left: auto;
  opacity: 0.7;
  transition: transform 0.15s ease;
}

.side-group.collapsed .side-chev { transform: rotate(-90deg); }

.side-group-cats { display: flex; flex-direction: column; gap: 2px; }

.side-group.collapsed .side-group-cats { display: none; }

.side-group-cats .side-link { padding-left: 1.5rem; font-size: 0.9rem; }

/* Listing card grid (Kanka-style entity cards). */
.entity-card { position: relative; }

.img-43 { aspect-ratio: 4 / 3; }

.entity-card-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.entity-card-title-row .entity-card-title {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entity-card-glyph {
  flex: 0 0 auto;
  display: inline-flex;
  color: var(--ink-dim);
}

.entity-card-glyph svg { width: 16px; height: 16px; }

.entity-card-placeholder .entity-card-glyph svg { width: 40px; height: 40px; opacity: 0.75; }

/* Bookmarks: article-page toggle, dashboard card toggles, bookmarks page. */
.bookmark-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink-dim);
  cursor: pointer;
  padding: 0.32rem 0.45rem;
  line-height: 0;
  margin-left: auto;
  flex: 0 0 auto;
}

.bookmark-btn svg { width: 18px; height: 18px; }

.bookmark-btn:hover { color: var(--accent); border-color: var(--accent); }

.bookmark-btn.saved { color: var(--accent); border-color: var(--accent); }

.bookmark-btn.saved svg { fill: currentColor; }

.entity-card-wrap { position: relative; min-width: 0; }

.entity-card-wrap > .entity-card { height: 100%; }

.card-bookmark {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  background: rgba(10, 12, 18, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  color: var(--on-dark);
  cursor: pointer;
  padding: 0.3rem;
  line-height: 0;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.entity-card-wrap:hover .card-bookmark,
.card-bookmark.saved,
.card-bookmark:focus-visible { opacity: 1; }

.card-bookmark svg { width: 16px; height: 16px; }

.card-bookmark.saved { color: var(--bookmark-gold); border-color: color-mix(in srgb, var(--bookmark-gold), transparent 40%); }

.card-bookmark.saved svg { fill: currentColor; }

@media (hover: none) {
  .card-bookmark { opacity: 1; }
}

.bm-remove {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  background: rgba(10, 12, 18, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  color: var(--on-dark);
  cursor: pointer;
  padding: 0.28rem 0.5rem;
  font-size: 0.85rem;
  line-height: 1;
}

.bm-remove:hover { background: rgba(180, 40, 40, 0.75); }

.bm-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0 0 1.25rem;
}

.bm-toolbar .empty { margin: 0; }

.bm-unavailable {
  color: var(--ink-dim);
  font-size: 0.85rem;
}

/* Phase 6: mobile hardening (390px) + export UI. Surgical fixes only. */

/* The topbar search must be allowed to shrink below its intrinsic input
   width, or the 390px topbar overflows horizontally. */
.top-search { min-width: 0; }
.top-search input { min-width: 0; }

/* Long breadcrumb chains and tab strips scroll instead of breaking layout. */
.crumbs { overflow-x: auto; white-space: nowrap; padding-bottom: 0.25rem; }
.tabs { overflow-x: auto; }
.tab-btn { white-space: nowrap; flex: 0 0 auto; }

/* Customize: data & backup card. */
.export-row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.export-hint { color: var(--ink-dim); font-size: 0.9rem; margin: 0.5rem 0 0; }

@media (max-width: 640px) {
  .topbar { gap: 0.5rem; }
  .top-actions { gap: 0.35rem; }
  .article-head h1 { overflow-wrap: anywhere; }
  .bm-toolbar { flex-wrap: wrap; }
  /* Customize category rows stack: move buttons become a horizontal row. */
  .cat-row { grid-template-columns: 1fr; }
  .cat-move { flex-direction: row; }
  .dash-banner-body { padding: 1rem; }
}
