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

:root {
  --bg: #12141f;
  --panel: #1d2033;
  --panel2: #262a44;
  --text: #eef0ff;
  --muted: #9aa0c3;
  --accent: #7c6cff;
  --accent2: #ff7ac6;
  --good: #4ade80;
  --radius: 16px;
}

html, body { height: 100%; }

body {
  font-family: "Segoe UI", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 20% -10%, #232a52 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

.screen {
  display: none;
  width: 100%;
  max-width: 560px;
  padding: 24px 18px 40px;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.screen.active { display: flex; }

.hidden { display: none !important; }

/* ---------- 首頁 ---------- */
.home-header { text-align: center; margin-top: 8px; }
.home-header h1 {
  font-size: 2rem;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { color: var(--muted); margin-top: 6px; font-size: .95rem; }

.panel {
  width: 100%;
  background: var(--panel);
  border: 1px solid #2c3152;
  border-radius: var(--radius);
  padding: 14px 16px 16px;
}
.panel h2 { font-size: .95rem; color: var(--muted); font-weight: 600; margin-bottom: 10px; }

.theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.theme-btn {
  background: var(--panel2);
  border: 2px solid transparent;
  border-radius: 12px;
  color: var(--text);
  padding: 10px 4px;
  font-size: .8rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform .1s, border-color .15s;
}
.theme-btn .emoji { font-size: 1.5rem; }
.theme-btn:active { transform: scale(.95); }
.theme-btn.selected { border-color: var(--accent); background: #2e2a5e; }

.option-row { display: flex; gap: 8px; }
.opt-btn {
  flex: 1;
  background: var(--panel2);
  border: 2px solid transparent;
  border-radius: 12px;
  color: var(--text);
  padding: 12px 6px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  transition: transform .1s, border-color .15s;
}
.opt-btn small { color: var(--muted); font-weight: 400; font-size: .72rem; }
.opt-btn:active { transform: scale(.97); }
.opt-btn.selected { border-color: var(--accent); background: #2e2a5e; }

.big-btn {
  width: 100%;
  padding: 16px;
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(124, 108, 255, .35);
  transition: transform .1s;
}
.big-btn:active { transform: scale(.98); }

.text-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: .95rem;
  cursor: pointer;
  padding: 6px 12px;
}
.text-btn:hover { color: var(--text); }

.stats-bar { color: var(--muted); font-size: .8rem; text-align: center; }

/* ---------- 載入 ---------- */
#screen-loading { justify-content: center; min-height: 100dvh; }
.loading-box { text-align: center; }
.loading-art {
  font-size: 4rem;
  animation: bounce 1s ease-in-out infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0) rotate(-8deg); }
  50% { transform: translateY(-14px) rotate(8deg); }
}
#loading-text { margin: 16px 0; color: var(--muted); }
.progress {
  width: 220px;
  height: 8px;
  background: var(--panel2);
  border-radius: 99px;
  overflow: hidden;
  margin: 0 auto;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 99px;
  transition: width .4s;
}

/* ---------- 遊戲 ---------- */
.game-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid #2c3152;
  background: var(--panel);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:active { background: var(--panel2); }
.game-info {
  display: flex;
  gap: 16px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  background: var(--panel);
  border: 1px solid #2c3152;
  padding: 10px 18px;
  border-radius: 12px;
}

#board-wrap {
  position: relative;
  width: min(92vw, 480px, 62dvh);
  aspect-ratio: 1;
}
#board {
  position: absolute;
  inset: 0;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid #2c3152;
  overflow: hidden;
}
.tile {
  position: absolute;
  background-repeat: no-repeat;
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.35);
  cursor: pointer;
  transition: transform .16s ease;
  user-select: none;
}
.tile.selected-tile {
  z-index: 2;
  box-shadow: inset 0 0 0 3px var(--accent2), 0 0 16px rgba(255,122,198,.6);
}
.tile.hint-tile {
  z-index: 2;
  box-shadow: inset 0 0 0 3px var(--good), 0 0 16px rgba(74,222,128,.6);
}
.tile.correct { box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
#board.swap-mode .tile.correct::after {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 6px rgba(74,222,128,.9);
}

#peek-overlay {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background-size: cover;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
  z-index: 5;
}
#peek-overlay.show { opacity: 1; }

.game-bottom { display: flex; gap: 10px; }
.small-btn {
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid #2c3152;
  background: var(--panel);
  color: var(--text);
  font-size: .9rem;
  cursor: pointer;
}
.small-btn:active { background: var(--panel2); }

.ai-note { color: #fbbf24; font-size: .8rem; }

/* ---------- 完成 ---------- */
#screen-win { justify-content: center; min-height: 100dvh; }
.win-box {
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.win-box h2 { font-size: 1.6rem; }
#win-img {
  width: min(80vw, 340px);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  animation: pop .4s ease;
}
@keyframes pop {
  from { transform: scale(.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.win-stats {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 340px;
}
.win-stats > div {
  flex: 1;
  background: var(--panel);
  border: 1px solid #2c3152;
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.win-stats b { font-size: 1.1rem; }
.win-stats span { color: var(--muted); font-size: .75rem; }
.new-record { color: var(--good); font-weight: 700; }

/* ---------- 圖鑑 ---------- */
.gallery-title { font-size: 1.1rem; }
.gallery-hint { color: var(--muted); font-size: .85rem; text-align: center; }
#gallery-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.gallery-item {
  background: var(--panel);
  border: 1px solid #2c3152;
  border-radius: 12px;
  overflow: hidden;
  text-align: center;
}
.gallery-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.gallery-item .meta { font-size: .68rem; color: var(--muted); padding: 5px 4px; }

@media (max-width: 400px) {
  .theme-grid { grid-template-columns: repeat(4, 1fr); }
  .theme-btn { font-size: .72rem; }
}
