:root {
  --bg: #ffffff;
  --bg-alt: #f4f4f5;
  --fg: #1a1a1a;
  --fg-muted: #6b7280;
  --border: #e2e2e6;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --danger: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --bg-alt: #242426;
    --fg: #e8e8ea;
    --fg-muted: #9ca3af;
    --border: #3a3a3e;
    --accent: #3b82f6;
    --accent-fg: #ffffff;
    --danger: #ef4444;
  }
}

* { box-sizing: border-box; }

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}

.brand {
  font-size: 1.15rem;
  margin: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

/* Buttons */
.btn {
  font: inherit;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}

.btn:hover { background: var(--bg-alt); }

.btn-icon {
  padding: 0.3rem 0.55rem;
  font-size: 1.05rem;
  line-height: 1.2;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover { filter: brightness(1.1); background: var(--accent); }

/* Burger menu */
.menu-wrap { position: relative; }

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 170px;
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  z-index: 20;
}

.menu[hidden] { display: none; }

.menu-item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

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

/* Layout */
.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* Note list drawer: overlays the editor, only visible during selection */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(300px, 85vw);
  z-index: 40;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  visibility: hidden;
  transition: transform 0.2s ease, visibility 0s linear 0.2s;
}

body.drawer-open .sidebar {
  transform: translateX(0);
  visibility: visible;
  transition: transform 0.2s ease;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);
}

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.35);
}

.drawer-scrim[hidden] { display: none; }

.sidebar-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}

.note-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.note-list li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

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

.note-list li.active {
  background: var(--bg);
  box-shadow: inset 3px 0 0 var(--accent);
}

.note-item-text {
  flex: 1;
  min-width: 0;
}

.note-item-title {
  display: block;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item-date {
  font-size: 0.75rem;
  color: var(--fg-muted);
}

.note-item-delete {
  border: none;
  background: none;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem;
  border-radius: 4px;
  visibility: hidden;
}

.note-list li:hover .note-item-delete { visibility: visible; }
.note-item-delete:hover { color: var(--danger); }

.empty-hint {
  padding: 1.5rem 1rem;
  color: var(--fg-muted);
  text-align: center;
  font-size: 0.9rem;
}

/* Editor */
.editor {
  flex: 1;
  display: flex;
  min-width: 0;
}

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

.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

/* Readable column: cap line length, center the text block */
.note-content {
  flex: 1;
  width: 100%;
  max-width: calc(72ch + 2rem);
  margin: 0 auto;
  resize: none;
  border: none;
  outline: none;
  padding: 1.25rem 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--fg);
}

.note-meta {
  font-size: 0.8rem;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

@media (max-width: 640px) {
  .note-meta { display: none; }
}

/* Sync status badge */
.sync-badge {
  align-self: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  white-space: nowrap;
  color: var(--fg-muted);
  border: 1px solid var(--border);
  background: var(--bg-alt);
}

/* Login overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

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

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: min(320px, 90vw);
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-alt);
}

.login-form .brand { text-align: center; }

.login-message {
  margin: 0;
  font-size: 0.9rem;
  color: var(--fg-muted, var(--fg));
  text-align: center;
}
