/* Town-building panels: Outfitter (shop), Barracks (hire units), Drill Yard (unit upgrades),
   Sanctum (powers). Shared frame (.town-panel) + one block per panel. */
.town-panel {
  position: absolute; left: 50%; bottom: 200px; transform: translateX(-50%);
  width: min(1040px, calc(100% - 16px)); max-height: calc(100% - 270px);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 8px;
  padding: 12px 14px 10px; border-radius: 12px; pointer-events: auto; z-index: 16;
  background: linear-gradient(180deg, rgba(26,24,20,.97), rgba(14,14,16,.97));
  border: 1px solid var(--gold-dim); box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.05);
  animation: alertIn .18s ease-out;
}
.town-panel[hidden] { display: none; }
.tp-shop { border-color: #4f86b0; } .tp-drillyard { border-color: #b0704f; } .tp-sanctum { border-color: #8a6ad0; }
.tw-head { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px; }
.tw-badge { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px; background: rgba(242,196,90,.14); color: var(--gold); border: 1px solid var(--gold-dim); }
.tw-badge .ic { width: 22px; height: 22px; }
.tp-shop .tw-badge { color: #8fd0ff; background: rgba(127,208,255,.12); border-color: #4f86b0; }
.tp-drillyard .tw-badge { color: #ffb08a; background: rgba(255,154,106,.12); border-color: #b0704f; }
.tp-sanctum .tw-badge { color: #d6b8ff; background: rgba(198,156,255,.12); border-color: #8a6ad0; }
.tw-title b { display: block; font: 800 24px/1 var(--head); color: var(--ink); letter-spacing: .03em; }
.tw-title span { color: var(--ink2); font-size: 13.5px; }
.tw-purse { display: flex; gap: 12px; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tw-purse > span { display: inline-flex; align-items: center; gap: 5px; }
.tw-gold { color: var(--gold); } .tw-inc { color: #9fe0a8; font-size: 15px; }
.tw-close { background: none; border: 0; color: var(--ink2); font-size: 26px; line-height: 1; cursor: pointer; }
.tw-body { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 12px; min-height: 0; }
.tw-foot { color: var(--ink3); font-size: 12.5px; text-align: center; }
.tw-foot b { color: var(--ink2); }

/* detail pane (Barracks + Outfitter) */
.tw-detail { display: grid; align-content: start; gap: 8px; padding: 10px 12px; border-radius: 10px; background: rgba(0,0,0,.28); border: 1px solid rgba(255,255,255,.08); overflow-y: auto; min-height: 0; }
.sd-top { display: grid; grid-template-columns: 64px 1fr; gap: 10px; align-items: center; }
.sd-ic { width: 64px; height: 64px; border-radius: 9px; overflow: hidden; display: grid; place-items: center; background: radial-gradient(circle at 50% 35%, #4a5260, #1c1f25); border: 1px solid var(--line-strong); }
.sd-ic img { width: 100%; height: 100%; object-fit: cover; }
.sd-ic b { font: 800 22px var(--head); }
.sd-name { font: 800 20px/1.1 var(--head); }
.sd-tier { display: flex; align-items: center; gap: 4px; color: var(--ink2); font-size: 13px; flex-wrap: wrap; }
.sd-tier .ic { width: 13px; height: 13px; color: var(--gold); }
.sd-tier .uq, .uq { color: var(--gold); font-weight: 700; }
.sd-line { margin: 0; font-size: 14px; color: var(--ink); line-height: 1.35; }
.sd-line b { color: #9fe0a8; }
.sd-stats { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; }
.sd-stats dt { color: var(--ink3); } .sd-stats dd { margin: 0; }
.sd-counters, .sd-lines { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink2); }
.sd-lines li { color: #a6f0b4; }
.sd-vs { display: flex; gap: 6px; flex-wrap: wrap; }
.pip { padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 1px solid; }
.pip.good { color: #a6f0b4; border-color: rgba(95,207,122,.5); } .pip.bad { color: #ffb0a2; border-color: rgba(224,80,62,.5); } .pip.even { color: var(--ink2); border-color: rgba(255,255,255,.2); }
.sd-traits { margin: 0; font-size: 12.5px; color: var(--ink2); font-style: italic; }
.sd-note { margin: 0; font-size: 12.5px; color: var(--ink2); }
.sd-why { margin: 0; font-size: 13px; color: #ffb0a2; font-weight: 600; }
.sd-actions { display: grid; grid-template-columns: 1fr; gap: 6px; }
.sd-send, .sd-sell { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px; border-radius: 7px; cursor: pointer; font-weight: 800; font-size: 15px; }
.sd-send { background: linear-gradient(180deg, #d9a842, #a87a24); color: #1a1206; border: 1px solid #f2c45a; }
.sd-sell { background: rgba(255,255,255,.05); color: var(--ink); border: 1px solid rgba(255,255,255,.2); }
.sd-send:disabled, .sd-sell:disabled { opacity: .45; cursor: default; filter: saturate(.3); }
.sd-send .ic, .sd-sell .ic { width: 15px; height: 15px; }

/* shared card feedback */
.bought { animation: bought .22s ease-out; }
@keyframes bought { 0% { box-shadow: 0 0 0 0 rgba(242,196,90,.9); } 100% { box-shadow: 0 0 0 10px rgba(242,196,90,0); } }
.refused { animation: refused .25s; }
@keyframes refused { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.coin-pop { position: absolute; left: 0; top: 0; transform: translate(-50%, 0); font: 800 13px var(--ui); color: var(--gold); text-shadow: 0 1px 2px #000; white-space: nowrap; animation: coinPop .65s ease-out forwards; }
@keyframes coinPop { from { opacity: 1; transform: translate(-50%, 0) scale(1.1); } to { opacity: 0; transform: translate(-50%, -26px) scale(.9); } }

/* ---------- Barracks ---------- */
.bk-tiers { display: grid; align-content: start; gap: 8px; overflow-y: auto; min-height: 0; padding: 2px 4px 2px 2px; }
.bk-tier { display: grid; grid-template-columns: 74px 1fr; gap: 8px; align-items: start; }
.bk-th { padding-top: 8px; font: 700 14px var(--head); color: var(--ink2); letter-spacing: .04em; }
.bk-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 6px; }
.bk-card {
  position: relative; display: grid; grid-template-columns: 46px 1fr auto; grid-template-rows: auto auto; column-gap: 8px; align-items: center;
  padding: 5px 8px 5px 5px; min-height: 58px; border-radius: 8px; cursor: pointer; text-align: left; user-select: none; touch-action: none;
  background: linear-gradient(180deg, #2b2e35, #1c1e23); border: 1px solid rgba(255,255,255,.12);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05), 0 2px 5px rgba(0,0,0,.35); transition: border-color .1s, filter .1s, transform .06s;
}
.bk-card:hover { filter: brightness(1.12); }
.bk-card:active { transform: scale(.97); }
.bk-card.can { border-color: rgba(242,196,90,.5); }
.bk-card.poor { filter: saturate(.4) brightness(.72); }
.bk-ic, .ot-ic { grid-row: span 2; width: 46px; height: 46px; border-radius: 7px; overflow: hidden; display: grid; place-items: center; background: radial-gradient(circle at 50% 35%, #4a5260, #1c1f25); border: 1px solid rgba(255,255,255,.12); }
.bk-ic img, .ot-ic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bk-ic b, .ot-ic b { font: 800 17px var(--head); }
.bk-card.t2 .bk-ic { background: radial-gradient(circle at 50% 35%, #3e5a70, #18242e); }
.bk-card.t3 .bk-ic { background: radial-gradient(circle at 50% 35%, #5a4a7a, #221a30); }
.bk-card.t4 .bk-ic { background: radial-gradient(circle at 50% 35%, #7a4a3a, #2e1a14); }
.bk-card.t6 .bk-ic { background: radial-gradient(circle at 50% 35%, #8a6a2a, #2e220e); border-color: var(--gold-dim); }
.bk-nm { grid-column: 2 / 4; font-weight: 700; font-size: 14.5px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 30px; }
.bk-nm small { color: var(--ink3); font-weight: 600; }
.bk-cost, .ot-price { display: inline-flex; align-items: center; gap: 3px; color: var(--gold); font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.bk-cost .ic, .ot-price .ic { width: 14px; height: 14px; }
.bk-plus { color: #9fe0a8; font-weight: 700; font-size: 13px; justify-self: end; padding-right: 18px; }
.bk-plus::after { content: ' inc'; color: var(--ink3); font-weight: 600; font-size: 11px; }
.bk-afford { position: absolute; right: 6px; top: 4px; font: 800 13px var(--ui); color: var(--ink); font-variant-numeric: tabular-nums; }
.bk-card.can .bk-afford { color: #ffe39a; }
.bk-key { position: absolute; right: 4px; bottom: 4px; font-size: 10px; line-height: 13px; padding: 0 3px; min-width: 0; }
.bk-pop { position: absolute; right: 30px; top: -4px; pointer-events: none; z-index: 3; }

/* ---------- Outfitter ---------- */
.ot-main { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 8px; min-height: 0; }
.ot-away { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 7px; color: #ffd38a; font-weight: 700; background: rgba(240,164,58,.1); border: 1px solid rgba(240,164,58,.4); }
.ot-away[hidden] { display: none; }
.ot-away .ic { width: 18px; height: 18px; }
.ot-walk { margin-left: auto; padding: 4px 12px; border-radius: 6px; cursor: pointer; font-weight: 800; background: linear-gradient(180deg, #d9a842, #a87a24); color: #1a1206; border: 1px solid #f2c45a; }
.ot-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.ot-tab { padding: 5px 12px; border-radius: 6px 6px 0 0; cursor: pointer; font-weight: 700; background: rgba(255,255,255,.03); border: 1px solid rgba(255,255,255,.1); border-bottom-color: transparent; color: var(--ink2); }
.ot-tab.on { background: rgba(127,208,255,.12); color: #cfeaff; border-color: #4f86b0; }
.ot-grid { --cols: 4; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 6px; align-content: start; overflow-y: auto; min-height: 0; padding: 2px; }
.ot-item { position: relative; display: grid; grid-template-columns: 46px 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center; padding: 5px 8px 5px 5px; border-radius: 8px; cursor: pointer; text-align: left;
  background: linear-gradient(180deg, #2b2e35, #1c1e23); border: 1px solid rgba(255,255,255,.12); }
.ot-item:hover { filter: brightness(1.12); }
.ot-item.t2 .ot-ic { background: radial-gradient(circle at 50% 35%, #3e5a70, #18242e); }
.ot-item.t3 .ot-ic { background: radial-gradient(circle at 50% 35%, #5a4a7a, #221a30); }
.ot-item.t4 .ot-ic { background: radial-gradient(circle at 50% 35%, #8a6a2a, #2e220e); }
.ot-item.unique { border-color: var(--gold-dim); }
.ot-item.can { border-color: rgba(127,208,255,.45); }
.tp-shop.away .ot-item, .ot-item.poor { filter: saturate(.45) brightness(.78); }
.ot-item.blocked { opacity: .5; }
.ot-nm { font-weight: 700; font-size: 13.5px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 18px; }
.ot-own { position: absolute; right: 6px; bottom: 4px; font: 800 12px var(--ui); color: #8fd0ff; }
.ot-uq { position: absolute; right: 5px; top: 3px; color: var(--gold); font-size: 13px; }
.ot-use { position: absolute; right: 6px; bottom: 4px; font-size: 10px; color: var(--ink3); text-transform: uppercase; letter-spacing: .06em; }
.ot-invrow { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 10px; padding-top: 6px; border-top: 1px solid rgba(255,255,255,.08); }
.ot-invh { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink3); }
.ot-inv-grid { display: grid; grid-template-columns: repeat(6, 44px); gap: 4px; }
.ot-inv { position: relative; width: 44px; height: 44px; padding: 0; border-radius: 6px; cursor: pointer; background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.15); overflow: hidden; }
.ot-inv .ot-ic { width: 100%; height: 100%; border: 0; border-radius: 0; }
.ot-inv kbd { position: absolute; left: 1px; top: 1px; font-size: 9px; line-height: 11px; padding: 0 2px; min-width: 0; }
.ot-inv .ot-ch { position: absolute; right: 2px; bottom: 1px; font: 800 11px var(--ui); color: #fff; text-shadow: 0 1px 2px #000; font-style: normal; }
.ot-inv.empty { border-style: dashed; }
.ot-inv.sel { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.ot-totals { font-size: 12px; color: #a6f0b4; line-height: 1.35; }

/* ---------- Drill Yard ---------- */
.tp-drillyard .tw-body { grid-template-columns: minmax(0, 1fr) 230px; }
.dy-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; align-content: start; overflow-y: auto; min-height: 0; padding: 2px; }
.dy-row { display: grid; grid-template-columns: 42px 1fr auto; grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding: 6px 10px 6px 6px; border-radius: 8px; cursor: pointer; text-align: left;
  background: linear-gradient(180deg, #2f2a26, #1d1a18); border: 1px solid rgba(255,255,255,.12); }
.dy-row:hover { filter: brightness(1.12); }
.dy-row.can { border-color: rgba(255,154,106,.55); }
.dy-row.poor { filter: saturate(.5) brightness(.8); }
.dy-row.maxed { opacity: .7; cursor: default; }
.dy-ic { grid-row: span 2; width: 42px; height: 42px; border-radius: 7px; overflow: hidden; display: grid; place-items: center; background: radial-gradient(circle at 50% 35%, #6a4a3a, #22160f); color: #ffb08a; }
.dy-ic img { width: 100%; height: 100%; object-fit: cover; }
.dy-txt { display: grid; line-height: 1.15; min-width: 0; }
.dy-txt b { font-size: 14.5px; } .dy-txt small { color: var(--ink2); font-size: 12px; }
.dy-pips { display: flex; gap: 2px; grid-column: 2; }
.dy-pips i { width: 9px; height: 5px; border-radius: 2px; background: rgba(255,255,255,.12); }
.dy-pips i.on { background: #ff9a6a; }
.dy-cost { grid-row: span 2; grid-column: 3; font: 800 15px var(--ui); color: var(--gold); font-variant-numeric: tabular-nums; }
.dy-row.maxed .dy-cost { color: #a6f0b4; }
.dy-side { display: grid; align-content: start; gap: 8px; padding: 10px 12px; border-radius: 10px; background: rgba(0,0,0,.28); border: 1px solid rgba(255,255,255,.08); }
.dy-spent { font-weight: 700; color: var(--gold); }
.dy-note { margin: 0; font-size: 13px; color: var(--ink2); }

/* ---------- Sanctum ---------- */
.tp-sanctum .tw-body { grid-template-columns: 1fr; }
.sc-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; overflow-y: auto; min-height: 0; }
.sc-col h4 { margin: 0 0 6px; font: 700 15px var(--head); display: grid; }
.sc-col h4 small { font: 500 12px var(--ui); color: var(--ink3); }
.sc-col.k-defensive h4 { color: #8fd0ff; } .sc-col.k-offensive h4 { color: #ff9a7a; } .sc-col.k-neutral h4 { color: #d6b8ff; }
.sc-pow { position: relative; width: 100%; display: grid; grid-template-columns: 40px 1fr auto; column-gap: 8px; align-items: center; padding: 6px 8px 6px 6px; margin-bottom: 6px; border-radius: 8px; cursor: pointer; text-align: left;
  background: linear-gradient(180deg, #2b2836, #1b1922); border: 1px solid rgba(255,255,255,.12); }
.sc-pow:hover { filter: brightness(1.12); }
.sc-pow.can { border-color: rgba(198,156,255,.5); }
.sc-pow.poor, .sc-pow.cooling { filter: saturate(.45) brightness(.75); }
.sc-ic { width: 40px; height: 40px; border-radius: 7px; overflow: hidden; display: grid; place-items: center; background: radial-gradient(circle at 50% 35%, #5a4a7a, #1d1528); color: #d6b8ff; }
.sc-ic img { width: 100%; height: 100%; object-fit: cover; }
.sc-txt { display: grid; line-height: 1.15; min-width: 0; } .sc-txt b { font-size: 14px; } .sc-txt small { color: var(--ink2); font-size: 11.5px; }
.sc-cost { display: inline-flex; align-items: center; gap: 3px; color: var(--gold); font-weight: 800; }
.sc-cost .ic { width: 13px; height: 13px; }
.sc-cd { position: absolute; right: 8px; bottom: 3px; font-size: 11px; color: #ffcf9a; font-weight: 700; }

/* power targeting hint (HUD) */
.aim-hint { position: absolute; top: 120px; left: 50%; transform: translateX(-50%); padding: 6px 16px; border-radius: 8px; font-weight: 700; pointer-events: none;
  background: rgba(20,14,30,.9); border: 1px solid #8a6ad0; color: #e6d6ff; box-shadow: var(--shadow); white-space: nowrap; }
.aim-hint[hidden] { display: none; }
.aim-hint .bad { color: #ffb0a2; }
body.aiming #view { cursor: crosshair; }

/* tooltips for game objects */
.tt { display: grid; gap: 3px; max-width: 300px; }
.tt-h { font-size: 14px; } .tt-sub { color: #a99a83; font-size: 11.5px; }
.tt-good { color: #8fd08a; } .tt-dim { color: #b8ad98; } .tt-gold { color: #f0c46a; }
.tt-key { color: #a99a83; font-size: 11.5px; margin-top: 2px; }

@container (max-width: 1000px) {
  .town-panel { bottom: 168px; max-height: calc(100% - 230px); padding: 8px 9px; }
  .tw-body { grid-template-columns: minmax(0, 1fr) 210px; gap: 8px; }
  .tw-title span { display: none; }
  .bk-tier { grid-template-columns: 1fr; gap: 3px; }
  .bk-th { padding-top: 0; }
  .bk-row { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .ot-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dy-list { grid-template-columns: 1fr; }
  .sc-cols { grid-template-columns: 1fr; }
  .sd-stats { font-size: 12px; }
  .sd-ic { width: 48px; height: 48px; } .sd-top { grid-template-columns: 48px 1fr; }
}
@container (max-width: 700px) {
  .tw-body { grid-template-columns: 1fr; }
  .tw-detail, .dy-side { display: none; }
}
