:root {
  --bg: #1a1b26;
  --bg-alt: #16161e;
  --bg-highlight: #292e42;
  --border: #30313f;
  --text: #a9b1d6;
  --text-bright: #c0caf5;
  --muted: #565f89;
  --muted-dim: #414868;
  --blue: #7aa2f7;
  --purple: #bb9af7;
  --cyan: #7dcfff;
  --green: #9ece6a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', Consolas, Menlo, monospace;
  font-size: 14px;
}

.editor {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Tab bar */
.tabbar {
  display: flex;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.tab {
  padding: 10px 18px;
  color: var(--muted);
  border-right: 1px solid var(--border);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  background: var(--bg-alt);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab:hover { color: var(--text-bright); }

.tab.active {
  color: var(--blue);
  background: var(--bg);
  border-bottom: 2px solid var(--blue);
}

.tab .close {
  color: var(--muted);
  font-size: 11px;
  padding: 0 2px;
}

.tab .close:hover { color: var(--text-bright); }

/* Body: sidebar + pane */
.body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  overflow-y: auto;
  color: var(--muted);
  font-size: 13px;
}

.sidebar .row {
  padding: 4px 16px;
  cursor: pointer;
  white-space: nowrap;
}

.sidebar .row:hover { color: var(--text-bright); }

.sidebar .row.active {
  background: var(--bg-highlight);
  color: var(--text-bright);
}

.sidebar .row.dir { color: var(--blue); }
.sidebar .row.child { padding-left: 28px; color: var(--cyan); }
.sidebar .row.child.active { color: var(--text-bright); }

.pane {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 22px 28px;
  outline: none;
}

/* Rendered markdown content, styled as "lines" with a gutter */
.pane-content {
  max-width: 640px;
  line-height: 1.75;
  counter-reset: line;
}

.pane-content > * {
  counter-increment: line;
  position: relative;
  padding-left: 2.6em;
  margin: 0 0 4px 0;
}

.pane-content > *::before {
  content: counter(line);
  position: absolute;
  left: 0;
  width: 2em;
  text-align: right;
  color: var(--muted-dim);
  font-size: 12px;
}

/* Raw markdown body: one .md-line per source line, numbered on its own
   counter so the gutter matches the file exactly no matter what synthetic
   header/footer markup (project title, tags, links) wraps around it. */
.pane-content > .md-lines {
  counter-increment: none;
  padding-left: 0;
  margin: 0;
}

.pane-content > .md-lines::before {
  content: none;
}

.pane-content > .links {
  counter-increment: none;
  padding-left: 0;
}

.pane-content > .links::before {
  content: none;
}

.md-lines {
  counter-reset: line;
}

.md-lines .md-line {
  counter-increment: line;
  position: relative;
  padding-left: 2.6em;
  margin: 0 0 4px 0;
  white-space: pre-wrap;
}

.md-lines .md-line::before {
  content: counter(line);
  position: absolute;
  left: 0;
  width: 2em;
  text-align: right;
  color: var(--muted-dim);
  font-size: 12px;
}

.md-heading { color: var(--purple); font-weight: 500; }
.md-bold { color: var(--blue); font-weight: 500; }
.md-comment { color: var(--muted-dim); }

.md-link {
  color: var(--green);
  text-decoration: none;
}

.md-link:hover { text-decoration: underline; }

.pane-content a {
  color: var(--green);
  text-decoration: none;
}

.pane-content a:hover { text-decoration: underline; }

.pane-content .links a {
  margin-right: 12px;
}

/* Status line */
.statusline {
  background: var(--blue);
  color: var(--bg);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 16px;
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
}

/* Command palette */
.palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  z-index: 10;
}

.palette-overlay[hidden] {
  display: none;
}

.palette {
  width: min(460px, 90vw);
  background: var(--bg);
  border: 1px solid var(--muted-dim);
  border-radius: 8px;
  overflow: hidden;
}

.palette-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.palette-input-row .prompt { color: var(--blue); }

.palette-input-row input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-bright);
  font: inherit;
}

.palette-results { padding: 6px 0; max-height: 260px; overflow-y: auto; }

.palette-result {
  display: flex;
  justify-content: space-between;
  padding: 6px 14px;
  cursor: pointer;
  color: var(--muted);
}

.palette-result .label { color: var(--text-bright); }
.palette-result.selected { background: var(--bg-highlight); }
.palette-result.selected .label { color: var(--blue); }

.palette-hint {
  border-top: 1px solid var(--border);
  padding: 5px 14px;
  color: var(--muted-dim);
  font-size: 11px;
}

/* Mobile */
@media (max-width: 640px) {
  .sidebar { display: none; }
  .pane { padding: 16px 18px; }
  .pane-content { padding-left: 0; }
  .pane-content > * { padding-left: 0; }
  .pane-content > *::before { display: none; }
  .md-lines .md-line { padding-left: 0; }
  .md-lines .md-line::before { display: none; }
}

/* Reduced motion / focus visibility */
a:focus-visible, .tab:focus-visible, .row:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
