:root {
  --bg: #ffffff;
  --bg-soft: #f6f6f4;
  --bg-active: #fdf1c7;
  --fg: #1d1d1b;
  --fg-muted: #6c6c66;
  --border: #e3e2dc;
  --accent: #c99a12;
  --accent-fg: #ffffff;
  --danger: #c2372b;
  --warn-bg: #fff4d6;
  --warn-fg: #7a5600;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1a;
    --bg-soft: #232321;
    --bg-active: #3a3220;
    --fg: #ecebe6;
    --fg-muted: #9a998f;
    --border: #34332f;
    --accent: #e0b23a;
    --accent-fg: #1b1b1a;
    --danger: #ff7a6b;
    --warn-bg: #3b3018;
    --warn-fg: #f3cf75;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button {
  font: inherit;
  color: inherit;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--fg-muted);
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

input,
textarea {
  font: inherit;
  color: inherit;
  background: transparent;
}

/* ---------- login ---------- */

.login-page {
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}

.login-card input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.login-card button {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 600;
}

.show-password {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--fg-muted);
}

.hint {
  margin: 0;
  font-size: 14px;
  color: var(--warn-fg);
}

.error {
  color: var(--danger);
  margin: 0;
}

/* ---------- app layout ---------- */

.app {
  display: grid;
  grid-template-columns: 300px 1fr;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 8px;
}

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

#new-note {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 600;
}

#search {
  margin: 4px 14px 10px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.note-list {
  list-style: none;
  margin: 0;
  padding: 0 8px;
  overflow-y: auto;
  flex: 1;
}

.note-list-empty {
  padding: 12px;
  color: var(--fg-muted);
}

.note-item {
  display: grid;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 9px 10px;
  margin-bottom: 2px;
  border-radius: 8px;
}

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

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

.note-item strong,
.note-item .snippet {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.note-item .snippet,
.note-item time {
  color: var(--fg-muted);
  font-size: 13px;
}

.sidebar-footer {
  padding: 8px 14px 12px;
  border-top: 1px solid var(--border);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.zec-price {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--fg-muted);
}

.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--fg-muted);
  text-decoration: underline;
}

/* ---------- editor ---------- */

.editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
}

.empty-state {
  margin: auto;
  color: var(--fg-muted);
}

.editor-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 12px 28px 20px;
}

.editor-pane[hidden],
.empty-state[hidden] {
  display: none;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status {
  flex: 1;
  color: var(--fg-muted);
  font-size: 13px;
}

.status.warn {
  color: var(--warn-fg);
  font-weight: 600;
}

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

.back {
  display: none;
}

.conflict {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-fg);
}

.conflict[hidden] {
  display: none;
}

.conflict span {
  flex: 1;
  min-width: 200px;
}

.title-input {
  border: none;
  outline: none;
  font-size: 26px;
  font-weight: 700;
  padding: 14px 0 6px;
}

.body-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 16px;
  line-height: 1.6;
  padding: 6px 0;
}

/* ---------- version badge ---------- */

.app-version {
  position: fixed;
  right: 10px;
  bottom: 6px;
  font-size: 11px;
  color: var(--fg-muted);
  opacity: 0.8;
  pointer-events: none;
  user-select: none;
}

/* Keep the end of a long note clear of the badge. */
.body-input {
  padding-bottom: 24px;
}

/* ---------- phones ---------- */

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

  .app.show-editor .sidebar,
  .app:not(.show-editor) .editor {
    display: none;
  }

  .sidebar {
    border-right: none;
  }

  .editor-pane {
    padding: 10px 16px 16px;
  }

  .back {
    display: inline-block;
  }
}
