/* Vault shell theme. Explainers style themselves; this only styles the shell. */

:root {
  --bg: oklch(96.5% 0.012 145);
  --sidebar: oklch(92.5% 0.018 145);
  --surface: oklch(98.5% 0.006 145);
  --surface-2: oklch(94.5% 0.012 145);
  --ink: oklch(22% 0.024 130);
  --muted: oklch(48% 0.035 130);
  --faint: oklch(60% 0.026 130);
  --border: oklch(84% 0.018 145);
  --border-strong: oklch(75% 0.026 145);
  --accent: oklch(54% 0.15 32);
  --accent-2: oklch(46% 0.12 205);
  --accent-soft: oklch(92% 0.045 32);
  --selected: oklch(90% 0.033 205);
  --shadow: 0 10px 32px rgb(35 41 33 / 0.08);
  --serif: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: oklch(18% 0.018 145);
  --sidebar: oklch(15.5% 0.018 145);
  --surface: oklch(21.5% 0.02 145);
  --surface-2: oklch(25% 0.024 145);
  --ink: oklch(92% 0.012 120);
  --muted: oklch(69% 0.028 130);
  --faint: oklch(54% 0.026 130);
  --border: oklch(30% 0.024 145);
  --border-strong: oklch(40% 0.03 145);
  --accent: oklch(70% 0.145 42);
  --accent-2: oklch(72% 0.105 205);
  --accent-soft: oklch(26% 0.045 42);
  --selected: oklch(27% 0.045 205);
  --shadow: 0 16px 42px rgb(0 0 0 / 0.28);
}

* { box-sizing: border-box; }

html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, input { font: inherit; }

:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection {
  background: color-mix(in oklch, var(--accent) 24%, transparent);
}

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

/* ---------------------------------------------------------- library page */

body.library {
  height: 100dvh;
  overflow: hidden;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  height: 100dvh;
  transition: grid-template-columns 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0px minmax(0, 1fr);
}

.sidebar {
  /* fixed width so content doesn't reflow while the track animates;
     the translate keeps its right edge glued to the shrinking track */
  width: 310px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: translate 280ms cubic-bezier(0.22, 1, 0.36, 1), visibility 0s 0s;
}

.app-shell.sidebar-collapsed .sidebar {
  translate: -100% 0;
  visibility: hidden;
  transition: translate 280ms cubic-bezier(0.22, 1, 0.36, 1), visibility 0s 280ms;
}

.sidebar-toggle-btn {
  position: absolute;
  left: 310px;
  top: 15px;
  z-index: 10;
  transition: left 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

.app-shell.sidebar-collapsed .sidebar-toggle-btn {
  left: 12px;
}

.app-shell.sidebar-collapsed .workspace-header {
  padding-left: 60px;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 14px 10px;
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--accent);
  font-family: var(--sans);
  font-size: 0.95rem;
}

.search {
  position: relative;
  padding: 0 10px 11px;
}

.search input {
  width: 100%;
  height: 34px;
  padding: 6px 34px 6px 34px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}

.search input:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent-2) 18%, transparent);
}

.search input::placeholder { color: var(--faint); }

.search .glyph {
  position: absolute;
  left: 21px;
  top: 50%;
  translate: 0 -50%;
  color: var(--faint);
  pointer-events: none;
}

.search kbd {
  position: absolute;
  right: 20px;
  top: 50%;
  translate: 0 -50%;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
}

.tree {
  flex: 1;
  overflow: auto;
  padding: 4px 8px 12px;
}

.topic-node { margin: 1px 0; }

.folder {
  width: 100%;
  min-height: 30px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  text-align: left;
}

.folder:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--ink);
}

.folder[aria-pressed="true"] {
  background: var(--selected);
  color: var(--ink);
}

.folder:disabled {
  cursor: default;
  opacity: 0.45;
}

.chevron {
  color: var(--faint);
  font-size: 0.8rem;
}

.folder-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 560;
}

.folder-count {
  min-width: 20px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.72rem;
  text-align: right;
}

.tree-files {
  display: grid;
  gap: 1px;
  padding: 1px 0 5px 26px;
  transition: opacity 150ms ease;
}

.tree-files[hidden] {
  display: none;
}

.tree-file {
  min-height: 28px;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  color: var(--muted);
  border-radius: 5px;
  padding: 3px 7px;
  text-decoration: none;
}

.tree-file:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.tree-file span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-num {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.05em;
  text-align: right;
}

.tree-file:hover .file-num { color: var(--accent); }

.sidebar-status {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--border);
  color: var(--faint);
  font-size: 0.74rem;
  padding: 9px 12px;
}

.workspace {
  min-width: 0;
  overflow: auto;
  background:
    linear-gradient(90deg, color-mix(in oklch, var(--accent-2) 8%, transparent), transparent 28%),
    var(--bg);
}

.workspace-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 28px 34px 16px;
  background: color-mix(in oklch, var(--bg) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.workspace-kicker {
  margin: 0 0 2px;
  color: var(--accent-2);
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.92rem;
}

.workspace-header h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.4rem, 1.1rem + 1.2vw, 1.9rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.workspace-count {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.78rem;
  white-space: nowrap;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 15px 34px 0;
}

.active-filters button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 2px 10px;
  cursor: pointer;
}

.active-filters button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.explainer-list {
  max-width: 980px;
  padding: 16px 34px 70px;
}

.explainer-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) minmax(130px, auto);
  gap: 18px;
  align-items: start;
  border-bottom: 1px solid var(--border);
  padding: 18px 0;
  animation: row-in 380ms cubic-bezier(0.22, 1, 0.36, 1) var(--stagger, 0ms) backwards;
}

@keyframes row-in {
  from {
    opacity: 0;
    translate: 0 10px;
  }
}

.explainer-row:first-child { border-top: 1px solid var(--border); }

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

.row-index {
  padding-top: 5px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}

.row-copy {
  min-width: 0;
}

.row-title {
  display: inline-block;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.3;
  text-decoration: none;
}

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

.row-desc {
  max-width: 66ch;
  margin: 5px 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.tagbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  cursor: pointer;
  font-size: 0.72rem;
}

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

.row-aside {
  display: grid;
  justify-items: end;
  gap: 6px;
  color: var(--faint);
  font-size: 0.78rem;
}

.row-topic {
  color: var(--accent-2);
  font-weight: 650;
}

.row-theme {
  color: var(--faint);
  font-size: 0.72rem;
}

.open-link {
  margin-top: 4px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 4px 10px;
  text-decoration: none;
}

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

.empty {
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  margin-top: 16px;
  padding: 42px 20px;
  text-align: center;
}

.empty .btn { margin-top: 14px; }

/* ------------------------------------------------------------ shared bits */

.btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn {
  padding: 5px 11px;
  font-size: 0.82rem;
}

.icon-btn {
  min-width: 32px;
  padding: 5px 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.btn:hover,
.icon-btn:hover {
  border-color: var(--border-strong);
  color: var(--ink);
}

/* ------------------------------------------------------------ viewer page */

body.viewer {
  height: 100dvh;
  overflow: hidden;
}

/* the entire chrome: one floating pill that ducks out while reading */
.viewer-pill {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: color-mix(in oklch, var(--surface) 86%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  transition: translate 240ms cubic-bezier(0.22, 1, 0.36, 1), opacity 240ms ease;
}

.viewer-pill.is-hidden {
  translate: 0 -70px;
  opacity: 0;
}

.pill-back {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
  white-space: nowrap;
}

.pill-back:hover {
  background: var(--surface-2);
  color: var(--accent);
}

.viewer-pill .icon-btn {
  min-width: 28px;
  min-height: 28px;
  border: 0;
  border-radius: 999px;
  background: transparent;
}

.viewer-pill .icon-btn:hover { background: var(--surface-2); }

.viewer-pill .btn-label { display: none; }

/* fixed-theme explainers pin the chrome; hide the pointless toggle */
html[data-fixed-theme] #theme-toggle { display: none; }

.viewer-frame {
  display: block;
  width: 100%;
  height: 100dvh;
  border: 0;
  background: var(--bg);
}

@media (max-width: 760px) {
  body.library {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    display: block;
    min-height: 100dvh;
  }

  /* collapsing is a desktop affordance; on mobile the sidebar is a header block */
  .sidebar-toggle-btn { display: none; }

  .sidebar,
  .app-shell.sidebar-collapsed .sidebar {
    width: auto;
    translate: none;
    visibility: visible;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .app-shell.sidebar-collapsed .workspace-header {
    padding-left: 18px;
  }

  .tree {
    max-height: 44dvh;
  }

  .sidebar-status {
    display: none;
  }

  .workspace {
    overflow: visible;
  }

  .workspace-header {
    position: static;
    align-items: start;
    padding: 22px 18px 14px;
  }

  .active-filters,
  .explainer-list {
    padding-left: 18px;
    padding-right: 18px;
  }

  .explainer-row {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .row-aside {
    grid-column: 2;
    justify-items: start;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px 10px;
  }
}

@media (max-width: 560px) {
  .viewer-pill {
    top: 10px;
    left: 10px;
  }

  .btn .btn-label,
  .search kbd {
    display: none;
  }

  .workspace-header h1 {
    font-size: 1.35rem;
  }
}
