:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #1f2a3d;
  --muted: #6f7682;
  --accent: #3a76d2;
  --accent-2: #2c64ba;
  --border: #e2e5ed;
  --shadow: 0 20px 60px rgba(31, 42, 61, 0.08);
  --topbar-h: 58px;
  font-family: "Open Sans", "Source Sans 3", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--topbar-h) + 12px); }

body {
  background: var(--bg);
  color: var(--ink);
  margin: 0;
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

main {
  padding: 8px 14px 20px;
  max-width: 1500px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid #e4e7f0;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.02);
  min-height: var(--topbar-h);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: #2f3642; letter-spacing: 0.01em; }
.brand .dot { display: none; }
.brand-icon { width: 20px; height: 20px; border-radius: 4px; }
.topbar nav a { margin-left: 16px; color: #7b8494; font-weight: 600; font-size: 14px; }
.topbar nav a:hover { color: var(--accent); }

.hero {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 32px;
  align-items: center;
  padding: 32px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.copy h1 { font-size: 40px; margin: 10px 0; letter-spacing: -0.01em; }
.lede { color: var(--muted); line-height: 1.7; max-width: 640px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); font-size: 12px; }
.chip { background: var(--panel); padding: 4px 8px; border-radius: 12px; border: 1px solid var(--border); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.panel.tight { max-width: 440px; }

label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 14px; }
.input-row { display: flex; gap: 8px; }
input, select {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #dfe3eb;
  background: #fff;
  color: var(--ink);
}
button {
  background: var(--accent);
  border: 1px solid var(--accent-2);
  padding: 9px 14px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  box-shadow: 0 8px 22px rgba(58, 118, 210, 0.16);
}
button:hover { background: var(--accent-2); }
button:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid #dfe3eb;
  background: #f4f6fa;
  color: #4b5563;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: none;
  padding: 0;
  margin-right: 10px;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); background: #eef2f7; }
.theme-toggle:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.note-msg, .flash { margin-top: 8px; color: var(--accent); }
.muted { color: var(--muted); }

.account-shell { display: grid; gap: 18px; padding: 24px; }
.account-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
.account-info { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 12px; }
.account-info .label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
.account-info .value { font-weight: 600; }
.card-headline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.alias-list { display: flex; gap: 8px; flex-wrap: wrap; }
.pill, .alias-list .pill {
  border: 1px solid #dfe3ec;
  background: #f2f5fb;
  color: #2e3747;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.pill .count { color: #8f97a7; font-size: 12px; }
.pill:hover { border-color: var(--accent); color: var(--accent); background: #e8edff; }

.doc-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  min-height: calc(100vh - 120px);
  background: #fff;
  border: 1px solid #e5e7f0;
  border-radius: 14px;
  align-items: start;
  box-shadow: 0 24px 70px rgba(17, 24, 39, 0.08);
  margin-top: 8px;
}

.toc {
  background: #f8f9fb;
  border-right: 1px solid #e4e7f0;
  padding: 12px;
  overflow-y: auto;
  position: sticky;
  top: calc(var(--topbar-h) + 12px);
  height: calc(100vh - (var(--topbar-h) + 32px));
}
.toc-header { padding: 4px 2px 8px; }
.toc-header .title { font-weight: 700; color: var(--ink); font-size: 15px; }
.toc-header .subtitle { color: var(--muted); font-size: 12px; }
.toc-section { margin-top: 10px; }
.toc-list { list-style: none; padding: 0; margin: 0; }
.toc-list > li { margin-bottom: 4px; }
.folder-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
}
.folder-toggle {
  border: 1px solid #e5e8f0;
  background: #f4f6fa;
  color: #6b7280;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 11px;
}
.folder-toggle:hover { border-color: #d5d8e0; color: #4b5563; background: #eceff5; }
.folder-link { font-weight: 700; color: #2f3642; }
.folder-link:hover { text-decoration: underline; color: var(--accent); }
.folder-item .chevron { display: inline-block; transition: transform 0.16s ease; }
.folder-item:not(.is-collapsed) .chevron { transform: rotate(90deg); }
.folder-item .chevron { font-size: 11px; }
.toc-list a { color: #3c4353; text-decoration: none; display: flex; gap: 6px; align-items: center; padding: 6px; border-radius: 8px; font-weight: 600; font-size: 14px; line-height: 1.3; cursor: pointer; }
.toc-list a:hover { background: #eef2f7; text-decoration: underline; color: var(--accent); }
.toc-list .folder-link {
  display: inline-flex;
  align-items: center;
  padding: 0;
  font-size: 15px;
  font-weight: 700;
  color: #2f3642;
}
.toc-list .folder-link:hover { background: none; }
.toc-num { color: #9aa3b5; font-weight: 600; min-width: 38px; }
.toc-text { font-weight: 600; }
.toc-sub { list-style: none; padding-left: 10px; margin: 2px 0 0; }
.toc-sub li { margin: 1px 0; }
.toc-sub a { font-weight: 500; color: #515b70; padding: 4px 5px; border-radius: 6px; font-size: 13px; line-height: 1.25; cursor: pointer; }
.toc-sub a:hover { background: #eef2f7; text-decoration: underline; color: var(--accent); }
.toc-sub[hidden] { display: none; }
.folder-row .count {
  padding: 2px 7px;
  background: #e5e7eb;
  border-radius: 999px;
  font-size: 11px;
  color: #4b5563;
  justify-self: end;
}
.toc-scrim { display: none; }
.toc-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  border: 1px solid #dfe3eb;
  background: #fff;
  color: #374151;
  border-radius: 8px;
  padding: 7px 10px;
  font-weight: 700;
  cursor: pointer;
}
.toc-toggle:hover { border-color: var(--accent); color: var(--accent); }

.doc-content {
  padding: 18px 24px 24px;
  background: #fff;
}

.doc-toolbar {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e5e7ef;
  position: sticky;
  top: calc(var(--topbar-h) + 8px);
  background: #fff;
  z-index: 5;
}
.search-bar {
  display: flex;
  gap: 10px;
  width: 100%;
  align-items: center;
  padding: 8px 10px;
  background: #f4f6fa;
  border: 1px solid #e3e6ef;
  border-radius: 10px;
}
.search-bar input[type="search"] {
  flex: 1;
  background: #fff;
  border: 1px solid #dfe3eb;
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 600;
  color: #1f2a3d;
}
.search-bar select {
  width: 180px;
  background: #fff;
  border: 1px solid #dfe3eb;
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 600;
  color: #3c4353;
}
.doc-actions { white-space: nowrap; }

.note-sort { display: flex; align-items: center; gap: 8px; padding: 4px 0 10px; }
.note-sort-buttons { justify-content: flex-start; }
.note-sort-select { display: none; width: 100%; }
.sort-btn {
  border: 1px solid #dfe3eb;
  background: #fff;
  color: #374151;
  border-radius: 8px;
  padding: 6px 10px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.sort-btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: underline; }
.sort-btn.is-active {
  background: #eef3ff;
  border-color: var(--accent);
  color: var(--accent-2);
}
.note-sort-select select {
  width: 100%;
  border-radius: 8px;
  border: 1px solid #dfe3eb;
  padding: 7px 10px;
  font-weight: 600;
  color: #374151;
}

.doc-toolbar-icons { display: flex; gap: 8px; }
.toolbar-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #e1e5ee;
  border-radius: 8px;
  background: #f6f8fb;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #7b8396;
  font-weight: 700;
}
.toolbar-btn:hover { border-color: var(--accent); color: var(--accent); background: #eef3ff; }

.doc-main { max-width: 980px; margin: 0 auto; }
.doc-view { padding: 8px 0 28px; }
.doc-note {
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid #e5e8f0;
  border-radius: 10px;
  background: #f7f8fc;
}
.doc-note:last-child { margin-bottom: 0; }
.doc-note-meta { margin-bottom: 8px; color: #7a8091; font-size: 13px; }
.meta-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.doc-note h1 { margin: 4px 0 8px; font-size: 24px; font-weight: 700; color: #111827; letter-spacing: -0.01em; }
.doc-body {
  background: #fdfefe;
  border: 1px solid #e2e6f0;
  border-radius: 6px;
  padding: 12px 14px;
  font-family: "Open Sans", "Source Sans 3", "Helvetica Neue", Arial, sans-serif;
  color: #1f2a3d;
  line-height: 1.55;
}
.doc-body.html-body h1,
.doc-body.html-body h2,
.doc-body.html-body h3,
.doc-body.html-body h4,
.doc-body.html-body h5,
.doc-body.html-body h6 { margin: 0.4em 0 0.3em; font-weight: 700; color: #0f172a; }
.doc-body.html-body p { margin: 0 0 0.65em; }
.doc-body.html-body ul,
.doc-body.html-body ol { margin: 0.2em 0 0.65em 1.2em; }
.doc-body.html-body li { margin: 0.15em 0; }
.doc-body.html-body strong,
.doc-body.html-body b { font-weight: 700; }
.doc-body.html-body em,
.doc-body.html-body i { font-style: italic; }
.doc-body.html-body blockquote {
  margin: 0.6em 0;
  padding: 0.35em 0.7em;
  border-left: 3px solid #d9deeb;
  color: #4a5161;
  background: #f6f7fb;
}
.doc-body.html-body pre {
  background: #f4f6fa;
  border: 1px solid #e3e6ef;
  border-radius: 6px;
  padding: 8px;
  overflow-x: auto;
}
.doc-body.html-body img { max-width: 100%; height: auto; }
.embed-trigger { color: var(--accent); font-weight: 700; cursor: pointer; }
.embed-trigger:hover { text-decoration: underline; }

.embed-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.embed-modal.is-open { display: flex; }
.embed-modal .embed-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 15, 26, 0.6);
  backdrop-filter: blur(3px);
}
.embed-modal .embed-dialog {
  position: relative;
  width: 90vw;
  max-width: 900px;
  max-height: 90vh;
  background: #0b101b;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.35);
  border: 1px solid #dbe1ee;
  display: flex;
  flex-direction: column;
}
.embed-modal .embed-dialog.ratio-16-9 .embed-frame-wrap { aspect-ratio: 16 / 9; }
.embed-modal .embed-dialog.ratio-9-16 .embed-frame-wrap { aspect-ratio: 9 / 16; }
.embed-modal .embed-dialog.ratio-4-5 .embed-frame-wrap { aspect-ratio: 4 / 5; }
.embed-modal .embed-dialog .embed-frame-wrap {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  background: #000;
}
.embed-modal .embed-dialog .embed-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.embed-modal .embed-dialog-header {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  z-index: 2;
}
.embed-modal .embed-close {
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 18px;
}
.doc-body pre.plain-body {
  background: transparent;
  border: none;
  padding: 0;
  font-family: "IBM Plex Mono", monospace;
  color: #2f3545;
  white-space: pre-wrap;
}
mark.search-hit {
  background: #ffed8a;
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
  box-shadow: 0 0 0 1px #f2d56d inset;
}
.doc-note.is-focused { border-color: var(--accent); box-shadow: 0 8px 24px rgba(47, 104, 255, 0.12); }

.empty { padding: 16px; border: 1px dashed var(--border); border-radius: 12px; color: var(--muted); background: #f9fafb; }

.centered { display: flex; justify-content: center; align-items: center; height: 60vh; }

@media (max-width: 1100px) {
  .doc-shell { grid-template-columns: 1fr; border-radius: 12px; }
}

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; padding: 20px; }
  main { padding: 0 12px 18px; }
  .input-row, .search-bar { flex-direction: column; }
  button, select { width: 100%; }
  .doc-shell { display: block; min-height: auto; }
  .doc-toolbar { position: static; flex-wrap: wrap; gap: 10px; }
  .toc-toggle { display: inline-flex; }
  .toc {
    position: fixed;
    left: 12px;
    top: calc(var(--topbar-h) + 8px);
    width: 240px;
    max-width: 82%;
    height: calc(100vh - (var(--topbar-h) + 18px));
    transform: translateX(-120%);
    transition: transform 0.25s ease;
    z-index: 30;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
    border-right: 1px solid var(--border);
  }
  body.nav-open .toc { transform: translateX(0); }
  .toc-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(1px);
    z-index: 29;
  }
  body.nav-open .toc-scrim { display: block; }
  .note-sort-buttons { display: none; }
  .note-sort-select { display: flex; }
}

@media (max-width: 720px) {
  main { padding: 0 10px 82px; }
  .doc-shell { border: none; box-shadow: none; background: transparent; }
  .doc-content { padding: 12px 0 18px; background: transparent; }
  .doc-toolbar {
    padding: 0;
    margin-bottom: 12px;
    border: none;
    background: transparent;
    box-shadow: none;
  }
  .search-bar {
    padding: 0;
    gap: 8px;
    background: transparent;
    border: none;
  }
  .search-bar input[type="search"],
  .search-bar select {
    width: 100%;
    border: 1px solid #e1e5ee;
    background: #fff;
    box-shadow: 0 10px 26px rgba(31, 42, 61, 0.08);
  }
  .doc-main { max-width: none; }
  .doc-note {
    border: none;
    background: #fff;
    border-radius: 14px;
    padding: 12px 12px 14px;
    box-shadow: 0 14px 30px rgba(17, 24, 39, 0.08);
  }
  .doc-body {
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
  }
  .doc-body.html-body p { margin-bottom: 0.8em; }
  .toc-toggle {
    position: fixed;
    right: 14px;
    bottom: 20px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 16px 40px rgba(58, 118, 210, 0.22);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 0;
    z-index: 34;
  }
  .toc-toggle:hover { background: var(--accent-2); }
  .toc-toggle-label { display: none; }
  .toc-toggle-icon { font-size: 20px; line-height: 1; }
}
