:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --surface-2: #fafaf9;
  --text: #1c1917;
  --muted: #78716c;
  --border: #e7e5e4;
  --accent: #b45309;
  --accent-soft: #fef3c7;
  --primary: #1c1917;
  --primary-text: #ffffff;
  --error: #b91c1c;
  --star: #d97706;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1917;
    --surface: #24201e;
    --surface-2: #292524;
    --text: #f5f5f4;
    --muted: #a8a29e;
    --border: #3a3532;
    --accent: #fbbf24;
    --accent-soft: #3a2f1c;
    --primary: #f5f5f4;
    --primary-text: #1c1917;
    --error: #f87171;
    --star: #fbbf24;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

[hidden] { display: none !important; }

.muted { color: var(--muted); }
.error { color: var(--error) !important; }
.spacer { flex: 1; }

button {
  font: inherit;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.primary:hover { opacity: 0.9; background: var(--primary); }
button.danger { color: var(--error); }
button.icon { font-size: 18px; line-height: 1; padding: 6px 10px; }
button.icon.on { color: var(--star); }
/* Read-only: the star still shows favourites, it just can't be clicked. */
.read-only #fav:disabled { opacity: 1; }

input, textarea {
  font: inherit;
  color: var(--text);
  background: transparent;
}

/* ---------- loading / sign-in ---------- */

.center {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}

.card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 24px;
}
.card h1 { margin: 0 0 8px; font-size: 1.75rem; }
#google-button { margin-top: 24px; min-height: 44px; }

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

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 1.1rem; }
.avatar { width: 28px; height: 28px; border-radius: 50%; }
.user-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar-top {
  display: flex;
  gap: 8px;
  padding: 12px;
}
.sidebar-top input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.list-status { padding: 0 14px 6px; font-size: 12px; }

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

.note-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 2px;
  background: transparent;
  white-space: normal;
}
.note-item:hover:not(:disabled) { background: var(--surface-2); }
.note-item.active { background: var(--accent-soft); }

.note-item-head { display: flex; gap: 6px; align-items: baseline; }
.note-item-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.star { color: var(--star); }
.note-item-meta,
.note-item-preview {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.editor {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  padding: 12px 24px 8px;
}

.editor-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
}
.save-status { font-size: 13px; }

.title-input,
.tags-input,
.text-input {
  border: 0;
  outline: none;
  width: 100%;
}
.title-input { font-size: 1.5rem; font-weight: 700; padding: 4px 0; }
.tags-input {
  font-size: 13px;
  color: var(--accent);
  padding: 2px 0 8px;
  border-bottom: 1px solid var(--border);
}
.text-input {
  flex: 1;
  min-height: 0;
  resize: none;
  padding: 12px 0;
  line-height: 1.6;
}

.editor-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.mobile-only { display: none; }

/* ---------- phone: one panel at a time ---------- */

@media (max-width: 720px) {
  .topbar { padding: 8px 16px; }
  .user-name { display: none; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .layout:not(.show-editor) .editor { display: none; }
  .layout.show-editor .sidebar { display: none; }
  .editor { padding: 8px 16px; }
  .mobile-only { display: inline-block; }
  .editor-foot { flex-direction: column; gap: 0; }
}
