:root {
  --bg-color: #0b0c10;
  --card-bg: #1f2833;
  --primary-color: #45f3ff;
  --secondary-color: #f3ca20;
  --accent-color: #ff007f;
  --text-primary: #c5c6c7;
  --text-bright: #ffffff;
  --font-family: 'Outfit', sans-serif;
  --border-radius: 12px;
  --box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

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

body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-family);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  overflow-x: hidden;
}

#app-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 1000px;
  width: 100%;
}

header {
  position: relative;
  text-align: center;
  margin-bottom: 24px;
  padding: 0 56px;
}

header h1 {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-bright);
  text-shadow: 0 0 10px rgba(69, 243, 255, 0.3);
  margin-bottom: 8px;
}

.subtitle {
  font-size: 1rem;
  color: var(--primary-color);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 600;
}

.settings-btn {
  position: absolute;
  top: 2px;
  right: 0;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(69, 243, 255, 0.45);
  border-radius: 50%;
  background: rgba(31, 40, 51, 0.92);
  color: var(--primary-color);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(69, 243, 255, 0.18);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.settings-btn:hover,
.settings-btn:focus-visible {
  border-color: var(--primary-color);
  box-shadow: 0 0 24px rgba(69, 243, 255, 0.38);
  transform: rotate(20deg) scale(1.06);
  outline: none;
}

.game-card {
  background-color: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  border: 1px solid rgba(255, 255, 255, 0.05);
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 1;
  background-color: #000;
}

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

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(11, 12, 16, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.3s ease;
  z-index: 10;
}

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

.overlay-content {
  text-align: center;
  max-width: 400px;
  padding: 20px;
}

.overlay-content h2 {
  font-size: 2rem;
  color: var(--text-bright);
  margin-bottom: 16px;
  font-weight: 800;
}

.overlay-content p {
  font-size: 1rem;
  margin-bottom: 24px;
  line-height: 1.6;
}

/* Start button group */
.start-btn-group {
  display: flex;
  justify-content: center;
  gap: 12px;
}

/* Rules content modal */
.overlay-content.rules-content {
  max-width: 600px;
  max-height: 85%;
  display: flex;
  flex-direction: column;
}

.dialogue-container {
  overflow-y: auto;
  max-height: 250px;
  padding: 12px;
  margin: 16px 0;
  background: rgba(0, 0, 0, 0.25);
  border: 3px solid #111111;
  border-radius: 8px;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

/* Comic bubbles */
.dialogue-bubble {
  position: relative;
  padding: 10px 16px;
  border-radius: 12px;
  border: 3px solid #111111;
  font-size: 0.9rem;
  line-height: 1.4;
  max-width: 85%;
  font-family: var(--font-family);
  box-shadow: 4px 4px 0 #111111;
}

/* Mentor bubble (left) */
.dialogue-bubble.mentor {
  align-self: flex-start;
  background: #ffffff;
  color: #111111;
}

/* Eater bubble (right) */
.dialogue-bubble.eater {
  align-self: flex-end;
  background: #c5f9c3;
  color: #111111;
  border-color: #111111;
}

.dialogue-bubble strong {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 3px;
  text-transform: uppercase;
  color: #1e1b4b;
}

.dialogue-bubble.eater strong {
  color: #065f46;
}

.player-name-field {
  margin: -8px auto 20px;
  max-width: 300px;
  text-align: left;
}

.player-name-field[hidden] {
  display: none;
}

.player-name-field label {
  display: block;
  margin-bottom: 8px;
  color: var(--primary-color);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.player-name-field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid rgba(69, 243, 255, 0.45);
  border-radius: 8px;
  outline: none;
  background-color: rgba(0, 0, 0, 0.45);
  color: var(--text-bright);
  font: inherit;
}

.player-name-field input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(69, 243, 255, 0.12);
}

.input-error {
  display: block;
  min-height: 1.2em;
  margin-top: 6px;
  color: #ff7cac;
  font-size: 0.8rem;
}

.btn {
  font-family: var(--font-family);
  font-weight: 600;
  font-size: 1rem;
  padding: 12px 28px;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-primary {
  background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
  color: #000;
  box-shadow: 0 0 15px rgba(69, 243, 255, 0.4);
}

.btn-primary:hover {
  transform: scale(1.05);
  box-shadow: 0 0 25px rgba(69, 243, 255, 0.6);
}

.btn-secondary {
  background: rgba(69, 243, 255, 0.12);
  color: var(--text-bright);
  border: 1px solid rgba(69, 243, 255, 0.45);
}

.btn-secondary:hover,
.btn-secondary:focus-visible {
  background: rgba(69, 243, 255, 0.22);
  box-shadow: 0 0 18px rgba(69, 243, 255, 0.28);
  outline: none;
}

.reset-size-btn {
  justify-self: center;
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
  background: rgba(255, 0, 127, 0.12);
  border: 1px solid rgba(255, 0, 127, 0.4);
  color: var(--text-bright);
  margin-top: 4px;
}

.reset-size-btn:hover,
.reset-size-btn:focus-visible {
  border-color: var(--accent-color);
  background: rgba(255, 0, 127, 0.24);
  box-shadow: 0 0 18px rgba(255, 0, 127, 0.26);
}

.mobile-controls-overlay {
  position: absolute;
  inset: auto 0 0;
  z-index: 8;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  padding: clamp(12px, 3vw, 22px);
  pointer-events: none;
}

.dpad,
.action-buttons {
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.touch-btn {
  width: clamp(52px, 13vw, 72px);
  height: clamp(52px, 13vw, 72px);
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 50%;
  background: rgba(11, 12, 16, 0.45);
  color: var(--text-bright);
  font: 800 1.35rem/1 var(--font-family);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.32), inset 0 0 18px rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}

.touch-btn:active,
.touch-btn.active {
  border-color: var(--primary-color);
  background: rgba(69, 243, 255, 0.25);
  transform: scale(0.95);
}

.jump-btn {
  border-color: rgba(243, 202, 32, 0.44);
  background: rgba(243, 202, 32, 0.18);
}

@media (max-width: 1024px), (pointer: coarse) {
  .mobile-controls-overlay {
    display: flex;
  }
}

.controls-panel {
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02) 0%, rgba(0,0,0,0.2) 100%);
}

@media (min-width: 768px) {
  .controls-panel {
    grid-template-columns: 1fr 1fr;
  }
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat-box {
  background-color: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--primary-color);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-bright);
  max-width: 100%;
  text-align: center;
  overflow-wrap: anywhere;
  line-height: 1.2;
}

#lives-val {
  color: var(--accent-color);
}

.how-to-play h3 {
  font-size: 1.1rem;
  color: var(--text-bright);
  margin-bottom: 12px;
  font-weight: 600;
}

.how-to-play ul {
  list-style: none;
}

.how-to-play li {
  font-size: 0.9rem;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
}

.leaderboard-card {
  grid-column: 1 / -1;
  padding-top: 20px;
  border-top: 2px solid rgba(69, 243, 255, 0.55);
}

.leaderboard-card h3 {
  margin-bottom: 12px;
  color: var(--text-bright);
  font-size: 1.1rem;
  font-weight: 600;
}

.leaderboard-table-wrapper {
  overflow-x: auto;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
}

#leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

#leaderboard-table th,
#leaderboard-table td {
  padding: 10px 14px;
}

#leaderboard-table th {
  background-color: rgba(0, 0, 0, 0.4);
  color: var(--primary-color);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#leaderboard-table tbody tr:nth-child(odd) {
  background-color: rgba(255, 255, 255, 0.025);
}

#leaderboard-table tbody tr:nth-child(even) {
  background-color: rgba(0, 0, 0, 0.18);
}

#leaderboard-table td:first-child {
  width: 72px;
  color: var(--secondary-color);
  font-weight: 800;
}

#leaderboard-table th:last-child,
#leaderboard-table td:last-child {
  text-align: right;
}

#leaderboard-table td:last-child {
  color: var(--text-bright);
  font-weight: 600;
}

#leaderboard-table .leaderboard-message {
  color: var(--text-primary);
  font-weight: 400;
  text-align: center;
}

.key {
  background-color: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.8rem;
  margin: 0 4px;
  color: var(--text-bright);
}

footer {
  margin-top: 30px;
  text-align: center;
  font-size: 0.8rem;
  opacity: 0.6;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(11, 12, 16, 0.78);
  backdrop-filter: blur(10px);
  opacity: 1;
  transition: opacity 0.2s ease;
}

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

.modal-content {
  width: min(420px, 100%);
  padding: 26px;
  border: 1px solid rgba(69, 243, 255, 0.38);
  border-radius: var(--border-radius);
  background: linear-gradient(180deg, rgba(31, 40, 51, 0.98), rgba(11, 12, 16, 0.98));
  box-shadow: var(--box-shadow), 0 0 32px rgba(69, 243, 255, 0.16);
  transform: translateY(0) scale(1);
  transition: transform 0.2s ease;
}

.modal.hidden .modal-content {
  transform: translateY(10px) scale(0.98);
}

.modal-content h2 {
  margin-bottom: 22px;
  color: var(--text-bright);
  font-size: 1.6rem;
  font-weight: 800;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.setting-item label {
  color: var(--text-bright);
  font-weight: 600;
}

#setting-sound {
  appearance: none;
  position: relative;
  width: 54px;
  height: 30px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

#setting-sound::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-bright);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s ease;
}

#setting-sound:checked {
  border-color: var(--primary-color);
  background: rgba(69, 243, 255, 0.36);
}

#setting-sound:checked::before {
  transform: translateX(24px);
}

#setting-sound:focus-visible,
#setting-lang:focus-visible {
  outline: 3px solid rgba(69, 243, 255, 0.24);
  outline-offset: 3px;
}

#setting-lang {
  min-width: 150px;
  padding: 10px 36px 10px 12px;
  border: 1px solid rgba(69, 243, 255, 0.45);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.42);
  color: var(--text-bright);
  font: inherit;
  cursor: pointer;
}

@media (max-width: 520px) {
  header {
    padding: 52px 0 0;
  }

  .settings-btn {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }

  .settings-btn:hover,
  .settings-btn:focus-visible {
    transform: translateX(-50%) rotate(20deg) scale(1.06);
  }

  .setting-item {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  #setting-lang {
    width: 100%;
  }
}
