html,
body {
  width: 100%;
  min-height: 100%;
  overscroll-behavior: none;
}

body.standalone-mode {
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.standalone-mode #gameCanvas,
.standalone-mode .mobile-controls,
.standalone-mode .mobile-controls button {
  touch-action: none;
  overscroll-behavior: contain;
}

.standalone-mode .app-shell {
  height: 100svh;
  min-height: 100svh;
}

.standalone-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.local-badge,
.just-play-label {
  color: var(--green);
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.just-play-label {
  margin: 0;
}

.chrome-action {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(169, 255, 21, 0.4);
  border-radius: 8px;
  color: var(--text);
  background: rgba(13, 18, 15, 0.9);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.privacy-note,
.howto-local {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.standalone-mode .side-panel {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.standalone-mode .leaderboard li {
  grid-template-columns: 34px minmax(0, 1fr) auto;
}

.standalone-mode .overlay {
  z-index: 4;
}

@media (max-width: 900px) {
  body.standalone-mode {
    overflow: hidden;
  }

  .standalone-mode .app-shell {
    width: 100vw;
    padding: max(6px, env(safe-area-inset-top)) 8px max(7px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  .standalone-mode .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    padding-bottom: 4px;
  }

  .standalone-mode .brand-logo {
    width: 42px;
    height: 42px;
  }

  .standalone-mode .brand h1 {
    font-size: 0.98rem;
  }

  .standalone-mode .brand p {
    font-size: 0.66rem;
  }

  .standalone-mode .local-badge {
    display: none;
  }

  .standalone-mode .chrome-action {
    min-height: 34px;
    padding: 0 9px;
    font-size: 0.62rem;
  }

  .standalone-mode .stats {
    order: 3;
    width: 100%;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
  }

  .standalone-mode .stat {
    min-height: 42px;
    padding: 5px 7px;
  }

  .standalone-mode .game-layout {
    min-height: 0;
    overflow: hidden;
  }

  .standalone-mode .arena-section {
    min-height: 0;
    grid-template-rows: 36px minmax(0, 1fr) auto;
    gap: 5px;
  }

  .standalone-mode .arena-tools {
    min-height: 36px;
  }

  .standalone-mode .arena-frame {
    width: min(100%, calc(100svh - 244px));
    aspect-ratio: 1;
    justify-self: center;
  }

  .standalone-mode #gameCanvas {
    width: 100%;
    height: 100%;
    max-height: none;
  }

  .standalone-mode .mobile-controls {
    width: min(100%, 272px);
    grid-template-rows: repeat(2, 46px);
    gap: 5px;
  }

  .standalone-mode .mobile-controls button {
    height: 46px;
    min-height: 46px;
  }

  .standalone-mode .side-panel {
    display: none !important;
  }

  .standalone-mode .overlay-logo {
    width: clamp(96px, 29vw, 138px);
    height: clamp(96px, 29vw, 138px);
  }
}

@media (max-width: 430px) and (max-height: 760px) {
  .standalone-mode .brand-logo {
    width: 36px;
    height: 36px;
  }

  .standalone-mode .brand p {
    display: none;
  }

  .standalone-mode .stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .standalone-mode .stat {
    min-height: 36px;
  }

  .standalone-mode .arena-frame {
    width: min(100%, calc(100svh - 214px));
  }

  .standalone-mode .mobile-controls {
    grid-template-rows: repeat(2, 42px);
  }

  .standalone-mode .mobile-controls button {
    height: 42px;
    min-height: 42px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  body.standalone-mode {
    overflow: hidden;
  }

  .standalone-mode .app-shell {
    width: 100vw;
    display: grid;
    grid-template-columns: minmax(150px, 220px) minmax(0, 1fr);
    grid-template-rows: 1fr;
    gap: 8px;
  }

  .standalone-mode .topbar {
    height: 100%;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    border: 0;
  }

  .standalone-mode .standalone-actions {
    justify-content: flex-start;
  }

  .standalone-mode .stats {
    grid-template-columns: 1fr;
  }

  .standalone-mode .game-layout,
  .standalone-mode .arena-section {
    min-height: 0;
  }

  .standalone-mode .arena-section {
    grid-template-columns: minmax(0, 1fr) 174px;
    grid-template-rows: 34px minmax(0, 1fr);
  }

  .standalone-mode .arena-tools {
    grid-column: 1 / -1;
  }

  .standalone-mode .arena-frame {
    width: min(100%, calc(100svh - 56px));
    align-self: center;
  }

  .standalone-mode .mobile-controls {
    align-self: center;
  }
}

@media (display-mode: standalone) {
  #installButton {
    display: none !important;
  }
}
