/* 點亮星空：玩家網頁樣式。預設是深藍「黃昏」主題，body.night 是觀星用的紅光模式 */

:root {
  --bg: #0f1631;
  --bg2: #141c3e;
  --card: #1a2350;
  --line: #2d3a72;
  --text: #eef1f8;
  --muted: #a9b4d3;
  --accent: #f2c14e;
  --accent-ink: #1d1500;
  --ok: #6fd69a;
  --bad: #ff8b7d;
  --qr-bg: #ffffff;
  --qr-fg: #0f1631;
  --star: #f2c14e;
  --star-off: #3a4677;
  --radius: 16px;
  color-scheme: dark;
}

/* 紅光夜間模式：全部只用暗紅色，保護暗適應、不干擾天文攝影 */
body.night {
  --bg: #000000;
  --bg2: #070101;
  --card: #120404;
  --line: #3a0d0a;
  --text: #d9473a;
  --muted: #9a3329;
  --accent: #e5483a;
  --accent-ink: #0a0000;
  --ok: #e5483a;
  --bad: #e5483a;
  --qr-bg: #a32418;
  --qr-fg: #000000;
  --star: #e5483a;
  --star-off: #2a0907;
}
body.night .em,
body.night img,
body.night video {
  filter: grayscale(1) sepia(1) saturate(5) hue-rotate(-40deg) brightness(0.5);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.3; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.12rem; display: flex; align-items: baseline; gap: .5em; flex-wrap: wrap; }
h2 small { font-size: .78rem; font-weight: 400; color: var(--muted); }
p { margin: .4em 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.fine { font-size: .82rem; color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .02em; }
.center { text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5em; }
#app > .center { min-height: 80vh; }
.error { color: var(--bad); font-weight: 600; }
.ok-text { color: var(--ok); font-weight: 600; }
.bad-text { color: var(--bad); font-weight: 600; }
.hint { background: var(--bg2); border-left: 3px solid var(--accent); padding: .5em .8em; border-radius: 8px; font-size: .92rem; }
[hidden] { display: none !important; }

/* ---------- 版面 ---------- */
.page { max-width: 560px; margin: 0 auto; padding: 24px 16px 48px; }
.page.narrow { max-width: 440px; }
.pagehead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.hero { text-align: center; padding: 28px 0 16px; }
.hero h1 { font-size: 2rem; letter-spacing: .08em; }
.logo { font-size: 2.6rem; color: var(--accent); line-height: 1; margin-bottom: 8px; }
.logo.ok { color: var(--ok); }
.logo.bad { color: var(--bad); }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.notice { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.notice.bad { border-color: var(--bad); }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.actions.wrap { flex-wrap: wrap; }
.actions .btn { flex: 1; }

/* ---------- 按鈕與表單 ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--bg2);
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.link { background: none; border: none; color: var(--muted); text-decoration: underline; min-height: 40px; padding: 8px 4px; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .9rem; border-radius: 10px; }
.btn.block { display: flex; width: 100%; margin: 10px 0; }
.btn:disabled { opacity: .5; }
.iconbtn { background: none; border: none; font-size: 1.4rem; padding: 6px 8px; cursor: pointer; color: var(--muted); min-width: 44px; min-height: 44px; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; font-weight: 600; }
.field small { font-weight: 400; color: var(--muted); font-size: .82rem; }
input, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-weight: 400;
  min-height: 46px;
}
input:focus, select:focus, .btn:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.check { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: center; margin: 14px 0; font-weight: 600; }
.check input { width: 22px; height: 22px; min-height: 0; }
.check small { grid-column: 2; font-weight: 400; color: var(--muted); font-size: .82rem; }
#join-code, #restore-code, #short-input { font-size: 1.3rem; letter-spacing: .12em; text-align: center; text-transform: uppercase; }

.steps { display: flex; gap: 6px; }
.steps span { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; font-size: .85rem; color: var(--muted); }
.steps span.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.steps span.past { color: var(--accent); border-color: var(--accent); }

.avatars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.avatars button { aspect-ratio: 1; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 1.5rem; cursor: pointer; }
.avatars button.on { border: 2px solid var(--accent); background: var(--bg2); }
.photo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.photo-prev { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }

.count { font-size: .85rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; font-weight: 400; }
.count.ok { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.qpick { border: 1px solid var(--line); border-radius: 12px; margin: 8px 0; overflow: hidden; }
.qpick.on { border-color: var(--accent); }
.qhead { width: 100%; text-align: left; background: none; border: none; padding: 12px 14px; display: flex; justify-content: space-between; gap: 10px; cursor: pointer; min-height: 48px; }
.qhead .tick { color: var(--accent); font-weight: 700; }
.qpick input { border: none; border-top: 1px solid var(--line); border-radius: 0; background: var(--bg); }

.recovery { font-size: 1.6rem; text-align: center; letter-spacing: .15em; padding: 12px; border: 1px dashed var(--accent); border-radius: 12px; color: var(--accent); margin: 8px 0; user-select: all; }
.howto { padding-left: 1.3em; }
.howto li, .tips li { margin: .45em 0; }
.tips { padding-left: 1.2em; margin: 0; }

/* ---------- 頭像 ---------- */
.av { width: 40px; height: 40px; border-radius: 50%; background: var(--bg2); border: 1px solid var(--line); display: inline-grid; place-items: center; font-size: 1.3rem; flex: none; overflow: hidden; }
.av.big { width: 56px; height: 56px; font-size: 1.9rem; }
.av img { width: 100%; height: 100%; object-fit: cover; }
.profile-line { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }

/* ---------- 題目與答案 ---------- */
.qa { list-style: none; padding: 0; margin: 8px 0; }
.qa li { display: flex; flex-direction: column; padding: 10px 0; border-top: 1px solid var(--line); }
.qa li:first-child { border-top: none; }
.qa .q { color: var(--muted); font-size: .9rem; }
.qa .a { font-weight: 700; font-size: 1.1rem; }
.qa.left { text-align: left; width: 100%; }
.qlist { padding-left: 1.2em; margin: .4em 0; }
.qlist li { margin: .3em 0; font-weight: 600; }

/* ---------- 主畫面 ---------- */
#main { min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px 16px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; }
.phase { font-size: .72rem; font-weight: 600; border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; color: var(--muted); }
.phase.ph-running { color: var(--ok); border-color: var(--ok); }
.score { font-weight: 800; font-size: 1.25rem; color: var(--accent); font-variant-numeric: tabular-nums; }
.score small { font-size: .7rem; font-weight: 400; margin-left: 2px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.on { background: var(--ok); }
.dot.wait { background: var(--accent); }
.dot.off { background: var(--bad); }
.content { max-width: 560px; margin: 0 auto; padding: 4px 14px 24px; }
#banners { max-width: 560px; margin: 0 auto; padding: 0 14px; }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; padding: 10px 14px; border-radius: 12px; background: var(--bg2); border: 1px solid var(--line); font-size: .92rem; }
.banner.warn { border-color: var(--bad); color: var(--bad); }
.banner.quiz { border: 2px solid var(--accent); }
.banner.quiz b { display: block; color: var(--accent); }
.banner .btn { flex: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--bg); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button { background: none; border: none; padding: 8px 2px 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); position: relative; cursor: pointer; min-height: 60px; }
.tabbar .ti { font-size: 1.35rem; line-height: 1.2; }
.tabbar button.on { color: var(--accent); font-weight: 700; }
.tabbar .badge { position: absolute; top: 4px; right: calc(50% - 22px); background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: .7rem; font-weight: 800; min-width: 18px; padding: 0 5px; }

/* ---------- 我的 QR ---------- */
.qrcard { text-align: center; }
.qrcard .profile-line { justify-content: center; }
#qr { width: min(78vw, 300px); height: auto; aspect-ratio: 1; border-radius: 14px; display: block; margin: 8px auto; }
.qrbar { height: 4px; width: min(78vw, 300px); margin: 0 auto 10px; background: var(--line); border-radius: 2px; overflow: hidden; }
.qrbar span { display: block; height: 100%; background: var(--accent); transition: width 1s linear; }
.short { font-size: 1rem; color: var(--muted); }
.short b { font-size: 1.7rem; color: var(--text); margin-left: 6px; }

/* ---------- 掃描 ---------- */
.scanbox { position: relative; margin-top: 12px; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 1; max-height: 60vh; width: 100%; }
.scanbox video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanbox .frame { position: absolute; inset: 15%; border: 3px solid var(--accent); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); pointer-events: none; }
.scan-status { position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; color: #fff; font-size: .9rem; text-shadow: 0 1px 3px #000; }
body.night .scan-status { color: var(--text); }
.scan-status.hidden { display: none; }
.shortform { display: flex; flex-direction: column; }
.scanok h2 { color: var(--ok); }

/* ---------- 好友 ---------- */
.flist { list-style: none; padding: 0; margin: 0; }
.frow { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.frow:first-child { border-top: none; }
.fmain { flex: 1; display: flex; align-items: center; gap: 10px; background: none; border: none; text-align: left; padding: 4px 0; cursor: pointer; min-width: 0; min-height: 48px; }
.fmain span:last-child { display: flex; flex-direction: column; min-width: 0; }
.fmain small { color: var(--muted); font-size: .8rem; }
.pill { font-size: .8rem; border-radius: 999px; padding: 3px 10px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.bad { color: var(--bad); border-color: var(--bad); }
.pill.wait { color: var(--accent); }
.empty { text-align: center; padding: 48px 16px; display: flex; flex-direction: column; align-items: center; gap: 6px; }

/* ---------- 星空 ---------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 12px 0 4px; }
.seg button { background: none; border: none; padding: 10px; cursor: pointer; color: var(--muted); min-height: 44px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.field .seg { margin: 4px 0; font-weight: 400; }
.sky-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.cons { margin: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 6px; }
.cons.done { border-color: var(--accent); }
.cons svg { width: 100%; display: block; }
.cons figcaption { display: flex; justify-content: space-between; font-size: .85rem; padding: 2px 4px; }
.cons figcaption span { color: var(--muted); font-variant-numeric: tabular-nums; }
.cons.done figcaption { color: var(--accent); font-weight: 700; }
.st { fill: var(--star-off); }
.st.on { fill: var(--star); }
.ln { stroke: var(--star-off); stroke-width: .6; }
.ln.on { stroke: var(--star); stroke-opacity: .55; stroke-width: .7; }
.mysky { width: 100%; display: block; background: radial-gradient(circle at 50% 40%, var(--bg2), var(--bg)); border-radius: 12px; border: 1px solid var(--line); }
.mystar { cursor: pointer; }
.mystar .hit { fill: transparent; }
.lbl { font-size: 3.6px; fill: var(--muted); text-anchor: middle; }
.bigstat { font-size: 1rem; color: var(--muted); }
.bigstat b { font-size: 2rem; color: var(--accent); }
.bigstat small { display: block; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; margin-top: 12px; }
.stats3 b { display: block; font-size: 1.5rem; color: var(--accent); }
.stats3 small { color: var(--muted); font-size: .8rem; }
.badges { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.badges li { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; color: var(--muted); }
.badges li.on { border-color: var(--accent); color: var(--text); }
.badges .bi { font-size: 1.3rem; color: var(--star-off); }
.badges li.on .bi { color: var(--accent); }
.badges small { font-size: .78rem; }

/* ---------- 排行榜 ---------- */
.rank { list-style: none; padding: 0; margin: 0; }
.rank li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.rank li:first-child { border-top: none; }
.rank li.me { background: var(--bg2); border-radius: 10px; padding-left: 6px; padding-right: 6px; }
.rk { width: 28px; text-align: center; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; flex: none; }
.who { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.who small { color: var(--muted); font-size: .8rem; }
.pts { font-weight: 800; font-variant-numeric: tabular-nums; }
.pts.small { font-size: .85rem; font-weight: 600; text-align: right; }
.myrank { text-align: center; color: var(--muted); margin-top: 12px; }
.award h2 { color: var(--accent); }

/* ---------- 彈出視窗 ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .7); display: flex; align-items: flex-end; justify-content: center; padding: 12px; }
.sheet { background: var(--card); border: 1px solid var(--line); border-radius: 20px; width: 100%; max-width: 520px; padding: 20px; max-height: 92vh; overflow: auto; margin-bottom: env(safe-area-inset-bottom); }
.sheet.center { text-align: center; align-items: center; }
.quizsheet .qtop { display: flex; justify-content: space-between; color: var(--muted); font-size: .9rem; }
.timer { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 10px 0 4px; }
.timer span { display: block; height: 100%; background: var(--accent); transition: width .2s linear; }
.secs { text-align: right; color: var(--muted); font-size: .85rem; }
.prompt { font-size: 1.25rem; display: block; margin: 12px 0 16px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.opt { text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; font-size: 1.05rem; cursor: pointer; min-height: 52px; }
.opt.chosen { border: 2px solid var(--accent); }
.opt.right { border: 2px solid var(--ok); color: var(--ok); font-weight: 700; }
.opt.wrong { border: 2px solid var(--bad); text-decoration: line-through; }
.opt:disabled { cursor: default; }

/* ---------- 提示訊息 ---------- */
/* 提示放在下方分頁列上面，不擋住上方的狀態列和隨堂考按鈕 */
.toasts { position: fixed; bottom: calc(80px + env(safe-area-inset-bottom)); left: 0; right: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast { background: var(--card); border: 1px solid var(--accent); color: var(--text); padding: 10px 16px; border-radius: 12px; max-width: 480px; box-shadow: 0 6px 20px rgba(0, 0, 0, .4); transition: opacity .4s, transform .4s; font-size: .95rem; }
.toast.big { font-weight: 700; font-size: 1.05rem; border-width: 2px; }
.toast.out { opacity: 0; transform: translateY(8px); }

.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 3s !important; }
}
