/* ===== 📱 手機介面優化樣式 ===== */
/* 此檔案提供所有頁面的響應式設計優化 */

/* 基礎響應式設定 */
* {
  box-sizing: border-box;
}

body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* 確保圖片自動等比例縮放 */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* 確保文字不會超出螢幕 */
p, h1, h2, h3, h4, h5, h6, span, div {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* ===== 漢堡選單樣式 ===== */
.mobile-nav-toggle {
  display: none;
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 10000;
  background: rgba(0, 255, 255, 0.2);
  border: 2px solid #0ff;
  color: #0ff;
  padding: 10px 15px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 24px;
  transition: all 0.3s;
  width: 50px;
  height: 50px;
  align-items: center;
  justify-content: center;
}

.mobile-nav-toggle:hover {
  background: rgba(0, 255, 255, 0.4);
  box-shadow: 0 0 20px #0ff;
  transform: scale(1.1);
}

.mobile-nav-menu {
  display: none;
  position: fixed;
  top: 0;
  left: -100%;
  width: 80%;
  max-width: 300px;
  height: 100vh;
  background: rgba(0, 0, 0, 0.95);
  border-right: 2px solid #0ff;
  z-index: 9999;
  padding: 80px 20px 20px;
  transition: left 0.3s ease;
  overflow-y: auto;
}

.mobile-nav-menu.active {
  left: 0;
}

.mobile-nav-menu a {
  display: block;
  padding: 15px 20px;
  margin: 10px 0;
  color: #0ff;
  text-decoration: none;
  border: 1px solid #0ff;
  border-radius: 8px;
  background: rgba(0, 255, 255, 0.1);
  transition: all 0.3s;
  text-align: center;
}

.mobile-nav-menu a:hover {
  background: rgba(0, 255, 255, 0.3);
  box-shadow: 0 0 15px #0ff;
  transform: translateX(5px);
}

.mobile-nav-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 9998;
}

.mobile-nav-overlay.active {
  display: block;
}

/* ===== 平板尺寸優化 (768px 以下) ===== */
@media (max-width: 768px) {
  /* 顯示漢堡選單 */
  .mobile-nav-toggle {
    display: flex;
  }
  
  .mobile-nav-menu {
    display: block;
  }
  
  /* 標題區 */
  h1 {
    font-size: 2em !important;
    padding: 0 15px;
  }
  
  h2 {
    font-size: 1.5em !important;
  }
  
  h3 {
    font-size: 1.2em !important;
  }
  
  header {
    padding: 40px 15px !important;
  }
  
  header p {
    font-size: 0.9em !important;
    padding: 0 10px;
  }
  
  /* Section 調整 */
  section {
    padding: 30px 15px !important;
  }
  
  /* 按鈕群組改為垂直排列 */
  .lab-buttons {
    flex-direction: column !important;
    gap: 12px !important;
    padding: 0 20px;
    margin-top: 30px !important;
  }
  
  .lab-btn {
    width: 100% !important;
    text-align: center;
    padding: 14px 20px !important;
    font-size: 0.95em !important;
  }
  
  /* 卡片容器 */
  .game-table,
  .lab-table {
    gap: 20px !important;
    margin-top: 60px !important;
    padding: 20px 10px !important;
  }
  
  .game-card,
  .lab-card {
    width: calc(50% - 10px) !important;
    height: auto !important;
    min-height: 200px !important;
    padding: 20px 10px !important;
  }
  
  .game-icon,
  .lab-icon {
    font-size: 40px !important;
    margin-bottom: 10px !important;
  }
  
  /* App 卡片 */
  .app-card {
    flex-direction: column !important;
    text-align: center;
    padding: 15px !important;
  }
  
  .app-image {
    width: 80px !important;
    height: 80px !important;
  }

  /* Featured quiz card */
  #featured-play {
    padding: 0 12px !important;
    margin-bottom: 16px !important;
  }

  .featured-play-card {
    padding: 18px !important;
    border-radius: 26px !important;
  }

  .featured-play-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 18px !important;
    align-items: stretch !important;
  }

  .featured-play-content,
  .featured-play-preview {
    width: 100% !important;
    min-width: 0 !important;
  }

  .featured-play-preview {
    order: -1;
    min-height: 0 !important;
    padding: 12px !important;
  }

  .featured-play-preview-link {
    min-height: 0 !important;
    aspect-ratio: 16 / 10;
  }

  .featured-play-preview-image {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    object-fit: cover !important;
  }

  .featured-play-preview-badge {
    top: 16px !important;
    left: 16px !important;
    font-size: 0.78rem !important;
  }

  .featured-play-preview-caption {
    margin-top: 12px !important;
    padding: 12px 14px !important;
  }

  .featured-play-title {
    font-size: 1.55rem !important;
    line-height: 1.2 !important;
  }

  .featured-play-copy {
    font-size: 0.94rem !important;
    line-height: 1.75 !important;
  }

  .featured-play-notes {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .featured-play-note {
    width: 100% !important;
    justify-content: center !important;
    text-align: center !important;
  }

  .featured-play-actions {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
  }

  .featured-play-primary,
  .featured-play-secondary {
    width: 100% !important;
    min-width: 0 !important;
  }
  
  /* 聊天容器 */
  #chatContainer {
    padding: 15px !important;
    margin: 20px 10px !important;
  }
  
  #chatHistory {
    height: 250px !important;
    padding: 10px !important;
  }
  
  .message-bubble {
    max-width: 85% !important;
    font-size: 0.9em !important;
  }
  
  .message-avatar {
    width: 30px !important;
    height: 30px !important;
  }
  
  #chatInputArea {
    flex-direction: column !important;
    gap: 8px !important;
  }
  
  #catInput {
    width: 100% !important;
    font-size: 14px !important;
  }
  
  #sendBtn {
    width: 100% !important;
    padding: 12px !important;
  }
  
  #quickQuestions {
    gap: 6px !important;
  }
  
  .quick-btn {
    font-size: 11px !important;
    padding: 5px 10px !important;
  }
  
  /* 輪播控制 */
  .slide-btn {
    padding: 8px 12px !important;
    font-size: 18px !important;
  }
  
  .slideshow-container {
    max-width: 100% !important;
    padding: 0 10px !important;
  }
  
  /* 媒體區域改為垂直排列 */
  .media-flex {
    flex-direction: column !important;
  }
  
  .video-container,
  .spotify-container {
    min-width: 100% !important;
  }
  
  /* 背景音樂按鈕 */
  #bgm-control {
    width: 45px !important;
    height: 45px !important;
    font-size: 20px !important;
    top: 15px !important;
    right: 15px !important;
  }
  
  /* 表格容器 */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
  
  /* Canvas 遊戲區域 */
  canvas {
    max-width: 100% !important;
    height: auto !important;
  }
}

/* ===== 小型手機優化 (480px 以下) ===== */
@media (max-width: 480px) {
  h1 {
    font-size: 1.8em !important;
  }
  
  h2 {
    font-size: 1.3em !important;
  }
  
  header p {
    font-size: 0.8em !important;
  }
  
  .lab-btn {
    padding: 12px 16px !important;
    font-size: 0.9em !important;
  }

  #featured-play {
    padding: 0 10px !important;
  }

  .featured-play-card {
    padding: 16px !important;
    border-radius: 24px !important;
  }

  .featured-play-title {
    font-size: 1.42rem !important;
  }

  .featured-play-copy {
    font-size: 0.91rem !important;
  }

  .featured-play-preview-link {
    aspect-ratio: 5 / 4;
  }

  .featured-play-preview-caption {
    font-size: 0.84rem !important;
    line-height: 1.5 !important;
  }

  .featured-play-note {
    font-size: 0.84rem !important;
    padding: 10px 12px !important;
  }

  .featured-play-primary,
  .featured-play-secondary {
    padding: 12px 16px !important;
    font-size: 0.94rem !important;
  }
  
  #chatHistory {
    height: 200px !important;
  }
  
  .message-bubble {
    font-size: 0.85em !important;
    padding: 10px 12px !important;
  }
  
  .game-card,
  .lab-card {
    width: 100% !important;
    max-width: 280px !important;
    margin: 0 auto !important;
  }
  
  .slide-btn {
    padding: 6px 10px !important;
    font-size: 16px !important;
  }
  
  .mobile-nav-menu {
    width: 90%;
  }
  
  .mobile-nav-toggle {
    width: 45px;
    height: 45px;
    font-size: 20px;
  }
}

/* ===== 2026 首頁手機版補強 ===== */
@media (max-width: 768px) {
  body {
    cursor: auto !important;
  }

  section {
    max-width: 100% !important;
    padding: 24px 14px !important;
  }

  #tiny-worlds {
    padding: 0 10px !important;
    margin-bottom: 16px !important;
  }

  .tiny-worlds-shell {
    padding: 18px 16px !important;
    border-radius: 28px !important;
  }

  .tiny-worlds-intro {
    margin-bottom: 16px !important;
  }

  .tiny-worlds-kicker {
    padding: 7px 12px !important;
    font-size: 0.76rem !important;
  }

  .tiny-worlds-title {
    margin-bottom: 12px !important;
    font-size: 1.78rem !important;
    line-height: 1.14 !important;
  }

  .tiny-worlds-copy,
  .world-map-heading p,
  .portal-card-desc,
  .world-card-desc,
  .tiny-worlds-footer-copy {
    max-width: none !important;
    font-size: 0.95rem !important;
    line-height: 1.76 !important;
  }

  .portal-grid,
  .world-map-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  .portal-card-featured {
    grid-column: auto !important;
  }

  .portal-card,
  .world-card {
    min-height: 0 !important;
    padding: 18px 16px !important;
    border-radius: 24px !important;
  }

  .portal-card-preview {
    min-height: 72px !important;
    margin-bottom: 12px !important;
    padding: 11px 12px !important;
  }

  .portal-card-preview-tag {
    font-size: 0.64rem !important;
    letter-spacing: 0.1em !important;
  }

  .portal-card-preview-title {
    max-width: 17ch !important;
    font-size: 0.9rem !important;
    line-height: 1.18 !important;
  }

  .portal-card-title,
  .world-card-title {
    max-width: calc(100% - 70px) !important;
    font-size: 1.28rem !important;
    line-height: 1.24 !important;
  }

  .portal-card-orb {
    top: 14px !important;
    right: 14px !important;
    min-width: 46px !important;
    height: 46px !important;
    font-size: 0.7rem !important;
  }

  .portal-card-sigil {
    width: 82px !important;
    height: 82px !important;
    right: 8px !important;
    bottom: 10px !important;
    opacity: 0.08 !important;
  }

  .portal-card-meta,
  .world-card-link,
  .world-card-ghost,
  .world-card-disabled {
    width: auto !important;
    min-height: 0 !important;
    justify-content: flex-start !important;
    text-align: left !important;
  }

  .world-card-actions {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .world-card-tags,
  .tag-row,
  .tiny-worlds-footer-links {
    gap: 8px !important;
  }

  .world-map-heading {
    gap: 10px !important;
    margin-bottom: 14px !important;
  }

  .world-map-heading h3 {
    font-size: 1.24rem !important;
  }

  .spotlight-rail {
    align-items: flex-start !important;
    margin-bottom: 14px !important;
  }

  .spotlight-rail-main,
  .spotlight-controls {
    width: 100% !important;
  }

  .spotlight-controls {
    justify-content: space-between !important;
    gap: 8px !important;
  }

  .spotlight-chip {
    width: 100% !important;
    justify-content: center !important;
  }

  .spotlight-status {
    width: 100% !important;
    justify-content: center !important;
    min-height: 40px !important;
  }

  .spotlight-nav {
    flex: 1 1 calc(50% - 4px) !important;
    min-height: 42px !important;
    padding: 0 12px !important;
  }

  .spotlight-dots {
    width: 100% !important;
    justify-content: center !important;
    order: 3 !important;
  }

  .spotlight-cover {
    min-height: 124px !important;
    padding: 13px !important;
  }

  .spotlight-cover-top {
    gap: 8px !important;
  }

  .spotlight-cover-badges {
    gap: 8px !important;
  }

  .spotlight-cover-note {
    font-size: 11px !important;
  }

  .spotlight-cover-title {
    font-size: 1rem !important;
  }

  .tiny-worlds-footer {
    padding: 16px !important;
    border-radius: 20px !important;
  }

  #catSection {
    padding-top: 22px !important;
  }

  #memeCat {
    width: 88px !important;
  }

  #chatContainer {
    margin: 16px auto 0 !important;
    padding: 14px !important;
    border-radius: 24px !important;
  }

  #chatHistory {
    height: auto !important;
    min-height: 220px !important;
    max-height: 50svh !important;
    margin-bottom: 14px !important;
    padding: 12px !important;
  }

  .message {
    gap: 8px !important;
    align-items: flex-end !important;
  }

  .message-bubble {
    max-width: calc(100% - 48px) !important;
    padding: 12px 14px !important;
    font-size: 0.95rem !important;
    line-height: 1.6 !important;
  }

  .message-avatar {
    width: 36px !important;
    height: 36px !important;
    margin: 0 !important;
    flex: 0 0 36px !important;
  }

  #quickQuestions {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .quick-btn {
    width: 100% !important;
    min-height: 44px !important;
    padding: 10px 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.89rem !important;
    line-height: 1.3 !important;
  }

  #chatInputArea {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  #catInput,
  #sendBtn,
  #clearChat {
    width: 100% !important;
    min-height: 48px !important;
  }

  #chatControls {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  #catMood {
    justify-content: center !important;
  }

  #bgm-control {
    top: 14px !important;
    right: 14px !important;
    bottom: auto !important;
    width: 48px !important;
    height: 48px !important;
    font-size: 21px !important;
  }

  .slideshow-container {
    max-width: 100% !important;
    padding: 0 !important;
  }

  .slide {
    width: 100% !important;
    aspect-ratio: 4 / 5 !important;
    object-fit: cover !important;
    border-radius: 20px !important;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.66), rgba(255, 245, 239, 0.52)) !important;
  }

  .slide-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 42px !important;
    height: 42px !important;
    padding: 0 !important;
    border-radius: 14px !important;
  }

  .slide-btn.prev {
    left: 12px !important;
  }

  .slide-btn.next {
    right: 12px !important;
  }
}

@media (max-width: 480px) {
  .tiny-worlds-title {
    font-size: 1.58rem !important;
  }

  .portal-card-title,
  .world-card-title {
    max-width: none !important;
    font-size: 1.18rem !important;
  }

  #quickQuestions {
    grid-template-columns: 1fr !important;
  }

  .quick-btn {
    min-height: 42px !important;
    font-size: 0.86rem !important;
  }

  .message-bubble {
    max-width: calc(100% - 44px) !important;
    font-size: 0.9rem !important;
  }

  #chatHistory {
    min-height: 200px !important;
  }

  #bgm-control {
    top: 12px !important;
    bottom: auto !important;
  }
}
