:root {
  --blue: #2f6fdb;
  --blue-dark: #1d4fa8;
  --blue-deep: #143a7c;
  --sky-top: #5db7ff;
  --sky-bottom: #cfefff;
  --yellow: #ffc93c;
  --yellow-dark: #d69a00;
  --red: #ff4b4b;
  --red-dark: #b81f1f;
  --green: #3ecf5a;
  --green-dark: #1f8f36;
  --white: #ffffff;
  --ink: #12274f;
  --panel: rgba(29, 79, 168, 0.85);
  --panel-light: rgba(255, 255, 255, 0.14);
  --team-blue: #3d8bff;
  --team-red: #ff4d4d;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--blue-dark);
  font-family: var(--font);
  color: var(--white);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
#app { position: fixed; inset: 0; width: 100%; height: 100%; height: 100dvh; }
.hidden { display: none !important; }

.screen {
  position: absolute; inset: 0; display: none; flex-direction: column;
  overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 12px) calc(env(safe-area-inset-bottom) + 14px) calc(env(safe-area-inset-left) + 12px);
}
.screen.active { display: flex; }
.sky {
  position: fixed; inset: 0; z-index: -1;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 60%, #8fdcff 100%);
}
.sky::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 38%;
  background: linear-gradient(180deg, rgba(47,111,219,0) 0%, rgba(47,111,219,0.75) 55%, var(--blue-deep) 100%);
}

h1, h2 { margin: 0; font-weight: 900; letter-spacing: 1px; text-transform: uppercase; text-shadow: 0 3px 0 rgba(0,0,0,0.25); }
h2 { font-size: 22px; }
.muted { color: rgba(255,255,255,0.75); font-size: 13px; }
.center { text-align: center; }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 0; border-radius: 16px; cursor: pointer;
  font-family: var(--font); font-weight: 900; font-size: 17px; letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--white); padding: 14px 18px; text-shadow: 0 2px 0 rgba(0,0,0,0.3);
  box-shadow: 0 6px 0 rgba(0,0,0,0.28), inset 0 -3px 0 rgba(0,0,0,0.15), inset 0 2px 0 rgba(255,255,255,0.25);
  transition: transform 0.06s, box-shadow 0.06s, filter 0.15s; touch-action: manipulation;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,0.28), inset 0 -2px 0 rgba(0,0,0,0.15); }
.btn:disabled { filter: grayscale(0.7) brightness(0.75); cursor: default; }
.btn-red { background: linear-gradient(#ff6b6b, var(--red)); }
.btn-yellow { background: linear-gradient(#ffd966, var(--yellow)); color: #4a3200; text-shadow: 0 1px 0 rgba(255,255,255,0.4); }
.btn-green { background: linear-gradient(#6fe08a, var(--green)); }
.btn-blue { background: linear-gradient(#5b93ee, var(--blue)); }
.btn-big { font-size: 20px; padding: 18px 22px; border-radius: 20px; }
.btn-small { font-size: 14px; padding: 10px 14px; border-radius: 12px; }

.panel {
  background: var(--panel); border-radius: 22px; padding: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.2);
  width: 100%; max-width: 480px; margin: auto;
}

/* ---------- home ---------- */
.home-panel { display: flex; flex-direction: column; gap: 14px; }
.logo { text-align: center; padding: 6px 0 2px; }
.logo-robot { font-size: 54px; filter: drop-shadow(0 6px 0 rgba(0,0,0,0.25)); }
.logo h1 { font-size: 34px; line-height: 1; color: var(--yellow); -webkit-text-stroke: 1px rgba(0,0,0,0.15); }
.logo-sub { font-weight: 800; letter-spacing: 4px; font-size: 13px; opacity: 0.9; margin-top: 6px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 800; font-size: 12px; letter-spacing: 1px; }
input {
  font-family: var(--font); font-size: 18px; font-weight: 700; color: var(--ink);
  border: 0; border-radius: 14px; padding: 12px 14px; width: 100%; background: var(--white);
  box-shadow: inset 0 3px 0 rgba(0,0,0,0.12); outline: none;
}
.home-actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
.join-box { background: var(--panel-light); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.join-title { font-weight: 900; letter-spacing: 1px; font-size: 13px; }
.room-list { display: flex; flex-direction: column; gap: 8px; max-height: 190px; overflow-y: auto; }
.room-row {
  display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.12); border-radius: 12px; padding: 10px 12px;
  cursor: pointer; border: 0; color: var(--white); font-family: var(--font); text-align: left; width: 100%;
}
.room-row:active { background: rgba(255,255,255,0.25); }
.room-row .code { font-weight: 900; font-size: 18px; letter-spacing: 2px; color: var(--yellow); }
.room-row .info { flex: 1; font-size: 13px; opacity: 0.9; }
.room-row .state { font-size: 11px; font-weight: 800; padding: 4px 8px; border-radius: 8px; background: rgba(0,0,0,0.25); }
.join-code { display: flex; gap: 8px; }
.join-code input { flex: 1; text-transform: uppercase; letter-spacing: 4px; text-align: center; font-size: 22px; }
.address { font-size: 12px; text-align: center; opacity: 0.85; line-height: 1.5; }
.address b { color: var(--yellow); font-size: 14px; letter-spacing: 0.5px; }

/* ---------- garage ---------- */
.garage, .lobby, .results { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 520px; margin: 0 auto; flex: 1; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.garage-preview {
  position: relative; background: radial-gradient(circle at 50% 40%, rgba(255,255,255,0.35), rgba(255,255,255,0.05) 70%), var(--panel);
  border-radius: 22px; height: 210px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
#garage-canvas { width: 100%; height: 100%; display: block; }
.stats {
  position: absolute; left: 10px; top: 10px; display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; font-weight: 800; text-shadow: 0 2px 0 rgba(0,0,0,0.35);
}
.stats span { background: rgba(0,0,0,0.3); padding: 3px 8px; border-radius: 8px; }
.tabs { display: flex; gap: 6px; }
.tab {
  flex: 1; border: 0; border-radius: 12px; padding: 10px 4px; font-family: var(--font); font-weight: 900; font-size: 12px; letter-spacing: 0.5px;
  background: rgba(0,0,0,0.25); color: rgba(255,255,255,0.8); cursor: pointer; touch-action: manipulation;
}
.tab.active { background: var(--yellow); color: #4a3200; box-shadow: 0 4px 0 var(--yellow-dark); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; padding-bottom: 12px; }
.card {
  background: var(--panel); border-radius: 16px; padding: 12px; cursor: pointer; border: 3px solid transparent;
  box-shadow: 0 6px 0 rgba(0,0,0,0.25); display: flex; flex-direction: column; gap: 6px; position: relative; touch-action: manipulation;
}
.card.selected { border-color: var(--yellow); background: linear-gradient(rgba(255,201,60,0.25), rgba(255,201,60,0.05)), var(--panel); }
.card.disabled { opacity: 0.45; }
.card .icon { font-size: 30px; line-height: 1; }
.card .name { font-weight: 900; font-size: 14px; text-transform: uppercase; }
.card .desc { font-size: 11px; opacity: 0.85; line-height: 1.3; }
.card .stat { font-size: 11px; font-weight: 800; color: var(--yellow); }
.card .badge { position: absolute; top: 8px; right: 8px; background: var(--green); border-radius: 10px; padding: 2px 8px; font-size: 11px; font-weight: 900; }
.swatches { display: flex; flex-wrap: wrap; gap: 12px; padding: 8px; }
.swatch { width: 48px; height: 48px; border-radius: 14px; border: 4px solid transparent; box-shadow: 0 5px 0 rgba(0,0,0,0.3); cursor: pointer; }
.swatch.selected { border-color: var(--white); transform: scale(1.08); }

/* ---------- lobby ---------- */
.room-code { font-weight: 900; letter-spacing: 1px; font-size: 14px; text-align: center; }
.room-code span { color: var(--yellow); font-size: 26px; letter-spacing: 6px; display: block; line-height: 1; }
.player-list { display: flex; flex-direction: column; gap: 6px; }
.player-row {
  display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 14px; padding: 8px 12px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.2);
}
.player-row.disconnected { opacity: 0.55; }
.player-row .avatar { width: 40px; height: 40px; border-radius: 12px; background: rgba(0,0,0,0.25); display: grid; place-items: center; font-size: 22px; }
.player-row .avatar canvas, .player-row .avatar img { width: 40px; height: 40px; display: block; }
.player-row .pname { flex: 1; font-weight: 900; font-size: 16px; }
.player-row .pname small { display: block; font-weight: 600; font-size: 11px; opacity: 0.75; }
.player-row .ready { font-weight: 900; font-size: 12px; padding: 5px 10px; border-radius: 10px; background: rgba(0,0,0,0.3); }
.player-row .ready.yes { background: var(--green); }
.player-row .host { font-size: 18px; }
.team-btn { border: 0; border-radius: 10px; padding: 6px 10px; font-weight: 900; font-size: 12px; color: white; cursor: pointer; touch-action: manipulation; }
.team-btn.t0 { background: var(--team-blue); } .team-btn.t1 { background: var(--team-red); }
.kick { border: 0; background: rgba(0,0,0,0.3); color: white; border-radius: 10px; width: 30px; height: 30px; font-weight: 900; cursor: pointer; }
.settings { display: flex; flex-direction: column; gap: 10px; }
.setting-label { font-weight: 900; font-size: 12px; letter-spacing: 1px; opacity: 0.9; margin-bottom: 6px; }
.mode-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode-card { padding: 10px 6px; text-align: center; gap: 3px; }
.mode-card .icon { font-size: 26px; }
.mode-card .name { font-size: 12px; }
.mode-card .desc { font-size: 10px; }
.map-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.map-card { padding: 8px 6px; text-align: center; }
.map-card .icon { font-size: 22px; }
.map-card .name { font-size: 11px; }
.steppers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stepper { background: var(--panel); border-radius: 14px; padding: 8px 10px; display: flex; align-items: center; gap: 6px; box-shadow: 0 4px 0 rgba(0,0,0,0.2); }
.stepper .lbl { flex: 1; font-size: 11px; font-weight: 900; letter-spacing: 0.5px; }
.stepper .val { font-weight: 900; font-size: 15px; min-width: 56px; text-align: center; color: var(--yellow); }
.stepper button { border: 0; width: 32px; height: 32px; border-radius: 10px; background: var(--yellow); color: #4a3200; font-weight: 900; font-size: 18px; cursor: pointer; touch-action: manipulation; box-shadow: 0 3px 0 var(--yellow-dark); }
.stepper button:disabled { opacity: 0.35; }
.lobby-actions { display: flex; flex-direction: column; gap: 10px; margin-top: auto; padding-top: 8px; }
.settings.readonly .card, .settings.readonly .stepper button { pointer-events: none; }
.settings.readonly .stepper button { opacity: 0.3; }

/* ---------- results ---------- */
.results h2 { text-align: center; font-size: 30px; color: var(--yellow); margin-top: 10px; }
.results-sub { text-align: center; font-weight: 800; font-size: 16px; }
.results-table { display: flex; flex-direction: column; gap: 6px; }
.res-row { display: grid; grid-template-columns: 40px 1fr 60px 60px; align-items: center; gap: 6px; background: var(--panel); border-radius: 12px; padding: 8px 12px; box-shadow: 0 4px 0 rgba(0,0,0,0.2); }
.res-row.me { outline: 3px solid var(--yellow); }
.res-row .place { font-size: 22px; text-align: center; }
.res-row .name { font-weight: 900; font-size: 16px; }
.res-row .name small { display: block; font-size: 11px; font-weight: 600; opacity: 0.75; }
.res-row .num { text-align: center; font-weight: 900; }
.res-row .num small { display: block; font-size: 10px; font-weight: 700; opacity: 0.7; }
.res-head { background: transparent; box-shadow: none; opacity: 0.8; font-size: 11px; padding: 0 12px; }

/* ---------- game / HUD ---------- */
.game-screen { padding: 0; overflow: hidden; background: #000; touch-action: none; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#hud { position: absolute; inset: 0; pointer-events: none; font-weight: 900; }
#hud * { pointer-events: none; }
#hud .hud-top {
  position: absolute; left: 0; right: 0; top: 0; display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 8px) 8px 0 8px;
}
.hud-board { display: flex; flex-direction: column; gap: 3px; }
.hud-board .row { display: grid; grid-template-columns: 1fr 26px 22px; align-items: center; gap: 4px; background: rgba(0,0,0,0.45); border-radius: 8px; padding: 3px 8px; font-size: 12px; max-width: 150px; }
.hud-board .row .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-board .row.me .n { color: var(--yellow); }
.hud-board .row .k { text-align: right; }
.hud-board .row .medal { font-size: 13px; text-align: center; }
.hud-board .row.t0 .n { color: #9cc4ff; } .hud-board .row.t1 .n { color: #ffa3a3; }
.hud-timer { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hud-timer .pill { background: var(--blue); border-radius: 0 0 18px 18px; padding: 6px 18px 10px; font-size: 22px; box-shadow: 0 5px 0 var(--blue-deep); text-align: center; line-height: 1.1; }
.hud-timer .pill small { display: block; font-size: 10px; letter-spacing: 1px; opacity: 0.9; }
.hud-timer .teams { display: flex; gap: 6px; font-size: 18px; }
.hud-timer .teams span { padding: 3px 10px; border-radius: 10px; }
.hud-timer .teams .t0 { background: var(--team-blue); } .hud-timer .teams .t1 { background: var(--team-red); }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
#hud-leave { pointer-events: auto; border: 0; background: rgba(0,0,0,0.45); color: white; border-radius: 12px; width: 40px; height: 40px; font-size: 20px; cursor: pointer; }
.hud-feed { display: flex; flex-direction: column; gap: 3px; align-items: flex-end; }
.hud-feed .line { background: rgba(0,0,0,0.45); border-radius: 8px; padding: 3px 8px; font-size: 12px; white-space: nowrap; animation: feedIn 0.25s ease-out; }
.hud-feed .line .me { color: var(--yellow); }
@keyframes feedIn { from { transform: translateX(30px); opacity: 0; } }

/* 每顆鍵自己定位(見 hud.js 的拇指弧),容器只負責蓋滿畫面。 */
.hud-abilities { position: absolute; inset: 0; pointer-events: none; }
.ability {
  pointer-events: auto !important; position: absolute; border-radius: 18px; border: 3px solid rgba(255,255,255,0.7);
  background: rgba(0,0,0,0.5); color: white; font-size: 30px; cursor: pointer; display: grid; place-items: center; touch-action: none;
  box-shadow: 0 5px 0 rgba(0,0,0,0.35); overflow: hidden;
}
.ability .cd { position: absolute; inset: 0; background: rgba(0,0,0,0.65); transform-origin: bottom; transform: scaleY(0); }
.ability .cdn { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; color: var(--yellow); text-shadow: 0 2px 0 #000; }
.ability .charges[hidden] { display: none !important; }
.ability .charges { position: absolute; left: -10px; top: -8px; background: var(--yellow); color: #4a3200; border-radius: 10px; min-width: 24px; height: 24px; font-size: 14px; display: grid; place-items: center; box-shadow: 0 3px 0 var(--yellow-dark); }
.ability.empty { opacity: 0.4; }
.ability.blocked { opacity: 0.45; filter: grayscale(1); border-color: rgba(255,255,255,0.35) !important; box-shadow: none !important; }
/* 已緩存 —— 「我收到了,能放的時候就放」。黃色蓋過 blocked 的灰,
   因為在被控的當下,這件事比「按不了」更重要。 */
.ability.buffered {
  opacity: 1 !important; filter: none !important;
  border-color: var(--yellow) !important;
  box-shadow: 0 0 0 4px rgba(255,201,60,0.35), 0 0 20px rgba(255,201,60,0.85) !important;
  animation: ability-buffered 0.45s ease-in-out infinite alternate;
}
@keyframes ability-buffered { from { background: rgba(0,0,0,0.5); } to { background: rgba(255,201,60,0.4); } }
.ability.ready { border-color: var(--yellow); box-shadow: 0 5px 0 rgba(0,0,0,0.35), 0 0 16px rgba(255,201,60,0.7); }
/* 絕招。蓄滿的時候要比戰術技更醒目 —— 一場只放三四次,錯過很痛。 */
.ability.ult { border-radius: 50%; overflow: visible; }
/* 蓄力環。長在按鈕外面,用 conic-gradient 掃一圈,再用 mask 挖空中間 ——
   跟按鈕同一個圓形語彙,但一眼看得出是兩件事:
   框裡面的黑色遮罩是「等時間」,框外面的環是「打出來的」。 */
.ability.ult::before {
  content: ''; position: absolute; inset: -9px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(from -90deg, var(--yellow) calc(var(--charge, 0) * 360deg), rgba(0,0,0,0.42) 0);
  -webkit-mask: radial-gradient(closest-side, transparent 79%, #000 80%);
  mask: radial-gradient(closest-side, transparent 79%, #000 80%);
  filter: drop-shadow(0 0 6px rgba(255,201,60,0.55));
}
.ability.ult.empty { opacity: 1; }          /* 蓄力未滿不該把整顆變暗,環已經在講了 */
.ability.ult.empty .ico { opacity: 0.45; }  /* 只把圖示壓暗,輪廓留著 */
.ability.ult.ready { box-shadow: 0 5px 0 rgba(0,0,0,0.35), 0 0 26px rgba(255,201,60,1); animation: ult-ready 0.9s ease-in-out infinite alternate; }
@keyframes ult-ready { from { transform: scale(1); } to { transform: scale(1.06); } }
.ability.ult .cdn { font-size: 15px; }
.ability:active { transform: translateY(3px); }
.ability.aiming { border-color: var(--white); box-shadow: 0 0 0 4px rgba(255,255,255,0.35), 0 0 22px rgba(255,255,255,0.6); transform: translateY(3px); }

/* Cancel strip — appears only while aiming. Sits at the top because that is the
   one part of the screen a thumb can reach without crossing the play area. */
/* 取消區。原本是一整條寫著「取消」的長方形 —— 太大、太像系統對話框,
   而且蓋掉了戰場。改成一個小圓,跟技能鍵同一個語彙(圓 = 可按的東西)。
   armed 的時候才變紅變大,平常安靜待著。 */
.hud-cancel {
  pointer-events: none; position: absolute; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top) + 16px);
  width: 54px; height: 54px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 3px solid rgba(255,255,255,0.55);
  background: rgba(0,0,0,0.38);
  color: rgba(255,255,255,0.8); font-size: 24px;
  transition: transform 0.12s, background 0.12s, border-color 0.12s;
}
.hud-cancel.armed {
  border-color: var(--red); background: var(--red); color: var(--white);
  box-shadow: 0 0 22px rgba(255,75,75,0.9);
  transform: translateX(-50%) scale(1.18);
}

.hud-center { position: absolute; left: 0; right: 0; top: 24%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.hud-banner {
  font-size: 34px; letter-spacing: 2px; text-transform: uppercase; text-shadow: 0 4px 0 rgba(0,0,0,0.4), 0 0 20px rgba(0,0,0,0.5);
  opacity: 0; transform: scale(0.6);
}
.hud-banner.show { animation: bannerPop 1.4s ease-out forwards; }
.hud-banner.purple { color: #d9a3ff; } .hud-banner.red { color: #ff5c5c; } .hud-banner.yellow { color: var(--yellow); } .hud-banner.green { color: #7bed9f; } .hud-banner.white { color: white; }
@keyframes bannerPop { 0% { opacity: 0; transform: scale(0.5); } 15% { opacity: 1; transform: scale(1.15); } 25% { transform: scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: scale(1) translateY(-20px); } }
.hud-popup { font-size: 22px; color: var(--yellow); text-shadow: 0 3px 0 rgba(0,0,0,0.5); opacity: 0; }
.hud-popup.show { animation: popupRise 1.2s ease-out forwards; }
@keyframes popupRise { 0% { opacity: 0; transform: translateY(10px); } 20% { opacity: 1; } 100% { opacity: 0; transform: translateY(-30px); } }
.hud-countdown { font-size: 110px; color: var(--yellow); text-shadow: 0 8px 0 rgba(0,0,0,0.4); line-height: 1; }
.hud-countdown.go { font-size: 74px; color: #ff5c5c; }
.hud-countdown.pop { animation: cdPop 0.9s ease-out; }
@keyframes cdPop { 0% { transform: scale(1.6); opacity: 0.4; } 30% { transform: scale(1); opacity: 1; } 100% { opacity: 1; } }
.hud-dead { background: rgba(0,0,0,0.55); border-radius: 16px; padding: 12px 20px; text-align: center; font-size: 18px; }
.hud-dead small { display: block; font-size: 13px; font-weight: 700; opacity: 0.85; }
.hud-dead .n { font-size: 40px; color: var(--yellow); }
.hud-flash { position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(255,0,0,0) 45%, rgba(255,0,0,0.45) 100%); opacity: 0; }
.hud-flash.show { animation: flash 0.35s ease-out; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
.hud-hint { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 16px); text-align: center; font-size: 13px; opacity: 0.85; text-shadow: 0 2px 0 rgba(0,0,0,0.5); }
.hud-zone { font-size: 13px; background: rgba(120, 0, 180, 0.6); border-radius: 10px; padding: 3px 10px; }

/* ---------- misc ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%) translateY(30px);
  background: rgba(0,0,0,0.8); color: white; padding: 10px 16px; border-radius: 12px; font-weight: 800; font-size: 14px;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; z-index: 50; max-width: 90%; text-align: center; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#conn-status { position: fixed; top: calc(env(safe-area-inset-top) + 6px); left: 50%; transform: translateX(-50%); background: var(--red); padding: 6px 14px; border-radius: 10px; font-weight: 900; font-size: 12px; z-index: 60; }

@media (min-width: 700px) {
  .screen { padding-top: 24px; }
}
@media (max-height: 640px) {
  .garage-preview { height: 150px; }
  .logo-robot { font-size: 40px; }
  .logo h1 { font-size: 26px; }
}

/* ---------- 3D overlay (labels, floats, joystick, markers) ---------- */
.overlay3d { position: absolute; inset: 0; pointer-events: none; overflow: hidden; font-weight: 900; }
.overlay3d .lbl { position: absolute; left: 0; top: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; will-change: transform; }
.overlay3d .lbl .n { font-size: 12px; text-shadow: 0 1px 0 #000, 0 0 4px rgba(0,0,0,0.8); white-space: nowrap; }
.overlay3d .lbl .bar { position: relative; width: 62px; height: 9px; border-radius: 4px; background: rgba(0,0,0,0.6); overflow: hidden; }
.overlay3d .lbl .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: #ff4b4b; border-radius: 4px; }
.overlay3d .lbl .bar s { position: absolute; left: 0; top: 0; height: 3px; background: rgba(123,237,159,0.95); }
.overlay3d .lbl .bar b { position: absolute; inset: 0; font-size: 8px; line-height: 9px; text-align: center; color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,0.8); }
.overlay3d .flt { position: absolute; left: 0; top: 0; font-size: 18px; text-shadow: 0 2px 0 rgba(0,0,0,0.8), 0 0 6px rgba(0,0,0,0.6); white-space: nowrap; will-change: transform; }
.overlay3d .joy { position: absolute; inset: 0; }
.overlay3d .joy-base { position: absolute; left: 0; top: 0; width: 124px; height: 124px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.6); background: rgba(255,255,255,0.12); }
.overlay3d .joy-knob { position: absolute; left: 0; top: 0; width: 52px; height: 52px; border-radius: 50%; background: rgba(255,255,255,0.85); box-shadow: 0 3px 8px rgba(0,0,0,0.3); }
.overlay3d .mk { position: absolute; left: 0; top: 0; width: 22px; height: 16px; clip-path: polygon(100% 50%, 0 0, 25% 50%, 0 100%); opacity: 0.9; }


/* ---------------------------------------------------------------- 選手名冊
   兩層:名冊(剪影平鋪)→ 詳細。剪影是這套美術的重點,要夠大才看得出來,
   所以名冊只放剪影和名字,數值和技能全部留到詳細頁。 */
.heroes { position: absolute; inset: 0; display: flex; flex-direction: column; padding: 10px; gap: 10px; }
.heroes-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* 直立的卡:剪影是站著的,卡也該是站著的。
   auto-fill + minmax 讓它在直式手機自然變兩欄、橫式和桌機變四欄,
   不用為每個裝置寫一條 media query。 */
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 10px; padding-bottom: 12px; }
.roster-card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 8px 12px; border-radius: 18px; cursor: pointer; color: var(--white);
  background: var(--panel); border: 3px solid rgba(255,255,255,0.16);
  transition: border-color 0.12s, transform 0.12s;
}
.roster-card:active { transform: translateY(2px); }
.roster-card.mine { border-color: var(--acc); box-shadow: 0 0 0 3px rgba(255,255,255,0.12), 0 0 22px -4px var(--acc); }
.roster-card canvas { width: 100%; height: 132px; display: block; }
.roster-name { font-size: 17px; letter-spacing: 1px; }
/* 體感標籤用角色主色。八組色是識別,在名冊裡就該開始建立關聯。 */
.roster-feel { font-size: 11px; letter-spacing: 1px; color: var(--acc); text-transform: uppercase; }
/* 職業用畫的不用寫的 —— 縮在角落,不搶戲也不用翻譯 */
.roster-cls { position: absolute; top: 8px; left: 9px; opacity: 0.5; }
.roster-mine {
  position: absolute; top: 7px; right: 8px; font-size: 9px; letter-spacing: 1px;
  background: var(--acc); color: #2b1a00; border-radius: 6px; padding: 2px 6px;
}

/* 詳細頁。窄螢幕上下疊、寬螢幕左右分 —— 模型要大,說明要能一次讀完。 */
.hero-detail { display: grid; grid-template-columns: 1fr; gap: 12px; padding-bottom: 12px; }
@media (min-width: 760px) { .hero-detail { grid-template-columns: minmax(240px, 40%) 1fr; align-items: start; } }
.hero-stage {
  position: relative; background: var(--panel); border: 3px solid rgba(255,255,255,0.16);
  border-radius: 18px; overflow: hidden;
}
.hero-stage canvas { width: 100%; height: 320px; display: block; cursor: grab; touch-action: none; }
.hero-stage canvas:active { cursor: grabbing; }
.hero-spinhint {
  position: absolute; left: 0; right: 0; bottom: 8px; text-align: center;
  font-size: 11px; letter-spacing: 1px; color: var(--white); opacity: 0.4;
}
.hero-clsbig { position: absolute; top: 10px; left: 12px; color: var(--acc); opacity: 0.85; }

.hero-info { display: flex; flex-direction: column; gap: 9px; color: var(--white); }
.hero-head { display: flex; align-items: center; gap: 10px; }
.hero-names b { font-size: 28px; letter-spacing: 1px; }
.hero-feel { background: var(--acc); color: #2b1a00; border-radius: 10px; padding: 3px 10px; font-size: 13px; white-space: nowrap; }
.hero-feelnote { font-size: 14px; opacity: 0.85; line-height: 1.45; }

.hero-stats { display: flex; flex-direction: column; gap: 4px; background: rgba(0,0,0,0.22); border-radius: 12px; padding: 9px 11px; }
.hero-bar { display: grid; grid-template-columns: 40px 1fr 44px; align-items: center; gap: 8px; font-size: 12px; }
.hero-bar span { opacity: 0.7; }
.hero-bar i { display: block; height: 7px; border-radius: 4px; background: var(--acc); }
.hero-bar b { text-align: right; opacity: 0.85; font-weight: 600; }

.hero-skill { display: flex; gap: 9px; background: rgba(0,0,0,0.22); border-radius: 12px; padding: 9px 11px; }
.hero-skill-icon {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 11px; border: 2px solid;
  display: grid; place-items: center; background: rgba(0,0,0,0.35);
}
.hero-skill-body { min-width: 0; }
.hero-skill-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hero-skill-top b { font-size: 15px; }
.hero-aim { font-size: 11px; background: rgba(255,255,255,0.16); border-radius: 8px; padding: 1px 7px; letter-spacing: 1px; }
.hero-tier { font-size: 11px; opacity: 0.55; letter-spacing: 1px; }
.hero-skill-desc { font-size: 12.5px; opacity: 0.82; line-height: 1.4; margin-top: 2px; }
.hero-skill-cost { font-size: 11px; opacity: 0.55; margin-top: 3px; letter-spacing: 1px; }

.hero-passive { background: rgba(255,255,255,0.07); border: 2px dashed rgba(255,255,255,0.3); border-radius: 12px; padding: 9px 11px; font-size: 12.5px; line-height: 1.45; }
.hero-passive-tag { background: var(--acc); color: #2b1a00; border-radius: 7px; padding: 1px 7px; font-size: 11px; margin-right: 6px; }
.hero-passive b { font-size: 14px; }
.hero-passive-see { opacity: 0.6; font-size: 11.5px; margin-top: 4px; }

.hero-story { font-size: 12px; opacity: 0.55; line-height: 1.5; font-style: italic; }


/* 閒置的走路搖桿。淡到不搶戲,但一定看得到 —— 沒有它,新玩家不知道可以拖著走。 */
.overlay3d .joy.idle { opacity: 0.3; }
.overlay3d .joy { transition: opacity 0.18s; }


/* 轉橫式提示。
   可見半徑(VIEW_RADIUS)是為橫式算的:直式之下吉祥物只有 23px,
   「可愛殘暴」的美術方向整個失效。AoV、激鬥峽谷、MLBB 也全部只做橫式 ——
   分界線不是地區,是「要不要連續瞄準」。
   一進來就擋,不是等到開打才問 —— 進到一半才被要求轉向,比一開始就講清楚糟。 */
.rotate { display: none; }
@media (orientation: portrait) and (max-height: 1000px) {
  .rotate {
    display: flex; position: fixed; inset: 0; z-index: 9999;
    flex-direction: column; align-items: center; justify-content: center; gap: 14px;
    background: linear-gradient(180deg, var(--sky-top), var(--blue-deep));
    color: var(--white); text-align: center; padding: 24px;
  }
}
.rotate-phone { font-size: 76px; animation: rotate-hint 1.8s ease-in-out infinite; }
@keyframes rotate-hint { 0%, 40% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
.rotate-text { font-size: 24px; letter-spacing: 2px; text-shadow: 0 3px 0 rgba(0,0,0,0.35); }
.rotate-sub { font-size: 14px; opacity: 0.75; letter-spacing: 1px; }


/* 自己畫的技能圖示。只吃 currentColor,所以同一顆能在角色卡(彩色)
   和技能鍵(白色)重用,不用存兩份。 */
.sk { display: block; }
.ability .ico { display: grid; place-items: center; color: var(--white); }
.ability .ico .sk { filter: drop-shadow(0 2px 0 rgba(0,0,0,0.45)); }
.hero-skill-icon .sk { width: 22px; height: 22px; }
