:root {
  color-scheme: light;
  --bg: #f6f3ed;
  --panel: #fffdf9;
  --panel-strong: #ffffff;
  --text: #1b2a2a;
  --muted: #66706d;
  --line: #d8d1c5;
  --accent: #1f6f68;
  --accent-dark: #154f4a;
  --danger: #b83232;
  --danger-bg: #fff1f1;
  --shadow: 0 18px 50px rgba(38, 55, 52, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: #eee8dc;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 18px 16px;
}

.sidebar-header h1,
.empty-state h2 {
  margin: 0;
  letter-spacing: 0;
}

.sidebar-header h1 {
  font-size: 1.35rem;
}

.sidebar-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 1.45rem;
  line-height: 1;
}

.primary,
.editor-actions button.active,
.empty-state button {
  background: var(--accent);
  color: #fff;
}

.sidebar-tools {
  display: grid;
  gap: 12px;
  padding: 0 18px 16px;
}

.search-label,
.editor-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

.danger-button,
.segmented-control button,
.empty-state button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0 12px;
}

.note-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding: 0 12px 18px;
}

.note-item {
  display: grid;
  gap: 5px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 12px;
  text-align: left;
}

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

.note-item.active {
  box-shadow: 0 8px 22px rgba(31, 111, 104, 0.12);
}

.note-title {
  overflow: hidden;
  color: var(--text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-excerpt,
.note-date {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  min-width: 0;
  background: var(--panel);
}

.empty-state {
  display: grid;
  place-content: center;
  min-height: 100vh;
  padding: 24px;
  text-align: center;
}

.empty-state h2 {
  font-size: clamp(1.6rem, 3vw, 2.4rem);
}

.empty-state p {
  margin: 12px 0 22px;
  color: var(--muted);
}

.empty-state button {
  justify-self: center;
  border-color: var(--accent);
  padding: 0 18px;
}

.editor-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.editor-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 249, 0.92);
  padding: 14px 18px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.title-input {
  border-color: transparent;
  background: transparent;
  font-size: clamp(1.35rem, 2.2vw, 2rem);
  font-weight: 800;
  letter-spacing: 0;
  padding-inline: 0;
}

.title-input:focus {
  outline: none;
  border-bottom-color: var(--accent);
  border-radius: 0;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.save-status {
  min-width: 76px;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: right;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(68px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented-control button {
  border: 0;
  border-radius: 0;
}

.danger-button {
  border-color: #ecc4c4;
  background: var(--danger-bg);
  color: var(--danger);
}

.editor-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 0;
}

#contentInput {
  min-height: calc(100vh - 75px);
  resize: none;
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--line);
  padding: 24px;
  background: #fffbf4;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 1rem;
  line-height: 1.65;
}

#contentInput:focus {
  outline: 2px solid rgba(31, 111, 104, 0.18);
  outline-offset: -2px;
}

.preview-pane {
  min-width: 0;
  overflow: auto;
  padding: 24px;
}

.preview-heading {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.markdown-preview {
  max-width: 860px;
  line-height: 1.7;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3 {
  line-height: 1.2;
}

.markdown-preview pre,
.markdown-preview code {
  border-radius: 6px;
  background: #f0ede7;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.markdown-preview code {
  padding: 0.1em 0.35em;
}

.markdown-preview pre {
  overflow-x: auto;
  padding: 14px;
}

.markdown-preview pre code {
  padding: 0;
}

.markdown-preview blockquote {
  margin-inline: 0;
  border-left: 4px solid var(--accent);
  padding-left: 14px;
  color: var(--muted);
}

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

.mode-edit {
  grid-template-columns: minmax(0, 1fr);
}

.mode-edit .preview-pane,
.mode-preview #contentInput {
  display: none;
}

.mode-preview {
  grid-template-columns: minmax(0, 1fr);
}

.mode-preview .preview-pane {
  padding: 30px min(8vw, 80px);
}

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

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

  .note-list {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 14px;
  }

  .note-item {
    min-width: 220px;
  }

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

  .editor-actions {
    flex-wrap: wrap;
  }

  .save-status {
    text-align: left;
  }

  .editor-body,
  .mode-edit,
  .mode-preview {
    grid-template-columns: 1fr;
  }

  #contentInput {
    min-height: 58vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 520px) {
  .sidebar-header,
  .sidebar-tools,
  .editor-header {
    padding-inline: 14px;
  }

  .editor-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented-control {
    width: 100%;
  }

  .danger-button {
    width: 100%;
  }
}
