:root {
  color-scheme: dark;
  --bg: #19151f;
  --bg-deep: #100e14;
  --surface: #211b2b;
  --surface-2: #272131;
  --surface-3: #31283d;
  --border: #3b3148;
  --border-soft: #30283a;
  --text: #d9d2e8;
  --text-bright: #f2edff;
  --muted: #91879f;
  --faint: #6e637c;
  --accent: #8b5cf6;
  --accent-2: #b38cff;
  --green: #64d39b;
  --blue: #66b7ff;
  --orange: #f0a45d;
  --danger: #ef6f8f;
  --shadow: #08060c;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg-deep);
  color: var(--text);
}

body {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

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

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

.app-shell {
  display: grid;
  grid-template-columns: 44px minmax(200px, 250px) minmax(0, 1fr) var(--right-pane-width);
  height: 100vh;
  min-height: 0;
  background: var(--bg);
  --right-pane-width: 280px;
  transition: grid-template-columns 140ms ease-out;
}

.app-shell.right-pane-hidden {
  --right-pane-width: 0px;
}

.ribbon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 6px;
  border-right: 1px solid var(--border-soft);
  background: #15111b;
}

.ribbon-button,
.graph-toolbar button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}

.ribbon-button:hover,
.ribbon-button.active,
.graph-toolbar button:hover {
  background: var(--surface-3);
  border-color: var(--border);
}

.ribbon-button svg,
.graph-toolbar svg,
.search-box svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ribbon-button svg path:first-child:not(:only-child) {
  fill: none;
}

.left-pane,
.right-pane {
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
}

.left-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-soft);
}

.right-pane {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 12px;
  border-left: 1px solid var(--border-soft);
  opacity: 1;
  visibility: visible;
  transition: opacity 100ms ease-out, padding 140ms ease-out, border-color 140ms ease-out;
}

.app-shell.right-pane-hidden .right-pane {
  width: 0;
  padding: 12px 0;
  border-left: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.workspace-tabs {
  display: flex;
  align-items: stretch;
  height: 38px;
  border-bottom: 1px solid var(--border-soft);
  background: #18131f;
}

.workspace-tab {
  border: 0;
  border-right: 1px solid var(--border-soft);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.workspace-tab.active {
  background: var(--surface);
  color: var(--text-bright);
}

.world-switcher {
  position: relative;
  flex: 0 0 auto;
  margin: 12px 12px 8px;
}

.world-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #1b1624;
  color: var(--text-bright);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 120ms ease-out, border-color 120ms ease-out;
}

.world-button:hover,
.world-button[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--surface-3);
}

.world-icon {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  color: var(--accent-2);
}

.world-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.world-caret {
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  color: var(--muted);
}

.world-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  overflow: hidden auto;
  max-height: 264px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  box-shadow: 0 12px 26px -12px var(--shadow);
}

.world-option {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}

.world-option:hover {
  background: var(--surface-3);
}

.world-option.active {
  color: var(--text-bright);
  background: var(--surface-3);
}

.world-option-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.world-option-count {
  flex: 0 0 auto;
  color: var(--faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px 12px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #16121d;
  color: var(--faint);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.file-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 8px 10px;
}

.file-item,
.context-link,
.tag-pill {
  display: flex;
  align-items: center;
  min-width: 0;
  border-radius: 4px;
  color: var(--text);
}

.file-item {
  width: 100%;
  padding: 6px 8px;
  font-size: 13px;
}

.file-item:hover,
.file-item.active,
.context-link:hover,
.tag-pill:hover,
.tag-pill.active {
  background: var(--surface-3);
  text-decoration: none;
}

.file-title,
.workspace-tab span:last-child,
.context-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-block {
  padding: 8px 12px 14px;
  border-top: 1px solid var(--border-soft);
}

.sidebar-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.tag-pill {
  padding: 3px 7px;
  border: 1px solid var(--border);
  font-size: 12px;
}

.workspace {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: var(--bg);
}

.workspace-tabs {
  flex: 0 0 auto;
}

.workspace-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 270px;
  padding: 0 14px;
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
  padding: 0 8px;
}

.top-action-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.top-action-button:hover {
  border-color: var(--border);
  background: var(--surface-3);
  color: var(--text-bright);
}

.top-action-button.active {
  color: var(--text-bright);
}

.top-action-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab-graph-icon {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.view {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.view.hidden {
  display: none;
}

.note-view {
  overflow: auto;
  background: #1b1622;
}

.markdown-body {
  width: min(880px, calc(100% - 52px));
  margin: 0 auto;
  padding: 42px 0 84px;
  color: var(--text);
  line-height: 1.4;
  font-size: 16px;
  font-family: Helvetica, "Helvetica Neue", Arial, sans-serif;
  font-weight: 300;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  color: var(--text-bright);
  line-height: 1.25;
  letter-spacing: 0;
}

.markdown-body h1 {
  margin: 0 0 26px;
  font-size: 30px;
}

.markdown-body h2 {
  margin: 34px 0 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 23px;
}

.markdown-body h3 {
  margin: 26px 0 10px;
  font-size: 19px;
}

.markdown-body h4 {
  margin: 22px 0 8px;
  font-size: 16px;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table {
  margin: 12px 0;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.5em;
}

.markdown-body li::marker {
  font-weight: 400;
}

.markdown-body code {
  padding: 0.12em 0.32em;
  border-radius: 3px;
  background: #100d15;
  color: #d7c5ff;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
}

.markdown-body pre {
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #100d15;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
}

.markdown-body blockquote {
  margin-left: 0;
  padding: 6px 0 6px 16px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--border-soft);
  margin: 28px 0;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
}

.markdown-body th,
.markdown-body td {
  padding: 8px 10px;
  border: 1px solid var(--border);
}

.internal-link,
.tag-link {
  color: #b899ff;
}

.missing-link {
  color: var(--danger);
}

.markdown-body img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 520px);
  max-height: 70vh;
  margin: 16px auto;
  border-radius: 4px;
}

.callout {
  margin: 16px 0;
  padding: 11px 14px;
  border: 1px solid #4f4260;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  background: #20192a;
}

.callout-title {
  margin-bottom: 6px;
  color: var(--text-bright);
  font-weight: 650;
}

.callout p {
  margin: 6px 0;
}

.math-block {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
}

.typst-math svg {
  vertical-align: middle;
}

.typst-math-display {
  display: block;
  text-align: center;
  margin: 0.6em 0;
}

.typst-math-display svg {
  display: block;
  margin: 0 auto;
}

.right-pane .context-card {
  min-height: 0;
}

.context-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 28vh;
  overflow: auto;
}

.context-link {
  gap: 7px;
  padding: 5px 7px;
  color: var(--text);
  font-size: 12px;
}

.context-empty {
  color: var(--faint);
  font-size: 12px;
}

.outline-list .context-link {
  color: var(--muted);
}

.outline-level-2 {
  padding-left: 14px;
}

.outline-level-3,
.outline-level-4 {
  padding-left: 24px;
}

.graph-view {
  background: #15111b;
}

#graph-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#graph-canvas.dragging {
  cursor: grabbing;
}

.graph-toolbar {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #211b2b;
}

.graph-tip {
  position: absolute;
  z-index: 3;
  max-width: 260px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #100d15;
  color: var(--text-bright);
  font-size: 12px;
  pointer-events: none;
}

.hidden {
  display: none;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: #4a3c5c;
  border: 2px solid var(--surface);
}

::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    --right-pane-width: 0px;
  }

  .ribbon,
  .left-pane,
  .right-pane {
    display: none;
  }

  .top-actions {
    display: none;
  }

  .workspace-tabs {
    height: 44px;
  }
}

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

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    height: 100dvh;
  }

  .workspace {
    min-width: 0;
  }

  .markdown-body {
    width: calc(100% - 32px);
    padding-top: 28px;
    font-size: 15px;
  }
}
