* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #0d1621;
  color: #e8edf4;
  font-family: -apple-system, 'Segoe UI', Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#map { position: fixed; inset: 0; display: block; }

#topbar {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; gap: 8px;
  padding: calc(max(env(safe-area-inset-top), var(--tg-safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px) + 4px) 10px 8px;
  pointer-events: none; z-index: 5;
}

.badge {
  background: rgba(10, 16, 24, .82);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 13px; font-weight: 600;
  backdrop-filter: blur(6px);
  max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

#hud {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 0 10px calc(env(safe-area-inset-bottom) + var(--tg-safe-area-inset-bottom, 0px) + 10px);
  z-index: 5;
}

#cellInfo {
  text-align: center; font-size: 12px; color: #9fb0c3;
  min-height: 18px; margin-bottom: 6px;
  text-shadow: 0 1px 3px #000;
}

#bottombar { display: flex; gap: 8px; justify-content: center; }

#unitbar, #buildbar {
  display: flex; gap: 5px; justify-content: flex-start;
  margin-bottom: 6px; overflow-x: auto; padding: 2px;
  scrollbar-width: none;
}
#unitbar::-webkit-scrollbar, #buildbar::-webkit-scrollbar { display: none; }
#buildbar .unit { min-width: 44px; padding: 5px 7px; }
#buildbar .unit svg { width: 17px; height: 17px; }

/* commander */
.cmdcard {
  display: flex; gap: 10px; align-items: flex-start;
  background: #0d141d; border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
  cursor: pointer; font-size: 12.5px; line-height: 1.4;
}
.cmdcard.cur { border-color: #2f80ed; background: #14243a; }
.cmdcard .em { font-size: 26px; line-height: 1; }
.cmdcard b { font-size: 14px; }
.cmdcard .pro { color: #7ce3a1; }
.cmdcard .con { color: #ff9a8a; }
.cmdcard .ab { color: #8fc3ff; }
#cmdCurrent { margin-bottom: 10px; font-size: 13px; }
#cmdCurrent .xpbar { height: 6px; background: #0d141d; border-radius: 3px; margin: 6px 0; overflow: hidden; }
#cmdCurrent .xpbar > div { height: 100%; background: #2f80ed; }
.cmdava { width: 46px; height: 46px; border-radius: 10px; object-fit: cover; }
.logoimg { width: 130px; height: 130px; display: block; margin: 0 auto 12px; border-radius: 24px; }

/* unlock guide */
#guideIcon { text-align: center; margin: 8px 0; }
#guideIcon svg { width: 52px; height: 52px; }
#guideIcon span { font-size: 44px; }
#guideName { text-align: center; margin-bottom: 8px; }
#guideText { font-size: 14px; color: #cdd9e5; line-height: 1.5; }
.unit {
  background: rgba(10, 16, 24, .85);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  padding: 6px 8px;
  color: #e8edf4;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  min-width: 48px; flex: 0 0 auto;
  backdrop-filter: blur(6px);
}
.unit svg { width: 20px; height: 20px; }
.unit .sub { font-size: 9px; margin-top: 2px; white-space: nowrap; }
.unit.sel { border-color: #2f80ed; background: rgba(35, 62, 99, .9); }
.unit.locked { opacity: .45; }
.unit.nuke { color: #ffd23e; }
.unit:active { transform: scale(.95); }

/* chat */
.chatsheet { display: flex; flex-direction: column; height: 70vh; }
#chatList {
  flex: 1; overflow-y: auto; margin: 6px 0;
  display: flex; flex-direction: column; gap: 6px;
}
.msg { font-size: 13px; line-height: 1.35; }
.msg .who { font-weight: 700; }
.msg .t { color: #cdd9e5; }
.msg .when { color: #64758a; font-size: 10px; margin-left: 5px; }
.msg .joinbtn {
  display: inline-block; background: #2f80ed; color: #fff;
  border: none; border-radius: 7px; padding: 3px 10px;
  font-size: 12px; font-weight: 700; cursor: pointer; margin-left: 6px;
}
.chatrow { display: flex; gap: 6px; }
.chatrow input { flex: 1; margin-bottom: 0; }
.chatbtn {
  background: #24405e; color: #fff; border: none; border-radius: 10px;
  width: 46px; font-size: 16px; cursor: pointer;
}

/* shop */
.shopitem {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  background: #0d141d; border-radius: 12px; padding: 12px; margin-bottom: 10px;
  font-size: 14px;
}
.shopbuy { width: auto !important; padding: 10px 14px !important; margin: 0 !important; white-space: nowrap; }
.packrow { display: flex; gap: 8px; margin-bottom: 10px; }
.pack {
  flex: 1; background: #12251a; border: 1px solid #2c5a3f; border-radius: 12px;
  padding: 10px 6px; text-align: center; cursor: pointer; color: #9fe8b8;
  font-size: 13px; font-weight: 700;
}
.pack .stars { display: block; color: #ffd23e; font-size: 12px; margin-top: 3px; }
#cashBalance { color: #7ce3a1; }

/* tutorial */
#tutBody { min-height: 120px; }
#tutBody h2 { margin-bottom: 8px; }
#tutBody p { font-size: 15px; color: #cdd9e5; }
#tutDots { text-align: center; margin: 10px 0 2px; color: #40506a; letter-spacing: 4px; }
#tutDots .on { color: #2f80ed; }

/* news */
#newsList { list-style: none; padding: 0; }
#newsList li { padding: 7px 0; font-size: 13px; border-bottom: 1px solid rgba(255,255,255,.06); }
#newsList .when { color: #64758a; font-size: 11px; }

/* language picker */
#langList { display: flex; flex-direction: column; gap: 8px; }
.langbtn {
  padding: 13px; border-radius: 10px; border: 1px solid rgba(255,255,255,.14);
  background: #1b2634; color: #fff; font-size: 16px; font-weight: 700; cursor: pointer;
}
.langbtn.sel { background: #24405e; border-color: #2f80ed; }

/* flag editor */
#flagCanvas {
  display: block; width: 240px; height: 160px; margin: 0 auto 10px;
  border: 1px solid rgba(255,255,255,.2); border-radius: 6px;
  image-rendering: pixelated; cursor: crosshair; touch-action: none;
}
#flagPalette { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 10px; }
#flagPalette .swatch { width: 26px; height: 26px; }
.flagrow { display: flex; gap: 8px; }
.flagrow > * { flex: 1; }
.filebtn { display: block; text-align: center; padding: 13px; border-radius: 10px; font-size: 15px; font-weight: 700; cursor: pointer; background: #1e3a2f; color: #7ce3a1; margin-top: 4px; }

.flagimg { image-rendering: pixelated; border-radius: 2px; vertical-align: -2px; margin-right: 5px; border: 1px solid rgba(255,255,255,.25); }

/* rtl support */
[dir="rtl"] .msg .when { margin-left: 0; margin-right: 5px; }
[dir="rtl"] .dot { margin-right: 0; margin-left: 6px; }
[dir="rtl"] .flagimg { margin-right: 0; margin-left: 5px; }
[dir="rtl"] ol { padding-left: 0; padding-right: 22px; }

.pill {
  background: rgba(10, 16, 24, .85);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px; font-weight: 700; color: #e8edf4;
  backdrop-filter: blur(6px);
}

.btn { cursor: pointer; }
.btn:active { transform: scale(.96); }

#toast {
  position: fixed; left: 50%; top: 18%;
  transform: translateX(-50%);
  background: rgba(16, 24, 34, .95);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
  z-index: 20; max-width: 86vw; text-align: center;
}
#toast.show { opacity: 1; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 10;
}
.modal.hidden { display: none; }

.sheet {
  background: #131c28;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(env(safe-area-inset-bottom) + 18px);
  width: 100%; max-width: 480px;
  max-height: 78vh; overflow-y: auto;
}

.sheet h2 { font-size: 18px; margin-bottom: 10px; }
.sheet p { font-size: 14px; color: #9fb0c3; margin-bottom: 12px; }

.tabs { display: flex; gap: 6px; margin: 12px 0; }
.tab {
  flex: 1; padding: 8px; border-radius: 8px;
  background: #1b2634; color: #9fb0c3;
  border: 1px solid transparent; font-weight: 700; font-size: 13px; cursor: pointer;
}
.tab.active { background: #24405e; color: #fff; border-color: rgba(255,255,255,.15); }

.tabpane.hidden { display: none; }

input {
  width: 100%; padding: 12px;
  border-radius: 10px; border: 1px solid rgba(255,255,255,.15);
  background: #0d141d; color: #fff; font-size: 15px;
  margin-bottom: 10px; outline: none;
}

button.primary, button.secondary, button.close {
  width: 100%; padding: 13px;
  border-radius: 10px; border: none;
  font-size: 15px; font-weight: 700; cursor: pointer;
  margin-top: 4px;
}
button.primary { background: #2f80ed; color: #fff; }
button.secondary { background: #1e3a2f; color: #7ce3a1; }
button.close { background: transparent; color: #9fb0c3; }
button:active { opacity: .85; }
.hidden { display: none !important; }

#colorPick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.swatch {
  width: 34px; height: 34px; border-radius: 8px;
  border: 2px solid transparent; cursor: pointer;
}
.swatch.sel { border-color: #fff; }

#myClanInfo { font-size: 14px; line-height: 1.5; color: #cdd9e5; }
#myClanInfo .code { font-family: ui-monospace, monospace; background: #0d141d; padding: 1px 7px; border-radius: 6px; letter-spacing: 1px; }

ol { padding-left: 22px; }
#myClanMembers, #ciMembers { list-style: none; padding-left: 0; padding-right: 0; }
ol li { padding: 7px 0; font-size: 14px; border-bottom: 1px solid rgba(255,255,255,.06); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.sub { color: #8296ab; font-size: 12px; }

.sysmsg { text-align: center; color: #8296ab; font-style: italic; font-size: 12px; }
.clanrow { cursor: pointer; }
.clanrow:active { opacity: .7; }
#ciDiplo { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }

#joinList { list-style: none; padding: 0; max-height: 34vh; overflow-y: auto; margin-bottom: 8px; }
#joinList li { display: block; padding: 8px 0; font-size: 13px; border-bottom: 1px solid rgba(255,255,255,.06); position: relative; }
#joinList .joinbtn { position: absolute; right: 0; top: 8px; background: #2f80ed; color: #fff; border: none; border-radius: 7px; padding: 5px 12px; font-size: 12px; font-weight: 700; cursor: pointer; }
[dir="rtl"] #joinList .joinbtn { right: auto; left: 0; }

.contlist { list-style: none; padding: 0; max-height: 46vh; overflow-y: auto; }
.contlist li { padding: 5px 0; font-size: 13.5px; border-bottom: 1px solid rgba(255,255,255,.06); }

#unitGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.unitcard {
  display: flex; gap: 8px; align-items: center;
  background: #0d141d; border-radius: 10px; padding: 8px; font-size: 12px;
}
.unitcard svg { width: 22px; height: 22px; flex: 0 0 auto; }
.unitcard .upbtn {
  margin-left: auto; background: #2f80ed; color: #fff; border: none;
  border-radius: 7px; padding: 4px 8px; font-size: 11px; font-weight: 700; cursor: pointer;
}
.unitcard .upbtn:disabled { background: #24303f; color: #5c6b7d; }
.invitecard {
  display: flex; gap: 8px; align-items: center;
  background: #14243a; border: 1px solid #2f80ed44; border-radius: 10px;
  padding: 8px 10px; margin-bottom: 6px; font-size: 13px;
}
.invitecard .acc { background: #2f80ed; color: #fff; border: none; border-radius: 7px; padding: 5px 10px; font-weight: 700; cursor: pointer; margin-left: auto; }
.invitecard .dec { background: transparent; color: #8296ab; border: none; font-size: 15px; cursor: pointer; padding: 4px; }
.tgtag { color: #5eb5f7; font-size: 11px; }

/* ---- mobile optimization ---- */
@media (max-width: 460px) {
  .pill { padding: 8px 9px; font-size: 11.5px; border-radius: 10px; }
  #bottombar { gap: 5px; }
  #energy { flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: center; }
  .unit { min-width: 40px; padding: 4px 6px; border-radius: 10px; }
  .unit svg { width: 16px; height: 16px; }
  .unit .sub { font-size: 7.5px; }
  #buildbar .unit { min-width: 38px; padding: 3px 5px; }
  #buildbar .unit svg { width: 14px; height: 14px; }
  #unitbar, #buildbar { margin-bottom: 4px; }
  .badge { font-size: 11.5px; padding: 5px 9px; max-width: 48vw; }
  #cellInfo { font-size: 11px; min-height: 15px; margin-bottom: 4px; }
  .sheet { padding: 16px 14px calc(env(safe-area-inset-bottom) + 14px); max-height: 84vh; }
  #unitGrid { grid-template-columns: 1fr; }
  .cmdcard { padding: 8px 10px; font-size: 12px; }
  #flagCanvas { width: 216px; height: 144px; }
}
@media (max-height: 700px) {
  #unitbar, #buildbar { margin-bottom: 3px; }
  #hud { padding-bottom: calc(env(safe-area-inset-bottom) + 6px); }
}

/* left chat tab (Clash-style) + unread badge */
#chatTab {
  position: fixed; left: 0; top: 40%;
  background: rgba(10, 16, 24, .9);
  border: 1px solid rgba(255,255,255,.16); border-left: none;
  border-radius: 0 14px 14px 0;
  padding: 12px 10px 12px 8px; font-size: 20px;
  color: #e8edf4; cursor: pointer; z-index: 6;
  backdrop-filter: blur(6px);
}
#chatTab:active { transform: scale(.95); }
#chatBadge {
  position: absolute; top: -6px; right: -6px;
  background: #e63946; color: #fff;
  border-radius: 10px; min-width: 18px; height: 18px;
  font-size: 11px; font-weight: 800; line-height: 18px;
  text-align: center; padding: 0 4px;
}
.langbtn-logo { padding: 3px 6px !important; }
.langbtn-logo img { width: 24px; height: 24px; border-radius: 7px; display: block; }
[dir="rtl"] #chatTab { left: auto; right: 0; border-radius: 14px 0 0 14px; border-right: none; border-left: 1px solid rgba(255,255,255,.16); }

button.danger { width: 100%; padding: 13px; border-radius: 10px; border: none; font-size: 15px; font-weight: 700; cursor: pointer; margin-top: 4px; background: #7a1f1f; color: #ffb3b3; }
button.success { width: 100%; padding: 13px; border-radius: 10px; border: none; font-size: 15px; font-weight: 700; cursor: pointer; margin-top: 4px; background: #1e5a34; color: #9fe8b8; }
.clandesc { background: #0d141d; border-radius: 10px; padding: 9px 11px; font-size: 13px; color: #cdd9e5; margin: 8px 0; font-style: italic; }
#myClanMembers { max-height: 24vh; overflow-y: auto; margin-bottom: 6px; }

#pcUnits { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
#pcUnits .uchip { display: flex; align-items: center; gap: 4px; background: #0d141d; border-radius: 8px; padding: 4px 8px; font-size: 11px; }
#pcUnits .uchip svg { width: 14px; height: 14px; }

.diplorow { display: flex; align-items: center; gap: 6px; background: #0d141d; border-radius: 9px; padding: 7px 9px; margin-bottom: 5px; font-size: 13px; cursor: pointer; }
.diplorow .locbtn { margin-left: auto; background: #24405e; border: none; border-radius: 7px; color: #fff; padding: 4px 9px; font-size: 13px; cursor: pointer; }

/* v26 HUD: profile card + resource bars + shop FAB */
.hudcard {
  background: rgba(10, 16, 24, .85);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  padding: 7px 10px;
  backdrop-filter: blur(6px);
  font-size: 12.5px; font-weight: 700;
  min-width: 128px; max-width: 46vw;
}
#profName { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xpmini { height: 5px; background: #0d141d; border-radius: 3px; margin: 4px 0; overflow: hidden; }
.xpmini > div { height: 100%; background: linear-gradient(90deg, #2f80ed, #6fb1ff); width: 0%; transition: width .4s; }
.subrow { font-size: 10.5px; color: #9fb0c3; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.resrow { display: flex; align-items: center; gap: 5px; margin-bottom: 3px; }
.resbar { flex: 1; height: 7px; background: #0d141d; border-radius: 4px; overflow: hidden; min-width: 40px; }
.resbar > div { height: 100%; background: linear-gradient(90deg, #e8b93e, #ffd23e); width: 0%; transition: width .4s; }
#enNum { font-size: 10.5px; white-space: nowrap; }
.oilnum { color: #9fe8b8; }
#shopFab {
  position: fixed; right: 12px; bottom: calc(env(safe-area-inset-bottom) + var(--tg-safe-area-inset-bottom, 0px) + 118px);
  width: 54px; height: 54px; border-radius: 18px;
  background: linear-gradient(160deg, #1e5a34, #123a22);
  border: 1.5px solid #3dbd6e66; color: #fff; font-size: 26px;
  cursor: pointer; z-index: 6;
  box-shadow: 0 4px 14px rgba(0,0,0,.45);
}
#shopFab:active { transform: scale(.93); }
@media (max-width: 460px) {
  .hudcard { min-width: 118px; padding: 6px 8px; font-size: 11.5px; }
  #shopFab { width: 48px; height: 48px; font-size: 22px; }
}

.oilico { width: 15px; height: 15px; vertical-align: -2px; display: inline-block; }
.shopbuy .oilico, #cashBalance .oilico { width: 16px; height: 16px; }

.ccardhead { display: flex; align-items: center; gap: 6px; font-size: 16px; margin-bottom: 6px; }
.statgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
.statchip { background: #0d141d; border-radius: 10px; padding: 7px 4px; text-align: center; }
.statchip b { display: block; font-size: 14px; }
.statchip span { font-size: 9.5px; color: #8296ab; }

#shopFab img { width: 100%; height: 100%; object-fit: cover; border-radius: 16px; display: block; }
#shopFab { padding: 0; overflow: hidden; }

.topcol { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; max-width: 48vw; }
.seasonbadge { font-size: 10.5px; padding: 4px 9px; pointer-events: none; }

.sysjoin { color: #7ce3a1; }
.sysleave { color: #ff8a8a; }

.goldbar > div { background: linear-gradient(90deg, #c9a227, #ffd75e) !important; }
#goldNum { font-size: 10.5px; white-space: nowrap; color: #ffd75e; }

#upPointsLine { white-space: pre-line; }

.askrow { display: flex; gap: 10px; margin-top: 12px; }
.askrow button { flex: 1; }
#askInput { width: 100%; margin-top: 10px; padding: 10px; border-radius: 10px; border: 1px solid #2b3b52; background: #101a28; color: #e8eef7; font-size: 16px; }

.goldico { width: 17px; height: 17px; vertical-align: -3px; display: inline-block; flex: 0 0 auto; }

.genhead { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.genface { width: 52px; height: 52px; border-radius: 50%; border: 2px solid #ffd75e; object-fit: cover; flex: 0 0 auto; box-shadow: 0 0 12px rgba(255,215,94,.35); }
.genname { font-weight: 700; color: #ffd75e; font-size: 15px; }
#guideIcon .genface { width: 44px; height: 44px; }

.goldico-sm { width: 13px; height: 13px; vertical-align: -2px; }
#toast svg.goldico-sm { vertical-align: -2px; }

#missionBar { position: fixed; left: 10px; right: 10px; top: calc(env(safe-area-inset-top, 0px) + 118px); z-index: 40;
  display: flex; align-items: center; gap: 8px; background: rgba(13,22,33,.92); border: 1px solid #ffd75e66;
  border-radius: 12px; padding: 8px 10px; font-size: 13px; color: #ffe9b0; box-shadow: 0 2px 12px rgba(0,0,0,.4); }
#missionBar .genface-sm { width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid #ffd75e; flex: 0 0 auto; }
#missionBar.hidden { display: none; }
@keyframes missionPulse { 0%,100% { transform: scale(1); opacity: .95; } 50% { transform: scale(1.25); opacity: .5; } }
