:root {
  color-scheme: dark;
  --bg: #121313;
  --panel: #1c2020;
  --panel-strong: #272c2b;
  --line: #3a403e;
  --paper: #f0efe7;
  --muted: #a9b0a9;
  --green: #5fc781;
  --red: #e86554;
  --gold: #e5b84f;
  --cyan: #6bbfd6;
  --steel: #8b9698;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(95, 199, 129, 0.12), transparent 38%),
    linear-gradient(315deg, rgba(232, 101, 84, 0.1), transparent 42%),
    var(--bg);
  color: var(--paper);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
}

input,
select {
  user-select: text;
  -webkit-user-select: text;
}

.app-layout {
  position: relative;
  width: min(1450px, calc(100vw - 24px));
  min-height: 100svh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
}

.powerup-panel {
  grid-column: 1;
  grid-row: 1;
  align-self: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(28, 32, 32, 0.9);
  overflow: hidden;
}

.powerup-panel h2 {
  margin: 0;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 1rem;
  letter-spacing: 0;
}

.powerup-status {
  min-height: 38px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.powerup-status[hidden] {
  display: none;
}

.powerup-status span,
.powerup-list span:last-child {
  color: var(--muted);
  font-size: 0.88rem;
}

.powerup-status strong {
  min-width: 0;
  color: var(--paper);
  font-size: 0.9rem;
  text-align: right;
}

.powerup-list {
  margin: 0;
  padding: 8px 0;
  list-style: none;
}

.powerup-list li {
  min-height: 30px;
  padding: 5px 12px;
  display: flex;
  align-items: center;
  gap: 9px;
}

.powerup-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 10px currentColor;
}

.powerup-dot.heal {
  color: #67d982;
  background: #67d982;
}

.powerup-dot.shield {
  color: #6bbfd6;
  background: #6bbfd6;
}

.powerup-dot.rapid {
  color: #f0cc5c;
  background: #f0cc5c;
}

.powerup-dot.nuke {
  color: #f06c59;
  background: #f06c59;
}

.powerup-dot.speed {
  color: #b58cff;
  background: #b58cff;
}

.powerup-dot.split {
  color: #ff94cf;
  background: #ff94cf;
}

.game-shell {
  grid-column: 2;
  grid-row: 1;
  width: min(1180px, calc(100vw - 24px), max(620px, calc((100svh - 170px) * 1.53)));
  min-height: 100svh;
  margin: 0;
  padding: 18px 0 20px;
  display: grid;
  grid-template-rows: auto auto auto auto;
  align-content: center;
  gap: 12px;
}

.topbar,
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h1 {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 2rem);
  font-weight: 800;
  letter-spacing: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-panel {
  min-height: 46px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(28, 32, 32, 0.82);
  display: grid;
  grid-template-columns: auto 116px auto 150px minmax(160px, 1fr);
  align-items: center;
  gap: 8px;
}

.room-button,
.room-input,
.level-select {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--paper);
  min-height: 34px;
}

.room-button {
  padding: 0 12px;
  cursor: pointer;
}

.room-button:hover {
  border-color: var(--gold);
}

.room-input,
.level-select {
  width: 100%;
  padding: 0 10px;
}

.room-input {
  text-transform: uppercase;
}

.room-input:focus,
.level-select:focus {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
}

.room-status {
  min-width: 0;
  color: var(--muted);
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-status.is-online {
  color: #dfffe7;
}

.room-status.is-error {
  color: #ffb3a9;
}

.room-panel.is-disabled {
  opacity: 0.72;
}

.room-button:disabled,
.room-input:disabled,
.level-select:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.mode-button,
.icon-button,
.touch-controls button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--paper);
  min-height: 42px;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.mode-button {
  min-width: 62px;
  padding: 0 14px;
}

.mode-button.is-active {
  background: #254437;
  border-color: var(--green);
  color: #eaffef;
}

.net-debug {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 10;
  max-width: min(340px, calc(100vw - 24px));
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(17, 20, 20, 0.9);
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.26);
  pointer-events: none;
}

.net-debug.is-warn {
  border-color: var(--gold);
  color: #fff0b6;
}

.icon-button.is-on {
  background: #3c3320;
  border-color: var(--gold);
  color: #fff3bc;
}

.icon-button {
  width: 44px;
  font-size: 1.5rem;
  line-height: 1;
}

.mode-button:hover,
.icon-button:hover,
.touch-controls button:hover {
  transform: translateY(-1px);
  border-color: var(--gold);
}

.touch-controls button.is-down {
  transform: translateY(1px);
  background: var(--panel-strong);
  border-color: var(--cyan);
}

.mode-button:focus-visible,
.icon-button:focus-visible,
.touch-controls button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.arena-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 26 / 17;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #171a19;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.34);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.center-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 32px));
  padding: 16px 18px;
  border: 1px solid rgba(240, 239, 231, 0.22);
  border-radius: 6px;
  background: rgba(18, 19, 19, 0.88);
  color: var(--paper);
  text-align: center;
  letter-spacing: 0;
  pointer-events: auto;
}

.banner-title {
  font-size: clamp(1.12rem, 3.8vw, 1.7rem);
  font-weight: 800;
}

.banner-text {
  margin-top: 8px;
  color: var(--muted);
  font-size: clamp(0.86rem, 2.6vw, 1rem);
  line-height: 1.45;
}

.banner-action {
  margin-top: 14px;
  min-height: 38px;
  padding: 0 18px;
  border: 1px solid var(--green);
  border-radius: 6px;
  background: rgba(95, 199, 129, 0.22);
  color: var(--paper);
  cursor: pointer;
  font-weight: 800;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(28, 32, 32, 0.92);
  overflow: hidden;
}

.hud.is-duel {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.hud-item {
  min-width: 0;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-right: 1px solid var(--line);
}

.hud-item:last-child {
  border-right: 0;
}

.hud.is-duel .hud-item:nth-child(3) {
  border-right: 0;
}

.hud-item[hidden] {
  display: none;
}

.hud-label {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.hud strong {
  color: var(--paper);
  font-size: 1.1rem;
  min-width: 2ch;
  text-align: right;
}

.touch-controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.touch-pad {
  width: 148px;
  height: 148px;
  position: relative;
  touch-action: none;
}

.joystick-base {
  position: absolute;
  inset: 8px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(107, 191, 214, 0.16), rgba(28, 32, 32, 0.92) 66%);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.35);
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border: 1px solid var(--cyan);
  border-radius: 50%;
  background: rgba(39, 44, 43, 0.98);
  box-shadow: 0 0 18px rgba(107, 191, 214, 0.35);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.fire-touch {
  width: 88px;
  height: 88px;
  padding: 0;
  font-size: 1.5rem;
  font-weight: 800;
  background: #442b27;
  border-color: var(--red);
}

.reward-tanks {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  min-width: 82px;
  min-height: 82px;
}

.reward-tanks:empty {
  min-width: 0;
  min-height: 0;
}

.reward-tanks-desktop {
  position: fixed;
  right: 128px;
  top: 50%;
  transform: translateY(-50%);
  flex-direction: column;
  z-index: 7;
}

.reward-tank {
  position: relative;
  width: 74px;
  height: 74px;
  opacity: 0.96;
  transform: rotate(-8deg);
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.34));
  outline: none;
}

.reward-tank::before {
  content: "";
  position: absolute;
  inset: -10px;
  z-index: 0;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--tank-main) 58%, transparent), transparent 68%);
  opacity: 0.72;
}

.reward-tank::after {
  content: attr(data-tip);
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  z-index: 3;
  width: max-content;
  max-width: 210px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(17, 20, 20, 0.94);
  color: var(--paper);
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.35;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
  opacity: 0;
  pointer-events: none;
  transform: translate(6px, -50%);
  transition: opacity 120ms ease, transform 120ms ease;
}

.reward-tank:hover::after,
.reward-tank:focus-visible::after {
  opacity: 1;
  transform: translate(0, -50%);
}

.reward-track,
.reward-body,
.reward-cannon,
.reward-turret {
  position: absolute;
  z-index: 1;
}

.reward-track {
  top: 18px;
  width: 11px;
  height: 40px;
  border-radius: 5px;
  background: linear-gradient(180deg, #13251d, var(--tank-track));
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
}

.reward-track.left {
  left: 15px;
}

.reward-track.right {
  right: 15px;
}

.reward-body {
  left: 24px;
  top: 18px;
  width: 26px;
  height: 40px;
  border-radius: 6px;
  background: linear-gradient(145deg, var(--tank-highlight), var(--tank-main) 58%, var(--tank-shadow));
  box-shadow: 0 0 20px var(--tank-main), inset 0 0 0 2px rgba(255, 255, 255, 0.22);
}

.reward-cannon {
  left: 48px;
  top: 33px;
  width: 24px;
  height: 8px;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--tank-accent), #eaffef);
  box-shadow: 0 0 10px rgba(95, 199, 129, 0.58);
}

.reward-turret {
  left: 31px;
  top: 30px;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: var(--tank-accent);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.38);
}

.reward-tank.silver {
  --tank-main: #c9d1d3;
  --tank-highlight: #f0f7f6;
  --tank-shadow: #7f8d8d;
  --tank-track: #406552;
  --tank-accent: #5fc781;
}

.reward-tank.gold {
  --tank-main: #e5b84f;
  --tank-highlight: #fff1a8;
  --tank-shadow: #a67524;
  --tank-track: #406552;
  --tank-accent: #5fc781;
}

.reward-tanks-mobile {
  display: none;
}

.cheat-panel {
  position: fixed;
  right: 72px;
  top: 112px;
  z-index: 8;
  width: 174px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(28, 32, 32, 0.9);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.cheat-panel h2 {
  margin: 0;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
  letter-spacing: 0;
}

.cheat-toggle {
  min-height: 34px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid rgba(58, 64, 62, 0.7);
  color: var(--muted);
  font-size: 0.86rem;
  cursor: pointer;
  user-select: none;
}

.cheat-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
}

.cheat-actions {
  padding: 8px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.cheat-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--paper);
  cursor: pointer;
  font-size: 0.84rem;
}

.cheat-button:hover {
  border-color: var(--gold);
}

@media (max-width: 760px) {
  .app-layout {
    width: min(100vw - 14px, 760px);
    min-height: 100svh;
    display: block;
    padding: 8px 0 12px;
  }

  .powerup-panel {
    margin-bottom: 8px;
  }

  .cheat-panel {
    position: static;
    width: auto;
    margin-top: 8px;
  }

  .cheat-panel h2 {
    display: none;
  }

  .cheat-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cheat-actions {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .powerup-panel h2 {
    display: none;
  }

  .powerup-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .game-shell {
    width: 100%;
    min-height: 0;
    padding: 0;
    align-content: start;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .toolbar {
    width: 100%;
  }

  .room-panel {
    grid-template-columns: 1fr 1fr;
  }

  .room-status {
    grid-column: 1 / -1;
    white-space: normal;
  }

  .mode-button {
    flex: 1;
    min-width: 0;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hud-item:nth-child(2) {
    border-right: 0;
  }

  .hud-item:nth-child(1),
  .hud-item:nth-child(2) {
    border-bottom: 1px solid var(--line);
  }

  .hud.is-duel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hud.is-duel .hud-item {
    border-bottom: 0;
  }

  .hud.is-duel .hud-item:nth-child(2) {
    border-right: 1px solid var(--line);
  }

  .hud.is-duel .hud-item:nth-child(3) {
    border-right: 0;
  }

  .touch-controls {
    display: flex;
  }

  .reward-tanks-desktop {
    display: none;
  }

  .reward-tanks-mobile {
    display: flex;
  }

  .reward-tank::after {
    right: auto;
    left: 50%;
    top: auto;
    bottom: calc(100% + 8px);
    max-width: 180px;
    transform: translate(-50%, 6px);
    text-align: center;
  }

  .reward-tank:hover::after,
  .reward-tank:focus-visible::after {
    transform: translate(-50%, 0);
  }
}
