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

html,
body {
  width: 100%;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111;
  color: #f5f5f5;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: #1d1d1d;
  border-bottom: 1px solid #333;
  font-size: 0.9rem;
}

#top-bar h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

#hud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
}

#hud span {
  white-space: nowrap;
}

.icon-btn {
  background: #333;
  border: none;
  color: #f5f5f5;
  border-radius: 999px;
  padding: 0.3rem 0.6rem;
  font-size: 1rem;
}

.icon-btn:active {
  transform: scale(0.95);
}

#main-area {
  position: relative;
  flex: 1;
  display: flex;
  background: radial-gradient(circle at top, #444 0, #111 65%);
  overflow: hidden;
}

/* Canvas fills central area */
#game-canvas {
  margin: auto;
  display: block;
  background: #c89b5f; /* wood base */
  border-radius: 16px;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.7);
  position: relative;
  z-index: 1;
  pointer-events: none; /* allow overlays and UI to receive input */
}

/* Overlays (menus) */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 20;       /* ensure menus are above canvas, joystick, etc. */
  pointer-events: auto;
}

.overlay.visible {
  display: flex;
}

.panel {
  width: 90%;
  max-width: 400px;
  background: #222;
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}

.panel h2 {
  font-size: 1.3rem;
  margin-bottom: 0.75rem;
}

.panel p {
  margin-bottom: 0.5rem;
}

.panel ul {
  margin: 0.5rem 0 1rem;
  padding-left: 1.2rem;
  font-size: 0.9rem;
}

button {
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}

button.primary {
  background: #ffc857;
  color: #222;
}

button.secondary {
  background: #333;
  color: #f5f5f5;
  margin-top: 0.25rem;
}

button.small {
  font-size: 0.75rem;
  padding: 0.3rem 0.7rem;
}

button:active {
  transform: scale(0.97);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0.4rem 0;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.setting-row select {
  padding: 0.25rem 0.4rem;
  border-radius: 8px;
  border: 1px solid #555;
  background: #111;
  color: #f5f5f5;
}

.info-text {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: #ccc;
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #555;
  transition: 0.2s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

.switch input:checked + .slider {
  background-color: #ffc857;
}

.switch input:checked + .slider:before {
  transform: translateX(22px);
}

/* Name input */
.name-input {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.4rem;
  border-radius: 999px;
  border: 1px solid #555;
  background: #111;
  color: #f5f5f5;
  font-size: 0.95rem;
  outline: none;
}

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

/* Leaderboard table */
#leaderboard-list {
  width: 100%;
  margin-bottom: 0.75rem;
  max-height: 300px;
  overflow-y: auto;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.lb-table th {
  text-align: left;
  padding: 0.3rem 0.4rem;
  color: #aaa;
  border-bottom: 1px solid #444;
  white-space: nowrap;
}

.lb-table td {
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid #333;
}

.lb-table tr.lb-win td {
  color: #ffc857;
}

.lb-empty {
  color: #888;
  font-size: 0.85rem;
  padding: 0.5rem 0;
}

/* Debug Panel */
#debug-panel {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.6);
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  pointer-events: none;
  z-index: 15;
  display: none;
}

/* Joystick */
#joystick-container {
  position: absolute;
  left: 0.4rem;
  bottom: 0.8rem;
  width: 120px;
  height: 120px;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
}

#joystick-base {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.35);
  position: relative;
}

#joystick-stick {
  position: absolute;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Bottom Bar */
#bottom-bar {
  padding: 0.4rem 0.6rem;
  background: #1d1d1d;
  border-top: 1px solid #333;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
}

#fallback-message {
  color: #ffc857;
}

/* Desktop tweaks */
@media (min-width: 800px) {
  #top-bar {
    font-size: 1rem;
  }

  .panel {
    max-width: 440px;
  }
}