:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --panel: #ffffff;
  --ink: #202425;
  --muted: #66706a;
  --line: #d9ded7;
  --accent: #1f6f68;
  --accent-dark: #174f4b;
  --danger: #9a2f2f;
  --code: #17201e;
  --code-line: #263330;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: #1f6f68;
  color: white;
  font-size: 13px;
  letter-spacing: 0;
}

.topbar-actions,
.editor-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button,
.icon-button {
  border: 1px solid transparent;
  background: var(--accent);
  color: white;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 650;
}

.button:hover,
.icon-button:hover {
  background: var(--accent-dark);
}

.button.secondary,
.icon-button {
  background: #ffffff;
  border-color: var(--line);
  color: var(--ink);
}

.button.secondary:hover,
.icon-button:hover {
  background: #eef2ee;
}

.button.danger {
  background: var(--danger);
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #fbfcfa;
  padding: 20px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.sidebar h1 {
  font-size: 18px;
  margin: 0;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 18px;
}

.note-list {
  display: grid;
  gap: 8px;
}

.note-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 12px;
  cursor: pointer;
  color: var(--ink);
}

.note-item:hover,
.note-item.active {
  background: #eef2ee;
  border-color: var(--line);
}

.note-item strong {
  display: block;
  font-size: 14px;
  line-height: 1.3;
}

.note-item time {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
}

.reader {
  padding: 28px;
  min-width: 0;
}

.note-panel,
.editor-panel,
.empty-state {
  max-width: 1060px;
  margin: 0 auto;
}

.empty-state {
  padding: 72px 16px;
  color: var(--muted);
  text-align: center;
}

.empty-state h2 {
  color: var(--ink);
  margin: 0 0 8px;
}

.note-header,
.editor-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.note-header h2 {
  margin: 0 0 6px;
  font-size: 30px;
  line-height: 1.12;
}

time {
  color: var(--muted);
  font-size: 13px;
}

.title-input {
  width: min(640px, 100%);
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  font-weight: 700;
  font-size: 20px;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  min-height: 62vh;
}

.editor-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  min-width: 0;
}

.editor-pane > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

textarea,
.preview-pane .markdown-body {
  min-height: 62vh;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

textarea {
  resize: vertical;
  padding: 14px;
  line-height: 1.55;
  color: var(--ink);
}

.preview-pane .markdown-body {
  overflow: auto;
  padding: 18px;
}

.markdown-body {
  line-height: 1.65;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  line-height: 1.18;
  margin: 1.4em 0 0.55em;
}

.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body h3:first-child,
.markdown-body p:first-child {
  margin-top: 0;
}

.markdown-body a {
  color: var(--accent-dark);
}

.markdown-body img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.markdown-body code {
  background: #e8eeeb;
  border-radius: 4px;
  padding: 0.12em 0.32em;
  font-size: 0.92em;
}

.code-block {
  margin: 18px 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #33413d;
  background: var(--code);
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  padding: 0 10px;
  border-bottom: 1px solid var(--code-line);
  color: #d8e0dd;
  font-size: 12px;
}

.copy-button {
  border: 1px solid #50615c;
  background: #21312d;
  color: #ffffff;
  border-radius: 5px;
  min-height: 28px;
  padding: 0 9px;
  cursor: pointer;
  font-size: 12px;
}

.copy-button:hover {
  background: #2e433e;
}

.code-block pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  color: #edf4f1;
}

.code-block code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  width: min(420px, calc(100vw - 32px));
}

.dialog::backdrop {
  background: rgba(23, 32, 30, 0.42);
}

.dialog form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.dialog h2 {
  margin: 0;
  font-size: 22px;
}

.dialog label {
  display: grid;
  gap: 7px;
}

.dialog input {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
}

.error-text {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  min-width: 190px;
  min-height: 42px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 6px;
  background: #17201e;
  color: white;
  z-index: 30;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.22);
}

.toast.visible {
  display: flex;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .reader {
    padding: 18px;
  }

  .note-header,
  .editor-header {
    flex-direction: column;
  }

  .editor-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 0 14px;
  }

  .brand span:last-child {
    display: none;
  }
}
