/* ============ 部落村庄 · 全局样式 ============ */
@font-face {
  font-family: 'KenneyFuture';
  src: url('../assets/fonts/KenneyFuture.ttf') format('truetype');
}
@font-face {
  font-family: 'KenneyFutureNarrow';
  src: url('../assets/fonts/KenneyFutureNarrow.ttf') format('truetype');
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #1a2f1a; }
body {
  font-family: 'KenneyFutureNarrow', 'Microsoft YaHei', 'PingFang SC', sans-serif;
  user-select: none; -webkit-user-select: none;
}

#game-root { position: fixed; inset: 0; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

/* ---------- 加载 ---------- */
#loading-screen {
  position: absolute; inset: 0; z-index: 100;
  background: radial-gradient(circle at 50% 35%, #3d6b35, #1c3419 70%);
  display: flex; align-items: center; justify-content: center;
}
.loading-box { text-align: center; color: #fff; }
.loading-box h1 { font-size: 52px; letter-spacing: 12px; text-shadow: 0 4px 0 #143010, 0 8px 18px rgba(0,0,0,.5); margin-bottom: 30px; color:#ffe08a; }
.loading-bar-outer { width: 340px; height: 26px; border-radius: 14px; background: rgba(0,0,0,.45); border: 3px solid #0f2410; overflow: hidden; margin: 0 auto; }
.loading-bar-inner { height: 100%; width: 0%; border-radius: 10px; background: linear-gradient(180deg,#ffe08a,#f0a830 60%,#c87f18); transition: width .15s; }
#loading-text { margin-top: 12px; font-size: 15px; opacity: .85; }

/* ---------- 通用面板皮肤（fantasy border 9-slice） ---------- */
.hud-panel, .modal-box, #info-panel, .card, #deploy-bar, #hud-player {
  border-style: solid;
  border-width: 12px;
  border-image: url('../assets/img/ui/panel-000.png') 16 fill stretch;
  image-rendering: pixelated;
}

/* ---------- HUD ---------- */
#hud-top {
  position: absolute; top: 8px; left: 8px; right: 8px; z-index: 20;
  display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none;
}
#hud-top > * { pointer-events: auto; }
#hud-player { display: flex; align-items: center; gap: 8px; padding: 2px 10px 2px 4px; color: #3d2b12; min-height: 52px; }
#hud-avatar {
  width: 44px; height: 44px; border-radius: 8px;
  background: url('../assets/img/units/knight.png') center/130% no-repeat, radial-gradient(#cfe6ff,#7fa9d8);
  border: 2px solid #7a5a2a;
}
#hud-name { font-weight: bold; font-size: 16px; }
.xp-bar { position: relative; width: 130px; height: 14px; background: #2c2416; border-radius: 8px; overflow: hidden; border: 1px solid #7a5a2a; }
#xp-fill { position:absolute; inset:0; width: 30%; background: linear-gradient(180deg,#9fe066,#5cae2a); }
#xp-text { position: absolute; inset: 0; font-size: 10px; color: #fff; text-align: center; line-height: 13px; text-shadow: 0 1px 2px #000; }
.hud-chip { background: rgba(30,22,10,.75); color: #ffe08a; border-radius: 12px; padding: 4px 10px; font-size: 14px; font-weight: bold; }

#hud-resources { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.res-bar {
  position: relative; width: 210px; height: 34px; border-radius: 18px;
  background: rgba(20,14,6,.78); border: 2px solid #6b4e20;
  display: flex; align-items: center; box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.res-bar.gems { width: 150px; }
.res-fill { position: absolute; left: 3px; top: 3px; bottom: 3px; border-radius: 14px; width: 50%; transition: width .3s; }
.res-fill.gold { background: linear-gradient(180deg,#ffd763,#e0a020 65%,#a86f10); }
.res-fill.elixir { background: linear-gradient(180deg,#f78bf0,#d33ecb 65%,#8e1f88); }
.res-icon { position: absolute; left: -8px; top: -6px; width: 44px; height: 44px; object-fit: contain; filter: drop-shadow(0 2px 3px rgba(0,0,0,.5)); }
.res-num { position: relative; margin-left: auto; padding-right: 14px; color: #fff; font-weight: bold; font-size: 17px; text-shadow: 0 2px 2px rgba(0,0,0,.7); font-family:'KenneyFutureNarrow', sans-serif; }

/* ---------- 底部按钮 ---------- */
#hud-bottom { position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 20; display: flex; gap: 10px; align-items: flex-end; pointer-events: none; }
#hud-bottom > * { pointer-events: auto; }
#btn-attack { margin-left: auto; }

.big-btn {
  min-width: 96px; padding: 12px 22px; font-size: 19px; font-weight: bold; color: #fff; cursor: pointer;
  border: 3px solid rgba(0,0,0,.35); border-radius: 14px;
  text-shadow: 0 2px 1px rgba(0,0,0,.45);
  box-shadow: inset 0 3px 0 rgba(255,255,255,.35), inset 0 -6px 0 rgba(0,0,0,.25), 0 4px 8px rgba(0,0,0,.4);
  font-family: inherit; display:flex; align-items:center; gap:6px; justify-content:center;
}
.big-btn:active { transform: translateY(2px); box-shadow: inset 0 3px 0 rgba(255,255,255,.2), 0 2px 4px rgba(0,0,0,.4); }
.big-btn.green { background: linear-gradient(180deg,#8ede4e,#4ea424); }
.big-btn.blue  { background: linear-gradient(180deg,#6fc0ff,#2f7cd6); }
.big-btn.red   { background: linear-gradient(180deg,#ff8f5e,#e04b1f); }
.big-btn.grey  { background: linear-gradient(180deg,#b9b9b9,#787878); }
.btn-ico { font-size: 22px; }

.round-btn {
  width: 54px; height: 54px; border-radius: 50%; cursor: pointer;
  background: linear-gradient(180deg,#e8dcbf,#b39b6a); border: 3px solid #6b4e20;
  box-shadow: inset 0 3px 0 rgba(255,255,255,.5), 0 4px 8px rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
}
.round-btn img { width: 26px; height: 26px; filter: invert(24%) sepia(30%) saturate(600%) hue-rotate(10deg); }
.round-btn.ok { background: linear-gradient(180deg,#8ede4e,#4ea424); border-color:#2c6410; }
.round-btn.no { background: linear-gradient(180deg,#ff8f5e,#e04b1f); border-color:#8a2600; }
.round-btn.ok img, .round-btn.no img { filter: brightness(10); width: 30px; height: 30px; }

/* ---------- 建筑信息面板 ---------- */
#info-panel {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 25;
  width: min(520px, 94vw); padding: 8px 14px 12px; color: #3d2b12;
}
.info-head { display: flex; align-items: center; gap: 10px; }
#info-title { font-size: 21px; font-weight: bold; }
.lv-chip { background: #6b4e20; color: #ffe08a; border-radius: 10px; padding: 2px 10px; font-size: 13px; font-weight: bold; }
.close-x { margin-left: auto; width: 34px; height: 34px; border-radius: 50%; border: 2px solid #6b4e20; background: #d8c294; font-size: 20px; font-weight: bold; color: #4a3416; cursor: pointer; line-height: 1; }
#info-desc { font-size: 13px; opacity: .8; margin: 4px 0 6px; }
#info-stats { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; margin-bottom: 8px; }
#info-stats b { color: #7a3c00; }
.info-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.act-btn {
  padding: 9px 16px; border-radius: 10px; font-size: 15px; font-weight: bold; color: #fff; cursor: pointer;
  border: 2px solid rgba(0,0,0,.3); font-family: inherit;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.35), inset 0 -4px 0 rgba(0,0,0,.22);
  display: flex; align-items: center; gap: 6px;
}
.act-btn.green { background: linear-gradient(180deg,#8ede4e,#4ea424); }
.act-btn.gold  { background: linear-gradient(180deg,#ffd763,#d99b13); color:#5b3c00; text-shadow:none; }
.act-btn.gem   { background: linear-gradient(180deg,#7ef0d0,#18b183); }
.act-btn.red   { background: linear-gradient(180deg,#ff8f5e,#e04b1f); }
.act-btn.blue  { background: linear-gradient(180deg,#6fc0ff,#2f7cd6); }
.act-btn:disabled { filter: grayscale(.8) brightness(.8); cursor: not-allowed; }
.act-btn img.mini { width: 18px; height: 18px; }

/* ---------- 模态窗口 ---------- */
.modal { position: absolute; inset: 0; z-index: 40; background: rgba(10,16,8,.55); display: flex; align-items: center; justify-content: center; }
.modal-box {
  width: min(760px, 95vw); max-height: 88vh; overflow-y: auto; padding: 10px 18px 18px;
  color: #3d2b12; background-clip: padding-box;
}
.modal-head { display: flex; align-items: center; margin-bottom: 8px; }
.modal-head h2 { font-size: 24px; color: #4a3416; text-shadow: 0 1px 0 #fff3d6; }
.modal-box.result { width: min(460px, 92vw); text-align: center; }

.tab-row { display: flex; gap: 6px; margin-bottom: 10px; }
.tab {
  padding: 8px 18px; border-radius: 10px 10px 0 0; border: 2px solid #6b4e20; border-bottom: none;
  background: #c9ad78; color: #57431f; font-weight: bold; font-size: 15px; cursor: pointer; font-family: inherit;
}
.tab.active { background: linear-gradient(180deg,#ffe9b3,#e8cf94); color: #3d2b12; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card-grid.small { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
.card {
  padding: 8px; text-align: center; cursor: pointer; position: relative;
  transition: transform .08s;
  background-color: #f7e7c3;
}
.card:hover { transform: scale(1.04); }
.card.disabled { filter: grayscale(.75) brightness(.85); cursor: not-allowed; }
.card img.thumb { width: 84px; height: 84px; object-fit: contain; image-rendering: auto; }
.card .c-name { font-weight: bold; font-size: 14px; margin-top: 2px; }
.card .c-sub { font-size: 11px; opacity: .75; min-height: 14px; }
.card .c-cost { display: flex; align-items: center; justify-content: center; gap: 4px; font-weight: bold; font-size: 14px; margin-top: 3px; }
.card .c-cost img { width: 18px; height: 18px; }
.card .c-cost.gold { color: #a06a00; }
.card .c-cost.elixir { color: #b0189f; }
.card .c-cnt { position: absolute; top: 4px; right: 8px; font-size: 12px; font-weight: bold; color: #57431f; background:#e8cf94; border-radius:8px; padding:1px 7px; }
.card .c-lv { position: absolute; top: 4px; left: 8px; font-size: 11px; font-weight: bold; color:#ffe08a; background:#6b4e20; border-radius:8px; padding:1px 7px; }

/* ---------- 军队面板 ---------- */
.army-sub { font-size: 14px; margin-bottom: 6px; color: #57431f; }
.army-row { display: flex; gap: 8px; flex-wrap: wrap; min-height: 64px; margin-bottom: 4px; }
.unit-chip {
  position: relative; width: 62px; height: 62px; border-radius: 10px; border: 2px solid #6b4e20;
  background: radial-gradient(#fdf3d8,#e2c988);
  display: flex; align-items: center; justify-content: center;
}
.unit-chip img { width: 46px; height: 46px; object-fit: contain; }
.unit-chip .u-cnt { position: absolute; right: -4px; top: -6px; background: #e04b1f; color: #fff; font-size: 12px; font-weight: bold; border-radius: 9px; padding: 1px 6px; border: 1px solid #7c2000; }
.unit-chip .u-lv { position: absolute; left: 2px; bottom: 2px; background: #6b4e20; color: #ffe08a; font-size: 10px; border-radius: 6px; padding: 0 5px; }
.army-h3 { margin: 10px 0 6px; color: #4a3416; font-size: 17px; }
.queue-row { display: flex; gap: 6px; margin-top: 8px; min-height: 54px; align-items: center; flex-wrap: wrap; }
.q-item { position: relative; width: 52px; height: 52px; border: 2px solid #6b4e20; border-radius: 8px; background: #efe0b8; }
.q-item img { width: 100%; height: 100%; object-fit: contain; }
.q-item .q-bar { position: absolute; left: 0; bottom: 0; height: 5px; background: #4ea424; width: 0%; }
.q-item .q-x { position:absolute; top:-8px; right:-8px; width:20px; height:20px; border-radius:50%; background:#e04b1f; color:#fff; border:1px solid #7c2000; font-size:12px; cursor:pointer; line-height:17px; text-align:center; font-weight:bold; }

/* ---------- 战斗 HUD ---------- */
#battle-hud { position: absolute; inset: 0; z-index: 22; pointer-events: none; }
#battle-hud > * { pointer-events: auto; }
#battle-top { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; gap: 10px; align-items: center; }
#battle-timer { font-size: 20px; font-weight: bold; padding: 4px 14px; color: #3d2b12; }
#battle-stars { font-size: 30px; color: #ffd763; text-shadow: 0 2px 3px rgba(0,0,0,.6); }
#battle-percent { font-size: 18px; font-weight: bold; padding: 4px 12px; color: #3d2b12; }
#battle-loot { margin-left: auto; padding: 4px 12px; display: flex; gap: 12px; color: #3d2b12; font-size: 15px; }
.loot-item { display: flex; align-items: center; gap: 4px; font-weight: bold; }
.loot-item img { width: 22px; height: 22px; }

#deploy-bar {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 8px;
  display: flex; gap: 8px; padding: 8px 12px; min-height: 74px; align-items: center;
}
.deploy-slot {
  position: relative; width: 64px; height: 64px; border-radius: 10px; cursor: pointer;
  border: 3px solid #6b4e20; background: radial-gradient(#fdf3d8,#e2c988);
  display: flex; align-items: center; justify-content: center; transition: transform .08s;
}
.deploy-slot img { width: 46px; height: 46px; object-fit: contain; pointer-events: none; }
.deploy-slot .d-cnt { position: absolute; right: -4px; top: -7px; background: #2f7cd6; color: #fff; font-size: 13px; font-weight: bold; border-radius: 10px; padding: 1px 7px; border: 1px solid #123f7a; }
.deploy-slot.active { border-color: #ffd763; transform: scale(1.1); box-shadow: 0 0 12px #ffd763aa; }
.deploy-slot.empty { filter: grayscale(1) brightness(.75); cursor: default; }
.deploy-slot.spell { background: radial-gradient(#f3d8fd,#cf88e2); }

#battle-actions { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
#scout-bar { position: absolute; left: 50%; transform: translateX(-50%); bottom: 12px; z-index: 22; display: flex; gap: 12px; }

/* ---------- 结算 ---------- */
.result-stars { font-size: 60px; letter-spacing: 14px; color: #cbb389; margin: 6px 0 10px; text-shadow: 0 3px 4px rgba(0,0,0,.3); }
.result-stars .earned { color: #ffcf3e; }
#result-loot { display: flex; justify-content: center; gap: 26px; font-size: 19px; font-weight: bold; color: #3d2b12; margin-bottom: 16px; }
#result-loot img { width: 26px; height: 26px; vertical-align: -6px; }
#result-title { font-size: 34px; color: #4a3416; }
#result-panel .big-btn { margin: 0 auto; }

/* ---------- 放置确认 ---------- */
#place-confirm { position: absolute; z-index: 30; display: flex; gap: 14px; }

/* ---------- Toast ---------- */
#toast-wrap { position: absolute; top: 90px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast {
  background: rgba(24,16,6,.85); color: #ffe9b3; padding: 9px 22px; border-radius: 20px; font-size: 15px; font-weight: bold;
  border: 2px solid #6b4e20; animation: toastIn .2s ease-out; text-shadow: 0 1px 2px #000;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; } }
.toast.out { transition: opacity .4s, transform .4s; opacity: 0; transform: translateY(-16px); }

/* 滚动条 */
.modal-box::-webkit-scrollbar { width: 10px; }
.modal-box::-webkit-scrollbar-thumb { background: #6b4e20; border-radius: 6px; }
.modal-box::-webkit-scrollbar-track { background: rgba(0,0,0,.15); }

@media (max-width: 700px) {
  .res-bar { width: 150px; height: 30px; }
  .res-bar.gems { width: 110px; }
  .big-btn { min-width: 70px; padding: 10px 12px; font-size: 15px; }
  .loading-box h1 { font-size: 34px; letter-spacing: 6px; }
  #hud-player { transform: scale(.85); transform-origin: top left; }
}
