/* ============================================
   同行宇宙翻翻樂 — style.css  v2.0
   ============================================ */

:root {
  --cosmos-bg: #080c18;
  --cosmos-mid: #0d1528;
  --cosmos-card-back: #111828;
  --cosmos-border: rgba(200, 185, 255, 0.12);
  --cosmos-border-hover: rgba(200, 185, 255, 0.3);
  /*--text-primary: rgba(240, 235, 255, 0.92);
  --text-secondary: rgba(200, 190, 230, 0.55);
  --text-gold: #c8a87a;
  --toolbar-border: rgba(255, 210, 120, 0.18);
  */
  --text-primary: rgba(0, 0, 0, 0.92);
  --text-secondary: rgba(50, 0, 0, 1);
  --text-gold: #573402;
  --toolbar-bg: rgba(255, 230, 180, 0.08);
  --toolbar-border: rgba(87, 52, 2, 0.3);
  --matched-glow: rgba(255, 210, 100, 0.5);
  --flip-duration: 0.55s;
  --card-radius: 14px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ---- Base ---- */
html {
  height: 100%;
}

body {
  min-height: 100%;
  background: var(--cosmos-bg) url('./assets/bg_pc.png') right center / cover no-repeat fixed;
  color: var(--text-primary);
  font-family: 'Noto Serif TC', serif;
  overflow: hidden;   /* PC: no scroll */
}

@media (max-width: 768px) {
  body {
    overflow-y: auto;
    background-image: url('./assets/bg_mobile.png');
    background-position: center top;
  }
}

/* ---- Stars ---- */
.stars-bg { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.star-dot {
  position: absolute; border-radius: 50%;
  background: rgba(240, 235, 255, 0.7);
  animation: starTwinkle var(--dur, 4s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}
@keyframes starTwinkle {
  0%,100% { opacity: var(--op-min,.2); transform: scale(1); }
  50%     { opacity: var(--op-max,.9); transform: scale(1.3); }
}
.nebula {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 60% 40% at 20% 30%, rgba(80,60,160,.18) 0%, transparent 70%),
    radial-gradient(ellipse 40% 50% at 80% 70%, rgba(50,80,180,.14) 0%, transparent 70%),
    radial-gradient(ellipse 30% 30% at 60% 20%, rgba(160,100,80,.08) 0%, transparent 60%);
}

/* ---- App 雙欄 ---- */
.app {
  position: relative; z-index: 1;
  display: flex;
  height: 100vh;
}

/* ---- 左側：遊戲區（透明，讓背景露出） ---- */
.game-panel {
  width: 45%;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  padding: 28px 20px 24px;
  /* 需求 2：移除整塊背景底色，讓背景圖直接透出 */
  background: transparent;
  backdrop-filter: none;
  border-right: none;
}

/* ---- info-card：PC 預設透明，手機才啟用玻璃效果 ---- */
.info-card {
  display: contents; /* PC：不產生額外盒子，子元件直接流入 flex */
}

/* scrollbar 細化 */
.game-panel::-webkit-scrollbar { width: 4px; }
.game-panel::-webkit-scrollbar-track { background: transparent; }
.game-panel::-webkit-scrollbar-thumb { background: var(--cosmos-border); border-radius: 4px; }

/* ---- Header：輕盈版，給棋盤更多空間 ---- */
.header {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding-bottom: 12px;
  border-bottom: none;   /* 移除分隔線，避免過重 */
  flex-shrink: 0;
}

.header-title {
  display: flex; flex-direction: row; align-items: baseline;
  justify-content: center; gap: 12px; flex-wrap: wrap; text-align: center;
}
.title-cn {
  font-weight: 300; font-size: clamp(18px, 3.5vw, 24px);
  letter-spacing: .18em; color: var(--text-gold);
}
.title-subtitle {
  font-weight: 300; font-size: clamp(15px, 2.5vw, 20px);
  letter-spacing: .12em; color: var(--text-primary); opacity: .92;
}

/* 狀態列 */
.status-bar {
  display: flex; align-items: center;
  background: var(--toolbar-bg);
  border: 1px solid var(--toolbar-border);
  border-radius: 18px; padding: 10px 20px;
  box-shadow: 0 0 18px rgba(255,210,90,.06);
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 56px; }
.stat-label { font-size: 10px; letter-spacing: .2em; color: var(--text-secondary); }
.stat-value { font-family: 'Cormorant Garamond', serif; font-size: 18px; color: var(--text-primary); line-height: 1; }
.stat-total { font-size: 11px; color: var(--text-secondary); }
.stat-divider { width: 1px; height: 24px; background: var(--cosmos-border); margin: 0 10px; }

/* 功能列 */
.toolbar {
  display: flex; align-items: center; justify-content: center;
  gap: 14px; flex-wrap: wrap; width: 100%;
  padding: 10px 14px;
  background: var(--toolbar-bg);
  border: 1px solid var(--toolbar-border);
  border-radius: 14px;
  box-shadow: 0 0 18px rgba(255,210,90,.06);
}
.card-count-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-count-label { font-weight: 300; font-size: 15px; letter-spacing: .1em; color: var(--text-primary); }
.card-count-input {
  font-family: 'Cormorant Garamond', serif; font-size: 16px;
  width: 62px; text-align: center;
  background: rgba(255,255,255,.3);
  border: 1px solid var(--cosmos-border); border-radius: 8px;
  color: var(--text-primary); padding: 4px 6px; outline: none;
  transition: border-color .2s;
  -moz-appearance: textfield;
}
.card-count-input::-webkit-inner-spin-button,
.card-count-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.card-count-input:focus { border-color: var(--cosmos-border-hover); }
.card-count-hint { font-size: 12px; color: var(--text-secondary); opacity: .9; letter-spacing: .04em; }

.controls, .controls-top { display: flex; justify-content: center; }
.btn-restart {
  font-family: 'Noto Serif TC', serif; font-weight: 400; font-size: 14px;
  letter-spacing: .18em; color: var(--text-primary);
  background: rgba(255,220,150,.08);
  border: 1px solid rgba(255,210,110,.28);
  border-radius: 50px; padding: 9px 22px; cursor: pointer; transition: all .3s;
}
.btn-restart:hover { background: rgba(255,220,150,.15); border-color: rgba(255,210,110,.5); color: var(--text-gold); }

/* ---- 棋盤 ---- */
.game-area {
  flex: 1; display: flex; align-items: flex-start;
  justify-content: center; padding: 14px 0 8px; overflow: hidden;
}
.board { display: grid; gap: 7px; width: 100%; grid-template-columns: repeat(6, 1fr); }

/* ============================================
   Card — 同行宇宙風（需求 3 全面升級）
   ============================================ */
.card {
  aspect-ratio: 1;
  cursor: pointer;
  perspective: 1000px;
  border-radius: var(--card-radius);
  /* 微陰影讓牌「漂浮」感 */
  filter: drop-shadow(0 2px 8px rgba(0,0,0,.35));
  transition: filter .25s;
}
.card:hover:not(.flipped):not(.matched) {
  filter: drop-shadow(0 4px 14px rgba(180,160,255,.25));
}

.card-inner {
  width: 100%; height: 100%; position: relative;
  transform-style: preserve-3d;
  transition: transform var(--flip-duration) cubic-bezier(.4,.06,.2,1);
  border-radius: var(--card-radius);
}

/* 需求 4：.flipped 與 .matched 都鎖定翻開狀態；
   .matched 用 !important 確保不被任何後續操作覆蓋 */
.card.flipped .card-inner {
  transform: rotateY(180deg);
}
.card.matched .card-inner {
  transform: rotateY(180deg) !important;
}

.card-face {
  position: absolute; inset: 0;
  border-radius: var(--card-radius);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  overflow: hidden;
}

/* 卡背：直接顯示圖片（img 由 JS 插入） */
.card-back {
  position: absolute;
  background: none;
  border: 1px solid rgba(200, 185, 255, 0.18);
  transition: border-color .3s, box-shadow .3s;
  overflow: hidden;
}

.card-back img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: inherit;
  pointer-events: none;
  user-select: none;
}

.card:hover:not(.flipped):not(.matched) .card-back {
  border-color: rgba(255, 220, 150, 0.5);
  box-shadow: 0 0 12px rgba(255, 210, 120, 0.25);
}

/* 卡正面：深宇宙底，讓圖片乾淨顯示 */
.card-front {
  transform: rotateY(180deg);
  background: rgba(8, 11, 24, 0.82);
  border: 1px solid rgba(160, 140, 220, 0.2);
  display: flex; align-items: center; justify-content: center; padding: 6%;
}
.card-front img { width: 100%; height: 100%; object-fit: contain; border-radius: 6px; }

/* 配對成功：金色柔光邊框，永久保持正面 */
.card.matched {
  filter: drop-shadow(0 0 10px rgba(255, 200, 80, 0.3));
}
.card.matched .card-face {
  border-color: rgba(255, 200, 80, 0.32);
}
.card.matched .card-front {
  background: rgba(12, 10, 4, 0.85);
}

/* matchFlash：配對瞬間柔金光暈，不誇張 */
@keyframes matchFlash {
  0%   { filter: drop-shadow(0 0 2px transparent); }
  35%  { filter: drop-shadow(0 0 16px rgba(255, 210, 80, 0.75)); }
  100% { filter: drop-shadow(0 0 10px rgba(255, 200, 80, 0.3)); }
}
.card.matched {
  animation: matchFlash .65s ease-out forwards;
}

/* ---- 右側：視覺區 ---- */
.visual-area {
  width: 55%; height: 100vh;
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}
.visual-inner {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 32px; padding: 40px;
  text-align: center;
}
.visual-eyebrow {
  font-size: 13px; letter-spacing: .3em; color: var(--text-secondary);
  margin-bottom: 8px;
}
.visual-headline {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: clamp(38px, 5vw, 60px); font-weight: 300;
  color: var(--text-gold); letter-spacing: .1em; line-height: 1.2;
}
.visual-tagline {
  font-size: 16px; font-weight: 300; line-height: 2.2;
  letter-spacing: .12em; color: var(--text-primary); opacity: .8;
}
.visual-deco {
  position: relative; width: 260px; height: 260px;
}

/* 視覺裝飾：浮動星球 */
.deco-orb {
  position: absolute; border-radius: 50%;
  animation: floatOrb var(--dur,8s) ease-in-out infinite;
  animation-delay: var(--delay,0s);
}
@keyframes floatOrb {
  0%,100% { transform: translateY(0) scale(1); }
  50%     { transform: translateY(-18px) scale(1.04); }
}

/* ---- 粒子 ---- */
.particle {
  position: fixed; pointer-events: none; border-radius: 50%; z-index: 50;
  animation: particleFly var(--fly-dur,.8s) ease-out forwards;
}
@keyframes particleFly {
  0%   { opacity: 1; transform: translate(0,0) scale(1); }
  100% { opacity: 0; transform: translate(var(--tx,0),var(--ty,0)) scale(0); }
}

/* ============================================
   Modals（共用底層）
   ============================================ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 7, 18, 0.85);
  backdrop-filter: blur(14px);
  animation: fadeIn .4s ease;
}
.modal-backdrop[hidden] { display: none; }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.modal-card {
  position: relative;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255,210,100,.22);
  border-radius: 24px;
  padding: 44px 48px;
  max-width: 480px; width: 92%;
  max-height: 92vh; overflow-y: auto;
  animation: slideUp .5s cubic-bezier(.2,.8,.3,1) both;
  box-shadow: 0 0 40px rgba(255,200,80,.08);
}
@keyframes slideUp {
  from { opacity:0; transform: translateY(24px) scale(.97); }
  to   { opacity:1; transform: translateY(0) scale(1); }
}

/* ---- 通關 Modal ---- */
.modal-badge {
  font-size: 11px; letter-spacing: .25em; color: var(--text-gold);
  text-transform: uppercase; margin-bottom: 12px; opacity: .85;
}
.modal-title {
  font-family: 'Cormorant Garamond', serif; font-weight: 300;
  font-size: 28px; letter-spacing: .15em; color: var(--text-primary);
  margin-bottom: 18px;
}
.modal-stats-row {
  display: flex; align-items: center; gap: 0;
  justify-content: center; margin-bottom: 24px;
}
.modal-stat { text-align: center; min-width: 80px; }
.modal-stat-n { font-family: 'Cormorant Garamond', serif; font-size: 28px; color: var(--text-gold); }
.modal-stat-l { font-size: 11px; letter-spacing: .2em; color: var(--text-secondary); }
.modal-stat-div { width: 1px; height: 32px; background: var(--cosmos-border); margin: 0 16px; }

.modal-body { display: flex; flex-direction: column; gap: 16px; }
.modal-copy {
  font-size: 14px; line-height: 2.2; letter-spacing: .08em;
  color: var(--text-primary); opacity: .88;
  border-top: 1px solid var(--cosmos-border);
  padding-top: 18px;
}
.modal-copy-note { font-size: 12px; color: var(--text-secondary); opacity: .7; }

.modal-field { display: flex; flex-direction: column; gap: 6px; }
.modal-label { font-size: 13px; letter-spacing: .12em; color: var(--text-secondary); }
.modal-label .required { color: #e8a070; margin-left: 2px; }
.modal-label .optional  { font-size: 11px; opacity: .6; }
.modal-input {
  font-family: 'Noto Serif TC', serif; font-size: 15px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--cosmos-border); border-radius: 10px;
  color: var(--text-primary); padding: 10px 14px; outline: none;
  transition: border-color .2s;
}
.modal-input:focus { border-color: rgba(255,210,100,.4); }
.modal-input::placeholder { color: var(--text-secondary); opacity: .5; }
.modal-error { font-size: 12px; color: #e8907a; margin-top: 2px; }
.modal-error[hidden] { display: none; }

.btn-submit {
  font-family: 'Noto Serif TC', serif; font-weight: 400;
  font-size: 14px; letter-spacing: .2em;
  color: var(--cosmos-bg);
  background: linear-gradient(135deg, #d4a870, #c8906a);
  border: none; border-radius: 50px; padding: 13px 32px;
  cursor: pointer; margin-top: 6px;
  transition: all .3s; box-shadow: 0 4px 20px rgba(200,150,80,.25);
}
.btn-submit:hover { background: linear-gradient(135deg, #e0b878, #d0986e); box-shadow: 0 6px 24px rgba(200,150,80,.35); }

/* ---- 紀念圖 Modal ---- */
.card-modal-inner {
  max-width: 660px;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  padding: 36px 36px 32px;
}

#memoryCanvas {
  width: 100%; max-width: 600px; border-radius: 16px;
  border: 1px solid rgba(255,210,100,.2);
  box-shadow: 0 0 30px rgba(255,200,80,.1);
}

.card-modal-actions {
  display: flex; flex-direction: column; align-items: center; gap: 20px; width: 100%;
}

.btn-download {
  display: inline-block;
  font-family: 'Noto Serif TC', serif; font-size: 14px;
  letter-spacing: .2em; color: var(--cosmos-bg);
  background: linear-gradient(135deg, #d4a870, #c8906a);
  border-radius: 50px; padding: 11px 28px; text-decoration: none;
  box-shadow: 0 4px 18px rgba(200,150,80,.25); transition: all .3s;
}
.btn-download:hover { background: linear-gradient(135deg, #e0b878, #d0986e); }

.challenge-block {
  width: 100%;
  margin-top: 8px;
}

.challenge-panel {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 220, 150, 0.18);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}
.challenge-text {
  font-size: 14px; line-height: 2; letter-spacing: .1em;
  color: var(--text-primary); opacity: .85; margin-bottom: 14px;
}
.challenge-row {
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.challenge-input { width: 80px; }
.btn-challenge {
  font-family: 'Noto Serif TC', serif; font-weight: 400;
  font-size: 14px; letter-spacing: .15em;
  color: var(--text-primary);
  background: rgba(255,220,150,.1);
  border: 1px solid rgba(255,210,110,.3); border-radius: 50px;
  padding: 9px 22px; cursor: pointer; transition: all .3s;
}
.btn-challenge:hover { background: rgba(255,220,150,.18); color: var(--text-gold); }

/* ---- 手機版（三層結構） ---- */
@media (max-width: 768px) {

  /* body：手機背景 + 允許滾動 */
  body {
    overflow-y: auto;
    background-image: url('./assets/bg_mobile.png');
    background-size: cover;
    background-position: center top;
    background-attachment: fixed;
  }

  /* App：單欄，高度自適應 */
  .app {
    flex-direction: column;
    align-items: center;
    height: auto;
    min-height: 100vh;
    padding-bottom: 0;
  }

  /* 右側視覺區隱藏（背景圖已承擔視覺） */
  .visual-area { display: none; }

  /* game-panel：全寬，透明，不固定高度 */
  .game-panel {
    width: 100%;
    height: auto;
    border: none;
    padding: 16px 14px 0;
    overflow-y: visible;
    /* 三層之間的間距由子元件自行控制 */
  }

  /* ── 層 1：資訊卡（header + status + toolbar 整合包） ── */
  .info-card {
    display: block; /* 覆蓋 PC 的 display:contents */
    background: rgba(20, 20, 40, 0.35);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    padding: 16px 14px 14px;
    margin: 0 auto 14px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 4px 24px rgba(0,0,0,.35);
  }

  /* 手機版 info-card 內：強制亮色文字覆蓋全域深色字 */
  .info-card .title-cn,
  .info-card .title-subtitle,
  .info-card .stat-value,
  .info-card .stat-label,
  .info-card .stat-total,
  .info-card .card-count-label,
  .info-card .card-count-hint,
  .info-card .btn-restart {
    color: rgba(255, 245, 220, 0.9);
  }
  .info-card .stat-label,
  .info-card .stat-total,
  .info-card .card-count-hint {
    color: rgba(255, 230, 200, 0.6);
  }
  .info-card .title-cn {
    color: rgba(255, 220, 150, 0.95);  /* 標題金色 */
  }
  .info-card .card-count-input {
    color: rgba(255, 245, 220, 0.9);
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.18);
  }
  .info-card .btn-restart {
    background: rgba(255, 220, 150, 0.14);
    border-color: rgba(255, 210, 110, 0.4);
    color: rgba(255, 245, 220, 0.92);
  }
  .info-card .btn-restart:hover {
    background: rgba(255, 220, 150, 0.25);
    color: rgba(255, 230, 160, 1);
  }

  /* header 在 info-card 內去掉多餘間距 */
  .header {
    gap: 10px;
    padding-bottom: 0;
  }

  /* 標題在手機縮小一點 */
  .title-cn    { font-size: clamp(14px, 4.5vw, 18px); }
  .title-subtitle { font-size: clamp(12px, 3.5vw, 16px); }

  /* status-bar 在 info-card 內背景改透明，邊框留輕線 */
  .status-bar {
    background: rgba(255,230,180,.06);
    border-color: rgba(255,210,120,.14);
    padding: 8px 16px;
    border-radius: 14px;
  }

  /* toolbar 在 info-card 內 */
  .toolbar {
    background: rgba(255,230,180,.06);
    border-color: rgba(255,210,120,.14);
    padding: 8px 12px;
    border-radius: 12px;
    gap: 10px;
  }

  /* ── 層 2：棋盤區 ── */
  .game-area {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 10px 0 0;
    /* 限制棋盤高度，保留角色視覺區 */
    max-height: 52vh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  /* 棋盤本身縮緊間距 */
  .board { gap: 5px; }

  /* ── 層 3：下方角色視覺區（靠背景圖自然呈現） ──
     給一段空白讓背景人物透出來 */
  .game-panel::after {
    content: '';
    display: block;
    height: 32vh;
    min-height: 120px;
  }

  /* Modal */
  .modal-card { padding: 28px 18px; }
  .card-modal-inner { padding: 20px 14px; }
  .modal-stats-row { gap: 0; }
}

@media (max-width: 480px) {
  .game-area { max-height: 48vh; }
  .info-card { padding: 12px 10px 10px; }
  .title-cn    { font-size: 14px; }
  .title-subtitle { font-size: 12px; }
  .stat-value  { font-size: 16px; }
  .board { gap: 4px; }
  .btn-restart { font-size: 13px; padding: 8px 18px; }
}
