:root {
  color-scheme: dark;
  --bg: #050b12;
  --panel: #0c1724;
  --panel-2: #101f2f;
  --line: rgba(155, 202, 234, 0.18);
  --ink: #f4f8fb;
  --muted: #91a9bb;
  --cyan: #39d9ff;
  --blue: #397cff;
  --red: #ff536a;
  --gold: #ffc857;
  --green: #51e39a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% -15%, rgba(57, 124, 255, 0.24), transparent 38%),
    linear-gradient(180deg, #07111d 0%, var(--bg) 70%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button { font: inherit; }

.app-shell {
  width: min(100%, 430px);
  min-height: 100dvh;
  margin: 0 auto;
  position: relative;
  background: rgba(5, 11, 18, 0.88);
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.topbar {
  height: 58px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 12, 20, 0.92);
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid rgba(57, 217, 255, 0.55); border-radius: 9px;
  color: var(--cyan); font-weight: 900; transform: skew(-7deg);
  box-shadow: inset 0 0 18px rgba(57, 217, 255, 0.12);
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; letter-spacing: .06em; }
.brand small { font-size: 8px; color: var(--muted); letter-spacing: .18em; margin-top: 2px; }

.icon-button {
  border: 1px solid var(--line); border-radius: 999px; padding: 7px 10px;
  color: var(--muted); background: rgba(255,255,255,.025); font-size: 10px; cursor: pointer;
}

.scoreboard {
  height: 72px; display: grid; grid-template-columns: 1fr 116px 1fr; align-items: center;
  padding: 7px 14px; background: linear-gradient(180deg, rgba(15,31,47,.95), rgba(8,18,29,.95));
  border-bottom: 1px solid var(--line);
}
.side-stats { display: grid; grid-template-columns: auto auto; align-items: baseline; gap: 1px 7px; }
.side-stats span { grid-column: 1 / -1; font-size: 9px; font-weight: 800; letter-spacing: .16em; color: var(--muted); }
.side-stats strong { font-size: 22px; line-height: 1; color: var(--gold); }
.side-stats small { font-size: 9px; color: var(--muted); }
.player-stats { text-align: right; justify-content: end; }
.enemy-stats { text-align: left; }

.match-stats { text-align: center; }
.match-stats > span, .match-stats > small { display: block; color: var(--muted); font-size: 9px; letter-spacing: .12em; }
.match-stats > strong { display: flex; justify-content: center; align-items: center; gap: 9px; font-size: 23px; line-height: 1.25; }
.match-stats b:first-child { color: var(--cyan); }
.match-stats b:last-child { color: var(--red); }
.match-stats i { color: rgba(255,255,255,.3); font-style: normal; }

.battle-wrap { position: relative; background: #08121d; }
#gameCanvas { width: 100%; height: auto; display: block; touch-action: none; }

.battle-banner {
  position: absolute; left: 50%; top: 49%; transform: translate(-50%, -50%);
  padding: 11px 22px; border-radius: 8px; background: rgba(4, 11, 18, .88);
  border: 1px solid var(--cyan); color: white; font-weight: 900; letter-spacing: .12em;
  box-shadow: 0 0 35px rgba(57,217,255,.18); white-space: nowrap; z-index: 5;
}
.toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 6;
  padding: 8px 14px; border-radius: 999px; color: #061019; background: var(--gold);
  font-size: 11px; font-weight: 800; box-shadow: 0 8px 25px rgba(0,0,0,.35); white-space: nowrap;
}
.hidden { display: none !important; }

.deploy-panel {
  min-height: 104px; padding: 8px 10px 12px; background: #09131f; border-top: 1px solid var(--line);
  transition: opacity .2s ease;
}
.deploy-panel.is-locked { opacity: .52; pointer-events: none; }
.deploy-hint { display: flex; justify-content: space-between; color: var(--muted); font-size: 9px; margin: 0 3px 7px; }
.unit-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.unit-card {
  position: relative; min-height: 58px; padding: 6px 4px; border: 1px solid var(--line); border-radius: 9px;
  background: linear-gradient(180deg, #13273a, #0b1724); color: var(--ink); cursor: pointer; overflow: hidden;
}
.unit-card.selected { border-color: var(--cyan); box-shadow: inset 0 0 0 1px var(--cyan), 0 0 16px rgba(57,217,255,.18); }
.unit-card:disabled { opacity: .4; cursor: not-allowed; }
.unit-card .unit-icon { font-size: 17px; display: block; }
.unit-card strong { font-size: 11px; display: block; margin: 2px 0; }
.unit-card small { color: var(--gold); font-size: 9px; }
.unit-card .cooldown-mask {
  position: absolute; inset: auto 0 0; height: 0; background: rgba(3,8,14,.76); pointer-events: none;
}
.unit-card .cd-text { position: absolute; inset: 0; display: none; place-items: center; font-weight: 900; font-size: 16px; }
.unit-card.cooling .cd-text { display: grid; }
.unit-card .upgrade-pip { position: absolute; right: 4px; top: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 8px var(--gold); }

.modal-layer {
  position: absolute; inset: 0; z-index: 20; display: none; align-items: center; justify-content: center;
  padding: 16px; background: rgba(2, 7, 12, .82); backdrop-filter: blur(10px);
}
.modal-layer.active { display: flex; }
.panel-card {
  width: 100%; border: 1px solid rgba(140,198,235,.22); border-radius: 18px;
  background: linear-gradient(155deg, rgba(18,36,53,.98), rgba(7,17,28,.99)); box-shadow: var(--shadow);
}
.start-card, .result-card { padding: 28px 22px; text-align: center; }
.eyebrow { color: var(--cyan); font-size: 9px; font-weight: 900; letter-spacing: .22em; }
.start-card h1, .result-card h2 { margin: 8px 0 10px; font-size: 34px; letter-spacing: .02em; }
.lead { margin: 0 auto 22px; color: #b6c8d6; font-size: 13px; line-height: 1.65; max-width: 330px; }
.rule-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 24px; }
.rule-grid div { padding: 12px 5px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.025); }
.rule-grid b, .rule-grid span, .rule-grid small { display: block; }
.rule-grid b { color: var(--gold); font-size: 10px; }
.rule-grid span { font-size: 11px; font-weight: 800; margin: 4px 0; }
.rule-grid small { color: var(--muted); font-size: 8px; line-height: 1.45; }
.primary-button {
  width: 100%; border: 0; border-radius: 11px; padding: 14px; cursor: pointer;
  color: #04131a; background: linear-gradient(90deg, var(--cyan), #72f0c6); font-weight: 900;
  box-shadow: 0 12px 35px rgba(57,217,255,.18);
}
.control-note { display: block; margin-top: 13px; color: #657f92; font-size: 8px; }

#auctionOverlay { align-items: flex-start; padding: 8px; }
.auction-panel { padding: 12px; max-height: calc(100dvh - 16px); overflow-y: auto; }
.auction-duelbar { display: grid; grid-template-columns: minmax(0, 1fr) 58px minmax(0, 1fr); gap: 6px; align-items: stretch; }
.auction-clock {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 1px solid rgba(255,200,87,.28); border-radius: 10px;
  background: radial-gradient(circle, rgba(255,200,87,.12), rgba(0,0,0,.16));
}
.auction-clock span { color: var(--muted); font-size: 7px; white-space: nowrap; }
.auction-clock strong { color: var(--gold); font-size: 22px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.auction-clock small { color: #806f4c; font-size: 7px; }
.auction-head { display: flex; align-items: end; justify-content: space-between; margin-top: 11px; }
.auction-head h2 { margin: 2px 0 0; font-size: 22px; }
.auction-tip { color: #688195; font-size: 8px; text-align: right; }
.lot-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
.preview-card { padding: 8px 5px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: rgba(255,255,255,.02); text-align: center; }
.preview-card.active { color: var(--ink); border-color: var(--gold); background: rgba(255,200,87,.08); }
.preview-card.done { opacity: .35; }
.preview-card strong { display: block; font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-card small { font-size: 8px; }
.active-lot {
  min-height: 126px; display: flex; align-items: center; gap: 14px; padding: 14px;
  border: 1px solid rgba(255,200,87,.28); border-radius: 14px;
  background: radial-gradient(circle at 10% 50%, rgba(255,200,87,.13), transparent 38%), rgba(255,255,255,.025);
}
.lot-icon {
  flex: 0 0 62px; width: 62px; height: 62px; display: grid; place-items: center;
  border: 1px solid rgba(255,200,87,.5); border-radius: 16px; color: var(--gold); font-size: 30px;
  transform: rotate(2deg); box-shadow: inset 0 0 24px rgba(255,200,87,.09);
}
.lot-copy > span { color: var(--gold); font-size: 9px; letter-spacing: .12em; }
.lot-copy h3 { margin: 5px 0; font-size: 20px; }
.lot-copy p { margin: 0; min-height: 38px; color: #aebfcd; font-size: 11px; line-height: 1.55; }
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.tag-row span { padding: 3px 6px; border-radius: 999px; background: rgba(57,217,255,.08); color: #9feaff; font-size: 8px; }
.bidder-card { min-width: 0; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: rgba(0,0,0,.18); }
.bot-bidder { border-color: rgba(255,83,106,.25); }
.player-bidder { border-color: rgba(57,217,255,.25); }
.bidder-title { display: block; }
.bidder-title span { color: var(--muted); font-size: 8px; font-weight: 900; letter-spacing: .08em; }
.bidder-title strong { display: block; margin-top: 2px; color: var(--gold); font-size: 12px; white-space: nowrap; }
.wallet-detail { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; margin-top: 5px; }
.wallet-detail span { padding: 4px 5px; border-radius: 5px; background: rgba(255,255,255,.035); color: #7891a3; font-size: 7px; }
.wallet-detail b { display: block; margin-top: 1px; color: #eef6fb; font-size: 10px; }
.bidder-state { margin: 5px 0; padding: 4px 5px; border-radius: 6px; background: rgba(255,255,255,.04); font-size: 8px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bot-bidder .bidder-state { color: #ff91a0; }
.player-bidder .bidder-state { color: #8cecff; }
.loadout-label { color: #667f91; font-size: 7px; margin-bottom: 4px; }
.auction-loadout { display: flex; flex-wrap: wrap; gap: 3px; overflow: hidden; min-height: 18px; max-height: 38px; }
.auction-loadout span { display: block; max-width: 100%; padding: 3px 5px; border-radius: 5px; background: rgba(255,255,255,.05); color: #aebfcd; font-size: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bid-readout { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 7px 0; }
.bid-readout div { padding: 9px 5px; text-align: center; border-radius: 8px; background: rgba(0,0,0,.18); }
.bid-readout span, .bid-readout strong { display: block; }
.bid-readout span { color: var(--muted); font-size: 8px; }
.bid-readout strong { margin-top: 3px; font-size: 13px; }
.auction-message { min-height: 34px; color: #a9bdcb; font-size: 10px; line-height: 1.5; text-align: center; }
.bid-actions { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 7px; margin-top: 10px; }
.bid-actions button { border-radius: 10px; padding: 12px 6px; cursor: pointer; font-weight: 900; }
.secondary-button { border: 1px solid var(--line); color: var(--muted); background: rgba(255,255,255,.025); }
.bid-button { border: 1px solid rgba(57,217,255,.35); color: var(--cyan); background: rgba(57,217,255,.08); }
.bid-button.hot { color: #08131b; background: var(--gold); border-color: var(--gold); }
.bid-actions button:disabled { opacity: .3; cursor: not-allowed; }

.result-card h2 { font-size: 30px; }
.result-card p { color: #aec1cf; font-size: 12px; line-height: 1.65; }
.result-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 18px 0 22px; }
.result-stats div { padding: 12px; background: rgba(255,255,255,.035); border: 1px solid var(--line); border-radius: 9px; }
.result-stats span, .result-stats strong { display: block; }
.result-stats span { color: var(--muted); font-size: 9px; }
.result-stats strong { margin-top: 3px; font-size: 16px; }

@media (max-height: 790px) {
  .topbar { height: 48px; padding-block: 7px; }
  .scoreboard { height: 62px; }
  .deploy-panel { min-height: 96px; }
  .unit-card { min-height: 52px; }
  .start-card { padding-block: 20px; }
  .rule-grid { margin-bottom: 16px; }
}

@media (min-width: 700px) {
  body { padding: 16px 0; }
  .app-shell { min-height: calc(100dvh - 32px); border-radius: 22px; border: 1px solid rgba(155,202,234,.15); }
}
