.fab {
  position: relative;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background-color: #F3EAD8;
  /* 同系但更深一階的米白色 */
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  /* 輕微紙感噪點 */
  background-image:
    radial-gradient(circle at 20% 20%, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
    radial-gradient(circle at 75% 75%, rgba(0, 0, 0, 0.02) 1px, transparent 1px);
  background-size: 5px 5px, 5px 5px;

  /* 調整：強調左下方深色投影，範圍小 */
  box-shadow: -4px 4px 10px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease-in-out;
}

/* 偽元素高光保留，若覺得過亮可刪除或調整透明度 */
.fab::before {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 40%;
  height: 40%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.20);
  filter: blur(6px);
  pointer-events: none;
}

.fab .line {
  display: block;
  width: 65%;
  height: 2px;
  margin: 3px 0;
  border-radius: 1px;
  background-color: #A09F97;

  /* 細微線條紙感 */
  background-image:
    radial-gradient(circle at 30% 30%, rgba(0, 0, 0, 0.05) 1px, transparent 1px),
    radial-gradient(circle at 60% 70%, rgba(0, 0, 0, 0.04) 1px, transparent 1px);
  background-size: 3px 3px, 3px 3px;
  transform-origin: center;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.fab .line:nth-child(1) {
  transform: rotate(1deg) scaleX(0.65);
}

.fab .line:nth-child(2) {
  transform: rotate(-1deg) scaleX(0.63);
}

.fab .line:nth-child(3) {
  transform: rotate(0.5deg) scaleX(0.64);
}

.fab:hover {
  transform: scale(1.08);
  /* Hover 時放大投影範圍略增，但依然集中左下 */
  box-shadow:
    -6px 6px 12px rgba(0, 0, 0, 0.3);
}

.fab:active {
  transform: scale(0.96);
  box-shadow:
    -2px 2px 8px rgba(0, 0, 0, 0.35);
  /* Adjusted active shadow */
}

/* Styles to position FAB at the bottom right */
.fab-container {
  position: fixed;
  bottom: 5px;
  
  /* 初始隱藏，等待 JavaScript 定位完成後顯示 */
  opacity: 0;
  visibility: hidden;

  z-index: 1000;
  /* Ensure it's above other content */
  transition: opacity 0.3s ease-in-out, left 0.3s ease-in-out, visibility 0.3s ease-in-out;
  /* Added left and visibility transitions */
}

/* FAB 容器準備就緒後的顯示狀態 */
.fab-container.positioned {
  opacity: 1;
  visibility: visible;
}

/* FAB Quick Menu Styles - Added */
.fab-quick-menu-container {
  position: absolute;
  bottom: 50px;
  /* 修改：向上偏移50px，避免覆蓋FAB */
  right: 0px;
  background-color: rgba(255, 255, 255, 0.85);
  /* Semi-transparent white */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  padding: 10px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(5px) scale(0.5);
  /* 修改：起始位置更接近最終位置 */
  transform-origin: 80% 100%;
  /* Added: Origin at bottom-rightish for expand effect */
  transition: opacity 0.25s ease-out, visibility 0.25s ease-out, transform 0.25s ease-out;
  /* Adjusted: Faster and ease-out */
  z-index: 999;
  /* min-width: 180px; */
  /* Removed to allow content to dictate width */
}

.fab-quick-menu-container.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.quick-menu-item {
  width: 80px;
  display: flex;
  align-items: center;
  padding: 12px 5px;
  cursor: pointer;
  border-radius: 8px;
  transition: background-color 0.2s ease;
  font-size: 16px;
  color: #333;
}

.quick-menu-item:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

.quick-menu-icon {
  margin-right: 12px;
  font-size: 20px;
  /* Adjust as needed for your SVG */
  display: inline-flex;
  align-items: center;
}

.quick-menu-text {
  font-weight: 500;
}

.quick-menu-item.item-font-size {
  position: relative;
  /* 讓子元素可以相對它定位 */
  overflow: visible;
  /* 確保子元素能夠超出父容器 */
}

.font-size-options {
  position: absolute;
  top: 0;
  left: auto;
  right: 90px;
  /* 起始位置在「字級」的右側 */
  height: 100%;
  padding: 6px;
  background-color: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 999;

  /* 初始狀態 - 隱藏並向右偏移 */
  transform: translateX(100%);
  /* 完全向右隱藏 */
  opacity: 0;
  pointer-events: none;
  /* 隱藏時不接收點擊 */

  /* 轉場效果 */
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.2s;

  /* 顯示內部按鈕的佈局 */
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.font-size-options.active {
  transform: translateX(0);
  /* 滑到最終位置 */
  opacity: 1;
  pointer-events: auto;
  /* 顯示時接收點擊 */
}

.font-size-button {
  background-color: transparent;
  border: 1px solid #ccc;
  color: #555;
  padding: 6px 0px;
  min-width: 36px;
  /* Ensure buttons have a minimum width */
  text-align: center;
  border-radius: 20px;
  /* Circular */
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  margin: 0 4px;
}

.font-size-button:hover {
  background-color: rgba(0, 0, 0, 0.08);
  border-color: #bbb;
}

.font-size-button.selected {
  background-color: #F3EAD8;
  /* FAB background color for consistency */
  border-color: #E0D5C1;
  /* Darker shade */
  color: #5D4037;
  /* Darker text */
  font-weight: bold;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Demo Font Size Adjustment Classes */
/* Apply these to .content-bundle */
.content-bundle p,
.content-bundle .quote p,
.content-bundle .content-paragraph {
  transition: font-size 0.3s ease-in-out;
}

.content-bundle h1,
.content-bundle h2,
.content-bundle h3,
.content-bundle h4 {
  transition: font-size 0.3s ease-in-out;
}

/* Default / Medium (20px) */
.font-size-20 .content-paragraph,
.font-size-20 .quote p,
.font-size-20 .content p {
  font-size: 20px;
}


.font-size-20 h2.subtitle {
  font-size: 24px;
}

.font-size-20 h3.chapter,
.font-size-20 h3.content-title {
  font-size: 22px;
}

/* Small (16px) */
.font-size-16 .content-paragraph,
.font-size-16 .quote p,
.font-size-16 .content p {
  font-size: 16px;
}


.font-size-16 h2.subtitle {
  font-size: 22px;
}

.font-size-16 h3.chapter,
.font-size-16 h3.content-title {
  font-size: 18px;
}

/* Large (24px) */
.font-size-24 .content-paragraph,
.font-size-24 .quote p,
.font-size-24 .content p {
  font-size: 24px;
}

.font-size-24 h2.subtitle {
  font-size: 30px;
}

.font-size-24 h3.chapter,
.font-size-24 h3.content-title {
  font-size: 26px;
}

/* Large (24px) */
.font-size-24 .content-paragraph,
.font-size-24 .quote p,
.font-size-24 .content p {
  font-size: 24px;
}

/* Extra Large (36px) */
.font-size-36 .content-paragraph,
.font-size-36 .quote p,
.font-size-36 .content p {
  font-size: 36px;
}

.content-bundle.font-size-36 h2.subtitle {
  font-size: 42px;
}

.content-bundle.font-size-36 h3.chapter,
.content-bundle.font-size-36 h3.content-title {
  font-size: 38px;
}

/* Ensure FAB container's left is also adjusted when vertical label moves */
.fab-container {
  transition: opacity 0.3s ease-in-out, left 0.3s ease-in-out;
  /* Added left transition */
}

/* Ensure FAB container is positioned correctly on smaller screens */
@media (max-width: 767px) {
  .fab-container {
    right: 5px;
    /* Restore right positioning for smaller screens */
    left: auto;
    /* Ensure left is not affecting fixed positioning */
  }
}

/* 修改：FAB按鈕展開菜單時的X形狀變換 */
.fab.menu-open .line:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.fab.menu-open .line:nth-child(2) {
  opacity: 0;
}

.fab.menu-open .line:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
  margin-top: 1px;
}

/* 恢復正常樣式，當菜單關閉時 */
.fab:not(.menu-open) .line:nth-child(1) {
  transform: rotate(1deg) scaleX(0.65);
}

.fab:not(.menu-open) .line:nth-child(2) {
  transform: rotate(-1deg) scaleX(0.63);
}

.fab:not(.menu-open) .line:nth-child(3) {
  transform: rotate(0.5deg) scaleX(0.64);
}

/* ====== 滑出式全螢幕目錄面板 ====== */
#side-directory-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  display: flex;
  pointer-events: none;
}

#side-directory-panel {
  width: 90vw;
  max-width: 420px;
  height: 100vh;
  background: #fff;
  box-shadow: 2px 0 24px rgba(0, 0, 0, 0.18);
  transform: translateX(-100%);
  transition: transform 0.35s cubic-bezier(.77, 0, .18, 1);
  overflow-y: auto;
  position: relative;
  pointer-events: auto;
}

#side-directory-overlay.active #side-directory-panel {
  transform: translateX(0);
}

#side-directory-backdrop {
  flex: 1 1 auto;
  background: rgba(0, 0, 0, 0.25);
  transition: opacity 0.3s;
  opacity: 0;
  pointer-events: none;
}

#side-directory-overlay.active #side-directory-backdrop {
  opacity: 1;
  pointer-events: auto;
}

#close-directory-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f7f3e9 60%, #e9e0c7 100%);
  border: none;
  color: #a08c6b;
  font-size: 2rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 10;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(160, 140, 107, 0.08);
  transition:
    background 0.35s cubic-bezier(.4,2,.6,1),
    color 0.25s cubic-bezier(.4,2,.6,1),
    box-shadow 0.35s cubic-bezier(.4,2,.6,1),
    transform 0.18s cubic-bezier(.4,2,.6,1),
    filter 0.35s cubic-bezier(.4,2,.6,1);
  outline: none;
  padding: 0;
}

#close-directory-btn svg {
  display: block;
  margin: auto;
  width: 22px;
  height: 22px;
  transition: stroke 0.3s cubic-bezier(.4,2,.6,1), filter 0.3s cubic-bezier(.4,2,.6,1);
}

#close-directory-btn:hover,
#close-directory-btn:focus-visible {
  background: linear-gradient(135deg, #e9e0c7 60%, #d6c6a1 100%);
  color: #333;
  box-shadow: 0 6px 24px 0 rgba(160, 140, 107, 0.22), 0 0 0 8px #f7f3e9cc;
  transform: scale(1.09);
  filter: blur(0.2px) brightness(1.04);
}

#close-directory-btn:hover svg,
#close-directory-btn:focus-visible svg {
  /* X icon 顏色漸變效果 */
  filter: drop-shadow(0 0 2px #fff6) drop-shadow(0 0 6px #d6c6a1cc);
  stroke: url(#close-x-gradient);
}

/* SVG 線性漸層定義（需在 HTML SVG 內加 <defs>） */

@media (max-width: 600px) {
  #side-directory-panel {
    max-width: 100vw;
    width: 100vw;
  }

}