*,
*::before,
*::after {
  box-sizing: border-box;
}

@font-face {
  font-family: 'Jersey 10';
  src: url('fonts/jersey-10-latin-400-normal.woff2') format('woff2');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'Press Start 2P';
  src: url('fonts/press-start-2p-latin-400-normal.woff2') format('woff2');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

html,
body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  /* keep page from scrolling during play */
  height: 100%;
  width: 100%;
  font-family: 'Jersey 10', sans-serif;
  font-size: 20px;
  /* Jersey 10 is naturally small */
  background-color: black;
  display: flex;
  justify-content: center;
  align-items: center;
}

#gameShell {
  position: relative;
  width: min(100vw, calc(100dvh * 9 / 16));
  height: min(100dvh, calc(100vw * 16 / 9));
  overflow: hidden;
  flex: 0 0 auto;
}

#homeScreen,
#gameOver {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.95);
  color: #000;
  padding: 18px;
  text-align: center;
  border-radius: 0;
  border: 4px solid #000;
  width: min(calc(100% - 24px), 520px);
  max-height: calc(100% - 24px);
  overflow: auto;
  box-shadow: 7px 8px 0 rgba(0, 0, 0, 0.28);
  z-index: 10;
}

#gameOver h2 {
  font-family: 'Press Start 2P', cursive;
  color: #ee1717;
  font-size: clamp(22px, 7vw, 34px);
  line-height: 1.25;
  margin: 4px 0 18px;
}

/* Home screen is visible by default */
#homeScreen {
  display: block;
  max-width: 512px;
}

#homeScreen h2 {
  margin-bottom: 15px;
  font-family: 'Press Start 2P', cursive;
  font-size: 24px;
  line-height: 1.5;
}


/* Slightly larger base font on start popup */
#homeScreen {
  font-size: 18px;
}

#homeScreen .hidden {
  display: none;
}

.screen-title {
  margin: 4px 0 10px;
  color: #0e2851;
  font-family: 'Press Start 2P', cursive;
  font-size: clamp(15px, 4.5vw, 22px);
  line-height: 1.35;
  text-transform: uppercase;
}

.arcade-intro {
  max-width: 390px;
  margin: 0 auto 16px;
  color: #163d6e;
  font-size: clamp(20px, 5.8vw, 27px);
  line-height: 1.05;
}

.mode-actions {
  display: grid;
  gap: 10px;
}

.legal-links {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 16px;
}

.legal-links a {
  color: #163d6e;
}

#homeScreen .mode-actions button {
  min-height: 58px;
}

#homeScreen #arcadeBtn {
  background: #10a807;
  color: #fff;
  font-size: clamp(13px, 4vw, 18px);
}

#homeScreen #customBtn {
  background: #f5c542;
  color: #0e2851;
}

.custom-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}

.custom-header .screen-title {
  grid-column: 2;
  margin: 0;
}

#homeScreen .compact-action {
  grid-column: 1;
  padding: 8px 9px;
  font-size: 9px;
  white-space: nowrap;
}

/* Start popup logo */
#homeScreen .logo {
  width: min(190px, 48vw);
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto 10px;
  border-radius: 20px;
}

#homeScreen .hint {
  font-size: 18px;
  opacity: 0.8;
  margin: 6px 0 10px;
}

#homeScreen .disabled {
  opacity: 0.5;
}

/* Make labels readable on light bg */
#homeScreen label {
  color: #000;
}

/* Ops layout */
#opsGroup {
  display: grid;
  gap: 8px;
  margin-bottom: 9px;
}

#opsGroup .op-item {
  display: grid;
  gap: 5px;
  padding: 9px 11px;
  text-align: left;
  background: #f7fbff;
  border: 2px solid #163d6e;
  box-shadow: 2px 2px 0 rgba(22, 61, 110, 0.2);
}

#opsGroup .op-heading {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  line-height: 1;
}

.op-level-readout {
  color: #163d6e;
  font-size: 16px;
  white-space: nowrap;
}

#opsGroup .op-level {
  display: flex;
  align-items: center;
  justify-content: center;
}

#opsGroup .op-level-range {
  width: 100%;
  height: 24px;
  accent-color: #1677ef;
  cursor: pointer;
}

#opsGroup .op-extra {
  margin-top: 1px;
  padding: 7px 9px;
  background: #eaf4ff;
  border: 1px solid #a9c6e6;
}

#opsGroup .op-extra label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 17px;
  font-weight: 700;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: #1677ef;
  flex: 0 0 auto;
}

#timerGroup,
#lanesGroup {
  padding: 9px 11px 7px;
  background: #f7fbff;
  border: 2px solid #163d6e;
  text-align: left;
}

#lanesGroup {
  margin-top: 8px;
}

#timerGroup label,
#lanesGroup label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-weight: 700;
}

#timerGroup strong,
#lanesGroup strong {
  color: #163d6e;
  font-size: 24px;
}

#timerRange,
#lanesRange {
  width: 100%;
  height: 24px;
  accent-color: #1677ef;
  cursor: pointer;
}

/* Consistent button style */
#homeScreen button,
#gameOver button {
  font-family: 'Press Start 2P', cursive;
  font-size: 12px;
  padding: 12px 16px;
  border-radius: 0;
  border: 2px solid #000;
  background: #fff;
  color: #0e2851;
  cursor: pointer;
  text-transform: uppercase;
  margin: 0;
}

#homeScreen button:hover,
#gameOver button:hover {
  background: #000;
  color: #fff;
}

#homeScreen button:disabled {
  background: #b5b5b5 !important;
  color: #333;
  border-color: #7f7f7f;
  cursor: not-allowed;
}


#homeScreen #startBtn {
  background: #10a807;
  color: white;
  font-size: clamp(10px, 3.2vw, 16px);
  white-space: nowrap;
}

.menu-actions,
.game-over-actions,
.custom-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.menu-actions > button,
.game-over-actions > button,
.custom-actions > button {
  min-width: 0;
}

.game-over-mode {
  display: inline-block;
  margin: 0 0 8px;
  padding: 5px 8px;
  border: 2px solid #163d6e;
  color: #163d6e;
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  text-transform: uppercase;
}

#homeScreen .secondary-action {
  background: #173b6d;
  color: #fff;
  flex: 0.9;
  font-size: clamp(8px, 2.6vw, 12px);
  white-space: nowrap;
}

#homeScreen .leaderboard-action {
  background: #f5c518;
  color: #0e2851;
  flex: 1.05;
  font-size: clamp(7px, 2.25vw, 10px);
  white-space: nowrap;
}

#finalScore {
  margin: 0;
}

#finalScore .score-label {
  display: block;
  color: #163d6e;
  font-family: 'Press Start 2P', cursive;
  font-size: 15px;
  margin-bottom: 8px;
}

#finalScore .score-value {
  display: block;
  font-family: 'Press Start 2P', cursive;
  font-size: clamp(48px, 18vw, 78px);
  line-height: 1;
  margin-bottom: 18px;
}

#finalScore .best-badge {
  display: inline-block;
  padding: 9px 12px;
  border: 2px solid #163d6e;
  color: #163d6e;
  font-family: 'Press Start 2P', cursive;
  font-size: 11px;
  line-height: 1.3;
  margin-bottom: 17px;
}

#finalScore .run-summary,
#finalScore .modifier-summary {
  font-family: 'Jersey 10', sans-serif;
  display: block;
  font-size: 21px;
  font-weight: 700;
}

#finalScore .modifier-summary {
  color: #526477;
  font-size: 18px;
  font-weight: normal;
  margin-top: 4px;
}

#gameOver .game-over-actions {
  align-items: stretch;
  margin-top: 20px;
}

#gameOver .play-again-btn {
  grid-column: 1 / -1;
  background: #10a807;
  color: #fff;
  font-size: 13px;
}

#gameOver .home-btn {
  flex: 0.75;
  background: #173b6d;
  color: #fff;
  font-size: 12px;
}

#gameOver .leaderboard-action {
  flex: 1.1;
  background: #f5c518;
  color: #0e2851;
  font-size: clamp(7px, 2.2vw, 10px);
}

.score-submit-panel {
  margin-top: 16px;
  padding: 11px;
  border: 2px solid #163d6e;
  background: #f7fbff;
  text-align: left;
}

.score-submit-panel > label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #163d6e;
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  line-height: 1.4;
}

.score-submit-panel > label span {
  color: #526477;
  font-family: 'Jersey 10', sans-serif;
  font-size: 16px;
  font-weight: normal;
  text-transform: uppercase;
}

.score-submit-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  margin-top: 8px;
}

#playerNameInput {
  min-width: 0;
  width: 100%;
  padding: 9px 10px;
  border: 2px solid #163d6e;
  border-radius: 0;
  background: #fff;
  color: #0e2851;
  font: 18px 'Jersey 10', sans-serif;
}

#gameOver .save-score-btn {
  padding: 9px 10px;
  background: #10a807;
  color: #fff;
  font-size: 8px;
  line-height: 1.3;
}

#gameOver .save-score-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.score-submit-status {
  min-height: 18px;
  margin-top: 7px;
  color: #526477;
  font-size: 16px;
  line-height: 1.15;
}

.score-submit-status[data-type="success"] {
  color: #087600;
}

.score-submit-status[data-type="error"] {
  color: #b01616;
}

#gameCanvas {
  background: linear-gradient(to top, #87ceeb, #ffffff);
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  /* respond to mobile browser UI */
  touch-action: none;
  /* allow custom swipe without browser gestures */
}

/* Score overlay so it doesn't affect layout flow */
#scoreBoard {
  display: none;
  position: absolute;
  top: 6px;
  left: 8px;
  z-index: 11;
  color: #fff;
  font-family: 'Press Start 2P',
    cursive;
  font-size: 14px;
  line-height: 1.5;
  text-shadow: 2px 2px 0 #000;
}

@media (max-width: 520px), (max-height: 760px) {
  #homeScreen,
  #gameOver {
    padding: 18px;
    width: min(calc(100% - 16px), 520px);
    max-height: calc(100% - 16px);
  }

  #homeScreen {
    font-size: 16px;
  }

  #homeScreen .logo {
    width: min(125px, 38vw);
    margin-bottom: 6px;
  }

  #opsGroup {
    gap: 6px;
    margin-bottom: 7px;
  }

  #opsGroup .op-item {
    padding: 7px 9px;
    gap: 3px;
  }

  #opsGroup .op-extra {
    padding: 5px 7px;
  }

  #timerGroup,
  #lanesGroup {
    padding: 7px 9px 5px;
  }

  #lanesGroup {
    margin-top: 6px;
  }

  #homeScreen button,
  #gameOver button {
    padding: 10px 14px;
  }

  #gameOver h2 {
    margin-bottom: 14px;
  }

  #finalScore .score-value {
    margin-bottom: 14px;
  }

  #finalScore .best-badge {
    margin-bottom: 13px;
  }
}

/* Mute button */
#homeScreen #muteBtn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 12;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 18px;
  padding: 6px 10px;
  margin: 0;
  line-height: 1;
  cursor: pointer;
}

#homeScreen #muteBtn:hover {
  background: rgba(0, 0, 0, 0.7);
}

/* Modal */
.modal {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.65);
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(100%, 680px);
  max-height: min(100%, 720px);
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.98);
  color: #000;
  border: 4px solid #000;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 2px solid #000;
  background: #fff;
  flex: 0 0 auto;
}

.modal-title {
  font-family: 'Press Start 2P', cursive;
  font-size: 14px;
  line-height: 1.3;
  text-align: left;
}

.modal-close {
  font-family: 'Press Start 2P', cursive;
  font-size: 12px;
  padding: 10px 12px;
  border: 2px solid #000;
  background: #fff;
  color: #000;
  cursor: pointer;
  text-transform: none;
  margin: 0;
  border-radius: 0;
}

.modal-close:hover {
  background: #000;
  color: #fff;
}

.modal-body {
  padding: 14px;
  overflow: auto;
  font-size: 18px;
  text-align: left;
}

.modal-body h3 {
  font-family: 'Press Start 2P', cursive;
  font-size: 12px;
  margin: 14px 0 6px;
}

.modal-body p {
  margin: 6px 0 10px;
}

.modal-body ul {
  margin: 6px 0 12px 18px;
  padding: 0;
}

.modal-body details {
  margin-top: 10px;
}

.modal-body summary {
  cursor: pointer;
  margin: 10px 0;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid #000;
  background: #fff;
}

.info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 16px;
  min-width: 560px;
}

.info-table th,
.info-table td {
  border: 1px solid #000;
  padding: 6px 8px;
  vertical-align: top;
  white-space: nowrap;
}

.info-table th {
  background: #f0f0f0;
}

.modal-note {
  font-size: 16px;
  opacity: 0.85;
  margin: 8px 0 0;
}

.guide-replay {
  width: 100%;
  margin: 2px 0 8px;
  padding: 12px;
  border: 2px solid #000;
  background: #173b6d;
  color: #fff;
  font-family: 'Press Start 2P', cursive;
  font-size: 11px;
  line-height: 1.35;
  cursor: pointer;
  text-transform: uppercase;
}

.guide-replay:hover {
  background: #10a807;
}

.leaderboard-card {
  max-width: 520px;
}

.leaderboard-body {
  min-height: 180px;
  padding: 12px;
  overflow: auto;
  background: #eaf4ff;
}

.leaderboard-status {
  min-height: 24px;
  margin: 2px 0 10px;
  color: #526477;
  text-align: center;
  font-size: 18px;
}

.delete-data-action {
  width: 100%;
  margin-top: 12px;
  padding: 10px 8px;
  border: 2px solid #8b1a1a;
  background: #fff;
  color: #8b1a1a;
  font: 8px/1.4 'Press Start 2P', cursive;
  text-transform: uppercase;
  cursor: pointer;
}

.delete-data-action:hover {
  background: #8b1a1a;
  color: #fff;
}

.leaderboard-status[data-type="error"] {
  color: #b01616;
}

.leaderboard-list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 6px 9px;
  border: 2px solid #163d6e;
  background: #fff;
  color: #0e2851;
}

.leaderboard-row:nth-child(-n + 3) {
  border-color: #9b7000;
  background: #fff8d8;
}

.leaderboard-rank {
  font-family: 'Press Start 2P', cursive;
  font-size: 10px;
  line-height: 1.2;
}

.leaderboard-player {
  display: block;
  min-width: 0;
  line-height: 1;
}

.leaderboard-name {
  display: block;
  overflow: hidden;
  font-size: 23px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-settings,
.leaderboard-modifiers {
  display: inline;
  color: #526477;
  font-size: 16px;
  line-height: 1;
  overflow-wrap: anywhere;
}

.leaderboard-modifiers {
  color: #6d7c8b;
}

.leaderboard-modifiers:not(:empty)::before {
  content: ' · ';
}

.leaderboard-score {
  color: #0e2851;
  font-family: 'Press Start 2P', cursive;
  font-size: 18px;
  line-height: 1.2;
  text-align: right;
}

.leaderboard-retry {
  display: block;
  margin: 12px auto 0;
  padding: 10px 12px;
  border: 2px solid #000;
  background: #173b6d;
  color: #fff;
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  cursor: pointer;
  text-transform: uppercase;
}

.leaderboard-retry.hidden {
  display: none;
}

@media (max-width: 390px) {
  .menu-actions,
  .game-over-actions {
    gap: 5px;
  }

  #homeScreen button,
  #gameOver button {
    padding-right: 8px;
    padding-left: 8px;
  }

  .leaderboard-row {
    grid-template-columns: 32px minmax(0, 1fr) 34px;
    gap: 5px;
    min-height: 52px;
    padding: 5px 7px;
  }

  .leaderboard-rank {
    font-size: 9px;
  }

  .leaderboard-name {
    font-size: 21px;
  }

  .leaderboard-settings,
  .leaderboard-modifiers {
    font-size: 15px;
  }

  .leaderboard-score {
    font-size: 17px;
  }
}
