:root {
  --ink: #e9eef5;
  --dim: #8fa1b6;
  --panel: rgba(11, 19, 32, 0.86);
  --panel-hi: rgba(26, 40, 62, 0.92);
  --edge: rgba(150, 190, 235, 0.22);
  --gold: #f6c453;
  --gold-dark: #9a6a12;
  --nato: #3aa0ff;
  --red: #ff4b3a;
  --green: #5fd17a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0b1320;
  color: var(--ink);
  font-family: 'Barlow Condensed', system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
  cursor: grab;
}
#view.placing { cursor: crosshair; }
#view:active { cursor: grabbing; }

.hidden { display: none !important; }
.dim { color: var(--dim); }
.k { color: var(--dim); font-weight: 700; letter-spacing: 0.08em; font-size: 0.8em; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
  touch-action: manipulation;
}

/* --- panels and buttons -------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  background: radial-gradient(ellipse at 50% 40%, rgba(5, 10, 18, 0.25), rgba(5, 10, 18, 0.78));
  overflow-y: auto;
}

.panel, .card {
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid var(--edge);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.panel {
  padding: 26px 30px;
  min-width: 280px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}
.panel.wide { width: 520px; }
.panel h2 {
  font-family: 'Black Ops One', sans-serif;
  font-weight: 400;
  font-size: 44px;
  margin: 0 0 6px;
  letter-spacing: 0.02em;
}
.panel button, .opts .v {
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--edge);
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 17px;
}
.panel button:hover, .opts .v:hover { background: rgba(255, 255, 255, 0.13); }

button.primary {
  background: linear-gradient(180deg, #ffd875, #e9a92a) !important;
  color: #2a1a00 !important;
  border: 1px solid #ffe7a6 !important;
  box-shadow: 0 4px 0 var(--gold-dark), 0 8px 22px rgba(246, 196, 83, 0.25);
  font-family: 'Black Ops One', sans-serif;
  font-weight: 400 !important;
  letter-spacing: 0.08em;
  font-size: 22px !important;
  padding: 12px 22px !important;
  border-radius: 12px;
  transition: transform 0.08s;
}
button.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-dark); }

.kicker { color: var(--gold); font-weight: 800; letter-spacing: 0.22em; font-size: 13px; }
.fine { color: var(--dim); font-size: 14px; margin: 4px 0 0; }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 6px; }
.row button { flex: 1; }

/* --- loading ------------------------------------------------------------------- */

#loading { background: #0b1320; }
.loader { text-align: center; }
.loader p { letter-spacing: 0.3em; color: var(--dim); font-weight: 700; }
.radar {
  width: 90px; height: 90px; margin: 0 auto 16px;
  border-radius: 50%;
  border: 2px solid rgba(58, 160, 255, 0.5);
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle, rgba(58, 160, 255, 0.15) 0 30%, transparent 31% 60%, rgba(58, 160, 255, 0.12) 61% 62%, transparent 63%);
}
.radar span {
  position: absolute; inset: 0;
  background: conic-gradient(from 0deg, rgba(58, 160, 255, 0.6), transparent 25%);
  animation: sweep 1.6s linear infinite;
}
@keyframes sweep { to { transform: rotate(360deg); } }

/* --- title ---------------------------------------------------------------------- */

#menu { background: radial-gradient(ellipse at 30% 40%, rgba(5, 10, 18, 0.1), rgba(5, 10, 18, 0.72)); }
.menuGrid {
  display: grid;
  grid-template-columns: minmax(300px, 520px) minmax(280px, 380px);
  gap: 28px;
  align-items: center;
  width: min(980px, 100%);
}
.titleBlock {
  padding: 26px 30px;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(11, 19, 32, 0.88), rgba(11, 19, 32, 0.6));
  border: 1px solid var(--edge);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.titleBlock h1 {
  white-space: nowrap;
  font-family: 'Black Ops One', sans-serif;
  font-weight: 400;
  font-size: clamp(44px, 8vw, 82px);
  line-height: 0.92;
  margin: 8px 0 10px;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 0 40px rgba(58, 160, 255, 0.25);
}
.titleBlock h1 .five {
  color: var(--gold);
  display: inline-block;
  transform: rotate(-4deg);
}
.tag { font-size: 20px; line-height: 1.3; color: #c9d6e6; max-width: 460px; margin: 0 0 18px; }
.opts { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; max-width: 460px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.opt .k { font-size: 15px; }
.seg { display: flex; border-radius: 10px; overflow: hidden; border: 1px solid var(--edge); }
.seg button { padding: 9px 13px; font-weight: 800; letter-spacing: 0.06em; background: rgba(255, 255, 255, 0.05); font-size: 16px; }
.seg button + button { border-left: 1px solid var(--edge); }
.seg button.on { background: var(--nato); color: #fff; }
#play { width: 100%; max-width: 460px; font-size: 28px !important; }

.side { display: flex; flex-direction: column; gap: 14px; }
.card { padding: 16px 18px; }
.card h3 { margin: 0 0 8px; font-family: 'Black Ops One', sans-serif; font-weight: 400; letter-spacing: 0.06em; font-size: 18px; }
.how ul { margin: 0; padding-left: 18px; font-size: 16px; line-height: 1.35; color: #c9d6e6; }
.how li { margin-bottom: 4px; }
.scores { width: 100%; border-collapse: collapse; font-size: 17px; }
.scores td { padding: 3px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.scores td.n { color: var(--dim); width: 22px; }
.scores td.name { font-weight: 800; letter-spacing: 0.1em; }
.scores td.w { color: var(--dim); text-align: right; }
.scores td.l { text-align: right; font-weight: 800; color: #ff8b7a; font-variant-numeric: tabular-nums; }
.scores tr.won td.w { color: var(--green); }
.scores tr.me td { background: rgba(246, 196, 83, 0.14); }

/* --- HUD -------------------------------------------------------------------------- */

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hud .pill, #buildbar > * { pointer-events: auto; }

.topbar {
  position: absolute;
  top: calc(10px + var(--safe-t));
  left: calc(10px + var(--safe-l));
  right: calc(10px + var(--safe-r));
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.pill {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.pill b { font-weight: 800; font-variant-numeric: tabular-nums; }
.funds { color: var(--gold); font-size: 22px; }
.funds .coin {
  width: 24px; height: 24px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff1c2, #f6c453 45%, #b07a12);
  color: #5a3b00; font-weight: 800; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}
.funds small { color: #c79a3a; font-weight: 700; }
.funds.bump b { animation: bump 0.25s; }
@keyframes bump { 50% { transform: scale(1.18); color: #fff; } }
.wave { flex-direction: column; gap: 0; align-items: flex-start; padding: 4px 14px; min-width: 150px; }
.waveLine { font-size: 17px; }
.waveLine b { font-size: 20px; }
.waveTitle { font-family: 'Black Ops One', sans-serif; font-size: 15px; letter-spacing: 0.05em; color: #ffd1c9; white-space: nowrap; }
.losses b { color: #ff7a66; font-size: 22px; }
.losses b:not(:empty)::before { content: '−'; }
.losses b.zero::before { content: ''; }
.losses.hit { animation: hit 0.35s; }
@keyframes hit { 30% { background: rgba(255, 60, 40, 0.55); } }
.status { gap: 14px; }

#feed {
  position: absolute;
  top: calc(64px + var(--safe-t));
  right: calc(12px + var(--safe-r));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  max-width: 60vw;
}
.feedItem {
  background: var(--panel);
  border-left: 4px solid var(--nato);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 600;
  animation: feedIn 0.25s ease-out;
  transition: opacity 0.6s;
}
.feedItem.bad { border-left-color: var(--red); }
.feedItem.good { border-left-color: var(--green); }
.feedItem.gold { border-left-color: var(--gold); }
.feedItem b { font-weight: 800; }
@keyframes feedIn { from { transform: translateX(30px); opacity: 0; } }

/* the build bar: a card per unit, always there, also the legend of costs */
#buildbar {
  position: absolute;
  left: calc(10px + var(--safe-l));
  bottom: calc(10px + var(--safe-b));
  display: flex;
  gap: 6px;
}
.bcard {
  width: 70px;
  padding: 6px 4px 5px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--edge);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.1s, background 0.15s;
}
.bcard svg { width: 40px; height: 30px; }
.bcard .nm { font-size: 13px; font-weight: 700; letter-spacing: 0.04em; color: #c9d6e6; }
.bcard .c { font-size: 15px; font-weight: 800; color: var(--gold); }
.bcard .hk {
  position: absolute; top: 3px; left: 6px; font-size: 11px; color: var(--dim); font-weight: 700;
}
.bcard.poor { opacity: 0.45; }
.bcard.poor .c { color: #d27b6b; }
.bcard.on { background: rgba(58, 160, 255, 0.35); border-color: var(--nato); transform: translateY(-4px); }

.corner {
  position: absolute;
  right: calc(12px + var(--safe-r));
  bottom: calc(12px + var(--safe-b));
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.round {
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--edge);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
}
.round.small { width: 46px; height: 46px; font-size: 16px; }
.round.big {
  width: 92px; height: 92px;
  position: relative;
  background: radial-gradient(circle at 50% 35%, #c2382b, #6e1410);
  border: 2px solid #ff9a85;
  font-family: 'Black Ops One', sans-serif;
  font-size: 17px;
  flex-direction: column;
  gap: 0;
  box-shadow: 0 0 0 4px rgba(255, 75, 58, 0.18), 0 8px 22px rgba(0, 0, 0, 0.4);
}
.round.big.ready { animation: throb 1.2s ease-in-out infinite; }
@keyframes throb { 50% { box-shadow: 0 0 0 10px rgba(255, 75, 58, 0.25), 0 8px 22px rgba(0, 0, 0, 0.4); } }
.round.big.off { filter: grayscale(0.85) brightness(0.7); }
.round.big .ring { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); transform: rotate(-90deg); }
.round.big .ring circle { fill: none; stroke: var(--gold); stroke-width: 5; stroke-dasharray: 289; stroke-dashoffset: 289; stroke-linecap: round; }
.round.big .bonus { font-family: 'Barlow Condensed', sans-serif; font-size: 14px; color: var(--gold); font-weight: 800; }

#banner {
  position: absolute;
  top: 22%;
  left: 0; right: 0;
  text-align: center;
  pointer-events: none;
  animation: bannerIn 0.5s ease-out;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.7);
  padding: 0 16px;
}
#banner .k { color: var(--gold); font-size: 18px; letter-spacing: 0.3em; }
#banner .big { font-family: 'Black Ops One', sans-serif; font-size: clamp(38px, 8vw, 72px); line-height: 1; margin: 4px 0; }
#banner .sub { font-size: 21px; color: #dbe5f2; max-width: 640px; margin: 0 auto; font-weight: 600; }
#banner.bad .big { color: #ff6a55; }
#banner.good .big { color: #8fe3a2; }
@keyframes bannerIn { from { transform: scale(1.3); opacity: 0; } }

#hint {
  position: absolute;
  bottom: calc(104px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--gold);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  max-width: 94vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- labels over the map -------------------------------------------------------- */

#labels { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.city {
  position: absolute;
  transform: translate(-50%, -100%);
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 1px 2px #000, 0 0 6px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  text-align: center;
  will-change: transform;
}
.city.cap { font-size: 16px; }
.city.cap::before { content: '★ '; color: var(--gold); }
.city.hostile { color: #ffb2a6; font-weight: 700; opacity: 0.85; }
.city.fallen { color: #ff6a55; }
.city.fallen::after { content: ' ✕'; }
.city .siege { display: block; height: 4px; margin: 2px auto 0; width: 44px; background: rgba(0, 0, 0, 0.6); border-radius: 2px; overflow: hidden; }
.city .siege i { display: block; height: 100%; background: var(--red); width: 0; }
.city.fallen .siege i { background: var(--nato); }

.incoming {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 46px; height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 75, 58, 0.95), rgba(140, 20, 10, 0.95));
  border: 2px solid #ffc0b4;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px;
  box-shadow: 0 0 0 0 rgba(255, 75, 58, 0.6);
  animation: ping 1.4s ease-out infinite;
}
.incoming svg { width: 24px; height: 24px; fill: #fff; }
.incoming .n { position: absolute; bottom: -18px; font-size: 13px; color: #ffd1c9; text-shadow: 0 1px 2px #000; white-space: nowrap; }
@keyframes ping { 70% { box-shadow: 0 0 0 18px rgba(255, 75, 58, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 75, 58, 0); } }

.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: 'Black Ops One', sans-serif;
  font-size: 22px;
  color: #ff6a55;
  text-shadow: 0 2px 6px #000;
  animation: floatUp 1.6s ease-out forwards;
  white-space: nowrap;
}
.float.gold { color: var(--gold); font-size: 18px; }
.float.good { color: #8fe3a2; }
@keyframes floatUp { to { transform: translate(-50%, -160%); opacity: 0; } }

/* --- radial menus --------------------------------------------------------------- */

#radial {
  position: fixed;
  z-index: 20;
  width: 0; height: 0;
}
#radial .hub {
  position: absolute;
  left: -34px; top: -34px;
  width: 68px; height: 68px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.55);
  animation: spin 8s linear infinite;
  pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.rbtn {
  position: absolute;
  width: 62px; height: 62px;
  margin: -31px 0 0 -31px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, #2a4566, #13233a);
  border: 2px solid #9cc8f5;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  animation: pop 0.18s ease-out backwards;
}
.rbtn svg { width: 34px; height: 26px; }
.rbtn .c {
  position: absolute; bottom: -12px;
  background: #111b29; border: 1px solid var(--gold);
  color: var(--gold); font-weight: 800; font-size: 13px;
  padding: 0 6px; border-radius: 8px; white-space: nowrap;
}
.rbtn .t {
  position: absolute; top: -17px;
  font-size: 12px; font-weight: 800; letter-spacing: 0.05em; color: #fff;
  text-shadow: 0 1px 3px #000; white-space: nowrap;
}
.rbtn.off { filter: grayscale(1) brightness(0.55); }
.rbtn.poor .c { color: #ff8b7a; border-color: #ff8b7a; }
.rbtn.gold { border-color: var(--gold); background: radial-gradient(circle at 50% 30%, #6a4c10, #2b1e05); }
.rbtn.red { border-color: #ff9a85; background: radial-gradient(circle at 50% 30%, #6a1c14, #2b0905); }
.rbtn .ico { font-size: 24px; line-height: 1; }
@keyframes pop { from { transform: scale(0.2); opacity: 0; } }

#unitCard {
  position: fixed;
  z-index: 19;
  left: 50%;
  bottom: calc(108px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 16px;
  display: flex; gap: 14px; align-items: center;
  white-space: nowrap;
  pointer-events: none;
}
#unitCard b { font-family: 'Black Ops One', sans-serif; font-weight: 400; font-size: 18px; }
#unitCard .stars { color: var(--gold); letter-spacing: 2px; }

/* --- game over ------------------------------------------------------------------ */

.stats { width: 100%; border-collapse: collapse; font-size: 18px; margin: 6px 0; }
.stats td { padding: 5px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.07); text-align: left; }
.stats td + td { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats tr.total td { font-size: 22px; color: #ff8b7a; border-bottom: none; }
.stats tr.total td:first-child { color: var(--ink); }
.status { font-size: 18px; color: #c9d6e6; margin: 0; }
#overTitle.won { color: #8fe3a2; }
#overTitle.lost { color: #ff6a55; }
.nameRow { display: flex; flex-direction: column; gap: 6px; align-items: center; margin: 4px 0; }
.nameRow label { color: var(--gold); font-weight: 800; letter-spacing: 0.12em; font-size: 14px; }
.nameInputs { display: flex; gap: 8px; }
#nameInput {
  width: 120px;
  font: 400 32px 'Black Ops One', sans-serif;
  text-align: center;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid var(--gold);
  color: #fff;
  border-radius: 10px;
  padding: 4px 6px;
  -webkit-user-select: text;
  user-select: text;
}

/* --- small screens ---------------------------------------------------------------- */

@media (max-width: 760px) {
  .menuGrid { grid-template-columns: 1fr; gap: 16px; }
  .side { order: 2; }
  .tag { font-size: 17px; }
  .pill { padding: 4px 9px; font-size: 15px; border-radius: 10px; }
  .funds { font-size: 18px; }
  .losses b { font-size: 18px; }
  .wave { min-width: 0; }
  .waveTitle { font-size: 12px; }
  .status .k { display: none; }
  .bcard { width: 56px; padding: 4px 2px; }
  .bcard svg { width: 32px; height: 24px; }
  .bcard .nm { font-size: 11px; }
  .bcard .hk { display: none; }
  .round.big { width: 76px; height: 76px; font-size: 14px; }
  .round.small { width: 40px; height: 40px; }
  .corner { flex-direction: column-reverse; align-items: flex-end; }
  #feed { top: calc(96px + var(--safe-t)); }
  .feedItem { font-size: 14px; }
  #unitCard { bottom: calc(160px + var(--safe-b)); font-size: 14px; }
  #hint { bottom: calc(80px + var(--safe-b)); font-size: 15px; }
  .city { font-size: 12px; }
  .city.cap { font-size: 13px; }
}

@media (max-width: 420px) {
  #buildbar { gap: 4px; }
  .bcard { width: 50px; }
  .bcard .nm { display: none; }
}
