:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1a1c20;
  --muted: #6b7280;
  --accent: #3b6fed;
  --border: #e3e5e9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --card: #1f2229;
    --text: #eceef1;
    --muted: #9aa0aa;
    --accent: #6f9bff;
    --border: #2c3038;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg);
  color: var(--text);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.2rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
}
.topbar .brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topbar nav a {
  margin-left: 1rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}
.topbar nav a:hover { color: var(--accent); }
.container { max-width: 960px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.muted { color: var(--muted); }
.error { color: #d64545; }

.login-box {
  max-width: 340px;
  margin: 15vh auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
}
.login-box form { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 1rem; }
.login-box label { text-align: left; font-size: 0.85rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.3rem; }
.login-box input { padding: 0.6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 1rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin-top: 1.2rem; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.2rem; }
.card h2 { margin-top: 0; font-size: 1.05rem; }
.card h3 { font-size: 0.9rem; color: var(--muted); margin-bottom: 0.3rem; }

.btn {
  display: inline-block;
  margin-top: 0.8rem;
  padding: 0.5rem 0.9rem;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
}

.event-list, .journal-list { list-style: none; padding: 0; margin: 0.4rem 0; }
.event-list li, .journal-list li { padding: 0.3rem 0; border-bottom: 1px dashed var(--border); }
.event-list .time, .event-list .date { color: var(--accent); font-weight: 600; margin-right: 0.4rem; }
.journal-list.wide li { padding: 0.7rem 0; }
.journal-list .preview { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.85rem; }

.cal-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; }
.cal-table { width: 100%; border-collapse: collapse; margin-top: 1rem; table-layout: fixed; }
.cal-table th { padding: 0.4rem; color: var(--muted); font-size: 0.8rem; }
.cal-table th.sun { color: #d64545; }
.cal-table th.sat { color: var(--accent); }
.cal-table td { border: 1px solid var(--border); vertical-align: top; height: 100px; padding: 0.3rem; font-size: 0.8rem; overflow-y: auto; }
.cal-table td.empty { background: transparent; border: none; }
.cal-table td.today { background: rgba(59,111,237,0.08); }
.daynum { font-weight: 600; margin-bottom: 0.2rem; }
.event-chip { background: var(--accent); color: #fff; border-radius: 6px; padding: 0.15rem 0.4rem; margin-bottom: 0.2rem; font-size: 0.72rem; display: flex; justify-content: space-between; gap: 0.3rem; }
.event-chip .time { font-weight: 700; margin-right: 0.2rem; }
.inline-form { display: inline; }
.event-chip .del { background: none; border: none; color: #fff; cursor: pointer; font-size: 0.85rem; line-height: 1; padding: 0; }
.add-event summary { cursor: pointer; color: var(--muted); font-size: 0.72rem; }
.add-event form { display: flex; flex-direction: column; gap: 0.3rem; margin-top: 0.3rem; }
.add-event input, .add-event textarea { font-size: 0.75rem; padding: 0.25rem; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); color: var(--text); }
.add-event textarea { resize: vertical; min-height: 2.5rem; }
.add-event button { font-size: 0.72rem; padding: 0.2rem 0.5rem; border: none; border-radius: 4px; background: var(--accent); color: #fff; cursor: pointer; }

.journal-textarea { width: 100%; min-height: 50vh; padding: 1rem; font-size: 1rem; border-radius: 10px; border: 1px solid var(--border); background: var(--card); color: var(--text); white-space: pre-wrap; font-family: inherit; margin-top: 0.6rem; }
.tags-input { width: 100%; margin-top: 0.8rem; padding: 0.6rem; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--text); font-size: 0.9rem; }
.title-input { width: 100%; margin-top: 1rem; padding: 0.7rem; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--text); font-size: 1.1rem; font-weight: 600; }

.chat-box { margin-top: 2rem; border-top: 1px solid var(--border); padding-top: 1.2rem; }
.chat-box h2 { font-size: 1rem; color: var(--muted); margin-bottom: 0.6rem; }
.chat-messages { display: flex; flex-direction: column; gap: 0.5rem; max-height: 420px; overflow-y: auto; margin-bottom: 0.8rem; }
.chat-msg { padding: 0.6rem 0.9rem; border-radius: 12px; max-width: 85%; white-space: pre-wrap; font-size: 0.92rem; line-height: 1.5; }
.chat-msg.chat-user { align-self: flex-end; background: var(--accent); color: #fff; }
.chat-msg.chat-assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--border); }
.chat-form { display: flex; gap: 0.5rem; }
.chat-form input { flex: 1; padding: 0.6rem 0.8rem; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--text); }

.md-toolbar { display: flex; gap: 0.4rem; margin-top: 1rem; flex-wrap: wrap; }
.md-toolbar button { padding: 0.4rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--text); cursor: pointer; font-size: 0.85rem; }
.md-toolbar button:hover { border-color: var(--accent); color: var(--accent); }
.form-actions { display: flex; gap: 0.6rem; margin-top: 0.8rem; }
.btn-secondary { background: var(--card); color: var(--text); border: 1px solid var(--border); }

.blog-content { margin-top: 1.2rem; line-height: 1.7; font-size: 1rem; }
.blog-content h1, .blog-content h2, .blog-content h3 { margin: 1.4rem 0 0.6rem; }
.blog-content p { margin: 0.6rem 0; }
.blog-content img { max-width: 100%; border-radius: 10px; margin: 0.8rem 0; display: block; }
.blog-content ul, .blog-content ol { padding-left: 1.4rem; }
.blog-content blockquote { border-left: 3px solid var(--accent); margin: 0.8rem 0; padding: 0.2rem 0 0.2rem 1rem; color: var(--muted); }
.blog-content code { background: rgba(128,128,128,0.15); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.9em; }
.blog-content pre { background: rgba(128,128,128,0.12); padding: 0.8rem; border-radius: 8px; overflow-x: auto; }
.blog-content pre code { background: none; padding: 0; }

.blog-list li { display: flex; gap: 0.8rem; align-items: flex-start; }
.blog-list .thumb-link { flex-shrink: 0; }
.blog-list .thumb { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; display: block; }
.blog-list-body { flex: 1; min-width: 0; }

.search-form { display: flex; gap: 0.5rem; margin-top: 1rem; align-items: center; }
.search-form input { flex: 1; padding: 0.5rem 0.7rem; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--text); }
.search-form button { padding: 0.5rem 0.9rem; border: none; border-radius: 8px; background: var(--accent); color: #fff; cursor: pointer; }

.tags { margin-left: 0.5rem; }
.tag-chip { display: inline-block; background: rgba(59,111,237,0.15); color: var(--accent); border-radius: 999px; padding: 0.1rem 0.6rem; font-size: 0.72rem; margin-right: 0.3rem; }
.event-chip .recur { margin-right: 0.15rem; }

.todo-add-form { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.todo-add-form input[type="text"] { flex: 1; min-width: 150px; padding: 0.5rem 0.7rem; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--text); }
.todo-add-form input[type="date"] { padding: 0.5rem; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--text); }
.todo-add-form button { padding: 0.5rem 0.9rem; border: none; border-radius: 8px; background: var(--accent); color: #fff; cursor: pointer; }

.todo-list { list-style: none; padding: 0; margin: 1rem 0; }
.todo-list li { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0; border-bottom: 1px dashed var(--border); }
.todo-list li.done .todo-title { text-decoration: line-through; color: var(--muted); }
.todo-check { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--accent); padding: 0; }
.todo-title { flex: 1; }
.todo-list .date { color: var(--muted); font-size: 0.8rem; }
.todo-list .del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; }

.breadcrumb { margin: 1rem 0; font-size: 0.9rem; color: var(--muted); }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.file-table { width: 100%; border-collapse: collapse; margin-top: 0.8rem; font-size: 0.9rem; }
.file-table th { text-align: left; padding: 0.5rem; color: var(--muted); font-size: 0.8rem; border-bottom: 1px solid var(--border); }
.file-table td { padding: 0.5rem; border-bottom: 1px solid var(--border); }
.file-table a { color: var(--accent); text-decoration: none; }
.file-actions { display: flex; gap: 0.5rem; align-items: center; white-space: nowrap; }
.file-actions .del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; }
.card form { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
.card form input[type="text"], .card form input[type="file"] { flex: 1; min-width: 120px; padding: 0.4rem; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }

.dup-group { margin-top: 1rem; }
.dup-list { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.dup-list li { display: flex; align-items: center; gap: 0.7rem; padding: 0.4rem 0; border-bottom: 1px dashed var(--border); font-size: 0.85rem; flex-wrap: wrap; }
.dup-path { font-family: monospace; word-break: break-all; }

@media (max-width: 640px) {
  .cal-table { font-size: 0.65rem; }
  .cal-table td { height: 80px; }
  .file-table { font-size: 0.78rem; }
}
