html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: #000;
  font-family: Arial, sans-serif;
  color: #fff;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  opacity: 1;
  transition: opacity 200ms ease;
}

.screen.is-hidden {
  opacity: 0;
  pointer-events: none;
}

/* Suppress transitions during first render to prevent visual glitches */
html.ui-initializing .start-menu-btn {
  transition: none !important;
}

@keyframes dd-shake {
  0%   { translate: 0 0; }
  20%  { translate: -3px 2px; }
  40%  { translate: 3px -2px; }
  60%  { translate: -2px 3px; }
  80%  { translate: 2px -1px; }
  100% { translate: 0 0; }
}

.shake {
  animation: dd-shake 140ms linear;
}

.enemy-hit {
  filter: brightness(2) contrast(1.2);
  transition: filter 0ms;
}

@keyframes dd-score-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.score-pop {
  animation: dd-score-pop 180ms ease-out;
}

main {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Screen wrappers: fullscreen flex containers that center the stage shell */
#game-intro,
#game-container,
#game-end {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#game-container,
#game-end {
  display: none;
}

/* Scaled stage shell: computed size for correct flex centering */
.stage-shell {
  width: var(--stage-width, 500px);
  height: var(--stage-height, 600px);
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  outline: 2px solid #111;
  outline-offset: -2px;
}

/* Stage base: 500x600 internal coords, transform-scaled to fit */
.stage-base {
  width: 500px;
  height: 600px;
  position: relative;
  transform: scale(var(--stage-scale, 1));
  transform-origin: 0 0;
  background-image: url("../images/background-light.png");
  background-size: cover;
  background-position: center;
  overflow: hidden;
  touch-action: manipulation;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

/* Dark theme background applied via data attribute for instant render */
html[data-theme="dark"] .stage-base {
  background-image: url("../images/background-dark.png");
}

/* Gameplay area: disable touch defaults to prevent scroll/zoom during play */
#game-screen {
  touch-action: none;
}

/* Game entity images: block drag, select, callout */
.stage-base img {
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  pointer-events: none;
}

.start-panel {
  position: absolute;
  inset: 16px;

  padding: 16px 24px;
  border-radius: 10px;
  box-sizing: border-box;

  background: rgba(10, 10, 20, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.6);

  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.start-panel h1 {
  margin: 10px 0 4px;
  font-size: 32px;
  letter-spacing: 1px;
}

.start-panel h2 {
  margin: 0 0 0px;
  font-size: 16px;
  font-weight: 400;
  color: #cbd5f5;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.controls-title {
  margin: 0 0 10px 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #e5e7eb;
  opacity: 0.85;
}

/* Key/badge indicators for controls */
.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  min-width: 86px;
  padding: 4px 10px;
  border-radius: 6px;
  box-sizing: border-box;

  border: 1px solid rgba(148, 163, 184, 0.9);
  background: rgba(15, 23, 42, 0.8);

  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.action {
  color: #e5e7eb;
  font-size: 13px;
}

#start-button {
  margin-top: 8px;
}

.end-panel {
  position: absolute;
  inset: 16px;

  padding: 16px 24px;
  border-radius: 10px;
  box-sizing: border-box;

  background: rgba(10, 10, 20, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.6);

  text-align: center;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.end-panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: 1px;
}

.final-score-text {
  margin: 0 0 10px;
  font-size: 20px;
  font-weight: 700;
  color: #fbbf24;
  text-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

/* Compact mode for Game Over screen to fit without scroll */
.final-score-text.compact {
  margin: 0 0 6px;
  font-size: 18px;
}

#restart-button {
  margin-top: 4px;
  padding: 10px 22px;
  border-radius: 999px;
  border: none;

  background: linear-gradient(135deg, #22c55e, #3b82f6);
  color: #0b1020;

  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  letter-spacing: 0.5px;

  transition: transform 0.1s ease, box-shadow 0.15s ease, filter 0.15s ease;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.7);
}

#restart-button:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.9);
}

#restart-button:active {
  transform: translateY(1px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.7);
}

#hud {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: bold;
  color: white;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
  z-index: 10;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 40px;
}

/* Subtle separator between HUD items */
.hud-item + .hud-item {
  padding-left: 10px;
  border-left: 1px solid rgba(255, 255, 255, 0.15);
}

.hud-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  opacity: 0.55;
  line-height: 1;
  margin-bottom: 2px;
}

.hud-value {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
}

/* Prevent text selection on rapid tap */
#hud,
#hud span {
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
}

#game-logo {
  width: 380px;
  max-width: 100%;
  margin: 2px auto 0 auto;
  display: block;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.6));
}

.enemy {
  transition: filter 0ms;
}

.heart-powerup {
  z-index: 5;
  filter: drop-shadow(0 0 6px rgba(239, 68, 68, 0.6));
  animation: heart-bob 1.2s ease-in-out infinite;
}

@keyframes heart-bob {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.1); }
}

#hud-score #score {
  color: #fbbf24;
  text-shadow: 0 0 8px rgba(251, 191, 36, 0.5), 0 0 2px rgba(251, 191, 36, 0.3);
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: center;
}

.heart {
  display: inline-block;
  font-style: normal;
  font-size: 15px;
  line-height: 1.1;
  margin: 0 1px;
  vertical-align: middle;
  transition: transform 150ms ease, opacity 150ms ease;
}

.heart.full {
  color: #ef4444;
  text-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

.heart.empty {
  color: rgba(255, 255, 255, 0.25);
  text-shadow: none;
}

#level-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  white-space: nowrap;
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #fff;
  text-shadow:
    0 0 20px rgba(249, 115, 22, 0.8),
    0 0 40px rgba(236, 72, 153, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  transition: opacity 300ms ease-out, transform 300ms ease-out;
  will-change: transform, opacity;
}

#level-indicator.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#damage-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at center, rgba(239, 68, 68, 0.2) 0%, rgba(239, 68, 68, 0.35) 100%);
  opacity: 0;
  pointer-events: none;
  z-index: 15;
  transition: opacity 80ms ease-out;
}

#damage-overlay.flash {
  opacity: 1;
}

.start-panel h1,
.end-panel h1 {
  text-shadow: 0 2px 12px rgba(249, 115, 22, 0.4);
}

.end-panel h2 {
  margin: 6px 0 4px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: #e5e7eb;
  opacity: 0.9;
}

.leaderboard-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin-bottom: 8px;
}

#high-scores,
#start-high-scores {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: 380px;
  margin-left: auto;
  margin-right: auto;
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 36px 1fr 68px 48px;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  margin-bottom: 3px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
  min-height: 28px;
  line-height: 1.2;
  box-sizing: border-box;
}

/* Pending entry row */
.leaderboard-item.pending-row {
  grid-template-columns: 36px 1fr 68px 48px;
}

.leaderboard-item:last-child {
  margin-bottom: 0;
}

.rank {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 34px;
  font-size: 12px;
  color: #94a3b8;
  font-weight: 600;
  text-align: left;
}

/* Star icon for top 3 */
.rank-star {
  font-size: 11px;
  line-height: 1;
}

.leaderboard-item.top-1 .rank-star {
  color: #fbbf24;
}

.leaderboard-item.top-2 .rank-star {
  color: #c0c7d0;
  opacity: 0.9;
}

.leaderboard-item.top-3 .rank-star {
  color: #d4a574;
  opacity: 0.7;
}

.leaderboard-score {
  font-size: 13px;
  font-weight: 700;
  color: #e5e7eb;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.leaderboard-level {
  font-size: 10px;
  color: #64748b;
  font-weight: 600;
  text-align: right;
}

/* Top 3 highlights */
.leaderboard-item.top-1 {
  background: rgba(251, 191, 36, 0.12);
}
.leaderboard-item.top-1 .rank,
.leaderboard-item.top-1 .leaderboard-score {
  color: #fbbf24;
}
.leaderboard-item.top-1 .leaderboard-level {
  color: #d4a517;
}

.leaderboard-item.top-2 {
  background: rgba(192, 199, 208, 0.12);
}
.leaderboard-item.top-2 .rank,
.leaderboard-item.top-2 .leaderboard-score {
  color: #d1d5db;
}
.leaderboard-item.top-2 .leaderboard-level {
  color: #a8b0bc;
}

.leaderboard-item.top-3 {
  background: rgba(180, 130, 100, 0.1);
}
.leaderboard-item.top-3 .rank,
.leaderboard-item.top-3 .leaderboard-score {
  color: #d4a574;
}
.leaderboard-item.top-3 .leaderboard-level {
  color: #a67c52;
}

/* Stars rendered in JS */

.leaderboard-item.top-1,
.leaderboard-item.top-2,
.leaderboard-item.top-3 {
  font-weight: 700;
}

.top10-message {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: #22c55e;
  text-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

/* Compact mode for congratulations message */
.top10-message.compact {
  margin: 0 0 4px;
  font-size: 16px;
  max-width: calc(100% - 24px);
  padding: 0 12px;
  overflow-wrap: anywhere;
  box-sizing: border-box;
  text-align: center;
}

.top10-message.hidden {
  display: none;
}

/* Non-qualifying game over message */
.top10-message.miss {
  color: #94a3b8;
  text-shadow: none;
}

.leaderboard-name {
  font-size: 12px;
  font-weight: 600;
  color: #cbd5e1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-item.top-1 .leaderboard-name {
  color: #fbbf24;
}
.leaderboard-item.top-2 .leaderboard-name {
  color: #d1d5db;
}
.leaderboard-item.top-3 .leaderboard-name {
  color: #d4a574;
}

.pending-name-input {
  width: 12ch;
  max-width: 100%;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(251, 191, 36, 0.5);
  background: rgba(15, 23, 42, 0.95);
  color: #fff;
  font-size: 12px;
  font-family: 'Courier New', Courier, monospace;
  font-weight: 600;
  outline: none;
  transition: border-color 0.15s ease;
  box-sizing: border-box;
  height: 22px;
  line-height: 1.2;
}

.pending-name-input:focus {
  border-color: #fbbf24;
}

.pending-name-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
  font-weight: 400;
}

/* Game Over two-row button layout */
.gameover-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding-top: 6px;
}

.action-row {
  display: flex;
  justify-content: center;
  gap: 8px;
}

/* Top row always reserves space to prevent Restart/Quit jump */
.action-row-top {
  min-height: 32px;
}

/* Uniform Game Over button sizing */
.gameover-btn {
  min-width: 120px;
  padding: 7px 14px !important;
  font-size: 12px !important;
  margin-top: 0 !important;
  box-sizing: border-box;
  text-align: center;
}

/* Save/Discard buttons */
.end-btn {
  margin-top: 4px;
  padding: 10px 22px;
  border-radius: 999px;
  border: none;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: transform 0.1s ease, box-shadow 0.15s ease, filter 0.15s ease;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.7);
}

.end-btn.save {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #0b1020;
}

.end-btn.discard {
  background: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.end-btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.9);
}

.end-btn:active {
  transform: translateY(1px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.7);
}

.end-btn.hidden {
  visibility: hidden;
  pointer-events: none;
}

/* Disabled state for buttons */
#restart-button:disabled,
#gameover-quit-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.5);
  transform: none !important;
}

#gameover-quit-button {
  margin-top: 4px;
  padding: 10px 22px;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: transform 0.1s ease, box-shadow 0.15s ease, filter 0.15s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#gameover-quit-button:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

#gameover-quit-button:active {
  transform: translateY(1px);
}

/* Button focus states for accessibility */
.start-menu-btn:focus-visible,
#restart-button:focus-visible,
#gameover-quit-button:focus-visible,
.end-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 3px;
}

#pause-menu-button {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 23, 42, 0.85);
  color: #f9fafb;
  font-family: Arial, sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: none;
  cursor: pointer;
  opacity: 0.7;
  z-index: 11;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
  transition: opacity 0.15s ease, transform 0.1s ease, background 0.15s ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

#pause-menu-button:hover {
  opacity: 1;
  background: rgba(15, 23, 42, 0.95);
  transform: translateY(-1px);
}

#pause-menu-button:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.6);
  outline-offset: 2px;
}

#pause-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

#pause-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

#pause-card {
  width: 260px;
  padding: 22px 24px;
  border-radius: 12px;
  background: rgba(10, 10, 20, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#pause-card h2 {
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: 2px;
  text-shadow: 0 2px 12px rgba(249, 115, 22, 0.4);
}

.pause-btn {
  width: 100%;
  padding: 10px 20px;
  border-radius: 999px;
  border: none;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.pause-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: 3px;
}

#resume-button {
  background: linear-gradient(135deg, #22c55e, #3b82f6);
  color: #0b1020;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.5);
}

#resume-button:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

#options-button {
  background: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#options-button:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

#pause-restart-button {
  background: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#pause-restart-button:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

#quit-button {
  background: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#quit-button:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

#pause-main,
#pause-options {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.pause-section-hidden {
  display: none !important;
}

#pause-options-nav {
  display: flex;
  gap: 8px;
  width: 100%;
}

.pause-nav-btn {
  flex: 1;
}

.pause-nav-resume {
  background: linear-gradient(135deg, #22c55e, #3b82f6);
  color: #0b1020;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.5);
}

.pause-nav-resume:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.pause-option-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #cbd5e1;
  font-size: 13px;
  box-shadow: none;
}

.pause-option-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  transform: translateY(-1px);
}

/* Start menu sub-panels */
.start-menu-btn {
  margin-top: 4px;
  padding: 10px 22px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #f97316, #ec4899);
  color: #0b1020;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease, filter 0.15s ease;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.7);
  width: 75%;
}

.start-menu-btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.9);
}

.start-menu-btn:active {
  transform: translateY(1px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.7);
}

/* Secondary start buttons (Options, High Scores, Instructions) */
.start-secondary-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.start-secondary-btn:hover {
  background: rgba(255, 255, 255, 0.17);
  filter: none;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

.start-back-btn {
  margin-top: 14px;
  background: rgba(255, 255, 255, 0.08);
  color: #94a3b8;
  font-size: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.start-subpanel .start-back-btn {
  margin-top: auto;
  padding: 10px 22px;
  font-size: 12px;
  width: 75%;
}

.start-back-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #e5e7eb;
}

.start-panel.hidden {
  display: none !important;
}

.start-sub-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}

/* Instructions panel layout */
.instructions-content {
  align-items: center;
  text-align: center;
  padding: 0 12px;
}

.instructions-intro {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.5;
  color: #cbd5e1;
  opacity: 0.9;
}

.instructions-nowrap {
  white-space: nowrap;
}

.instructions-columns {
  display: grid;
  grid-template-columns: auto auto;
  gap: 16px;
  width: fit-content;
  margin: 0 auto;
  align-items: start;
}

.instructions-col {
  text-align: left;
}

.instructions-col .controls-title {
  margin-bottom: 8px;
}

.instructions-col .control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  width: 100%;
}

/* About panel layout */
.about-content {
  align-items: center;
  text-align: center;
  padding: 0 12px;
}

.about-description {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.5;
  color: #cbd5e1;
  opacity: 0.9;
}

.about-links {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.about-link {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: #e5e7eb;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: 0.5px;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
  width: 75%;
  box-sizing: border-box;
}

.about-link:hover {
  background: rgba(255, 255, 255, 0.17);
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
}

.about-link:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 3px;
}

.start-leaderboard-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 8px 0;
  width: 100%;
}

#start-highscores-panel .start-leaderboard-container {
  margin: 2px 0;
  flex: 1;
  min-height: 0;
}

/* Start menu high scores sizing */
#start-highscores-panel #start-high-scores {
  max-width: 420px;
}

#start-highscores-panel .leaderboard-item {
  min-height: 30px;
  padding: 4px 10px;
}

#start-highscores-panel .rank,
#start-highscores-panel .leaderboard-name,
#start-highscores-panel .leaderboard-score,
#start-highscores-panel .leaderboard-level {
  font-size: 13px;
}

#start-highscores-panel .leaderboard-level {
  white-space: nowrap;
}

#start-highscores-panel .leaderboard-item {
  grid-template-columns: 36px 1fr 68px 56px;
}

/* Override the start panel for subpanels to fill game area better */
.start-subpanel {
  overflow: hidden;
}

/* High-score overlay */
#highscore-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  white-space: nowrap;
  text-align: center;
  max-width: calc(100% - 32px);
  padding: 0 16px;
  box-sizing: border-box;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: #fff;
  text-shadow:
    0 0 20px rgba(251, 191, 36, 0.8),
    0 0 40px rgba(251, 191, 36, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  z-index: 60;
  transition: opacity 400ms ease-out, transform 400ms ease-out;
  will-change: transform, opacity;
}

#highscore-indicator.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#highscore-indicator.top1 {
  font-size: 19px;
  letter-spacing: 0.5px;
  color: #fffbe6;
  text-shadow:
    0 0 8px rgba(251, 191, 36, 1),
    0 0 24px rgba(251, 191, 36, 0.7),
    0 0 48px rgba(249, 115, 22, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.7);
  animation: hs-pulse 700ms ease-in-out 2;
}

@keyframes hs-pulse {
  0%   { transform: translate(-50%, -50%) scale(1); }
  50%  { transform: translate(-50%, -50%) scale(1.05); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* Empty leaderboard row placeholder */
.leaderboard-item.empty-row {
  opacity: 0.35;
}

/* Touch controls overlay: invisible layer split into 3 fixed zones */
#touch-controls-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  pointer-events: none;
}

/* Enable touch only on mobile / touch devices */
@media (pointer: coarse) {
  #touch-controls-layer {
    pointer-events: auto;
  }
}

.touch-zone {
  flex: 1;
  height: 100%;
}
