:root {
  --bg: #12142b;
  --bg2: #1c1f3d;
  --fg: #ffffff;
  --muted: #b9bdd6;
  --accent: #ff2e7e;
  --accent-2: #ffd23f;
  --card: #262a4f;
  --radius: 18px;
  --gutter: max(16px, env(safe-area-inset-left));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 80% at 70% 0%, #2a2f63 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--fg);
  font-family: system-ui, "Noto Sans TC", sans-serif;
  user-select: none; -webkit-user-select: none;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }

/* ---- 頂列 ---- */
.top {
  position: absolute; z-index: 5; inset: 0 0 auto 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) var(--gutter) 10px;
  background: linear-gradient(rgba(18, 20, 43, .85), rgba(18, 20, 43, 0));
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 22px; letter-spacing: 1px; text-shadow: 0 2px 6px rgba(0, 0, 0, .4); }
.brand svg { width: 40px; height: 40px; }

/* 家長鎖：低調、長按 3 秒 */
.parent-lock {
  position: relative; width: 52px; height: 52px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, .12);
  display: grid; place-items: center; font-size: 22px; opacity: .7;
}
.parent-lock .ring {
  position: absolute; inset: -4px; border-radius: 50%;
  background: conic-gradient(var(--accent-2) calc(var(--p, 0) * 1turn), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 27px, #000 28px);
          mask: radial-gradient(circle, transparent 27px, #000 28px);
}
.parent-lock.holding { opacity: 1; }

/* ---- Hero 大橫幅 ---- */
.hero {
  position: relative;
  height: min(68vh, 56.25vw + 40px);
  min-height: 300px;
  overflow: hidden;
  touch-action: pan-y;
}
.hero-art img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: 75% 50%;
  opacity: 0; transition: opacity .45s ease, transform 6s ease-out;
  transform: scale(1.04);
}
.hero-art img.show { opacity: 1; transform: scale(1); }
.hero-shade {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(90deg, rgba(18, 20, 43, .92) 0%, rgba(18, 20, 43, .55) 32%, rgba(18, 20, 43, 0) 55%),
    linear-gradient(0deg, var(--bg) 0%, rgba(18, 20, 43, 0) 28%);
}
/* 橫向：整張橫幅靠右完整顯示（不裁掉主角），左緣淡入深色底 */
@media (orientation: landscape) {
  .hero-art img {
    left: auto; right: 0; width: auto; max-width: 100%;
    object-fit: cover; object-position: 100% 50%;
    -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 22%);
            mask-image: linear-gradient(90deg, transparent 0%, #000 22%);
  }
}
.hero-info {
  position: absolute; left: calc(var(--gutter) + 76px); bottom: 12%;
  width: min(44%, 560px);
  display: flex; flex-direction: column; align-items: flex-start; gap: 12px;
}
.hero-info.swap { animation: infoIn .45s ease; }
.title {
  margin: 0; font-size: clamp(34px, 5.2vw, 72px); line-height: 1.08; font-weight: 900;
  letter-spacing: 2px; text-shadow: 0 4px 16px rgba(0, 0, 0, .55);
}
.tagline { margin: 0; font-size: clamp(16px, 1.8vw, 24px); color: var(--accent-2); font-weight: 700; text-shadow: 0 2px 8px rgba(0, 0, 0, .5); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font-size: 15px; font-weight: 800; padding: 4px 12px; border-radius: 999px; background: rgba(255, 255, 255, .16); backdrop-filter: blur(4px); }
.chip.fav { background: var(--accent-2); color: #3b2a00; }
.chip.web { background: rgba(92, 200, 255, .25); }
.chip.ok { background: rgba(34, 197, 94, .32); }
.card .badges span[hidden], .pin[hidden] { display: none; }   /* display:grid 會蓋過 hidden 屬性 */
/* 開始玩＋放到桌面（次要、給家長） */
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.actions .play { margin-top: 0; }
.pin {
  min-height: 52px; padding: 0 20px; border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, .35); background: rgba(18, 20, 43, .45);
  color: #fff; font-size: 17px; font-weight: 800; backdrop-filter: blur(4px);
}
.pin:active { transform: scale(.96); }
/* URL 模式的遊戲在離線時變灰 */
.card.needs-net .thumb { filter: grayscale(1) brightness(.6); }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 140%); z-index: 50;
  background: #fff; color: #222; font-weight: 800; font-size: 18px;
  padding: 12px 22px; border-radius: 999px; box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
  transition: transform .3s;
}
.toast.show { animation: toastShow 2.6s ease forwards; }
@keyframes toastShow { 10%, 85% { transform: translate(-50%, 0); } 100% { transform: translate(-50%, 140%); } }
.play {
  margin-top: 4px;
  display: inline-flex; align-items: center; gap: 12px;
  min-height: 76px; padding: 0 34px 0 26px;
  border: 0; border-radius: 999px;
  background: var(--accent); color: #fff;
  font-size: 28px; font-weight: 900; letter-spacing: 2px;
  box-shadow: 0 6px 0 #b8155a, 0 10px 30px rgba(255, 46, 126, .45);
  animation: breathe 2.4s ease-in-out infinite;
}
.play .tri { font-size: 30px; }
.play:active { transform: translateY(5px); box-shadow: 0 1px 0 #b8155a; animation: none; }

.nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 64px; height: 64px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .35); color: #fff; font-size: 44px; line-height: 1;
  display: grid; place-items: center; padding-bottom: 6px;
}
.nav.prev { left: 8px; }
.nav.next { right: 8px; }
.nav:active { background: rgba(0, 0, 0, .6); }

/* ---- 縮圖列 ---- */
.rail {
  display: flex; gap: 14px;
  padding: 14px var(--gutter) max(24px, env(safe-area-inset-bottom));
  overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding: 0 var(--gutter);
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.card {
  flex: 0 0 auto;
  width: clamp(200px, 22vw, 320px);
  scroll-snap-align: start;
  border: 0; padding: 0; background: none; text-align: left;
  transition: transform .2s;
}
.card .thumb {
  position: relative; display: block;
  aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden;
  background: var(--card);
  outline: 4px solid transparent; outline-offset: 0;
  transition: outline-color .2s, box-shadow .2s;
}
.card img { width: 100%; height: 100%; object-fit: cover; object-position: 80% 50%; display: block; }
.card .badges { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; }
.card .badges span { font-size: 18px; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: rgba(18, 20, 43, .7); }
.card .name { display: block; margin-top: 8px; font-weight: 800; font-size: 18px; color: var(--muted); padding-left: 4px; }
.card.on { transform: translateY(-4px); }
.card.on .thumb { outline-color: var(--accent); box-shadow: 0 10px 30px rgba(255, 46, 126, .35); }
.card.on .name { color: #fff; }
.card:active { transform: scale(.97); }

/* ---- 直向（手機）：圖在上、文字在下，不疊在插畫上 ---- */
@media (orientation: portrait) {
  .actions { align-items: stretch; }
  .actions .play { flex: 1 1 auto; }
  .hero { height: auto; min-height: 0; display: flex; flex-direction: column; }
  .hero-art { position: relative; aspect-ratio: 4 / 3.2; }
  .hero-art img { object-position: 82% 50%; }
  .hero-shade { background: linear-gradient(0deg, var(--bg) 0%, rgba(18, 20, 43, 0) 30%), linear-gradient(180deg, rgba(18, 20, 43, .6) 0%, rgba(18, 20, 43, 0) 25%); height: calc(100vw * 3.2 / 4 + 2px); }
  .hero-info { position: relative; left: auto; bottom: auto; width: auto; padding: 0 var(--gutter); margin-top: -36px; align-items: stretch; }
  .play { justify-content: center; }
  .nav { top: calc(100vw * 3.2 / 4 / 2); }
  .card { width: 46vw; }
}
@media (orientation: portrait) and (min-width: 700px) {
  .card { width: 30vw; }
  .hero-info { align-items: flex-start; }
}
/* 矮的橫向（手機橫放） */
@media (orientation: landscape) and (max-height: 520px) {
  .hero { height: 70vh; min-height: 0; }
  .hero-info { bottom: 10%; gap: 6px; }
  .title { font-size: 34px; }
  .tagline { font-size: 15px; }
  .play { min-height: 60px; font-size: 22px; padding: 0 24px 0 20px; }
  .card { width: 150px; }
  .card .name { font-size: 14px; margin-top: 4px; }
  .rail { padding-top: 6px; }
  .brand { font-size: 18px; }
}

/* ---- 家長對話框 ---- */
dialog.sheet {
  border: 0; border-radius: 24px; padding: 0;
  background: #fff; color: #222;
  width: min(92vw, 560px); max-height: 88vh;
}
dialog.sheet::backdrop { background: rgba(8, 10, 25, .7); }
.quiz-form { padding: 24px; text-align: center; }
.quiz-form h2 { margin: 0 0 6px; }
.quiz-form .q { font-size: 40px; font-weight: 900; margin: 8px 0 12px; }
.quiz-form .ans { width: 100%; font-size: 32px; text-align: center; padding: 10px; border: 3px solid #ddd; border-radius: 14px; }
.quiz-form.wrong .ans { border-color: #ef4444; animation: shake .35s; }
.row { display: flex; gap: 10px; margin-top: 16px; }
.row button, .parent-body button { flex: 1; min-height: 52px; border-radius: 14px; border: 0; font-weight: 800; font-size: 18px; }
.primary { background: var(--accent); color: #fff; }
.ghost { background: #eee; }

.parent-body { padding: 18px 22px 24px; }
.parent-body header { display: flex; justify-content: space-between; align-items: center; }
.parent-body h2 { margin: 0; }
.parent-body h3 { margin: 18px 0 6px; font-size: 16px; color: #555; }
.parent-body .close { flex: 0 0 48px; background: #eee; border-radius: 50%; }
.parent-body .hint { margin: 0 0 8px; font-size: 14px; color: #888; }
.games-data { list-style: none; margin: 0; padding: 0; }
.games-data li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid #eee; }
.games-data img { width: 44px; height: 44px; border-radius: 10px; }
.games-data .meta { flex: 1; }
.games-data .meta b { display: block; }
.games-data .meta small { display: block; line-height: 1.4; }
.games-data .off-text { color: #2563eb; }
.games-data .btns { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
.install-lobby { width: 100%; background: #12142b; color: #fff; }
.games-data .meta small { color: #888; }
.games-data button { flex: 0 0 auto; min-height: 44px; padding: 0 16px; background: #fde8ef; color: #b8155a; font-size: 15px; }
.games-data button:disabled { opacity: .4; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.switch input { width: 26px; height: 26px; accent-color: var(--accent); }
.stickers { display: flex; flex-wrap: wrap; gap: 6px; font-size: 34px; min-height: 44px; }
.stickers .empty { font-size: 15px; color: #999; }

@keyframes breathe { 50% { transform: scale(1.04); } }
@keyframes infoIn { from { opacity: 0; transform: translateX(-24px); } }
@keyframes shake { 25%, 75% { transform: translateX(-8px); } 50% { transform: translateX(8px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
