* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #14110b; color: #f3ead2;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}
#game { position: fixed; inset: 0; display: block; touch-action: none; }
#game3d { position: fixed; inset: 0; display: block; pointer-events: none; }
body:not(.view3d) #game3d { display: none; }
body:not(.view3d) .only3d { display: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- yuqori panel ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  padding: calc(6px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 6px calc(10px + env(safe-area-inset-left));
  background: linear-gradient(rgba(12, 10, 6, .85), rgba(12, 10, 6, 0));
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.res {
  font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums;
  background: rgba(0, 0, 0, .45); padding: 4px 12px; border-radius: 8px;
  border: 1px solid rgba(62, 230, 193, .45); min-width: 90px;
}
.coin { color: #3ee6c1; margin-right: 6px; }
.clock { font-variant-numeric: tabular-nums; opacity: .75; font-size: 14px; }
.topbtns { margin-left: auto; display: flex; gap: 6px; }
.topbtns button, #modeBanner button {
  background: rgba(30, 28, 22, .85); border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 8px; padding: 6px 10px; font-size: 14px; min-height: 34px; min-width: 36px;
}
.topbtns button.on { background: #2f6f3a; border-color: #7cff8a; }

#minimap {
  position: fixed; z-index: 2;
  top: calc(50px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right));
  width: 168px; height: 126px;
  border: 2px solid rgba(0, 0, 0, .65); border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .5); touch-action: none;
}
/* maxsus qurollar (taymerli) */
#specials {
  position: fixed; z-index: 2; right: calc(10px + env(safe-area-inset-right));
  top: calc(184px + env(safe-area-inset-top));
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.spec {
  position: relative; width: 64px; height: 64px; border-radius: 50%; padding: 0;
  border: 2px solid rgba(255, 255, 255, .2); background: #1d1a13; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .5);
}
.spec .ring { position: absolute; inset: 0; border-radius: 50%; }
.spec::after { content: ''; position: absolute; inset: 5px; border-radius: 50%; background: #1d1a13; }
.spec .ico, .spec .t { position: relative; z-index: 1; }
.spec .ico { font-size: 22px; line-height: 1; }
.spec .t { font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; }
.spec.ready { border-color: #ff5a3c; animation: pulse 1s infinite; }
.spec.scan.ready { border-color: #7cc8ff; }
.spec.active { box-shadow: 0 0 0 3px #ffd36b; }
@keyframes pulse { 50% { transform: scale(1.07); } }

#modeBanner {
  position: fixed; z-index: 3; top: calc(52px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  background: rgba(20, 18, 12, .92); border: 1px solid #ffd36b; border-radius: 10px;
  padding: 5px 6px 5px 14px; display: flex; gap: 10px; align-items: center; font-size: 14px;
  max-width: calc(100vw - 220px);
}
#toasts {
  position: fixed; z-index: 3; top: calc(52px + env(safe-area-inset-top)); left: calc(12px + env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 6px; pointer-events: none; max-width: 46vw;
}
.toast {
  background: rgba(15, 13, 9, .9); border-left: 4px solid #ffd36b;
  padding: 6px 12px; border-radius: 6px; font-size: 14px;
  transition: opacity .5s, transform .5s;
}
.toast.out { opacity: 0; transform: translateX(-20px); }

/* ---------- pastki panel ---------- */
#panel {
  position: fixed; z-index: 2; left: 0; right: 0; bottom: 0;
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px;
  padding: 18px calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
  background: linear-gradient(rgba(12, 10, 6, 0), rgba(12, 10, 6, .9) 40%);
  pointer-events: none;
}
#panel > * { pointer-events: auto; }
#selInfo {
  min-width: 140px; max-width: 240px; min-height: 62px; font-size: 13px;
  background: rgba(0, 0, 0, .4); border-radius: 10px; padding: 6px 10px;
  display: flex; flex-direction: column; justify-content: center;
}
#selInfo .sub { opacity: .7; font-size: 11px; margin-top: 3px; }
#actions { display: flex; gap: 6px; flex: 1 1 auto; overflow-x: auto; min-width: 0; }
#build { display: flex; gap: 6px; padding-left: 8px; border-left: 1px solid rgba(255, 255, 255, .12); }

.btn {
  position: relative; width: 66px; height: 62px; flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: linear-gradient(#3a3527, #26221a);
  border: 1px solid rgba(255, 255, 255, .14); border-radius: 10px;
  overflow: hidden; padding: 2px;
}
.btn:active { transform: scale(.94); }
.btn .ico { font-size: 20px; line-height: 1.1; }
.btn .nm { font-size: 11px; white-space: nowrap; }
.btn .cost { font-size: 11px; color: #3ee6c1; font-weight: 700; }
.btn.disabled { opacity: .45; }
.btn.locked .cost::after { content: ' 🔒'; }
.btn.active { border-color: #ffd36b; box-shadow: inset 0 0 0 2px #ffd36b; }
.btn.danger .nm { color: #ffb0a0; }
.btn .q {
  position: absolute; top: 3px; right: 4px; display: none;
  background: #ffd36b; color: #222; font-size: 11px; font-weight: 800;
  border-radius: 9px; min-width: 18px; padding: 0 4px;
}
.btn .prog { position: absolute; left: 0; bottom: 0; height: 4px; width: 0; background: #7cc8ff; }

.hpbar { height: 5px; background: rgba(0, 0, 0, .6); border-radius: 3px; margin-top: 5px; overflow: hidden; }
.hpbar i { display: block; height: 100%; width: 100%; background: #5be36a; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { background: rgba(255, 255, 255, .09); border-radius: 6px; padding: 1px 6px; }
.hint { opacity: .7; }
.enemy { color: #ff7c7c; }

/* ---------- menyular ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(10, 8, 4, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.card {
  background: linear-gradient(#2c271c, #1b1811);
  border: 1px solid rgba(255, 211, 107, .35); border-radius: 16px;
  padding: 22px 26px; width: 100%; max-width: 460px; text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .6);
  max-height: calc(100vh - 32px); overflow-y: auto; touch-action: pan-y;
}
.card h1 { margin: 0; font-size: 42px; letter-spacing: 4px; color: #ffd36b; text-shadow: 0 3px 0 #7a4b12; }
.card h1.win { color: #7cff8a; text-shadow: 0 3px 0 #1f5a2a; }
.card h1.lose { color: #ff7c7c; text-shadow: 0 3px 0 #5a1f1f; }
.card h2 { margin: 0 0 6px; color: #ffd36b; }
.card p { line-height: 1.45; opacity: .9; }
.tag { color: #e0b46a; font-weight: 600; margin-top: 4px; }
.card button {
  display: block; width: 100%; margin-top: 10px; padding: 11px;
  border-radius: 10px; background: #3a3527; border: 1px solid rgba(255, 255, 255, .15); font-size: 16px;
}
.card button.big { background: linear-gradient(#e8ae42, #b9761c); color: #1b1408; font-weight: 800; font-size: 18px; border: none; }
.diff { display: flex; gap: 8px; }
.diff button.sel { background: #2f6f3a; border-color: #7cff8a; }
details { text-align: left; margin-top: 14px; font-size: 13px; }
summary { cursor: pointer; color: #ffd36b; font-weight: 600; }
details h4 { margin: 10px 0 4px; }
details ul { margin: 0; padding-left: 18px; line-height: 1.5; opacity: .9; }
#endStats { margin: 14px 0 6px; text-align: left; }
#endStats div { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid rgba(255, 255, 255, .08); }
#endStats span { opacity: .75; }

.teambadge {
  font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 8px;
  background: rgba(0, 0, 0, .45); border: 2px solid #fff;
}
.mp { margin-top: 4px; padding: 4px 12px 12px; background: rgba(0, 0, 0, .25); border-radius: 12px; }
.joinrow { display: flex; gap: 8px; margin-top: 10px; }
.joinrow input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; font-size: 18px; letter-spacing: 4px; text-align: center;
  background: #14110b; color: #f3ead2; border: 1px solid rgba(255, 255, 255, .25);
  user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
.joinrow button { margin-top: 0 !important; width: auto !important; padding: 10px 16px !important; }
#mpStatus { margin-top: 10px; font-size: 14px; line-height: 1.5; min-height: 1em; }
#mpStatus .code { font-size: 30px; letter-spacing: 6px; color: #ffd36b; }
.opts { text-align: left; margin-top: 12px; font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.opts label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.opts input { width: 18px; height: 18px; accent-color: #e8ae42; }

/* ---------- lobbi ---------- */
.card.wide { max-width: 860px; text-align: left; }
.card.wide h2 { text-align: center; }
.namein {
  display: block; width: 100%; margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-size: 16px; text-align: center;
  background: #14110b; color: #f3ead2; border: 1px solid rgba(255, 255, 255, .25);
  user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
#lobbyCode { text-align: center; margin-bottom: 8px; }
#lobbyCode .code { font-size: 30px; letter-spacing: 6px; color: #ffd36b; margin: 0 8px; }
#lobbyCode span { display: block; font-size: 13px; opacity: .75; }
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.lobby-grid h4 { margin: 4px 0 8px; }
#mapList { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.card .mapbtn { margin: 0; padding: 7px 8px; text-align: left; font-size: 14px; display: flex; flex-direction: column; }
.mapbtn span { font-size: 11px; opacity: .7; }
.mapbtn.sel { background: #2f6f3a; border-color: #7cff8a; }
.mapbtn:disabled { opacity: .4; }
#mapPreview { display: block; margin: 10px auto 6px; border-radius: 6px; border: 2px solid rgba(0, 0, 0, .5); }
.sub { font-size: 12px; opacity: .7; line-height: 1.4; }
.presets { display: flex; gap: 6px; margin-bottom: 8px; }
.card .presets button { margin: 0; padding: 6px; font-size: 12px; }
.slot { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; padding: 4px 6px; border-radius: 10px; background: rgba(0, 0, 0, .25); }
.slot.off { opacity: .55; }
.slot.mine { box-shadow: inset 0 0 0 2px #7cff8a; }
.slot .dot, .score .dot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; display: inline-block; vertical-align: middle; margin-right: 6px; border: 2px solid rgba(0,0,0,.4); }
.slot .num { width: 14px; font-weight: 800; opacity: .7; }
.card .slot button { margin: 0; padding: 7px 8px; font-size: 13px; }
.card .slot .who { flex: 1; text-align: left; }
.card .slot .team { width: auto; flex: 0 0 auto; min-width: 82px; }
.card .slot button:disabled { opacity: 1; cursor: default; }
.lobbyhint { text-align: center; margin-top: 10px; color: #ffb86b; min-height: 1.2em; font-size: 14px; }
.ally { color: #7cc8ff; }
table.score { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
.score th { text-align: left; opacity: .7; font-weight: 600; padding: 4px; }
.score td { padding: 5px 4px; border-top: 1px solid rgba(255, 255, 255, .08); }
.score tr.mine td { color: #7cff8a; }
@media (max-width: 720px) {
  .lobby-grid { grid-template-columns: 1fr; }
}

#rotate { display: none; }
@media (orientation: portrait) and (max-width: 600px) {
  #rotate {
    display: block; position: fixed; z-index: 4; left: 50%; transform: translateX(-50%);
    top: calc(184px + env(safe-area-inset-top)); white-space: nowrap;
    background: rgba(0, 0, 0, .7); padding: 6px 12px; border-radius: 8px; font-size: 13px; pointer-events: none;
  }
  #minimap { width: 120px; height: 90px; }
  .topbtns .lbl { display: none; }
}

/* kichik balandlikdagi ekranlar (telefon yotqizilgan) */
@media (max-height: 480px) {
  .btn { width: 56px; height: 50px; border-radius: 8px; }
  .btn .ico { font-size: 17px; }
  .btn .nm, .btn .cost { font-size: 10px; }
  #minimap { width: 132px; height: 99px; top: calc(44px + env(safe-area-inset-top)); }
  #specials { top: calc(150px + env(safe-area-inset-top)); flex-direction: row; }
  .spec { width: 52px; height: 52px; }
  .spec .ico { font-size: 18px; }
  .spec .t { font-size: 10px; }
  .topbtns button { padding: 3px 8px; min-height: 30px; font-size: 13px; }
  #selInfo { max-width: 170px; min-width: 110px; min-height: 50px; font-size: 12px; }
  #selInfo .sub { display: none; }
  .res { font-size: 16px; }
  #panel { padding-top: 12px; }
  .card { padding: 16px 20px; }
  .card h1 { font-size: 32px; }
}
@media (max-width: 720px) {
  .topbtns .lbl { display: none; }
}

/* gameuzb.uz portaliga qaytish havolasi (bosh menyu kartochkasida) */
.portal-link { display: inline-block; margin: 0 0 6px; padding: 6px 12px; border-radius: 999px; background: rgba(255,255,255,.08); color: inherit; text-decoration: none; font-size: 13px; font-weight: 700; }
.portal-link:hover { background: rgba(255,255,255,.16); }

/* modellar mualliflari (CC-BY 3.0 talabi — o'yinchiga ko'rinadigan joyda) */
.credits { margin: 10px 0 0; font-size: 11px; line-height: 1.4; opacity: .6; text-align: center; }
.credits a { color: inherit; }
