* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  font-family:
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
  background: linear-gradient(135deg, #43389f 0%, #4ec6ca 100%);
  color: #fff;
  overflow: hidden;
  position: fixed;
  width: 100%;
  padding-top: var(--safe-area-top);
}

.app-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

.platform-header {
  text-align: center;
  padding: 0.5rem;
  flex-shrink: 0;
  margin-bottom: 2rem;
  position: relative;
}

/* 客服圖示容器樣式 */
.header-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  flex-wrap: nowrap;
}

/* 主要 Logo 樣式 */
.main-logo {
  max-width: 380px;
  width: 100%;
  height: auto;
  display: block;
  flex-shrink: 0;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.3));
}

/* 客服圖示樣式 */
.customer-service {
  width: 50px;
  height: 50px;
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.3s ease;
  flex-shrink: 0;
  box-shadow:
    0 0 12px rgba(255, 255, 255, 0.4),
    0 0 24px rgba(78, 198, 202, 0.3),
    0 0 36px rgba(67, 56, 159, 0.2);
  animation: glow-pulse 2s ease-in-out infinite alternate;
}

.customer-service:hover {
  transform: scale(1.1);
  box-shadow:
    0 0 18px rgba(255, 255, 255, 0.6),
    0 0 36px rgba(78, 198, 202, 0.5),
    0 0 54px rgba(67, 56, 159, 0.4);
}

.customer-service img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
}

/* 原有 Logo 樣式（備用） */
.platform-header img:not(.customer-service img) {
  max-width: 380px;
  width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.3));
}

@keyframes glow {
  0% {
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.5));
  }
  50% {
    filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.8));
  }
  100% {
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.5));
  }
}

/* 客服圖示光暈動畫 */
@keyframes glow-pulse {
  0% {
    box-shadow:
      0 0 10px rgba(255, 255, 255, 0.3),
      0 0 20px rgba(78, 198, 202, 0.2),
      0 0 30px rgba(67, 56, 159, 0.1);
  }
  100% {
    box-shadow:
      0 0 14px rgba(255, 255, 255, 0.5),
      0 0 28px rgba(78, 198, 202, 0.4),
      0 0 42px rgba(67, 56, 159, 0.3);
  }
}

.platform-subtitle {
  font-size: 0.7em;
  color: rgba(255, 255, 255, 0.8);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 0.3rem;
}

.content-area {
  position: relative;
  flex-grow: 1;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 1rem;
}

.books-view {
  height: 100%;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  max-width: 600px;
  margin: 0 auto;
  align-content: start;
  row-gap: 1rem;
  transition: transform 0.3s ease;
}

.books-view.shifted {
  transform: translateX(-100%);
}

.book-item {
  position: relative;
  width: 100%;
  max-width: 140px;
  margin: 0 auto;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.book-cover {
  width: 100%;
  padding-bottom: 130%;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  margin-bottom: 0.5rem;
}

.book-cover img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.book-title {
  font-size: 1em;
  font-weight: 600;
  text-align: center;
  width: 100%;
}

.book-item:active {
  transform: scale(0.95);
}

.lessons-panel {
  position: absolute;
  top: 0;
  right: -100%;
  width: 100%;
  height: 100%;
  backdrop-filter: blur(20px);
  border-radius: 20px;
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.lessons-panel.active {
  transform: translateX(-100%);
}

.panel-header {
  padding: 1rem;
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  background: linear-gradient(135deg, rgba(67, 56, 159, 0.8) 0%, rgba(78, 198, 202, 0.6) 100%);
  border-radius: 20px 20px 0 0;
}

.back-btn {
  padding: 0.8rem;
  margin-right: 0.8rem;
  font-size: 1.4em;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  transition: color 0.3s ease;
}

.panel-header h2 {
  font-size: 1.3em;
  font-weight: 800;
  background: linear-gradient(45deg, #fff, #4ec6ca);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.lessons-scroll {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
}

.lessons-list {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.lesson-item,
.review-item {
  width: 100%;
  padding: 1rem;
  border-radius: 15px;
  font-size: 1em;
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.lesson-item {
  justify-content: flex-start;
}

.review-item {
  justify-content: center;
}

.lesson-badge {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9em;
  font-weight: 600;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.lesson-title {
  flex-grow: 1;
  text-align: left;
  padding-left: 1rem;
  font-weight: 500;
  letter-spacing: 0.5px;
  color: #fff;
}

.review-container {
  display: flex;
  justify-content: flex-end;
  padding: 0.5rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  margin-top: 0.8rem;
  width: 100%;
}

.lesson-item:hover,
.review-item:hover {
  transform: translateX(5px);
  filter: brightness(1.1);
}

/* Book 1 Theme */
.lessons-panel[data-book="1"] .lesson-item {
  background: linear-gradient(135deg, rgba(67, 56, 159, 0.8) 0%, rgba(78, 198, 202, 0.6) 100%);
}
.lessons-panel[data-book="1"] .review-item {
  background: linear-gradient(135deg, rgba(67, 56, 159, 0.4) 0%, rgba(78, 198, 202, 0.2) 100%);
}

/* Book 2 Theme */
.lessons-panel[data-book="2"] .lesson-item {
  background: linear-gradient(135deg, rgba(22, 160, 133, 0.8) 0%, rgba(39, 174, 96, 0.6) 100%);
}
.lessons-panel[data-book="2"] .review-item {
  background: linear-gradient(135deg, rgba(22, 160, 133, 0.4) 0%, rgba(39, 174, 96, 0.2) 100%);
}

/* Book 3 Theme */
.lessons-panel[data-book="3"] .lesson-item {
  background: linear-gradient(135deg, rgba(230, 126, 34, 0.8) 0%, rgba(231, 76, 60, 0.6) 100%);
}
.lessons-panel[data-book="3"] .review-item {
  background: linear-gradient(135deg, rgba(230, 126, 34, 0.4) 0%, rgba(231, 76, 60, 0.2) 100%);
}

/* Book 4 Theme */
.lessons-panel[data-book="4"] .lesson-item {
  background: linear-gradient(135deg, rgba(155, 89, 182, 0.8) 0%, rgba(142, 68, 173, 0.6) 100%);
}
.lessons-panel[data-book="4"] .review-item {
  background: linear-gradient(135deg, rgba(155, 89, 182, 0.4) 0%, rgba(142, 68, 173, 0.2) 100%);
}

/* Book 5 Theme */
.lessons-panel[data-book="5"] .lesson-item {
  background: linear-gradient(135deg, rgba(41, 128, 185, 0.8) 0%, rgba(52, 152, 219, 0.6) 100%);
}
.lessons-panel[data-book="5"] .review-item {
  background: linear-gradient(135deg, rgba(41, 128, 185, 0.4) 0%, rgba(52, 152, 219, 0.2) 100%);
}

/* Book 6 Theme */
.lessons-panel[data-book="6"] .lesson-item {
  background: linear-gradient(135deg, rgba(202, 125, 138, 0.8) 0%, rgba(255, 192, 203, 0.6) 100%);
}
.lessons-panel[data-book="6"] .review-item {
  background: linear-gradient(135deg, rgba(255, 182, 193, 0.4) 0%, rgba(255, 192, 203, 0.2) 100%);
}

/* 鎖定狀態樣式 */
.book-item.locked {
  opacity: 0.7;
  cursor: not-allowed;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

.book-item.locked .book-cover {
  filter: grayscale(100%);
  transition: all 0.3s ease;
}

.book-item.locked:hover {
  transform: translateY(-2px);
}

.book-item.locked:hover::after {
  content: "尚未開放";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 8px;
  font-size: 0.9em;
  text-align: center;
  animation: slideUp 0.3s ease;
}

.lock-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2em;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(0, 0, 0, 0.5);
  padding: 15px;
  border-radius: 50%;
  animation: pulse 2s infinite;
  z-index: 2;
}

.lesson-item.locked {
  opacity: 0.7;
  cursor: not-allowed;
  position: relative;
  overflow: hidden;
  background: rgba(128, 128, 128, 0.3) !important;
  transition: all 0.3s ease;
}

.lesson-item.locked:hover {
  transform: translateX(0) !important;
  background: rgba(128, 128, 128, 0.4) !important;
}

.lesson-item.locked:hover::after {
  content: "課程尚未開放";
  position: absolute;
  top: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 5px 10px;
  border-radius: 0 15px 0 15px;
  font-size: 0.8em;
  animation: fadeIn 0.3s ease;
}

.lesson-item:not(.locked) {
  position: relative;
  overflow: hidden;
}

.lesson-item:not(.locked)::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  animation: shine 2s infinite;
}

/* 動畫效果 */
@keyframes pulse {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.1);
    opacity: 0.8;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes shine {
  0% {
    left: -100%;
  }
  20% {
    left: 100%;
  }
  100% {
    left: 100%;
  }
}

.book-item:not(.locked):hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.lesson-item:not(.locked):hover {
  transform: translateX(10px) !important;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* 響應式媒體查詢 */
@media (max-width: 360px) {
  .platform-header {
    padding: 0.3rem;
  }

  .main-logo,
  .platform-header img {
    max-width: 200px;
  }

  .header-content {
    gap: 1rem;
  }

  .customer-service {
    width: 40px;
    height: 40px;
    box-shadow:
      0 0 8px rgba(255, 255, 255, 0.3),
      0 0 16px rgba(78, 198, 202, 0.2),
      0 0 24px rgba(67, 56, 159, 0.1);
  }

  .customer-service:hover {
    box-shadow:
      0 0 12px rgba(255, 255, 255, 0.5),
      0 0 24px rgba(78, 198, 202, 0.4),
      0 0 36px rgba(67, 56, 159, 0.3);
  }

  .books-view {
    gap: 0.3rem;
    row-gap: 0.8rem;
  }

  .book-item {
    max-width: 120px;
  }

  .app-container {
    padding: 0.5rem;
  }

  .content-area {
    padding: 0.5rem;
  }

  .lesson-item,
  .review-item {
    padding: 0.8rem;
  }

  .lesson-badge {
    width: 24px;
    height: 24px;
    font-size: 0.8em;
  }
}

@media (max-width: 480px) {
  .header-content {
    gap: 1.5rem;
  }

  .main-logo,
  .platform-header img {
    max-width: 250px;
  }

  .customer-service {
    width: 35px;
    height: 35px;
    box-shadow:
      0 0 10px rgba(255, 255, 255, 0.3),
      0 0 20px rgba(78, 198, 202, 0.2),
      0 0 30px rgba(67, 56, 159, 0.1);
  }

  .customer-service:hover {
    box-shadow:
      0 0 15px rgba(255, 255, 255, 0.5),
      0 0 30px rgba(78, 198, 202, 0.4),
      0 0 45px rgba(67, 56, 159, 0.3);
  }
}

@media (min-width: 768px) {
  .books-view {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ===== Footer 與 版權聲明滑出面板 ===== */
.site-footer {
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  padding: 12px 16px;
  text-align: center;
  font-size: 0.9em;
}

.site-footer .footer-link {
  margin-left: 8px;
  background: transparent;
  border: 0;
  color: #fff;
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}

/* 從頁尾往上滑出的面板 */
.copyright-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: -100%;
  background: #fff;
  color: #333;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.25);
  transition: bottom 0.35s ease-out;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  z-index: 999;
  max-height: 80vh;
  overflow-y: auto;
}

.copyright-panel.active {
  bottom: 0;
}

.copyright-panel .panel-content {
  padding: 20px;
  max-width: 800px;
  margin: auto;
  line-height: 1.7;
}

.copyright-panel h3 {
  margin-top: 0;
}

.copyright-panel .close-btn {
  position: absolute;
  right: 16px;
  top: 10px;
  border: 0;
  background: transparent;
  font-size: 26px;
  cursor: pointer;
  color: #333;
}

/* ===================== */
/* ===== Overrides ===== */
/* ===================== */

/* iPhone Safari 可視高度 & 底部安全區修正 */
body {
  height: 100dvh !important;
  height: calc(100dvh - var(--safe-area-top) - var(--safe-area-bottom)) !important;
  padding-bottom: 0 !important;
}

/* 讓 footer 穩定貼底，並避開底部安全區 */
.site-footer {
  margin-top: auto;
  position: relative;
  z-index: 2;
  padding-bottom: calc(12px + var(--safe-area-bottom));

  margin-left: -1rem;
  margin-right: -1rem;
  border-radius: 0;
}

@media (max-width: 360px) {
  .site-footer {
    margin-left: -0.5rem;
    margin-right: -0.5rem;
  }
}

/* 客服 ICON：行動版放大 + 右側安全邊距 + 觸控熱區 */
.header-content .customer-service {
  width: clamp(56px, 12vw, 64px) !important;
  height: clamp(56px, 12vw, 64px) !important;
  margin-right: calc(env(safe-area-inset-right, 0px) + 16px);
  padding: 4px;
}

/* LOGO 與 客服 ICON 間距（更寬鬆，含自適應）*/
.header-content {
  gap: clamp(1.5rem, 6vw, 3rem) !important;
}

/* 針對極窄螢幕再微調 */
@media (max-width: 480px) {
  .header-content .customer-service {
    width: 56px !important;
    height: 56px !important;
  }
  .content-area {
    margin-bottom: clamp(14px, 2.5vh, 24px) !important;
  }
}
