:root {
  --bg: #fafaf8; --panel: #fff; --text: #1f2328; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --accent-soft: #dbeafe; --danger: #dc2626;
  --diary: #3b82f6; --tech: #16a34a; --english: #f59e0b;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --panel: #1a1d23; --text: #e6e8eb; --muted: #9aa1ac; --line: #2c313a;
    --accent: #60a5fa; --accent-soft: #1e3a5f; --danger: #f87171;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.65 -apple-system, "Segoe UI", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif; }
html, body { overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--danger); }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

#top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
#top .brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
#top .spacer { flex: 1; }
#top input[type=search] { width: 220px; max-width: 100%; }

#layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; max-width: 1200px; margin: 0 auto; padding: 16px; }
@media (max-width: 800px) { #layout { grid-template-columns: minmax(0, 1fr); padding: 12px; } #top input[type=search] { width: 100%; order: 9; } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; }
.card h3 { margin: 0 0 8px; font-size: .95rem; color: var(--muted); font-weight: 600; }

/* calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-head b { font-size: 1rem; }
.cal-head button { padding: 2px 9px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; text-align: center; }
.cal-dow { font-size: .75rem; color: var(--muted); padding: 2px 0; }
.cal-day { aspect-ratio: 1; border-radius: 8px; border: 1px solid transparent; background: none; padding: 2px; display: flex;
  flex-direction: column; align-items: center; justify-content: center; font-size: .9rem; line-height: 1.1; }
.cal-day:hover { background: var(--accent-soft); }
.cal-day.today { border-color: var(--accent); }
.cal-day.sel { background: var(--accent); color: #fff; }
.cal-day.empty { visibility: hidden; }
.dots { display: flex; gap: 2px; height: 6px; margin-top: 3px; }
.dot { width: 6px; height: 6px; border-radius: 50%; }
.cal-day.sel .dot { box-shadow: 0 0 0 1.5px #fff; }
.t-diary { background: var(--diary); } .t-tech { background: var(--tech); } .t-english { background: var(--english); }

/* tags */
.tagcloud { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-block; padding: 1px 9px; border-radius: 999px; border: 1px solid var(--line); font-size: .82rem;
  color: var(--text); background: var(--bg); }
.tag:hover { border-color: var(--accent); text-decoration: none; }
.tag.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tag small { color: var(--muted); margin-left: 3px; } .tag.active small { color: #fff; }
.tag.child { margin-left: 0; opacity: .9; }

/* entries */
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h2 { margin: 0; font-size: 1.3rem; }
.page-head .spacer { flex: 1; }
.entry h2.title { margin: 0 0 4px; font-size: 1.35rem; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); margin-bottom: 10px; }
.badge { display: inline-block; padding: 0 8px; border-radius: 6px; font-size: .75rem; color: #fff; }
.badge.diary { background: var(--diary); } .badge.tech { background: var(--tech); } .badge.english { background: var(--english); }
.badge.vis { background: var(--muted); } .badge.vis.public { background: var(--tech); } .badge.vis.draft { background: var(--english); }
.entry-actions { display: flex; gap: 8px; margin-top: 10px; }
.excerpt { color: var(--muted); font-size: .92rem; margin: 4px 0 6px; }
.list-item h3 { margin: 0; font-size: 1.1rem; }
.empty-note { color: var(--muted); text-align: center; padding: 30px 0; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { padding: 2px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: .85rem; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* markdown */
.md { overflow-wrap: anywhere; }
.md h1, .md h2, .md h3 { margin: 1.2em 0 .5em; line-height: 1.3; }
.md img { max-width: 100%; border-radius: 6px; }
.md pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.md pre code.hljs { background: transparent; padding: 0; }
.md code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9em; }
.md :not(pre) > code { background: var(--bg); border: 1px solid var(--line); padding: 0 5px; border-radius: 5px; }
.md blockquote { margin: 1em 0; padding: 0 1em; border-left: 3px solid var(--line); color: var(--muted); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 10px; }
.md hr { border: none; border-top: 1px solid var(--line); }

/* editor */
.editor-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 10px; }
.editor-grid label { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); gap: 3px; }
.editor-title { width: 100%; font-size: 1.2rem; margin-bottom: 10px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.split textarea { width: 100%; min-height: 420px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92rem; line-height: 1.55; }
.preview { border: 1px dashed var(--line); border-radius: 8px; padding: 8px 12px; min-height: 420px; overflow: auto; }
.tagedit { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: var(--panel); margin-bottom: 10px; }
.tagedit input { border: none; outline: none !important; flex: 1; min-width: 120px; padding: 2px; background: transparent; }
.tagedit .tag button { border: none; background: none; padding: 0 0 0 4px; color: var(--muted); }
.status { font-size: .85rem; color: var(--muted); }
.error { color: var(--danger); }
.login-box { max-width: 340px; margin: 40px auto; }
.login-box input { width: 100%; margin: 8px 0; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 16px; border-radius: 8px; font-size: .9rem; z-index: 20; }

/* profile card and About page */
a.profile { display: flex; align-items: center; gap: 12px; color: var(--text); }
a.profile:hover { text-decoration: none; border-color: var(--accent); }
.avatar { border-radius: 50%; object-fit: cover; background: var(--line); flex: none; }
.profile-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.profile-text small { color: var(--muted); }
.about-head { display: flex; align-items: center; gap: 18px; margin-bottom: 14px; flex-wrap: wrap; }

/* comments */
.comment { padding: 10px 0; border-bottom: 1px solid var(--line); }
.comment:last-child { border-bottom: none; }
.comment-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-form { display: grid; gap: 8px; margin-top: 12px; }
.comment-form input:not(.hp) { max-width: 320px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.md h1, .md h2, .md h3, .md h4 { scroll-margin-top: 72px; }   /* keep headings clear of the sticky header */
