:root {
  --field-bg: #8f7a66;
  --grid-bg: rgba(238, 228, 218, 0.35);
  --text-dark: #4e4033;
  --text-light: #ffffff;
  --bg-color: #faf8ef;
  --accent-color: #f67c5f;
  --accent-color-hover: #e56b4e;
  
  /* Fluid calculations for absolute responsiveness */
  --grid-width: min(90vw, 490px);
  --grid-cells: 4; /* Dynamic cell count (3, 4, 5), updated by JS */
  --grid-spacing: 12px;
  --tile-size: calc((var(--grid-width) - (var(--grid-spacing) * (var(--grid-cells) + 1))) / var(--grid-cells));
  --border-radius: 12px;
  --shadow-premium: 0 10px 30px -10px rgba(78, 64, 51, 0.15);
  --shadow-active: 0 15px 35px -5px rgba(246, 124, 95, 0.25);
}

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top, #fafaf6 0%, #f3ede2 100%);
  color: var(--text-dark);
  font-family: "Outfit", "Clear Sans", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  box-sizing: border-box;
}

*, *:before, *:after {
  box-sizing: inherit;
}

.container {
  width: var(--grid-width);
  margin: 0 auto;
  padding: 10px 0;
  display: flex;
  flex-direction: column;
}



/* Heading / Scores */
.heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 20px;
  width: 100%;
}

.heading-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.title {
  font-size: 72px;
  font-weight: 800;
  margin: 0;
  line-height: 0.85;
  letter-spacing: -2px;
  color: var(--text-dark);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.title-duel {
  font-size: 20px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-light);
  background: var(--accent-color);
  padding: 2px 8px;
  border-radius: 6px;
  letter-spacing: 0.5px;
  transform: translateY(-12px);
  box-shadow: 0 4px 10px rgba(246, 124, 95, 0.2);
}

.scores-container {
  display: flex;
  gap: 8px;
}

.score-container, .best-container {
  position: relative;
  background: var(--field-bg);
  padding: 5px 15px;
  font-size: 22px;
  height: 55px;
  font-weight: bold;
  border-radius: 6px;
  color: white;
  text-align: center;
  min-width: 80px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  line-height: 1.1;
}

.score-container::before, .best-container::before {
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  text-transform: uppercase;
  font-size: 10px;
  color: #eee4da;
  text-align: center;
  font-weight: bold;
}

.score-container::before {
  content: "Score";
}

.best-container::before {
  content: "Best";
}

.score-addition {
  position: absolute;
  right: 15px;
  bottom: 30px;
  font-size: 22px;
  line-height: 22px;
  font-weight: bold;
  color: rgba(119, 110, 101, 0.9);
  z-index: 100;
  animation: float-up 600ms ease-in-out;
  animation-fill-mode: both;
}

@keyframes float-up {
  0% {
    opacity: 0;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-50px);
  }
}

/* Above Game Info & Buttons */
.above-game {
  display: flex;
  justify-content: center;
  text-align: center;
  margin-bottom: 20px;
  width: 100%;
}

.game-intro {
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-dark);
}

.mode-label {
  display: inline-block;
  font-size: 13px;
  color: var(--accent-color);
  font-weight: 700;
  margin-top: 4px;
  background: rgba(246, 124, 95, 0.1);
  padding: 2px 8px;
  border-radius: 20px;
}

.controls-buttons {
  display: flex;
  gap: 8px;
}

.restart-button {
  background: var(--field-bg);
  border-radius: 8px;
  padding: 8px 16px;
  text-decoration: none;
  color: var(--text-light);
  font-weight: bold;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 4px 0 #8f7a66, 0 6px 15px rgba(0,0,0,0.15);
  transform: translateY(0);
}

.restart-button:hover {
  background: #a38c76;
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #8f7a66, 0 8px 20px rgba(0,0,0,0.2);
}

.restart-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #8f7a66, 0 4px 10px rgba(0,0,0,0.1);
}

/* Game Board Container */
.game-container {
  position: relative;
  width: var(--grid-width);
  height: var(--grid-width);
  background: #a99684;
  border-radius: var(--border-radius);
  padding: var(--grid-spacing);
  box-sizing: border-box;
  touch-action: none;
  box-shadow: inset 0 8px 15px rgba(0,0,0,0.15), 0 0 0 6px #bcac9b, 0 26px 40px -15px rgba(78, 64, 51, 0.3);
}

/* Start/Difficulty Selector Overlay */
.start-menu {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: #faf8ef;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 40px 20px;
  text-align: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: fade-in 400ms ease;
}

.menu-title {
  font-size: 80px;
  font-weight: 800;
  color: var(--text-dark);
  margin: 20px 0 25px 0;
  letter-spacing: -3px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.menu-title .title-duel {
  font-size: 24px;
  transform: translateY(-16px);
}

.menu-logo-wrapper {
  position: relative;
  width: 65%;
  max-width: 400px;
  margin-top: 60px;
  margin-bottom: 20px;
  overflow: hidden;
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.menu-logo-wrapper:hover {
  transform: scale(1.04);
}

.menu-logo-wrapper::after {
  content: '';
  position: absolute;
  top: 0;
  left: -200%;
  width: 50%;
  height: 100%;
  background: linear-gradient(
    to right, 
    rgba(255, 255, 255, 0) 0%, 
    rgba(255, 255, 255, 0.45) 50%, 
    rgba(255, 255, 255, 0) 100%
  );
  transform: skewX(-35deg);
  pointer-events: none;
  animation: shine-sweep 8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.menu-logo {
  width: 100%;
  height: auto;
  opacity: 0.9;
  transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
  filter: drop-shadow(0 2px 5px rgba(78, 64, 51, 0.1));
  animation: logo-glow 3s ease-in-out infinite alternate;
}

.menu-logo-wrapper:hover .menu-logo {
  opacity: 1;
  filter: drop-shadow(0 8px 25px rgba(246, 124, 95, 0.25));
}

@keyframes shine-sweep {
  0% {
    left: -200%;
  }
  60% {
    left: 200%;
  }
  100% {
    left: 200%;
  }
}

@keyframes logo-glow {
  0% {
    filter: drop-shadow(0 2px 5px rgba(78, 64, 51, 0.1));
  }
  100% {
    filter: drop-shadow(0 4px 15px rgba(246, 124, 95, 0.2)) saturate(1.1);
  }
}

.difficulty-options {
  display: flex;
  flex-direction: row;
  gap: 8px;
  width: 100%;
  max-width: 380px;
  margin-bottom: 25px;
}

.diff-btn {
  flex: 1;
  background: rgba(238, 228, 218, 0.8);
  border: none;
  border-radius: 10px;
  padding: 12px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--text-dark);
  box-shadow: 0 4px 0 #cdc1b4, 0 6px 15px rgba(0,0,0,0.1);
  transform: translateY(0);
}

.diff-btn:hover {
  background: rgba(238, 228, 218, 1);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #cdc1b4, 0 8px 20px rgba(0,0,0,0.15);
}

.diff-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #cdc1b4, 0 4px 10px rgba(0,0,0,0.1);
}

.diff-btn.active {
  background: var(--field-bg);
  color: var(--text-light);
  box-shadow: 0 4px 0 #8f7a66, 0 6px 15px rgba(0,0,0,0.2);
}

.diff-btn.active:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #8f7a66, 0 4px 10px rgba(0,0,0,0.1);
}

.diff-title {
  font-size: 18px;
  font-weight: bold;
}

.diff-desc {
  font-size: 11px;
  opacity: 0.8;
  margin-top: 2px;
}

.start-btn {
  background: var(--accent-color);
  color: var(--text-light);
  border: none;
  border-radius: 12px;
  padding: 18px 45px;
  font-size: 20px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 6px 0 #7a6857, 0 10px 20px rgba(0,0,0,0.15);
  transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateY(0);
}

.start-btn:hover {
  background: var(--accent-color-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #6e5b4c, 0 12px 25px rgba(0,0,0,0.2);
}

.start-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #7a6857, 0 4px 10px rgba(0,0,0,0.1);
}

/* Overlay message (Game Over / Win) */
.game-message {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(238, 228, 218, 0.73);
  z-index: 10;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  animation: fade-in 800ms ease;
  border-radius: var(--border-radius);
}

.game-message p {
  font-size: 60px;
  font-weight: 800;
  height: 60px;
  line-height: 60px;
  margin: 0 0 20px 0;
  color: var(--text-dark);
  text-shadow: 0 4px 10px rgba(0,0,0,0.15), 0 1px 0 rgba(255,255,255,0.5);
}

.game-message .lower {
  display: flex;
  gap: 10px;
}

.game-message button {
  background: #8f7a66;
  border-radius: 8px;
  padding: 0 20px;
  text-decoration: none;
  color: #f9f6f2;
  height: 40px;
  line-height: 40px;
  font-weight: bold;
  border: none;
  cursor: pointer;
  font-size: 15px;
  transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 0 #6e5b4c, 0 6px 15px rgba(0,0,0,0.15);
  transform: translateY(0);
}

.game-message button:hover {
  background: #a38c76;
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #8f7a66, 0 8px 20px rgba(0,0,0,0.2);
}

.game-message button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #6e5b4c, 0 4px 10px rgba(0,0,0,0.1);
}

.game-message.game-won {
  background: rgba(237, 194, 46, 0.5);
  color: #f9f6f2;
}

.game-message.game-won .keep-playing-button {
  display: inline-block;
}

.game-message .keep-playing-button {
  display: none;
}

@keyframes fade-in {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

/* Background grid (CSS Grid, cell dimensions handled via JS variables) */
.grid-container {
  position: absolute;
  top: 0;
  left: 0;
  padding: var(--grid-spacing);
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(var(--grid-cells), var(--tile-size));
  grid-template-rows: repeat(var(--grid-cells), var(--tile-size));
  gap: var(--grid-spacing);
}

.grid-cell {
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: var(--border-radius);
  background: var(--grid-bg);
}

/* Tiles container and elements */
.tile-container {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
}

/* Parent tile ONLY handles movement/translations */
.tile {
  position: absolute;
  width: var(--tile-size);
  height: var(--tile-size);
  transition: transform 100ms ease-in-out;
  z-index: 10;
}

/* Child tile-inner handles styling, colors, and scaling animations */
.tile-inner {
  width: 100%;
  height: 100%;
  border-radius: var(--border-radius);
  font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
  transition: background-color 100ms ease-in-out;
  box-shadow: 0 4px 0 rgba(0,0,0,0.1), inset 0 2px 0 rgba(255,255,255,0.4);
}

.tile-2 .tile-inner {
  background: #eee4da;
  color: var(--text-dark);
  font-size: calc(var(--tile-size) * 0.55);
  box-shadow: 0 4px 0 #d6ccbd, inset 0 2px 0 rgba(255,255,255,0.8);
}
.tile-4 .tile-inner {
  background: #ede0c8;
  color: var(--text-dark);
  font-size: calc(var(--tile-size) * 0.55);
  box-shadow: 0 4px 0 #d1c7b1, inset 0 2px 0 rgba(255,255,255,0.8);
}
.tile-8 .tile-inner {
  background: #f2b179;
  color: var(--text-light);
  font-size: calc(var(--tile-size) * 0.55);
  box-shadow: 0 4px 0 #c99364, inset 0 2px 0 rgba(255,255,255,0.6);
}
.tile-16 .tile-inner {
  background: #f59563;
  color: var(--text-light);
  font-size: calc(var(--tile-size) * 0.5);
  box-shadow: 0 4px 0 #cc7c52, inset 0 2px 0 rgba(255,255,255,0.6);
}
.tile-32 .tile-inner {
  background: #f67c5f;
  color: var(--text-light);
  font-size: calc(var(--tile-size) * 0.5);
  box-shadow: 0 4px 0 #ce674e, inset 0 2px 0 rgba(255,255,255,0.6);
}
.tile-64 .tile-inner {
  background: #f65e3b;
  color: var(--text-light);
  font-size: calc(var(--tile-size) * 0.5);
  box-shadow: 0 4px 0 #cc4e31, inset 0 2px 0 rgba(255,255,255,0.6);
}
.tile-128 .tile-inner {
  background: #edcf72;
  color: var(--text-light);
  font-size: calc(var(--tile-size) * 0.4);
  box-shadow: 0 4px 0 #c8af60, inset 0 2px 0 rgba(255,255,255,0.6), 0 0 30px 10px rgba(243, 215, 116, 0.2381);
}
.tile-256 .tile-inner {
  background: #edcc61;
  color: var(--text-light);
  font-size: calc(var(--tile-size) * 0.4);
  box-shadow: 0 4px 0 #c7ab51, inset 0 2px 0 rgba(255,255,255,0.6), 0 0 30px 10px rgba(243, 215, 116, 0.31746);
}
.tile-512 .tile-inner {
  background: #edc850;
  color: var(--text-light);
  font-size: calc(var(--tile-size) * 0.4);
  box-shadow: 0 4px 0 #c9a944, inset 0 2px 0 rgba(255,255,255,0.6), 0 0 30px 10px rgba(243, 215, 116, 0.39683);
}
.tile-1024 .tile-inner {
  background: #edc53f;
  color: var(--text-light);
  font-size: calc(var(--tile-size) * 0.32);
  box-shadow: 0 4px 0 #cba535, inset 0 2px 0 rgba(255,255,255,0.6), 0 0 30px 10px rgba(243, 215, 116, 0.47619);
}
.tile-2048 .tile-inner {
  background: #edc22e;
  color: var(--text-light);
  font-size: calc(var(--tile-size) * 0.32);
  box-shadow: 0 4px 0 #cca627, inset 0 2px 0 rgba(255,255,255,0.6), 0 0 30px 10px rgba(243, 215, 116, 0.55556);
}
/* Super tiles */
.tile-super .tile-inner {
  background: #3c3a32;
  color: var(--text-light);
  font-size: calc(var(--tile-size) * 0.3);
  box-shadow: 0 4px 0 #2a2823, inset 0 2px 0 rgba(255,255,255,0.2);
}

/* Scaling animations on tile-inner (decoupled from parent translation) */
.tile-new .tile-inner {
  animation: appear 200ms ease;
  animation-fill-mode: backwards;
}

.tile-merged {
  z-index: 20;
}

.tile-merged .tile-inner {
  animation: pop 200ms ease 100ms;
  animation-fill-mode: backwards;
}

@keyframes appear {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pop {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

/* Explanations text */
.game-explanation {
  margin-top: 25px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-dark);
  text-align: left;
}

/* Power-ups Section Styling */
.powerups-container {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 15px;
}

.powerup-button {
  flex: 1;
  background: #8f7a66;
  color: var(--text-light);
  border: none;
  border-radius: var(--border-radius);
  padding: 10px 5px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
  font-family: inherit;
  box-shadow: 0 4px 0 #6e5b4c, 0 6px 15px rgba(0,0,0,0.15);
  transform: translateY(0);
}

.powerup-button:hover:not(:disabled) {
  background: #a38c76;
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #8f7a66, 0 8px 20px rgba(0,0,0,0.2);
}

.powerup-button:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #6e5b4c, 0 4px 10px rgba(0,0,0,0.1);
}

.powerup-button:disabled {
  background: #dcd0c4;
  color: #a4998e;
  cursor: not-allowed;
  box-shadow: 0 2px 0 #c2b6a9;
  transform: translateY(2px);
}

.powerup-button.active {
  background: #f67c5f;
  box-shadow: 0 4px 0 #d96146, 0 6px 15px rgba(246, 124, 95, 0.3);
}

.powerup-button.active:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #d96146, 0 4px 10px rgba(246, 124, 95, 0.2);
}

.powerup-icon {
  font-size: 20px;
  font-weight: bold;
}

.powerup-name {
  font-size: 12px;
  font-weight: bold;
}

.powerup-status {
  margin-top: 15px;
  font-size: 13px;
  font-weight: bold;
  color: #8f7a66;
  text-align: center;
  background: #eee4da;
  padding: 8px;
  border-radius: 4px;
  transition: all 150ms ease;
}

.powerup-status.active-mode {
  background: #f67c5f;
  color: white;
  animation: pulse-status 1s infinite alternate;
}

@keyframes pulse-status {
  0% { transform: scale(1); }
  100% { transform: scale(1.02); }
}

/* Highlight Selected Tile */
.tile-selected .tile-inner {
  outline: 4px solid #f67c5f;
  outline-offset: -2px;
  box-shadow: 0 0 15px 5px rgba(246, 124, 95, 0.7);
  animation: pulse-tile 800ms infinite alternate;
}

@keyframes pulse-tile {
  0% { transform: scale(1); }
  100% { transform: scale(0.95); }
}

/* Hide powerups when start menu is open */
.start-menu-open .powerups-container,
.start-menu-open .powerup-status {
  display: none !important;
}

/* Power-up visual charge indicator bars */
.powerup-charges {
  display: flex;
  gap: 3px;
  margin-top: 6px;
  width: 100%;
  max-width: 50px;
  justify-content: center;
}

.charge-bar {
  height: 3px;
  flex: 1;
  background: rgba(249, 246, 242, 0.25); /* Translucent when spent */
  border-radius: 1.5px;
  transition: background 150ms ease;
}

.charge-bar.active {
  background: var(--text-light); /* Solid color when active */
}

/* Multiplayer Layout */
#multiplayer-layout {
  width: 100%;
}

.mp-above-game {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  width: 100%;
}

.mp-title {
  font-size: 38px;
  font-weight: 800;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.mp-title .title-duel {
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 5px;
  transform: translateY(-8px);
}

.multiplayer-boards {
  display: flex;
  justify-content: center;
  gap: 30px;
  width: 100%;
}

.player-board {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Override default grid sizes for multiplayer view */
  --grid-width: min(43vw, 440px);
  --grid-spacing: 12px;
  --tile-size: calc((var(--grid-width) - (var(--grid-spacing) * (var(--grid-cells) + 1))) / var(--grid-cells));
}

.player-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: var(--grid-width);
  margin-bottom: 15px;
  background: rgba(238, 228, 218, 0.5);
  padding: 8px 15px;
  border-radius: var(--border-radius);
  box-sizing: border-box;
}

.player-header h2 {
  font-size: 16px;
  margin: 0;
  font-weight: bold;
}

.p1-board h2 {
  color: #c05c46; /* Player 1 Red Accent */
}

.p2-board h2 {
  color: #3b789e; /* Player 2 Blue Accent */
}

/* Versus Winner Overlay (Glassmorphic Backdrop) */
.versus-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(250, 248, 239, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 300ms ease-out;
}

/* Responsive Multiplayer Container sizes */
body.multiplayer-active .container {
  width: min(95vw, 1000px);
  max-width: 1000px;
}

body.multiplayer-active #singleplayer-layout {
  display: none !important;
}

body:not(.multiplayer-active) #multiplayer-layout {
  display: none !important;
}

/* Menu Redesign for Multiple Mode Boxes */
.menu-modes {
  display: flex;
  gap: 24px;
  width: 100%;
  max-width: 680px;
  margin-top: 15px;
}

@media screen and (max-width: 720px) {
  .menu-modes {
    flex-direction: column;
    gap: 20px;
    max-width: 380px;
  }
}

/* Hide 2-Player Local VS Option Card on Screen sizes below Desktop limit */
@media screen and (max-width: 680px) {
  .vs-box {
    display: none !important;
  }
  /* Hide Single Player Title inside the mode-box */
  .mode-box h3 {
    display: none !important;
  }
  /* Remove container box styles to make it look native and fit perfectly */
  .mode-box {
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
  }
  /* Stack difficulty buttons vertically */
  .difficulty-options {
    flex-direction: column !important;
    gap: 16px !important;
    width: 100% !important;
    max-width: 320px !important;
    margin-bottom: 25px !important;
  }
  .diff-btn {
    flex: none !important;
    width: 100% !important;
    padding: 18px 24px !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    border-radius: 12px !important;
  }
  .diff-title {
    font-size: 22px !important;
  }
  .diff-desc {
    margin-top: 0 !important;
    font-size: 14px !important;
  }
  .start-btn {
    width: 100% !important;
    max-width: 320px !important;
    padding: 18px 20px !important;
    font-size: 20px !important;
    border-radius: 12px !important;
  }
  /* Push logo down and title up inside vertical layout */
  .menu-title {
    margin: 40px 0 50px 0 !important;
  }
  .menu-logo-wrapper {
    margin-top: 80px !important;
    margin-bottom: 40px !important;
  }
}

/* Mobile Portrait Styling for Single Player Header */
@media screen and (max-width: 520px) {
  .heading {
    flex-direction: column !important;
    align-items: center !important;
    gap: 8px !important;
    margin-bottom: 10px !important;
  }
  .heading-right {
    align-items: center !important;
    width: 100% !important;
    gap: 6px !important;
  }
  .scores-container {
    width: 100% !important;
    justify-content: center !important;
    gap: 6px !important;
  }
  .score-container, .best-container {
    flex: 1 !important;
    height: 45px !important;
    font-size: 16px !important;
    padding: 2px 8px !important;
  }
  .score-container::before, .best-container::before {
    font-size: 8px !important;
    top: 3px !important;
  }
  .controls-buttons {
    width: 100% !important;
    justify-content: center !important;
    gap: 6px !important;
  }
  .restart-button {
    flex: 1 !important;
    padding: 6px 12px !important;
    font-size: 12px !important;
  }
  .title {
    font-size: 42px !important;
    line-height: 1 !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
  }
  .title-duel {
    font-size: 16px !important;
    transform: translateY(-6px) !important;
  }
  .above-game {
    margin-bottom: 10px !important;
  }
  .game-intro {
    font-size: 12px !important;
    line-height: 1.3 !important;
  }
  .powerups-container {
    margin-top: 10px !important;
    gap: 6px !important;
  }
  .powerup-button {
    padding: 6px 3px !important;
  }
  .powerup-icon {
    font-size: 16px !important;
  }
  .powerup-name {
    font-size: 10px !important;
  }
  .powerup-status {
    margin-top: 10px !important;
    padding: 6px !important;
    font-size: 11px !important;
  }
}

/* Centering on tall desktop viewports */
@media screen and (min-height: 750px) {
  .start-menu {
    justify-content: center;
  }
}

.mode-box {
  flex: 1;
  background: #ffffff;
  border-radius: 16px;
  padding: 30px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 8px 0 rgba(143, 122, 102, 0.1), 0 10px 30px -10px rgba(78, 64, 51, 0.15);
  transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid rgba(143, 122, 102, 0.05);
  transform: translateY(0);
}

.mode-box:hover {
  transform: translateY(-6px);
  box-shadow: 0 14px 0 rgba(143, 122, 102, 0.08), 0 20px 40px -10px rgba(78, 64, 51, 0.12);
  border-color: rgba(143, 122, 102, 0.1);
}

.mode-box h3 {
  font-size: 22px;
  margin-top: 0;
  margin-bottom: 15px;
  font-weight: 800;
  color: var(--text-dark);
}

.vs-box {
  background: #ffffff;
  border: 1px solid rgba(246, 124, 95, 0.1);
}

.vs-box:hover {
  border-color: rgba(246, 124, 95, 0.3);
  box-shadow: 0 20px 40px -10px rgba(246, 124, 95, 0.1);
}

.vs-box h3 {
  color: var(--accent-color);
}

.vs-desc {
  font-size: 13px;
  line-height: 1.7;
  color: #776e65;
  margin-bottom: 25px;
}

.vs-btn {
  background: var(--accent-color);
}

/* Mobile Warning screen details */
.mobile-warning {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: var(--bg-color);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  text-align: center;
}

.warning-content {
  max-width: 450px;
}

.warning-content h2 {
  font-size: 28px;
  margin-bottom: 15px;
}

.warning-content p {
  font-size: 16px;
  line-height: 1.6;
  margin-bottom: 25px;
  color: var(--text-dark);
}

/* Media Query to show screen warning when multiplayer is active */
@media screen and (max-width: 680px) {
  body.multiplayer-active .mobile-warning {
    display: flex !important;
  }
}

/* Versus Mode Round Tracker Header */
.round-tracker {
  display: flex;
  background: var(--field-bg);
  padding: 10px 24px;
  border-radius: 10px;
  color: var(--text-light);
  gap: 20px;
  align-items: center;
  font-weight: bold;
  box-shadow: 0 10px 25px -10px rgba(143, 122, 102, 0.3);
}

.tracker-item {
  font-size: 15px;
}

.p1-score-tracker {
  color: #ffbba6; /* Light Red for P1 */
}

.p2-score-tracker {
  color: #bce3ff; /* Light Blue for P2 */
}

.round-number {
  background: rgba(255, 255, 255, 0.15);
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Versus Card overlay details */
.versus-card {
  background: #ffffff;
  border: 2px solid rgba(143, 122, 102, 0.05);
  border-radius: 20px;
  padding: 45px 40px;
  max-width: 450px;
  width: 90%;
  box-shadow: 0 10px 0 rgba(143, 122, 102, 0.1), 0 30px 70px -15px rgba(78, 64, 51, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: scale(0.95);
  animation: pop-card 300ms cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes pop-card {
  to {
    transform: scale(1);
  }
}

.versus-card h2 {
  font-size: 12px;
  font-weight: 800;
  color: #a39485;
  margin: 0 0 10px 0;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-align: center;
}

.versus-card h1 {
  font-size: 38px;
  font-weight: 800;
  color: var(--text-dark);
  margin: 0 0 12px 0;
  line-height: 1.2;
  text-align: center;
  text-shadow: 0 4px 10px rgba(0,0,0,0.1), 0 1px 0 rgba(255,255,255,0.8);
}

.versus-result-subtitle {
  font-size: 17px;
  color: #776e65;
  margin: 0 0 30px 0;
  font-weight: bold;
  opacity: 0.9;
  text-align: center;
}

.versus-overlay-actions {
  display: flex;
  gap: 15px;
}

/* Keyboard key styling */
.player-title-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
}

.player-title-box h2 {
  margin: 0;
  line-height: 1;
}

.key {
  display: inline-block;
  background-color: #eee4da;
  color: #776e65;
  border-radius: 4px;
  padding: 2px 6px;
  font-family: monospace;
  font-weight: bold;
  border-bottom: 2px solid #cdc1b4;
  margin: 0 2px;
  font-size: 0.9em;
  line-height: 1.2;
}

.player-controls-info {
  font-size: 13px;
  color: #776e65;
  margin-top: 8px;
  font-weight: normal;
}

@media screen and (max-width: 520px) {
  .game-explanation {
    display: none !important;
  }
}

.player-board .game-message p {
  font-size: 32px;
  height: auto;
  line-height: 1.2;
}

/* Responsiveness optimizations for shorter screen/iframe heights (like 950x534) */
@media screen and (max-height: 560px) and (min-width: 680px) {
  html, body {
    align-items: center !important;
    padding: 0 !important;
    height: 100% !important;
    min-height: 100% !important;
    overflow: hidden !important;
  }

  /* Scale down grid sizes to fit strictly within 534px height */
  :root {
    --grid-width: min(90vw, 340px);
  }
  
  .player-board {
    --grid-width: min(42vw, 290px);
  }
  
  body:not(.multiplayer-active) .container {
    width: min(95vw, 540px) !important;
    max-width: 540px !important;
    padding: 0 !important;
    margin: 0 auto !important;
  }

  body.multiplayer-active .container {
    width: min(95vw, 1000px) !important;
    max-width: 1000px !important;
    padding: 0 !important;
    margin: 0 auto !important;
  }

  #singleplayer-layout {
    display: grid !important;
    grid-template-columns: 340px 160px !important;
    justify-content: center !important;
    gap: 15px !important;
    width: 100% !important;
  }
  
  .heading {
    grid-column: 1 / span 2 !important;
    margin-bottom: 0 !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
  }
  
  .title {
    font-size: 32px !important;
  }
  
  .title-duel {
    font-size: 13px !important;
    transform: translateY(-5px) !important;
    padding: 1px 6px !important;
  }

  .heading-right {
    flex-direction: row !important;
    align-items: center !important;
    gap: 10px !important;
  }
  
  .scores-container {
    gap: 5px !important;
  }
  
  .score-container, .best-container {
    height: 38px !important;
    font-size: 13px !important;
    min-width: 60px !important;
    padding: 2px 4px !important;
  }
  
  .score-container::before, .best-container::before {
    font-size: 8px !important;
    top: 3px !important;
  }

  .controls-buttons {
    gap: 5px !important;
  }

  .restart-button {
    padding: 6px 12px !important;
    font-size: 12px !important;
  }
  
  .above-game {
    display: none !important;
  }
  
  .game-container {
    grid-column: 1 !important;
    grid-row: 2 / span 2 !important;
    margin: 0 !important;
  }
  
  .powerup-status {
    grid-column: 2 !important;
    grid-row: 2 !important;
    margin-top: 0 !important;
    padding: 6px !important;
    font-size: 11px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
  
  .powerups-container {
    grid-column: 2 !important;
    grid-row: 3 !important;
    margin-top: 0 !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    gap: 8px !important;
    height: 100% !important;
  }
  
  .powerup-button {
    flex: 1 !important;
    padding: 8px 5px !important;
    flex-direction: row !important;
    justify-content: flex-start !important;
    align-items: center !important;
    gap: 8px !important;
    width: 100% !important;
    border-radius: 8px !important;
  }
  
  .powerup-icon {
    font-size: 16px !important;
    margin-left: 6px !important;
  }
  
  .powerup-name {
    font-size: 11px !important;
  }
  
  .powerup-charges {
    margin-top: 0 !important;
    margin-left: auto !important;
    margin-right: 6px !important;
    max-width: 30px !important;
  }

  .game-explanation {
    display: none !important;
  }
  
  /* Multiplayer adjustments */
  .mp-above-game {
    margin-bottom: 8px !important;
  }
  
  .mp-title {
    font-size: 28px !important;
  }
  
  .mp-title .title-duel {
    font-size: 12px !important;
    transform: translateY(-4px) !important;
  }
  
  .round-tracker {
    padding: 5px 12px !important;
    gap: 10px !important;
    border-radius: 6px !important;
  }
  
  .tracker-item {
    font-size: 12px !important;
  }
  
  .player-header {
    padding: 4px 10px !important;
    margin-bottom: 8px !important;
    border-radius: 6px !important;
  }
  
  .player-header h2 {
    font-size: 13px !important;
  }
  
  .player-controls-info {
    font-size: 10px !important;
    margin-top: 2px !important;
  }
  
  .player-board .score-container {
    height: 25px !important;
    min-width: 50px !important;
    font-size: 14px !important;
    padding: 0 5px !important;
    justify-content: center !important;
    align-items: center !important;
  }
  
  .player-board .score-container::before {
    display: none !important;
  }
  
  /* Menu Start Screen adjustments for 534px height (keeping it clean and not too small) */
  .start-menu {
    padding: 15px 10px !important;
    justify-content: center !important;
    overflow: hidden !important;
  }
  
  .menu-title {
    font-size: 52px !important;
    margin: 0 0 15px 0 !important;
  }
  
  .menu-title .title-duel {
    font-size: 16px !important;
    transform: translateY(-10px) !important;
  }
  
  .menu-modes {
    gap: 16px !important;
    margin-top: 10px !important;
  }
  
  .mode-box {
    padding: 15px 12px !important;
    border-radius: 12px !important;
  }
  
  .mode-box h3 {
    font-size: 16px !important;
    margin-bottom: 10px !important;
  }
  
  .difficulty-options {
    margin-bottom: 15px !important;
    gap: 6px !important;
  }
  
  .diff-btn {
    padding: 8px 4px !important;
    border-radius: 8px !important;
  }
  
  .diff-title {
    font-size: 14px !important;
  }
  
  .diff-desc {
    font-size: 9px !important;
    margin-top: 2px !important;
  }
  
  .start-btn {
    padding: 10px 30px !important;
    font-size: 15px !important;
    border-radius: 10px !important;
    box-shadow: 0 4px 0 #7a6857, 0 6px 12px rgba(0,0,0,0.15) !important;
  }
  
  .menu-logo-wrapper {
    margin-top: 20px !important;
    margin-bottom: 0px !important;
    width: 150px !important;
  }
}
