:root {
  --bg: #0a0d12;
  --panel: #151b23;
  --panel-border: #232b36;
  --text: #e8edf3;
  --text-dim: #8b96a5;
  --accent: #3ee08a;
  --accent-dim: #1f8f57;
  --danger: #ff5d5d;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  overscroll-behavior: none; /* stop pull-to-refresh / rubber-band bounce from leaking out of the fixed-position screens */
}

body {
  background: radial-gradient(circle at 50% 0%, #151d27 0%, #0a0d12 65%);
}

.hidden {
  display: none !important;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* flex-start, not center: a centered flex container clips the far side of
     any child taller than the viewport - scrollTop can't go negative, so
     content above the centered position becomes permanently unreachable.
     The panels below center themselves via their own auto margins instead,
     which degrades to top-aligned (fully scrollable, nothing clipped) once
     they no longer fit. */
  justify-content: flex-start;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  gap: 18px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 36px 32px;
  text-align: center;
  max-width: 440px;
  width: 100%;
  margin: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.start-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 36px 32px 40px;
  text-align: center;
  max-width: 600px;
  width: 100%;
  margin: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* --- logo --- */

.logo-lockup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.logo-lockup--hero {
  gap: 20px;
  margin-bottom: 6px;
}

.logo-lockup--small {
  gap: 8px;
  margin-right: 6px;
}

/* The official game logo artwork - shown whole (object-fit: contain, never
   cropped to a circle) in a framed badge that matches the app's existing
   card language, so it reads as branding rather than a profile picture. */
.logo-icon {
  flex-shrink: 0;
  display: block;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: #0a0d12;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

.logo-icon--hero {
  width: 112px;
  height: 112px;
}

.logo-icon--small {
  width: 34px;
  height: 34px;
  border-radius: 8px;
}

.wordmark {
  margin: 0;
  display: flex;
  flex-direction: column;
  line-height: 0.92;
  text-align: left;
}

.wordmark-line {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-transform: uppercase;
}

.wordmark-snake {
  background: linear-gradient(135deg, #78f5b0, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.wordmark-eaters {
  background: linear-gradient(135deg, #ff9f4d, var(--danger));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.wordmark-small {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  white-space: nowrap;
  background: linear-gradient(135deg, var(--accent), #ff9f4d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title {
  margin: 0 0 8px;
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), #5db3ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-sm {
  font-size: 2rem;
}

.subtitle {
  color: var(--text-dim);
  margin: 0 0 16px;
  font-size: 0.95rem;
}

.combat-rule {
  background: #1c242e;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 16px;
  margin: 0 0 22px;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text-dim);
}

.rule-win {
  color: var(--accent);
  font-weight: 700;
}

.rule-lose {
  color: var(--danger);
  font-weight: 700;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 14px 32px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  touch-action: manipulation; /* no double-tap-to-zoom delay */
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #05130a;
  box-shadow: 0 8px 24px rgba(62, 224, 138, 0.25);
}

.btn-play {
  font-size: 1.25rem;
  padding: 16px 56px;
  margin: 4px 0 8px;
  animation: playPulse 2.4s ease-in-out infinite;
}

@keyframes playPulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(62, 224, 138, 0.3); }
  50% { box-shadow: 0 8px 34px rgba(62, 224, 138, 0.65); }
}

.btn-ghost {
  background: #1c242e;
  color: var(--text);
  border: 1px solid var(--panel-border);
  width: 42px;
  height: 42px;
  border-radius: 10px;
  font-size: 1.1rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.start-section {
  margin-top: 28px;
  text-align: center;
}

.section-label {
  margin: 0 0 12px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
}

.control-card {
  background: #1c242e;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.control-card--boost {
  border-color: #2a5566;
}

.control-card--secondary {
  opacity: 0.75;
}

.control-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.control-keys {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.control-desc {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.key {
  display: inline-block;
  background: #1c242e;
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  padding: 2px 8px;
  font-family: monospace;
  color: var(--text);
  margin: 0 2px;
}

.skin-groups {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.skin-group-heading {
  margin: 18px 0 2px;
}
.skin-group-heading:first-child {
  margin-top: 4px;
}

.skin-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 10px;
  margin: 8px 0 4px;
}

.skin-card {
  background: #1c242e;
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  padding: 8px 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  color: inherit;
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.skin-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.25);
}

.skin-card.selected {
  border-color: #fff;
  background: #232d3a;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
}

.skin-preview {
  width: 100%;
  aspect-ratio: 1.4 / 1;
  border-radius: 8px;
  display: block;
}

.skin-card-name {
  font-size: 0.68rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.25;
  color: var(--text-dim);
}

.skin-card.selected .skin-card-name {
  color: var(--text);
}

.final-stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 22px 0 28px;
}

.final-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #1c242e;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 16px;
}

.final-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

/* --- game screen --- */

#gameScreen {
  gap: 10px;
}

.hud {
  width: 100%;
  max-width: 980px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 6px 14px;
  min-width: 64px;
}

.hud-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.hud-value {
  font-size: 1.15rem;
  font-weight: 700;
}

.you-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(62, 224, 138, 0.12);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 8px;
  max-width: 100%;
  overflow-wrap: anywhere; /* never a horizontal-overflow source, whatever the skin name's length */
}

.you-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  flex-shrink: 0;
}

.hud-status {
  margin-left: auto;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
}

.arena-wrap {
  position: relative;
  width: 100%;
  max-width: 980px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  touch-action: none; /* the whole board region is the swipe surface */
}

#gameCanvas {
  /* Fit inside the arena wrapper but ALWAYS keep the arena's 7:5 shape. (width:100% together with
     max-height only clamped the height, which stretched the board on short/landscape screens.) */
  width: auto;
  height: auto;
  max-width: min(100%, 980px);
  max-height: 100%;
  aspect-ratio: 7 / 5;
  display: block;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
  touch-action: none; /* swipes on the board are game input, never a page-scroll gesture */
  -webkit-user-select: none;
  user-select: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 12, 0.6);
  border-radius: 12px;
}

.overlay-text {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--text);
}

.action-row {
  width: 100%;
  max-width: 980px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-boost {
  background: #1c242e;
  color: #78e6ff;
  border: 1px solid #2a5566;
  min-width: 180px;
}

.btn-boost.boosting {
  background: linear-gradient(135deg, #78e6ff, #3ea8d8);
  color: #04222e;
  box-shadow: 0 0 18px rgba(120, 230, 255, 0.5);
}

.btn-boost.cooldown {
  color: var(--text-dim);
  border-color: var(--panel-border);
  cursor: not-allowed;
  opacity: 0.7;
}

/* --- touch d-pad, shown only on coarse pointers (touch devices) --- */

.dpad {
  display: none;
}

@media (pointer: coarse) {
  .dpad {
    display: grid;
    grid-template-columns: 56px 56px 56px;
    grid-template-rows: 56px 56px;
    gap: 6px;
    justify-content: center;
    margin-bottom: 6px;
  }

  .dpad-btn {
    background: rgba(28, 36, 46, 0.9);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    color: var(--text);
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none; /* dpad drives the snake directly - never a scroll/zoom gesture */
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .dpad-up { grid-column: 2; grid-row: 1; }
  .dpad-left { grid-column: 1; grid-row: 2; }
  .dpad-down { grid-column: 2; grid-row: 2; }
  .dpad-right { grid-column: 3; grid-row: 2; }
}

@media (max-width: 560px) {
  .title { font-size: 2rem; }
  .panel { padding: 28px 20px; }
  .hud-stat { min-width: 52px; padding: 5px 10px; }
  .hud-value { font-size: 1rem; }
  .btn-boost { min-width: 0; width: 100%; max-width: 320px; }

  .start-card { padding: 28px 18px 32px; }
  .logo-lockup--hero { flex-direction: column; gap: 10px; }
  .wordmark { text-align: center; align-items: center; }
  .logo-icon--hero { width: 96px; height: 96px; }
  .wordmark-line { font-size: 1.9rem; }
  .btn-play { width: 100%; padding: 16px 24px; }
  .controls-grid { grid-template-columns: repeat(2, 1fr); }
  .wordmark-small { display: none; } /* icon alone is enough in the compact mobile HUD */

  .btn-ghost { width: 44px; height: 44px; } /* comfortable touch target */
}

/* Extra-small phones (iPhone SE / 320-400px class) - tighten further so the
   start screen needs as little scrolling as possible and nothing crowds. */
@media (max-width: 400px) {
  .screen { gap: 14px; }
  .start-card, .panel { padding: 20px 14px 24px; }
  .subtitle { font-size: 0.85rem; margin-bottom: 12px; }
  .combat-rule { font-size: 0.8rem; padding: 10px 12px; margin-bottom: 16px; }
  .logo-icon--hero { width: 76px; height: 76px; }
  .wordmark-line { font-size: 1.6rem; }
  .btn-play { padding: 14px 20px; font-size: 1.1rem; }
  .start-section { margin-top: 20px; }
  .skin-picker { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .skin-card { padding: 6px 4px 8px; }
  .skin-card-name { font-size: 0.62rem; }
  .controls-grid { gap: 8px; }
  .control-card { padding: 10px 6px; }
  .hud { gap: 8px; }
  .hud-stat { min-width: 44px; padding: 4px 8px; }
  .you-badge { font-size: 0.72rem; padding: 5px 10px; }
}

/* Short landscape (phones rotated sideways): stacking hud/board/controls
   vertically like portrait would starve the board of height, so the touch
   controls move beside the board instead of below it. */
@media (orientation: landscape) and (max-height: 500px) {
  #gameScreen {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "hud  hud   hud"
      "dpad arena boost";
    align-items: center;
    justify-items: center;
    width: 100%;
    height: 100%;
    gap: 6px 10px;
    padding: 6px;
  }
  #gameScreen .hud { grid-area: hud; width: 100%; gap: 8px; }
  #gameScreen .hud-stat { padding: 3px 8px; min-width: 40px; }
  #gameScreen .hud-value { font-size: 0.9rem; }
  #gameScreen .you-badge { padding: 4px 8px; font-size: 0.7rem; }
  #gameScreen .arena-wrap { grid-area: arena; width: 100%; height: 100%; max-height: 100%; }
  #gameScreen #dpad { grid-area: dpad; margin: 0; }
  #gameScreen .action-row { grid-area: boost; width: auto; max-width: none; }
  #gameScreen .btn-boost { min-width: 0; width: auto; padding: 10px 16px; font-size: 0.8rem; }

  @media (pointer: coarse) {
    #gameScreen .dpad {
      grid-template-columns: 44px 44px 44px;
      grid-template-rows: 44px 44px;
      gap: 4px;
    }
  }

  .start-card, .panel { padding: 18px 20px; max-height: 100%; overflow-y: auto; }
  .logo-lockup--hero { margin-bottom: 0; }
  .logo-icon--hero { width: 64px; height: 64px; }
  .wordmark-line { font-size: 1.5rem; }
  .subtitle, .combat-rule { display: none; } /* reclaim vertical room in a very short viewport */
  .start-section { margin-top: 14px; }
}

/* --- multiplayer --- */

.btn-secondary {
  background: #1c242e;
  color: var(--text);
  border: 1px solid #2a5566;
}

.btn-secondary:disabled,
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.85rem;
  min-height: 40px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-dim);
  text-decoration: underline;
  min-height: 44px;
  padding: 8px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  align-self: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-mp {
  display: block;
  margin: 2px auto 6px;
  padding: 12px 40px;
  min-height: 48px;
}

.mp-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 460px;
}

.mp-panel .title {
  margin-bottom: 0;
}

.mp-status {
  margin: 0;
  min-height: 1.3em;
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--text-dim);
}

.mp-status.error { color: var(--danger); }
.mp-status.ok { color: var(--accent); }

.mp-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.mp-field .section-label {
  margin: 0;
}

.text-input {
  width: 100%;
  background: #0f151c;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 14px;
  min-height: 48px;
  color: var(--text);
  font: inherit;
  font-size: 1rem; /* 16px+ so mobile browsers don't zoom on focus */
}

.text-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}


.mp-skin-line {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #1c242e;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 12px;
  text-align: left;
  font-size: 0.9rem;
}

.mp-skin-line small {
  color: var(--text-dim);
}

.mp-skin-preview {
  width: 70px;
  height: 50px;
  border-radius: 8px;
  flex-shrink: 0;
}

.mp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.mp-actions .btn {
  flex: 1 1 140px;
  min-height: 48px;
  padding-left: 12px;
  padding-right: 12px;
  white-space: nowrap;
}






.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #1c242e;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 6px 10px;
  text-align: left;
}

.player-row canvas {
  border-radius: 6px;
  flex-shrink: 0;
}

.player-row--me {
  border-color: rgba(62, 224, 138, 0.5);
}

.player-row--dc {
  opacity: 0.55;
}

.player-name {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 6px;
  background: #2a3442;
  color: var(--text-dim);
  white-space: nowrap;
}

.tag--host { background: rgba(255, 210, 63, 0.15); color: #ffd23f; }
.tag--you { background: rgba(62, 224, 138, 0.15); color: var(--accent); }
.tag--dc { background: rgba(255, 93, 93, 0.15); color: var(--danger); }

.rank {
  font-weight: 800;
  color: var(--text-dim);
  min-width: 26px;
}

.standing-stats {
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.mp-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 92%;
  text-align: center;
  background: rgba(10, 13, 18, 0.88);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 2;
  pointer-events: none;
}

.mp-banner--big {
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.8rem;
  padding: 14px 26px;
}

.overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px;
  max-width: 90%;
  text-align: center;
}

.overlay-text--sm {
  font-size: 1.4rem;
}

.overlay-note {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}

@media (max-width: 560px) {
  .btn-mp { width: 100%; }
}

@media (max-width: 400px) {
  .mp-panel { gap: 12px; }
  .standing-stats { display: none; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .mp-panel { gap: 10px; }
  .overlay-card { gap: 6px; padding: 8px; }
  .overlay-note { display: none; }
}

/* --- lobby browser --------------------------------------------------------------------------- */

.lobby-heading {
  margin: 4px 0 0;
  text-align: left;
}

.lobby-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column; /* cards stack vertically on every screen size */
  gap: 10px;
}

.lobby-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #1c242e;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  transition: border-color 0.15s ease, opacity 0.15s ease;
}

.lobby-card[data-state="countdown"] {
  border-color: rgba(62, 224, 138, 0.45);
}

.lobby-card--full {
  opacity: 0.72;
}

.lobby-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.lobby-name {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.lobby-meta {
  display: flex;
  flex-wrap: wrap;
  column-gap: 10px;
  row-gap: 2px;
  font-size: 0.88rem;
}

.lobby-players {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.lobby-state {
  color: var(--text-dim);
}

.lobby-pips {
  display: flex;
  gap: 4px;
  margin-top: 2px;
}

.lobby-pips i {
  width: 14px;
  height: 6px;
  border-radius: 3px;
  background: #2a3442;
}

.lobby-pips i.on {
  background: var(--accent);
}

.lobby-join {
  flex-shrink: 0;
  min-width: 104px;
  min-height: 48px;
  padding: 10px 18px;
}

.lobby-count {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.lobby-count-num {
  font-size: 2.6rem;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.lobby-count-label {
  color: var(--text-dim);
  font-weight: 700;
}

/* --- connection indicator (real measured ping) ---------------------------------------------------- */

.mp-conn {
  display: inline-flex;
  align-items: center;
  align-self: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: #1c242e;
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  white-space: nowrap;
}

.mp-conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.mp-conn--ok { color: var(--accent); }
.mp-conn--warn { color: #ffcf4d; }
.mp-conn--bad { color: var(--danger); }
.mp-conn .mp-conn-text { color: var(--text); }

/* --- live leaderboard (part of the layout flow: it can never sit on top of the arena) ---------------------- */

.mp-board {
  flex: 0 0 auto;
  width: 100%;
  max-width: 980px;
  margin: 0;
  padding: 4px 10px;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 14px;
  row-gap: 1px;
  background: rgba(10, 13, 18, 0.72);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  font-size: 0.76rem;
  pointer-events: none; /* purely informational: never swallows a touch */
}

.board-row {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.35;
}

.board-rank { width: 1.1em; color: var(--text-dim); font-weight: 800; text-align: right; }
.board-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.board-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.board-score { font-variant-numeric: tabular-nums; font-weight: 800; color: #ffd23f; }
.board-row--me .board-name { color: var(--accent); }
.board-row--me { background: rgba(62, 224, 138, 0.12); border-radius: 6px; }
.board-row--dead { opacity: 0.45; text-decoration: line-through; }

/* --- chat ---------------------------------------------------------------------------------------------------- */

.chat-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.chat-log {
  min-height: 84px;
  max-height: 150px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #0f151c;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.chat-line { overflow-wrap: anywhere; }
.chat-name { font-weight: 800; color: var(--accent); margin-right: 6px; }
.chat-line--me .chat-name { color: #ffd23f; }
.chat-line--sys { color: var(--text-dim); font-style: italic; }

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form .text-input {
  flex: 1;
  min-width: 0;
}

.chat-send {
  min-width: 76px;
  min-height: 48px;
  padding: 0 16px;
}

.chat-toggle {
  position: relative;
  font-size: 1.1rem;
}

.chat-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}

/* Opens over the bottom of the screen only while typing; the arena's swipe surface is unaffected. */
.chat-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 12px max(12px, env(safe-area-inset-bottom));
  background: rgba(21, 27, 35, 0.97);
  border: 1px solid var(--panel-border);
  border-bottom: none;
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
}

.chat-drawer .chat-log {
  max-height: 32vh;
}

@media (max-width: 560px) {
  .lobby-card { padding: 12px; }
  .lobby-join { min-width: 92px; padding: 10px 14px; }
  .lobby-count-num { font-size: 2.2rem; }
}

@media (max-width: 400px) {
  .lobby-name { font-size: 0.98rem; }
  .lobby-meta { font-size: 0.8rem; }
  .lobby-join { min-width: 84px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .lobby-card { padding: 8px 12px; }
  .lobby-count-num { font-size: 1.8rem; }
  .chat-log { max-height: 90px; min-height: 60px; }
  .chat-drawer .chat-log { max-height: 26vh; }
}

/* Short landscape: get the lobby list on screen without scrolling past the header. */
@media (orientation: landscape) and (max-height: 500px) {
  #lobbyBrowserScreen .mp-skin-line,
  #lobbyBrowserScreen .lobby-heading,
  #lobbyBrowserScreen .mp-field .section-label { display: none; }
  #lobbyBrowserScreen .title { font-size: 1.3rem; }
  #lobbyBrowserScreen .mp-status { min-height: 0; }
  #lobbyBrowserScreen .mp-panel,
  #lobbyBrowserScreen.screen .panel { padding: 12px 16px; gap: 8px; }
  #lobbyScreen .panel { padding: 12px 16px; gap: 8px; }
}

/* Wide screens: two columns so all lobbies are visible at once (narrow screens stay stacked). */
@media (min-width: 900px) {
  #lobbyBrowserScreen .panel { max-width: 760px; }
  .lobby-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
}

/* =========================================================================================
   Polish pass: leaderboard placement, MP HUD, countdown, toast, lobby cards, results
   ========================================================================================= */

.board-row { flex: 0 1 auto; line-height: 1.55; }
.board-name { max-width: 11ch; }

/* --- multiplayer HUD on portrait phones: two rows instead of three, so the leaderboard strip
       costs the arena almost nothing. (Badge + "Playing" text are redundant in multiplayer:
       your nickname tag, the leaderboard highlight and the connection pill say the same.) ---- */
@media (max-width: 560px) {
  #gameScreen.mp-mode { gap: 6px; }
  #gameScreen.mp-mode .you-badge,
  #gameScreen.mp-mode .hud-status { display: none; }
  #gameScreen.mp-mode #hudConn { margin-right: auto; }
}

/* Very narrow phones: the leaderboard shows the top 3 (plus you, if you are lower) on one line. */
@media (max-width: 360px) {
  .mp-board { flex-wrap: nowrap; overflow: hidden; column-gap: 10px; font-size: 0.72rem; }
  .mp-board .board-row:nth-child(n+4):not(.board-row--me) { display: none; }
  .board-name { max-width: 7ch; }
}

/* Short landscape (grid layout): the leaderboard lives in the left column, above the D-pad,
   never on the arena and never on the controls. */
@media (orientation: landscape) and (max-height: 500px) {
  #gameScreen .mp-board {
    grid-area: dpad;
    align-self: start;
    justify-self: start;
    flex-direction: column;
    flex-wrap: nowrap;
    width: auto;
    min-width: 108px;
    max-width: 150px;
    padding: 4px 6px;
    font-size: 0.66rem;
    row-gap: 0;
  }
  #gameScreen.mp-mode #dpad { align-self: end; }
  #gameScreen.mp-mode .you-badge { display: none; }
}

/* --- connection pill states ---------------------------------------------------------------- */
.mp-conn--pending { color: #ffcf4d; }
.mp-conn--pending .mp-conn-dot { animation: connPulse 1s ease-in-out infinite; }
.mp-conn--neutral { color: var(--text-dim); }
.mp-conn .mp-conn-ms { color: var(--text-dim); font-weight: 600; margin-left: 4px; font-variant-numeric: tabular-nums; }
@media (max-width: 400px) { #hudConn .mp-conn-label { display: none; } #hudConn .mp-conn-ms { margin-left: 0; color: var(--text); } }
@keyframes connPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* --- countdown 3 / 2 / 1 / GO ---------------------------------------------------------------- */
.mp-banner--count {
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 4.2rem;
  font-weight: 900;
  line-height: 1;
  padding: 8px 34px;
  background: rgba(10, 13, 18, 0.55);
  border-color: transparent;
  animation: countPop 0.5s ease-out;
}
.mp-banner--go { color: var(--accent); animation: countGo 0.7s ease-out forwards; }
@keyframes countPop { from { transform: translate(-50%, -50%) scale(1.7); opacity: 0.15; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@keyframes countGo { 0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0.2; } 30% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1.3); opacity: 0; } }

/* --- join / leave toast (never blocks input) ------------------------------------------------------ */
.mp-toast {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  max-width: 90%;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(10, 13, 18, 0.92);
  border: 1px solid var(--panel-border);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  animation: toastIn 0.2s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* --- lobby cards ---------------------------------------------------------------------------------- */
.lobby-card { border-left: 4px solid #2a3442; }
.lobby-card[data-state="waiting"] { border-left-color: var(--accent); }
.lobby-card[data-state="countdown"] { border-left-color: #ffcf4d; }
.lobby-card[data-state="running"] { border-left-color: var(--danger); }
.lobby-card[data-state="full"] { border-left-color: #4a5566; }
.lobby-card:not(.lobby-card--full):hover { border-color: rgba(255, 255, 255, 0.22); border-left-color: inherit; }
.lobby-players { font-size: 1.05rem; }
.lobby-state { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.lobby-state::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.lobby-card[data-state="countdown"] .lobby-state { color: #ffcf4d; }
.lobby-card[data-state="countdown"] .lobby-state::before { background: #ffcf4d; animation: connPulse 1s ease-in-out infinite; }
.lobby-card[data-state="running"] .lobby-state { color: #ff8a8a; }
.lobby-card[data-state="running"] .lobby-state::before { background: var(--danger); }
.lobby-card[data-state="full"] .lobby-state { color: var(--text-dim); }
.lobby-card[data-state="full"] .lobby-state::before { background: #4a5566; }
.lobby-card--full .lobby-name { color: var(--text-dim); }
.lobby-join.is-joining { position: relative; color: transparent; pointer-events: none; }
.lobby-join.is-joining::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(5, 19, 10, 0.35);
  border-top-color: #05130a;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- waiting room ------------------------------------------------------------------------------------ */
.lobby-countdown {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: #1c242e;
  border: 1px solid rgba(255, 207, 77, 0.35);
  border-radius: 12px;
  padding: 12px 14px;
}
.lobby-countdown-num { font-size: 3rem; font-weight: 900; line-height: 1; color: #ffcf4d; font-variant-numeric: tabular-nums; }
.lobby-countdown-label { font-size: 0.8rem; color: var(--text-dim); }
.lobby-progress { width: 100%; height: 6px; border-radius: 3px; background: #2a3442; overflow: hidden; }
.lobby-progress i { display: block; height: 100%; width: 100%; background: #ffcf4d; transition: width 0.3s linear; }
.player-row--new { animation: rowIn 0.6s ease-out; }
@keyframes rowIn { from { background: rgba(62, 224, 138, 0.35); transform: translateX(-6px); } to { background: #1c242e; transform: none; } }

/* --- results ------------------------------------------------------------------------------------------- */
.player-row--winner { border-color: rgba(255, 210, 63, 0.7); background: linear-gradient(90deg, rgba(255, 210, 63, 0.12), #1c242e 60%); }
.rank { min-width: 34px; font-size: 1.05rem; }
.standing-main { display: flex; flex: 1; min-width: 0; flex-direction: column; text-align: left; gap: 1px; }
.standing-main .player-name { flex: none; }
.standing-stats { font-size: 0.72rem; color: var(--text-dim); white-space: normal; }
.result-actions .btn { min-height: 52px; font-size: 1.1rem; }

@media (prefers-reduced-motion: reduce) {
  .mp-banner--count, .mp-banner--go, .mp-toast, .player-row--new, .mp-conn--pending .mp-conn-dot,
  .lobby-card[data-state="countdown"] .lobby-state::before, .lobby-join.is-joining::after { animation: none; }
}

/* Smooth hand-over between multiplayer screens (multiplayer only; single-player is untouched). */
#lobbyBrowserScreen:not(.hidden),
#lobbyScreen:not(.hidden),
#mpResultsScreen:not(.hidden),
#gameScreen.mp-mode:not(.hidden) { animation: screenIn 0.2s ease-out; }
@keyframes screenIn { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  #lobbyBrowserScreen:not(.hidden), #lobbyScreen:not(.hidden), #mpResultsScreen:not(.hidden), #gameScreen.mp-mode:not(.hidden) { animation: none; }
}

/* Touch targets: in-game HUD buttons and Boost never drop below 44px, in any orientation. */
#gameScreen .hud .btn-ghost { min-width: 44px; min-height: 44px; }
#gameScreen .btn-boost { min-height: 44px; }

/* ===== Profile + progression ============================================================================ */

.xp-bar {
  display: block;
  height: 12px;
  background: #0f151c;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  overflow: hidden;
}
.xp-bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #5db3ff);
  border-radius: inherit;
  transition: width 0.5s ease-out;
}
.xp-bar--sm { height: 8px; }

/* main-menu card */
.profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 380px;
  min-height: 64px;
  margin: 0 auto 14px;
  padding: 10px 12px;
  background: #1c242e;
  border: 1px solid #2a5566;
  border-radius: 12px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.profile-card:hover { border-color: var(--accent); }
.profile-card:active { transform: scale(0.98); }
.profile-card:focus-visible, .skin-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.profile-card-avatar {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  object-fit: contain;
  border-radius: 10px;
  background: #0a0d12;
  border: 1px solid var(--panel-border);
}
.profile-card-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.profile-card-label { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-dim); }
.profile-card-name { font-size: 1.02rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-card-level { display: flex; justify-content: space-between; gap: 8px; font-size: 0.75rem; color: var(--text-dim); }
.profile-card-level b { color: var(--accent); }
.profile-card-chev { font-size: 1.7rem; line-height: 1; color: var(--text-dim); }

/* profile screen */
.profile-panel { max-width: 440px; padding: 20px 18px 10px; }
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; text-align: left; }
.profile-avatar {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  object-fit: contain;
  border-radius: 14px;
  background: #0a0d12;
  border: 1px solid var(--panel-border);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}
.profile-id { min-width: 0; }
.profile-name { margin: 0; font-size: 1.6rem; font-weight: 800; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-level { color: var(--text-dim); font-weight: 700; }
.profile-level b { color: var(--accent); font-size: 1.25rem; }
.xp-caption { display: flex; justify-content: space-between; gap: 8px; margin: 6px 2px 12px; font-size: 0.75rem; color: var(--text-dim); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-cell {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  background: #1c242e;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}
.stat-cell b { font-size: 1.1rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-cell span { font-size: 0.58rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }
.profile-skin-line {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: #1c242e;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  text-align: left;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.profile-skin-text strong { display: block; color: var(--text); font-size: 0.95rem; }
.profile-recent { display: block; margin-top: 2px; color: var(--accent); font-weight: 700; }
.profile-actions { display: flex; gap: 10px; margin-top: 12px; }
.profile-actions .btn { flex: 1; min-height: 48px; padding: 12px 8px; text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.95rem; }
.profile-name-form { margin-top: 12px; text-align: left; }
.profile-name-form .section-label { display: block; margin-bottom: 6px; }
.profile-name-row { display: flex; flex-wrap: wrap; gap: 8px; }
.profile-name-row .text-input { flex: 1 1 100%; }
.profile-name-row .btn { flex: 1 1 0; min-height: 48px; padding: 12px 8px; }
.profile-name-form .mp-status { min-height: 1.3em; margin: 6px 0 0; }
#profileSkins .mp-status { margin: 0 0 4px; }
#profileSkinGrid { margin-top: 12px; }

/* skins: locked state */
.skin-card { position: relative; }
.skin-card.locked { border-style: dashed; opacity: 0.85; }
.skin-card.locked .skin-preview { filter: grayscale(1) brightness(0.45); }
.skin-card.locked .skin-card-name { color: var(--text-dim); }
.skin-lock { font-size: 0.62rem; font-weight: 800; letter-spacing: 0.02em; color: #ffcf4d; }
.skin-lock:empty { display: none; }
.skin-card.is-new { border-color: var(--accent); }
.skin-card.is-new .skin-lock { color: var(--accent); }

.profile-toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 420px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(10, 13, 18, 0.96);
  border: 1px solid #2a5566;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  animation: toastIn 0.2s ease-out;
}

/* live XP feed (over the arena; never intercepts touches) */
.xp-feed {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 14px;
  border-radius: 999px;
  background: rgba(10, 13, 18, 0.88);
  border: 1px solid rgba(62, 224, 138, 0.45);
  pointer-events: none;
  white-space: nowrap;
}
.xp-feed--in { animation: xpPop 0.25s ease-out; }
.xp-feed-xp { color: var(--accent); font-weight: 800; font-size: 0.95rem; line-height: 1.2; }
.xp-feed-what { font-size: 0.62rem; color: var(--text-dim); line-height: 1.2; }
@keyframes xpPop { from { opacity: 0.2; transform: translateX(-50%) translateY(6px) scale(0.9); } to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); } }

/* "XP earned" breakdown on result screens */
.rewards {
  margin: 14px 0 16px;
  padding: 12px 14px;
  background: #1c242e;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  text-align: left;
}
.rewards-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.rewards-title { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-dim); }
.rewards-total { font-size: 1.5rem; color: var(--accent); }
.rewards-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 3px; font-size: 0.85rem; }
.rewards-list li { display: flex; justify-content: space-between; gap: 10px; color: var(--text-dim); }
.rewards-list li b { color: var(--text); }
.rewards-empty { margin: 0; font-size: 0.82rem; color: var(--text-dim); }
.rewards-badge { display: inline-block; margin-bottom: 8px; padding: 3px 10px; border-radius: 999px; background: rgba(255, 207, 77, 0.14); color: #ffcf4d; font-size: 0.75rem; font-weight: 800; }
.rewards-level { display: flex; align-items: center; gap: 10px; }
.rewards-level .xp-bar { flex: 1; }
.rewards-level-label { font-size: 0.8rem; font-weight: 800; color: var(--accent); white-space: nowrap; }

/* level up */
.levelup-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(4, 6, 9, 0.78);
  overflow-y: auto;
}
.levelup-card {
  width: 100%;
  max-width: 340px;
  margin: auto;
  padding: 22px 20px 18px;
  text-align: center;
  background: var(--panel);
  border: 1px solid #ffcf4d;
  border-radius: var(--radius);
  box-shadow: 0 0 40px rgba(255, 207, 77, 0.25), 0 20px 60px rgba(0, 0, 0, 0.6);
}
.levelup-card--in { animation: levelPop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1); }
.levelup-card .levelup-ok { margin-top: 14px; min-height: 48px; min-width: 140px; }
.levelup-title { font-size: 1.05rem; font-weight: 800; letter-spacing: 0.18em; color: #ffcf4d; }
.levelup-number { font-size: 4.2rem; font-weight: 800; line-height: 1.05; color: #fff; text-shadow: 0 0 24px rgba(255, 207, 77, 0.55); }
.levelup-sub { font-size: 0.85rem; font-weight: 700; color: var(--text-dim); }
.levelup-unlock { margin-top: 10px; font-size: 0.9rem; font-weight: 700; color: var(--accent); }
.levelup-skins { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 8px; }
.levelup-skin { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.levelup-skin-preview { width: 84px; height: 60px; border-radius: 8px; }
.levelup-skin-name { font-size: 0.75rem; font-weight: 700; }
.levelup-banner {
  margin-top: 10px;
  padding: 10px 12px;
  text-align: center;
  background: #10161d;
  border: 1px solid #ffcf4d;
  border-radius: 12px;
  animation: levelPop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.levelup-banner .levelup-number { font-size: 2.6rem; }
@keyframes levelPop { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: scale(1); } }

@media (max-width: 400px) {
  .profile-panel { padding: 16px 12px 6px; }
  .profile-avatar { width: 60px; height: 60px; }
  .profile-name { font-size: 1.35rem; }
  .profile-head { margin-bottom: 8px; }
  .stat-grid { gap: 6px; margin-bottom: 8px; }
  .stat-cell { padding: 6px 2px; }
  .stat-cell b { font-size: 1rem; }
  .xp-caption { margin-bottom: 8px; }
  .profile-actions { margin-top: 8px; }
  .levelup-number { font-size: 3.6rem; }
}

/* Short landscape phones: identity + bar on the left, statistics on the right, no scrolling. */
@media (orientation: landscape) and (max-height: 500px) {
  #profileScreen .profile-panel { max-width: 760px; padding: 12px 16px 6px; }
  #profileMain {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    grid-template-areas: "head stats" "bar stats" "cap stats" "skin stats" "act back";
    column-gap: 16px;
    align-items: start;
  }
  #profileMain > .profile-head { grid-area: head; margin-bottom: 4px; }
  #profileMain > .xp-bar { grid-area: bar; }
  #profileMain > .xp-caption { grid-area: cap; margin-bottom: 6px; }
  #profileMain > .stat-grid { grid-area: stats; margin: 0; }
  #profileMain > .profile-skin-line { grid-area: skin; padding: 4px 10px; }
  #profileMain > .profile-actions, #profileMain > .profile-name-form { grid-area: act; margin-top: 6px; }
  #profileMain > .btn-link { grid-area: back; justify-self: end; align-self: end; }
  #profileMain .profile-avatar { width: 52px; height: 52px; }
  #profileMain .profile-name { font-size: 1.3rem; }
  #profileMain .mp-skin-preview { width: 56px; height: 40px; }
  .levelup-number { font-size: 3rem; }
}

@media (prefers-reduced-motion: reduce) {
  .xp-bar > i { transition: none; }
  .xp-feed--in, .levelup-card--in, .levelup-banner { animation: none; }
}

#profileMain.is-editing .profile-skin-line { display: none; }

/* Compact, non-blocking level-up card on the multiplayer results screen. */
.levelup-banner .levelup-title, .levelup-banner .levelup-number { display: inline-block; vertical-align: middle; margin: 0 6px; }
.levelup-banner .levelup-title { font-size: 0.95rem; }
.levelup-banner .levelup-number { font-size: 2rem; }
.levelup-banner .levelup-unlock { margin-top: 4px; font-size: 0.82rem; }
.levelup-banner .levelup-skin-preview { width: 56px; height: 40px; }
.levelup-banner .levelup-skins { margin-top: 4px; gap: 8px; }

/* Results actions stay reachable when a long results list scrolls. */
#mpResultsScreen .result-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: 10px 0 4px;
  background: linear-gradient(to bottom, rgba(21, 27, 35, 0), var(--panel) 32%);
}

/* ===== Power-ups: compact status chips (inside the action row, above Boost; reserved height so nothing shifts) ===== */
.fx-hud {
  flex: 0 0 100%;
  min-height: 24px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.fx-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  background: #10161d;
  border: 1px solid var(--panel-border);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  line-height: 1.35;
  animation: fxIn 0.18s ease-out;
}
.fx-chip[data-type="speed"] { color: #ffe14d; border-color: rgba(255, 225, 77, 0.6); }
.fx-chip[data-type="magnet"] { color: #ff8b8b; border-color: rgba(255, 107, 107, 0.6); }
.fx-chip[data-type="shield"] { color: #8cc8ff; border-color: rgba(93, 179, 255, 0.7); }
.fx-time { min-width: 2.4em; text-align: left; font-variant-numeric: tabular-nums; }
.fx-time:empty { display: none; }
@keyframes fxIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 400px) { .fx-label { display: none; } .fx-chip { padding: 2px 8px; } }
@media (prefers-reduced-motion: reduce) { .fx-chip { animation: none; } }

/* Short portrait phones (e.g. 320x568): the status row costs ~24px, so win the room back from padding and
   gaps - the arena keeps the width it had before power-ups. Everything stays >= 44px. */
@media (max-height: 620px) and (orientation: portrait) {
  #gameScreen {
    gap: 6px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  #gameScreen .action-row { gap: 3px; }
  #gameScreen .fx-hud { min-height: 20px; }
  #gameScreen .btn-boost { padding-top: 10px; padding-bottom: 10px; }
}

/* While editing the nickname on a short phone the statistics step aside so the form never needs scrolling. */
@media (max-height: 640px) and (orientation: portrait) {
  #profileMain.is-editing .stat-grid { display: none; }
}

/* Landscape phones: the status chips stack in the Boost column (never widening it, so the arena keeps its size). */
@media (orientation: landscape) and (max-height: 500px) {
  #gameScreen .action-row { flex-direction: column; align-items: center; gap: 4px; }
  #gameScreen .fx-hud { flex: 0 0 auto; flex-direction: column; flex-wrap: nowrap; gap: 3px; min-height: 24px; }
  #gameScreen .fx-label { display: none; }
}

/* Desktop / tablets: plenty of width, so the chips sit beside the Boost button instead of costing arena height. */
@media (min-width: 700px) and (min-height: 501px) {
  #gameScreen .action-row { position: relative; flex-wrap: nowrap; }
  #gameScreen .fx-hud {
    position: absolute;
    left: calc(50% + 110px);
    top: 50%;
    transform: translateY(-50%);
    min-height: 0;
    flex: none;
    justify-content: flex-start;
    flex-wrap: nowrap;
    white-space: nowrap;
  }
}

/* ===== Maps: the lobby's map shown as a small tag next to its name ===== */
.lobby-map {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: middle;
  color: var(--text-dim);
}
.lobby-map[data-map="blocks"] { color: #8fa6c6; border-color: rgba(143, 166, 198, 0.55); }
.lobby-map[data-map="arena"] { color: #ffcf4d; border-color: rgba(255, 207, 77, 0.5); }

/* ===== Match events ===== */
.event-toast {
  position: absolute;
  top: 54px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  max-width: 94%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 8px;
  border-radius: 999px;
  background: rgba(10, 13, 18, 0.93);
  border: 1px solid rgba(143, 166, 198, 0.55);
  pointer-events: none;
  animation: eventIn 0.22s ease-out;
}
.event-toast-icon { font-size: 1.05rem; line-height: 1; flex-shrink: 0; }
.event-toast-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.event-toast-title { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: #cfe0f5; }
.event-toast-detail { font-size: 0.68rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-toast--mine { border-color: var(--accent); }
.event-toast--mine .event-toast-title { color: var(--accent); }
/* Major events (First Blood, Giant Snake, Comeback) are bigger and glow */
.event-toast--major {
  padding: 6px 16px 6px 10px;
  border-color: #ffcf4d;
  box-shadow: 0 0 18px rgba(255, 207, 77, 0.35);
  animation: eventMajorIn 0.32s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.event-toast--major .event-toast-icon { font-size: 1.35rem; }
.event-toast--major .event-toast-title { font-size: 0.86rem; color: #ffcf4d; }
.event-toast--major .event-toast-detail { font-size: 0.74rem; color: var(--text); }
@keyframes eventIn { from { opacity: 0; transform: translateX(-50%) translateY(-6px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes eventMajorIn { from { opacity: 0; transform: translateX(-50%) scale(0.85); } to { opacity: 1; transform: translateX(-50%) scale(1); } }

.event-summary {
  margin: 12px 0 6px;
  padding: 10px 12px;
  background: #1c242e;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  text-align: left;
}
.event-summary-title { margin-bottom: 8px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-dim); }
.event-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.event-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 3px 10px 3px 7px;
  border-radius: 999px;
  background: #10161d;
  border: 1px solid var(--panel-border);
  font-size: 0.74rem;
}
.event-chip-name { font-weight: 800; }
.event-chip-who { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-chip--mine { border-color: var(--accent); }
.event-chip--mine .event-chip-who { color: var(--accent); font-weight: 700; }
.event-chip--major .event-chip-name { color: #ffcf4d; }

@media (prefers-reduced-motion: reduce) { .event-toast, .event-toast--major { animation: none; } }
