/* ============================================================
   因數分數魔法城堡 — 基礎樣式：變數、重設、版面、畫面切換、RWD
   ============================================================ */
:root {
  --bg0: #140d33;
  --bg1: #1d1450;
  --panel: rgba(30, 21, 76, 0.82);
  --panel-solid: #261b66;
  --panel-2: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.16);
  --text: #fff8ea;
  --muted: #cdc3f2;
  --gold: #ffd166;
  --gold-d: #f4a62a;
  --mint: #3ee0a9;
  --coral: #ff6f86;
  --sky: #5cc8ff;
  --violet: #a78bfa;
  --accent: #ffd166;
  --accent-2: #f4a62a;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(8, 4, 30, 0.45);
  --footer-h: 30px;
  --gutter: max(16px, env(safe-area-inset-left, 0px));
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", "Hiragino Sans TC", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

#app[data-area="1"] { --accent: #f6b73c; --accent-2: #d98a14; }
#app[data-area="2"] { --accent: #35c7d9; --accent-2: #1d8fb0; }
#app[data-area="3"] { --accent: #ff8a4c; --accent-2: #d95a2b; }
#app[data-area="4"] { --accent: #a78bfa; --accent-2: #7c5ce0; }

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

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg0);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body { overflow: hidden; background: var(--bg0); }

h1, h2, h3, p, ul, ol, dl, dd { margin: 0; padding: 0; }
ul, ol { list-style: none; }
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--gold); }
[hidden] { display: none !important; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico { width: 1.35em; height: 1.35em; fill: currentColor; flex: none; }
.ico--star { fill: var(--gold); }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ---------- 應用外框 ---------- */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg0);
  overflow: hidden;
}

.bg {
  position: absolute;
  inset: 0;
  background: var(--bg1) center / cover no-repeat;
  transition: opacity 0.5s ease;
}
.bg-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(20, 13, 51, 0.5) 0%, rgba(20, 13, 51, 0.78) 60%, rgba(20, 13, 51, 0.9) 100%);
  pointer-events: none;
}
#app[data-screen="home"] .bg-shade {
  background: linear-gradient(180deg, rgba(20, 13, 51, 0.15) 0%, rgba(20, 13, 51, 0.35) 55%, rgba(20, 13, 51, 0.82) 100%);
}
#app[data-screen="ending"] .bg-shade {
  background: linear-gradient(180deg, rgba(20, 13, 51, 0.2), rgba(20, 13, 51, 0.7));
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  min-height: 0;
}
.screen.is-active {
  display: flex;
  animation: screen-in 0.35s ease both;
}

.screen__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px var(--gutter) 24px;
  -webkit-overflow-scrolling: touch;
}

/* ---------- 頂列 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--gutter) 6px;
  padding-top: max(10px, env(safe-area-inset-top, 0px));
}
.topbar__title { flex: 1; min-width: 0; }
.topbar__title h1 {
  font-size: clamp(1.05rem, 3.6vw, 1.5rem);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__kicker {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__spacer { flex: 1; }

.tools { display: flex; gap: 6px; align-items: center; }
.tools--play { gap: 6px; }
.tools [data-tools-inline] { display: contents; }

/* ---------- 頁尾（所有畫面固定顯示） ---------- */
.site-footer {
  position: relative;
  z-index: 5;
  flex: none;
  min-height: var(--footer-h);
  padding: 4px var(--gutter);
  padding-bottom: max(4px, env(safe-area-inset-bottom, 0px));
  background: rgba(14, 8, 38, 0.92);
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 0.75rem;
  line-height: 1.35;
  color: #e4dcff;
}
.site-footer a { color: var(--gold); display: inline-block; min-height: 44px; box-sizing: border-box; padding: 15px 4px; margin: -15px 0; }

/* ---------- 工具與狀態 ---------- */
.noscript {
  position: fixed;
  inset: auto 16px 48px;
  z-index: 99;
  background: #fff;
  color: #111;
  padding: 16px;
  border-radius: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--footer-h) + 22px);
  z-index: 80;
  max-width: min(92vw, 520px);
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(255, 248, 234, 0.96);
  color: #2a1b63;
  font-weight: 700;
  box-shadow: var(--shadow);
  transform: translate(-50%, 24px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

.fx {
  position: fixed;
  inset: 0;
  z-index: 70;
  pointer-events: none;
  overflow: hidden;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 響應式 ---------- */
@media (max-width: 520px) {
  .site-footer { font-size: 0.7rem; }
}
