:root {
  color-scheme: light;
  --paper: #fbfaf7;
  --panel: #f5f2eb;
  --rail: #f0ece3;
  --ink: #171614;
  --muted: #7c776e;
  --faint: #9c968c;
  --line: rgba(23, 22, 20, 0.12);
  --hover: rgba(23, 22, 20, 0.045);
  --accent: #c4552d;
  --accent-soft: rgba(196, 85, 45, 0.08);
  --accent-line: rgba(196, 85, 45, 0.36);
  --active: #fbfaf7;
  --rail-w: 56px;
  --sidebar-w: 282px;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", "Roboto Mono", Menlo,
    Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0c0c0c;
  --panel: #111110;
  --rail: #090909;
  --ink: #e9e6df;
  --muted: #918d85;
  --faint: #6e6a63;
  --line: rgba(233, 230, 223, 0.13);
  --hover: rgba(233, 230, 223, 0.055);
  --accent: #e08a5f;
  --accent-soft: rgba(224, 138, 95, 0.12);
  --accent-line: rgba(224, 138, 95, 0.4);
  --active: #191817;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.file-input {
  display: none;
}

html,
body,
#app {
  height: 100%;
}

html {
  background: var(--paper);
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: var(--accent-soft);
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.boot {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 1rem;
  letter-spacing: -0.04em;
}

.boot span {
  color: var(--accent);
}

.icon {
  display: block;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

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

.app {
  display: grid;
  grid-template-columns: var(--rail-w) auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
}

/* ---------- left rail ---------- */

.rail {
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 0;
  padding: 12px 0 14px;
  background: var(--rail);
  border-right: 1px solid var(--line);
}

.rail__brand {
  margin: 2px 0 12px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: -0.06em;
  user-select: none;
}

.rail__brand span {
  color: var(--accent);
}

.rail__btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  transition:
    color 0.15s,
    background 0.15s,
    border-color 0.15s;
}

.rail__btn .icon {
  width: 17px;
  height: 17px;
}

.rail__btn:hover {
  color: var(--ink);
  background: var(--paper);
  border-color: var(--line);
}

.rail__btn--new {
  margin-bottom: 2px;
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.rail__btn--new .icon {
  width: 19px;
  height: 19px;
}

.rail__btn--new:hover {
  color: var(--paper);
  background: var(--accent);
  border-color: var(--accent);
}

.rail__spacer {
  flex: 1;
}

/* ---------- notes sidebar ---------- */

.sidebar {
  width: var(--sidebar-w);
  min-width: 0;
  overflow: hidden;
  background: var(--panel);
  border-right: 1px solid var(--line);
  transition:
    width 0.24s ease,
    opacity 0.18s ease,
    border-color 0.2s ease;
}

.sidebar__inner {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  height: 100%;
}

.app[data-sidebar="closed"] .sidebar {
  width: 0;
  opacity: 0;
  border-right-width: 0;
  border-right-color: transparent;
}

.app[data-sidebar="closed"] .sidebar__inner {
  pointer-events: none;
}

.sidebar__head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

.sidebar__title {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.sidebar__count {
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.5rem;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.sidebar__list {
  flex: 1;
  min-height: 0;
  padding: 8px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-color: var(--faint) transparent;
  scrollbar-width: thin;
}

.sidebar__list::-webkit-scrollbar {
  width: 8px;
}

.sidebar__list::-webkit-scrollbar-thumb {
  background: var(--line);
  border: 3px solid var(--panel);
  border-radius: 8px;
}

.sidebar__foot {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  height: 32px;
  padding: 0 18px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.5rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  border-top: 1px solid var(--line);
}

.sidebar__local::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-right: 6px;
  vertical-align: 1px;
  background: var(--faint);
  border-radius: 50%;
}

/* ---------- note rows ---------- */

.note-item {
  position: relative;
  display: flex;
  align-items: stretch;
  margin: 0 0 2px;
  border-radius: 8px;
  transition: background 0.12s ease;
}

.note-item:hover {
  background: var(--hover);
}

.note-item.is-open:not(.is-active) {
  background: var(--hover);
}

.note-item.is-active {
  background: var(--active);
}

.note-item.is-active::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 0;
  width: 2px;
  background: var(--accent);
  border-radius: 2px;
}

.note-item__open {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 9px 8px 9px 13px;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.note-item__open:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

.note-item__top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.note-item__title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.008em;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.12s ease;
}

.note-item:hover .note-item__title,
.note-item.is-open .note-item__title,
.note-item.is-active .note-item__title {
  color: var(--ink);
}

.note-item__meta {
  overflow: hidden;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.5rem;
  line-height: 1.4;
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-item__chips {
  display: flex;
  flex: 0 0 auto;
  gap: 2px;
}

.chip {
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.4rem;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
}

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

.note-item__acts {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 1px;
  padding-right: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.note-item:hover .note-item__acts,
.note-item:focus-within .note-item__acts {
  pointer-events: auto;
  opacity: 1;
}

.note-item__act {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--faint);
  background: none;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}

.note-item__act .icon {
  width: 13px;
  height: 13px;
}

.note-item__act:hover {
  color: var(--ink);
  background: var(--rail);
}

.note-item__act[data-act="note-delete"]:hover {
  color: var(--accent);
}

.note-item.is-renaming::before {
  display: none;
}

.note-item__rename {
  width: 100%;
  padding: 9px 10px 9px 13px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.008em;
  background: var(--active);
  border: 1px solid var(--accent);
  border-radius: 8px;
  outline: none;
}

.note-list__empty {
  padding: 24px 16px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.05em;
  text-align: center;
}

/* ---------- workspace and toolbar ---------- */

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

.topbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 14px;
  height: 48px;
  padding: 0 24px 0 26px;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: -0.03em;
  user-select: none;
}

.wordmark span {
  color: var(--accent);
}

.save-state {
  overflow: hidden;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.52rem;
  letter-spacing: 0.09em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
  transition: color 0.2s ease;
}

.save-state.is-saving {
  color: var(--muted);
}

.save-state.is-saved {
  color: var(--ink);
}

.save-state.is-error {
  color: var(--accent);
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.action {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.54rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  transition:
    color 0.15s,
    background 0.15s;
}

.action .icon {
  width: 14px;
  height: 14px;
}

.action:hover {
  color: var(--ink);
  background: var(--hover);
}

.action.is-on {
  color: var(--accent);
}

.action.is-on .icon {
  stroke-width: 1.9;
}

/* ---------- panes ---------- */

.panes {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
  background: var(--paper);
}

.panes[data-split="on"] {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.panes[data-split="off"] .pane--second {
  display: none;
}

.pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.pane--second {
  border-left: 1px solid var(--line);
}

.pane::before {
  content: "";
  position: absolute;
  z-index: 3;
  top: 0;
  right: 0;
  left: 0;
  height: 2px;
  background: transparent;
}

.pane.is-active::before {
  background: var(--accent);
}

.pane__paper {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  min-height: 0;
  overflow: hidden;
}

.editor {
  display: block;
  width: min(720px, 100%);
  height: 100%;
  margin: 0;
  padding: 34px 30px 26px;
  color: var(--ink);
  caret-color: var(--accent);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.85;
  letter-spacing: 0.002em;
  tab-size: 2;
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
  scrollbar-color: var(--faint) transparent;
  scrollbar-width: thin;
}

.editor::-webkit-scrollbar {
  width: 10px;
}

.editor::-webkit-scrollbar-thumb {
  background: var(--line);
  border: 4px solid var(--paper);
  border-radius: 8px;
}

.editor::placeholder {
  color: var(--faint);
  opacity: 0.85;
}

.editor:focus-visible {
  outline: none;
}

/* ---------- markdown preview ---------- */

.preview {
  display: none;
  min-width: 0;
  min-height: 0;
  padding: 32px 30px 26px;
  overflow: auto;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  overflow-wrap: anywhere;
  scrollbar-color: var(--faint) transparent;
  scrollbar-width: thin;
}

.preview::-webkit-scrollbar {
  width: 10px;
}

.preview::-webkit-scrollbar-thumb {
  background: var(--line);
  border: 4px solid var(--paper);
  border-radius: 8px;
}

.panes[data-preview="on"] .pane__paper {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  justify-items: stretch;
}

.panes[data-preview="on"] .editor {
  width: 100%;
  border-right: 1px solid var(--line);
}

.panes[data-preview="on"] .preview {
  display: block;
}

.preview > :first-child {
  margin-top: 0;
}

.preview > :last-child {
  margin-bottom: 0;
}

.preview h1,
.preview h2,
.preview h3,
.preview h4,
.preview h5,
.preview h6 {
  margin: 1.45em 0 0.5em;
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: -0.018em;
}

.preview h1 {
  padding-bottom: 0.28em;
  font-size: 1.65em;
  border-bottom: 1px solid var(--line);
}

.preview h2 {
  font-size: 1.35em;
}

.preview h3 {
  font-size: 1.16em;
}

.preview h4,
.preview h5,
.preview h6 {
  font-size: 1em;
}

.preview p {
  margin: 0.8em 0;
}

.preview ul,
.preview ol {
  margin: 0.7em 0;
  padding-left: 1.55em;
}

.preview li {
  margin: 0.2em 0;
}

.preview li > ul,
.preview li > ol {
  margin: 0.18em 0;
}

.preview li::marker {
  color: var(--accent);
}

.preview ul:has(> li > input[type="checkbox"]) {
  padding-left: 0.25em;
  list-style: none;
}

.preview li:has(> input[type="checkbox"]) {
  list-style: none;
}

.preview input[type="checkbox"] {
  margin: 0 0.45em 0 0;
  vertical-align: -0.08em;
  accent-color: var(--accent);
}

.preview blockquote {
  margin: 1em 0;
  padding: 0.05em 1em;
  color: var(--muted);
  border-left: 2px solid var(--accent-line);
}

.preview blockquote > :first-child {
  margin-top: 0;
}

.preview blockquote > :last-child {
  margin-bottom: 0;
}

.preview hr {
  margin: 1.6em 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.preview a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.preview strong {
  font-weight: 600;
}

.preview code {
  padding: 0.1em 0.34em;
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--panel);
  border-radius: 4px;
}

.preview pre {
  margin: 1em 0;
  padding: 12px 14px;
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.preview pre code {
  padding: 0;
  background: none;
  border-radius: 0;
  font-size: 0.86em;
}

.preview table {
  width: 100%;
  margin: 1em 0;
  border-collapse: collapse;
  font-size: 0.93em;
}

.preview th,
.preview td {
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
  border: 1px solid var(--line);
}

.preview th {
  font-weight: 600;
  background: var(--panel);
}

.preview img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

.preview del {
  color: var(--muted);
}

.preview .footnote-definition {
  margin-top: 1.5em;
  padding-top: 0.8em;
  color: var(--muted);
  font-size: 0.9em;
  border-top: 1px solid var(--line);
}

.pane__foot {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 32px;
  padding: 0 26px;
  overflow: hidden;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.51rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  border-top: 1px solid var(--line);
}

.panes[data-split="on"] .pane__foot {
  padding: 0 20px;
}

.panes[data-split="on"] .pane__hint {
  display: none;
}

/* ---------- scrim (mobile sidebar) ---------- */

.scrim {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 0;
  bottom: 0;
  left: var(--rail-w);
  display: none;
  pointer-events: none;
  background: rgba(10, 10, 10, 0.22);
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  .panes[data-split="on"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .panes[data-preview="on"] .pane__paper {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .panes[data-preview="on"] .editor {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .panes[data-split="on"] .pane--second {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .panes[data-split="on"] .editor {
    padding-top: 22px;
    padding-bottom: 16px;
  }

  .panes[data-split="on"] .pane__foot {
    height: 27px;
  }
}

@media (max-width: 780px) {
  .app {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
  }

  .scrim {
    display: block;
  }

  .app[data-sidebar="open"] .scrim {
    pointer-events: auto;
    opacity: 1;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: var(--rail-w);
    z-index: 30;
    width: min(286px, calc(100vw - var(--rail-w) - 18px));
    opacity: 1;
    border-right: 1px solid var(--line);
    transform: translateX(-100%);
    transition: transform 0.24s ease;
  }

  .sidebar__inner {
    width: 100%;
  }

  .app[data-sidebar="closed"] .sidebar {
    width: min(286px, calc(100vw - var(--rail-w) - 18px));
    opacity: 1;
    border-right-color: var(--line);
    transform: translateX(-100%);
  }

  .app[data-sidebar="open"] .sidebar {
    transform: translateX(0);
  }

  .topbar {
    gap: 10px;
    padding: 0 14px 0 16px;
  }

  .save-state {
    display: none;
  }

  .action {
    padding: 6px;
  }

  .action .icon {
    width: 16px;
    height: 16px;
  }

  .action__label {
    display: none;
  }

  .pane__foot {
    padding: 0 16px;
  }

  .pane__hint {
    display: none;
  }

  .editor {
    padding: 26px 18px 20px;
    font-size: 14.5px;
  }

  .preview {
    padding: 24px 18px 18px;
    font-size: 14.5px;
  }

  .note-item__rename {
    font-size: 16px;
  }

  .panes[data-split="on"] .pane__foot {
    padding: 0 16px;
  }
}

@media (max-width: 420px) {
  .topbar {
    padding-right: 10px;
  }

  .topbar__actions {
    gap: 1px;
  }

  .rail {
    padding-top: 10px;
  }
}

@media (hover: none) {
  .note-item__acts {
    pointer-events: auto;
    opacity: 1;
  }
}

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