:root {
  --bg: #07070a;
  --card: #141418;
  --chip: #1c1c22;
  --text: #f4f4f7;
  --muted: #8b8b97;
  --pink: #7a2048;
  --pink2: #c45c7a;
  --green: #c8f542;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  height: auto;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.app {
  min-height: 100dvh;
  height: auto;
  display: flex;
  flex-direction: column;
  padding: calc(10px + env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom));
  max-width: 520px;
  margin: 0 auto;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.mode-nav {
  display: none;
}
.mode-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 700 12px/1 inherit;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.mode-btn.on {
  background: #2a2a32;
  color: #fff;
}

.ava, .ava-fb {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  background: #2a2a32;
}

.ava-fb {
  display: none;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.ava-wrap .ava[src=""] { display: none; }
.ava-wrap .ava[src=""] + .ava-fb { display: flex; }

.bal-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #121218;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 18px;
}

.gem {
  width: 16px;
  height: 16px;
  background: conic-gradient(#60a5fa, #22d3ee, #60a5fa);
  transform: rotate(45deg);
  border-radius: 3px;
}

.meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}

.meta-left { display: flex; align-items: center; gap: 8px; }
.meta-right { display: flex; align-items: center; gap: 10px; }
.hist-btn {
  border: 0;
  background: #1c1c22;
  color: #d4d4dc;
  font: 650 12px/1 inherit;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
}
.tag {
  font-size: 10px;
  letter-spacing: 0.08em;
  background: #2a2a32;
  padding: 3px 7px;
  border-radius: 6px;
  color: #d4d4dc;
}

.timer {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  color: #f4f4f7;
}
.timer.hot { color: #fb7185; }
.timer.wait { color: var(--muted); font-weight: 650; font-size: 14px; }

.bank {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 4px 0 2px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
  min-height: 18px;
}

.arena {
  flex: 0 0 auto;
  height: 58vh;
  min-height: 380px;
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: #0c0c10;
}

#field { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.bets {
  flex: 0 0 auto;
  max-height: 96px;
  overflow-y: auto;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
}
.bets:empty { display: none; }

.fair-now {
  flex: 0 0 auto;
  margin-top: 16px;
  padding: 12px;
  border-radius: 14px;
  background: #121218;
}
.fair-now[hidden] { display: none !important; }
.fair-now-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.fair-help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin-bottom: 10px;
}
.fair-now .fair-row { background: #1a1a22; }
.fair-cell {
  margin-top: 10px;
  font-weight: 800;
  font-size: 15px;
  color: #fff;
}
.fair-cell span { color: var(--green); }
.verify-btn {
  margin-top: 10px;
  width: 100%;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: #2a2a32;
  color: #fff;
  font: 700 14px/1 inherit;
  cursor: pointer;
}
.verify-btn[hidden], .verify-out[hidden], .fair-cell[hidden] { display: none !important; }
.verify-out {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.4;
  color: #d4d4dc;
  white-space: pre-wrap;
}
.verify-out.ok { color: #bbf7d0; }
.verify-out.bad { color: #fda4af; }

.bet-row {
  display: grid;
  grid-template-columns: 36px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #121218;
}
.bet-ava {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: #2a2a32;
  border: 2px solid var(--accent, #a78bfa);
}
.bet-ava.fb {
  display: flex;
  align-items: center;
  justify-content: center;
  font: 700 12px/1 inherit;
  color: #fff;
}
.bet-name {
  font-weight: 650;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bet-pct {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.bet-sum {
  font-weight: 800;
  font-size: 14px;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

.dock { flex: 0 0 auto; padding-top: 10px; }

.presets {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 48px;
  gap: 8px;
  margin-bottom: 10px;
}

.chip, .edit {
  height: 48px;
  border: 0;
  border-radius: 14px;
  background: var(--chip);
  color: #fff;
  font: 700 15px/1 inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.chip.on { background: #2a2438; box-shadow: inset 0 0 0 1px #a78bfa; }
.edit { font-size: 18px; }

.put {
  width: 100%;
  height: 56px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #ff4d8d 0%, #e11d6a 45%, #be185d 100%);
  color: #fff;
  font: 800 19px/1 inherit;
  letter-spacing: 0.02em;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 0 0 1px rgba(255, 105, 160, 0.35), 0 8px 24px rgba(225, 29, 106, 0.45);
}
.put:active { transform: scale(0.985); filter: brightness(1.05); }
.put:disabled {
  opacity: 0.4;
  box-shadow: none;
  filter: grayscale(0.25);
}

.modal, .win, .gate {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}
.modal[hidden], .win[hidden], .gate[hidden] {
  display: none !important;
}
.win, .gate { align-items: center; }
.sheet, .win-card {
  width: 100%;
  max-width: 520px;
  background: #16161c;
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet h3 { margin-bottom: 12px; }
.sheet input {
  width: 100%;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: #1c1c22;
  color: #fff;
  padding: 0 12px;
  margin-bottom: 8px;
  font: 16px inherit;
}
.win-card {
  width: auto;
  min-width: 220px;
  border-radius: 20px;
  text-align: center;
  padding: 22px 28px;
}
.win-ava {
  width: 64px; height: 64px; border-radius: 50%;
  margin: 0 auto 10px;
  background: #2a2a32 center/cover;
}
.win-name { color: var(--muted); margin-bottom: 6px; }
.win-sum { font-size: 28px; font-weight: 800; color: var(--green); }
.gate p { background: #16161c; padding: 18px 22px; border-radius: 16px; }

.hist-sheet {
  max-height: min(78vh, 640px);
  display: flex;
  flex-direction: column;
}
.hist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.hist-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: #1c1c22;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.hist-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.hist-card {
  background: #1a1a22;
  border-radius: 14px;
  padding: 12px;
}
.hist-top {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}
.hist-ava {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #2a2a32;
  border: 2px solid #a78bfa;
}
.hist-ava.fb {
  display: flex;
  align-items: center;
  justify-content: center;
  font: 700 13px/1 inherit;
  color: #fff;
}
.hist-who { font-weight: 700; font-size: 14px; }
.hist-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.hist-pay { font-weight: 800; color: var(--green); font-size: 15px; }
.hist-fair {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fair-row {
  display: grid;
  grid-template-columns: 44px 1fr 34px;
  gap: 8px;
  align-items: center;
  background: #121218;
  border-radius: 10px;
  padding: 7px 8px;
}
.fair-lab { color: var(--muted); font-size: 11px; font-weight: 650; }
.fair-val {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  color: #e5e5ea;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.copy-btn {
  width: 34px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: #2a2a32;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}
.copy-btn.ok { background: #365314; color: #d9f99d; }
.hist-empty { color: var(--muted); text-align: center; padding: 24px 8px; }

#viewTower[hidden], #viewBattle[hidden], #viewMenu[hidden] { display: none !important; }

.menu-sub {
  color: var(--muted);
  font-size: 14px;
  margin: 4px 0 14px;
}

.menu-card {
  position: relative;
  display: block;
  width: 100%;
  box-sizing: border-box;
  height: 32vh;
  min-height: 200px;
  max-height: 280px;
  margin: 0 0 14px;
  border: 0;
  border-radius: 22px;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  background: #101018;
  text-align: left;
  flex: 0 0 auto;
}
.menu-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.menu-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(7,7,10,0.15), rgba(7,7,10,0.82));
}
.menu-copy {
  position: absolute;
  left: 18px;
  bottom: 18px;
  right: 18px;
  z-index: 2;
  color: #fff;
}
.menu-copy b {
  display: block;
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 4px;
}
.menu-copy span {
  color: rgba(255,255,255,0.72);
  font-size: 14px;
}

.ping {
  font-size: 11px;
  color: #86efac;
  font-variant-numeric: tabular-nums;
}
.trade-x {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 2px 0 4px;
}
.trade-x.up { color: #4ade80; }
.trade-x.down { color: #fb7185; }

.trade-arena {
  flex: 0 0 auto;
  height: 52vh;
  min-height: 340px;
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: #0c0c10;
}
#tradeChart { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.trade-pos {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 88px;
  overflow-y: auto;
}
.trade-pos:empty { display: none; }
.tpos-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  background: #121218;
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 13px;
}
.tpos-pnl.pos { color: #4ade80; font-weight: 800; }
.tpos-pnl.neg { color: #fb7185; font-weight: 800; }

.trade-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.buy, .sell {
  height: 56px;
  border: 0;
  border-radius: 16px;
  font: 800 17px/1 inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.buy {
  background: linear-gradient(180deg, #34d399, #059669);
  color: #052e1c;
  box-shadow: 0 8px 22px rgba(16, 185, 129, 0.35);
}
.sell {
  background: linear-gradient(180deg, #fb7185, #e11d48);
  color: #fff;
  box-shadow: 0 8px 22px rgba(225, 29, 72, 0.35);
}
.buy:disabled, .sell:disabled { opacity: 0.4; box-shadow: none; }

/* —— Tower —— */
.tower-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 2px 0 10px;
}
.tower-hint {
  flex: 1;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.3;
}
.tower-hist {
  flex: 0 0 auto;
  border: 0;
  background: #1c1c24;
  color: #d4d4d8;
  font: 600 12px/1 inherit;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.tower-cashbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 8px;
  padding: 10px 12px;
  border-radius: 16px;
  background: linear-gradient(180deg, #16161e, #101016);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}
.tower-cashbar.is-live {
  background:
    radial-gradient(100% 120% at 0% 50%, rgba(250, 204, 21, 0.12), transparent 55%),
    linear-gradient(180deg, #1a1810, #12100c);
  box-shadow: inset 0 0 0 1px rgba(253, 230, 138, 0.22);
}
.tower-cash-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
}
.tower-cash-label {
  width: 100%;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #a1a1aa;
}
.tower-cash-amt {
  font-family: Orbitron, "Segoe UI", sans-serif;
  font-weight: 800;
  font-size: clamp(22px, 6.5vw, 32px);
  letter-spacing: 0.02em;
  color: #fef9c3;
  text-shadow: 0 0 18px rgba(250, 204, 21, 0.28);
  line-height: 1;
}
.tower-cash-mult {
  font-family: Orbitron, sans-serif;
  font-weight: 600;
  font-size: 13px;
  color: #fde68a;
}
.tower-cash-btn {
  flex: 0 0 auto;
  min-width: 108px;
  height: 48px;
  border: 0;
  border-radius: 14px;
  font: 800 15px/1 inherit;
  cursor: pointer;
  color: #1a1a12;
  background: linear-gradient(180deg, #fde68a, #f59e0b 55%, #d97706);
  box-shadow: 0 8px 18px rgba(245, 158, 11, 0.28);
  opacity: 0.35;
  pointer-events: none;
}
.tower-cash-btn.on {
  opacity: 1;
  pointer-events: auto;
}
.tower-cash-btn:disabled { opacity: 0.35; pointer-events: none; }

.tower-board {
  flex: 0 0 auto;
  margin-bottom: 2px;
}
.tower-grid {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.tower-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 8px;
  align-items: center;
  opacity: 0.42;
  transition: opacity 0.2s, transform 0.2s;
}
.tower-row.current {
  opacity: 1;
  transform: scale(1.015);
}
.tower-row.cleared { opacity: 0.78; }
.tower-mult {
  font-family: Orbitron, sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: #a78bfa;
  text-align: right;
}
.tower-row.current .tower-mult { color: #fde68a; }
.tower-cells {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.tower-cell {
  aspect-ratio: 1;
  border: 0;
  border-radius: 12px;
  background: #1a1a24;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
  cursor: default;
  display: grid;
  place-items: center;
  padding: 0;
  touch-action: manipulation;
}
.tower-cell.live {
  cursor: pointer;
  background: linear-gradient(180deg, #2a2a38, #1c1c28);
  box-shadow: inset 0 0 0 1px rgba(253, 230, 138, 0.35), 0 0 16px rgba(250, 204, 21, 0.12);
  animation: towerPulse 1.4s ease-in-out infinite;
}
.tower-cell.live:active { transform: scale(0.96); }
.tower-cell.safe {
  background: linear-gradient(180deg, #34d399, #059669);
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.4);
}
.tower-cell.safe-dim {
  background: #1f2937;
  opacity: 0.55;
}
.tower-cell.boom {
  background: radial-gradient(circle at 35% 30%, #fb7185, #9f1239 70%);
  box-shadow: 0 0 18px rgba(225, 29, 72, 0.45);
}
.gem-dot {
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: #ecfdf5;
  box-shadow: 0 0 10px rgba(255,255,255,0.7);
}
.bomb-ico {
  width: 68%;
  height: 68%;
  display: block;
}
.bomb-spark {
  animation: bombSpark 0.7s ease-in-out infinite;
}
@keyframes bombSpark {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}
@keyframes towerPulse {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(253, 230, 138, 0.35), 0 0 12px rgba(250, 204, 21, 0.1); }
  50% { box-shadow: inset 0 0 0 1px rgba(253, 230, 138, 0.55), 0 0 20px rgba(250, 204, 21, 0.22); }
}

.tower-dock {
  gap: 10px;
}
.tower-bombs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}
.tower-bombs-lab {
  font-size: 12px;
  color: var(--muted);
  margin-right: 4px;
}
.bomb-opt {
  width: 40px;
  height: 36px;
  border: 0;
  border-radius: 11px;
  background: #1c1c24;
  color: #d4d4d8;
  font: 800 14px/1 Orbitron, inherit;
  cursor: pointer;
}
.bomb-opt.on {
  background: linear-gradient(180deg, #fb7185, #e11d48);
  color: #fff;
  box-shadow: 0 6px 14px rgba(225, 29, 72, 0.3);
}

.tower-fair {
  margin-top: 12px;
  border-radius: 14px;
  background: #121218;
  padding: 8px 12px 10px;
}
.tower-fair summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  list-style: none;
}
.tower-fair summary::-webkit-details-marker { display: none; }
.tower-fair[open] summary { color: #e4e4e7; margin-bottom: 8px; }
.tower-fair .fair-help { margin-bottom: 8px; font-size: 12px; }

#towerIdle[hidden] { display: none !important; }

@media (min-width: 821px) {
  .app { padding-top: 18px; }
}
