:root {
  --bg: #f3efe6;
  --paper: #fffcf7;
  --ink: #1f1b16;
  --muted: #6f675c;
  --line: #ddd4c6;
  --accent: #2f5d50;
  --accent-soft: #dce8e2;
  --danger: #8b2e2e;
  --shadow: 0 12px 40px rgba(31, 27, 22, 0.08);
  --radius: 16px;
  --font: "Iowan Old Style", "Palatino Linotype", "Songti SC", "Noto Serif SC", serif;
  --ui: "Avenir Next", "PingFang SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--ui);
  color: var(--ink);
  background: radial-gradient(1200px 600px at 10% -10%, #e7f0ea 0%, var(--bg) 45%);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
h1, h2, .brand, .eyebrow { font-family: var(--font); }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 252, 247, 0.92);
  position: sticky;
  top: 0;
  z-index: 10;
}
.primary-nav { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: baseline; }
.brand { font-size: 1.15rem; margin-right: 8px; }
.primary-nav a, .side-nav a, .sub-nav a {
  padding: 6px 2px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.primary-nav a.is-active,
.side-nav a.is-active,
.sub-nav a.is-active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}
.logout-form { margin: 0; }
.btn-quiet,
.btn-primary {
  font: inherit;
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
}
.btn-quiet {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}
.btn-primary {
  border: 0;
  background: var(--accent);
  color: white;
}
.danger { color: var(--danger); }

.todo-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 58px);
}
.side-nav {
  padding: 20px 16px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(255, 252, 247, 0.55);
}
.nav-label {
  margin: 16px 0 0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.info-layout { display: flex; flex-direction: column; }
.sub-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 14px 20px 0;
  border-bottom: 1px solid var(--line);
}
.content { padding: 28px 24px 48px; max-width: 760px; }
.empty {
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px;
  color: var(--muted);
  box-shadow: var(--shadow);
}
.muted { color: var(--muted); }
.small { font-size: 0.9rem; margin: 0 0 8px; }

.login-body { display: grid; place-items: center; }
.login-shell { width: min(440px, calc(100vw - 32px)); padding: 32px 0; }
.login-card {
  background: var(--paper);
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.eyebrow { margin: 0; color: var(--accent); letter-spacing: 0.12em; text-transform: uppercase; font-size: 0.78rem; }
.lead { color: var(--muted); line-height: 1.55; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; }
.stack input,
.stack textarea,
.stack select {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
}
.alert {
  background: #fbeaea;
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 10px;
}

.task-group { margin: 0 0 28px; }
.task-group h2 { font-size: 1.05rem; margin: 0 0 10px; }
.task-list { list-style: none; margin: 0; padding: 0; }
.task-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
}
.task-row.is-done .task-title { color: var(--muted); text-decoration: line-through; }
.complete-form { margin: 0; }
.check {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.task-title { flex: 1; min-width: 0; }
.priority-mark {
  font-size: 0.75rem;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 8px;
}
.quick-add {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.quick-add select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.list-save-form select {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.doc-list .inline-form { margin: 0; }
.info-panel h3 { font-size: 0.95rem; margin: 16px 0 8px; }
.completed-block { margin-top: 24px; color: var(--muted); }
.inline-form { display: inline-flex; gap: 6px; align-items: center; }
.admin-list { list-style: none; padding: 0; margin: 0; }
.admin-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.list-admin { margin-bottom: 28px; }
.edit-form textarea,
.edit-form select,
.edit-form input[type="date"] {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 100%;
}
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.habit-panel {
  margin: 0 0 32px;
  padding: 16px 16px 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.habit-panel h2 { font-size: 1.05rem; margin: 0 0 12px; }
.habit-list { list-style: none; margin: 0; padding: 0; }
.habit-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}
.habit-row:last-child { border-bottom: 0; }
.habit-check-form { margin: 0; }
.habit-dot {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.habit-row.is-done .habit-dot {
  background: var(--accent-soft);
}
.habit-name { font-weight: 600; }
.habit-meta { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }

.sub-nav .capture-settings {
  margin-left: auto;
  font-size: 0.9rem;
}
.token-once { border-color: var(--accent); }
.token-value {
  font-size: 1.05rem;
  word-break: break-all;
  background: #fff;
  border: 1px dashed var(--accent);
  border-radius: 10px;
  padding: 12px;
}
.scope-set {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.scope-set legend { color: var(--muted); }
.check-label { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.section-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}
.section-head h1,
.section-head h2 { margin: 0; }
.info-panel {
  margin: 0 0 28px;
  padding: 16px 16px 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.info-panel h2 { font-size: 1.05rem; margin: 0 0 12px; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}
.plain-list li:last-child { border-bottom: 0; }
.crumb { color: var(--muted); margin: 0 0 8px; }
.md-editor {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  min-height: 22rem;
  line-height: 1.5;
  resize: vertical;
}
.md-body {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px 28px;
  box-shadow: var(--shadow);
  line-height: 1.65;
  overflow-x: auto;
}
.md-body > *:first-child { margin-top: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 {
  font-family: var(--font);
  line-height: 1.3;
}
.md-body pre {
  overflow-x: auto;
  background: #f4efe6;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.92rem;
  line-height: 1.45;
}
.md-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.md-body :not(pre) > code {
  background: var(--accent-soft);
  padding: 1px 6px;
  border-radius: 6px;
}
.md-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
}
.md-body th, .md-body td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}
.md-body blockquote {
  margin: 12px 0;
  padding: 0 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.md-body a { color: var(--accent); text-decoration: underline; }
.md-body img { max-width: 100%; height: auto; }
.md-body .k, .md-body .kd, .md-body .kn, .md-body .kc { color: #2f5d50; font-weight: 600; }
.md-body .s, .md-body .s1, .md-body .s2, .md-body .sa, .md-body .sb { color: #8b2e2e; }
.md-body .c, .md-body .c1, .md-body .cm { color: #6f675c; font-style: italic; }
.md-body .mi, .md-body .mf, .md-body .nb, .md-body .bp { color: #1d4e89; }
.md-body .nf { color: #245c8a; }
.md-body .o, .md-body .p { color: #3d3832; }

@media (max-width: 720px) {
  .todo-layout { grid-template-columns: 1fr; }
  .side-nav {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    align-items: center;
  }
  .nav-label { margin: 8px 8px 0 0; width: 100%; }
  .topbar { padding: 12px; }
  .content { padding: 20px 16px 40px; }
  .check { width: 36px; height: 36px; min-width: 36px; }
  .habit-dot { width: 36px; height: 36px; min-width: 36px; }
  .quick-add { flex-wrap: wrap; }
  .quick-add input { min-width: 160px; }
}
