/**
 * 前台響應式強化樣式表
 * Frontend Responsive Enhancement Stylesheet
 *
 * 專為前台所有頁面（遊戲模組、語音讀經模組等）提供完整的響應式支援
 * 支援從極小螢幕 (320px) 到大螢幕 (1440px+)
 */

/* ===== CSS 變數 ===== */
:root {
  /* 安全區域 */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);

  /* 觸摸目標最小尺寸 */
  --touch-target-min: 44px;

  /* 響應式間距 */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 16px;
  --spacing-xl: 20px;
  --spacing-2xl: 24px;
  --spacing-3xl: 32px;

  /* 響應式字體 */
  --font-xs: 11px;
  --font-sm: 13px;
  --font-base: 15px;
  --font-lg: 17px;
  --font-xl: 20px;
  --font-2xl: 24px;
  --font-3xl: 28px;

  /* 底部導航高度 */
  --bottom-nav-height: 60px;
}

/* ===== 基礎響應式重置 ===== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: -webkit-fill-available;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

/* ===== 通用容器 ===== */
.frontend-container {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding-left: var(--spacing-lg);
  padding-right: var(--spacing-lg);
  padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + var(--spacing-lg));
}

/* ===== 全局觸摸優化 ===== */
@media (hover: none) and (pointer: coarse) {
  /* 觸摸設備最小點擊區域 */
  button,
  a,
  [role="button"],
  [onclick],
  input[type="checkbox"],
  input[type="radio"],
  select,
  .clickable,
  .game-card,
  .mode-card,
  .option-btn,
  .nav-btn {
    min-height: var(--touch-target-min);
  }

  /* 防止 iOS 輸入框縮放 */
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  /* 禁用不必要的觸摸高亮 */
  * {
    -webkit-tap-highlight-color: transparent;
  }

  /* 觸摸反饋 */
  .touch-feedback:active {
    opacity: 0.85;
    transform: scale(0.98);
  }
}

/* ===== 極小螢幕 (320px 以下) ===== */
@media screen and (max-width: 319px) {
  :root {
    --font-xs: 10px;
    --font-sm: 11px;
    --font-base: 13px;
    --font-lg: 15px;
    --font-xl: 17px;
    --font-2xl: 20px;
    --spacing-lg: 12px;
  }

  .frontend-container {
    padding-left: var(--spacing-md);
    padding-right: var(--spacing-md);
  }

  /* 遊戲卡片網格 */
  .game-grid,
  .mode-grid,
  .quick-start {
    gap: 8px !important;
  }

  .game-card,
  .mode-card {
    padding: 12px 10px !important;
  }

  .game-card h3,
  .mode-card h3 {
    font-size: 13px !important;
  }

  .game-card p,
  .mode-card p {
    font-size: 10px !important;
  }

  .game-icon,
  .mode-icon {
    font-size: 24px !important;
    width: 48px !important;
    height: 48px !important;
  }

  /* 統計網格 */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
}

/* ===== 超小螢幕 (320px - 359px) ===== */
@media screen and (min-width: 320px) and (max-width: 359px) {
  :root {
    --font-base: 14px;
    --spacing-lg: 14px;
  }

  .frontend-container {
    padding-left: var(--spacing-md);
    padding-right: var(--spacing-md);
  }

  h1, .page-title {
    font-size: var(--font-xl) !important;
  }

  /* 遊戲網格調整 */
  .game-grid,
  .mode-grid {
    gap: 10px !important;
  }

  /* 底部導航五欄版本 */
  .bottom-nav .nav-btn span:last-child,
  .bottom-nav-5 .bottom-nav-item span:not(.icon) {
    font-size: 9px !important;
  }
}

/* ===== 小螢幕手機 (360px - 389px) ===== */
@media screen and (min-width: 360px) and (max-width: 389px) {
  :root {
    --font-base: 14px;
    --spacing-lg: 14px;
  }

  .frontend-container {
    max-width: 360px;
  }

  /* 兩欄網格保持 */
  .game-grid,
  .mode-grid,
  .quick-start {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}

/* ===== 標準手機 (390px - 414px) - iPhone 12/13/14 ===== */
@media screen and (min-width: 390px) and (max-width: 414px) {
  :root {
    --font-base: 15px;
    --spacing-lg: 16px;
  }

  .frontend-container {
    max-width: 414px;
  }

  .game-grid,
  .mode-grid,
  .quick-start {
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
  }
}

/* ===== 大螢幕手機 (415px - 479px) - iPhone Plus/Max ===== */
@media screen and (min-width: 415px) and (max-width: 479px) {
  :root {
    --font-base: 15px;
    --spacing-lg: 18px;
  }

  .frontend-container {
    max-width: 480px;
  }

  .game-grid,
  .mode-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
}

/* ===== 平板直向 (480px - 767px) ===== */
@media screen and (min-width: 480px) and (max-width: 767px) {
  :root {
    --font-base: 16px;
    --spacing-lg: 20px;
  }

  .frontend-container {
    max-width: 600px;
    padding-left: var(--spacing-xl);
    padding-right: var(--spacing-xl);
  }

  /* 遊戲網格可以 2-3 欄 */
  .game-grid,
  .mode-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
  }

  /* 快速開始可以三欄 */
  .quick-start {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  /* 統計網格 4 欄 */
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ===== 平板橫向 / 小桌面 (768px - 1023px) ===== */
@media screen and (min-width: 768px) and (max-width: 1023px) {
  :root {
    --font-base: 16px;
    --spacing-lg: 24px;
  }

  .frontend-container {
    max-width: 720px;
    padding-left: var(--spacing-2xl);
    padding-right: var(--spacing-2xl);
  }

  /* 遊戲網格三欄 */
  .game-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }

  .mode-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }

  /* 快速開始兩欄 */
  .quick-start {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }

  /* 底部導航可以隱藏或居中 */
  .bottom-nav {
    max-width: 600px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 20px 20px 0 0;
  }
}

/* ===== 桌面 (1024px+) ===== */
@media screen and (min-width: 1024px) {
  :root {
    --font-base: 16px;
    --spacing-lg: 28px;
  }

  /* 桌面版確保垂直捲動正常 */
  html, body {
    overflow-y: auto !important;
    overflow-x: hidden;
    height: auto;
  }

  .frontend-container {
    max-width: 900px;
    padding-left: var(--spacing-3xl);
    padding-right: var(--spacing-3xl);
  }

  /* 遊戲網格三到四欄 */
  .game-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
  }

  .mode-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
  }

  /* 快速開始三欄 */
  .quick-start {
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
  }

  /* 桌面隱藏底部導航 */
  .bottom-nav,
  .mobile-bottom-nav {
    display: none !important;
  }

  /* 移除底部導航的間距 */
  .frontend-container {
    padding-bottom: var(--spacing-3xl);
  }
}

/* ===== 大桌面 (1440px+) ===== */
@media screen and (min-width: 1440px) {
  .frontend-container {
    max-width: 1200px;
  }
}

/* ===== 橫向模式特殊處理 ===== */
@media screen and (max-height: 500px) and (orientation: landscape) {
  :root {
    --bottom-nav-height: 50px;
  }

  .bottom-nav {
    padding-top: 6px;
    padding-bottom: calc(6px + var(--safe-area-bottom));
  }

  .bottom-nav .nav-btn,
  .bottom-nav-item {
    height: 44px !important;
  }

  .bottom-nav .nav-btn span:first-child,
  .bottom-nav-item .icon {
    font-size: 18px !important;
  }

  /* 遊戲頁面橫向時卡片可以更小 */
  .game-card,
  .mode-card {
    padding: 12px !important;
  }

  /* 統計卡片壓縮 */
  .stat-card,
  .stat-item {
    padding: 10px !important;
  }
}

/* ===== 遊戲模組專用響應式 ===== */

/* 遊戲卡片基礎樣式 */
.game-card {
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
  padding: var(--spacing-lg);
  border-radius: 16px;
  text-decoration: none;
  color: inherit;
  transition: all 0.3s ease;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.game-card:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.12);
}

.game-card:active {
  transform: scale(0.98);
}

/* 遊戲圖標響應式 */
.game-icon {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

@media screen and (max-width: 374px) {
  .game-icon {
    width: 48px;
    height: 48px;
    min-width: 48px;
    font-size: 24px;
    border-radius: 12px;
  }
}

@media screen and (min-width: 768px) {
  .game-icon {
    width: 64px;
    height: 64px;
    min-width: 64px;
    font-size: 32px;
    border-radius: 16px;
  }
}

/* 遊戲信息區塊 */
.game-info {
  flex: 1;
  min-width: 0;
}

.game-info h3 {
  font-size: var(--font-base);
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-info p {
  font-size: var(--font-sm);
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 模式卡片響應式 */
.mode-card {
  display: block;
  padding: var(--spacing-lg);
  border-radius: 18px;
  text-decoration: none;
  color: inherit;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.mode-card:hover {
  transform: translateY(-4px);
}

.mode-card:active {
  transform: scale(0.98);
}

.mode-icon {
  font-size: 32px;
  margin-bottom: var(--spacing-sm);
  display: block;
}

@media screen and (max-width: 374px) {
  .mode-icon {
    font-size: 28px;
  }

  .mode-card h3 {
    font-size: 14px;
  }

  .mode-card p {
    font-size: 11px;
  }
}

/* 問答選項響應式 */
.option-btn {
  width: 100%;
  padding: var(--spacing-lg) var(--spacing-lg);
  border-radius: 14px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  font-size: var(--font-base);
  cursor: pointer;
  transition: all 0.25s ease;
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
}

.option-btn:hover:not(:disabled) {
  transform: translateX(4px);
  background: rgba(255, 255, 255, 0.12);
}

@media screen and (max-width: 374px) {
  .option-btn {
    padding: var(--spacing-md) var(--spacing-md);
    font-size: var(--font-sm);
    gap: var(--spacing-sm);
  }
}

/* 選項字母標籤 */
.option-letter {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

@media screen and (max-width: 374px) {
  .option-letter {
    width: 28px;
    height: 28px;
    min-width: 28px;
    font-size: 12px;
  }
}

/* ===== 語音讀經模組專用響應式 ===== */

/* 經節卡片響應式 */
.verse-card {
  padding: var(--spacing-xl);
  border-radius: 24px;
}

@media screen and (max-width: 374px) {
  .verse-card {
    padding: var(--spacing-lg);
    border-radius: 20px;
  }

  .verse-card .verse-ref {
    font-size: 18px;
  }

  .verse-card .verse-text {
    font-size: 14px;
  }
}

/* 錄音控制區響應式 */
.recording-controls {
  padding: var(--spacing-2xl);
  border-radius: 24px;
}

@media screen and (max-width: 374px) {
  .recording-controls {
    padding: var(--spacing-lg);
    border-radius: 20px;
  }

  .recording-time {
    font-size: 36px;
  }

  .record-btn-main {
    width: 70px;
    height: 70px;
    font-size: 24px;
  }
}

@media screen and (min-width: 768px) {
  .recording-controls {
    padding: var(--spacing-3xl);
  }

  .record-btn-main {
    width: 100px;
    height: 100px;
    font-size: 36px;
  }
}

/* 錄音列表項目響應式 */
.recording-item {
  padding: var(--spacing-lg);
  border-radius: 16px;
}

@media screen and (max-width: 374px) {
  .recording-item {
    padding: var(--spacing-md);
  }

  .recording-item-title {
    font-size: 14px;
  }

  .recording-item-meta {
    font-size: 12px;
  }
}

/* 波形視覺化響應式 */
.waveform-canvas {
  height: 60px;
}

@media screen and (min-width: 480px) {
  .waveform-canvas {
    height: 80px;
  }
}

@media screen and (min-width: 768px) {
  .waveform-canvas {
    height: 100px;
  }
}

/* 排行榜響應式 */
.podium {
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-lg);
}

@media screen and (min-width: 480px) {
  .podium {
    flex-direction: row;
    justify-content: center;
    align-items: flex-end;
  }

  .podium-item.first {
    order: 2;
    transform: scale(1.1);
  }

  .podium-item.second {
    order: 1;
  }

  .podium-item.third {
    order: 3;
  }
}

/* 排名列表響應式 */
.rank-item {
  padding: var(--spacing-md) var(--spacing-lg);
  gap: var(--spacing-md);
}

@media screen and (max-width: 374px) {
  .rank-item {
    padding: var(--spacing-sm) var(--spacing-md);
    gap: var(--spacing-sm);
  }

  .rank-avatar {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  .rank-name {
    font-size: 13px;
  }

  .rank-stats {
    font-size: 11px;
  }
}

/* ===== 底部導航響應式 ===== */

/* 通用底部導航 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding-top: var(--spacing-sm);
  padding-bottom: calc(var(--spacing-sm) + var(--safe-area-bottom));
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
  z-index: 100;
  background: rgba(15, 23, 42, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-btn,
.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--spacing-sm) var(--spacing-md);
  border: none;
  background: none;
  cursor: pointer;
  font-size: 10px;
  text-decoration: none;
  transition: all 0.2s ease;
  border-radius: 10px;
  min-width: 56px;
}

.nav-btn span:first-child,
.bottom-nav-item .icon {
  font-size: 22px;
  transition: transform 0.2s ease;
}

.nav-btn.active,
.bottom-nav-item.active {
  color: #FFD700;
}

.nav-btn.active span:first-child,
.bottom-nav-item.active .icon {
  transform: scale(1.1);
}

/* 五欄底部導航 */
.bottom-nav-5 {
  grid-template-columns: repeat(5, 1fr);
}

.bottom-nav-5 .bottom-nav-item,
.bottom-nav.cols-5 .nav-btn {
  font-size: 9px;
  padding: var(--spacing-xs) var(--spacing-xs);
  min-width: 48px;
}

.bottom-nav-5 .bottom-nav-item .icon,
.bottom-nav.cols-5 .nav-btn span:first-child {
  font-size: 20px;
}

/* 極小螢幕底部導航 */
@media screen and (max-width: 359px) {
  .nav-btn,
  .bottom-nav-item {
    padding: var(--spacing-xs) var(--spacing-xs);
    min-width: 44px;
    font-size: 9px;
  }

  .nav-btn span:first-child,
  .bottom-nav-item .icon {
    font-size: 18px;
  }

  .bottom-nav-5 .bottom-nav-item,
  .bottom-nav.cols-5 .nav-btn {
    font-size: 8px;
    min-width: 40px;
  }

  .bottom-nav-5 .bottom-nav-item .icon,
  .bottom-nav.cols-5 .nav-btn span:first-child {
    font-size: 16px;
  }
}

/* ===== 模態框響應式 ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-lg);
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 20px;
  background: white;
}

@media screen and (max-width: 414px) {
  .modal-overlay {
    padding: var(--spacing-md);
    align-items: flex-end;
  }

  .modal-content {
    max-width: 100%;
    border-radius: 20px 20px 0 0;
  }
}

/* ===== Toast 響應式 ===== */
.toast-container {
  position: fixed;
  top: calc(var(--safe-area-top) + var(--spacing-lg));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  width: calc(100% - var(--spacing-2xl) * 2);
  max-width: 400px;
}

.toast {
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: 12px;
  margin-bottom: var(--spacing-sm);
}

@media screen and (max-width: 374px) {
  .toast-container {
    width: calc(100% - var(--spacing-lg) * 2);
  }

  .toast {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-sm);
  }
}

/* ===== 卡片通用響應式 ===== */
.card {
  border-radius: 16px;
  overflow: hidden;
}

.card-body {
  padding: var(--spacing-lg);
}

.card-header,
.card-footer {
  padding: var(--spacing-md) var(--spacing-lg);
}

@media screen and (max-width: 374px) {
  .card {
    border-radius: 14px;
  }

  .card-body {
    padding: var(--spacing-md);
  }

  .card-header,
  .card-footer {
    padding: var(--spacing-sm) var(--spacing-md);
  }
}

@media screen and (min-width: 768px) {
  .card {
    border-radius: 20px;
  }

  .card-body {
    padding: var(--spacing-xl);
  }

  .card-header,
  .card-footer {
    padding: var(--spacing-lg) var(--spacing-xl);
  }
}

/* ===== 按鈕響應式 ===== */
.btn {
  padding: var(--spacing-md) var(--spacing-xl);
  font-size: var(--font-base);
  border-radius: 12px;
  min-height: var(--touch-target-min);
}

.btn-sm {
  padding: var(--spacing-sm) var(--spacing-lg);
  font-size: var(--font-sm);
}

.btn-lg {
  padding: var(--spacing-lg) var(--spacing-2xl);
  font-size: var(--font-lg);
}

@media screen and (max-width: 374px) {
  .btn {
    padding: var(--spacing-sm) var(--spacing-lg);
    font-size: var(--font-sm);
  }

  .btn-lg {
    padding: var(--spacing-md) var(--spacing-xl);
    font-size: var(--font-base);
  }
}

/* ===== 文字溢出處理 ===== */
.text-truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.text-truncate-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== 安全區域工具類 ===== */
.safe-area-top {
  padding-top: var(--safe-area-top);
}

.safe-area-bottom {
  padding-bottom: var(--safe-area-bottom);
}

.safe-area-left {
  padding-left: var(--safe-area-left);
}

.safe-area-right {
  padding-right: var(--safe-area-right);
}

.safe-area-all {
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
}

/* ===== 動畫優化 ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===== 打印樣式 ===== */
@media print {
  .bottom-nav,
  .mobile-bottom-nav,
  .fab,
  .modal-overlay,
  .toast-container {
    display: none !important;
  }

  body {
    background: white !important;
    color: black !important;
  }

  .frontend-container {
    padding-bottom: 0 !important;
  }
}

/* ===== 隱藏/顯示工具類 ===== */
.hide-mobile {
  display: block;
}

.show-mobile {
  display: none;
}

@media screen and (max-width: 767px) {
  .hide-mobile {
    display: none !important;
  }

  .show-mobile {
    display: block !important;
  }

  .show-mobile-flex {
    display: flex !important;
  }

  .show-mobile-grid {
    display: grid !important;
  }
}

@media screen and (min-width: 1024px) {
  .hide-desktop {
    display: none !important;
  }

  .show-desktop {
    display: block !important;
  }
}

/* ========================================
 * 前台UI/UX深度增強 v2.0
 * Enhanced UI/UX for Frontend Systems
 * ======================================== */

/* ===== 全局溢出防護 ===== */
html,
body {
  overflow-x: hidden;
  max-width: 100%;
}

*,
*::before,
*::after {
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* ===== 滾動條美化 ===== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* 深色模式滾動條 */
@media (prefers-color-scheme: dark) {
  ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
  }

  ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
  }
}

/* ===== 高對比度模式支持 ===== */
@media (prefers-contrast: high) {
  .game-card,
  .mode-card,
  .verse-card,
  .stat-card,
  .card {
    border-width: 2px !important;
  }

  .option-btn {
    border-width: 3px !important;
  }

  .option-btn.correct {
    border-color: #10b981 !important;
    background: rgba(16, 185, 129, 0.3) !important;
  }

  .option-btn.wrong {
    border-color: #ef4444 !important;
    background: rgba(239, 68, 68, 0.3) !important;
  }

  button,
  .btn,
  a[role="button"] {
    border: 2px solid currentColor;
  }

  .bottom-nav,
  .bottom-nav-item.active {
    border: 2px solid;
  }
}

/* ===== 焦點可見性增強 ===== */
:focus-visible {
  outline: 3px solid #FFD700;
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #FFD700;
  outline-offset: 2px;
}

/* ===== 輸入框通用樣式 ===== */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="url"],
textarea,
select {
  -webkit-appearance: none;
  appearance: none;
  font-size: 16px;
  border-radius: var(--spacing-md);
  padding: var(--spacing-md);
  border: 2px solid rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease;
  width: 100%;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #FFD700;
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.2);
  outline: none;
}

/* ===== 表單響應式佈局 ===== */
.form-group {
  margin-bottom: var(--spacing-lg);
}

.form-label {
  display: block;
  margin-bottom: var(--spacing-sm);
  font-weight: 500;
  font-size: var(--font-sm);
}

.form-row {
  display: flex;
  gap: var(--spacing-md);
}

@media screen and (max-width: 479px) {
  .form-row {
    flex-direction: column;
  }
}

/* ===== 骨架屏載入（Claude Design 金色 shimmer）===== */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(232, 213, 163, 0.18) 25%,   /* gold-200 半透明 */
    rgba(201, 169, 98, 0.28) 50%,    /* gold-300 半透明（高光）*/
    rgba(232, 213, 163, 0.18) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
  border-radius: var(--spacing-sm);
}

.skeleton-dark {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.08) 25%,
    rgba(255, 255, 255, 0.14) 50%,
    rgba(255, 255, 255, 0.08) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
  border-radius: var(--spacing-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 16px;
  margin-bottom: var(--spacing-sm);
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: var(--spacing-md);
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.skeleton-card {
  height: 120px;
  border-radius: var(--spacing-lg);
}

/* ===== 空狀態顯示 ===== */
.empty-state {
  text-align: center;
  padding: var(--spacing-3xl) var(--spacing-lg);
  animation: empty-state-fade-in 0.5s ease;
}

@keyframes empty-state-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.empty-state-icon {
  font-size: 64px;
  opacity: 0.5;
  margin-bottom: var(--spacing-lg);
  display: inline-block;
  animation: empty-state-float 3s ease-in-out infinite;
}

@keyframes empty-state-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.empty-state-title {
  font-size: var(--font-lg);
  font-weight: 600;
  margin-bottom: var(--spacing-sm);
  color: var(--text-secondary, #4B5563);
}

.empty-state-desc {
  font-size: var(--font-sm);
  color: var(--text-muted, #9CA3AF);
  max-width: 320px;
  margin: 0 auto;
  line-height: 1.7;
}

@media (prefers-reduced-motion: reduce) {
  .empty-state, .empty-state-icon { animation: none; }
}

@media screen and (max-width: 374px) {
  .empty-state {
    padding: var(--spacing-2xl) var(--spacing-md);
  }

  .empty-state-icon {
    font-size: 48px;
  }

  .empty-state-title {
    font-size: var(--font-base);
  }
}

/* ===== 錯誤/成功狀態 ===== */
.alert {
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-md);
}

.alert-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.alert-content {
  flex: 1;
  min-width: 0;
}

.alert-title {
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
}

.alert-message {
  font-size: var(--font-sm);
  opacity: 0.9;
}

.alert-success {
  background: rgba(16, 185, 129, 0.15);
  border-left: 4px solid #10b981;
  color: #065F46;
}

.alert-error {
  background: rgba(239, 68, 68, 0.15);
  border-left: 4px solid #ef4444;
  color: #991B1B;
}

.alert-warning {
  background: rgba(245, 158, 11, 0.15);
  border-left: 4px solid #f59e0b;
  color: #92400E;
}

.alert-info {
  background: rgba(59, 130, 246, 0.15);
  border-left: 4px solid #3b82f6;
  color: #1E40AF;
}

/* ===== 進度條 ===== */
.progress-bar {
  height: 8px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-fill-success { background: #10b981; }
.progress-fill-warning { background: #f59e0b; }
.progress-fill-danger { background: #ef4444; }
.progress-fill-gold { background: linear-gradient(90deg, #FFD700, #FFA500); }

/* ===== 標籤/徽章 ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--spacing-xs) var(--spacing-md);
  border-radius: 20px;
  font-size: var(--font-xs);
  font-weight: 600;
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: #065F46;
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #92400E;
}

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #991B1B;
}

.badge-info {
  background: rgba(59, 130, 246, 0.15);
  color: #1E40AF;
}

.badge-gold {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 165, 0, 0.2));
  color: #B8860B;
}

/* ===== 分割線 ===== */
.divider {
  height: 1px;
  background: rgba(0, 0, 0, 0.1);
  margin: var(--spacing-lg) 0;
}

.divider-dark {
  background: rgba(255, 255, 255, 0.1);
}

.divider-with-text {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.divider-with-text::before,
.divider-with-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(0, 0, 0, 0.1);
}

.divider-text {
  font-size: var(--font-sm);
  opacity: 0.6;
}

/* ===== 載入指示器 ===== */
.loading-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: #FFD700;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-spinner-light {
  border-color: rgba(255, 255, 255, 0.2);
  border-top-color: #FFD700;
}

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

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loading-overlay-dark {
  background: rgba(0, 0, 0, 0.9);
}

/* ===== 標籤切換 ===== */
.tabs {
  display: flex;
  gap: var(--spacing-sm);
  overflow-x: auto;
  padding-bottom: var(--spacing-sm);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  padding: var(--spacing-sm) var(--spacing-lg);
  border-radius: 20px;
  font-size: var(--font-sm);
  font-weight: 500;
  white-space: nowrap;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  background: rgba(0, 0, 0, 0.05);
  color: inherit;
}

.tab:hover {
  background: rgba(0, 0, 0, 0.1);
}

.tab.active {
  background: #FFD700;
  color: #1a1a2e;
}

.tab-dark {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.tab-dark:hover {
  background: rgba(255, 255, 255, 0.15);
}

.tab-dark.active {
  background: #FFD700;
  color: #1a1a2e;
}

/* ===== 彈性網格工具 ===== */
.grid {
  display: grid;
  gap: var(--spacing-md);
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media screen and (max-width: 479px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media screen and (max-width: 374px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
}

.grid-auto-fit {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.grid-auto-fill {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

/* ===== Flexbox 工具 ===== */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-around { justify-content: space-around; }
.justify-evenly { justify-content: space-evenly; }
.flex-1 { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }

.gap-xs { gap: var(--spacing-xs); }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }
.gap-lg { gap: var(--spacing-lg); }
.gap-xl { gap: var(--spacing-xl); }

/* ===== 間距工具 ===== */
.m-0 { margin: 0; }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }
.mb-xl { margin-bottom: var(--spacing-xl); }

.p-0 { padding: 0; }
.p-sm { padding: var(--spacing-sm); }
.p-md { padding: var(--spacing-md); }
.p-lg { padding: var(--spacing-lg); }

/* ===== 圓角工具 ===== */
.rounded { border-radius: var(--spacing-md); }
.rounded-lg { border-radius: var(--spacing-lg); }
.rounded-xl { border-radius: var(--spacing-xl); }
.rounded-full { border-radius: 9999px; }

/* ===== 陰影工具 ===== */
.shadow-sm { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05); }
.shadow { box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); }
.shadow-md { box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1); }
.shadow-lg { box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15); }

/* ===== 動畫工具 ===== */
.animate-fade-in {
  animation: fadeIn 0.3s ease;
}

.animate-slide-up {
  animation: slideUp 0.3s ease;
}

.animate-scale-in {
  animation: scaleIn 0.3s ease;
}

.animate-bounce {
  animation: bounce 0.6s ease;
}

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

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

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* ===== 可見性工具 ===== */
.hidden { display: none !important; }
.invisible { visibility: hidden; }
.opacity-50 { opacity: 0.5; }
.opacity-75 { opacity: 0.75; }

/* ===== 文字工具 ===== */
.text-xs { font-size: var(--font-xs); }
.text-sm { font-size: var(--font-sm); }
.text-base { font-size: var(--font-base); }
.text-lg { font-size: var(--font-lg); }
.text-xl { font-size: var(--font-xl); }
.text-2xl { font-size: var(--font-2xl); }

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

/* ===== 極端橫向模式增強 ===== */
@media screen and (max-height: 400px) and (orientation: landscape) {
  .frontend-container {
    padding-top: var(--spacing-sm);
    padding-bottom: calc(44px + var(--safe-area-bottom));
  }

  h1, .page-title {
    font-size: var(--font-lg) !important;
    margin-bottom: var(--spacing-sm) !important;
  }

  .card-body {
    padding: var(--spacing-sm);
  }

  .btn {
    padding: var(--spacing-sm) var(--spacing-md);
    min-height: 36px;
  }

  .bottom-nav {
    padding: 4px var(--spacing-sm);
    padding-bottom: max(4px, var(--safe-area-bottom));
  }

  .nav-btn,
  .bottom-nav-item {
    padding: 4px;
    min-width: 40px;
    height: 36px;
  }

  .nav-btn span:first-child,
  .bottom-nav-item .icon {
    font-size: 16px;
  }

  .nav-btn span:last-child,
  .bottom-nav-item span:not(.icon) {
    font-size: 8px;
  }
}

/* ===== 安全區域完整支持 ===== */
@supports (padding: max(0px)) {
  .frontend-container {
    padding-left: max(var(--spacing-lg), var(--safe-area-left));
    padding-right: max(var(--spacing-lg), var(--safe-area-right));
  }

  .bottom-nav {
    padding-left: max(var(--spacing-sm), var(--safe-area-left));
    padding-right: max(var(--spacing-sm), var(--safe-area-right));
    padding-bottom: max(var(--spacing-sm), var(--safe-area-bottom));
  }
}
