@import url('https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600;700&display=swap');

:root {
  --paper: #f2ede0;
  --card: #fffdf9;
  --card-line: #e6ddc6;
  --ink: #2c291f;
  --ink-dim: #756c58;
  --teal: #3f8570;
  --teal-soft: #e2efe8;
  --terracotta: #c4633c;
  --terracotta-soft: #f8e6da;
  --red: #b23b3b;
  --shadow: 0 6px 20px rgba(70,58,30,0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: 'Inter', sans-serif;
  color: var(--ink);
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 15% 5%, rgba(63,133,112,0.06), transparent 45%),
    radial-gradient(circle at 90% 95%, rgba(196,99,60,0.06), transparent 50%);
}

.page { padding: 44px 24px 80px; min-height: 100vh; }

.head {
  max-width: 1040px;
  margin: 0 auto 24px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.head h1 {
  font-family: 'Sora', sans-serif;
  font-weight: 800;
  font-size: 28px;
  margin: 0;
  color: var(--ink);
}

.head .sub { font-size: 13px; font-weight: 500; color: var(--ink-dim); margin-top: 4px; }

.back-link {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-dim);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.back-link:hover { color: var(--teal); }

/* ---- 篩選工具列 ---- */
.toolbar {
  max-width: 1040px;
  margin: 0 auto 20px;
  position: sticky;
  top: 16px;
  z-index: 5;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.search-row { display: flex; gap: 10px; margin-bottom: 12px; }

.search-input {
  flex: 1;
  min-width: 0;
  background: var(--paper);
  border: 1px solid var(--card-line);
  border-radius: 11px;
  padding: 9px 14px;
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
}
.search-input::placeholder { color: var(--ink-dim); }
.search-input:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

.unlock-btn {
  flex: 0 0 auto;
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-dim);
  background: var(--paper);
  border: 1px solid var(--card-line);
  padding: 9px 14px;
  border-radius: 11px;
  cursor: pointer;
  white-space: nowrap;
}
.unlock-btn:hover { border-color: var(--teal); color: var(--ink); }
.unlock-btn.unlocked { background: var(--teal-soft); border-color: var(--teal); color: var(--teal); }

.chip-groups { display: flex; flex-wrap: wrap; gap: 14px; }
.chip-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chip-group .glabel {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-dim);
  letter-spacing: 0.03em;
  margin-right: 2px;
}

.chip {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 20px;
  color: var(--ink-dim);
  background: var(--paper);
  border: 1px solid transparent;
  cursor: pointer;
}
.chip.active { background: var(--teal-soft); border-color: var(--teal); color: var(--teal); }

.result-count {
  max-width: 1040px;
  margin: 0 auto;
  font-size: 12px;
  color: var(--ink-dim);
  font-weight: 600;
  padding: 0 2px 16px;
}

/* ---- 筆記卡片列表 ---- */
.n-grid {
  max-width: 1040px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.n-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 20px;
  padding: 20px 20px 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
}
.n-card:hover { border-color: var(--teal); }
.n-card:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.n-card.is-hidden { display: none; }

.n-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }

.n-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  background: var(--teal-soft);
  border: 1px solid var(--card-line);
  flex: 0 0 auto;
}

.n-date { font-size: 11px; font-weight: 600; color: var(--ink-dim); font-family: 'IBM Plex Mono', monospace; }

.n-card h3 {
  font-family: 'Sora', sans-serif;
  font-size: 16.5px;
  font-weight: 800;
  margin: 0 0 8px;
  color: var(--ink);
}

.n-summary { font-size: 13px; font-weight: 500; line-height: 1.55; color: var(--ink-dim); margin: 0 0 14px; flex: 1; }

.n-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.n-tag { font-size: 10.5px; font-weight: 700; padding: 3px 9px; border-radius: 20px; background: var(--paper); color: var(--ink-dim); }
.n-tag.project { background: var(--teal-soft); color: var(--teal); }

/* 私人筆記鎖定卡片 */
.n-card.locked { align-items: center; justify-content: center; text-align: center; gap: 8px; opacity: 0.8; }
.n-card.locked .n-top { justify-content: center; margin-bottom: 6px; }
.n-card.locked .lock-label { font-size: 13px; font-weight: 700; color: var(--ink-dim); }
.n-card.locked .lock-hint { font-size: 11px; color: var(--ink-dim); }

.empty-state { max-width: 1040px; margin: 0 auto; text-align: center; padding: 50px 20px; color: var(--ink-dim); font-size: 13.5px; font-weight: 600; }
.empty-state.is-hidden { display: none; }

/* ---- 筆記詳情彈出視窗 ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(44,41,31,0.4);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-overlay.is-open { display: flex; }

.modal {
  max-width: 820px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 22px;
  padding: 32px 28px 28px;
  position: relative;
  box-shadow: 0 24px 60px rgba(60,50,30,0.18);
}

.modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--card-line);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
}
.modal-close:hover { border-color: var(--teal); color: var(--teal); }

.modal-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }

/* Markdown 內文排版（marked.js 產出的 HTML） */
.md-body { font-size: 14px; line-height: 1.7; color: #46412f; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 {
  font-family: 'Sora', sans-serif;
  color: var(--ink);
  margin: 24px 0 10px;
}
.md-body h1:first-child, .md-body h2:first-child, .md-body h3:first-child { margin-top: 0; }
.md-body h1 { font-size: 22px; font-weight: 800; }
.md-body h2 { font-size: 18px; font-weight: 800; }
.md-body h3 { font-size: 15.5px; font-weight: 700; color: var(--teal); }
.md-body p { margin: 0 0 14px; }
.md-body ul, .md-body ol { margin: 0 0 14px; padding-left: 22px; }
.md-body li { margin-bottom: 6px; }
.md-body strong { color: var(--ink); font-weight: 700; }
.md-body a { color: var(--teal); }
.md-body img { max-width: 100%; border-radius: 12px; border: 1px solid var(--card-line); margin: 10px 0 16px; display: block; }
.md-body code { font-family: 'IBM Plex Mono', monospace; font-size: 12.5px; background: var(--paper); color: var(--ink); padding: 2px 6px; border-radius: 6px; }
.md-body pre { background: var(--paper); border: 1px solid var(--card-line); border-radius: 12px; padding: 14px; overflow-x: auto; margin: 0 0 16px; }
.md-body pre code { background: none; padding: 0; }
.md-body table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 0 0 16px; }
.md-body th, .md-body td { padding: 8px 10px; border-bottom: 1px solid var(--card-line); text-align: left; }
.md-body th { color: var(--ink); font-weight: 700; }
.md-body blockquote { margin: 0 0 16px; padding: 10px 16px; border-left: 3px solid var(--teal); background: var(--teal-soft); border-radius: 0 10px 10px 0; }
.md-body hr { border: none; border-top: 1px solid var(--card-line); margin: 20px 0; }

/* ---- 流程圖元件（白底方框卡片） ---- */
.flow-card {
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 18px;
  padding: 26px 24px 22px;
  margin: 0 0 18px;
  overflow-x: auto;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.flow-caption { font-size: 12px; font-weight: 600; color: var(--ink-dim); margin: 0 0 18px; }
.flow-caption:last-child { margin-bottom: 0; }

.flow-lane { min-width: 560px; }
.flow-lane + .flow-lane { margin-top: 22px; padding-top: 22px; border-top: 1px dashed var(--card-line); }

.flow-row-track { display: flex; align-items: flex-start; gap: 6px; flex-wrap: nowrap; }
.flow-row-track.wrap { flex-wrap: wrap; }

.flow-node { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1 1 0; min-width: 110px; }

.flow-box { border-radius: 12px; padding: 12px 12px; text-align: center; width: 100%; box-sizing: border-box; }
.flow-box.dashed { border: 1.5px dashed var(--card-line); background: var(--paper); }
.flow-box.solid { border: 1.5px solid #c3d6ce; background: var(--teal-soft); }
.flow-box.highlight { border: 1.5px solid var(--terracotta); background: var(--terracotta-soft); }
.flow-box.ok { border: 1.5px solid #a9c9ba; background: #eaf4ee; }
.flow-box.missing { border: 1.5px dashed var(--terracotta); background: var(--terracotta-soft); }

.flow-box-title { font-weight: 700; font-size: 13px; color: var(--ink); line-height: 1.45; }
.flow-box-sub { font-size: 11px; color: var(--ink-dim); line-height: 1.45; margin-top: 3px; }

.flow-arrow-right { display: flex; flex-direction: column; align-items: center; justify-content: center; padding-top: 22px; color: #a89f88; font-size: 15px; flex: 0 0 auto; }
.flow-arrow-right .lbl { font-size: 10px; color: var(--ink-dim); margin-top: 2px; white-space: nowrap; }
.flow-arrow-right.dashed-arrow { color: var(--terracotta); }

.flow-arrow-down { text-align: center; color: #a89f88; font-size: 15px; line-height: 1.3; margin: 2px 0; }
.flow-arrow-down .lbl { display: block; font-size: 10px; color: var(--ink-dim); margin-top: 1px; }
.flow-arrow-down.dashed-arrow { color: var(--terracotta); }
.flow-arrow-down.dashed-arrow .lbl { color: var(--terracotta); }

.flow-merge-label { text-align: center; font-size: 11.5px; color: var(--ink-dim); margin: 4px 0 8px; }

.flow-center { display: flex; justify-content: center; }
.flow-node-narrow { max-width: 240px; }

/* ---- 密碼解鎖彈窗 ---- */
.pw-modal { max-width: 340px; padding: 28px 24px 24px; }
.pw-modal h2 { font-family: 'Sora', sans-serif; font-size: 16px; font-weight: 800; margin: 0 0 6px; color: var(--ink); }
.pw-modal p { font-size: 12.5px; color: var(--ink-dim); margin: 0 0 16px; line-height: 1.5; }
.pw-row { display: flex; gap: 8px; }
.pw-input {
  flex: 1;
  min-width: 0;
  background: var(--paper);
  border: 1px solid var(--card-line);
  border-radius: 11px;
  padding: 9px 12px;
  color: var(--ink);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13.5px;
}
.pw-input:focus { outline: 2px solid var(--teal); outline-offset: 1px; }
.pw-toggle {
  flex: 0 0 auto;
  background: var(--paper);
  border: 1px solid var(--card-line);
  border-radius: 11px;
  color: var(--ink-dim);
  font-size: 13px;
  padding: 0 12px;
  cursor: pointer;
}
.pw-submit {
  margin-top: 14px;
  width: 100%;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--teal);
  padding: 10px;
  border-radius: 11px;
  border: none;
  cursor: pointer;
}
.pw-error { font-size: 12px; color: var(--red); font-weight: 600; margin-top: 10px; min-height: 15px; }
.pw-submit-ghost { margin-top: 8px; background: var(--paper); color: var(--ink); border: 1px solid var(--card-line); }

@media (max-width: 640px) {
  .search-row { flex-direction: column; }
}
