/* ============================================================
   《圓柱宇宙觀測站》主要樣式：變數、版面、畫面切換、RWD
   ============================================================ */
:root {
  --bg0: #070b24;
  --bg1: #101c4d;
  --text: #eef6ff;
  --muted: #b3c4e8;
  --accent: #38e8ff;
  --accent2: #8b7bff;
  --accent-ink: #04122b;
  --card: rgba(255, 255, 255, 0.09);
  --card-strong: rgba(18, 28, 78, 0.92);
  --line: rgba(255, 255, 255, 0.2);
  --good: #5df2a8;
  --bad: #ff8d8d;
  --warn: #ffd166;
  --pink: #ff6bd6;
  --radius: 18px;
  --footer-h: 46px;
  --toolbar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

#game[data-chapter="2"] { --accent: #ff9f6b; --accent2: #ff6bd6; --accent-ink: #2a0c10; }
#game[data-chapter="3"] { --accent: #ffd166; --accent2: #7dffb2; --accent-ink: #2a2005; }
#game[data-chapter="4"] { --accent: #d58bff; --accent2: #ff6bd6; --accent-ink: #1d0a2e; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg0);
  background-image: radial-gradient(1200px 700px at 80% -10%, #1d2f7a 0%, transparent 60%),
    radial-gradient(900px 600px at 0% 100%, #2a1360 0%, transparent 60%);
  background-attachment: fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 17px;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

img { max-width: 100%; }
button { font: inherit; color: inherit; }
b { font-weight: 800; }
h1, h2, h3 { margin: 0; line-height: 1.25; }

a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--warn); outline-offset: 2px; border-radius: 8px; }
[tabindex="-1"]:focus, [tabindex="-1"]:focus-visible { outline: none; }

/* ---------- 背景星空 ---------- */
.cosmos { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.starfield { position: absolute; inset: 0; }
.cosmos::after { content: ""; position: absolute; inset: 0; background-image: var(--chapter-bg, none); background-size: cover; background-position: center; opacity: 0.2; }
.star { position: absolute; border-radius: 50%; background: #fff; opacity: 0.8; }

/* ---------- 全域工具列 ---------- */
.toolbar {
  position: fixed;
  top: calc(6px + var(--safe-top));
  right: calc(8px + env(safe-area-inset-right, 0px));
  z-index: 60;
  display: flex;
  gap: 8px;
}
.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(14, 22, 66, 0.82);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text);
  padding: 0;
  transition: transform 0.15s, background 0.2s;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:hover { background: rgba(40, 56, 130, 0.95); }
.icon-btn:active { transform: scale(0.92); }

/* ---------- 畫面 ---------- */
.game { position: relative; min-height: 100vh; min-height: 100dvh; }
.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(var(--toolbar-h) + var(--safe-top)) 16px calc(var(--footer-h) + 18px + var(--safe-bottom));
  max-width: 1120px;
  margin: 0 auto;
}
.screen.is-active { display: block; animation: screenIn 0.35s ease backwards; }

/* ---------- 固定頁尾 ---------- */
.site-footer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 130;
  min-height: var(--footer-h);
  padding: 6px 14px calc(6px + var(--safe-bottom));
  background: rgba(5, 8, 28, 0.94);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
  text-align: center;
  display: block;
}
.site-footer a { color: #8be9ff; font-weight: 700; }

/* ---------- 首頁 ---------- */
.screen--home { max-width: none; padding-left: 0; padding-right: 0; position: relative; overflow: hidden; }
.home__bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 30%; opacity: 0.9; }
.home__shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(7, 11, 36, 0.35) 0%, rgba(7, 11, 36, 0.55) 45%, rgba(7, 11, 36, 0.92) 100%); }
.home {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 4vh 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
}
.home__kicker { margin: 0; color: var(--accent); font-weight: 800; letter-spacing: 0.08em; font-size: 15px; text-shadow: 0 2px 8px #000; }
.home__title { display: flex; flex-direction: column; font-size: clamp(44px, 11vw, 88px); font-weight: 900; line-height: 1.05; text-shadow: 0 4px 24px rgba(56, 232, 255, 0.55), 0 2px 0 #031030; }
.home__title span:last-child { background: linear-gradient(90deg, var(--accent), #ffd166); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.6)); }
.home__tagline { margin: 0; max-width: 30em; color: #dbe8ff; text-shadow: 0 2px 8px #000; font-size: 18px; }
.home__cta { margin-top: 10px; }
.home__progress { color: #dbe8ff; font-weight: 700; min-height: 1.6em; text-shadow: 0 2px 8px #000; }
.home__mascot { width: 140px; height: 140px; object-fit: contain; filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.5)); }

/* ---------- 上方列 ---------- */
.topbar, .playbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.topbar__title { flex: 1; min-width: 0; }
.topbar__kicker { color: var(--accent); font-size: 13px; font-weight: 800; letter-spacing: 0.06em; }
.topbar h2 { font-size: 24px; }
.topbar__stats { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- 星圖 ---------- */
.chapter-list { display: grid; gap: 20px; }
.chapter { border: 1px solid var(--line); border-radius: 22px; overflow: hidden; background: rgba(8, 14, 46, 0.7); }
.chapter__banner {
  position: relative; padding: 18px 18px 14px; min-height: 92px;
  background-size: cover; background-position: center;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.chapter__banner::before { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(5, 8, 30, 0.9), rgba(5, 8, 30, 0.45)); }
.chapter__banner > * { position: relative; }
.chapter__name { font-size: 22px; font-weight: 900; color: var(--c1); }
.chapter__desc { color: #dbe8ff; font-size: 14px; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; padding: 14px; }

/* ---------- 關卡介紹 ---------- */
.intro { display: grid; place-items: center; padding-top: 8px; }
.intro__card { width: min(720px, 100%); background: var(--card-strong); border: 1px solid var(--line); border-radius: 24px; padding: 22px; display: grid; gap: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.intro__head { display: flex; gap: 16px; align-items: center; }
.intro__img { width: 110px; height: 110px; object-fit: contain; flex: none; filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.5)); }
.intro__card h2 { font-size: 28px; }
.intro__topic { margin: 2px 0 0; color: var(--accent); font-weight: 700; }
.intro__story { margin: 0; font-size: 18px; }
.intro__task { margin: 0; padding: 10px 14px; border-radius: 12px; background: rgba(255, 255, 255, 0.08); }
.intro__meta { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.intro__meta li { padding: 6px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.1); font-size: 14px; }
.intro__actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; }

/* ---------- 答題 ---------- */
.playbar__info { flex: 1; min-width: 0; display: grid; gap: 6px; }
.playbar__level { font-weight: 900; font-size: 18px; }
.dots { display: flex; gap: 6px; }
.dots i { flex: 1; max-width: 34px; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.2); }
.dots i.is-done { background: var(--good); }
.dots i.is-now { background: var(--accent); box-shadow: 0 0 10px var(--accent); }

.hud { display: flex; gap: 10px; align-items: stretch; margin-bottom: 12px; }
.hud__cell { min-width: 84px; padding: 4px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); display: grid; align-content: center; text-align: center; }
.hud__label { font-size: 12px; color: var(--muted); }
.hud__cell b { font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.hud__timer { flex: 1; padding: 6px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); display: grid; align-content: center; gap: 4px; }
.timer__bar { height: 12px; border-radius: 6px; background: rgba(255, 255, 255, 0.16); overflow: hidden; }
.timer__bar i { display: block; height: 100%; width: 100%; transform-origin: left; background: var(--good); border-radius: 6px; transition: background 0.3s; }
.timer__num { font-size: 13px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

.play-stage { display: grid; gap: 14px; grid-template-columns: 1fr; align-items: start; }
.play-visual-wrap { background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: grid; place-items: center; min-height: 150px; }
.play-visual { width: 100%; max-width: 520px; display: grid; justify-items: center; }
.play-panel { display: grid; gap: 12px; }

/* ---------- 結算 ---------- */
.result { display: grid; place-items: center; padding-top: 6px; }
.result__card { width: min(640px, 100%); background: var(--card-strong); border: 1px solid var(--line); border-radius: 26px; padding: 24px 20px; text-align: center; display: grid; gap: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.result__kicker { margin: 0; color: var(--accent); font-weight: 800; letter-spacing: 0.08em; }
.result__card h2 { font-size: 32px; }
.result__sub { margin: 0; color: #dbe8ff; }
.result__actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

@media (min-width: 900px) {
  .play-stage { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
  .play-visual-wrap { position: sticky; top: calc(var(--toolbar-h) + 6px); min-height: 280px; }
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  .screen { padding-left: 12px; padding-right: 12px; }
  .topbar h2 { font-size: 20px; }
  .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 10px; gap: 10px; }
  .intro__head { flex-direction: row; }
  .intro__img { width: 84px; height: 84px; }
  .intro__card h2 { font-size: 23px; }
  .home__title { font-size: 46px; }
  .site-footer { font-size: 11.5px; }
}
