/* ============================================================
   側邊欄導覽網站 — 暖色系主題
   配色：米白、奶茶、淺棕、暖灰、柔和橘
   間距基數：8px
   功能：側邊欄可拖拉調整寬度、設定面板、文字大小切換
   ============================================================ */

/* --- CSS Variables --- */
:root {
  --color-bg: #FDF8F0;
  --color-sidebar: #F5E6D3;
  --color-sidebar-hover: #EDD9C4;
  --color-sidebar-active: #D4A574;
  --color-primary: #D4A574;
  --color-primary-dark: #B8895A;
  --color-accent: #E8976B;
  --color-text: #3D2B1F;
  --color-text-light: #6B5344;
  --color-text-muted: #9B8574;
  --color-border: #E0D0C0;
  --color-code-bg: #F9F2EB;
  --color-code-border: #E8D8C8;
  --color-white: #FFFFFF;
  --color-footer-bg: #3D2B1F;
  --color-footer-text: #F5E6D3;

  --sidebar-width: 280px;
  --header-height: 64px;

  --font-body: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
  --font-mono: "Fira Code", "Source Code Pro", "Consolas", monospace;

  --shadow-sm: 0 1px 3px rgba(61, 43, 31, 0.08);
  --shadow-md: 0 4px 12px rgba(61, 43, 31, 0.1);
  --shadow-lg: 0 8px 24px rgba(61, 43, 31, 0.12);

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --transition: all 0.3s ease;
  --color-card: rgba(255, 255, 255, 0.7);

  /* Callout colors (semantic — consistent across all themes) */
  --callout-tip-bg: #f0f9f0;
  --callout-tip-border: #5a8a5a;
  --callout-warning-bg: #fff8f0;
  --callout-warning-border: #d4874d;
  --callout-note-bg: #f0f4fa;
  --callout-note-border: #5b7fa5;
}

/* --- Theme: Ocean --- */
body.theme-ocean {
  --color-bg: #F5F7FA; --color-sidebar: #E8ECF1; --color-sidebar-hover: #D8DFE8;
  --color-sidebar-active: #5B7FA5; --color-primary: #5B7FA5; --color-primary-dark: #486A8C;
  --color-accent: #4A90D9; --color-text: #2D3748; --color-text-light: #4A5568;
  --color-text-muted: #718096; --color-border: #CBD5E0; --color-code-bg: #EDF2F7;
  --color-code-border: #D2DCE6; --color-footer-bg: #1B3A4B; --color-footer-text: #E8ECF1;
  --shadow-sm: 0 1px 3px rgba(45,55,72,.08); --shadow-md: 0 4px 12px rgba(45,55,72,.1);
  --shadow-lg: 0 8px 24px rgba(45,55,72,.12);
}
body.theme-ocean .site-header { background: linear-gradient(135deg,#2C5F7C 0%,#1B3A4B 100%); }
body.theme-ocean .footer-license { background: #122830; }
body.theme-ocean .copy-btn.copied { background: #2B6CB0; }

/* --- Theme: Forest --- */
body.theme-forest {
  --color-bg: #F5F9F0; --color-sidebar: #E0EDD3; --color-sidebar-hover: #D0DFC2;
  --color-sidebar-active: #6B9B5A; --color-primary: #6B9B5A; --color-primary-dark: #558247;
  --color-accent: #8BC34A; --color-text: #2E3D1F; --color-text-light: #4A5E38;
  --color-text-muted: #7A8E6A; --color-border: #C5D6B4; --color-code-bg: #EFF5E8;
  --color-code-border: #D5E3C8; --color-footer-bg: #2E3D1F; --color-footer-text: #E0EDD3;
  --shadow-sm: 0 1px 3px rgba(46,61,31,.08); --shadow-md: 0 4px 12px rgba(46,61,31,.1);
  --shadow-lg: 0 8px 24px rgba(46,61,31,.12);
}
body.theme-forest .site-header { background: linear-gradient(135deg,#3E5C2A 0%,#2E3D1F 100%); }
body.theme-forest .footer-license { background: #1F2A14; }
body.theme-forest .copy-btn.copied { background: #558247; }

/* --- Theme: Sakura --- */
body.theme-sakura {
  --color-bg: #FFF5F5; --color-sidebar: #FFE4E4; --color-sidebar-hover: #FFD4D4;
  --color-sidebar-active: #D4838A; --color-primary: #D4838A; --color-primary-dark: #B86B72;
  --color-accent: #E8636B; --color-text: #3D1F22; --color-text-light: #6B4448;
  --color-text-muted: #9B7478; --color-border: #F0C8CA; --color-code-bg: #FFF0F0;
  --color-code-border: #F0D8DA; --color-footer-bg: #3D1F22; --color-footer-text: #FFE4E4;
  --shadow-sm: 0 1px 3px rgba(61,31,34,.08); --shadow-md: 0 4px 12px rgba(61,31,34,.1);
  --shadow-lg: 0 8px 24px rgba(61,31,34,.12);
}
body.theme-sakura .site-header { background: linear-gradient(135deg,#5C2D33 0%,#3D1F22 100%); }
body.theme-sakura .footer-license { background: #2C1418; }
body.theme-sakura .copy-btn.copied { background: #B86B72; }

/* --- Theme Transition Animation --- */
body.theme-transitioning,
body.theme-transitioning * {
  transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease !important;
}

/* --- Theme Grid in Settings Panel --- */
.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.theme-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 8px; background: var(--color-white); border: 2px solid var(--color-border);
  border-radius: var(--radius-md); cursor: pointer; transition: all .2s ease; font-family: inherit;
}
.theme-card:hover { border-color: var(--color-primary); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.theme-card.active { border-color: var(--color-accent); background: var(--color-code-bg); box-shadow: 0 0 0 1px var(--color-accent); }
.theme-preview { display: flex; gap: 4px; width: 100%; height: 28px; border-radius: var(--radius-sm); overflow: hidden; }
.tp-bar { flex: 1; border-radius: 3px; }
.theme-name { font-size: 12px; font-weight: 600; color: var(--color-text); white-space: nowrap; }

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.75;
  font-size: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--header-height);
  background: linear-gradient(135deg, #5C3D2E 0%, #3D2B1F 100%);
  color: var(--color-footer-text);
  display: flex;
  align-items: center;
  padding: 0 24px;
  box-shadow: var(--shadow-md);
}

.header-content {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

/* Header Action Buttons */
.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 16px;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--color-footer-text);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  text-decoration: none;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  line-height: 1;
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-1px);
}

.header-btn:active {
  transform: translateY(0);
}

.header-btn svg {
  flex-shrink: 0;
}

/* Fullscreen active state */
.header-btn.fullscreen-active {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.site-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-subtitle {
  font-size: 14px;
  opacity: 0.8;
  white-space: nowrap;
}

/* Hamburger */
.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  margin-right: 12px;
  z-index: 110;
}

.menu-toggle span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--color-footer-text);
  border-radius: 2px;
  transition: all 0.3s ease;
}

/* --- Main Layout --- */
.main-layout {
  display: flex;
  margin-top: var(--header-height);
  flex: 1;
  min-height: calc(100vh - var(--header-height));
}

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-sidebar);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  z-index: 50;
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-light);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.nav-list {
  list-style: none;
  padding: 8px 0;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  margin: 0;
}

.nav-item a {
  display: block;
  padding: 10px 20px;
  color: var(--color-text);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.5;
  border-left: 3px solid transparent;
  transition: all 0.2s ease;
  cursor: pointer;
}

.nav-item a:hover {
  background: var(--color-sidebar-hover);
  border-left-color: var(--color-primary);
}

.nav-item a.active {
  background: var(--color-white);
  border-left-color: var(--color-accent);
  color: var(--color-accent);
  font-weight: 600;
}

/* 子單元縮排 */
.nav-item.sub-item a {
  padding-left: 36px;
  font-size: 13px;
}

/* 群組標題 */
.nav-item.group-title {
  border-top: 1px solid var(--color-border);
  margin-top: 4px;
  padding-top: 4px;
}

.nav-item.group-title:first-child,
.nav-list > .nav-item:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

/* 頂層獨立項目分隔線 */
.nav-item.top-item {
  border-top: 1px solid var(--color-border);
  margin-top: 4px;
  padding-top: 4px;
}

.nav-item.group-title a {
  font-weight: 700;
  color: var(--color-text-light);
  cursor: pointer;
  font-size: 14px;
}

.nav-item.group-title a:hover {
  background: var(--color-sidebar-hover);
}

/* 群組展開圖示 */
.nav-item.group-title .expand-icon {
  float: right;
  transition: transform 0.2s ease;
  font-size: 12px;
}

.nav-item.group-title.expanded .expand-icon {
  transform: rotate(90deg);
}

/* --- Sidebar Footer (Settings Button) --- */
.sidebar-footer {
  position: sticky;
  bottom: 0;
  padding: 12px 16px;
  background: var(--color-sidebar);
  border-top: 1px solid var(--color-border);
}

.settings-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: var(--color-white);
  color: var(--color-text-light);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.settings-btn:hover {
  background: var(--color-sidebar-hover);
  color: var(--color-text);
  border-color: var(--color-primary);
}

.settings-btn svg {
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.settings-btn:hover svg {
  transform: rotate(45deg);
}

/* --- Sidebar Resizer (Drag Handle) --- */
.sidebar-resizer {
  position: fixed;
  top: var(--header-height);
  left: var(--sidebar-width);
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 55;
  background: transparent;
  transition: background 0.2s ease;
  transform: translateX(-3px);
}

.sidebar-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 40px;
  background: var(--color-border);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sidebar-resizer:hover {
  background: var(--color-primary);
  opacity: 0.3;
}

.sidebar-resizer:hover::after {
  opacity: 1;
}

body.resizing .sidebar-resizer {
  background: var(--color-primary);
  opacity: 0.4;
}

body.resizing .sidebar-resizer::after {
  opacity: 1;
}

body.resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

/* --- Settings Panel --- */
.settings-panel {
  position: fixed;
  top: var(--header-height);
  left: var(--sidebar-width);
  bottom: 0;
  width: 320px;
  background: var(--color-white);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.3s ease, opacity 0.3s ease;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--color-border);
}

.settings-panel.open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.settings-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--color-border);
}

.settings-panel-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
}

.settings-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--color-code-bg);
  color: var(--color-text-light);
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  line-height: 1;
}

.settings-close:hover {
  background: var(--color-sidebar-hover);
  color: var(--color-text);
}

.settings-panel-body {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.settings-group {
  margin-bottom: 28px;
}

.settings-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 12px;
}

.settings-options {
  display: flex;
  gap: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.settings-option {
  flex: 1;
  padding: 10px 16px;
  background: var(--color-white);
  color: var(--color-text-light);
  border: none;
  border-right: 1px solid var(--color-border);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.settings-option:last-child {
  border-right: none;
}

.settings-option:hover {
  background: var(--color-code-bg);
}

.settings-option.active {
  background: var(--color-primary);
  color: var(--color-white);
  font-weight: 600;
}

/* --- Font Size Modes --- */
body.font-medium {
  font-size: 15px;
}

body.font-medium .content-inner h1 { font-size: 26px; }
body.font-medium .content-inner h2 { font-size: 21px; }
body.font-medium .content-inner h3 { font-size: 17px; }
body.font-medium .content-inner p,
body.font-medium .content-inner li { font-size: 15px; }
body.font-medium .content-inner pre code { font-size: 13px; }

body.font-large {
  font-size: 16px;
}
/* font-large is default, no overrides needed */

body.font-xlarge {
  font-size: 18px;
}

body.font-xlarge .content-inner h1 { font-size: 32px; }
body.font-xlarge .content-inner h2 { font-size: 26px; }
body.font-xlarge .content-inner h3 { font-size: 21px; }
body.font-xlarge .content-inner p,
body.font-xlarge .content-inner li { font-size: 18px; line-height: 1.9; }
body.font-xlarge .content-inner pre code { font-size: 15px; }
body.font-xlarge .content-inner table { font-size: 16px; }

/* --- Overlay --- */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(61, 43, 31, 0.5);
  z-index: 40;
  transition: opacity 0.3s ease;
}

/* --- Content Area --- */
.content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: calc(100vh - var(--header-height));
}

.content-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 48px;
}

/* Welcome screen */
.welcome-screen {
  text-align: center;
  padding: 100px 24px 80px;
  color: var(--color-text-muted);
}

.welcome-screen::before {
  content: "\1F4D6";
  display: block;
  font-size: 56px;
  margin-bottom: 20px;
  filter: grayscale(0.2);
}

.welcome-screen h2 {
  font-size: 32px;
  font-weight: 900;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--color-primary-dark), var(--color-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-screen p {
  font-size: 16px;
  margin-bottom: 8px;
}

.welcome-screen .keyboard-hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
  padding: 10px 20px;
  background: var(--color-code-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: 13px;
  color: var(--color-text-light);
}

.welcome-screen .keyboard-hint kbd {
  display: inline-block;
  padding: 2px 8px;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* --- Rendered Markdown Content --- */
.content-inner h1 {
  font-size: 28px;
  font-weight: 900;
  color: var(--color-text);
  margin: 48px 0 24px;
  padding-bottom: 16px;
  line-height: 1.4;
  position: relative;
}

.content-inner h1::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent), var(--color-primary-dark));
  border-radius: 2px;
}

.content-inner h1:first-child {
  margin-top: 0;
}

.content-inner h2 {
  font-size: 22px;
  font-weight: 800;
  color: var(--color-text);
  margin: 40px 0 16px;
  padding-left: 16px;
  border-left: 4px solid var(--color-primary);
  line-height: 1.4;
}

.content-inner h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-primary-dark);
  margin: 32px 0 12px;
  padding: 6px 14px;
  background: var(--color-code-bg);
  border-radius: var(--radius-md);
  display: inline-block;
  line-height: 1.4;
}

.content-inner h4 {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text-light);
  margin: 24px 0 8px;
}

.content-inner p {
  margin: 0 0 16px;
  line-height: 1.85;
}

.content-inner ul {
  margin: 0 0 16px;
  padding-left: 0;
  list-style: none;
}

.content-inner ol {
  margin: 0 0 16px;
  padding-left: 24px;
}

.content-inner ol > li::marker {
  color: var(--color-primary-dark);
  font-weight: 700;
}

.content-inner ul > li {
  position: relative;
  padding-left: 20px;
}

.content-inner ul > li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 11px;
  width: 8px;
  height: 8px;
  background: var(--color-primary);
  border-radius: 50%;
}

.content-inner ul > li > ul > li::before {
  background: transparent;
  border: 2px solid var(--color-primary);
  width: 6px;
  height: 6px;
}

.content-inner li {
  margin-bottom: 6px;
  line-height: 1.75;
}

.content-inner li > ul,
.content-inner li > ol {
  margin-top: 6px;
  margin-bottom: 0;
}

.content-inner strong {
  font-weight: 700;
  color: var(--color-text);
}

.content-inner em {
  font-style: italic;
  color: var(--color-text-light);
}

.content-inner blockquote {
  margin: 20px 0;
  padding: 16px 20px 16px 24px;
  border-left: 4px solid var(--color-primary);
  background: var(--color-card);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  color: var(--color-text-light);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.3s ease, transform 0.3s ease;
  position: relative;
}

.content-inner blockquote::before {
  content: "\1F4A1";
  position: absolute;
  top: -10px;
  left: -10px;
  font-size: 20px;
  background: var(--color-bg);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.content-inner blockquote:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.content-inner blockquote p:last-child {
  margin-bottom: 0;
}

/* Callout variants (auto-classified by JS) */
.content-inner blockquote.callout-tip {
  border-left-color: var(--callout-tip-border);
  background: var(--callout-tip-bg);
}
.content-inner blockquote.callout-tip::before {
  content: "\2705";
}

.content-inner blockquote.callout-warning {
  border-left-color: var(--callout-warning-border);
  background: var(--callout-warning-bg);
}
.content-inner blockquote.callout-warning::before {
  content: "\26A0\FE0F";
}

.content-inner blockquote.callout-note {
  border-left-color: var(--callout-note-border);
  background: var(--callout-note-bg);
}
.content-inner blockquote.callout-note::before {
  content: "\1F4DD";
}

.content-inner hr {
  border: none;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--color-primary), var(--color-accent), var(--color-primary), transparent);
  margin: 40px 0;
  border-radius: 2px;
}

.content-inner a {
  color: var(--color-accent);
  text-decoration: none;
  border-bottom: 2px solid rgba(232, 151, 107, 0.3);
  transition: all 0.3s ease;
  padding-bottom: 1px;
}

.content-inner a:hover {
  border-bottom-color: var(--color-accent);
  background: rgba(232, 151, 107, 0.08);
  border-radius: 2px;
}

.content-inner img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-lg);
  margin: 16px 0;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.content-inner img:hover {
  transform: scale(1.01);
  box-shadow: var(--shadow-md);
}

/* --- Tables --- */
.content-inner table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 20px 0 28px;
  font-size: 14px;
  background: var(--color-white);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  transition: box-shadow 0.3s ease;
}

.content-inner table:hover {
  box-shadow: var(--shadow-md);
}

.content-inner thead {
  background: linear-gradient(135deg, var(--color-sidebar), var(--color-sidebar-hover));
}

.content-inner th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 700;
  color: var(--color-text);
  border-bottom: 2px solid var(--color-primary);
}

.content-inner td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.content-inner tbody tr {
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.content-inner tbody tr:hover {
  background: var(--color-code-bg);
  transform: scale(1.002);
}

.content-inner tbody tr:last-child td {
  border-bottom: none;
}

/* --- Code --- */
.content-inner code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  font-weight: 500;
  background: var(--color-code-bg);
  border: 1px solid var(--color-code-border);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--color-accent);
  word-break: break-word;
}

.content-inner pre {
  margin: 20px 0 28px;
  border-radius: var(--radius-lg);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: box-shadow 0.3s ease;
}

.content-inner pre:hover {
  box-shadow: var(--shadow-md);
}

.content-inner pre::before {
  content: "";
  display: block;
  height: 3px;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.content-inner pre code {
  display: block;
  padding: 20px 24px;
  font-size: 13.5px;
  line-height: 1.65;
  background: var(--color-code-bg);
  border: 1px solid var(--color-code-border);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  color: var(--color-text);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Language badge (inserted by JS) */
.code-lang-badge {
  position: absolute;
  top: 7px;
  right: 80px;
  padding: 2px 8px;
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--color-primary);
  color: var(--color-white);
  border-radius: 10px;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 5;
}

.code-wrapper:hover .code-lang-badge {
  opacity: 0.8;
}

/* Copy button for code blocks */
.code-wrapper {
  position: relative;
}

.copy-btn {
  position: absolute;
  top: 7px;
  right: 10px;
  padding: 4px 14px;
  font-size: 12px;
  font-family: inherit;
  background: var(--color-primary);
  color: var(--color-white);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 5;
}

.code-wrapper:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background: var(--color-primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.copy-btn.copied {
  background: #5a8a5a;
}

/* --- Footer --- */
.site-footer {
  margin-left: var(--sidebar-width);
}

.footer-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 48px;
}

/* Footer Layer 1: Author */
.footer-author {
  background: var(--color-sidebar);
  padding: 48px 0;
  border-top: 3px solid var(--color-primary);
}

.author-card {
  display: flex;
  gap: 32px;
  align-items: flex-start;
}

.author-photo {
  flex-shrink: 0;
  width: 280px;
}

.author-photo img {
  width: 100%;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.author-info {
  flex: 1;
  min-width: 0;
}

.author-info h3 {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 12px;
}

.author-positions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.position-tag {
  display: inline-block;
  padding: 4px 12px;
  background: var(--color-primary);
  color: var(--color-white);
  font-size: 13px;
  border-radius: 20px;
  font-weight: 500;
}

.author-awards h4 {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-light);
  margin-bottom: 8px;
}

.author-awards ul {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 24px;
}

.author-awards li {
  font-size: 13px;
  color: var(--color-text-light);
  padding-left: 16px;
  position: relative;
  line-height: 1.7;
}

.author-awards li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  width: 6px;
  height: 6px;
  background: var(--color-accent);
  border-radius: 50%;
}

/* Footer Layer 2: Links */
.footer-links {
  background: var(--color-footer-bg);
  padding: 24px 0;
}

.footer-links .footer-inner {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.social-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  color: var(--color-white);
}

.social-btn.youtube {
  background: #c4302b;
}

.social-btn.youtube:hover {
  background: #a52722;
}

.social-btn.facebook {
  background: #1877f2;
}

.social-btn.facebook:hover {
  background: #1565c0;
}

.social-btn.email {
  background: var(--color-primary);
}

.social-btn.email:hover {
  background: var(--color-primary-dark);
}

/* Footer Layer 3: License */
.footer-license {
  background: #2C1E14;
  padding: 20px 0;
  text-align: center;
}

.footer-license p {
  color: var(--color-footer-text);
  font-size: 13px;
  margin: 4px 0;
}

.footer-license .license-detail {
  font-size: 11px;
  opacity: 0.7;
}

/* --- Scroll to Top --- */
.scroll-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  background: var(--color-primary);
  color: var(--color-white);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 30;
}

.scroll-top.visible {
  opacity: 1;
  visibility: visible;
}

.scroll-top:hover {
  background: var(--color-primary-dark);
  transform: translateY(-2px);
}

/* --- Sidebar Scrollbar --- */
.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--color-primary);
}

/* --- Content Scrollbar --- */
.content-inner::-webkit-scrollbar {
  width: 8px;
}

.content-inner::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

/* --- Loading Indicator --- */
.loading {
  text-align: center;
  padding: 80px 24px;
  color: var(--color-text-muted);
}

.loading::after {
  content: "";
  display: block;
  width: 40px;
  height: 40px;
  margin: 24px auto 0;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   Responsive Design
   ============================================================ */

/* Tablet */
@media (max-width: 1024px) {
  .header-btn .btn-label {
    display: none;
  }

  .header-btn {
    padding: 8px 10px;
  }

  .content-inner {
    padding: 32px 32px;
  }

  .footer-inner {
    padding: 0 32px;
  }

  .author-photo {
    width: 220px;
  }

  .author-awards ul {
    grid-template-columns: 1fr;
  }
}

/* Mobile */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 280px;
    --header-height: 56px;
  }

  .menu-toggle {
    display: flex;
  }

  .site-title {
    font-size: 16px;
  }

  .site-subtitle {
    display: none;
  }

  /* Header buttons: hide labels, icon-only */
  .header-actions {
    gap: 4px;
    margin-left: 8px;
  }

  .header-btn {
    padding: 8px;
    border-radius: 50%;
  }

  .header-btn .btn-label {
    display: none;
  }

  /* Sidebar off-canvas */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .overlay.active {
    display: block;
  }

  /* Hide resizer on mobile */
  .sidebar-resizer {
    display: none;
  }

  /* Settings panel full width on mobile */
  .settings-panel {
    left: 0;
    width: 100%;
  }

  /* Content full width */
  .content {
    margin-left: 0;
  }

  .site-footer {
    margin-left: 0;
  }

  .content-inner {
    padding: 24px 20px;
  }

  .footer-inner {
    padding: 0 20px;
  }

  /* Footer author card stack */
  .author-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .author-photo {
    width: 200px;
  }

  .author-positions {
    justify-content: center;
  }

  .author-awards ul {
    grid-template-columns: 1fr;
    text-align: left;
  }

  /* Content typography */
  .content-inner h1 {
    font-size: 22px;
    margin: 36px 0 16px;
  }

  .content-inner h2 {
    font-size: 19px;
    margin: 28px 0 12px;
  }

  .content-inner h3 {
    font-size: 16px;
  }

  .content-inner pre code {
    font-size: 12px;
    padding: 16px;
  }

  .content-inner table {
    font-size: 12px;
  }

  .content-inner th,
  .content-inner td {
    padding: 8px 10px;
  }

  .welcome-screen {
    padding: 60px 16px;
  }

  .welcome-screen h2 {
    font-size: 22px;
  }

  .social-btn {
    padding: 8px 16px;
    font-size: 13px;
  }
}

/* Small phones */
@media (max-width: 480px) {
  .content-inner {
    padding: 16px 14px;
  }

  .footer-author {
    padding: 32px 0;
  }

  .author-photo {
    width: 160px;
  }

  .footer-links .footer-inner {
    flex-direction: column;
    align-items: center;
  }

  .social-btn {
    width: 100%;
    max-width: 280px;
    justify-content: center;
  }
}

/* --- Print Styles --- */
@media print {
  .sidebar,
  .menu-toggle,
  .overlay,
  .scroll-top,
  .copy-btn,
  .sidebar-resizer,
  .settings-panel {
    display: none !important;
  }

  .content {
    margin-left: 0 !important;
  }

  .site-footer {
    margin-left: 0 !important;
  }

  .site-header {
    position: static;
  }

  .main-layout {
    margin-top: 0;
  }
}

/* ============================================================
   安裝精靈 — Wizard
   ============================================================ */

/* --- 側邊欄入口按鈕 --- */
.wizard-entry {
  padding: 12px 16px 4px;
}

.wizard-entry-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  background: linear-gradient(135deg, var(--color-accent), var(--color-primary-dark));
  color: #fff;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.25s ease;
  text-align: left;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
}

.wizard-entry-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  filter: brightness(1.08);
}

.wizard-entry-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  flex-shrink: 0;
}

.wizard-entry-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.wizard-entry-text strong {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
}

.wizard-entry-text small {
  font-size: 11px;
  opacity: 0.85;
  line-height: 1.3;
}

.wizard-entry-arrow {
  font-size: 12px;
  opacity: 0.7;
  flex-shrink: 0;
}

/* --- 精靈全頁覆蓋 --- */
.wizard-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.wizard-overlay.open {
  display: flex;
}

.wizard-panel {
  width: 100%;
  max-width: 780px;
  max-height: 92vh;
  background: var(--color-bg);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- 精靈標題列 --- */
.wizard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  background: linear-gradient(135deg, var(--color-accent), var(--color-primary-dark));
  color: #fff;
}

.wizard-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.wizard-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.wizard-close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  font-size: 24px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  line-height: 1;
}

.wizard-close:hover {
  background: rgba(255,255,255,0.35);
}

/* --- 進度條 --- */
.wizard-progress {
  position: relative;
  padding: 16px 24px;
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
}

.wizard-progress-bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--color-accent);
  transition: width 0.4s ease;
}

.wizard-progress-steps {
  display: flex;
  justify-content: space-between;
  gap: 4px;
}

.wizard-progress-dot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.wizard-progress-dot .dot-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  background: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--color-text-muted);
  transition: all 0.3s ease;
}

.wizard-progress-dot.active .dot-circle {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: #fff;
}

.wizard-progress-dot.done .dot-circle {
  border-color: #5a8a5a;
  background: #5a8a5a;
  color: #fff;
}

.wizard-progress-dot .dot-label {
  font-size: 11px;
  color: var(--color-text-muted);
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.wizard-progress-dot.active .dot-label {
  color: var(--color-accent);
  font-weight: 600;
}

.wizard-progress-dot.done .dot-label {
  color: #5a8a5a;
}

/* --- 步驟內容區 --- */
.wizard-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.wizard-step-content {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
  line-height: 1.8;
  font-size: 15px;
}

.wizard-step-content h2 {
  font-size: 22px;
  margin-bottom: 12px;
  color: var(--color-text);
}

.wizard-step-content h3 {
  font-size: 17px;
  margin: 20px 0 8px;
  color: var(--color-text);
}

.wizard-step-content p {
  margin-bottom: 12px;
}

.wizard-step-content code {
  background: var(--color-code-bg);
  border: 1px solid var(--color-code-border);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.wizard-step-content pre {
  background: var(--color-code-bg);
  border: 1px solid var(--color-code-border);
  border-radius: var(--radius-md);
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
}

.wizard-step-content pre code {
  background: none;
  border: none;
  padding: 0;
}

.wizard-step-content .step-checklist {
  list-style: none;
  padding: 0;
  margin: 16px 0;
}

.wizard-step-content .step-checklist li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 6px;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
}

.wizard-step-content .step-checklist li:hover {
  border-color: var(--color-primary);
}

.wizard-step-content .step-checklist li.checked {
  background: #f0f9f0;
  border-color: #5a8a5a;
}

.wizard-step-content .step-checklist li .check-icon {
  width: 22px;
  height: 22px;
  border: 2px solid var(--color-border);
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
  transition: all 0.2s;
}

.wizard-step-content .step-checklist li.checked .check-icon {
  background: #5a8a5a;
  border-color: #5a8a5a;
  color: #fff;
}

/* 成功/完成區塊 */
.wizard-success-card {
  text-align: center;
  padding: 40px 24px;
}

.wizard-success-card .success-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.wizard-success-card h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.wizard-success-card p {
  color: var(--color-text-light);
}

/* --- AI 聊天區 --- */
.wizard-chat {
  border-top: 1px solid var(--color-border);
  background: var(--color-white);
}

.wizard-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-light);
  user-select: none;
  transition: background 0.2s;
}

.wizard-chat-header:hover {
  background: var(--color-code-bg);
}

.wizard-chat-header span {
  flex: 1;
}

.wizard-chat-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: transform 0.3s;
  padding: 4px;
  display: flex;
}

.wizard-chat.expanded .wizard-chat-toggle {
  transform: rotate(180deg);
}

.wizard-chat-body {
  display: none;
  flex-direction: column;
  max-height: 280px;
}

.wizard-chat.expanded .wizard-chat-body {
  display: flex;
}

.wizard-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 200px;
}

.chat-msg {
  display: flex;
}

.chat-msg.chat-user {
  justify-content: flex-end;
}

.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.chat-ai .chat-bubble {
  background: var(--color-code-bg);
  color: var(--color-text);
  border-bottom-left-radius: 4px;
}

.chat-user .chat-bubble {
  background: var(--color-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble.typing::after {
  content: '...';
  animation: typingDots 1s infinite;
}

@keyframes typingDots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

.wizard-chat-input-wrap {
  display: flex;
  gap: 8px;
  padding: 10px 24px 14px;
  border-top: 1px solid var(--color-border);
}

.wizard-chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  background: var(--color-bg);
  color: var(--color-text);
}

.wizard-chat-input:focus {
  border-color: var(--color-accent);
}

.wizard-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--color-accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.wizard-chat-send:hover {
  filter: brightness(1.1);
  transform: scale(1.05);
}

.wizard-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.wizard-chat-apikey-hint {
  display: none;
  padding: 8px 24px 12px;
  font-size: 12px;
  color: var(--color-text-muted);
  text-align: center;
}

.wizard-chat-apikey-hint.show {
  display: block;
}

/* --- 底部按鈕列 --- */
.wizard-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-top: 1px solid var(--color-border);
  background: var(--color-white);
}

.wizard-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.wizard-btn-primary {
  background: var(--color-accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(232,151,107,0.3);
}

.wizard-btn-primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(232,151,107,0.4);
}

.wizard-btn-secondary {
  background: var(--color-sidebar);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.wizard-btn-secondary:hover {
  background: var(--color-sidebar-hover);
}

.wizard-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

.wizard-step-indicator {
  font-size: 13px;
  color: var(--color-text-muted);
  font-weight: 600;
}

/* --- 設定面板 API Key --- */
.settings-apikey-wrap {
  display: flex;
  gap: 8px;
}

.settings-apikey-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: var(--font-mono);
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;
}

.settings-apikey-input:focus {
  border-color: var(--color-accent);
}

.settings-apikey-save {
  padding: 8px 16px;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.2s;
  white-space: nowrap;
}

.settings-apikey-save:hover {
  filter: brightness(1.1);
}

.settings-apikey-note {
  margin-top: 6px;
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.settings-apikey-note a {
  color: var(--color-accent);
  text-decoration: underline;
}

/* --- 精靈 RWD --- */
@media (max-width: 768px) {
  .wizard-panel {
    max-height: 100vh;
    border-radius: 0;
    height: 100%;
  }

  .wizard-overlay {
    padding: 0;
  }

  .wizard-progress-dot .dot-label {
    font-size: 10px;
  }

  .wizard-step-content {
    padding: 16px;
  }

  .wizard-chat-messages {
    padding: 10px 16px;
  }

  .wizard-chat-input-wrap {
    padding: 10px 16px 12px;
  }

  .wizard-footer {
    padding: 12px 16px;
  }

  .wizard-btn {
    padding: 10px 16px;
    font-size: 14px;
  }
}
