/* 版面：手機直式單欄（戰場 → K 線押注 → 徵兵）；寬螢幕兩欄（左戰場＋徵兵、右 K 線） */
:root {
  --ink: #140f1c;
  --panel: #211830;
  --panel-2: #2b2040;
  --line: #3e2f57;
  --text: #f1eaf8;
  --muted: #a293b8;
  --gold: #ffd84d;
  --stone: #8fd3ff;
  --up: #ff4d5e;
  --dn: #19c38a;
  --font-ui: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-num: "JetBrains Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--ink); color: var(--text); font: 14px/1.45 var(--font-ui); }
body { min-height: 100%; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
button:disabled { opacity: .4; cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
#app { max-width: 1180px; margin: 0 auto; padding-block: 10px 24px; padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); }

/* HUD */
#hud { display: grid; gap: 6px; margin-bottom: 10px; }
.hud-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lbl { color: var(--muted); font-size: 11px; letter-spacing: .08em; margin-right: 4px; }
.wave b { font: 700 18px var(--font-num); }
.track { display: flex; gap: 4px; }
.tw { min-width: 26px; height: 26px; display: grid; place-items: center; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); font: 700 12px var(--font-num); color: var(--muted); }
.tw.cur { background: var(--gold); color: #1a1300; border-color: var(--gold); transform: scale(1.12); }
.tw.done { opacity: .45; }
.tw.elite { color: #ffb347; border-color: #8a5a1f; font-family: var(--font-ui); }
.tw.boss { color: #ff6b6b; border-color: #8a2a2a; font-family: var(--font-ui); }
.tw.cur.elite, .tw.cur.boss { color: #1a1300; }
.toboss { margin-left: auto; color: #ff8a8a; font-size: 12px; font-weight: 700; }
.stats { gap: 8px 16px; }
.stat b { font: 700 15px var(--font-num); }
.stat .stone { color: var(--stone); }
.base { display: flex; align-items: center; gap: 4px; }
.bar { display: inline-block; width: 70px; height: 6px; background: #3a1d26; border-radius: 3px; overflow: hidden; margin-left: 4px; }
.bar i { display: block; height: 100%; background: var(--up); transition: width .2s; }

/* 版面 */
#grid { display: grid; gap: 10px; grid-template-columns: 1fr; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; min-width: 0; }
@media (min-width: 900px) {
  #grid { grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); grid-template-areas: "field market" "ctrl slot"; }
  #fieldWrap { grid-area: field; } #ctrl { grid-area: ctrl; } #slotPanel { grid-area: slot; }
  #market { grid-area: market; align-self: stretch; display: flex; flex-direction: column; }
  #market .chart-wrap { flex: 1; position: relative; min-height: 220px; }
  #market #chart { position: absolute; inset: 0; width: 100%; height: 100%; aspect-ratio: auto; }
}

/* 戰場 */
#fieldWrap { position: relative; padding: 0; overflow: hidden; }
#field { display: block; width: 100%; aspect-ratio: 600 / 340; touch-action: none; image-rendering: auto; }
.field-foot { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; font-size: 12px; color: var(--muted); min-height: 30px; }
#reso { color: var(--gold); }
.banner { position: absolute; left: 50%; top: 18%; transform: translateX(-50%); text-align: center; background: rgba(20, 15, 28, .82); border: 1px solid var(--line); padding: 8px 22px; border-radius: 8px; font-size: 14px; animation: drop 2.2s ease forwards; pointer-events: none; white-space: nowrap; }
.banner b { font-size: 20px; font-weight: 900; }
.banner.boss { border-color: var(--up); color: #ffb3b3; }
.banner.elite { border-color: #ffb347; color: #ffd8a0; }
@keyframes drop { 0% { opacity: 0; transform: translate(-50%, -14px); } 12%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }
.rally { position: absolute; left: 10px; top: 10px; background: rgba(255, 77, 94, .85); color: #fff; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 4px; }

/* K 線與轉輪 */
.chart-wrap { border-radius: 6px; overflow: hidden; }
#chart { display: block; width: 100%; aspect-ratio: 600 / 210; }
.slot { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.reels { display: flex; gap: 6px; padding: 6px; background: #120d19; border: 2px solid var(--line); border-radius: 8px; cursor: pointer; }
.reel { width: 54px; height: 54px; border-radius: 6px; background: linear-gradient(#f7f1e3, #d9cfb8); display: grid; place-items: center; overflow: hidden; transition: box-shadow .2s; }
.reel img { width: 48px; height: 48px; }
.reels.spinning .reel img { filter: blur(1px); animation: roll .12s linear infinite; }
@keyframes roll { 0% { transform: translateY(-6px); } 100% { transform: translateY(6px); } }
.reel.hit { box-shadow: 0 0 0 3px var(--gold), 0 0 14px var(--gold); }
.reel.miss { filter: grayscale(.8) brightness(.7); }
#rlabel { font: 700 16px var(--font-num); color: var(--muted); min-width: 0; }
#rlabel.up { color: var(--up); } #rlabel.dn { color: var(--dn); }
#result { margin: 8px 0; padding: 6px 10px; border-radius: 6px; font-weight: 700; font-size: 13px; min-height: 32px; background: var(--panel-2); }
#result.win { background: #3a2f0a; color: var(--gold); }
#result.lose { background: #2b2230; color: #c9b8d9; }
.bet { display: grid; grid-template-columns: 1fr 1.1fr 1fr; gap: 8px; align-items: stretch; }
.bet button { padding: 14px 6px; border-radius: 8px; font-size: 18px; font-weight: 900; letter-spacing: .05em; }
.bet .up { background: var(--up); color: #fff; box-shadow: 0 4px 0 #a32232; }
.bet .dn { background: var(--dn); color: #04281b; box-shadow: 0 4px 0 #0b7a54; }
.bet button:not(:disabled):active { transform: translateY(3px); box-shadow: none; }
.tbox { position: relative; background: #120d19; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: grid; place-items: center; text-align: center; padding: 4px; }
.tbox i { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--gold); transition: width .1s linear; }
#hint { font-size: 12px; color: var(--muted); }
.fight { width: 100%; margin-top: 10px; }
.primary { background: var(--gold); color: #1a1300; font-weight: 900; padding: 12px; border-radius: 8px; font-size: 16px; box-shadow: 0 4px 0 #a88a1c; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 6px 10px; }
.sm { font-size: 12px; padding: 4px 8px; }

/* 徵兵 */
.ctrl-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.ctrl-head h2 { margin: 0; font-size: 15px; font-weight: 900; letter-spacing: .1em; }
.tools { display: flex; gap: 6px; }
.shop { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
@media (max-width: 520px) { .shop { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.buy { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 2px 6px; display: grid; justify-items: center; gap: 1px; }
.buy img { width: 44px; height: 44px; }
.buy .nm { font-size: 12px; font-weight: 700; }
.buy .nm i { font-style: normal; font-size: 10px; margin-left: 2px; }
.buy .cost { font: 700 12px var(--font-num); color: var(--stone); }
.buy:not(:disabled):hover { border-color: var(--gold); }
.unit-panel { margin-top: 8px; display: flex; align-items: center; gap: 8px; background: #1a1326; border-radius: 8px; padding: 8px; min-height: 64px; }
.unit-panel img { width: 48px; height: 48px; flex: none; background: #f2ead8; border-radius: 6px; }
.ui-info { display: grid; gap: 1px; min-width: 0; flex: 1; }
.ui-info .nums { font: 11px var(--font-num); color: var(--muted); overflow-wrap: anywhere; }
.star { color: var(--gold); }
.ui-btns { display: grid; gap: 4px; }
.ui-btns { display: grid; gap: 4px; align-content: start; }
.ui-btns button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 12px; white-space: nowrap; }
.ui-btns #btnUpg:not(:disabled) { background: var(--gold); color: #1a1300; font-weight: 700; }
.muted { color: var(--muted); font-size: 12px; margin: 0; }
.legend-box { margin-top: 8px; font-size: 12px; }
.legend-box summary { cursor: pointer; color: var(--muted); }
.legend { list-style: none; padding: 0; margin: 6px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 10px; }
.legend li { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.legend img { width: 28px; height: 28px; background: #f2ead8; border-radius: 4px; }
.legend span { color: var(--muted); }

/* 提示與彈窗 */
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: #000c; border: 1px solid var(--gold); color: var(--gold); padding: 8px 16px; border-radius: 8px; font-weight: 700; z-index: 30; max-width: calc(100% - 32px); }
.modal { position: fixed; inset: 0; background: rgba(8, 5, 12, .72); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-body { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 18px; width: min(460px, 100%); max-height: 90vh; overflow: auto; }
.modal-body h2 { margin: 0 0 10px; font-size: 20px; font-weight: 900; text-wrap: balance; }
.modal-body h3 { font-size: 14px; margin: 12px 0 4px; }
.modal-body dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0 0 10px; }
.modal-body dt { color: var(--muted); }
.modal-body dd { margin: 0; font: 700 14px var(--font-num); text-align: right; }
.modal-body dd.g { color: #5dff8a; } .modal-body dd.s { color: var(--stone); }
.modal-body .primary { width: 100%; margin-top: 10px; }
.help { padding-left: 20px; margin: 0; display: grid; gap: 4px; }
b.up { color: var(--up); } b.dn { color: var(--dn); }
@media (prefers-reduced-motion: reduce) { .banner, .reels.spinning .reel img { animation: none; } }

/* 九宮格拉霸 */
.slot-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.slot-head h2 { margin: 0; font-size: 15px; font-weight: 900; letter-spacing: .1em; }
.slot-body { display: flex; gap: 10px; align-items: stretch; }
.slot-left { flex: 1; max-width: 260px; display: grid; gap: 6px; align-content: start; }
.slot-grid { position: relative; width: 100%; aspect-ratio: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; padding: 6px; background: #120d19; border: 2px solid var(--line); border-radius: 10px; cursor: pointer; }
.reelcol { position: relative; overflow: hidden; border-radius: 6px; background: #d9cfb8; box-shadow: inset 0 10px 10px -6px rgba(0,0,0,.45), inset 0 -10px 10px -6px rgba(0,0,0,.45); }
.reelcol .strip { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }
.slot-grid .cell { height: var(--cellh, 70px); background: linear-gradient(#f7f1e3, #e2d8c2); border-bottom: 2px solid #c9bea5; display: grid; place-items: center; transition: box-shadow .15s; }
.slot-grid .cell img { width: 80%; height: 80%; }
.reelcol.fast .cell img { filter: blur(2px); transform: scaleY(1.25); }
.slot-grid .cell.win { box-shadow: inset 0 0 0 3px var(--gold), inset 0 0 14px var(--gold); }
.slot-lines { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); pointer-events: none; }
.slot-lines line { stroke: var(--gold); stroke-width: 7; stroke-linecap: round; opacity: .85; }
.spin { flex: none; width: 92px; border-radius: 10px; background: linear-gradient(#ff6b7a, #c92a3e); color: #fff; display: grid; justify-items: center; align-content: center; gap: 6px; box-shadow: 0 5px 0 #7a1424; padding: 10px 4px; }
.spin b { font-size: 20px; font-weight: 900; }
.spin .cost { font: 12px var(--font-num); color: #ffe7b0; }
.spin .lever { width: 16px; height: 16px; border-radius: 50%; background: #ffd84d; box-shadow: 0 18px 0 -5px #ffd84d88; }
.spin:not(:disabled):active { transform: translateY(4px); box-shadow: none; }
#slotPanel .muted { margin-top: 6px; }

/* 微調按鈕 */
.nudge-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; padding: 0 6px; }
.nudge-row div { display: flex; gap: 3px; }
.nudge-row button { flex: 1; min-height: 28px; padding: 0; border-radius: 6px; background: #2a2036; color: var(--gold); border: 1px solid var(--line); font-size: 13px; }
.nudge-row button:not(:disabled):hover { background: #3a2c4a; }
.nudge-row button:disabled { opacity: .35; }
/* 刻印、核心 */
.imps { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 2px; }
.imp { font-size: 11px; padding: 1px 6px; border-radius: 999px; border: 1px solid currentColor; background: rgba(255,255,255,.04); }
.cores { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.cores:empty { display: none; }
.core { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: #2a2036; border: 1px solid var(--gold); color: var(--gold); }
/* 過波商店 */
.shop-head { display: flex; justify-content: space-between; align-items: baseline; margin-top: 12px; }
.shop-head h3 { margin: 0; }
.offers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
.offer { display: grid; gap: 4px; align-content: start; text-align: left; padding: 8px; border-radius: 8px; background: #1f1729; border: 1px solid var(--line); color: var(--text); min-height: 118px; }
.offer .k { font-size: 11px; color: var(--muted); }
.offer.core-k { border-color: var(--gold); }
.offer b { font-size: 14px; color: var(--text); }
.offer.core-k b { color: var(--gold); }
.offer .d { font-size: 12px; color: var(--muted); line-height: 1.35; }
.offer .p { font: 700 13px var(--font-num); color: var(--stone); margin-top: auto; }
.offer.sold { opacity: .4; }
.offer:disabled { cursor: default; }
.reroll { width: 100%; padding: 8px; border-radius: 8px; background: #2a2036; color: var(--text); border: 1px solid var(--line); }
@media (max-width: 420px) { .offers { grid-template-columns: 1fr; } .offer { min-height: 0; } }
.shop-head .s { color: var(--stone); font-family: var(--font-num); }

/* 金色符號 */
.slot-grid .cell.gold { background: radial-gradient(circle, #fff6c2, #f2c14e 70%, #d99a12); box-shadow: inset 0 0 0 3px #fff2a8, 0 0 14px #ffd84d; animation: goldpulse 1s ease-in-out infinite alternate; }
@keyframes goldpulse { from { filter: brightness(1); } to { filter: brightness(1.18); } }
.goldin { color: var(--gold); }
.slot-body.goldnext .spin { box-shadow: 0 5px 0 #7a1424, 0 0 18px #ffd84d; }
/* 稀有度、等級條、陣營 */
.rar, .fac { font-size: 12px; font-weight: 700; }
.lvbar { position: relative; display: block; height: 15px; max-width: 260px; border-radius: 4px; background: #2a2036; overflow: hidden; margin: 2px 0; }
.lvbar i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #b88a1e, #ffd84d); }
.lvbar em { position: relative; z-index: 1; font: 10px/14px var(--font-num); font-style: normal; padding-left: 5px; color: #fff; text-shadow: 0 1px 2px #000; }
.imp.empty { color: var(--muted); opacity: .5; border-style: dashed; }
.facs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.facchip { font-size: 12px; padding: 2px 7px; border-radius: 6px; background: #1f1729; border: 1px solid #3a2f48; color: var(--muted); }
.facchip b { font-weight: 700; color: var(--fc); }
.facchip small { opacity: .6; }
.facchip.on { border-color: var(--fc); color: var(--text); background: color-mix(in srgb, var(--fc) 14%, #1f1729); }
.facchip i { font-style: normal; color: var(--fc); margin-left: 4px; }

/* 關卡：選股票 */
.stock-tag { position: absolute; left: 50%; top: 6px; transform: translateX(-50%); z-index: 2; font: 700 12px var(--font-ui); padding: 3px 10px; border-radius: 999px; background: rgba(20,15,28,.8); border: 1px solid var(--gold); color: var(--gold); }
.stocks { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.stk { display: grid; gap: 1px; padding: 8px 4px; border-radius: 8px; background: #1f1729; border: 1px solid var(--line); color: var(--text); text-align: center; }
.stk b { font: 700 14px var(--font-num); color: var(--gold); }
.stk span { font-size: 11px; color: var(--muted); }
.stk:hover { border-color: var(--gold); }
.stk.rnd, .stk.sim { background: #2a2036; }
.reveal { margin: 8px 0; padding: 8px 10px; border-radius: 8px; background: #1f1729; border: 1px solid var(--gold); text-align: center; line-height: 1.6; }
@media (max-width: 420px) { .stocks { grid-template-columns: repeat(3, 1fr); } }

/* =========================================================
   精緻化外觀
   ========================================================= */
body { background: radial-gradient(120% 60% at 50% 0%, #2a1d3d 0%, var(--ink) 60%) fixed, var(--ink); }
.panel { background: linear-gradient(180deg, #2a1f3c 0%, var(--panel) 40%); border-color: #4a3866; box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 6px 18px rgba(0,0,0,.35); }
#fieldWrap { border: 2px solid #6b5420; box-shadow: 0 0 0 1px #000, 0 8px 24px rgba(0,0,0,.5); }
.stat { background: rgba(255,255,255,.04); border: 1px solid #3a2c52; border-radius: 999px; padding: 1px 9px; }
.stat .stone { color: var(--gold); text-shadow: 0 0 8px rgba(255,216,77,.35); }
.buy { background: linear-gradient(180deg, #34284a, #251c35); }
.buy img, .unit-panel img, .legend img { background: radial-gradient(circle at 50% 60%, #4a3a63, #241a33); object-fit: contain; }
.slot-grid .cell { background: radial-gradient(circle at 50% 55%, #3d2f55, #1c1428); border-bottom-color: #120d19; }
.reelcol { background: #1c1428; }
.slot-grid .cell img { object-fit: contain; filter: drop-shadow(0 2px 2px rgba(0,0,0,.6)); }
.slot-grid { background: linear-gradient(#1a1224, #0e0a14); border-color: #6b5420; box-shadow: inset 0 0 20px rgba(0,0,0,.6), 0 0 0 1px #000; }
.spin { background: linear-gradient(#ff7a88, #c92a3e 60%, #9a1b2d); }
.bet .up { background: linear-gradient(#ff6b79, var(--up)); }
.bet .dn { background: linear-gradient(#3fe0a8, var(--dn)); }
.primary { background: linear-gradient(#ffe27a, var(--gold)); }

/* 分頁列（桌機不顯示） */
#tabs { display: none; }

/* =========================================================
   手機：整個畫面固定在一屏，不用上下捲動
   上：HUD ／ 中：戰場 ／ 下：一個面板（K線押注、拉霸、徵兵三選一）／ 底：分頁列
   ========================================================= */
@media (max-width: 899px) {
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  #app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; padding: calc(6px + env(safe-area-inset-top, 0px)) max(8px, env(safe-area-inset-right, 0px)) 0 max(8px, env(safe-area-inset-left, 0px)); }
  #hud { flex: none; gap: 4px; margin-bottom: 6px; }
  .hud-row { flex-wrap: nowrap; gap: 6px; min-width: 0; }
  .wave b { font-size: 15px; }
  .track { overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; gap: 3px; }
  .track::-webkit-scrollbar { display: none; }
  .tw { min-width: 22px; height: 22px; font-size: 11px; flex: none; }
  .tw.cur { transform: none; }
  .toboss { font-size: 11px; white-space: nowrap; flex: none; }
  .stats { gap: 4px; justify-content: space-between; }
  .stat { padding: 1px 6px; white-space: nowrap; }
  .stat .lbl { font-size: 10px; margin-right: 2px; letter-spacing: 0; }
  .stat b { font-size: 13px; }
  .bar { width: 30px; }

  #grid { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 6px; }
  #fieldWrap { flex: none; }
  .field-foot { position: absolute; left: 0; right: 0; bottom: 0; min-height: 0; padding: 10px 8px 3px; font-size: 11px; background: linear-gradient(transparent, rgba(0,0,0,.55)); pointer-events: none; color: #e9def5; }
  .field-foot:has(span:empty + span:empty) { display: none; }

  .pane { display: none; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  .pane.on { display: flex; flex-direction: column; }

  /* K 線：圖表吃滿剩下空間 */
  #market .chart-wrap { flex: 1; position: relative; min-height: 90px; }
  #market #chart { position: absolute; inset: 0; width: 100%; height: 100%; aspect-ratio: auto; }
  #result { margin: 6px 0; padding: 5px 8px; min-height: 28px; font-size: 12px; flex: none; }
  .bet { flex: none; }
  .bet button { padding: 12px 4px; font-size: 17px; }
  .fight { flex: none; margin-top: 8px; padding: 10px; }

  /* 拉霸：九宮格依剩餘高度自動縮放 */
  .slot-head { flex: none; flex-wrap: wrap; gap: 2px 8px; }
  .slot-head .muted { font-size: 11px; }
  .slot-body { flex: 1; min-height: 0; container-type: size; justify-content: center; align-items: center; }
  .slot-left { flex: none; max-width: none; width: min(100cqw - 104px, 100cqh - 36px); }
  .spin { align-self: center; height: min(100%, 220px); }
  #slotPanel .slot-rules { display: none; }

  /* 徵兵 */
  .ctrl-head { flex: none; }
  .shop { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .buy img { width: 40px; height: 40px; }
  .unit-panel { min-height: 56px; }

  /* 底部分頁列 */
  #tabs { flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px)); }
  #tabs button { position: relative; display: grid; gap: 0; justify-items: center; padding: 6px 2px; border-radius: 10px; background: #1f1729; border: 1px solid var(--line); color: var(--muted); }
  #tabs button b { font-size: 14px; font-weight: 900; letter-spacing: .06em; }
  #tabs button small { font: 11px var(--font-num); opacity: .85; }
  #tabs button.on { background: linear-gradient(#3b2c55, #2a1f3c); border-color: var(--gold); color: var(--gold); box-shadow: 0 0 12px rgba(255,216,77,.25); }
  #tabs button.alert::after { content: ''; position: absolute; top: 5px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--up); box-shadow: 0 0 0 2px #1f1729, 0 0 10px var(--up); animation: ping 0.8s ease-in-out infinite alternate; }
  #tabs button[data-tab="market"].alert { border-color: var(--up); color: #ffd0d5; }
  @keyframes ping { from { transform: scale(.8); } to { transform: scale(1.25); } }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 899px) and (max-height: 700px) {
  #hud .stats .stat:nth-child(4) { display: none; }
  .bet button { padding: 9px 4px; font-size: 16px; }
}

/* 音樂／音效開關 */
.audio-tg { display: flex; gap: 4px; flex: none; }
.atg { position: relative; display: inline-flex; align-items: center; gap: 3px; height: 26px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #2a2036; border: 1px solid var(--gold); color: var(--gold); }
.atg span { font-size: 12px; line-height: 1; }
.atg.off { border-color: var(--line); color: var(--muted); opacity: .75; }
.atg.off::after { content: ''; position: absolute; left: 8px; right: 8px; top: 50%; height: 2px; background: var(--up); transform: rotate(-12deg); }
@media (max-width: 899px) { .atg { height: 24px; padding: 0 6px; font-size: 11px; } }
@media (max-width: 380px) { #hud .stats .stat:nth-child(4) { display: none; } }

/* =========================================================
   標題畫面、世界地圖、設定、新手教學
   ========================================================= */
html, body { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overscroll-behavior: none; }
.toast { z-index: 50; }
.modal-body h2.win { color: var(--gold); } .modal-body h2.lose { color: var(--up); }
.modal-body .unlock { background: #3a2f0a; border: 1px solid var(--gold); color: var(--gold); border-radius: 8px; padding: 8px 10px; font-weight: 700; margin: 0 0 10px; }
.modal-body .reroll + .reroll, .modal-body .primary + .reroll { margin-top: 8px; }
.modal-body .reroll { width: 100%; }
.confirm-t { font-size: 15px; margin: 0 0 6px; }
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 2px; border-bottom: 1px solid var(--line); font-size: 15px; }
.set-row .tg { min-width: 84px; padding: 8px 12px; border-radius: 999px; background: #2a2036; border: 1px solid var(--line); font-weight: 700; }
.set-row .tg.on { background: var(--gold); color: #1a1300; border-color: var(--gold); }
.set-row.danger span { color: var(--up); } .set-row.danger .tg { border-color: var(--up); color: var(--up); }
#btnMenu span { font-size: 13px; }

/* ---- 標題畫面：手機用直式圖，電腦用橫式圖 ---- */
.title-screen { position: fixed; inset: 0; z-index: 35; overflow: hidden; background: #1a1408; }
.title-art { position: absolute; inset: 0; background: var(--tm) center 30% / cover no-repeat; animation: titleZoom 24s ease-in-out infinite alternate; }
.title-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,.25) 0%, transparent 30%, transparent 52%, rgba(10,6,2,.85) 100%); }
@keyframes titleZoom { from { transform: scale(1); } to { transform: scale(1.06); } }
.title-inner { position: relative; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 20px calc(18px + env(safe-area-inset-bottom, 0px)); }
.title-logo { width: min(92vw, 520px); height: auto; filter: drop-shadow(0 6px 14px rgba(0,0,0,.6)); animation: logoIn .9s cubic-bezier(.2,1.4,.4,1) both; }
@keyframes logoIn { from { opacity: 0; transform: translateY(-20px) scale(.85); } to { opacity: 1; transform: none; } }
.title-btns { display: flex; flex-direction: column; gap: 12px; width: min(84vw, 340px); animation: logoIn .9s .25s both; }
.tbtn { position: relative; padding: 14px 16px; border-radius: 14px; font-size: 20px; font-weight: 900; letter-spacing: .12em; color: #ffe9a8;
  background: linear-gradient(180deg, #3b2a12, #1d1308); border: 2px solid #c9a24a; box-shadow: 0 4px 0 #6b4f17, 0 8px 18px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,230,160,.35);
  text-shadow: 0 2px 0 #000; display: flex; flex-direction: column; align-items: center; }
.tbtn.main { background: linear-gradient(180deg, #ffe07a, #d39a1f); color: #3a2200; text-shadow: 0 1px 0 #fff3; border-color: #fff1b8; box-shadow: 0 4px 0 #8a5a0c, 0 0 22px rgba(255,210,90,.55); }
.tbtn small { font-size: 12px; font-weight: 500; letter-spacing: 0; color: #e6d3a2; opacity: .9; margin-top: 2px; }
.tbtn:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 #6b4f17; }
.title-foot { margin: 6px 0 0; font-size: 12px; color: #f3e3bb; text-shadow: 0 1px 3px #000; opacity: .85; }
@media (min-aspect-ratio: 1/1) and (min-width: 700px) {
  .title-art { background-image: var(--td); background-position: center; }
  .title-art::after { background: radial-gradient(ellipse at 50% 30%, transparent 30%, rgba(0,0,0,.45) 100%), linear-gradient(180deg, transparent 55%, rgba(10,6,2,.8) 100%); }
  .title-inner { justify-content: center; gap: 28px; }
  .title-logo { width: min(46vw, 600px); }
  .title-btns { width: 320px; }
}

/* ---- 世界地圖 ---- */
.worldmap { position: fixed; inset: 0; z-index: 36; background: #2a2218; display: flex; flex-direction: column; }
.wm-head { display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px; background: linear-gradient(180deg, #1d1308, #2d1f0c); border-bottom: 2px solid #c9a24a; z-index: 2; }
.wm-btn { padding: 8px 12px; border-radius: 10px; background: #3b2a12; border: 1px solid #c9a24a; color: #ffe9a8; font-weight: 700; flex: none; }
.wm-lv { flex: 1; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: center; min-width: 0; }
.wm-lv b { color: var(--gold); font-size: 16px; }
.wm-lv small { grid-column: 1 / -1; color: #e6d3a2; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lvxp { position: relative; height: 14px; border-radius: 7px; background: #0008; overflow: hidden; border: 1px solid #c9a24a66; }
.lvxp i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #8a5a0c, var(--gold)); }
.lvxp em { position: relative; display: block; text-align: center; font: 700 10px/14px var(--font-num); color: #fff; font-style: normal; text-shadow: 0 1px 2px #000; }
.wm-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.wm-map { position: relative; width: 100%; }
.wm-map img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
/* MAPANIM_V1: canvas overlay under path + nodes, never intercepts clicks */
#wmFx, .wm-fx { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; z-index: 2; }
#wmPath { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
#wmNodes { z-index: 4; }
#wmPath .road { fill: none; stroke: rgba(255,244,214,.9); stroke-width: 4; stroke-dasharray: 2 8; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; filter: drop-shadow(0 1px 1px #0009); }
#wmPath .road.done { stroke: #ffc93a; stroke-width: 5; stroke-dasharray: none; }
#wmNodes { position: absolute; inset: 0; }
.wm-node { position: absolute; transform: translate(-50%, -50%); width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font: 900 14px var(--font-num); color: #3a2200; background: radial-gradient(circle at 35% 30%, #fff3b0, #f0b32a 60%, #a86a08); border: 2px solid #fff6cf; box-shadow: 0 3px 0 #6b4310, 0 4px 10px #0009; padding: 0; }
.wm-node.big { width: 40px; height: 40px; font-size: 15px; }
.wm-node.done { background: radial-gradient(circle at 35% 30%, #d6ffd8, #3fbf6a 60%, #1d6e3a); color: #fff; border-color: #eaffea; box-shadow: 0 3px 0 #134a26, 0 4px 10px #0009; }
.wm-node.lock { background: radial-gradient(circle at 35% 30%, #9aa3ad, #59616b 65%, #333a42); color: #fff; border-color: #c9d0d8; font-size: 13px; box-shadow: 0 2px 0 #222, 0 3px 6px #0008; cursor: not-allowed; opacity: .92; }
.wm-node.reserved { opacity: .48; pointer-events: none; box-shadow: 0 1px 0 #222, 0 2px 4px #0006; }
.wm-node.cur { animation: nodePulse 1.2s ease-in-out infinite; }
.wm-node.sel { outline: 3px solid #fff; outline-offset: 3px; z-index: 3; }
@keyframes nodePulse { 0%,100% { box-shadow: 0 3px 0 #6b4310, 0 0 0 0 rgba(255,214,80,.8); } 50% { box-shadow: 0 3px 0 #6b4310, 0 0 0 12px rgba(255,214,80,0); } }
.wm-hero { position: absolute; transform: translate(-50%, -112%); pointer-events: none; z-index: 4; animation: heroBob 1s ease-in-out infinite alternate; }
.wm-hero img { width: 46px; height: 46px; object-fit: contain; filter: drop-shadow(0 3px 3px #000a); }
@keyframes heroBob { from { margin-top: 0; } to { margin-top: -6px; } }
.wm-region { position: absolute; transform: translate(-50%, -50%); padding: 3px 10px; border-radius: 999px; background: rgba(29,19,8,.78); border: 1px solid #c9a24a; color: #ffe9a8; font-size: 12px; font-weight: 900; letter-spacing: .1em; white-space: nowrap; pointer-events: none; text-shadow: 0 1px 2px #000; }
.wm-info { background: linear-gradient(180deg, #2d1f0c, #1d1308); border-top: 2px solid #c9a24a; padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px)); color: #f3e3bb; }
.wm-info h3 { margin: 0; font-size: 20px; color: #fff; } .wm-info h3 small { font-size: 14px; color: #e6d3a2; font-weight: 700; margin-left: 6px; }
.wi-top { display: flex; justify-content: space-between; font-weight: 900; color: var(--gold); }
.wi-line { margin: 2px 0; font-size: 13px; } .wi-line b { color: var(--gold); }
.wm-info .primary { width: 100%; margin-top: 8px; font-size: 18px; }
.wm-info .reroll { width: 100%; margin-top: 6px; }
/* 電腦版：地圖整張放進畫面，右邊是關卡資訊 */
.worldmap.d { display: grid; grid-template-columns: 1fr 300px; grid-template-rows: auto 1fr; }
.worldmap.d .wm-head { grid-column: 1 / -1; }
.worldmap.d .wm-scroll { overflow: hidden; display: grid; place-items: center; padding: 12px; }
.worldmap.d .wm-map { width: min(100%, calc((100vh - 90px) * 16 / 9)); border-radius: 12px; overflow: hidden; box-shadow: 0 0 0 3px #c9a24a, 0 10px 30px #000a; }
.worldmap.d .wm-info { border-top: 0; border-left: 2px solid #c9a24a; display: flex; flex-direction: column; gap: 4px; padding: 18px; }
.worldmap.d .wm-info h3 { font-size: 26px; }
.worldmap.d .wm-node { width: 30px; height: 30px; font-size: 13px; } .worldmap.d .wm-node.big { width: 36px; height: 36px; }

/* ---- 新手教學 ---- */
.tut { position: fixed; inset: 0; z-index: 38; pointer-events: none; }
.tut.dim { opacity: 0; }
.tut-spot { position: fixed; border-radius: 12px; border: 3px solid var(--gold); box-shadow: 0 0 0 9999px rgba(5,3,10,.55), 0 0 18px var(--gold); transition: all .25s ease; }
.tut-arrow { position: fixed; transform: translateX(-50%); font-size: 38px; line-height: 1; filter: drop-shadow(0 2px 4px #000); animation: tutBounce .7s ease-in-out infinite alternate; transition: left .25s, top .25s; }
@keyframes tutBounce { from { translate: 0 -5px; } to { translate: 0 6px; } }
.tut-tip { position: fixed; pointer-events: auto; background: #1d1308f2; border: 2px solid var(--gold); border-radius: 12px; padding: 12px 14px 10px; color: #fff; box-shadow: 0 8px 24px #000c; transition: top .25s, left .25s; }
.tut-tip p { margin: 0 0 8px; font-size: 15px; line-height: 1.55; }
.tut-tip b { color: var(--gold); } .tut-tip b.up { color: var(--up); } .tut-tip b.dn { color: var(--dn); }
.tut-btns { display: flex; justify-content: space-between; gap: 8px; }
.tut-btns .primary { padding: 8px 18px; font-size: 15px; margin: 0; }
.tut-btns .ghost { color: var(--muted); background: transparent; padding: 8px 4px; }

/* ---------- 過關動畫 ---------- */
.vic { position: fixed; inset: 0; z-index: 39; display: grid; place-items: center; overflow: hidden; cursor: pointer;
  background: radial-gradient(circle at 50% 45%, rgba(255,214,110,.4), rgba(20,12,4,.93) 62%); animation: vicFade .35s ease-out; }
.vic.out { animation: vicOut .35s ease-in forwards; }
@keyframes vicFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes vicOut { to { opacity: 0; } }
.vic-rays { position: absolute; left: 50%; top: 45%; width: 180vmax; height: 180vmax; transform: translate(-50%, -50%);
  background: repeating-conic-gradient(rgba(255,220,120,.24) 0 7deg, transparent 7deg 18deg); animation: vicSpin 16s linear infinite;
  -webkit-mask: radial-gradient(circle, #000 8%, transparent 55%); mask: radial-gradient(circle, #000 8%, transparent 55%); }
@keyframes vicSpin { to { transform: translate(-50%, -50%) rotate(360deg); } }
.vic-in { position: relative; text-align: center; padding: 0 16px; animation: vicIn .7s cubic-bezier(.2,1.6,.4,1) .15s both; }
@keyframes vicIn { from { transform: scale(.3); opacity: 0; } to { transform: none; opacity: 1; } }
.vic-stage { font-size: clamp(16px, 4.5vw, 24px); color: #ffe9b0; letter-spacing: .3em; font-weight: 800; text-shadow: 0 2px 4px #000; }
.vic-title { font-family: "Noto Serif TC", "Songti TC", "STSong", serif; font-weight: 900; font-size: clamp(72px, 20vw, 160px); line-height: 1.1;
  background: linear-gradient(#fffbe6, #ffd35a 42%, #b8700c 56%, #ffe7a0); -webkit-background-clip: text; background-clip: text; color: transparent;
  -webkit-text-stroke: 2px #5a3406; filter: drop-shadow(0 6px 0 #3a2105) drop-shadow(0 0 26px rgba(255,200,80,.75)); }
/* 征服！：書法金字圖（同 LOGO 風格），取代襯線字 */
.vic-title.vic-img { background: none; -webkit-text-stroke: 0; color: inherit; font-size: 0; line-height: 0; margin: 4px 0 6px;
  filter: drop-shadow(0 5px 3px rgba(20,8,0,.7)) drop-shadow(0 0 22px rgba(255,200,80,.55)); }
.vic-title.vic-img img { display: block; width: min(88vw, 560px); height: auto; margin: 0 auto; }
.vic-sub { color: #fff; font-size: clamp(15px, 4vw, 20px); font-weight: 700; text-shadow: 0 2px 4px #000; }
.vic-stars { margin-top: 8px; font-size: clamp(34px, 9vw, 54px); color: #ffd35a; letter-spacing: .12em; text-shadow: 0 0 14px #ffb300, 0 3px 0 #7a4a08; }
.vic-stars span { display: inline-block; animation: vicStar .5s cubic-bezier(.2,1.8,.4,1) both; }
.vic-stars span:nth-child(1) { animation-delay: .8s; } .vic-stars span:nth-child(2) { animation-delay: 1.05s; } .vic-stars span:nth-child(3) { animation-delay: 1.3s; }
@keyframes vicStar { from { transform: scale(0) rotate(-120deg); opacity: 0; } to { transform: none; opacity: 1; } }
.vic-fx i { position: absolute; left: 50%; top: 45%; width: 8px; height: 15px; border-radius: 2px; background: var(--c); animation: vicConf var(--d) cubic-bezier(.1,.6,.4,1) var(--w) both; }
@keyframes vicConf { from { transform: translate(-50%, -50%) rotate(0); opacity: 1; } to { transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(var(--r)); opacity: 0; } }
.vic-tap { position: absolute; left: 0; right: 0; bottom: calc(26px + env(safe-area-inset-bottom, 0px)); text-align: center; color: #ffe9b0; font-size: 14px; animation: vicBlink 1.1s ease-in-out 1.6s infinite alternate both; }
@keyframes vicBlink { from { opacity: 0; } to { opacity: .85; } }

/* ---------- 世界地圖：征服動畫、股票名標籤 ---------- */
.wm-hero { transition: left .9s cubic-bezier(.45,0,.55,1), top .9s cubic-bezier(.45,0,.55,1); }
.wm-tag { position: absolute; transform: translate(-50%, 24px); z-index: 5; pointer-events: none; white-space: nowrap;
  background: linear-gradient(#3b2a12, #1d140a); color: #ffe9b0; border: 1px solid #e0b257; border-radius: 8px; padding: 3px 9px;
  font-size: 12px; font-weight: 800; box-shadow: 0 3px 8px #000a; animation: wmTagIn .35s ease-out; }
.worldmap.d .wm-tag { transform: translate(-50%, 20px); }
@keyframes wmTagIn { from { opacity: 0; margin-top: -8px; } to { opacity: 1; margin-top: 0; } }
.wm-node.conquer { z-index: 6; animation: wmConquer 1s ease-out forwards; }
@keyframes wmConquer {
  0% { filter: brightness(1); transform: translate(-50%, -50%) scale(1); box-shadow: 0 0 0 0 rgba(255,240,180,.9); }
  40% { filter: brightness(2.4); transform: translate(-50%, -50%) scale(1.7); box-shadow: 0 0 34px 16px rgba(255,230,140,.95); }
  100% { filter: brightness(1.5); transform: translate(-50%, -50%) scale(1.3); box-shadow: 0 0 24px 10px rgba(255,214,80,.85); } }
.wm-node.justdone { animation: wmPop .6s ease-out; }
.wm-node.unlock { animation: wmPop .6s ease-out, nodePulse 1.2s ease-in-out .6s infinite; }
@keyframes wmPop { 0% { transform: translate(-50%, -50%) scale(1.5); filter: brightness(2); } 100% { transform: translate(-50%, -50%) scale(1); filter: none; } }
.wm-burst { position: absolute; transform: translate(-50%, -50%); width: 10px; height: 10px; border: 3px solid #ffd76a; border-radius: 50%;
  pointer-events: none; z-index: 5; box-shadow: 0 0 12px #ffcf4a; animation: wmBurst .9s ease-out both; }
@keyframes wmBurst { from { width: 10px; height: 10px; opacity: 1; } to { width: 150px; height: 150px; opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .vic-rays { animation: none; } .wm-hero { transition: none; } }

/* ---------- 盔甲進階（armor.js） ---------- */
.armtag { font: 700 11px var(--font-ui); padding: 1px 6px; border-radius: 999px; color: #1a1408; background: var(--ac); box-shadow: 0 0 6px var(--ac); }
.wm-arm { text-shadow: 0 0 6px currentColor; }
.lvup { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: radial-gradient(circle at 50% 45%, rgba(60,40,8,.88), rgba(6,4,10,.94)); padding: 16px; animation: lvIn .35s ease-out; --ac: #ffd84d; }
.lvup.out { animation: lvOut .25s ease-in forwards; }
.lvup-rays { position: absolute; inset: -50%; background: repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--ac) 22%, transparent) 0 8deg, transparent 8deg 20deg); animation: lvSpin 14s linear infinite; pointer-events: none; mask: radial-gradient(circle, #000 15%, transparent 55%); }
.lvup-in { position: relative; text-align: center; width: min(440px, 100%); }
.lvup-t { font: 900 clamp(34px, 11vw, 52px)/1.1 var(--font-ui); color: #ffe27a; text-shadow: 0 3px 0 #8a5a00, 0 0 24px #ffb300; animation: lvPop .5s cubic-bezier(.2,1.6,.4,1); }
.lvup-lv { margin: 10px 0 4px; font: 900 26px var(--font-num); color: #fff; display: flex; gap: 12px; justify-content: center; align-items: center; }
.lvup-lv span { opacity: .6; } .lvup-lv b { color: var(--gold); } .lvup-lv em { font-style: normal; color: #ffe27a; font-size: 34px; text-shadow: 0 0 14px #ffb300; }
.lvup-b { color: #f3e7c6; margin: 4px 0 12px; font-weight: 700; }
.lvup-next { color: #cfc6b0; font-size: 14px; } .lvup-next b { margin-left: 4px; }
.lvup-arm { border: 2px solid var(--ac); border-radius: 14px; padding: 12px 10px; background: rgba(0,0,0,.45); box-shadow: 0 0 28px color-mix(in srgb, var(--ac) 60%, transparent), inset 0 0 18px color-mix(in srgb, var(--ac) 30%, transparent); animation: lvPop .6s .15s cubic-bezier(.2,1.5,.4,1) both; }
.lvup-an { font: 900 24px var(--font-ui); color: var(--ac); text-shadow: 0 0 12px var(--ac), 0 2px 0 #000; }
.lvup-units { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin: 10px 0 6px; }
.lvup-units img { width: 100%; aspect-ratio: 1; object-fit: contain; filter: drop-shadow(0 0 6px var(--ac)); animation: lvUnit .5s cubic-bezier(.2,1.6,.4,1) both; }
.lvup-units img:nth-child(2) { animation-delay: .25s } .lvup-units img:nth-child(3) { animation-delay: .32s } .lvup-units img:nth-child(4) { animation-delay: .39s }
.lvup-units img:nth-child(5) { animation-delay: .46s } .lvup-units img:nth-child(6) { animation-delay: .53s } .lvup-units img:nth-child(7) { animation-delay: .6s } .lvup-units img:nth-child(1) { animation-delay: .18s }
.lvup-arm p { margin: 4px 0 0; color: #fff; font-weight: 700; } .lvup-arm small { color: #cfc6b0; font-weight: 400; }
.lvup.a3 .lvup-an { background: linear-gradient(90deg, #8ff4ff, #d9a8ff, #fff, #8ff4ff); -webkit-background-clip: text; background-clip: text; color: transparent; background-size: 200% 100%; animation: lvShine 2s linear infinite; }
.lvup-tap { margin-top: 14px; color: #cfc6b0; font-size: 13px; animation: lvBlink 1.2s ease-in-out infinite; }
@keyframes lvIn { from { opacity: 0 } } @keyframes lvOut { to { opacity: 0; transform: scale(1.04) } }
@keyframes lvSpin { to { transform: rotate(360deg) } }
@keyframes lvPop { from { transform: scale(.3); opacity: 0 } }
@keyframes lvUnit { from { transform: translateY(18px) scale(.4); opacity: 0 } }
@keyframes lvShine { to { background-position: -200% 0 } }
@keyframes lvBlink { 50% { opacity: .4 } }

/* 投報率（HUD）：手機上把「交易勝率」縮成「勝率」、藏起連勝，讓投報率擠得下 */
.stat.roi b.up { color: var(--up); } .stat.roi b.dn { color: var(--dn); }
#wmBonus b.up { color: var(--up); } #wmBonus b.dn { color: var(--dn); }
@media (max-width: 899px) {
  #hud .stats .stat:nth-child(4) { display: none; }
  #hud .stat .dk { display: none; }
  #hud .stats { gap: 3px; }
  #hud .stat { padding: 1px 5px; }
  #hud .stat .bar { width: 22px; }
}
@media (max-width: 380px) { #hud .stat .bar { display: none; } #hud .stat { padding: 1px 4px; } }

/* ---- 標題畫面：全球排行榜（LOGO 下方） ---- */
.lb { --rows: 5; width: min(92vw, 380px); margin: 4px 0 auto; flex: 0 1 auto; min-height: 0; overflow: hidden; z-index: 1;
  background: linear-gradient(180deg, rgba(34,22,8,.82), rgba(16,10,4,.86)); border: 1.5px solid #c9a24a; border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,230,160,.25); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  padding: 6px 8px 6px; color: #f3e3bb; }
.lb-head { display: flex; align-items: center; gap: 6px; }
.lb-head > b { flex: none; font-family: "Noto Serif TC", "Songti TC", serif; font-weight: 900; font-size: 13px; color: var(--gold); letter-spacing: .06em; text-shadow: 0 1px 2px #000; }
.lb-tabs { flex: 1; display: flex; gap: 3px; min-width: 0; }
.lb-tabs button { flex: 1 1 auto; padding: 4px 2px; border-radius: 7px; font-size: 12px; font-weight: 700; white-space: nowrap; color: #e6d3a2; background: rgba(0,0,0,.35); border: 1px solid #6b4f17; }
.lb-tabs button.on { background: linear-gradient(180deg, #ffe07a, #d39a1f); color: #3a2200; border-color: #fff1b8; }
.lb-list { list-style: none; margin: 5px 0 0; padding: 0; height: calc(var(--rows) * 22px); overflow: hidden; }
.lb-list li { display: flex; align-items: center; gap: 6px; height: 22px; font-size: 13px; border-bottom: 1px solid rgba(201,162,74,.16); }
.lb-list li:nth-child(n + 6) { display: none; }
.lb-list li.me { background: rgba(255,216,77,.14); border-radius: 5px; }
.lb-list li.lb-msg { justify-content: center; color: var(--muted); height: calc(var(--rows) * 22px); border: 0; }
.lb-list .rk { flex: none; width: 20px; height: 18px; display: grid; place-items: center; font: 700 11px var(--font-num); font-style: normal; border-radius: 5px; background: rgba(255,255,255,.08); color: #e6d3a2; }
.lb-list .rk.r1 { background: linear-gradient(#ffe98a, #d6a21c); color: #3a2200; }
.lb-list .rk.r2 { background: linear-gradient(#f2f4f8, #a9b0bc); color: #22262e; }
.lb-list .rk.r3 { background: linear-gradient(#f0b27a, #a8642c); color: #2a1404; }
.lb-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.lb-list .v { flex: none; font: 500 12px var(--font-num); color: #e6d3a2; }
.lb-list .v b { font-weight: 700; color: #fff3c4; } .lb-list .v b.up { color: var(--up); } .lb-list .v b.dn { color: var(--dn); }
.lb-list .v small { margin-left: 4px; font-size: 10px; color: var(--muted); }
.lb-me { margin-top: 5px; }
.lb-me button { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 8px; font-size: 12px; color: #f3e3bb; background: rgba(0,0,0,.35); border: 1px dashed #c9a24a; }
.lb-me .lb-join { justify-content: center; font-weight: 900; color: var(--gold); }
.lb-me .lb-mine .nm { font-weight: 700; color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-me .lb-mine b { color: #fff3c4; font-family: var(--font-num); }
.lb-input { width: 100%; box-sizing: border-box; margin: 4px 0 6px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: #0b0812; color: #fff; font-size: 16px; }
/* 矮螢幕少顯示幾名，維持一屏不捲動 */
@media (max-height: 720px) { .lb { --rows: 4; } .lb-list li:nth-child(n + 5) { display: none; } }
@media (max-height: 640px) { .lb { --rows: 3; } .lb-list li:nth-child(n + 4) { display: none; } .title-btns { gap: 8px; } .tbtn { padding: 10px 14px; } }
@media (max-height: 560px) { .lb { --rows: 2; } .lb-list li:nth-child(n + 3) { display: none; } }
@media (max-width: 480px) { .lb-head > b { display: none; } }
/* 電腦橫式：LOGO 在上，排行榜和按鈕並排 */
@media (min-aspect-ratio: 1/1) and (min-width: 700px) {
  .title-inner { display: grid; grid-template-columns: auto auto; grid-template-areas: "logo logo" "lb btns" "foot foot"; justify-content: center; align-content: center; column-gap: 32px; row-gap: 22px; }
  .title-logo-box { grid-area: logo; justify-self: center; }
  .lb { --rows: 7; grid-area: lb; width: 400px; margin: 0; align-self: center; }
  .lb-list li:nth-child(n + 6) { display: flex; } .lb-list li:nth-child(n + 8) { display: none; }
  .title-btns { grid-area: btns; align-self: center; }
  .title-foot { grid-area: foot; justify-self: center; margin: 0; }
}
@media (min-aspect-ratio: 1/1) and (min-width: 700px) and (max-height: 760px) { .lb { --rows: 5; } .lb-list li:nth-child(n + 6) { display: none; } }
@media (min-aspect-ratio: 1/1) and (min-width: 700px) and (max-height: 560px) { .lb { --rows: 3; } .lb-list li:nth-child(n + 4) { display: none; } }
/* NDX5_V1 章節切換 */
.wm-chap { display: flex; gap: 6px; margin: 0 0 8px; }
.wm-ch { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 4px; border-radius: 10px; border: 1px solid #8a6d2e; background: rgba(29,19,8,.7); color: #d9c38a; font-weight: 800; font-size: 13px; line-height: 1.15; cursor: pointer; }
.wm-ch small { font-size: 11px; font-weight: 700; opacity: .85; }
.wm-ch.on { background: linear-gradient(180deg, #ffe08a, #c9902a); color: #2a1a05; border-color: #ffe9a8; box-shadow: 0 0 10px #ffcf5a88; }
.wm-ch.lock { opacity: .55; }
/* NDX13_V1：六個章節分頁在窄屏不溢出 */
@media (max-width: 430px) {
  .wm-chap { gap: 3px; }
  .wm-ch { padding: 4px 2px; font-size: 11px; }
  .wm-ch small { font-size: 9px; }
}
/* NDX5_V1 神龍盔甲升級畫面、10 兵種頭像 */
.lvup-units { grid-template-columns: repeat(5, 1fr); }
.lvup-units img:nth-child(8) { animation-delay: .67s } .lvup-units img:nth-child(9) { animation-delay: .74s } .lvup-units img:nth-child(10) { animation-delay: .81s }
.lvup.a4 .lvup-an { background: linear-gradient(90deg, #ff5a3a, #ffd45a, #fff3c4, #ff5a3a); -webkit-background-clip: text; background-clip: text; color: transparent; background-size: 200% 100%; animation: lvShine 1.6s linear infinite; }
/* NDX5_V1 招募列：10 個兵種（手機 5×2、電腦 10 欄），未開放的兵種上鎖 */
.shop { grid-template-columns: repeat(10, minmax(0, 1fr)); }
@media (max-width: 900px) { .shop { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.buy.lock { filter: grayscale(.85) brightness(.7); }
.buy.lock .cost { color: #cfc6b0; font: 700 10px var(--font-ui); white-space: nowrap; }
.buy.new:not(.lock) { border-color: #c9a24a; box-shadow: inset 0 0 8px #ffd84d44; }

/* =========================================================
   UI_OVERLAP_V1：征服字組上移到戰場、過關標籤不與股票 pill 疊字；
   徵兵 10 兵種卡片與選中單位資訊在 360/390/430／桌面不重疊、不裁切
   ========================================================= */
body:has(#vic:not([hidden])) #stockTag { visibility: hidden; pointer-events: none; }
.vic { display: block; background: radial-gradient(circle at var(--vic-cx, 50%) var(--vic-cy, 32%), rgba(255,214,110,.4), rgba(20,12,4,.88) 42%, rgba(12,8,4,.94) 70%); }
.vic-rays { top: var(--vic-cy, 32%); left: var(--vic-cx, 50%); }
.vic-fx i { top: var(--vic-cy, 32%); left: var(--vic-cx, 50%); }
.vic-in { position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%);
  padding: 8px 12px 10px; max-width: min(var(--vic-w, calc(100vw - 16px)), 640px); max-height: var(--vic-h, 46vh);
  box-sizing: border-box; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(16,10,4,.82) 0%, rgba(16,10,4,.42) 58%, transparent 76%); }
@keyframes vicIn { from { transform: translate(-50%, -50%) scale(.3); opacity: 0; } to { transform: translate(-50%, -50%); opacity: 1; } }
.vic-stage { display: inline-block; margin: 0 auto 4px; padding: 3px 12px; border-radius: 999px;
  background: rgba(20,15,28,.92); border: 1px solid #e6c36a; color: #ffe9b0;
  font-size: clamp(13px, 3.6vw, 20px); letter-spacing: .18em; font-weight: 800; text-shadow: 0 2px 4px #000;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.vic-title.vic-img { margin: 2px 0 4px; }
.vic-title.vic-img img { display: block; width: auto; height: auto; margin: 0 auto;
  max-width: min(88vw, 560px, 100%, var(--vic-w, 88vw));
  max-height: min(26vh, calc(var(--vic-h, 42vh) * 0.55)); }
.vic-sub { padding: 0 8px; font-size: clamp(13px, 3.6vw, 18px); overflow-wrap: anywhere; }
.vic-stars { margin-top: 4px; font-size: clamp(24px, 6.5vw, 48px); }

/* 徵兵卡片：名稱、職業分行，窄欄不裁切、不擠成兩行亂排 */
.shop, .buy, .buy .nm { min-width: 0; }
.buy { overflow: hidden; }
.buy .nm { display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  width: 100%; line-height: 1.15; text-align: center; font-size: 11px; font-weight: 700; }
.buy .nm .nn { display: block; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 1px; }
.buy .nm i { display: block; margin-left: 0; font-size: 9px; font-weight: 700; opacity: .8; line-height: 1.2;
  width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 選中單位：不縮到內容以下、不往上溢出蓋住商店 */
#ctrl .shop { flex: 0 0 auto; overflow: visible; }
#ctrl .unit-panel, #ctrl .facs, #ctrl .cores, #ctrl .ctrl-head { flex: none; }
.unit-panel { min-height: min-content; align-items: flex-start; overflow: hidden; z-index: 1; }
.ui-info { min-width: 0; overflow: hidden; }
.ui-head { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 6px; min-width: 0; }
.ui-name { min-width: 0; font-size: 13px; font-weight: 800; line-height: 1.25; }
.ui-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); }
.ui-stats { display: flex; flex-wrap: wrap; gap: 0 8px; }
.ui-stats span { white-space: nowrap; }

@media (max-width: 899px) {
  .shop { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .buy { padding: 3px 1px 4px; }
  .buy img { width: 36px; height: 36px; }
  .buy .nm { font-size: 11px; }
  .buy.lock .cost { font-size: 9px; }
  .unit-panel { min-height: min-content; align-items: flex-start; padding: 6px; gap: 6px; }
  .unit-panel img { width: 40px; height: 40px; }
  .ui-btns button { font-size: 11px; padding: 4px 6px; }
  .ui-info .ui-talent { display: none; }
}
@media (max-width: 370px) {
  .buy img { width: 32px; height: 32px; }
  .buy .nm { font-size: 10px; }
  .buy .nm i { font-size: 8px; }
  .unit-panel img { width: 36px; height: 36px; }
  .ui-name { font-size: 12px; }
}
@media (min-width: 900px) {
  .buy .nm { font-size: 12px; }
  .buy .nm i { font-size: 10px; }
}

@media (max-width: 899px) and (max-height: 700px) {
  #ctrl .facs { margin-top: 4px; gap: 3px; }
  #ctrl .cores { margin-top: 2px; }
  .facchip { font-size: 11px; padding: 1px 6px; }
}
