/* Terran RTS — тёмный металлический интерфейс в духе классических RTS.
   Только локальные стили, без внешних шрифтов и библиотек. */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0b0e12;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: #dfe6ef;
  user-select: none;
  -webkit-user-select: none;
}

#game-root { position: fixed; inset: 0; }

#game-canvas {
  position: absolute; inset: 0;
  display: block;
  background: #000;
}

/* ---------- Верхняя панель ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  height: 40px;
  display: flex; align-items: center; gap: 14px;
  padding: 0 12px;
  background: linear-gradient(#232a33, #171c23);
  border-bottom: 1px solid #3a4450;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
  z-index: 10;
}
.res { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 14px; }
.dot { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.dot.mineral { background: #3fd3e8; box-shadow: 0 0 6px #3fd3e8; }
.dot.supply { background: #9aa7b5; }
#res-supply.blocked { color: #ff6b5b; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.spacer { flex: 1; }
.tb-btn {
  background: linear-gradient(#39424e, #262d36);
  color: #cfe0f5;
  border: 1px solid #4a5663;
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}
.tb-btn:hover { background: linear-gradient(#46515f, #303945); }

/* ---------- Нижняя панель ---------- */
#bottom-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 190px;
  display: flex; gap: 10px;
  padding: 8px 10px;
  background: linear-gradient(#232a33, #141920);
  border-top: 1px solid #3a4450;
  box-shadow: 0 -2px 8px rgba(0,0,0,.5);
  z-index: 10;
}
#minimap-box {
  flex: 0 0 176px;
  border: 2px solid #4a5663;
  border-radius: 4px;
  overflow: hidden;
  background: #000;
  height: 176px;
}
#minimap { display: block; width: 176px; height: 176px; cursor: pointer; }

#sel-info {
  flex: 1;
  border: 1px solid #343e4a;
  border-radius: 4px;
  padding: 10px 12px;
  overflow-y: auto; /* страховка: даже длинное описание не обрежется */
  background: rgba(10, 14, 19, .45);
}
.hint { color: #8b98a7; font-size: 13px; line-height: 1.55; }
.sel-name { font-weight: 700; font-size: 15px; margin-bottom: 6px; color: #eaf2fb; }
.small { color: #93a1b1; font-size: 12px; margin-top: 5px; line-height: 1.45; }

.bar {
  width: 200px; height: 9px;
  background: #10151b;
  border: 1px solid #39434f;
  border-radius: 3px;
  overflow: hidden;
  margin: 3px 0;
}
.bar-fill { height: 100%; background: #4be36a; width: 100%; }
.bar-fill.amber { background: #e8c04a; }

.queue { display: flex; gap: 5px; margin-top: 7px; align-items: center; flex-wrap: wrap; }
.queue-empty { color: #6f7d8c; font-size: 12px; font-style: italic; }
.chip {
  width: 38px; height: 38px;
  background: #1b2129;
  border: 1px solid #46525f;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  padding: 3px;
}
.chip:hover { border-color: #7d8fa3; }
.chip canvas { width: 100%; height: 100%; }
.chip-progress {
  position: absolute; left: 0; bottom: 0;
  height: 3px; background: #4be36a; width: 0;
}
.chip-time {
  position: absolute; top: -1px; right: 1px;
  font-size: 9px; color: #cfd9e4; font-weight: 700;
  text-shadow: 0 1px 2px #000;
}
.res-line { margin-top: 7px; font-size: 12.5px; color: #ffe4a1; }
.res-line b { color: #ffd977; }

/* ---------- Тултип кнопок панели ---------- */
#cmd-tip {
  position: fixed;
  width: 300px;
  background: linear-gradient(#212932, #151b22);
  border: 1px solid #4a5663;
  border-left: 3px solid #ffd977;
  border-radius: 6px;
  padding: 9px 12px;
  box-shadow: 0 8px 26px rgba(0,0,0,.6);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .12s ease-out, transform .12s ease-out;
  z-index: 40;
}
#cmd-tip.show { opacity: 1; transform: none; }
.tip-title { font-weight: 800; font-size: 13.5px; color: #eaf2fb; display: flex; justify-content: space-between; gap: 10px; }
.tip-cost { color: #3fd3e8; font-weight: 700; }
.tip-desc { font-size: 12px; color: #b9c5d2; line-height: 1.5; margin-top: 4px; }
.tip-row { font-size: 11.5px; color: #8b98a7; margin-top: 3px; line-height: 1.4; }

/* ---------- Команды ---------- */
#cmd-grid {
  flex: 0 0 230px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 82px;
  gap: 6px;
  align-content: start;
  overflow-y: auto; /* страховка: ничего не пропадает за краем панели */
}
/* Меню стройки (9 кнопок: 8 зданий + «Назад»): 2 колонки × 5 рядов
   горизонтальных кнопок по 32px — ровно вписывается в 174px панели. */
#cmd-grid.compact {
  flex: 0 0 320px;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: 32px;
  gap: 3px;
}
#cmd-grid.compact .cmd {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding: 2px 7px;
}
#cmd-grid.compact .cmd canvas { width: 18px; height: 18px; flex: 0 0 18px; }
#cmd-grid.compact .cmd-label {
  flex: 1;
  font-size: 10.5px;
  line-height: 1.08;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#cmd-grid.compact .cmd-cost { font-size: 10px; margin-left: auto; }
/* В компактных кнопках хоткей — обычный элемент в строке, иначе он
   абсолютом налезает на цену. */
#cmd-grid.compact .cmd kbd { position: static; transform: none; margin-left: 6px; }
.cmd {
  position: relative;
  background: linear-gradient(#333d49, #222932);
  border: 1px solid #4a5663;
  border-radius: 5px;
  color: #dfe8f2;
  cursor: pointer;
  padding: 6px 4px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.cmd:hover { background: linear-gradient(#414d5b, #2b333e); border-color: #6f8195; }
.cmd.disabled { opacity: .45; }
.cmd canvas { width: 26px; height: 26px; }
.cmd-label { font-size: 10.5px; line-height: 1.15; text-align: center; }
.cmd-cost { font-size: 10.5px; color: #3fd3e8; font-weight: 700; }
.cmd kbd {
  position: absolute; top: 2px; right: 4px;
  font-size: 9px; color: #93a1b1;
  border: 1px solid #4a5663; border-radius: 3px;
  padding: 0 3px;
}

/* ---------- Тосты ---------- */
#toasts {
  position: absolute;
  bottom: 200px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  z-index: 20;
  pointer-events: none;
}
.toast {
  background: rgba(20, 26, 33, .92);
  border: 1px solid #4a5663;
  border-left: 3px solid #4f8fe8;
  border-radius: 4px;
  padding: 7px 14px;
  font-size: 13px;
  animation: toast-in .18s ease-out;
}
.toast.err { border-left-color: #e04b3f; color: #ffb3ab; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Оверлеи ---------- */
.overlay {
  position: absolute; inset: 0;
  background: rgba(5, 8, 12, .78);
  display: flex; align-items: center; justify-content: center;
  z-index: 30;
}
.overlay.thin { background: rgba(5, 8, 12, .45); }
/* Оверлей паузы перекрывает поле, но оставляет верхнюю панель кликабельной. */
#pause-overlay.overlay { z-index: 5; }
.overlay.hidden { display: none; }
.overlay-box {
  text-align: center;
  background: linear-gradient(#1d242d, #12171d);
  border: 1px solid #3f4a57;
  border-radius: 10px;
  padding: 34px 44px;
  box-shadow: 0 10px 50px rgba(0,0,0,.7);
  max-width: 560px;
}
.overlay-box h1 {
  font-size: 34px;
  letter-spacing: 4px;
  color: #eaf2fb;
  text-shadow: 0 0 24px rgba(79, 143, 232, .55);
}
.overlay-box h1.win { color: #7dff9b; text-shadow: 0 0 24px rgba(80, 255, 140, .5); }
.overlay-box h1.lose { color: #ff7a6b; text-shadow: 0 0 24px rgba(255, 90, 70, .5); }
.sub { color: #93a1b1; margin: 8px 0 16px; font-size: 14px; }
.help { text-align: left; margin: 0 auto 20px; display: inline-block; }
.help p { font-size: 13px; color: #b9c5d2; line-height: 1.75; }
.help b { color: #eaf2fb; }
.help .goal { color: #ffd977; }
.big-btn {
  background: linear-gradient(#3f74c4, #2a5290);
  color: #fff;
  border: 1px solid #6f9fe0;
  border-radius: 6px;
  font-size: 17px;
  font-weight: 700;
  padding: 12px 38px;
  cursor: pointer;
  letter-spacing: 1px;
}
.big-btn:hover { background: linear-gradient(#4a83d6, #3260a4); }

#end-stats { margin: 6px 0 22px; }
#end-stats .row {
  display: flex; justify-content: space-between; gap: 40px;
  font-size: 14px; color: #b9c5d2;
  padding: 5px 2px;
  border-bottom: 1px dashed #333d49;
}
#end-stats .row b { color: #eaf2fb; }

.pause-text {
  font-size: 44px; letter-spacing: 12px; color: #eaf2fb;
  text-shadow: 0 0 30px rgba(79,143,232,.8);
}

/* ---------- Строка цели миссии ---------- */
.res.objective {
  color: #ffd977;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .3px;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Главное меню ---------- */
.menu-box { max-width: 640px; }
.menu-buttons { display: flex; gap: 12px; justify-content: center; margin: 4px 0 16px; }
.ghost-btn {
  background: linear-gradient(#2b333d, #20262e);
  border-color: #556373;
  color: #d5e2f0;
}
.ghost-btn:hover { background: linear-gradient(#353f4a, #28303a); }
.small-start { font-size: 13px; padding: 8px 22px; margin-top: 4px; }
.fac-teaser { display: flex; gap: 10px; justify-content: center; margin-bottom: 14px; flex-wrap: wrap; }
.fac-chip {
  font-size: 12px; font-weight: 700; letter-spacing: .5px;
  padding: 4px 12px; border-radius: 12px; border: 1px solid;
}
.fac-human { color: #9cc4f5; border-color: #4f8fe8; background: rgba(79,143,232,.12); }
.fac-alien { color: #a8f0bd; border-color: #67c98a; background: rgba(103,201,138,.12); }

/* ---------- Список миссий ---------- */
.overlay-box.wide { max-width: 720px; max-height: 88vh; overflow-y: auto; }
#mission-list { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 18px; }
.act-head {
  text-align: center;
  font-size: 13px; font-weight: 800; letter-spacing: 3px;
  text-transform: uppercase; color: #ffd977;
  margin: 14px 0 2px;
  border-bottom: 1px dashed #3a4450;
  padding-bottom: 6px;
}
.act-head:first-child { margin-top: 0; }
.mc-intro { font-size: 11.5px; color: #a8f0bd; margin-top: 4px; }
.mission-card {
  text-align: left;
  background: linear-gradient(#262e38, #1a2028);
  border: 1px solid #44505e;
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
  color: #dfe8f2;
}
.mission-card:hover { border-color: #7d92aa; background: linear-gradient(#2d3642, #1f2630); }
.mission-card.locked { opacity: .5; cursor: not-allowed; filter: grayscale(.6); }
.mc-top { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.mc-num { font-size: 11px; color: #8b98a7; letter-spacing: 1px; text-transform: uppercase; }
.mc-lock { margin-left: auto; font-size: 11px; color: #ffb3ab; }
.mc-name { font-size: 17px; font-weight: 700; color: #eaf2fb; }
.mc-place { font-size: 12px; color: #8b98a7; margin-top: 3px; font-style: italic; }
.mc-obj { font-size: 12.5px; color: #ffd977; margin-top: 6px; }
.mc-def { font-size: 11.5px; color: #a8f0bd; margin-top: 3px; }

.badge {
  display: inline-block;
  font-size: 11px; font-weight: 800; letter-spacing: 1.5px;
  padding: 3px 10px; border-radius: 10px; border: 1px solid;
}

/* ---------- Брифинг ---------- */
.brief-box { max-width: 660px; text-align: left; }
.brief-head { display: flex; align-items: center; gap: 14px; }
.brief-head h1 { font-size: 26px; letter-spacing: 2px; }
#brief-place { font-style: italic; }
#brief-text { max-height: 40vh; overflow-y: auto; margin: 4px 0 12px; }
#brief-text p { font-size: 13.5px; color: #c3cfdc; line-height: 1.65; margin-bottom: 10px; }
#brief-text p.brief-intro {
  color: #a8f0bd;
  border-left: 3px solid #67c98a;
  padding-left: 10px;
  font-weight: 600;
}
.objective-line {
  border-left: 3px solid #ffd977;
  background: rgba(255, 217, 119, .08);
  padding: 9px 12px;
  font-size: 13.5px; font-weight: 700; color: #ffe4a1;
  margin-bottom: 16px;
}

/* ---------- Выбор фракции ---------- */
.fac-cards { display: flex; gap: 14px; justify-content: center; margin: 10px 0 18px; flex-wrap: wrap; }
.fac-card {
  flex: 1 1 240px; max-width: 280px;
  text-align: center;
  background: linear-gradient(#262e38, #1a2028);
  border: 2px solid #44505e;
  border-radius: 10px;
  padding: 18px 14px;
  cursor: pointer;
  color: #dfe8f2;
}
.fac-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.5); }
.fac-card.fac-human { border-color: #4f8fe8; }
.fac-card.fac-human:hover { border-color: #7dabf2; }
.fac-card.fac-alien { border-color: #67c98a; }
.fac-card.fac-alien:hover { border-color: #93e2ab; }
.fc-title { font-size: 22px; font-weight: 800; letter-spacing: 3px; }
.fac-card.fac-human .fc-title { color: #9cc4f5; text-shadow: 0 0 16px rgba(79,143,232,.6); }
.fac-card.fac-alien .fc-title { color: #a8f0bd; text-shadow: 0 0 16px rgba(103,201,138,.6); }
.fc-sub { font-size: 12.5px; color: #93a1b1; margin: 5px 0 10px; }
.fc-list { font-size: 12px; color: #b9c5d2; line-height: 1.6; }

.end-reason { color: #ffd977; font-size: 14px; margin: 2px 0 8px; min-height: 18px; }
