/* ============================================================
   寶可夢注音點讀練習 - Gallery & Detail CSS
   針對 iPad Safari 觸控與兒童學習最佳化
   ============================================================ */

/* 載入專案現有的注音字型 */
@font-face {
  font-family: 'BpmfGenYoMin';
  src: url('../../fonts/BpmfGenYoMin-R.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: block;
}

:root {
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --badge-bg: #f1f5f9;
  --badge-text: #475569;
  --btn-radius: 16px;
  --card-radius: 22px;
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  -webkit-user-select: none;
  user-select: none;
  overflow-x: hidden;
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 10px) env(safe-area-inset-right, 16px) env(safe-area-inset-bottom, 16px) env(safe-area-inset-left, 16px);
}

.view-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* ============================================================
   圖鑑主畫面 (Gallery View)
   ============================================================ */

.app-header {
  padding: 12px 8px 16px 8px;
}

.app-title {
  font-size: 1.9rem;
  font-weight: 800;
  text-align: center;
  color: #1e3a8a;
  margin-bottom: 14px;
  letter-spacing: 1px;
}

.controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

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

.control-label {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
}

.select-input {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: 14px;
  padding: 10px 40px 10px 18px;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  min-height: 50px;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23334155' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px;
  box-shadow: var(--shadow-sm);
}

.select-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.search-group {
  flex: 1;
  max-width: 420px;
}

.search-input-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
}

.text-input {
  width: 100%;
  min-height: 50px;
  padding: 10px 44px 10px 18px;
  border: 2px solid var(--border-color);
  border-radius: 14px;
  font-size: 1.1rem;
  font-weight: 500;
  background-color: var(--card-bg);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.text-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.clear-btn {
  position: absolute;
  right: 12px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background-color: var(--border-color);
  color: #475569;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.gallery-status-bar {
  text-align: center;
  margin-top: 4px;
}

.status-count {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-muted);
  background-color: #e2e8f0;
  padding: 4px 14px;
  border-radius: 9999px;
  display: inline-block;
}

/* 圖鑑網格 (CSS Grid) */
.gallery-content {
  flex: 1;
  padding: 8px 4px 32px 4px;
}

.pokemon-gallery-grid {
  display: grid;
  /* iPad 橫向約 4~6 隻，直向約 3~4 隻，自適應 */
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 16px;
  width: 100%;
}

/* 圖鑑單張卡片 */
.gallery-card {
  background-color: var(--card-bg);
  border: 2.5px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 14px 10px 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  touch-action: manipulation;
}

.gallery-card:hover {
  border-color: #93c5fd;
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.12);
}

.gallery-card:active {
  transform: scale(0.95);
  border-color: var(--primary-color);
}

.gallery-card-image-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.gallery-card-img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.08));
}

.gallery-card-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
}

.gallery-card-number {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.gallery-card-name {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-main);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* 無搜尋結果 */
.no-result-card {
  background-color: var(--card-bg);
  border-radius: var(--card-radius);
  padding: 48px 24px;
  text-align: center;
  box-shadow: var(--shadow-md);
  margin: 30px auto;
  max-width: 480px;
  border: 2px solid var(--border-color);
}

.no-result-text {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ============================================================
   寶可夢詳細頁 (Detail View)
   ============================================================ */

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 8px 16px 8px;
}

.btn-back {
  background-color: #475569;
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  min-height: 52px;
  font-size: 1.25rem;
  font-weight: 700;
  border-radius: var(--btn-radius);
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.btn-back:hover {
  background-color: #334155;
}

.btn-back:active {
  transform: scale(0.96);
}

.back-icon {
  font-size: 1.4rem;
}

.detail-counter {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-muted);
  background-color: #e2e8f0;
  padding: 8px 18px;
  border-radius: 9999px;
}

.detail-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 8px;
}

.detail-card {
  width: 100%;
  max-width: 680px;
  background-color: var(--card-bg);
  border-radius: 28px;
  box-shadow: var(--shadow-md);
  border: 3.5px solid #e2e8f0;
  padding: 24px 28px 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.detail-number-badge {
  background-color: var(--badge-bg);
  color: var(--badge-text);
  font-size: 1.45rem;
  font-weight: 800;
  padding: 6px 24px;
  border-radius: 9999px;
  letter-spacing: 1.5px;
}

.detail-image-wrapper {
  width: 100%;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail-image {
  max-width: 90%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.12));
}

.detail-names-box {
  width: 100%;
  background-color: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 20px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.name-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.name-label {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
  letter-spacing: 0.5px;
}

.name-value.standard-font {
  font-size: 2.4rem;
  font-weight: 900;
  color: #0f172a;
  letter-spacing: 2px;
}

.name-divider {
  width: 80%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #cbd5e1, transparent);
}

.phonetic-block .name-label {
  color: #2563eb;
}

/* 核心注音字型呈現：超大尺寸，供孩童清楚看見注音與聲調 */
.phonetic-name {
  font-family: 'BpmfGenYoMin', serif !important;
  font-size: 4.4rem;
  font-weight: normal;
  font-style: normal;
  color: #1e3a8a;
  line-height: 1.35;
  text-align: center;
  letter-spacing: 4px;
  margin-top: 2px;
}

/* 詳細頁底部導覽列 */
.detail-nav-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 8px 12px 8px;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 12px 32px;
  font-size: 1.3rem;
  font-weight: 700;
  border-radius: var(--btn-radius);
  border: none;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease;
  touch-action: manipulation;
}

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

.nav-btn {
  background-color: var(--primary-color);
  color: #ffffff;
  flex: 1;
  max-width: 240px;
  box-shadow: var(--shadow-sm);
  gap: 10px;
}

.nav-btn:hover:not(:disabled) {
  background-color: var(--primary-hover);
}

.nav-btn:disabled {
  background-color: #cbd5e1;
  color: #94a3b8;
  cursor: not-allowed;
  transform: none;
}

.btn-arrow {
  font-size: 1.15rem;
}

.btn-secondary {
  background-color: #64748b;
  color: #ffffff;
}

/* ============================================================
   iPad 與螢幕適配調整
   ============================================================ */

/* iPad 橫向模式 (Landscape) */
@media (min-width: 768px) and (orientation: landscape) {
  .detail-card {
    flex-direction: row;
    padding: 20px 28px;
    max-width: 820px;
    align-items: center;
  }

  .detail-image-wrapper {
    flex: 1;
    height: 320px;
  }

  .detail-names-box {
    flex: 1.2;
    padding: 20px;
  }

  .phonetic-name {
    font-size: 4.2rem;
  }
}

/* 小型螢幕適配 */
@media (max-width: 480px) {
  .app-title {
    font-size: 1.4rem;
  }

  .pokemon-gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .gallery-card {
    padding: 10px 6px;
  }

  .gallery-card-name {
    font-size: 1.15rem;
  }

  .name-value.standard-font {
    font-size: 1.9rem;
  }

  .phonetic-name {
    font-size: 3.2rem;
    letter-spacing: 2px;
  }

  .btn {
    min-height: 48px;
    padding: 10px 18px;
    font-size: 1.1rem;
  }
}
