:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --text: #22201d;
  --muted: #77716a;
  --line: #e5e1db;
  --accent: #1f6f5c;
  --danger: #a33a2c;
  --code-bg: #f2efea;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --surface: #1f1e23;
    --text: #e8e5e0;
    --muted: #9a938b;
    --line: #33313a;
    --accent: #6dc4ac;
    --danger: #e08272;
    --code-bg: #26252b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo",
        "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 0.75rem;
}

.brand {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text);
  text-decoration: none;
}

.topbar nav { display: flex; align-items: center; gap: 0.75rem; }
.topbar form { margin: 0; }

main {
  max-width: 46rem;
  margin: 0 auto;
  padding: 0.5rem 1.25rem 5rem;
}

/* --- 폼 요소 --- */

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

input[type="text"], input[name="title"], input[type="password"], textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

textarea {
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.6;
}

button { cursor: pointer; }

.primary {
  padding: 0.5rem 1.1rem;
  background: var(--accent);
  color: var(--bg);
  border: 0;
  border-radius: var(--radius);
  font-weight: 600;
}

.primary:hover { filter: brightness(1.08); }

.link {
  padding: 0;
  background: none;
  border: 0;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
}

.link:hover { color: var(--text); text-decoration: underline; }
.link.danger:hover { color: var(--danger); }

.row { display: flex; align-items: center; gap: 1rem; }

/* --- 카드 / 에디터 --- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 2rem;
}

.editor { display: flex; flex-direction: column; gap: 0.75rem; }

.preview:empty { display: none; }

.preview {
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.login { max-width: 22rem; margin: 3rem auto; display: flex; flex-direction: column; gap: 0.75rem; }
.login label { font-size: 0.875rem; color: var(--muted); }
.error { margin: 0; color: var(--danger); font-size: 0.875rem; }

/* --- 목록 --- */

.entry {
  padding: 1.5rem 0;
  border-top: 1px solid var(--line);
}

.entry:first-child { border-top: 0; }
.entry.editing { padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }

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

.meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.meta .actions { margin-left: auto; display: flex; gap: 0.75rem; }
.edited::before { content: "· "; }

#entries:not(:empty) + #empty { display: none; }
.empty { color: var(--muted); text-align: center; padding: 3rem 0; }

/* --- 마크다운 본문 --- */

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { line-height: 1.3; margin: 1.4em 0 0.5em; }
.md h1 { font-size: 1.3rem; }
.md h2 { font-size: 1.15rem; }
.md h3 { font-size: 1rem; }
.md a { color: var(--accent); }
.md ul, .md ol { padding-left: 1.4rem; }
.md blockquote {
  margin: 1em 0;
  padding-left: 1rem;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.md code {
  padding: 0.12em 0.35em;
  background: var(--code-bg);
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
}

.md pre {
  padding: 0.9rem 1rem;
  background: var(--code-bg);
  border-radius: var(--radius);
  overflow-x: auto;
}

.md pre code { padding: 0; background: none; }

.md table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.md th, .md td { padding: 0.4rem 0.7rem; border: 1px solid var(--line); text-align: left; }
.md img { max-width: 100%; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.5em 0; }
