:root{
  --sidebar-w: 260px;
  --border: rgba(55, 53, 47, 0.16);
  --text: #37352f;
  --text-dim: rgba(55, 53, 47, 0.65);
  --bg: #ffffff;
  --sidebar-bg: #fbfbfa;
  --hover: rgba(55, 53, 47, 0.08);
  --accent: #2383e2;
  --callout-bg: #fbf3db;
  --callout-border: #e8c766;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
  color: var(--text);
  background: var(--bg);
  display: flex;
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  overflow-y: auto;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  display: flex;
  flex-direction: column;
}
.side-search {
  display: flex; align-items: center; gap: 6px;
  margin: 0 12px 12px; padding: 6px 10px;
  color: var(--text-dim); font-size: 14px;
  border-radius: 4px;
  cursor: pointer;
}
.side-search:hover { background: var(--hover); }
.side-search input {
  border: none; background: transparent; outline: none; width: 100%;
}
#tree { padding: 0 12px; }

.tree-item {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; border-radius: 4px; cursor: pointer;
  color: var(--text); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tree-item:hover { background: var(--hover); }
.tree-item.active { background: rgba(55, 53, 47, 0.08); font-weight: 500; }
.tree-item .caret {
  width: 14px; flex: 0 0 14px; color: var(--text-dim); font-size: 10px; transition: transform .1s; display: flex; align-items: center; justify-content: center;
}
.tree-item .icon { flex: 0 0 auto; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; text-align: center; }
.tree-icon-img { width: 16px; height: 16px; object-fit: cover; border-radius: 3px; }
.children { margin-left: 14px; display: none; }
.children.open { display: block; }

/* Category Link List (Advanced Database Home) */
.category-link-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 28px 0 60px;
}
.category-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  padding: 4px 0;
  cursor: pointer;
}
.category-list-item:hover .cat-item-text {
  text-decoration: underline;
}
.cat-item-icon {
  width: 22px;
  height: 22px;
  object-fit: cover;
  border-radius: 4px;
}
.cat-item-icon.emoji {
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-cover-banner {
  width: 100%;
  height: 230px;
  margin-bottom: 20px;
  overflow: hidden;
  border-radius: 4px;
}
.page-cover-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---------- Main ---------- */
#main { flex: 1; height: 100vh; overflow-y: auto; }
.topbar {
  position: sticky; top: 0; background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(8px);
  padding: 10px 32px;
  font-size: 14px; color: var(--text-dim);
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 8px; overflow: hidden; }
#crumb-trail { display: flex; align-items: center; gap: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-left b { color: var(--text); font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-btn {
  background: transparent; border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 10px; font-size: 13px; color: var(--text); cursor: pointer;
  display: flex; align-items: center; gap: 4px;
}
.topbar-btn:hover { background: var(--hover); }

#pages { max-width: 900px; margin: 0 auto; padding: 36px 48px 96px; }

/* Metadata / Pages */
.page-icon { font-size: 78px; margin-bottom: 20px; line-height: 1.1; }
.page-icon-box {
  width: 124px;
  height: 124px;
  border-radius: 4px;
  background: #f0ede6;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.page-icon-box img {
  width: 104px;
  height: 104px;
  object-fit: contain;
  border-radius: 50%;
  display: block;
}
h1.page-title { font-size: 40px; margin: 0 0 20px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }
.flowus-quote {
  border-left: 3px solid #37352f;
  padding-left: 14px;
  margin: 14px 0 24px 0;
  color: #37352f;
  font-size: 15px;
  line-height: 1.6;
}
.flowus-quote div { margin: 4px 0; }
h2 { font-size: 24px; margin: 40px 0 16px; font-weight: 600; }
h3 { font-size: 20px; margin: 24px 0 12px; font-weight: 600; }
.text-block { margin: 0 0 8px; }
.page-img { max-width: 100%; height: auto; border-radius: 4px; margin: 16px 0; display: block; }
.page-img.img-icon,
.page-img[src*="logo"],
.page-img[src*="icon"],
.page-img[src*=".svg"] {
  max-width: 120px;
  max-height: 120px;
  object-fit: contain;
  margin: 12px 0;
  border-radius: 4px;
}

.callout {
  display: flex; gap: 12px;
  background: var(--callout-bg);
  border-radius: 4px;
  padding: 16px;
  margin: 0 0 24px;
}
.callout .em { font-size: 20px; }
.callout p { margin: 0 0 6px; font-size: 15px; }
.callout p:last-child { margin-bottom: 0; }

/* ---------- Database Toolbar ---------- */
.db-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding: 6px 0 10px;
  margin: 16px 0 20px;
  font-size: 14px;
}
.db-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  color: var(--text);
  padding-bottom: 6px;
  border-bottom: 2px solid #37352f;
  margin-bottom: -11px;
  cursor: pointer;
}
.db-tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}
.db-tools {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-dim);
  font-size: 13px;
}
.db-tool-btn {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}
.db-tool-btn:hover {
  color: var(--text);
}

/* ---------- Course Gallery Grid ---------- */
.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin: 16px 0 32px;
}
.course-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  cursor: pointer;
  box-shadow: rgba(15, 15, 15, 0.05) 0px 0px 0px 1px, rgba(15, 15, 15, 0.1) 0px 2px 4px;
  transition: background 20ms ease-in;
  display: flex;
  flex-direction: column;
}
.course-card:hover {
  background: rgba(239, 239, 238, 0.5);
  box-shadow: rgba(15, 15, 15, 0.1) 0px 3px 6px;
}
.course-cover {
  height: 140px;
  border-bottom: 1px solid var(--border);
  background: #ebe4d8;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.course-emoji {
  font-size: 48px;
}
.course-svg-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.course-svg-icon svg {
  width: 100%;
  height: 100%;
}
.course-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}
.course-body {
  padding: 8px 10px 12px;
}
.course-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 0 8px;
}

/* ---------- Property Rows ---------- */
.course-props {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.prop-row {
  display: flex;
  align-items: flex-start;
  font-size: 12px;
  line-height: 1.5;
}
.prop-label {
  color: rgba(55, 53, 47, 0.5);
  width: 56px;
  flex-shrink: 0;
}
.prop-val {
  color: var(--text);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

/* ---------- FlowUs 精確色碼 Pill 標籤 ---------- */
/* 所有數值皆從真實 FlowUs 頁面以 Puppeteer 爬取 */
.pill {
  display: inline-block;
  padding: 0px 6px;
  border-radius: 2px;
  font-size: 12px;
  white-space: nowrap;
  line-height: 1.5;
}
.pill-pink { background: rgb(248, 218, 230); color: rgb(139, 43, 105); }
.pill-orange { background: rgb(248, 222, 197); color: rgb(104, 61, 38); }
.pill-grey { background: rgb(236, 237, 237); color: rgb(71, 77, 88); }
.pill-yellow { background: rgb(255, 242, 197); color: rgb(140, 101, 47); }
.pill-brown { background: rgb(232, 229, 215); color: rgb(81, 72, 43); }
.pill-purple { background: rgb(220, 220, 248); color: rgb(71, 43, 132); }
.pill-blue { background: rgb(210, 225, 249); color: rgb(38, 60, 104); }
.pill-red { background: rgb(255, 216, 215); color: rgb(139, 39, 48); }
.pill-green { background: rgb(210, 236, 213); color: rgb(59, 91, 70); }
/* 向下相容舊 class 名 */
.pink-pill { background: rgb(248, 218, 230); color: rgb(139, 43, 105); }
.yellow-pill { background: rgb(255, 242, 197); color: rgb(140, 101, 47); }
.purple-pill { background: rgb(220, 220, 248); color: rgb(71, 43, 132); }

.course-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.course-coach {
  background: rgba(227, 226, 224, 0.5);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 12px;
  color: var(--text-dim);
  display: inline-block;
  white-space: nowrap;
}

#loading { padding: 48px; color: var(--text-dim); text-align: center; }

/* ---------- 根頁面自訂黑底 Banner ---------- */
.root-custom-banner {
  background: #000000;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 36px 20px;
  color: #ffffff;
}
.root-custom-banner .banner-title-big {
  font-size: 38px;
  font-weight: 800;
  color: #fbde38;
  letter-spacing: 2px;
  margin-bottom: 12px;
}
.root-custom-banner .banner-title-mid {
  font-size: 20px;
  font-weight: 700;
  color: #fbde38;
  letter-spacing: 1px;
  margin-bottom: 16px;
}
.root-custom-banner .banner-sub-line {
  font-size: 14px;
  color: #ffffff;
  letter-spacing: 1px;
  font-weight: 400;
}

/* ---------- B站推廣連結列 ---------- */
.promo-links-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  font-size: 14px;
  margin: 16px 0;
  padding: 10px 14px;
  background: #fbfbfa;
  border: 1px solid rgba(55, 53, 47, 0.09);
  border-radius: 4px;
}
.promo-links-bar a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
  margin: 0 4px;
  font-weight: 500;
}
.promo-links-bar a:hover {
  color: var(--accent);
}
.promo-links-bar .promo-title {
  font-weight: 600;
  color: var(--text);
}
.promo-links-bar .promo-sep {
  color: var(--text-dim);
  margin: 0 4px;
}
.promo-links-bar .promo-icon {
  margin-right: 6px;
}

.cat-item-icon-emoji {
  width: 22px;
  height: 22px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ---------- FlowUs 文章排版元素 ---------- */
.flowus-quote {
  border-left: 3px solid #37352f;
  padding: 2px 0 2px 14px;
  margin: 14px 0 18px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
}
.flowus-quote .quote-bold {
  font-weight: 600;
  margin-bottom: 2px;
}
.flowus-quote.disclaimer {
  border-left-color: rgba(55, 53, 47, 0.3);
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 24px;
}

.flowus-h2 {
  font-size: 20px;
  font-weight: 700;
  margin: 28px 0 12px;
  color: var(--text);
  line-height: 1.3;
}

.flowus-paragraph {
  margin: 12px 0;
  line-height: 1.65;
  color: var(--text);
  font-size: 15px;
}

.flowus-bullet-list {
  margin: 10px 0 18px 24px;
  padding: 0;
  list-style-type: disc;
}
.flowus-bullet-list li {
  margin-bottom: 6px;
  line-height: 1.6;
  color: var(--text);
}

.flowus-official-link {
  margin: 12px 0;
  font-size: 15px;
  color: var(--text);
}
.flowus-official-link a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 500;
}

/* ---------- Mobile Responsive Enhancements ---------- */

/* Menu Toggle Button (Hidden on Desktop) */
.menu-toggle-btn {
  display: none;
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--text);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  margin-right: 4px;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.menu-toggle-btn:hover, .menu-toggle-btn:active {
  background: var(--hover);
}

/* Sidebar Backdrop Overlay (Hidden on Desktop) */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sidebar-overlay.mobile-open {
  display: block;
  opacity: 1;
}

@media (max-width: 768px) {
  /* Layout Adjustments */
  body {
    position: relative;
    overflow-x: hidden;
  }
  
  /* Sidebar Drawer */
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.15);
    width: 280px;
    min-width: 280px;
  }
  #sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Show Menu Toggle Button */
  .menu-toggle-btn {
    display: inline-flex;
  }

  /* Topbar Adjustments */
  .topbar {
    padding: 8px 14px;
    height: 52px;
  }
  .topbar-left {
    font-size: 13.5px;
    gap: 6px;
  }
  .topbar-right {
    gap: 4px;
  }
  .topbar-btn {
    padding: 3px 8px;
    font-size: 12px;
  }

  /* Main Container & Page Padding */
  #main {
    width: 100%;
    overflow-x: hidden;
  }
  #pages {
    padding: 18px 16px 64px;
    max-width: 100%;
  }

  /* Page Headers & Typography */
  h1.page-title {
    font-size: 25px;
    margin-bottom: 14px;
    line-height: 1.3;
    word-break: break-word;
  }
  .page-icon-box {
    width: 88px;
    height: 88px;
    margin-bottom: 14px;
  }
  .page-icon-box img {
    width: 72px;
    height: 72px;
  }
  .page-icon {
    font-size: 54px;
    margin-bottom: 14px;
  }

  /* Page Cover Banner */
  .page-cover-banner {
    height: 140px;
    margin-bottom: 14px;
  }

  /* Root Custom Banner (德撲高級課程資料庫) */
  .root-custom-banner {
    min-height: 180px;
    padding: 24px 14px;
  }
  .root-custom-banner .banner-title-big {
    font-size: 24px;
    letter-spacing: 1px;
  }
  .root-custom-banner .banner-title-mid {
    font-size: 16px;
  }
  .root-custom-banner .banner-sub-line {
    font-size: 12px;
  }

  /* Course Grid (1 Column on Mobile) */
  .course-grid {
    grid-template-columns: 1fr;
    gap: 14px;
    margin: 14px 0 24px;
  }
  .course-cover {
    height: 150px;
  }
  .course-body {
    padding: 10px 12px 14px;
  }
  .course-title {
    font-size: 15px;
    white-space: normal;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Database Toolbar */
  .db-toolbar {
    flex-wrap: wrap;
    gap: 10px;
    padding-bottom: 8px;
  }
  .db-tools {
    gap: 10px;
    font-size: 12px;
  }

  /* Headings & Text Formatting */
  .flowus-h2 {
    font-size: 18px;
    margin: 22px 0 10px;
  }
  .flowus-paragraph {
    font-size: 14.5px;
    margin: 10px 0;
    line-height: 1.6;
  }
  .flowus-bullet-list {
    margin: 8px 0 14px 18px;
  }
  .flowus-bullet-list li {
    font-size: 14.5px;
  }
  .flowus-quote {
    font-size: 14px;
    padding-left: 12px;
    margin: 10px 0 16px;
  }
  .flowus-official-link {
    font-size: 14px;
    word-break: break-all;
  }

  /* Promo Links Bar */
  .promo-links-bar {
    padding: 8px 10px;
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  #pages {
    padding: 14px 12px 48px;
  }
  h1.page-title {
    font-size: 22px;
  }
  .topbar-left b {
    max-width: 140px;
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
  }
  .topbar-right {
    display: none;
  }
}
