:root {
    --bg: #020b16; --panel: rgba(4, 18, 34, .82); --line: rgba(60, 214, 255, .32); --cyan: #34d6ff; --cyan2: #9fefff;
    --text: #e6f7ff; --dim: #8fb4c9; --warn: #ffcf5a; --ok: #59ffb0; --bad: #ff7a8a;
    --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
    font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#stage { position: fixed; inset: 0; overflow: hidden; background: #01060d; touch-action: none; }
#stage > * { position: absolute; left: 0; top: 0; width: 100vw; height: 100vh; height: 100dvh; }
#cam { object-fit: cover; background: #000; }
#cam.mirror { transform: scaleX(-1); }
/* 相機畫面稍微壓暗、偏冷色，身上的 X 光片才看得清楚；「整張底片」時 3D 畫布整張不透明，後面的影像就不用畫了。 */
#tint { pointer-events: none; background: rgba(0, 18, 36, .3); }
body.film #cam, body.film #demo, body.film #tint { visibility: hidden; }
body[data-source="camera"] #demo, body[data-source="demo"] #cam, body[data-source="idle"] #demo, body[data-source="idle"] #cam { visibility: hidden; }
#gl, #hud { pointer-events: none; }

#topbar { position: fixed; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 10px;
    padding: calc(8px + var(--safe-t)) calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l));
    background: linear-gradient(180deg, rgba(2, 11, 22, .88), rgba(2, 11, 22, 0)); z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .08em; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; color: var(--cyan); }
.brand small { font-size: 10px; color: var(--cyan); letter-spacing: .22em; border: 1px solid var(--line); padding: 2px 6px; border-radius: 3px; }
.status { flex: 1; display: flex; gap: 6px; min-width: 0; overflow: hidden; }
.chip { font-size: 13px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: rgba(6, 28, 50, .7); white-space: nowrap; }
.chip.dim { color: var(--dim); }
nav { display: flex; gap: 6px; }
.tool { display: flex; align-items: center; gap: 6px; height: 40px; min-width: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: rgba(6, 28, 50, .72); font-size: 13px; }
.tool.icon { padding: 0; justify-content: center; }
.tool svg { width: 20px; height: 20px; }
.tool[aria-pressed="false"] { color: var(--dim); opacity: .7; }
.tool:active, .pill:active, .seg button:active { transform: translateY(1px); }

#panel::before { content: ""; position: absolute; left: 14px; right: 14px; top: -1px; height: 1px; background: linear-gradient(90deg, transparent, var(--cyan), transparent); }

#toast, #notice { position: fixed; left: 50%; transform: translateX(-50%); z-index: 6; padding: 9px 16px; border-radius: 999px; font-size: 14px;
    background: rgba(4, 22, 40, .92); border: 1px solid var(--line); max-width: 92vw; text-align: center; pointer-events: none; }
#toast { top: 21%; color: var(--ok); border-color: rgba(89, 255, 176, .5); font-size: 16px; animation: pop .35s ease-out; }
#toast.bad { color: var(--bad); border-color: rgba(255, 122, 138, .5); }
#notice { top: calc(60px + var(--safe-t)); color: var(--warn); border-color: rgba(255, 207, 90, .4); }
@keyframes pop { from { transform: translateX(-50%) scale(.85); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

#panel { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + var(--safe-b)); width: min(96vw, 860px); z-index: 4;
    padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.info { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; }
.focus small { display: block; font-size: 11px; color: var(--dim); letter-spacing: .1em; }
.focus b { font-size: 22px; color: var(--cyan2); white-space: nowrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; min-height: 30px; align-items: center; }
.chips button { font-size: 13px; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); background: rgba(52, 214, 255, .08); }
.chips button.organ { border-color: rgba(255, 150, 190, .45); background: rgba(255, 120, 170, .1); }
.chips button.on { background: var(--cyan); color: #012; border-color: var(--cyan); font-weight: 700; }
.chips button.off { opacity: .4; }
#fact { grid-column: 1 / -1; margin: 2px 0 0; font-size: 14px; line-height: 1.5; color: #cfe9f6; min-height: 42px; }
.controls { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { padding: 9px 13px; font-size: 14px; background: rgba(6, 28, 50, .7); }
.seg button.on { background: var(--cyan); color: #012; font-weight: 700; }
.pill { padding: 9px 13px; font-size: 14px; border: 1px solid var(--line); border-radius: 10px; background: rgba(6, 28, 50, .7); white-space: nowrap; }
.pill[aria-pressed="true"] { background: rgba(52, 214, 255, .28); border-color: var(--cyan); }
.pill.primary { margin-left: auto; background: linear-gradient(135deg, #17b9ee, #2ee6b6); color: #012; font-weight: 700; border: 0; }
body[data-screen="start"] #topbar, body[data-screen="start"] #panel { display: none; }

.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: calc(14px + var(--safe-t)) 14px calc(14px + var(--safe-b));
    background: rgba(1, 6, 13, .78); overflow: auto; }
#start { background: linear-gradient(160deg, #03111f 0%, #020b16 55%, #041a2a 100%); }
#start::before { content: ""; position: absolute; inset: 0; opacity: .5; pointer-events: none;
    background-image: linear-gradient(rgba(52, 214, 255, .07) 1px, transparent 1px), linear-gradient(90deg, rgba(52, 214, 255, .07) 1px, transparent 1px); background-size: 34px 34px; }
.card { position: relative; width: min(100%, 460px); max-height: 100%; overflow: auto; padding: 22px 20px; background: rgba(5, 20, 37, .96); border: 1px solid var(--line); border-radius: 18px; text-align: center; }
.card.wide { width: min(100%, 760px); }
.logo svg { width: 76px; height: 76px; color: var(--cyan); stroke-width: 2.2; animation: glow 3s ease-in-out infinite; }
@keyframes glow { 50% { color: var(--cyan2); transform: scale(1.04); } }
.eyebrow { margin: 6px 0 0; font-size: 11px; letter-spacing: .32em; color: var(--cyan); }
h1 { margin: 4px 0 8px; font-size: 34px; letter-spacing: .06em; }
h1 span { display: block; font-size: 18px; color: var(--cyan2); letter-spacing: .4em; margin-top: 2px; }
h2 { margin: 4px 0; font-size: 22px; }
.lead { margin: 8px 0; font-size: 15px; line-height: 1.65; color: #cfe9f6; }
.lead.small { font-size: 13px; color: var(--dim); }
.actions { display: flex; flex-direction: column; gap: 10px; margin: 16px 0 8px; }
.big { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 10px 16px; font-size: 17px; border-radius: 12px; border: 1px solid var(--line); background: rgba(6, 28, 50, .8); color: var(--text); text-decoration: none; }
.big.primary { background: linear-gradient(135deg, #17b9ee, #2ee6b6); color: #012; font-weight: 700; border: 0; }
.big svg { width: 22px; height: 22px; }
.big:disabled { opacity: .5; }
.notes { margin: 14px 0 0; padding: 12px 14px 12px 30px; text-align: left; font-size: 13px; line-height: 1.7; color: var(--dim); border-top: 1px solid var(--line); }
.error { color: var(--warn); font-size: 14px; line-height: 1.6; }
.load { margin: 12px 0 0; font-size: 13px; color: var(--dim); }
.load .bar { height: 6px; border-radius: 3px; background: rgba(60, 214, 255, .15); overflow: hidden; margin-bottom: 6px; }
.load .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--ok)); transition: width .25s; }
.dlg-head { display: flex; align-items: center; gap: 10px; text-align: left; }
.dlg-head h2 { flex: 1; }
.dlg-head span { font-size: 13px; color: var(--cyan2); }
.close { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); font-size: 16px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 2px; border-bottom: 1px solid rgba(60, 214, 255, .14); font-size: 15px; text-align: left; }
.row input[type=range] { flex: 1; max-width: 220px; accent-color: var(--cyan); height: 28px; }
.row input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--cyan); }
.row select { font: inherit; font-size: 14px; color: var(--text); background: rgba(6, 28, 50, .9); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; max-width: 230px; }
.lead.credit { text-align: left; border-top: 1px solid rgba(60, 214, 255, .14); padding-top: 10px; margin-top: 12px; font-size: 12px; }
.atlas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 10px; text-align: left; }
.atlas-grid div { padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(52, 214, 255, .06); font-size: 12.5px; line-height: 1.55; color: #cfe9f6; }
.atlas-grid div b { display: block; font-size: 15px; color: var(--cyan2); }
.atlas-grid div small { color: var(--dim); letter-spacing: .04em; }
.atlas-grid div.locked { opacity: .45; }
.atlas-grid div.organ b { color: #ffb3d1; }
#shotImg { width: 100%; max-height: 60vh; object-fit: contain; border-radius: 10px; border: 1px solid var(--line); margin-top: 10px; -webkit-user-select: auto; user-select: auto; -webkit-touch-callout: default; }

@media (max-width: 560px) {
    .brand span, .brand small { display: none; }
    .focus b { font-size: 19px; }
    #fact { font-size: 13px; min-height: 40px; }
    .pill, .seg button { padding: 9px 10px; font-size: 13px; }
    h1 { font-size: 28px; }
}
@media (max-height: 480px) and (orientation: landscape) {
    #panel { width: min(96vw, 980px); padding: 6px 10px; }
    #fact { display: none; }
    .controls { margin-top: 4px; }
    .card { padding: 12px 16px; } .logo { display: none; } .notes { display: none; }
    .actions { flex-direction: row; } .actions > * { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { .logo svg, #toast { animation: none; } }
