:root {
  --play-board-size: 400px;
  --joystick-size: 173px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  font-family: 'Arial', sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  overflow-x: hidden;
}

#app {
  width: 100%;
  max-width: min(600px, 100%);
  padding: clamp(6px, 2vw, 20px) 0;
}

.game-wrapper {
  width: 100%;
  max-width: min(430px, 100%);
  margin: 0 auto;
}

.game-container {
  text-align: center;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: clamp(12px, 3vw, 30px) clamp(8px, 2.5vw, 12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  position: relative;
}

.play-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.5vh, 12px);
  width: 100%;
  min-width: 0;
}

.play-header {
  display: grid;
  grid-template-columns: minmax(40px, 1fr) auto minmax(40px, 1fr);
  align-items: center;
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  gap: 4px;
}

.play-header__spacer {
  width: 40px;
  min-width: 40px;
  height: 40px;
  pointer-events: none;
}

.game-container h1,
.play-title {
  margin: 0;
  font-size: clamp(1.55rem, 6.5vw, 2.5em);
  line-height: 1.15;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.play-header .play-title {
  grid-column: 2;
  justify-self: center;
  text-align: center;
  min-width: 0;
}

.game-container.play-viewport--compact h1,
.game-container.play-viewport--compact .play-title {
  font-size: clamp(1.35rem, 5.5vw, 1.85rem);
}

.game-container.play-viewport--compact .play-header {
  min-height: 40px;
}

.score-board {
  margin: 0;
  width: 100%;
  box-sizing: border-box;
}

/* Most players are solo: one wide strip, no cramped multi-column strip */
.score-board--solo {
  display: flex;
  justify-content: center;
}

.score-solo-panel {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  width: 100%;
  max-width: min(400px, 100%);
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 14px 18px;
  gap: 0;
}

.score-solo-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  text-align: center;
}

.score-solo-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  opacity: 0.88;
}

.score-solo-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.score-solo-value {
  font-size: clamp(1.85rem, 7vw, 2.35rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.score-solo-best-value {
  font-size: clamp(1.15rem, 4.5vw, 1.5rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  opacity: 0.95;
}

.score-solo-divider {
  width: 1px;
  align-self: stretch;
  min-height: 2.5rem;
  margin: 2px 14px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.28);
}

.score-solo-out {
  font-size: 0.8rem;
}

.score-solo-play-again {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(78, 205, 196, 0.85);
  background: rgba(78, 205, 196, 0.22);
  color: #eafffb;
  cursor: pointer;
  line-height: 1.2;
  white-space: nowrap;
  flex-shrink: 0;
}

.score-solo-play-again:hover {
  background: rgba(78, 205, 196, 0.38);
  transform: none;
}

.restart-hint-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  cursor: pointer;
  padding: 12px;
  box-sizing: border-box;
}

.restart-hint-overlay.show {
  display: flex;
}

.restart-hint-overlay__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 100%;
  text-align: center;
  pointer-events: none;
}

.restart-hint-overlay__message {
  margin: 0;
  font-size: clamp(0.95rem, 3.8vw, 1.15rem);
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  line-height: 1.35;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.restart-hint-overlay__view-result {
  pointer-events: auto;
  font-size: 0.82rem;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.45);
  color: rgba(255, 255, 255, 0.92);
  cursor: pointer;
}

.restart-hint-overlay__view-result:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: none;
}

.score-board--multi {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 8px;
  font-size: clamp(0.8rem, 2.8vw, 1.05rem);
}

.score-item {
  background: rgba(255, 255, 255, 0.2);
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  text-align: center;
}

.score-item-title {
  font-size: 0.82em;
  font-weight: 600;
  opacity: 0.95;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.score-item-current {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 6px;
  line-height: 1.15;
}

.score-item-current .score-value {
  font-weight: 700;
  font-size: 1.15em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.score-item-high {
  font-size: 0.78em;
  opacity: 0.92;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
}

.score-item-high .score-high-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.score-item .eliminated {
  color: #ff6b6b;
  font-size: 0.72em;
  font-weight: 600;
  white-space: nowrap;
}

.game-area {
  position: relative;
  margin: 0 auto;
  display: block;
  width: var(--play-board-size);
  max-width: 100%;
  aspect-ratio: 1;
  flex-shrink: 0;
}

#phaser-game {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
}

#phaser-game canvas {
  display: block;
  margin: 0 auto;
}

.pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  cursor: pointer;
  pointer-events: none;
}

.pause-overlay.show {
  display: flex;
  pointer-events: auto;
}

.pause-overlay-content {
  text-align: center;
  padding: 24px;
}

.pause-overlay-title {
  font-size: 2.5rem;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  margin-bottom: 12px;
}

.pause-overlay-hint {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.85);
  margin: 0;
}

.replay-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(78, 205, 196, 0.9);
  color: #1a1a2e;
  font-size: 0.85em;
  font-weight: bold;
  pointer-events: none;
}

.jump-in-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 0.85em;
  font-weight: bold;
  cursor: pointer;
}

.jump-in-btn:hover {
  background: rgba(255, 255, 255, 0.35);
}

.hamburger-btn {
  grid-column: 3;
  justify-self: end;
  position: relative;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  cursor: pointer;
  color: #fff;
  z-index: 2;
  flex-shrink: 0;
  box-sizing: border-box;
  transition: background 0.2s ease;
}

.hamburger-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.hamburger-line {
  display: block;
  width: 22px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  transition: transform 0.25s ease, opacity 0.2s ease;
}

.hamburger-btn[aria-expanded="true"] .hamburger-line:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

.hamburger-btn[aria-expanded="true"] .hamburger-line:nth-child(2) {
  opacity: 0;
}

.hamburger-btn[aria-expanded="true"] .hamburger-line:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  z-index: 10;
}

.menu-overlay.open {
  opacity: 1;
  visibility: visible;
}

.menu-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(320px, 90vw);
  max-width: 100%;
  height: 100%;
  background: rgba(30, 30, 50, 0.98);
  backdrop-filter: blur(12px);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
  transform: translateX(100%);
  transition: transform 0.3s ease, visibility 0.3s ease;
  z-index: 11;
  overflow-y: auto;
  visibility: hidden;
}

.menu-drawer.open {
  transform: translateX(0);
  visibility: visible;
}

.menu-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.menu-close-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.menu-content {
  padding: 24px 20px;
  padding-top: 60px;
  position: relative;
}

.menu-content .control-instructions,
.menu-content .game-instructions {
  text-align: left;
}

.control-instructions {
  font-size: 0.85em;
  margin-top: 5px;
  color: rgba(255, 255, 255, 0.8);
}

.game-instructions {
  font-size: 0.85em;
  margin-top: 5px;
  color: rgba(255, 255, 255, 0.8);
}

.menu-content .options-row,
.menu-content .controls-row {
  flex-direction: column;
  align-items: stretch;
}

.saved-replays-row {
  margin-top: 10px;
}

.saved-replays-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9em;
}

.saved-replays-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.auth-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.auth-user {
  font-size: 0.95em;
  color: rgba(255, 255, 255, 0.9);
}

.auth-sign-in-btn,
.auth-sign-up-btn {
  background: rgba(78, 205, 196, 0.4);
  border-color: rgba(78, 205, 196, 0.7);
  color: #fff;
  padding: 8px 14px;
  font-size: 0.9em;
}

.auth-sign-in-btn:hover,
.auth-sign-up-btn:hover {
  background: rgba(78, 205, 196, 0.6);
}

.auth-sign-out-btn {
  background: rgba(255, 107, 107, 0.4);
  border-color: rgba(255, 107, 107, 0.7);
  color: #fff;
  padding: 8px 14px;
  font-size: 0.9em;
}

.auth-sign-out-btn:hover {
  background: rgba(255, 107, 107, 0.6);
}

.auth-modal .auth-form-content {
  min-height: auto;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.auth-overlay .modal.auth-modal {
  min-width: 0;
  width: min(100%, 360px);
  max-height: 92vh;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 320px;
  width: 100%;
}

.auth-nickname-status {
  margin: -4px 0 0;
  font-size: 0.85em;
  min-height: 1.1em;
  color: rgba(255, 255, 255, 0.75);
}

.auth-nickname-status--ok {
  color: #4ecdc4;
}

.auth-nickname-status--bad {
  color: #ff6b6b;
}

.auth-nickname-status--neutral {
  color: rgba(255, 255, 255, 0.65);
}

.auth-form label {
  display: block;
  font-size: 0.95em;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: -6px;
}

.auth-form input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 1em;
  box-sizing: border-box;
}

.auth-form input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.auth-form input:focus {
  outline: none;
  border-color: rgba(78, 205, 196, 0.8);
}

.auth-error {
  color: #ff6b6b;
  font-size: 0.9em;
  margin-bottom: 4px;
}

.auth-send-code-btn {
  margin: 0.25rem 0 0.75rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.auth-send-code-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.auth-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 6px;
}

.auth-submit {
  background: #4ecdc4;
  color: #1a1a2e;
  border: none;
  padding: 10px 20px;
  font-size: 1em;
}

.auth-submit:hover {
  background: #45b7b8;
}

.auth-switch {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  padding: 8px 0;
  font-size: 0.9em;
  text-decoration: underline;
  cursor: pointer;
}

.auth-switch:hover {
  color: #fff;
  transform: none;
}

.options-row {
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: center;
  margin-top: 15px;
  margin-bottom: 10px;
}

.options-row .button-group {
  margin-top: 0;
  flex: 1;
  max-width: 300px;
}

.controls-row {
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: center;
  margin-top: 15px;
}

.controls-row .button-group {
  margin-top: 0;
}

.button-group {
  margin-top: 15px;
}

.list-box {
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #fff !important;
  padding: 8px;
  border-radius: 8px;
  font-size: 1em;
}

.list-box option {
  color: #000;
  background: #fff;
}

button {
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  padding: 10px 20px;
  margin: 5px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1em;
  transition: all 0.3s ease;
}

button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.game-over-overlay .game-over-modal {
  text-align: center;
}

.game-over-rank {
  margin: 10px 0 4px;
  padding: 0 8px;
  font-size: clamp(0.9rem, 3.6vw, 1.05rem);
  line-height: 1.4;
  color: #d8e4ff;
  word-wrap: break-word;
}

.game-over-rank--loading {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.92rem;
}

.game-over-modal-wrap {
  position: relative;
  overflow: hidden;
}

.game-over-confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.game-over-rank__badge {
  display: block;
  font-weight: 700;
  font-size: 1.05em;
  color: #4ecdc4;
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

.game-over-rank__text {
  display: block;
}

.game-over-rank--revealed:not(.game-over-rank--loading) {
  animation: game-over-rank-reveal 0.45s ease-out both;
}

.game-over-rank--pop-best .game-over-rank__badge {
  animation: game-over-best-pop 0.55s cubic-bezier(0.34, 1.4, 0.64, 1) both;
  text-shadow: 0 0 12px rgba(78, 205, 196, 0.85), 0 0 28px rgba(102, 126, 234, 0.45);
}

.game-over-rank--tier-gold .game-over-rank__text {
  color: #ffe08a;
  text-shadow: 0 0 10px rgba(255, 215, 100, 0.5);
  animation: game-over-rank-shimmer 2.2s ease-in-out infinite;
}

.game-over-rank--tier-silver .game-over-rank__text {
  color: #e8edf5;
  text-shadow: 0 0 8px rgba(200, 210, 230, 0.45);
  animation: game-over-rank-shimmer 2.4s ease-in-out infinite;
}

.game-over-rank--tier-bronze .game-over-rank__text {
  color: #e8b08a;
  text-shadow: 0 0 8px rgba(210, 140, 90, 0.45);
  animation: game-over-rank-shimmer 2.6s ease-in-out infinite;
}

.game-over-rank--top10:not(.game-over-rank--tier-gold):not(.game-over-rank--tier-silver):not(.game-over-rank--tier-bronze)
  .game-over-rank__text {
  text-shadow: 0 0 14px rgba(102, 126, 234, 0.35);
}

@keyframes game-over-rank-reveal {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes game-over-best-pop {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  70% {
    transform: scale(1.08);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes game-over-rank-shimmer {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.15);
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-over-rank--revealed,
  .game-over-rank--pop-best .game-over-rank__badge,
  .game-over-rank--tier-gold .game-over-rank__text,
  .game-over-rank--tier-silver .game-over-rank__text,
  .game-over-rank--tier-bronze .game-over-rank__text {
    animation: none !important;
  }
}

.close-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 1.5em;
  cursor: pointer;
  padding: 0 8px;
  line-height: 1;
}

.game-over-modal .button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  justify-content: center;
  margin-top: 20px;
}

.game-over-modal .game-over-actions {
  max-width: 100%;
}

.share-score-button {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 2px solid rgba(78, 205, 196, 0.75);
}

.share-score-button:hover {
  background: rgba(78, 205, 196, 0.25);
}

.save-gif-button {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 2px solid rgba(102, 126, 234, 0.85);
}

.save-gif-button:hover:not(:disabled) {
  background: rgba(102, 126, 234, 0.28);
}

.save-gif-button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.game-over-gif-error {
  margin: 10px 0 0;
  color: #ff8a8a;
  font-size: 0.9rem;
  text-align: center;
}

.share-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 30;
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(20, 20, 35, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 0.92rem;
  max-width: min(360px, calc(100vw - 24px));
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.share-manual-overlay .share-manual-modal .header {
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.share-manual-overlay .share-manual-modal .header h2 {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.share-manual-hint {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
}

.share-manual-text {
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 0.9rem;
  resize: vertical;
}

.replay-button {
  background: #4ecdc4;
  color: white;
}

.play-again-button {
  background: #ff6b6b;
  color: white;
}

.restart-hint {
  margin-top: 10px;
  font-size: 0.9em;
  color: rgba(255, 255, 255, 0.7);
  font-style: italic;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 12px;
  box-sizing: border-box;
}

.overlay .modal {
  min-width: 0;
  width: 100%;
  max-width: min(420px, calc(100vw - 24px));
  max-height: 80vh;
  background: rgba(0, 0, 0, 0.9);
  padding: 15px;
  border-radius: 15px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  margin: 0 auto;
}

.overlay .header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 15px;
  width: 100%;
  min-width: 0;
}

.overlay .header h2 {
  margin: 0;
  color: #ff6b6b;
  flex: 1;
  min-width: 0;
  text-align: left;
  font-size: clamp(1.1rem, 5vw, 1.5rem);
  line-height: 1.2;
}

.overlay .header .close-btn {
  flex-shrink: 0;
  margin: 0;
}

.overlay .content {
  overflow-y: auto;
  min-height: 120px;
}

.overlay .empty {
  color: rgba(255, 255, 255, 0.7);
  text-align: center;
  padding: 24px;
}

.overlay .empty.error {
  color: #ff6b6b;
}

.saved-replays-sentinel {
  text-align: center;
  padding: 12px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.9em;
}

.saved-replays-sentinel.loading {
  color: rgba(255, 255, 255, 0.8);
}

.overlay .list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.overlay .item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.overlay .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 0.9em;
  color: rgba(255, 255, 255, 0.9);
}

.overlay .saved-at {
  flex-basis: 100%;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.85em;
}

.overlay .play-btn {
  background: #4ecdc4;
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9em;
}

.overlay .delete-btn {
  background: rgba(255, 107, 107, 0.8);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9em;
}

.control-type-joystick {
  display: flex;
  justify-content: center;
}

.play-joystick-host {
  width: 100%;
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

.virtual-joystick {
  position: relative;
  width: var(--joystick-size);
  height: var(--joystick-size);
  margin: 4px auto 0;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  transition: all 0.3s ease;
  overflow: hidden;
}

.joystick-divider.diagonal {
  position: absolute;
  width: 2px;
  height: 100%;
  left: 50%;
  top: 50%;
  transform-origin: center;
  background: rgba(255, 255, 255, 0.25);
  pointer-events: none;
  z-index: 1;
}

.joystick-divider.diag1 {
  transform: translate(-50%, -50%) rotate(45deg);
}

.joystick-divider.diag2 {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.joystick-sector {
  position: absolute;
  width: 50%;
  height: 50%;
  pointer-events: none;
  opacity: 0.2;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.joystick-sector.up {
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  background: rgba(100, 200, 255, 0.2);
}

.joystick-sector.down {
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  clip-path: polygon(50% 100%, 0% 0%, 100% 0%);
  background: rgba(100, 200, 255, 0.2);
}

.joystick-sector.left {
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  clip-path: polygon(0% 50%, 100% 0%, 100% 100%);
  background: rgba(100, 200, 255, 0.2);
}

.joystick-sector.right {
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  clip-path: polygon(100% 50%, 0% 0%, 0% 100%);
  background: rgba(100, 200, 255, 0.2);
}

.joystick-sector.active {
  opacity: 0.5;
  background: rgba(150, 220, 255, 0.4);
}

.joystick-handle {
  position: absolute;
  width: 40%;
  height: 40%;
  background: rgba(255, 255, 255, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s ease;
  pointer-events: none;
  top: 50%;
  left: 50%;
  margin-top: -20%;
  margin-left: -20%;
}

.joystick-direction {
  position: absolute;
  color: rgba(255, 255, 255, 0.55);
  font-size: clamp(14px, 4.5vw, 20px);
  font-weight: 700;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  line-height: 1;
  letter-spacing: 0.02em;
  pointer-events: none;
  user-select: none;
  transition: color 0.2s ease, transform 0.2s ease;
}

.joystick-direction.up {
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
}

.joystick-direction.up.active {
  color: rgba(255, 255, 255, 1);
  transform: translateX(-50%) scale(1.3);
}

.joystick-direction.down {
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
}

.joystick-direction.down.active {
  color: rgba(255, 255, 255, 1);
  transform: translateX(-50%) scale(1.3);
}

.joystick-direction.left {
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
}

.joystick-direction.left.active {
  color: rgba(255, 255, 255, 1);
  transform: translateY(-50%) scale(1.3);
}

.joystick-direction.right {
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
}

.joystick-direction.right.active {
  color: rgba(255, 255, 255, 1);
  transform: translateY(-50%) scale(1.3);
}

.game-container .controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  margin-top: 8px;
  padding: 0 0 12px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.game-container .controls--below-play {
  margin-top: clamp(10px, 2vh, 16px);
}

.game-container.play-viewport--compact .score-solo-panel {
  padding: 8px 12px;
}

.game-container.play-viewport--compact .score-solo-value {
  font-size: clamp(1.45rem, 6vw, 1.85rem);
}

.game-container.play-viewport--compact .score-solo-best-value {
  font-size: clamp(1rem, 4vw, 1.25rem);
}

.game-container.play-viewport--compact .score-solo-divider {
  min-height: 1.75rem;
  margin: 2px 10px;
}

@media (min-width: 900px) {
  body {
    align-items: center;
  }

  #app {
    padding: 20px 0;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .game-container.play-viewport--compact .play-stack {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    column-gap: 12px;
  }

  .game-container.play-viewport--compact .play-joystick-host {
    width: auto;
    flex: 0 0 var(--joystick-size);
  }
}

.leaderboard-panel {
  width: 100%;
  max-width: var(--play-board-size);
  min-width: 0;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  text-align: left;
}

.leaderboard-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 10px;
  color: rgba(255, 255, 255, 0.95);
  text-align: center;
}

.leaderboard-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  justify-content: center;
  margin-bottom: 10px;
}

.leaderboard-filters-speed-with-refresh {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
  min-width: 0;
}

.leaderboard-refresh-btn.leaderboard-page-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 14px;
  line-height: 1.2;
}


.leaderboard-filter-group {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  min-width: 0;
  max-width: 100%;
}

.leaderboard-filter-group label {
  flex-shrink: 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.75);
}

.leaderboard-filter-group .leaderboard-select {
  flex: 1 1 auto;
  min-width: 0;
}

.leaderboard-select.list-box {
  min-width: 0;
  max-width: 100%;
  font-size: 0.9em;
  padding: 6px 8px;
}

.leaderboard-table-wrap {
  overflow-x: hidden;
  max-width: 100%;
  min-width: 0;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.leaderboard-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  vertical-align: top;
}

.leaderboard-table td {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.leaderboard-table th:nth-child(1),
.leaderboard-table td:nth-child(1) {
  width: 10%;
  text-align: center;
}

.leaderboard-table th:nth-child(2),
.leaderboard-table td:nth-child(2) {
  width: 22%;
}

.leaderboard-table th:nth-child(3),
.leaderboard-table td:nth-child(3) {
  width: 14%;
  text-align: right;
}

.leaderboard-table th:nth-child(4),
.leaderboard-table td:nth-child(4) {
  width: 22%;
}

.leaderboard-table th:nth-child(5),
.leaderboard-table td:nth-child(5) {
  width: 32%;
}

.leaderboard-table th {
  color: rgba(255, 255, 255, 0.65);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.leaderboard-table tbody tr:last-child td {
  border-bottom: none;
}

.leaderboard-empty {
  text-align: center;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.85rem;
}

.leaderboard-status {
  min-height: 1.2em;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.6);
  margin: 8px 0 4px;
  text-align: center;
}

.leaderboard-pager {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.leaderboard-page-btn {
  margin: 0;
  padding: 6px 14px;
  font-size: 0.85em;
}

/* Global button:hover uses translateY; going disabled drops :hover:not(:disabled) → snap without this */
.leaderboard-page-btn:hover:not(:disabled) {
  transform: none;
}
