:root {
  --bg: #f4f6fb;
  --ink: #111;
  --line: #d6dbe8;
  --accent: #0d8a5f;
  --panel: #ffffffdd;
}

* { box-sizing: border-box; }
html, body {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}
body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background: radial-gradient(circle at 20% 20%, #ffffff, var(--bg));
  color: var(--ink);
}

.screen { display: none; min-height: 100vh; }
.screen.visible { display: flex; }

#landing {
  align-items: center;
  justify-content: center;
}

.card {
  width: min(460px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  display: grid;
  gap: 10px;
}

.card label {
  font-weight: 600;
  color: #666;
  font-size: 14px;
  margin-top: 8px;
}

#character-selector {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: #fafafa;
  border: 2px solid #ddd;
  border-radius: 12px;
  justify-content: center;
  align-items: center;
}

.color-nav-btn {
  width: 36px;
  height: 36px;
  border: 2px solid #ccc;
  border-radius: 8px;
  background: white;
  color: #666;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.color-nav-btn:hover {
  border-color: #999;
  background: #fafafa;
}

.color-nav-btn:active {
  background: #f0f0f0;
}

.character-option {
  width: 64px;
  height: 64px;
  border: 2px solid #ccc;
  border-radius: 12px;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.character-option:hover {
  border-color: #999;
  background: #fafafa;
}

.character-option.selected {
  border-color: #333;
  border-width: 3px;
  background: #f5f5f5;
}

.character-placeholder {
  font-size: 32px;
  font-weight: 600;
  color: #ccc;
}

.character-preview {
  width: 64px;
  height: 64px;
  image-rendering: crisp-edges;
}

input, button {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
}

#game {
  position: relative;
  align-items: stretch;
}

#world-canvas {
  width: 100vw;
  height: 100vh;
  background: #fff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#leaderboard {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 240px;
  background: var(--panel);
  border: 1px solid var(--line);
  /* border-radius: 12px; */
  padding: 10px;
}

#tools-container {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  width: min(400px, calc(100vw - 32px));
}

#tool-panel {
  display: flex;
  gap: 24px;
  padding: 16px 24px;
  background: rgba(255, 255, 255, 0);
  /* border: 2px solid #ddd; */
  /* border-radius: 16px; */
}

.tool {
  width: 64px;
  height: 72px;
  border: 1px solid #ccc;
  /* border-radius: 12px; */
  background: rgba(255, 255, 255, 0.315);
  color: #666;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 8px 6px 6px 6px;
}

.tool:hover {
  border-color: #999;
  background: #fafafa4b;
}

.tool.active {
  border-color: #333;
  border-width: 2px;
  background: #f5f5f548;
  color: #333;
  padding: 7px 5px 5px 5px;
}

.tool-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  object-fit: contain;
}

.bar-wrap {
  width: 100%;
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  overflow: hidden;
}

.bar {
  height: 100%;
  width: 100%;
  background: #666;
  transition: width 0.3s ease;
  border-radius: 3px;
}

#chat-container {
  width: 100%;
  display: flex;
  gap: 8px;
}

#chat-input-desktop {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid #ddd;
  background: white;
  font-size: 14px;
  outline: none;
  transition: all 0.15s ease;
}

#chat-input {
  flex: 1;
  padding: 0px 6px;
  border: 2px solid #ddd;
  /* border-radius: 12px; */
  background: white;
  font-size: 14px;
  outline: none;
  transition: all 0.15s ease;
}

#chat-input:focus {
  border-color: #999;
}


#connection-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px;
  text-align: center;
  z-index: 10000;
  font-weight: 600;
  font-size: 14px;
  transition: transform 0.3s ease-in-out;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

#connection-banner.hidden {
  transform: translateY(-100%);
}

#connection-banner.warning {
  background: #ff9800;
  color: white;
}

#connection-banner.info {
  background: #2196F3;
  color: white;
}

#connection-banner.error {
  background: #f44336;
  color: white;
}

#connection-banner.success {
  background: #4caf50;
  color: white;
}

.connection-link {
  color: white;
  text-decoration: underline;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
  transition: background 0.2s;
}

.connection-link:hover {
  background: rgba(0, 0, 0, 0.3);
}

.connection-link.hidden {
  display: none;
}

/* Debug overlay - hidden by default, can be enabled for debugging */
#debug-overlay {
  position: fixed;
  bottom: 140px;
  right: 10px;
  background: rgba(0, 0, 0, 0.8);
  color: #0f0;
  padding: 6px;
  font-family: monospace;
  font-size: 9px;
  border-radius: 4px;
  z-index: 9999;
  pointer-events: none;
  max-width: 150px;
  max-height: 120px;
  overflow-y: auto;
  display: none;
  line-height: 1.3;
  white-space: nowrap;
}

/* Mobile touch controls */
#mobile-controls {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#joystick-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 90px;
  height: 90px;
  background: rgba(0, 0, 0, 0.2);
  border: 2px solid rgba(0, 0, 0, 0.3);
  border-radius: 50%;
  pointer-events: all;
  touch-action: none;
  z-index: 1000;
}

#joystick-stick {
  position: absolute;
  width: 45px;
  height: 45px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: background 0.1s ease;
}

#joystick-container:active #joystick-stick {
  background: rgba(0, 0, 0, 0.7);
}

#jump-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 80px;
  height: 80px;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(0, 0, 0, 0.4);
  border-radius: 50%;
  color: white;
  font-size: 14px;
  font-weight: 600;
  pointer-events: all;
  touch-action: none;
  transition: background 0.1s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#jump-button:active {
  background: rgba(0, 0, 0, 0.5);
}

#mobile-chat-container {
  display: none;
}

@media (max-width: 768px), (pointer: coarse) {
  #mobile-controls {
    display: block;
  }
  
  /* Hide desktop chat on mobile */
  #chat-container {
    display: none;
  }
  
  #mobile-chat-container {
    display: flex;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    max-width: calc(100vw - 240px);
    pointer-events: all;
    z-index: 1000;
  }

  #mobile-chat-container #chat-input {
    width: 200px;
    padding: 10px 14px;
    border: 2px solid rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.95);
    font-size: 14px;
    outline: none;
  }
  
  #tools-container {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
  }
  
  #tool-panel {
    gap: 16px;
    padding: 10px 16px;
  }
}

@media (max-width: 720px) {
  #tools-container {
    width: calc(100vw - 16px);
  }
  #tool-panel {
    gap: 16px;
    padding: 12px 16px;
  }
  .tool {
    width: 56px;
    height: 64px;
  }
}
