:root {
  --bg: #0d1117;
  --panel: rgba(12, 16, 24, 0.72);
  --line: rgba(255, 255, 255, 0.14);
  --text: #eef2f6;
  --muted: #9aa6b2;
  --accent: #ffcc00;
  --accent2: #ff7a1a;
  --good: #4ade80;
  --bad: #ff5a5a;
}
* { box-sizing: border-box; }
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;
  -webkit-user-select: none; user-select: none;
}
#scene, #scene canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button {
  font: inherit; font-weight: 700; cursor: pointer;
  color: var(--text); background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 18px;
  transition: transform .08s, background .15s;
}
button:hover { background: rgba(255, 255, 255, 0.16); }
button:active { transform: scale(0.97); }
button.primary { background: var(--accent); color: #1a1400; border-color: #ffdd55; }
button.primary:hover { background: #ffd83d; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}

/* HUD */
#hud { position: fixed; top: 14px; left: 14px; z-index: 5; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
#telemetry { padding: 10px 14px; min-width: 210px; font-size: 13px; }
#telemetry .row { display: flex; justify-content: space-between; gap: 16px; line-height: 1.75; }
#telemetry .row span { color: var(--muted); }
#telemetry b { font-variant-numeric: tabular-nums; font-family: ui-monospace, Consolas, monospace; }
#telemetry b.warn { color: var(--accent2); }
#telemetry b.bad { color: var(--bad); }
#telemetry b.good { color: var(--good); }
.fuel .bar { flex: 1; height: 10px; margin-top: 7px; background: rgba(255,255,255,.1); border-radius: 6px; overflow: hidden; }
.fuel .bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ff5a5a, #ffcc00 30%, #4ade80); border-radius: 6px; }
#arms-status { padding: 8px 14px; font-size: 13px; font-weight: 700; }
#arms-status.closing { color: var(--accent); animation: blink .3s infinite alternate; }
#arms-status.closed { color: var(--good); }
@keyframes blink { to { opacity: .55; } }

#toast {
  position: fixed; top: 16%; left: 50%; transform: translateX(-50%);
  z-index: 6; pointer-events: none; text-align: center;
  font-size: clamp(20px, 3.6vw, 40px); font-weight: 900;
  text-shadow: 0 3px 0 #000, 0 0 18px rgba(0,0,0,.6);
  opacity: 0; transition: opacity .25s; max-width: 92vw;
}
#toast.show { opacity: 1; }
#toast.good { color: var(--good); }
#toast.bad { color: var(--bad); }
#toast.warn { color: var(--accent); }

/* 直播資訊列 */
#cast {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 26px; pointer-events: none;
  padding: 8px 26px; border-radius: 40px;
  background: linear-gradient(90deg, transparent, rgba(8, 10, 14, 0.72) 18%, rgba(8, 10, 14, 0.72) 82%, transparent);
  font-family: ui-monospace, Consolas, monospace; color: #fff;
}
#cast .dial { position: relative; width: 58px; height: 58px; }
#cast .dial svg { width: 58px; height: 58px; transform: rotate(-90deg); }
#cast .dial circle { fill: none; stroke-width: 3; }
#cast .dial .trk { stroke: rgba(255, 255, 255, .2); }
#cast .dial .val { stroke: #fff; stroke-dasharray: 163.4; stroke-dashoffset: 163.4; stroke-linecap: round; }
#cast .dl { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05; }
#cast .dl small { font-size: 7px; letter-spacing: .08em; opacity: .8; }
#cast .dl b { font-size: 15px; }
#cast .clock { display: flex; flex-direction: column; align-items: center; }
#cast .clock b { font-size: 24px; letter-spacing: .04em; font-weight: 700; }
#cast .clock small { font-size: 10px; letter-spacing: .1em; opacity: .85; font-family: "Noto Sans TC", sans-serif; }
#cast .eng svg { width: 52px; height: 52px; display: block; }
#cast .eng circle { fill: rgba(255, 255, 255, .15); stroke: rgba(255, 255, 255, .6); stroke-width: 1; }
#cast .eng circle.ring { fill: none; stroke: rgba(255, 255, 255, .35); }
#cast .eng circle.on { fill: #ffe3ee; stroke: #fff; filter: drop-shadow(0 0 3px #ff9fc4); }
#cast .eng circle.lost { fill: #ff4d4d; stroke: #ff4d4d; opacity: .7; }

/* 老闆 */
#boss { position: fixed; left: 10px; bottom: 6px; z-index: 7; width: 230px; pointer-events: none; }
#musk { width: 230px; height: 248px; display: block; filter: drop-shadow(0 6px 10px rgba(0,0,0,.45)); }
#boss .tag {
  text-align: center; font-size: 11px; color: #e3e8ee; font-weight: 700;
  background: rgba(12, 16, 24, 0.85); border: 1px solid rgba(255, 204, 0, .35); border-radius: 8px; padding: 3px 6px; margin-top: -4px;
}
#bubble {
  position: absolute; left: 150px; bottom: 210px; width: max-content; max-width: 230px;
  background: #fff; color: #111; font-weight: 700; font-size: 14px; line-height: 1.35;
  padding: 8px 12px; border-radius: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.35);
  opacity: 0; transform: translateY(6px) scale(.95); transition: opacity .2s, transform .2s;
}
#bubble::after {
  content: ""; position: absolute; left: 14px; bottom: -9px;
  border: 10px solid transparent; border-top-color: #fff; border-bottom: 0;
}
#bubble.show { opacity: 1; transform: none; }

#cam { position: fixed; right: 12px; bottom: 12px; z-index: 5; padding: 5px; border-radius: 10px; background: #111; border: 2px solid #333; box-shadow: 0 6px 18px rgba(0,0,0,.5); }
#cctv { width: 240px; height: 150px; display: block; border-radius: 6px; }

#corner-btns { position: fixed; top: 12px; right: 12px; z-index: 20; display: flex; gap: 8px; }
#corner-btns > button { padding: 7px 12px; background: var(--panel); }
/* 三選一語言切換：目前的語言會亮起來 */
#lang-switch { display: flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
#lang-switch button { padding: 5px 10px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 13px; }
#lang-switch button:hover { color: var(--text); background: rgba(255,255,255,.08); }
#lang-switch button[aria-checked="true"] { background: var(--accent); color: #1a1400; }
#lang-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#touch { position: fixed; bottom: 175px; right: 12px; z-index: 8; display: grid; grid-template-columns: repeat(2, 64px); gap: 8px; }
#touch button { width: 64px; height: 64px; font-size: 24px; background: rgba(255,255,255,.16); touch-action: none; }
#touch button.on { background: var(--accent); color: #000; }

/* Overlays */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 60px 16px 16px;
  background: radial-gradient(ellipse at center, rgba(5,8,14,.35), rgba(5,8,14,.75));
}
.card {
  background: rgba(14, 18, 26, 0.92); border: 1px solid var(--line); border-radius: 18px;
  padding: 26px 30px; max-width: 640px; width: 100%; max-height: calc(100vh - 76px); overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.card.small { max-width: 360px; text-align: center; }
.card h2 { margin: 0 0 12px; font-size: 26px; font-weight: 900; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.title-card { text-align: center; max-width: 720px; }
.title-card .btns { justify-content: center; }
.title-card h1 {
  margin: 8px 0 6px; font-family: "Bungee", "Noto Sans TC", sans-serif; font-weight: 900;
  font-size: clamp(34px, 7vw, 68px); line-height: 1.05; color: var(--accent);
  text-shadow: 0 4px 0 #8a5a00, 0 10px 30px rgba(255, 180, 0, .25);
}
.kicker { font-size: 12px; letter-spacing: .06em; color: var(--muted); }
.sub { color: #cfd6de; font-size: 17px; margin: 6px 0 0; }
.kicker.disclaimer { margin: 10px 0 0; opacity: .8; }
.help-body p { margin: 4px 0; line-height: 1.55; color: #d8dee6; }
.help-body b { color: var(--accent); }
.help-body a, .credit a { color: var(--accent); text-decoration: none; font-weight: 700; }
.help-body a:hover, .credit a:hover { text-decoration: underline; }
.credit { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.about-title { margin: 18px 0 4px; font-size: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.about-body p { font-size: 13px; color: var(--muted); }

.board-note { color: var(--muted); font-size: 12px; margin: 4px 0 8px; min-height: 16px; }
.board-list { display: flex; flex-direction: column; gap: 4px; }
.board-row {
  display: grid; grid-template-columns: 34px 1fr 70px 70px; gap: 8px; align-items: center;
  padding: 6px 10px; border-radius: 8px; background: rgba(255,255,255,.04); font-size: 14px;
}
.board-row.head { background: none; color: var(--muted); font-size: 12px; }
.board-row.me { background: rgba(255, 204, 0, .18); outline: 1px solid rgba(255,204,0,.5); }
.board-row .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-row .s { text-align: right; font-family: ui-monospace, Consolas, monospace; font-weight: 700; }
.board-row .o { text-align: right; color: var(--muted); font-size: 12px; }

.results-card { max-width: 820px; padding-bottom: 0; }
.results-card h2 { font-size: 28px; margin-bottom: 4px; }
.results-card .sub { font-size: 15px; }
.results-card .btns {
  position: sticky; bottom: 0; margin: 14px -30px 0; padding: 12px 30px 18px;
  background: linear-gradient(transparent, rgba(14, 18, 26, 0.97) 30%);
}
.res-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-top: 10px; }
#res-table { width: 100%; border-collapse: collapse; font-size: 14px; }
#res-table td { padding: 3px 0; border-bottom: 1px dashed rgba(255,255,255,.08); }
#res-table td:last-child { text-align: right; font-family: ui-monospace, Consolas, monospace; font-weight: 700; }
#res-table tr.neg td:last-child { color: var(--bad); }
#res-table tr.pos td:last-child { color: var(--good); }
.res-total, .res-rank { display: flex; justify-content: space-between; align-items: baseline; margin-top: 10px; }
.res-total b { font-size: 34px; color: var(--accent); font-family: ui-monospace, Consolas, monospace; }
.res-rank b { font-size: 20px; }
.res-loss { text-align: right; color: #ff9a9a; font-weight: 700; font-size: 14px; }
.res-loss:empty { display: none; }
.board-row.worst { background: rgba(255, 90, 90, .1); margin-top: 6px; }
.res-detail { margin-top: 8px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.res-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.res-badges .bt { font-size: 12px; color: var(--muted); }
.res-badges .badge {
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  background: rgba(255, 204, 0, .14); border: 1px solid rgba(255, 204, 0, .45); color: #ffe27a;
}
.share-head { font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 6px; }
.share-head:not(:first-child) { margin-top: 14px; }
.share-img { display: block; width: 100%; border-radius: 10px; margin-top: 10px; border: 1px solid var(--line); }
.share-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.share-btns button { flex: 1; padding: 8px 10px; font-size: 14px; }
#share-form { display: flex; gap: 8px; }
#share-form input {
  flex: 1; min-width: 0; font: inherit; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(255,255,255,.06); color: var(--text);
  -webkit-user-select: text; user-select: text;
}

.res-head { display: flex; align-items: center; gap: 16px; }
#res-musk { width: 100px; height: 108px; flex: none; background: rgba(255,255,255,.04); border-radius: 14px; }
.res-quote { margin: 8px 0 0; font-weight: 700; color: var(--accent); }
.res-quote:not(:empty)::before { content: "💬 "; }
body.on-results #boss { visibility: hidden; }

@media (max-width: 760px) {
  .res-grid { grid-template-columns: 1fr; }
  #boss { width: 150px; }
  #boss .tag { font-size: 9.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #musk { width: 150px; height: 162px; }
  #bubble { left: 100px; bottom: 150px; font-size: 12px; max-width: 170px; }
  #cam { padding: 3px; }
  #cctv { width: 160px; height: 100px; }
  #telemetry { min-width: 150px; font-size: 11px; padding: 7px 9px; }
  #telemetry .row { gap: 10px; }
  #corner-btns { gap: 6px; }
  #corner-btns > button { padding: 5px 8px; }
  #lang-switch button { padding: 4px 7px; font-size: 12px; }
  #touch { bottom: 130px; grid-template-columns: repeat(2, 56px); }
  #touch button { width: 56px; height: 56px; }
  .card { padding: 20px 18px; }
  #cast { top: 62px; bottom: auto; left: auto; right: 12px; transform: none; padding: 4px 10px; gap: 8px; }
  .results-card .btns { margin: 14px -18px 0; padding: 12px 18px 16px; }
  #cast .dial, #cast .eng { display: none; }
  #cast .clock b { font-size: 15px; }
  #cast .clock small { font-size: 8px; }
}

/* 簡體中文用簡體字型 */
html:lang(zh-Hans) body, html:lang(zh-Hans) button, html:lang(zh-Hans) input { font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; }
html:lang(zh-Hans) .title-card h1 { font-family: "Bungee", "Noto Sans SC", sans-serif; }
html:lang(zh-Hans) #cast .clock small { font-family: "Noto Sans SC", sans-serif; }
