/* ============================================================
   《比例極速賽車場》基礎樣式：變數、版面、背景、頁尾、螢幕切換
   ============================================================ */
:root {
  --bg: #0b1226;
  --bg-2: #121b3a;
  --panel: #18235a;
  --panel-2: #1f2d6e;
  --line: rgba(255, 255, 255, 0.16);
  --text: #f4f7ff;
  --muted: #b4c0e6;
  --yellow: #ffd23f;
  --orange: #ff8a3d;
  --red: #ff5a5f;
  --green: #34d399;
  --cyan: #38bdf8;
  --teal: #2dd4bf;
  --gold: #fbbf24;
  --accent: var(--orange);
  --radius: 18px;
  --footer-h: 34px;
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", system-ui, -apple-system, "Segoe UI", sans-serif;
}
.app[data-zone="1"] { --accent: #ff8a3d; }
.app[data-zone="2"] { --accent: #2dd4bf; }
.app[data-zone="3"] { --accent: #38bdf8; }
.app[data-zone="4"] { --accent: #fbbf24; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; }
button { font-family: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

.app { position: relative; min-height: 100dvh; display: flex; flex-direction: column; }

/* 背景圖（依賽區切換）+ 暗化漸層，確保文字對比 */
.bg {
  position: fixed; inset: 0; z-index: 0;
  background: var(--bg) center / cover no-repeat;
  transition: background-image 0.4s ease, opacity 0.4s ease;
}
.bg::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(8, 13, 32, 0.55) 0%, rgba(8, 13, 32, 0.78) 55%, rgba(8, 13, 32, 0.9) 100%);
}
.app[data-screen="home"] .bg::after { background: linear-gradient(180deg, rgba(8, 13, 32, 0.05) 0%, rgba(8, 13, 32, 0.15) 45%, rgba(8, 13, 32, 0.85) 100%); }

/* 常駐工具列 */
.toolbar {
  position: fixed; z-index: 60;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  right: calc(env(safe-area-inset-right, 0px) + 10px);
  display: flex; gap: 8px;
}
.icon-btn {
  width: 44px; height: 44px; min-width: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 1px solid var(--line);
  background: rgba(13, 20, 48, 0.78); color: var(--text);
  cursor: pointer; backdrop-filter: blur(6px);
  transition: transform 0.12s ease, background 0.2s ease;
}
.icon-btn:hover { background: rgba(40, 56, 120, 0.9); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn[aria-pressed="false"] { opacity: 0.6; }
.icon-btn--sm { width: 44px; height: 44px; min-width: 44px; }

.game { position: relative; z-index: 1; flex: 1 0 auto; padding-bottom: calc(var(--footer-h) + env(safe-area-inset-bottom, 0px) + 8px); }
.screen { display: none; width: 100%; padding: calc(env(safe-area-inset-top, 0px) + 56px) 16px 16px; }
.screen.is-active { display: block; animation: screenIn 0.35s ease both; }

/* 頁尾：固定於所有畫面底部。z-index 高於計算紙、進站維修、倒數等遮罩，任何畫面都不會被遮暗 */
.site-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 95;
  min-height: var(--footer-h);
  padding: 4px 12px calc(4px + env(safe-area-inset-bottom, 0px));
  text-align: center; font-size: 12px; line-height: 1.4;
  color: #dbe3ff; background: rgba(8, 12, 30, 0.92);
  border-top: 1px solid var(--line);
}
.site-footer a { color: var(--yellow); text-underline-offset: 2px; }

@media (max-width: 600px) { :root { --footer-h: 48px; } .site-footer { font-size: 11.5px; } }
.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) + 18px); z-index: 90;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 460px); padding: 10px 18px; border-radius: 999px;
  background: rgba(20, 30, 70, 0.96); border: 1px solid var(--line); text-align: center; font-weight: 700;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

.confetti { position: fixed; inset: 0; z-index: 80; pointer-events: none; overflow: hidden; }
.flash { position: fixed; inset: 0; z-index: 85; pointer-events: none; opacity: 0; background: radial-gradient(circle at 50% 45%, rgba(255, 245, 160, 0.95), rgba(255, 138, 61, 0.55) 45%, rgba(255, 138, 61, 0) 75%); }
.flash.is-on { animation: flashBurst 1.4s ease-out both; }

/* 主畫面 */
.screen--home { padding: 0; }
.home { position: relative; min-height: calc(100dvh - var(--footer-h)); overflow: hidden; }
.home__art { position: absolute; inset: 0; background: url("../assets/img/hero.webp") 42% 50% / cover no-repeat; }
.home__panel { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; justify-content: space-between; align-items: center; text-align: center; padding: calc(env(safe-area-inset-top, 0px) + 58px) 16px 20px; }
.home__top, .home__bottom { display: flex; flex-direction: column; align-items: center; }
.home__kicker { margin: 0 0 4px; color: #fff; font-weight: 800; letter-spacing: 0.08em; font-size: 0.95rem; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8), 0 0 14px rgba(0, 0, 0, 0.5); }
.home__title { margin: 0; display: flex; flex-direction: column; line-height: 1.05; font-weight: 900; text-shadow: 0 4px 0 #b3261e, 0 8px 24px rgba(0, 0, 0, 0.55); }
.home__title span:first-child { font-size: clamp(2.2rem, min(10vw, 10vh), 4.2rem); color: #fff; }
.home__title span:last-child { font-size: clamp(2rem, min(9vw, 9vh), 3.8rem); color: var(--yellow); font-style: italic; }
.home__tagline { margin: 0 0 14px; max-width: 28em; font-weight: 800; color: #fff; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.95), 0 0 16px rgba(0, 0, 0, 0.8); }
.home__progress { margin: 10px 0 0; color: #fff; font-weight: 800; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.95); min-height: 1.6em; }
@media (max-width: 640px) { .home__art { background-position: 40% 50%; } }

.topbar { display: flex; align-items: center; gap: 12px; max-width: 1040px; margin: 0 auto 14px; padding-right: 150px; }
.topbar__title h2 { margin: 0; font-size: 1.5rem; line-height: 1.2; }
.topbar__sub { margin: 0; color: var(--muted); font-size: 0.9rem; }
@media (max-width: 520px) { .topbar { padding-right: 0; flex-wrap: wrap; margin-top: 8px; } }
