:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --sidebar: #f1f0ec;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e6e4de;
  --hover: #eae8e1;
  --active: #e3e1d9;
  --accent: #2f6fed;
  --quote: #5a5a5a;
  --danger: #c0392b;
  --radius: 8px;
  --sidebar-w: 260px;
  --font: "Segoe UI", "PingFang HK", "PingFang TC", "Noto Sans TC",
    "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

.app { display: flex; min-height: 100%; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px 14px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-weight: 650;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: #111;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
}
.brand-text { font-size: 15px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-section {
  margin: 14px 8px 6px;
  font-size: 11px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
}
.nav-item:hover { background: var(--hover); text-decoration: none; }
.nav-item.active { background: var(--active); font-weight: 600; }
.nav-ico { opacity: 0.7; font-size: 13px; width: 1.2em; text-align: center; }
.sidebar-foot { margin: 16px 8px 4px; font-size: 12px; color: var(--muted); }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid transparent;
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  z-index: 5;
}
.crumbs {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.crumbs strong { color: var(--text); font-weight: 600; }

.page {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 24px 28px 96px;
  outline: none;
}
.page-title {
  font-size: clamp(1.75rem, 3vw, 2.35rem);
  line-height: 1.25;
  font-weight: 700;
  margin: 8px 0 8px;
  letter-spacing: -0.02em;
}
.page-meta { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

.blocks { display: flex; flex-direction: column; }
.block-row {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 4px;
  align-items: start;
  position: relative;
}
.block-gutter {
  opacity: 0;
  transition: opacity .12s;
  padding-top: 4px;
}
.block-row:hover .block-gutter { opacity: 1; }
.block-del {
  width: 26px; height: 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
}
.block-del:hover { background: var(--hover); color: var(--text); }
.block-main { min-width: 0; padding: 2px 0; }

.block-h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 22px 0 6px;
  letter-spacing: -0.01em;
}
.block-h3 { font-size: 1.1rem; font-weight: 650; margin: 16px 0 4px; }
.block-p { margin: 0; font-size: 16px; color: #242424; }
.block-ul, .block-ol { margin: 4px 0; padding-left: 1.35em; font-size: 16px; }
.block-ul li, .block-ol li { margin: 3px 0; }
.block-quote {
  margin: 10px 0;
  padding: 8px 14px;
  border-left: 3px solid #c9c5bb;
  color: var(--quote);
  background: #f1efe9;
  border-radius: 0 6px 6px 0;
  font-size: 15px;
}
.block-hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

.callout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: #eef3ff;
  border: 1px solid #d7e3ff;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 8px 0;
  font-size: 15px;
}
.callout-ico { font-size: 18px; line-height: 1.4; }

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  color: inherit;
  text-decoration: none;
  transition: border-color .15s, box-shadow .15s;
}
.card:hover {
  text-decoration: none;
  border-color: #cfcbc2;
  box-shadow: 0 4px 16px rgba(0,0,0,.04);
}
.card-title { font-weight: 650; margin: 0 0 6px; font-size: 15px; }
.card-desc { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

/* Insert */
.insert-row {
  position: relative;
  height: 14px;
  display: flex;
  align-items: center;
  margin: 2px 0 2px 32px;
}
.insert-btn {
  position: absolute;
  left: -30px;
  width: 22px; height: 22px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  font-size: 16px;
  line-height: 1;
  z-index: 2;
}
.insert-row:hover .insert-btn,
.insert-row:focus-within .insert-btn { opacity: 1; }
.insert-btn:hover { background: var(--hover); border-color: var(--line); color: var(--text); }
.insert-line {
  flex: 1;
  height: 1px;
  background: transparent;
}
.insert-row:hover .insert-line { background: var(--accent); opacity: .35; }
.insert-menu {
  position: absolute;
  top: 22px;
  left: -8px;
  width: min(280px, calc(100vw - 48px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.12);
  padding: 8px;
  z-index: 40;
}
.insert-menu-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 6px 8px 8px;
}
.insert-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}
.insert-item:hover { background: var(--hover); }
.insert-ico {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--sidebar);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #444;
}
.insert-menu-foot {
  border-top: 1px solid var(--line);
  margin-top: 6px;
  padding-top: 6px;
}
.insert-item.danger { color: var(--danger); }
.insert-item.map-variant .insert-ico { background: #111; color: #fff; }

/* Database */
.db-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  margin: 8px 0 12px;
}
.db-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fafaf7;
}
.db-title-row { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.db-ico { opacity: .7; }
.db-tabs { display: flex; gap: 4px; background: var(--sidebar); padding: 3px; border-radius: 8px; }
.db-tab {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}
.db-tab.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.db-table-wrap { overflow: auto; }
.db-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 720px;
}
.db-table th {
  text-align: left;
  font-weight: 650;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fcfcfa;
  white-space: nowrap;
}
.db-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.db-table tr:last-child td { border-bottom: 0; }
.db-table tr:hover td { background: #fafaf8; }
.db-title, .db-title-link { font-weight: 650; color: var(--text); }
.db-title-link:hover { color: var(--accent); }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  color: #fff;
  background: var(--pill, #6b6b6b);
}
.tag-row { display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 6px;
  background: #eeebe4;
  color: #444;
  font-size: 12px;
  font-weight: 600;
}
.progress-cell { display: flex; align-items: center; gap: 8px; }
.progress-cell span { font-size: 12px; color: var(--muted); min-width: 2.5em; }
.progress {
  flex: 1;
  height: 7px;
  border-radius: 999px;
  background: #ebe8e1;
  overflow: hidden;
  min-width: 64px;
}
.progress i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #5b8def, #2f6fed);
  border-radius: 999px;
}

.db-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  padding: 12px;
  background: #f7f6f3;
}
.db-col {
  background: #efeee9;
  border-radius: 10px;
  padding: 8px;
  min-height: 120px;
}
.db-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding: 2px 4px;
}
.db-col-cards { display: flex; flex-direction: column; gap: 8px; }
.db-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}
.db-card-title { font-weight: 650; font-size: 13.5px; margin-bottom: 4px; }
.db-card-meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; min-height: 1.2em; }

/* Map embed */
.map-block {
  margin: 10px 0 16px;
  border: 1px solid #2a2624;
  border-radius: 14px;
  overflow: hidden;
  background: #0b0b0c;
  box-shadow: 0 10px 36px rgba(0,0,0,.18);
}
.map-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #1a1715, #121010);
  color: #f5f5f7;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.map-title { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.map-ico { opacity: .85; }
.map-hint { margin: 4px 0 0; font-size: 12px; color: #a1a1a6; max-width: 52ch; }
.map-open {
  flex: none;
  font-size: 12px;
  font-weight: 650;
  color: #ffd79a;
  border: 1px solid rgba(255,179,64,.45);
  border-radius: 999px;
  padding: 6px 12px;
  text-decoration: none;
  background: rgba(255,179,64,.1);
}
.map-open:hover { background: rgba(255,179,64,.2); text-decoration: none; }
.map-frame-wrap { width: 100%; background: #0b0b0c; }
.map-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #0b0b0c;
}

.icon-btn {
  border: 0;
  background: transparent;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  color: var(--text);
}
.icon-btn:hover { background: var(--hover); }
.mobile-only { display: none; }
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 20;
}

@media (max-width: 900px) {
  .page { width: min(100%, 100%); }
  .block-row { grid-template-columns: 22px 1fr; }
  .insert-row { margin-left: 24px; }
}
@media (max-width: 800px) {
  .mobile-only { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    z-index: 30;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,.08);
  }
  .sidebar.open { transform: translateX(0); }
  .page { padding: 12px 14px 72px; }
  .topbar { padding: 8px 12px; border-bottom-color: var(--line); }
  .map-frame-wrap { height: 480px !important; }
  .block-gutter { opacity: 1; }
  .insert-btn { opacity: 1; }
}
