:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent: #f59e0b;
  --accent-light: #fbbf24;
  --accent-glow: rgba(245, 158, 11, 0.25);
  --danger: #ef4444;
  --success: #10b981;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  --safe-bottom: env(safe-area-inset-bottom, 16px);
  --safe-top: max(env(safe-area-inset-top, 0px), 50px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "Noto Sans TC", sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

/* 純手機容器限制，無論在哪裡開啟都維持標準手機手感比例 */
.mobile-container {
  width: 100%;
  max-width: 440px;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-primary);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  padding-bottom: calc(var(--safe-bottom) + 80px);
}

/* 頂部手機標題列 (純淨原生 DOM 排版，杜絕 GPU 合成圖層次像素失真) */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  width: 100%;
  padding-top: max(env(safe-area-inset-top, 0px), 44px);
  padding-bottom: 8px;
  padding-left: 20px;
  padding-right: 20px;
  background: var(--bg-primary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo-img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(245, 158, 11, 0.3);
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

.header-titles .app-title {
  font-size: 19px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
  -webkit-font-smoothing: antialiased;
}

.header-titles .app-subtitle {
  font-size: 11px;
  color: var(--accent);
  display: block;
}

.icon-btn {
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, color 0.15s;
}

.icon-btn:hover {
  color: #fff;
}

.icon-btn:active {
  transform: scale(0.92);
  background: #334155;
}

/* 主視圖容器與面板 */
.app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.view-panel {
  display: none;
  flex-direction: column;
  padding: 16px 20px;
  flex: 1;
  min-height: calc(100vh - 120px);
  animation: fadeIn 0.15s ease-out;
}

.view-panel.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* 書架 Banner */
.shelf-banner {
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  border: 1px solid rgba(245, 158, 11, 0.2);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}

.banner-badge {
  display: inline-block;
  background: var(--accent);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  margin-bottom: 8px;
}

.shelf-banner h2 {
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 6px;
  color: #fff;
}

.shelf-banner p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* 列表標題行 */
.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.section-title-row h3 {
  font-size: 17px;
  font-weight: 700;
}

.badge {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 2px 10px;
  border-radius: var(--radius-full);
}

/* 書籍列表卡片 */
.books-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.book-card {
  display: flex;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 12px;
  gap: 14px;
  align-items: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s, border-color 0.15s;
}

.book-card:active {
  transform: scale(0.98);
  border-color: var(--accent);
}

.book-cover-thumb {
  width: 72px;
  height: 96px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: #334155;
  flex-shrink: 0;
}

.book-cover-placeholder {
  width: 72px;
  height: 96px;
  border-radius: var(--radius-sm);
  background: #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  flex-shrink: 0;
}

.book-info {
  flex: 1;
  min-width: 0;
}

.book-info h4 {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.book-info .book-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.book-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-play-mini {
  background: var(--accent);
  color: #000;
  border: none;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.btn-delete-mini {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.08);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-delete-mini:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}

.book-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #475569;
  background: #1e293b;
}

/* 空白狀態 */
.empty-placeholder {
  text-align: center;
  padding: 48px 24px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px dashed rgba(255, 255, 255, 0.12);
}

.empty-icon-svg {
  color: #475569;
  margin-bottom: 14px;
}

.empty-placeholder p {
  color: #fff;
  font-weight: 600;
  margin-bottom: 6px;
}

.empty-placeholder .empty-hint {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
  line-height: 1.6;
}

/* 大拇指操作熱區 (固定置底懸浮按鍵) */
.thumb-action-zone {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: 100%;
  max-width: 440px;
  padding: 16px 20px calc(var(--safe-bottom) + 8px);
  background: linear-gradient(to top, rgba(15, 23, 42, 0.98) 60%, rgba(15, 23, 42, 0) 100%);
  z-index: 40;
}

.btn-primary-large {
  width: 100%;
  height: 56px;
  background: linear-gradient(135deg, var(--accent) 0%, #ea580c 100%);
  color: #000;
  border: none;
  border-radius: var(--radius-full);
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 24px var(--accent-glow);
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn-primary-large:active:not(:disabled) {
  transform: scale(0.96);
}

.btn-primary-large:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

/* 建立新繪本頁面頂部導航列 (iOS 標準單一獨立頂欄，徹底消除雙表頭堆疊失衡) */
#view-uploader {
  padding-top: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  width: 100%;
  padding-top: max(env(safe-area-inset-top, 0px), 44px);
  padding-bottom: 12px;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.btn-back-nav {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px 8px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-back-nav svg {
  color: var(--accent);
  transition: transform 0.15s ease;
}

.btn-back-nav:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.15);
}

.panel-title {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-align: center;
  flex: 1;
  letter-spacing: 0.5px;
}

.panel-header-spacer {
  width: 98px;
  flex-shrink: 0;
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 22px;
  margin-bottom: 24px;
}

.photo-shoot-box {
  background: var(--bg-secondary);
  border: 2px dashed rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-lg);
  padding: 24px 16px;
  text-align: center;
}

.shoot-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-shoot {
  height: 52px;
  background: #fff;
  color: #000;
  border: none;
  border-radius: var(--radius-full);
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

.btn-shoot:active {
  transform: scale(0.96);
  background: #f1f5f9;
}

.btn-secondary {
  height: 44px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: none;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.shoot-tip {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 14px;
}

/* 預覽照片標題列與清空按鈕 */
.preview-section {
  margin-bottom: 24px;
}

.preview-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 0 4px;
}

.preview-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-title-text {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.3px;
}

.preview-count-pill {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent);
  border: 1px solid rgba(245, 158, 11, 0.3);
  font-size: 12px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: var(--radius-full);
}

.btn-clear-ghost {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #f87171;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-clear-ghost:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.btn-clear-ghost:active {
  transform: scale(0.95);
  background: rgba(239, 68, 68, 0.3);
}

.clear-icon {
  font-size: 12px;
}

/* 照片縮圖網格 */
.photo-preview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.photo-thumb-item {
  position: relative;
  aspect-ratio: 3/4;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #1e293b;
}

.photo-thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-page-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

.thumb-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(239, 68, 68, 0.9);
  color: #fff;
  border: none;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* 進度條提示 */
.progress-box {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.progress-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(245, 158, 11, 0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress-info h4 {
  font-size: 14px;
  color: #fff;
  margin-bottom: 2px;
}

.progress-info p {
  font-size: 12px;
  color: var(--accent-light);
}

/* 伴讀播放器畫面 (iOS 標準單一獨立頂欄) */
#view-player {
  padding-top: 0;
}

.player-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--safe-bottom) - 20px);
  justify-content: space-between;
}

.player-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: max(env(safe-area-inset-top, 0px), 44px);
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.icon-btn-round {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.player-top-spacer {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.player-speed-btn {
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  user-select: none;
}

.player-speed-btn:active {
  transform: scale(0.92);
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.player-title-box {
  text-align: center;
  flex: 1;
  padding: 0 10px;
}

.player-title {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-page-badge {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}

/* 雙語切換條 */
.bilingual-switch-bar {
  display: flex;
  background: var(--bg-secondary);
  padding: 3px;
  border-radius: var(--radius-full);
  margin-bottom: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.bilingual-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 0;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s;
}

.bilingual-btn.active {
  background: var(--accent);
  color: #000;
  font-weight: 700;
}

/* 播放狀態列 (細緻呼吸指示燈) */
.player-status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 4px 12px;
}

.status-pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: all 0.3s ease;
}

.status-pulse-dot.playing {
  background: #10b981;
  box-shadow: 0 0 10px #10b981, 0 0 20px rgba(16, 185, 129, 0.5);
  animation: pulseDot 1.5s infinite;
}

@keyframes pulseDot {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.player-status-tag {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.5px;
}

.player-wakelock-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #10b981;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.28);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  letter-spacing: 0.3px;
  margin-left: 4px;
  transition: opacity 0.3s ease;
}

.player-wakelock-badge svg {
  display: block;
}

/* 核心主角：直接呈現的故事內文卡片 (不隱藏、閱讀最佳體驗) */
.story-content-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: rgba(30, 41, 59, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 18px 20px;
  margin-bottom: 16px;
  min-height: 220px;
  max-height: calc(100vh - 290px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.story-content-card.reading {
  border-color: rgba(245, 158, 11, 0.45);
  box-shadow: 0 10px 35px rgba(245, 158, 11, 0.12), 0 4px 20px rgba(0, 0, 0, 0.4);
}

.story-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.story-card-page-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent);
  border: 1px solid rgba(245, 158, 11, 0.3);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  letter-spacing: 0.5px;
}

.btn-edit-text-mini {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-edit-text-mini:hover,
.btn-edit-text-mini:active {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
}

.story-text-viewport {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 6px;
}

/* 自訂滑順卷軸 */
.story-text-viewport::-webkit-scrollbar {
  width: 4px;
}
.story-text-viewport::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.story-reading-text {
  font-size: 19px;
  line-height: 1.85;
  color: #f8fafc;
  font-weight: 400;
  letter-spacing: 0.6px;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
}

/* 雙語卡片排版 */
.bilingual-story-box {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.bilingual-en-block {
  font-size: 19px;
  line-height: 1.7;
  color: #fbbf24;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-weight: 500;
  letter-spacing: 0.3px;
  white-space: pre-wrap;
  word-break: break-word;
}

.bilingual-divider {
  width: 100%;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
}

.bilingual-zh-block {
  font-size: 18px;
  line-height: 1.8;
  color: #e2e8f0;
  font-weight: 400;
  letter-spacing: 0.6px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 翻頁倒數條 */
.auto-page-timer-container {
  margin-bottom: 14px;
}

.timer-label {
  font-size: 12px;
  color: var(--accent-light);
  margin-bottom: 4px;
  text-align: center;
  font-weight: 600;
}

.timer-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width 0.1s linear;
}

/* 底部大拇指播放控制三鍵 */
.player-controls-zone {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: var(--safe-bottom);
}

.player-nav-btn {
  flex: 1;
  height: 64px;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.player-nav-btn:active {
  transform: scale(0.94);
  background: #334155;
}

.player-nav-btn svg {
  color: var(--accent);
  transition: transform 0.15s ease;
}

.player-nav-btn:active svg {
  transform: scale(0.9);
}

.nav-text {
  font-size: 12px;
  font-weight: 600;
  color: #e2e8f0;
  margin-top: 2px;
}

.player-main-btn {
  width: 76px;
  height: 76px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent) 0%, #ea580c 100%);
  border: none;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px var(--accent-glow);
  cursor: pointer;
  transition: transform 0.15s;
}

.player-main-btn span {
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-main-btn:active {
  transform: scale(0.92);
}

/* Modal 彈窗樣式 (標準 iOS Bottom Sheet 抽屜架構) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-top: calc(env(safe-area-inset-top, 24px) + 20px);
  overflow: hidden;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: calc(100dvh - env(safe-area-inset-top, 24px) - 36px);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.6);
  padding: 0;
  overflow: hidden;
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
}

.icon-btn-close {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn-close:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
}

.modal-footer {
  padding: 14px 20px calc(var(--safe-bottom) + 14px);
  background: var(--bg-secondary);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-group label {
  font-size: 14px;
  font-weight: 600;
  color: #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.label-hint {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
}

.form-input, .form-select, .form-textarea {
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-md);
  color: #fff;
  padding: 13px 16px;
  font-size: 15px;
  outline: none;
  width: 100%;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  background: #0f172a;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}

.input-tip {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-actions-row {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.modal-actions-row button {
  flex: 1;
}

.btn-primary {
  width: 100%;
  height: 48px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius-full);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary:active {
  transform: scale(0.97);
}

/* 語言選擇器 Pill Group */
.lang-selector-group {
  display: flex;
  background: var(--bg-primary);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.12);
  gap: 6px;
  margin-top: 4px;
}

.lang-pill {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.lang-pill.active {
  background: var(--accent);
  color: #000;
  font-weight: 700;
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* 設定面板獨立語音設定區塊 */
.settings-voice-section {
  background: rgba(15, 23, 42, 0.6);
  border-radius: var(--radius-md);
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-test-mini {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  align-self: flex-start;
  margin-top: 6px;
  transition: background 0.15s;
}

.btn-test-mini:active {
  background: rgba(255, 255, 255, 0.25);
}

.upload-rules-tip {
  margin-top: 14px;
  background: rgba(245, 158, 11, 0.08);
  border: 1px dashed rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-rules-tip p {
  font-size: 12px;
  color: #e2e8f0;
  line-height: 1.5;
}

.thumb-cover-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: var(--accent);
  color: #000;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
}

/* ========================================================
   家庭守護通行門 (Family Gate) 視覺樣式
   ======================================================== */
.gate-card-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  max-width: 380px;
  margin: auto;
  min-height: calc(100vh - 120px);
}

.gate-logo-badge {
  width: 88px;
  height: 88px;
  margin-bottom: 24px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4), 0 0 30px rgba(245, 158, 11, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.gate-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gate-title {
  font-size: 24px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.gate-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 32px;
}

.gate-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gate-input-box {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  background: rgba(30, 41, 59, 0.85);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  padding: 0 16px;
  transition: all 0.25s ease;
}

.gate-input-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2);
  background: rgba(30, 41, 59, 0.98);
}

.gate-input-box.shake {
  animation: gateShake 0.45s ease-in-out;
  border-color: #ef4444;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.2);
}

@keyframes gateShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.gate-lock-icon {
  color: var(--text-secondary);
  margin-right: 12px;
  flex-shrink: 0;
}

.gate-pin-input {
  width: 100%;
  height: 52px;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  outline: none;
  letter-spacing: 2px;
}

.gate-pin-input::placeholder {
  color: rgba(255, 255, 255, 0.35);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
}

.btn-toggle-eye {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: color 0.2s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.btn-toggle-eye:active {
  color: #fff;
  transform: scale(0.92);
}

.gate-error-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #f87171;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-top: -4px;
}

.gate-btn-submit {
  width: 100%;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  border-radius: var(--radius-md);
  margin-top: 8px;
  box-shadow: 0 8px 25px rgba(245, 158, 11, 0.3);
}

.gate-footer-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 28px;
  line-height: 1.4;
}

/* 全域 Toast 通知 */
.app-toast {
  position: fixed;
  top: calc(var(--safe-top) + 16px);
  left: 16px;
  right: 16px;
  max-width: 400px;
  margin: 0 auto;
  z-index: 99999;
  pointer-events: none;
  animation: toastSlideDown 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(245, 158, 11, 0.4);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 0 15px rgba(245, 158, 11, 0.2);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  pointer-events: auto;
}

.app-toast.error .toast-content {
  border-color: rgba(239, 68, 68, 0.6);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 0 15px rgba(239, 68, 68, 0.25);
}

.app-toast.error .toast-icon {
  color: #ef4444;
}

.app-toast.warning .toast-icon {
  color: #f59e0b;
}

.toast-icon {
  flex-shrink: 0;
}

.toast-text {
  flex: 1;
}

@keyframes toastSlideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.app-toast.fade-out {
  animation: toastFadeOut 0.35s ease forwards;
}

@keyframes toastFadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-15px);
  }
}

/* 全螢幕 AI 處理中沉浸遮罩 */
.ai-processing-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 25, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 99990;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.25s ease-out;
}

.ai-processing-card {
  width: 100%;
  max-width: 340px;
  background: rgba(30, 41, 59, 0.95);
  border: 1.5px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: 0 20px 45px -10px rgba(0, 0, 0, 0.7), 0 0 30px rgba(245, 158, 11, 0.15);
}

.ai-spinner-halo {
  position: relative;
  width: 84px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.ai-halo-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3.5px solid rgba(245, 158, 11, 0.18);
  border-top-color: var(--accent);
  border-right-color: #fbbf24;
  animation: spin 1s cubic-bezier(0.55, 0.15, 0.45, 0.85) infinite;
}

.ai-halo-logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.ai-modal-title {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}

.ai-modal-step {
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 22px;
  min-height: 20px;
}

.ai-progress-track {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}

.ai-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
  border-radius: 999px;
  transition: width 0.35s ease;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.6);
}

.ai-progress-percent-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 20px;
  font-weight: 500;
}

#ai-progress-percent {
  color: #fff;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ai-loading-tip-card {
  width: 100%;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.4;
  text-align: left;
}

.ai-loading-tip-card svg {
  flex-shrink: 0;
  color: var(--accent);
}



