/* 玩具要塞 · 移动端优先深色 UI */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #12151c; color: #e8e6e0;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
#cv, #cv3d, #cv-hit { position: fixed; inset: 0; display: block; touch-action: none; }
#cv, #cv3d { z-index: 0; }
#cv-hit { z-index: 1; }
#cv.inactive, #cv3d.inactive { display: none; }
#ui { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
#ui > * { pointer-events: auto; }
.hidden { display: none !important; }

/* ---------- 通用 ---------- */
.screen {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, #1d2433 0%, #12151c 70%);
  overflow-y: auto; padding: 12px;
}
.panel {
  width: min(560px, 96vw); max-height: 94vh; overflow-y: auto;
  background: #1a1f2bcc; border: 1px solid #313a4e; border-radius: 16px;
  padding: 20px; backdrop-filter: blur(6px);
}
.panel.center { text-align: center; }
h1 { font-size: 30px; margin-bottom: 6px; letter-spacing: 2px; }
h2 { font-size: 20px; margin-bottom: 12px; }
h3 { font-size: 15px; margin: 14px 0 8px; color: #b8c0d0; }
.sub { color: #8f9ab0; margin-bottom: 18px; font-size: 14px; }
.dim { color: #7d8699; font-size: 13px; }
.gold { color: #f5c542; }
.tag { font-size: 13px; background: #2a3245; border-radius: 6px; padding: 2px 8px; vertical-align: middle; }
.row { display: flex; gap: 10px; margin: 10px 0; align-items: stretch; }
.grow { flex: 1; }
.render-mode-row .mode-choice.active { border-color: #f5c542; box-shadow: 0 0 0 1px #f5c54266 inset; color: #f5c542; }

input, select {
  background: #10141d; color: #e8e6e0; border: 1px solid #3a445c; border-radius: 10px;
  padding: 12px 14px; font-size: 16px; outline: none; width: 100%;
}
input:focus { border-color: #f5c542; }
#inp-name { text-align: center; margin-bottom: 14px; }
#inp-room { flex: 1; }

.btn {
  background: #2a3245; color: #e8e6e0; border: 1px solid #3d4660;
  border-radius: 10px; padding: 12px 16px; font-size: 15px; cursor: pointer;
  transition: transform .06s, background .15s; white-space: nowrap;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(180deg, #f5c542, #d9a520); color: #241c05; font-weight: 700; border-color: #f5c542; }
.btn.danger { background: #55232a; border-color: #7c3742; }
.btn.pulse-danger { box-shadow: 0 0 0 2px rgba(255, 92, 92, .28), 0 0 18px rgba(255, 92, 92, .35); }
.btn.big { font-size: 17px; padding: 14px 18px; }
.btn.mini { font-size: 12px; padding: 6px 10px; }

/* ---------- 大厅 ---------- */
#room-list { display: flex; flex-direction: column; gap: 8px; max-height: 30vh; overflow-y: auto; }
.room-item {
  display: flex; justify-content: space-between; align-items: center;
  background: #222a3b; border-radius: 10px; padding: 10px 14px; cursor: pointer;
  border: 1px solid #303a52;
}
.room-item:active { background: #2c3650; }
.room-item .st { font-size: 12px; color: #8f9ab0; }

/* ---------- 房间 ---------- */
.teams { display: flex; gap: 10px; margin: 12px 0; }
.team-col { flex: 1; border-radius: 12px; padding: 10px; min-height: 120px; }
.team-col.blue { background: #1b2a4288; border: 1px solid #2e4a7d; }
.team-col.red { background: #3a1f2488; border: 1px solid #7d2e3a; }
.team-col h4 { font-size: 14px; margin-bottom: 8px; text-align: center; }
.member { display: flex; align-items: center; gap: 6px; background: #00000030; border-radius: 8px; padding: 7px 9px; margin-bottom: 6px; font-size: 14px; }
.member .race-ic { font-size: 16px; }
.member .host-ic { margin-left: auto; font-size: 12px; color: #f5c542; }
.member.me { outline: 1px solid #f5c54288; }
.member.off { opacity: .45; }

/* ---------- HUD ---------- */
#hud-top {
  position: absolute; top: 0; left: 0; right: 0; height: 44px;
  display: flex; align-items: center; gap: 10px; padding: 6px 10px;
  background: linear-gradient(180deg, #0e1118ee, #0e111800);
}
#hud-gold { font-size: 16px; min-width: 130px; }
#hud-gold b { color: #f5c542; }
#hud-castles { flex: 1; display: flex; align-items: center; gap: 8px; justify-content: center; }
#hud-view3d { display: flex; gap: 6px; align-items: center; }
.cbar { position: relative; width: min(200px, 26vw); height: 16px; background: #00000088; border-radius: 8px; overflow: hidden; border: 1px solid #ffffff22; }
.cbar div { height: 100%; width: 100%; transition: width .3s; }
.cbar.blue div { background: linear-gradient(90deg, #3f7fd9, #66a8ff); }
.cbar.red div { background: linear-gradient(90deg, #d94040, #ff7a66); float: right; }
.cbar span { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 16px; color: #fff; text-shadow: 0 1px 2px #000; }
#hud-time { font-size: 14px; color: #b8c0d0; min-width: 44px; text-align: center; }

#hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 8px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, #0e1118ee, #0e111800);
}
#build-bar, #spell-bar { display: flex; gap: 6px; }
.card {
  position: relative; width: 62px; height: 68px; border-radius: 10px;
  background: #1c2333ee; border: 1px solid #3a4560; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  transition: transform .06s;
}
.card:active { transform: scale(.94); }
.card.sel { border-color: #f5c542; box-shadow: 0 0 10px #f5c54266; background: #2a3040; }
.card.dis { opacity: .45; }
.card .ic { font-size: 24px; line-height: 1; }
.card .nm { font-size: 10px; color: #c8d0e0; }
.card .cost { font-size: 11px; color: #f5c542; }
.card .cdmask {
  position: absolute; inset: 0; background: #000000aa; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 18px; color: #fff;
}
.card.spell { background: #251d33ee; }

#mode-tip {
  position: absolute; top: 84px; left: 50%; transform: translateX(-50%);
  background: #000000b0; padding: 6px 16px; border-radius: 20px; font-size: 13px; color: #f5c542;
  pointer-events: none;
}
#fate-offer {
  position: absolute; left: 50%; bottom: 94px; transform: translateX(-50%);
  width: min(520px, calc(100vw - 24px)); padding: 10px;
  background: #121722f2; border: 1px solid #44516d; border-radius: 10px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; z-index: 8;
}
#fate-offer .fate-card {
  min-height: 58px; white-space: normal; line-height: 1.2; padding: 8px;
}
#confirm-bar {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 10px;
}
#confirm-bar .btn { font-size: 16px; padding: 12px 18px; min-width: 108px; }

#bld-info {
  position: absolute; bottom: 92px; left: 50%; transform: translateX(-50%);
  background: #1a1f2bee; border: 1px solid #3a4560; border-radius: 12px; padding: 12px 16px;
  display: flex; align-items: center; gap: 12px; font-size: 14px;
}

/* ---------- 结算 ---------- */
#over-stats { margin: 14px 0; }
#over-stats table { width: 100%; border-collapse: collapse; font-size: 13px; }
#over-stats th, #over-stats td { padding: 6px 8px; text-align: center; border-bottom: 1px solid #2c3650; }
#over-stats th { color: #8f9ab0; font-weight: normal; }
#over-stats tr.blue td:first-child { color: #66a8ff; }
#over-stats tr.red td:first-child { color: #ff7a66; }

/* ---------- 杂项 ---------- */
#toast {
  position: fixed; top: 56px; left: 50%; transform: translateX(-50%);
  background: #402730ee; border: 1px solid #7c3742; color: #ffd9d9;
  padding: 8px 18px; border-radius: 20px; font-size: 14px; z-index: 50;
  pointer-events: none; transition: opacity .3s;
}
/* 重连遮罩：盖住战场但让玩家看见「位置还在」，否则弱网玩家会直接杀进程 */
#reconnect-mask {
  position: fixed; inset: 0; background: #0d1017cc; z-index: 120;
  display: flex; align-items: center; justify-content: center;
}
#reconnect-mask.hidden { display: none; }
.reconnect-box {
  background: #1b2130ee; border: 1px solid #38455f; border-radius: 14px;
  padding: 22px 30px; text-align: center; max-width: 300px;
}
.reconnect-box p { margin: 6px 0; font-size: 15px; }
.reconnect-box .dim { font-size: 12px; }
.reconnect-box .btn { margin-top: 12px; }
.reconnect-spin {
  width: 30px; height: 30px; margin: 0 auto 12px;
  border: 3px solid #38455f; border-top-color: #ffd166; border-radius: 50%;
  animation: reconnect-spin 1s linear infinite;
}
@keyframes reconnect-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .reconnect-spin { animation-duration: 3s; } }

#rotate-tip {
  position: fixed; inset: 0; background: #12151cf5; z-index: 100;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
@media (orientation: landscape) { #rotate-tip { display: none !important; } }

/* 窄屏（手机竖屏时菜单仍可用） */
@media (max-width: 600px) {
  .card { width: 54px; height: 62px; }
  .card .ic { font-size: 20px; }
  #hud-gold { min-width: 100px; font-size: 14px; }
  #hud-top { gap: 6px; padding-inline: 6px; }
  #hud-view3d .btn { padding: 5px 7px; font-size: 11px; }
  .cbar { width: min(150px, 22vw); }
}
