* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #1e1a14; color: #f3e9d8;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  user-select: none; -webkit-user-select: none; overscroll-behavior: none;
}
#app { display: flex; flex-direction: row; height: 100%; }
#stage { position: relative; flex: 1 1 auto; min-width: 0; min-height: 0; background: #14110d; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#mini {
  position: absolute; left: 10px; bottom: 10px; width: 128px; height: 128px;
  border: 2px solid #f3e9d8aa; border-radius: 6px; image-rendering: pixelated;
  background: #0008; touch-action: none; cursor: pointer;
}
#hint {
  position: absolute; left: 10px; top: 10px; right: 10px; max-width: 420px; padding: 6px 10px;
  font-size: 12px; line-height: 1.3; background: #000a; border-radius: 8px; pointer-events: none;
  transition: opacity 1s;
}
#hint.hide { opacity: 0; }
#toast {
  position: absolute; left: 50%; top: 14%; transform: translateX(-50%); padding: 8px 14px;
  background: #000c; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .3s; text-align: center; max-width: 80%;
}
#toast.show { opacity: 1; }

#ui {
  flex: 0 0 340px; display: flex; flex-direction: column; gap: 10px; padding: 12px;
  background: linear-gradient(#3b2d1f, #2a2016); border-left: 3px solid #6b4d2e; overflow-y: auto;
}
.stats { background: #1e1610; border-radius: 12px; padding: 10px 14px; }
.big { font-size: 34px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.big .ico { font-size: 30px; }
.row { display: flex; justify-content: space-between; font-size: 15px; opacity: .9; margin-top: 2px; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
.boost {
  padding: 12px; border-radius: 12px; background: linear-gradient(#e0a02a, #b9731a);
  font-weight: 700; font-size: 15px; color: #2a1a05;
}
.boost:disabled { background: #5a4a2a; color: #d9c9a0; cursor: default; }
#upgrades { display: grid; grid-template-columns: 1fr; gap: 8px; }
.card {
  display: grid; grid-template-columns: 38px 1fr auto; grid-template-areas: "i n c" "i d c";
  column-gap: 10px; align-items: center; text-align: left; padding: 8px 10px;
  background: #4a3826; border-radius: 12px; border: 2px solid #6b4d2e;
}
.card:active:not(:disabled) { transform: scale(.98); }
.card .i { grid-area: i; font-size: 28px; text-align: center; }
.card .n { grid-area: n; font-weight: 700; font-size: 15px; }
.card .d { grid-area: d; font-size: 12px; opacity: .8; }
.card .c { grid-area: c; font-weight: 700; font-size: 15px; color: #ffd36b; white-space: nowrap; }
.card.no { opacity: .55; }
.card.no .c { color: #e49a8a; }
.card.max { border-color: #7aa65a; opacity: .8; }
.card.max .c { color: #9fd47a; }
.foot { display: flex; gap: 8px; margin-top: auto; }
.foot button { padding: 8px 12px; border-radius: 8px; background: #4a3826; font-size: 13px; }
.foot #reset { flex: 1; }

@media (orientation: portrait) {
  #app { flex-direction: column; }
  #ui { flex: 0 0 42%; border-left: 0; border-top: 3px solid #6b4d2e; padding: 8px 10px; gap: 8px; }
  #upgrades { grid-template-columns: 1fr 1fr; }
  .big { font-size: 26px; }
  .card { grid-template-columns: 30px 1fr; grid-template-areas: "i n" "i d" "c c"; padding: 6px 8px; }
  .card .i { font-size: 22px; }
  .card .n { font-size: 13px; }
  .card .d { font-size: 11px; }
  .card .c { font-size: 13px; }
  #mini { width: 92px; height: 92px; }
}
@media (max-height: 420px) and (orientation: landscape) {
  #ui { flex-basis: 300px; }
  #mini { width: 90px; height: 90px; }
}

.big small { font-size: 16px; font-weight: 400; opacity: .7; margin-left: -4px; align-self: flex-end; padding-bottom: 6px; }
.big small.warn { color: #ff9c8a; opacity: 1; }
.row.mat { font-size: 12px; opacity: .75; margin-top: 4px; justify-content: flex-start; gap: 6px; }
.tools { display: flex; gap: 6px; }
.tools button { flex: 1; padding: 10px 4px; border-radius: 10px; background: #4a3826; border: 2px solid #6b4d2e; font-weight: 700; font-size: 14px; }
.tools button.on { background: #7a5a2f; border-color: #ffd36b; }
.tools button.pulse { animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px #ffd36b88; } }
@media (orientation: portrait) { .tools button { padding: 8px 2px; font-size: 12px; } }

[hidden] { display: none !important; }
#merge { display: flex; flex-direction: column; gap: 6px; }
.merge { padding: 10px; border-radius: 10px; background: #3f6b3a; border: 2px solid #8fd37a; font-weight: 700; font-size: 14px; }
.row.mat { flex-wrap: wrap; }

.tools { flex-wrap: wrap; }
.tools button { flex: 1 1 30%; }

#buildings { display: flex; flex-direction: column; gap: 6px; }
.bcard { background: #3a2c1e; border: 2px solid #6b4d2e; border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.bcard .bt { font-size: 13px; font-weight: 700; }
.hire { padding: 8px; border-radius: 8px; background: #3f6b3a; border: 2px solid #8fd37a; font-weight: 700; font-size: 13px; }
.hire.no { opacity: .55; }

.pause { padding: 8px; border-radius: 8px; background: #4a3826; border: 2px solid #6b4d2e; font-weight: 700; font-size: 13px; }

#zones { display: flex; flex-direction: column; gap: 6px; }
.zcard { background: #3a2c1e; border: 2px solid #6b4d2e; border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.zcard.cur { border-color: #ffd36b; }
.zh { display: flex; justify-content: space-between; font-size: 13px; }
.zk { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { padding: 4px 8px; border-radius: 999px; background: #2a2016; border: 1px solid #6b4d2e; font-size: 12px; opacity: .55; }
.chip.on { background: #3f6b3a; border-color: #8fd37a; opacity: 1; }
.za { display: flex; gap: 6px; }
.za button, .zadd { padding: 8px; border-radius: 8px; background: #4a3826; border: 2px solid #6b4d2e; font-weight: 700; font-size: 13px; }
.za .zsel { flex: 1; }

.bup { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.bu { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 6px 8px; border-radius: 8px; background: #4a3826; border: 2px solid #6b4d2e; font-size: 11px; }
.bu .un { font-size: 12px; }
.bu .ue { opacity: .85; }
.bu .ul { opacity: .65; }
.bu .uc { color: #ffd36b; font-weight: 700; font-size: 13px; }
.bu.no { opacity: .55; }
.bu.no .uc { color: #e49a8a; }
.bu.max { border-color: #7aa65a; }
.bu.max .uc { color: #9fd47a; }

.bh { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.bclose { padding: 2px 8px; border-radius: 6px; background: #4a3826; border: 1px solid #6b4d2e; font-size: 13px; }
.bc { font-size: 13px; font-weight: 700; color: #ffd36b; }
.br { font-size: 11px; opacity: .7; }

#topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 6px; padding: 6px 8px; overflow-x: auto; background: #000b; font-size: 13px; z-index: 3; scrollbar-width: none; }
#topbar::-webkit-scrollbar { display: none; }
.rc { white-space: nowrap; padding: 3px 9px; border-radius: 999px; background: #ffffff1c; }
.rc b { margin-left: 2px; }
#hint { top: 44px; }
#zwin { position: absolute; left: 50%; top: 74px; transform: translateX(-50%); width: min(320px, 92%); background: #2a2016f2; border: 2px solid #ffd36b; border-radius: 12px; padding: 10px 12px; z-index: 4; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
#zwin[hidden] { display: none; }
.zwh { display: flex; justify-content: space-between; align-items: center; font-size: 16px; }
.zwx { padding: 2px 8px; border-radius: 6px; background: #4a3826; border: 1px solid #6b4d2e; }
.zwc { font-size: 12px; opacity: .8; }
.zwbar { height: 8px; border-radius: 4px; background: #000a; overflow: hidden; }
.zwbar i { display: block; height: 100%; background: #ffd36b; }
.zwl { display: flex; flex-direction: column; gap: 3px; }
.zwr { display: flex; justify-content: space-between; padding: 3px 8px; border-radius: 6px; background: #ffffff10; }
.zwe { opacity: .6; text-align: center; padding: 6px; }
.zwa { font-size: 12px; opacity: .8; }

.zic { font-style: normal; font-size: 22px; margin-right: 4px; vertical-align: middle; }
.zwr { align-items: center; }
.zwa { display: flex; flex-direction: column; gap: 6px; }
.zwk { display: flex; flex-wrap: wrap; gap: 6px; }
.zk2 { width: 42px; height: 42px; font-size: 24px; border-radius: 10px; background: #1b140d; border: 2px solid #6b4d2e; opacity: .45; }
.zk2.on { opacity: 1; background: #3f6b3a; border-color: #8fd37a; }

.zwb { display: flex; gap: 6px; }
.zwd { flex: 1; padding: 8px; border-radius: 8px; background: #4a3826; border: 2px solid #6b4d2e; font-weight: 700; font-size: 13px; }

#hires { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (orientation: portrait) { #hires { grid-template-columns: 1fr 1fr; } }

.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tools button { flex: none; aspect-ratio: 1 / 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 2px; font-size: 11px; line-height: 1.1; text-align: center; }
.tools .ti { font-size: 26px; line-height: 1; }
.tools .tn { font-weight: 700; font-size: 11px; }
.tools .tp { font-size: 11px; color: #ffd36b; min-height: 13px; }
.tools button.no .tp { color: #e49a8a; }
@media (orientation: portrait) { .tools .ti { font-size: 22px; } .tools .tn, .tools .tp { font-size: 10px; } }

#stage #buildings { position: absolute; left: 50%; top: 74px; transform: translateX(-50%); width: min(360px, 94%); max-height: calc(100% - 90px); overflow-y: auto; z-index: 4; background: #2a2016f2; border: 2px solid #ffd36b; border-radius: 12px; padding: 8px; }
#stage #buildings[hidden] { display: none; }
#stage #buildings .bcard { border: 0; padding: 0; background: transparent; }
#stage #buildings .hire { padding: 12px; font-size: 15px; }

.sellrow { display: flex; flex-direction: column; gap: 6px; }
.sh { font-size: 12px; opacity: .8; }
.sbs { display: flex; gap: 6px; flex-wrap: wrap; }
.sk { padding: 8px 12px; font-size: 20px; border-radius: 10px; background: #1b140d; border: 2px solid #6b4d2e; opacity: .45; }
.sk.on { opacity: 1; background: #3f6b3a; border-color: #8fd37a; }

#lvwin { position: absolute; left: 50%; top: 74px; transform: translateX(-50%); width: min(340px, 94%); max-height: calc(100% - 90px); overflow-y: auto; background: #2a2016f2; border: 2px solid #ffd36b; border-radius: 12px; padding: 10px 12px; z-index: 4; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
#lvwin[hidden] { display: none; }
.mrow { display: flex; flex-direction: column; gap: 1px; padding: 6px 10px; border-radius: 8px; background: #ffffff0d; opacity: .6; }
.mrow.on { opacity: 1; }
.mrow.cur { background: #3f6b3a; }
.rk { display: flex; flex-direction: column; padding: 6px 10px; border-radius: 8px; background: #ffd36b22; }
.rk b { font-size: 15px; color: #ffd36b; }
.rk small { font-size: 12px; opacity: .85; }
.mrow span { font-size: 12px; opacity: .85; }
.mrow small { font-size: 11px; opacity: .75; }
.lvc { cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.lvbar { display: inline-block; width: 44px; height: 6px; border-radius: 3px; background: #000a; overflow: hidden; }
.lvbar u { display: block; height: 100%; background: #ffd36b; text-decoration: none; }

.skrow { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px; background: #3f6b3a44; }
.skrow small { display: block; font-size: 11px; opacity: .8; }
.skbuy { padding: 8px 10px; border-radius: 8px; background: #3f6b3a; border: 2px solid #8fd37a; font-weight: 700; font-size: 12px; white-space: nowrap; }
.skbuy:disabled { opacity: .4; }

.sawrow { display: flex; flex-direction: column; gap: 6px; }
.sawm { padding: 8px 12px; font-size: 14px; border-radius: 10px; background: #1b140d; border: 2px solid #6b4d2e; opacity: .55; }
.sawm.on { opacity: 1; background: #3f6b3a; border-color: #8fd37a; }
.sawlim { display: flex; align-items: center; gap: 8px; }
.sawlim[hidden] { display: none; }
.sawr { flex: 1; min-width: 0; }
.sawn { min-width: 2.2em; text-align: right; }
.sawgo { padding: 8px 10px; border-radius: 8px; background: #3f6b3a; border: 2px solid #8fd37a; font-weight: 700; font-size: 12px; white-space: nowrap; }
.sawst { font-size: 12px; opacity: .85; }

/* Панель построек внизу игрового поля: квадратные кнопки в ряд, как в стратегиях */
#stage .tools { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); display: flex; flex-wrap: nowrap; gap: 6px; padding: 6px; max-width: calc(100% - 16px); overflow-x: auto; background: #000b; border: 2px solid #6b4d2e; border-radius: 14px; z-index: 3; scrollbar-width: none; }
#stage .tools::-webkit-scrollbar { display: none; }
#stage .tools button { flex: 0 0 auto; width: 68px; height: 68px; aspect-ratio: auto; padding: 2px; border-radius: 10px; gap: 0; }
#stage .tools .ti { font-size: 24px; }
#stage .tools .tn { font-size: 9px; font-weight: 700; }
#stage .tools .tp { font-size: 9px; min-height: 11px; }
#mini { bottom: 92px; }
@media (orientation: portrait) { #stage .tools button { width: 60px; height: 60px; } #mini { bottom: 82px; } }
