:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-hover: #f1f3f5;
  --text: #1f2328;
  --muted: #656d76;
  --border: #d0d7de;
  --accent: #fbbc04;
  --accent-text: #1f2328;
  --danger: #cf222e;
  --ok: #1a7f37;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #202329;
    --surface-hover: #282c34;
    --text: #e6edf3;
    --muted: #8b949e;
    --border: #30363d;
    --accent: #fbbc04;
    --accent-text: #16181c;
    --danger: #f85149;
    --ok: #3fb950;
    --shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--accent);
  display: inline-block;
}

.search-wrap {
  flex: 1;
  max-width: 460px;
}

.search-wrap input {
  width: 100%;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.92rem;
}

.search-wrap input:focus,
.composer input:focus,
.composer textarea:focus,
.edit-form input:focus,
.edit-form textarea:focus,
.auth-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.composer-wrap {
  max-width: 580px;
  margin: 0 auto 1.75rem;
}

.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.composer-title,
.composer-content,
.edit-title,
.edit-content {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  resize: vertical;
}

.composer-title,
.edit-title {
  font-weight: 600;
  font-size: 0.98rem;
  padding: 0.25rem 0.35rem;
}

.composer-content,
.edit-content {
  font-size: 0.93rem;
  padding: 0.35rem;
  min-height: 64px;
}

.composer-footer,
.edit-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}

.md-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.section-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1.25rem 0 0.6rem;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.85rem;
  align-items: start;
}

.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  word-break: break-word;
}

.note-card.is-pinned {
  border-color: var(--accent);
}

.note-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
}

.note-body {
  font-size: 0.92rem;
  max-height: 360px;
  overflow-y: auto;
}

.note-plain {
  white-space: pre-wrap;
}

.note-markdown p:first-child { margin-top: 0; }
.note-markdown p:last-child { margin-bottom: 0; }
.note-markdown pre,
.note-markdown code {
  background: var(--bg);
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.84em;
}
.note-markdown code { padding: 0.1em 0.3em; }
.note-markdown pre { padding: 0.5rem; overflow-x: auto; }
.note-markdown ul, .note-markdown ol { padding-left: 1.25rem; margin: 0.35rem 0; }

.note-footer {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
}

.note-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.3rem;
  font-size: 0.68rem;
  font-weight: 600;
}

.note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.action-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 0.22rem 0.5rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.action-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.action-btn.danger:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.action-btn.copied {
  color: var(--ok);
  border-color: var(--ok);
}

.btn {
  border: none;
  border-radius: 7px;
  padding: 0.45rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.8rem;
}

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

.btn-primary:hover {
  filter: brightness(0.95);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.edit-form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.edit-actions {
  display: flex;
  gap: 0.35rem;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  margin-top: 2.5rem;
  font-size: 0.95rem;
}

/* Login */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.auth-sub {
  margin: 0.5rem 0 1rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.auth-error {
  margin: 0 0 0.75rem;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  background: rgba(207, 34, 46, 0.12);
  color: var(--danger);
  font-size: 0.85rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.auth-form input {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
