* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* Comic book page: warm paper + halftone dots */
  background-color: #f5e6c8;
  background-image:
    radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0.08) 1px, transparent 1px);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  color: #2c1810;
  padding: 1.5rem;
}

h1 {
  margin-bottom: 0.25rem;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #1a1a1a;
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.8);
}

#tagline {
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: #5c4033;
}

#game-container {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 0 4px #1a1a1a,
    0 0 0 6px #fff,
    0 0 0 8px #1a1a1a,
    6px 6px 0 rgba(0, 0, 0, 0.3);
}

#game-canvas {
  display: block;
  /* Fallback; comic sky/ground are drawn in JS */
  background: #87ceeb;
}

#ui-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.35) 0%,
    rgba(0, 0, 0, 0.15) 60%,
    transparent 100%
  );
  backdrop-filter: blur(4px);
}

#player-label {
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.95;
  color: #fff;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000;
}

#top-stats {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  pointer-events: none;
}

#level-display,
#speed-display,
#score-display {
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000;
}

#score-display {
  font-size: 1.15rem;
}

#bottom-overlay {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#controls-row {
  margin-top: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  align-content: center;
  justify-content: center;
}

#nickname-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

#nickname-form input {
  padding: 8px 14px;
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  background: #fff;
  color: #1a1a1a;
  font-size: 0.9rem;
  line-height: 1.25;
  font-family: inherit;
  width: 180px;
  height: 38px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#nickname-form input::placeholder {
  color: #888;
}

#nickname-form input:focus {
  outline: none;
  border-color: #e63946;
  box-shadow: 0 0 0 2px rgba(230, 57, 70, 0.3);
}

#nickname-form button {
  padding: 8px 16px;
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  background: #e63946;
  color: #fff;
  font-size: 0.9rem;
  line-height: 1.25;
  font-weight: 600;
  font-family: inherit;
  height: 38px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
}

#nickname-form button:hover {
  transform: translateY(-1px);
  box-shadow: 3px 3px 0 #1a1a1a;
}

#nickname-form button:focus {
  outline: none;
  box-shadow: 0 0 0 2px #1a1a1a;
}

.anonymous-hint {
  font-size: 0.8rem;
  color: #5c4033;
  margin: 0;
  align-self: center;
}

#mute-btn {
  padding: 8px 14px;
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  background: #fff;
  color: #1a1a1a;
  font-size: 0.85rem;
  line-height: 1.25;
  font-family: inherit;
  height: 38px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}

#mute-btn:hover {
  background: #f0e6d8;
  box-shadow: 2px 2px 0 #1a1a1a;
}

#mute-btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px #1a1a1a;
}

#mute-btn.muted {
  opacity: 0.7;
}

.create-account-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.create-account-box {
  background: #fff;
  border: 3px solid #1a1a1a;
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 360px;
  box-shadow: 6px 6px 0 #1a1a1a;
}

.create-account-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 0.5rem;
}

.create-account-desc {
  font-size: 0.9rem;
  color: #5c4033;
  margin-bottom: 1.25rem;
}

.create-account-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.create-account-actions button {
  padding: 10px 16px;
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

#create-account-btn {
  background: #e63946;
  color: #fff;
}

#create-account-btn:hover {
  background: #c92a37;
  box-shadow: 3px 3px 0 #1a1a1a;
}

#create-account-skip {
  background: #fff;
  color: #1a1a1a;
}

#create-account-skip:hover {
  background: #f0e6d8;
  box-shadow: 2px 2px 0 #1a1a1a;
}

#message {
  font-size: 0.8rem;
  color: #fef3c7;
  text-align: center;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000;
}

#start-prompt {
  font-size: 0.9rem;
  font-weight: 700;
  color: #ffffff;
  text-align: center;
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000;
}

#leaderboard {
  margin-top: 1.5rem;
  width: 100%;
  max-width: 360px;
  padding: 16px 20px;
  background: #fff;
  border: 3px solid #1a1a1a;
  border-radius: 8px;
  font-size: 0.9rem;
  box-shadow: 4px 4px 0 #1a1a1a;
}

#leaderboard h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: #1a1a1a;
}

#leaderboard ol {
  padding-left: 1.25rem;
}

#leaderboard li {
  margin: 6px 0;
  color: #2c1810;
}

#leaderboard .nick {
  color: #e63946;
  font-weight: 600;
}

#leaderboard .anon {
  color: #666;
}

#leaderboard-link-row {
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

#leaderboard-link {
  color: #1a1a1a;
  font-weight: 600;
}

/* Dedicated leaderboard page */
#leaderboard-header {
  width: 100%;
  max-width: 720px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

#leaderboard-header h1 {
  margin-bottom: 0.15rem;
}

#leaderboard-tagline {
  font-size: 0.9rem;
  color: #5c4033;
}

#back-to-game {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1a1a1a;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 999px;
  border: 2px solid #1a1a1a;
  background: #fff7e6;
  box-shadow: 2px 2px 0 #1a1a1a;
}

#back-to-game:hover {
  transform: translateY(-1px);
}

#leaderboard-main {
  width: 100%;
  max-width: 720px;
}

#leaderboard-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.lb-filter-btn {
  border-radius: 999px;
  padding: 6px 12px;
  border: 2px solid #1a1a1a;
  background: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.lb-filter-btn.active {
  background: #e63946;
  color: #fff;
}

#leaderboard-table-card {
  background: #fff;
  border: 3px solid #1a1a1a;
  border-radius: 8px;
  box-shadow: 4px 4px 0 #1a1a1a;
  padding: 14px 16px;
}

#leaderboard-table-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

#leaderboard-table-header h2 {
  font-size: 1rem;
}

#leaderboard-count {
  font-size: 0.8rem;
  color: #5c4033;
}

.leaderboard-table-wrapper {
  max-height: 420px;
  overflow: auto;
}

#leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

#leaderboard-table th,
#leaderboard-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #eee;
  text-align: left;
}

#leaderboard-table th:nth-child(1),
#leaderboard-table td:nth-child(1) {
  width: 40px;
}

#leaderboard-table th:nth-child(3),
#leaderboard-table td:nth-child(3) {
  text-align: right;
}

#leaderboard-table th:nth-child(4),
#leaderboard-table td:nth-child(4) {
  white-space: nowrap;
}

.lb-nick {
  color: #e63946;
  font-weight: 600;
}

.lb-anon {
  color: #666;
}

/* Statistics page: create account block */
.stats-create-block {
  margin: 1rem 0;
  padding: 1rem;
  background: #fff;
  border: 2px solid #1a1a1a;
  border-radius: 8px;
  box-shadow: 3px 3px 0 #1a1a1a;
  max-width: 420px;
}

.stats-create-block label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: #2c1810;
}

.stats-create-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.stats-create-row input {
  padding: 8px 12px;
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  font-size: 0.9rem;
  line-height: 1.25;
  font-family: inherit;
  width: 160px;
  min-width: 0;
  height: 38px;
}

.stats-create-row button {
  padding: 8px 14px;
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  background: #e63946;
  color: #fff;
  font-size: 0.9rem;
  line-height: 1.25;
  font-weight: 600;
  font-family: inherit;
  height: 38px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
}

.stats-create-row button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 2px 2px 0 #1a1a1a;
}

.stats-create-row button:disabled {
  opacity: 0.8;
  cursor: not-allowed;
}

/* Statistics page: search account section */
#stats-search-section {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: #fff;
  border: 2px solid #1a1a1a;
  border-radius: 8px;
  box-shadow: 3px 3px 0 #1a1a1a;
}

#stats-search-section h2 {
  font-size: 1rem;
  margin-bottom: 0.35rem;
}

.stats-search-block {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 0.5rem;
}

.stats-search-block input {
  flex: 1;
  min-width: 180px;
  padding: 8px 12px;
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.25;
  height: 38px;
}

.stats-search-block button {
  padding: 8px 14px;
  border: 2px solid #1a1a1a;
  border-radius: 6px;
  background: #fff7e6;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.25;
  font-weight: 600;
  height: 38px;
  cursor: pointer;
  box-shadow: 2px 2px 0 #1a1a1a;
}

.stats-search-block button:hover {
  transform: translateY(-1px);
  box-shadow: 2px 2px 0 #1a1a1a;
}

.stats-message {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: #5c4033;
}

.stats-message-error {
  color: #c62828;
  font-weight: 500;
}

/* Statistics summary cards */
#stats-summary-card,
#stats-ranks-card {
  background: #fff;
  border: 3px solid #1a1a1a;
  border-radius: 8px;
  box-shadow: 4px 4px 0 #1a1a1a;
  padding: 14px 16px;
  margin-bottom: 1rem;
}

#stats-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin: 0.5rem 0 0.75rem;
}

.stats-summary-item .stats-label {
  font-size: 0.8rem;
  color: #5c4033;
  margin-bottom: 0.2rem;
}

.stats-summary-item .stats-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1a1a1a;
}

.stats-summary-item .stats-sub {
  font-size: 0.8rem;
  color: #666;
  margin-top: 0.15rem;
}

.stats-note {
  font-size: 0.8rem;
  color: #5c4033;
  margin-top: 0.5rem;
}

#stats-links-row {
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

#stats-links-row a {
  font-weight: 600;
  color: #1a1a1a;
}

@media (max-width: 480px) {
  body {
    padding: 1rem;
  }

  h1 {
    font-size: 1.6rem;
  }

  #tagline {
    font-size: 0.875rem;
  }

  #game-container {
    border-radius: 12px;
  }

  #controls-row {
    flex-direction: column;
    width: 100%;
    max-width: 320px;
  }

  #nickname-form {
    width: 100%;
  }

  #nickname-form input {
    flex: 1;
    min-width: 0;
  }

  #leaderboard {
    max-width: 100%;
    padding: 14px 16px;
  }

  #leaderboard-header {
    flex-direction: column;
    align-items: flex-start;
  }

  #leaderboard-main {
    max-width: 100%;
  }
}
