/* ==========================================================================

   1. 基礎重設與滿版暗色舞台 (Reset & Stage)

   ========================================================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}


body {
    background-color: #f0f0f0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    font-family: 'Noto Serif TC', -apple-system, serif;
    -webkit-font-smoothing: antialiased;
}

/* ==========================================================================

   2. Navbar

   ========================================================================== */

.navbar {
  background-color: #33333333;
  overflow: visible;
  position: fixed;
  top: 0;
  left: 0;  
  width: 100%;
  z-index: 999; /* 確保導覽列永遠在最上層 */
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0; /* 移除原本會導致歪斜的 padding-left */
  margin: 0;
}


.navbar a {
  /* float: left; */
  display: block;
  color: #f2f2f2;
  background-color:#005C00;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 16px;
}


.navbar a:hover {
  background-color: #04AA6D;
  color: black;
}


.navbar a.active {
  background-color: #04AA6D;
  color: white;
}


/* ==========================================================================

   3. Dropdown

   ========================================================================== */

/* 1. 讓選單容器跟著 Navbar 連結一起往左排隊 */

.dropdown {
  /* float: left; */
  position: relative; /* 作為內部選單向上定位的基準點 */
}


/* 2. 觸發按鈕的樣式 */
.dropdown .dropbtn {
  font-size: 16px;    
  border: none;
  outline: none;
  color: #fff;
  padding: 14px 16px;
  background-color: #996E00;
  font-family: inherit;
  margin: 0;
  cursor: pointer;
}

/* 按鈕滑入時的變色*/

.dropdown:hover .dropbtn {
  background-color: darkorange;
  color: black;
}


/* 3. 向下彈出的選單內容方塊 */

.dropdown .dropdown-content {
  display: none;       /* 預設隱藏 */
  position: absolute;
  background-color: #f2f2f2;
  min-width: 110px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); /* 陰影往下投射 */
  left: 0;
}



/* 4. 彈出選單內部的每一個超連結樣式 */

.dropdown .dropdown-content a {
  color: black;
  background-color: #f2f2f2;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  float:none;
  text-align: left;
}



/* 選單內部超連結的 Hover 變色 */

.dropdown .dropdown-content a:hover {
  background-color: #ddd;
  color: black;
}



/* 5. 觸發機制：當滑鼠移入 .dropdown 容器時，立刻展現選單 */

.dropdown:hover .dropdown-content {
  display: block;
}




/* ==========================================================================

   4. 3D 書本容器與核心旋轉軸心

   ========================================================================== */

:root {
    /* 1. 定義你心目中「最完美、最漂亮」的書本基本尺寸（雙頁展開） */
    --base-width: 1448px;
    --base-height: 1024px;
}



   .book-container {
    position: relative;
    aspect-ratio: 16 / 10;
    /* 固定書頁展開比例 */
    width: var(--base-width);
    height: var(--base-height);
    --scale: min(var(--scale-x), var(--scale-y), 1);
    /* RWD */
    --scale-x: calc(95dvw / var(--base-width));
    --scale-y: calc(80dvh / var(--base-height));
    /* 設定與視窗邊界 */
    transform: scale(var(--scale));
    transform-origin: center center;
    transition: transform 0.3s ease;
    perspective: none;
     /* 3D 縱深感（數值越小，翻頁透視誇張感越強） */
     margin-top: 3rem;
     margin-bottom: 1rem;
     margin-right: auto;
     margin-left: auto;

    }


.book {
    width: 50%;  
    /* 初始為單頁寬度，立在中央  */
    height: 100%;
    position: relative;
    margin-left: auto;
    margin-right: auto;
    /* transform-style: preserve-3d; */
    transform: translateX(50%);  
    /* 書軸置中：將中央軸線移到舞台正中間  */
    transition: transform 1s cubic-bezier(0.25, 1, 0.5, 1); 
}


/* ==========================================================================

   5. 書頁層疊與正反面 (3D Flipbook Core)

   ========================================================================== */


.front-page, .back-page {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    backface-visibility: hidden; /* 翻轉到背面時，隱藏正面，防止穿透錯亂 */
    overflow: hidden;
}



/* 右頁正面：向內投影，模擬書溝 */

.front-page {
    box-shadow: inset -50px 0 10px rgba(0,0,0,0.35), 5px 0 15px rgba(133, 133, 133, 0.3);
}



/* 左頁背面：必須先水平翻轉 180 度，並向左投影模擬書溝 */

.back-page {
    transform: rotateY(180deg);
    box-shadow: inset 50px 0 10px rgba(0,0,0,0.35), -5px 0 15px rgba(133, 133, 133, 0.3);
}



.front-page img, .back-page img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* 照片完美滿版且不變形 */
}


img {
    opacity: 0;
    transition: opacity 0.2s ease;
}
img.is-decoded {
    opacity: 1;
}


/* 插入空白頁 */

.text-content-page {
    background-color: #ffffff;
    color: #1a1a1a;
    height: 100% ;
}

/* ==========================================================================

   6. 核心 CSS 跨頁語法 (Two-Page Spread Engine)

   ========================================================================== */

.page {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    cursor: pointer;
    pointer-events: none;
    transform-origin: left center;
    transform-style: preserve-3d;
}

.page.is-layered {

    transition: transform 1.1s cubic-bezier(0.25, 1, 0.5, 1);
}

.page.flipped {
    transform: rotateY(-180deg);
}

.spread-page {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;

}

.spread-page img {
    /* 💡 核心修正 1：寬度必須是容器的 2 倍，這樣 object-position 才有空間進行 50% 的對切 */
    width: 200% !important; 
    height: 100% !important;
    object-fit: cover !important;
    position: absolute;
    top: 0;
    will-change: transform;
    transition: opacity 0.4s ease-in-out;
    transform: translateZ(0); 
}


/* 跨頁圖片的左半邊：讓兩倍寬的大圖貼齊左側，右邊多出的 50% 自動被 overflow: hidden 閹割 */
.spread-left img {
    left: 0 !important;
    object-position: left center !important;
}

/* 跨頁圖片的右半邊：讓兩倍寬的大圖貼齊右側，左邊多出的 50% 自動被 overflow: hidden 閹割 */
.spread-right img {
    right: 0 !important;
    object-position: right center !important; 
}



/* ==========================================================================

   7. 箭頭固定在書本外側

   ========================================================================== */

.nav-arrow {
    position: absolute;
    top: 0;
    margin: 0;
    padding-top: 30%;
    width: 60px;
    height: 100%;
    background-color: rgba(255, 255, 255, 0);
    color: #cacaca;
    font-family: -apple-system, sans-serif;
    font-size: 40px;
    text-align: center;
    user-select: none;
    cursor: pointer;
    z-index: 10;
    /* backdrop-filter: blur(4px);  */
    transition: background-color 0.3s, transform 0.3s, opacity 0.3s, left 0.5s cubic-bezier(0.25, 1, 0.5, 1);
    opacity: 0.5;

}


.nav-arrow:hover {
    background-color: rgba(255, 255, 255, 0.3);
    color: #333;
    opacity: 1;
}


/* 右頁的右箭頭：強制推到容器寬度 (100%) 再往右加 20px 的外側位置 */

.next-arrow {
    left: calc(100% + 0px);
}



/* 左頁的左箭頭：強制推到容器起點 (0) 再往左扣掉自身寬度與 20px 的外側位置 */

.prev-arrow {
    left: calc(0% - 60px - 0px);
}




/* ==========================================================================

   8. 可點選進度條 (Custom Range input)

   ========================================================================== */

.progress-wrapper {
    position: absolute;
    bottom: -3rem;    /* 固定在書本外容器下方 */
    left: 10%;
    width: 80%;
    height: 20px;     /* 稍微加大，讓滑鼠更好點擊 */
    display: flex;
    align-items: center;
    z-index: 10;
}

#bookProgress {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 5px;       /* 軌道粗細 */
    background: rgba(0, 0, 0, 0.1); /* 軌道顏色 */
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

/* 美化滑動的小圓鈕 (Chrome, Safari, Opera, Edge) */
#bookProgress::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: #990000; 
    cursor: pointer;
    transition: transform 0.1s ease;
}

#bookProgress::-webkit-slider-thumb:hover {
    transform: scale(1.5); /* 滑鼠懸停時微放大 */
}



@media (max-width: 768px) {

    .book-container {
        /* 手機版可以讓它稍微貼邊一點 */
        --scale-x: calc(90dvw / var(--base-width));
        --scale-y: calc(80dvh / var(--base-height));
     margin-top: 4rem;
     margin-bottom: 2rem;
     margin-right: auto;
     margin-left: auto;
    }

.navbar {
    background-color: #222222;
    justify-content: space-around;
  }


  .navbar a, .dropdown .dropbtn {
    padding: 14px 10px;
    font-size: 14px;
    flex: 1;
    text-align: center;
  }


  .dropdown {
    flex: 1;
    display: flex;
  }


  .dropdown .dropbtn {
    width: 100%;
  }


  .dropdown .dropdown-content {
    min-width: 100%;
    top: 3rem;
  }


.progress-wrapper {
        bottom: -3rem;
        left: 5%;
        width: 90%;
    }


/* 美化滑動的小圓鈕 (Chrome, Safari, Opera, Edge) */
#bookProgress::-webkit-slider-thumb {
    width: 3rem;
    height: 3rem;
}




}
