:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #1b2029;
  --panel-2: #242b35;
  --text: #f3f6f8;
  --muted: #aab3bd;
  --line: #343d49;
  --accent: #52d273;
  --danger: #ff6868;
  --gold: #ffd166;
  --blue: #69a7ff;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.shell {
  width: min(1600px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 18px 0;
}

.shell:has(.game-screen:not([hidden])) {
  width: 100vw;
  height: 100dvh;
  padding: 0;
  overflow: hidden;
}

.menu-screen {
  min-height: calc(100vh - 36px);
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 18px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  width: min(720px, 100%);
}

.mode-grid button {
  min-height: 70px;
  font-size: 16px;
}

.mode-grid button:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.56;
}

.ai-difficulty-panel {
  display: grid;
  gap: 18px;
  width: min(720px, 100%);
}

.ai-difficulty-panel > header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ai-difficulty-panel h2,
.ai-difficulty-panel p {
  margin: 0;
}

.menu-back {
  width: 46px;
  min-width: 46px;
  padding: 0;
  font-size: 24px;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.difficulty-grid button {
  min-height: 112px;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 8px;
  padding: 18px;
  text-align: left;
}

.difficulty-grid strong {
  font-size: 20px;
}

.difficulty-grid span {
  color: var(--muted);
  font-size: 13px;
}

.difficulty-grid button:nth-child(1) {
  border-color: rgba(82, 210, 115, 0.55);
}

.difficulty-grid button:nth-child(2) {
  border-color: rgba(255, 209, 102, 0.55);
}

.difficulty-grid button:nth-child(3) {
  border-color: rgba(255, 104, 104, 0.58);
}

.online-lobby {
  min-height: calc(100vh - 36px);
  display: grid;
  align-content: start;
  gap: 24px;
  padding: clamp(18px, 4vw, 48px) 0;
}

.lobby-header,
.lobby-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.lobby-header h1,
.lobby-section-header h2,
.lobby-section-header p {
  margin: 0;
}

.lobby-section-header h2 {
  font-size: 22px;
}

.lobby-section-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.lobby-profile {
  display: grid;
  grid-template-columns: 130px minmax(220px, 420px);
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 16px 0;
}

.lobby-profile label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

input {
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: 0;
  background: var(--panel);
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(105, 167, 255, 0.14);
}

.lobby-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
  gap: clamp(28px, 5vw, 72px);
}

.room-browser,
.team-picker {
  min-width: 0;
}

.create-room-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin: 16px 0 12px;
}

.create-room-form button {
  padding-inline: 20px;
}

.room-search {
  display: block;
  margin-bottom: 12px;
}

.room-search input {
  width: 100%;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.room-list {
  display: grid;
  gap: 8px;
  max-height: min(520px, 56vh);
  overflow: auto;
}

.room-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 10px 14px;
  text-align: left;
}

.room-entry.is-selected {
  border-color: var(--blue);
  background: rgba(105, 167, 255, 0.1);
}

.room-entry strong,
.room-entry span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-entry span {
  color: var(--muted);
  font-size: 13px;
}

.room-entry b {
  color: var(--gold);
  white-space: nowrap;
}

.room-list-empty {
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.team-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.team-choice {
  display: grid;
  justify-items: start;
  align-content: start;
  gap: 9px;
  min-height: 190px;
  padding: 18px;
  text-align: left;
}

.team-choice__swatch {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
}

.team-choice--green {
  border-color: rgba(82, 210, 115, 0.56);
  background: rgba(28, 91, 50, 0.38);
}

.team-choice--green .team-choice__swatch {
  background: var(--accent);
}

.team-choice--red {
  border-color: rgba(255, 104, 104, 0.56);
  background: rgba(113, 39, 43, 0.38);
}

.team-choice--red .team-choice__swatch {
  background: var(--danger);
}

.team-choice span,
.team-choice small {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: rgba(243, 246, 248, 0.76);
}

.team-choice:disabled {
  cursor: not-allowed;
  filter: grayscale(0.7);
  opacity: 0.5;
}

.lobby-status {
  min-height: 24px;
  margin: 14px 0 0;
  color: var(--gold);
  font-size: 14px;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 42px);
  line-height: 1.02;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stats span,
kbd {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.game-screen {
  width: 100vw;
  height: 100dvh;
}

.game-layout {
  display: grid;
  width: 100vw;
  height: 100dvh;
  min-height: 0;
}

.game-screen:fullscreen {
  display: block;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.game-screen:fullscreen .game-layout {
  height: 100dvh;
  min-height: 0;
}

.game-screen:fullscreen .arena-wrap {
  display: flex;
  min-height: 0;
}

.game-screen:fullscreen #game {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.arena-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 0;
  overflow: hidden;
  background: #141820;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
}

#game {
  width: 100%;
  height: 100%;
  aspect-ratio: 5 / 3;
  object-fit: cover;
  cursor: crosshair;
}

.game-top-actions {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
}

.minimap {
  position: relative;
  width: 96px;
  aspect-ratio: 5 / 3;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 6px;
  background: #11161a;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.34);
  pointer-events: none;
}

#minimap,
#minimapUnits {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.tower-priority {
  position: relative;
  display: flex;
  align-items: center;
  gap: 5px;
  width: auto;
  min-height: 34px;
  padding: 4px 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: rgba(17, 19, 24, 0.9);
  color: rgba(243, 246, 248, 0.76);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
  font-size: 10px;
  font-weight: 800;
}

.tower-priority select {
  width: 94px;
  height: 25px;
  border: 1px solid rgba(105, 167, 255, 0.5);
  border-radius: 4px;
  background: #202a34;
  color: #f3f6f8;
  padding: 0 5px;
  font: inherit;
  cursor: pointer;
}

.tower-priority select:focus-visible {
  outline: 2px solid #69a7ff;
  outline-offset: 1px;
}

.connection-quality {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  background: rgba(17, 19, 24, 0.86);
  color: #d9e1e7;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.connection-quality__dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 50%;
  background: #8b949e;
  box-shadow: 0 0 8px rgba(139, 148, 158, 0.5);
}

.connection-quality strong {
  font-size: 11px;
  line-height: 1;
}

.connection-quality[data-quality="good"] .connection-quality__dot {
  background: #52d273;
  box-shadow: 0 0 10px rgba(82, 210, 115, 0.72);
}

.connection-quality[data-quality="fair"] .connection-quality__dot {
  background: #ffd166;
  box-shadow: 0 0 10px rgba(255, 209, 102, 0.68);
}

.connection-quality[data-quality="poor"] .connection-quality__dot,
.connection-quality[data-quality="offline"] .connection-quality__dot {
  background: #ff6868;
  box-shadow: 0 0 10px rgba(255, 104, 104, 0.68);
}

.message {
  position: absolute;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 32px));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(20, 24, 32, 0.92);
  padding: 12px 14px;
  text-align: center;
  font-weight: 800;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.25);
  z-index: 7;
  pointer-events: none;
}

.result-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(4, 7, 10, 0.42);
  backdrop-filter: blur(3px);
}

.post-match-actions {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: min(340px, calc(100% - 32px));
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(17, 19, 24, 0.92);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.34);
  transform: translateX(-50%);
  backdrop-filter: blur(8px);
}

.post-match-actions button {
  min-height: 44px;
  padding: 8px 12px;
}

.result-card {
  position: relative;
  width: min(520px, calc(100vw - 44px));
  min-height: 440px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 14px;
  border: 2px solid rgba(255, 255, 255, 0.24);
  border-radius: 12px;
  padding: 30px 26px;
  text-align: center;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.44);
}

.result-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border-color: rgba(255, 255, 255, 0.26);
  background: rgba(0, 0, 0, 0.2);
  color: #fff;
  font-size: 28px;
  line-height: 1;
}

.result-close:hover {
  background: rgba(0, 0, 0, 0.34);
}

.result-card.is-win {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 34%),
    linear-gradient(135deg, #17683b, #1d9c57);
}

.result-card.is-lose {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 36%),
    linear-gradient(135deg, #7b1f2a, #d05a28);
}

.result-icon {
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  border: 3px solid rgba(255, 255, 255, 0.42);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--gold);
  font-size: 58px;
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.34);
}

.result-card.is-lose .result-icon {
  color: #ffe1c4;
}

.upgrade-overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 7, 10, 0.5);
  backdrop-filter: blur(3px);
}

.upgrade-dialog {
  width: min(620px, calc(100vw - 36px));
  max-height: calc(100dvh - 36px);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(20, 24, 32, 0.98);
  padding: 18px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.46);
}

.upgrade-dialog__header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.upgrade-dialog h2,
.upgrade-dialog p {
  margin: 0;
}

.upgrade-dialog h2 {
  font-size: 24px;
}

.upgrade-dialog p {
  margin-top: 5px;
  color: var(--gold);
  font-size: 14px;
  font-weight: 800;
}

.upgrade-close {
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 26px;
  line-height: 1;
}

.barracks-upgrade-dialog {
  width: min(760px, calc(100vw - 36px));
}

.upgrade-view-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(260px, 100%);
  gap: 3px;
  margin: -4px 0 12px auto;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
}

.upgrade-view-toggle button {
  min-height: 32px;
  border: 0;
  border-radius: 4px;
  padding: 5px 10px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.upgrade-view-toggle button.is-active {
  background: #33485c;
  color: #fff;
}

.upgrade-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.upgrade-grid button {
  display: grid;
  justify-items: start;
  gap: 6px;
  min-height: 132px;
  padding: 14px;
  text-align: left;
}

.upgrade-option__head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.upgrade-option__icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: #222b33;
  color: #f3f6f8;
  font-size: 24px;
  font-weight: 950;
  line-height: 1;
}

.upgrade-option__icon--health {
  background: #3c2429;
  color: #ff6868;
}

.upgrade-option__icon--damage {
  background: #29333c;
  color: #dce8f2;
}

.upgrade-option__icon--speed {
  background: #20334a;
  color: #69a7ff;
  font-family: "Segoe UI Emoji", system-ui, sans-serif;
}

.upgrade-option__icon--count {
  background: #3b3020;
  color: #ffd166;
  font-size: 18px;
}

.upgrade-option__icon--bullet {
  background: #26352f;
  color: #8ff0bc;
  font-size: 18px;
}

.upgrade-option__title {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.upgrade-option__title strong {
  color: #f3f6f8;
  font-size: 16px;
}

.upgrade-option__title small {
  color: rgba(243, 246, 248, 0.62);
  font-size: 12px;
  font-weight: 700;
}

.upgrade-grid button:hover {
  background: rgba(82, 210, 115, 0.12);
}

.upgrade-grid button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.upgrade-grid button.is-unaffordable:disabled {
  border-color: rgba(255, 157, 77, 0.92);
  background: rgba(104, 58, 29, 0.5);
  color: rgba(255, 220, 192, 0.72);
}

.upgrade-grid button.is-unaffordable:disabled:hover {
  background: rgba(104, 58, 29, 0.5);
}

.upgrade-grid [data-upgrade-level],
.upgrade-grid [data-hero-upgrade-level] {
  color: var(--muted);
  font-size: 13px;
}

.upgrade-grid em {
  color: var(--gold);
  font-size: 14px;
  font-style: normal;
  font-weight: 850;
}

.upgrade-grid progress {
  width: 100%;
  height: 7px;
  overflow: hidden;
  border: 0;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.12);
}

.upgrade-grid progress::-webkit-progress-bar {
  background: rgba(255, 255, 255, 0.12);
}

.upgrade-grid progress::-webkit-progress-value,
.upgrade-grid progress::-moz-progress-bar {
  background: #52d273;
}

.segmented-progress {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 3px;
  width: 100%;
  height: 10px;
}

.segmented-progress i {
  display: block;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
}

.segmented-progress i.is-filled {
  border-color: rgba(82, 210, 115, 0.72);
  background: #52d273;
}

.upgrade-grid b {
  color: var(--gold);
  font-size: 15px;
}

.barracks-upgrade-dialog.is-compact .upgrade-option__title small,
.barracks-upgrade-dialog.is-compact [data-upgrade-level],
.barracks-upgrade-dialog.is-compact [data-upgrade-effect] {
  display: none;
}

.barracks-upgrade-dialog.is-compact .barracks-upgrade-grid button {
  min-height: 98px;
  align-content: space-between;
  padding: 11px;
}

.barracks-upgrade-dialog.is-compact .upgrade-option__icon {
  width: 36px;
  height: 36px;
  flex-basis: 36px;
  font-size: 21px;
}

.barracks-upgrade-dialog.is-compact .upgrade-option__title strong {
  font-size: 14px;
}

.hero-upgrade-dialog {
  width: min(820px, calc(100vw - 36px));
}

.base-upgrade-dialog {
  width: min(680px, calc(100vw - 36px));
}

.base-upgrade-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.hero-upgrade-dialog.is-compact .upgrade-option__title small,
.hero-upgrade-dialog.is-compact [data-hero-upgrade-level],
.hero-upgrade-dialog.is-compact [data-hero-upgrade-effect],
.base-upgrade-dialog.is-compact .upgrade-option__title small,
.base-upgrade-dialog.is-compact [data-base-upgrade-level],
.base-upgrade-dialog.is-compact [data-base-upgrade-effect] {
  display: none;
}

.hero-upgrade-dialog.is-compact .hero-upgrade-grid button,
.base-upgrade-dialog.is-compact .base-upgrade-grid button {
  min-height: 98px;
  align-content: space-between;
  padding: 11px;
}

.hero-xp-progress {
  display: grid;
  gap: 7px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
}

.hero-xp-progress span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.hero-xp-progress progress {
  width: 100%;
  height: 9px;
  accent-color: var(--gold);
}

.respawn-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: rgba(7, 9, 12, 0.3);
}

.respawn-indicator {
  display: grid;
  justify-items: center;
  gap: 8px;
  min-width: min(360px, calc(100vw - 36px));
  border: 1px solid rgba(255, 128, 103, 0.56);
  border-radius: 8px;
  background: rgba(29, 19, 22, 0.94);
  padding: 22px 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.44);
  pointer-events: auto;
}

.respawn-indicator strong {
  color: #ff8f78;
  font-size: 28px;
}

.respawn-indicator span {
  color: rgba(255, 255, 255, 0.82);
  font-size: 16px;
  font-weight: 800;
}

.respawn-indicator b {
  color: var(--gold);
  font-size: 28px;
}

.buyback-button {
  min-width: 210px;
  margin-top: 5px;
  border-color: rgba(255, 209, 102, 0.64);
  background: #3b3020;
  color: #ffd166;
}

.buyback-button:hover:not(:disabled) {
  border-color: #ffd166;
  background: #4a3a21;
}

.buyback-button:disabled {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(30, 31, 34, 0.84);
  color: rgba(255, 255, 255, 0.38);
  cursor: not-allowed;
}

.result-card h2 {
  margin: 0;
  font-size: 40px;
  line-height: 1;
}

.result-card p {
  margin: 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: 17px;
  font-weight: 800;
}

.result-stats-details {
  width: 100%;
}

.result-stats-details summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  padding: 10px 13px;
  background: rgba(7, 12, 15, 0.3);
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  font-weight: 850;
  list-style: none;
}

.result-stats-details summary::-webkit-details-marker {
  display: none;
}

.result-stats-details summary::after {
  content: "+";
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
}

.result-stats-details[open] summary::after {
  content: "−";
}

.result-stats {
  width: 100%;
  display: grid;
  gap: 1px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.16);
  margin-top: 7px;
}

.result-stats > div {
  min-height: 43px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 9px 13px;
  background: rgba(7, 12, 15, 0.3);
  text-align: left;
}

.result-stats span {
  color: rgba(255, 255, 255, 0.78);
  font-size: 14px;
  font-weight: 750;
}

.result-stats strong {
  color: #fff;
  font-size: 17px;
  white-space: nowrap;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  margin-top: 8px;
}

.controls,
.stats,
.speed-panel,
.action-buttons,
button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.player-hud {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 3;
  display: flex;
  align-items: end;
  gap: 10px;
  pointer-events: none;
}

.touch-controls {
  display: none;
}

.touch-enabled .game-screen {
  touch-action: none;
  overscroll-behavior: none;
}

.touch-enabled .touch-controls {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: block;
  pointer-events: none;
}

.touch-enabled .touch-controls.is-hidden {
  display: none;
}

.touch-stick {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 116px;
  height: 116px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background: rgba(12, 16, 20, 0.38);
  box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.28);
  pointer-events: auto;
  touch-action: none;
}

.touch-stick--move {
  left: max(18px, env(safe-area-inset-left));
}

.touch-stick--aim {
  right: max(18px, env(safe-area-inset-right));
  border-color: rgba(255, 104, 104, 0.38);
}

.touch-stick__knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  background: rgba(75, 91, 104, 0.82);
  box-shadow: 0 7px 18px rgba(0, 0, 0, 0.34);
  transform: translate(-50%, -50%);
}

.touch-stick--aim .touch-stick__knob {
  background: rgba(139, 57, 57, 0.84);
}

.touch-actions {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 46px);
  gap: 7px;
  transform: translateX(-50%);
  pointer-events: auto;
}

.touch-actions button {
  width: 46px;
  min-height: 46px;
  padding: 0;
  border-color: rgba(255, 255, 255, 0.26);
  border-radius: 50%;
  background: rgba(23, 29, 36, 0.88);
  color: #f3f6f8;
  font-size: 25px;
  line-height: 1;
  touch-action: manipulation;
}

.touch-actions button:active {
  border-color: #69a7ff;
  background: #33485c;
  transform: scale(0.94);
}

.touch-enabled .player-hud {
  left: 10px;
  top: 10px;
  right: auto;
  bottom: auto;
  transform: scale(0.78);
  transform-origin: top left;
}

.touch-enabled .minimap {
  width: 76px;
}

.tower-priority--base { margin: -4px 0 12px auto; }

.hero-health,
.hero-level-counter,
.coin-counter,
.tower-counter {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(17, 19, 24, 0.84);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(8px);
}

.hero-health {
  width: min(320px, calc(100vw - 132px));
  padding: 10px 12px 12px;
}

.hero-health__top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 7px;
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}

.hero-health__top span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(243, 246, 248, 0.76);
}

.hero-health__top strong {
  flex: 0 0 auto;
}

.hero-health__track {
  height: 18px;
  border: 2px solid rgba(0, 0, 0, 0.42);
  border-radius: 4px;
  background: rgba(11, 14, 18, 0.88);
  overflow: hidden;
}

.hero-health__bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #35d268, #8ff27d);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
  transition: width 120ms ease-out;
}

.resource-counters {
  display: flex;
  gap: 8px;
}

.hero-level-counter,
.coin-counter,
.tower-counter {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 86px;
  min-height: 48px;
  padding: 10px 13px;
  font-size: 22px;
  font-weight: 950;
}

.hero-level-counter {
  position: relative;
  min-width: 88px;
  color: #8ff0bc;
  pointer-events: auto;
}

.hero-level-icon {
  font-size: 24px;
  line-height: 1;
}

.hero-level-counter > b {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0 5px;
  border: 2px solid #17201b;
  border-radius: 12px;
  background: var(--gold);
  color: #201807;
  font-size: 12px;
}

.coin-counter {
  color: var(--gold);
}

.tower-counter {
  color: #f3f6f8;
}

.coin-icon {
  position: relative;
  display: inline-block;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  border: 2px solid #f7a928;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff1a5 0 18%, #ffd166 19% 58%, #d88916 59% 100%);
  box-shadow:
    inset -3px -4px 0 rgba(146, 84, 10, 0.28),
    0 0 18px rgba(255, 209, 102, 0.28);
}

.coin-icon::after {
  content: "";
  position: absolute;
  inset: 5px 8px;
  border-left: 2px solid rgba(116, 69, 8, 0.48);
  border-right: 2px solid rgba(116, 69, 8, 0.34);
  border-radius: 50%;
}

.tower-icon {
  display: block;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.4));
}

.hud-toggle {
  position: relative;
  min-width: 68px;
  min-height: 34px;
  background: rgba(27, 32, 41, 0.92);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.25);
}

.hud-panel {
  position: absolute;
  right: 14px;
  top: 68px;
  z-index: 4;
  display: grid;
  width: min(420px, calc(100vw - 28px));
  max-height: calc(100% - 82px);
  overflow: auto;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 19, 24, 0.94);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.34);
}

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

.controls div {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}

.speed-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.speed-panel > span {
  color: var(--muted);
  font-size: 14px;
}

.speed-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.speed-buttons button {
  min-height: 38px;
  border-radius: 6px;
}

.speed-buttons button.is-active {
  border-color: var(--accent);
  background: rgba(82, 210, 115, 0.16);
  color: var(--text);
}

.speed-panel.is-disabled {
  opacity: 0.58;
}

.speed-panel.is-disabled button {
  cursor: not-allowed;
}

.action-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
}

kbd {
  display: inline-block;
  padding: 6px 8px;
  text-align: center;
}

button {
  min-height: 44px;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.sound-button {
  border-color: rgba(255, 209, 102, 0.55);
}

.sound-button.is-muted {
  border-color: var(--line);
  color: var(--muted);
}

@media (max-width: 900px) {
  .topbar {
    display: none;
  }

  .mode-grid,
  .difficulty-grid,
  .hud-panel,
  .stats,
  .controls,
  .action-buttons {
    grid-template-columns: 1fr;
  }

  .player-hud {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }

  .hero-health {
    flex: 1;
    width: auto;
  }

  .hero-level-counter,
  .coin-counter,
  .tower-counter {
    min-width: 68px;
    padding-inline: 9px;
    font-size: 18px;
  }

  .hero-level-counter {
    gap: 5px;
  }

  .hero-level-icon {
    font-size: 20px;
  }

  .hero-upgrade-grid {
    grid-template-columns: 1fr;
  }

  .base-upgrade-grid {
    grid-template-columns: 1fr;
  }

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

  .online-lobby {
    padding: 18px 0 30px;
  }

  .lobby-layout,
  .lobby-profile,
  .team-choices {
    grid-template-columns: 1fr;
  }

  .lobby-header,
  .lobby-section-header {
    align-items: flex-start;
  }

  .game-layout {
    height: 100dvh;
  }
}

@media (orientation: landscape) and (pointer: coarse) {
  .touch-enabled .touch-stick {
    bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
    width: 104px;
    height: 104px;
  }

  .touch-enabled .touch-stick__knob {
    width: 48px;
    height: 48px;
  }

  .touch-enabled .touch-actions {
    bottom: max(34px, calc(env(safe-area-inset-bottom) + 22px));
    grid-template-columns: repeat(3, 42px);
    gap: 6px;
  }

  .touch-enabled .touch-actions button {
    width: 42px;
    min-height: 42px;
    font-size: 22px;
  }

  .touch-enabled .upgrade-overlay {
    padding:
      max(8px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .touch-enabled .barracks-upgrade-dialog {
    position: relative;
    width: min(720px, calc(100vw - 24px));
    max-height: calc(100dvh - 16px);
    padding: 10px 12px;
  }

  .touch-enabled .barracks-upgrade-dialog .upgrade-dialog__header {
    margin-bottom: 7px;
  }

  .touch-enabled .barracks-upgrade-dialog h2 {
    font-size: 18px;
  }

  .touch-enabled .barracks-upgrade-dialog p {
    font-size: 11px;
  }

  .touch-enabled .barracks-upgrade-dialog .upgrade-view-toggle {
    position: absolute;
    top: 10px;
    right: 62px;
    width: 190px;
    margin: 0;
  }

  .touch-enabled .barracks-upgrade-grid {
    gap: 7px;
  }

  .touch-enabled .barracks-upgrade-dialog.is-compact .barracks-upgrade-grid button {
    min-height: 82px;
    gap: 4px;
    padding: 8px 10px;
  }

  .touch-enabled .post-match-actions {
    top: max(12px, env(safe-area-inset-top));
    bottom: auto;
    width: min(300px, calc(100% - 360px));
    min-width: 240px;
  }
}

@media (orientation: portrait) and (pointer: coarse) {
  .touch-enabled .touch-stick {
    width: 94px;
    height: 94px;
  }

  .touch-enabled .touch-stick__knob {
    width: 44px;
    height: 44px;
  }

  .touch-enabled .touch-actions {
    bottom: 122px;
    grid-template-columns: repeat(3, 42px);
    gap: 6px;
  }

  .touch-enabled .touch-actions button {
    width: 42px;
    min-height: 42px;
    font-size: 22px;
  }

  .touch-enabled .player-hud {
    transform: scale(0.6);
  }

}
