* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100%;
  background: #0a0a0a;
  color: #e4e4e7;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', sans-serif;
}

canvas {
  display: block;
}

/* Top UI Bar */
#ui {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.4));
  backdrop-filter: blur(8px);
  z-index: 10;
}

#group-id {
  font-weight: 600;
  font-size: 14px;
}

.mode-toggle-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e4e4e7;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.mode-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.mode-toggle-btn.full-mode {
  background: rgba(34, 197, 94, 0.2);
  border-color: rgba(34, 197, 94, 0.5);
  color: #4ade80;
}

/* HUD */
#hud {
  position: absolute;
  left: 16px;
  bottom: 16px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(12px);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
  z-index: 10;
}

/* Touch Controls */
#touch-controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}

.control-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.ctrl-btn {
  min-width: 56px;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  color: #e4e4e7;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
}

.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
}

/* Main Menu */
#main-menu {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 10, 10, 0.95);
  backdrop-filter: blur(20px);
  padding: 48px 56px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
  z-index: 100;
  min-width: 400px;
}

#main-menu h1 {
  margin: 0 0 40px 0;
  font-size: 42px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.5px;
}

#menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.menu-btn {
  padding: 16px 32px;
  font-size: 16px;
  font-weight: 500;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: #e4e4e7;
  cursor: pointer;
  transition: all 0.2s ease;
}

.menu-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.menu-btn.primary {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

.menu-btn.primary:hover {
  background: linear-gradient(135deg, #16a34a, #15803d);
  box-shadow: 0 6px 16px rgba(34, 197, 94, 0.4);
}

/* Editor UI */
#editor-ui {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 300px;
  background: rgba(10, 10, 10, 0.95);
  backdrop-filter: blur(20px);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 50;
  padding: 20px;
}

#editor-ui::-webkit-scrollbar {
  width: 8px;
}

#editor-ui::-webkit-scrollbar-track {
  background: transparent;
}

#editor-ui::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

#editor-ui::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

#editor-ui.hidden {
  display: none;
}

#editor-toolbar h3 {
  margin: 0 0 20px 0;
  font-size: 24px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 12px;
  letter-spacing: -0.3px;
}

#editor-toolbar h4 {
  margin: 24px 0 12px 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #a1a1aa;
}

/* Tile Palette */
#tile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.tile-option {
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
}

.tile-option:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.tile-option.selected {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
  box-shadow: 0 0 0 1px #22c55e;
}

.tile-option canvas {
  width: 100%;
  height: 60px;
  margin-bottom: 8px;
  border-radius: 6px;
}

.tile-option span {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: #d4d4d8;
}

/* Object Palette */
#object-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
  max-height: 300px;
  overflow-y: auto;
}

.object-option {
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
}

.object-option:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.object-option.selected {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
  box-shadow: 0 0 0 1px #22c55e;
}

.object-option canvas {
  width: 100%;
  height: 60px;
  margin-bottom: 8px;
  border-radius: 6px;
}

.object-option span {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: #d4d4d8;
}

.object-item,
.waypoint-item {
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  margin: 8px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.delete-object-btn,
.delete-waypoint-btn {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #f87171;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.delete-object-btn:hover,
.delete-waypoint-btn:hover {
  background: rgba(239, 68, 68, 0.3);
  border-color: rgba(239, 68, 68, 0.6);
}

.button-row {
  display: flex;
  gap: 8px;
}

.button-row .editor-btn {
  flex: 1;
}

.mode-btn {
  width: 100%;
  padding: 10px;
  margin: 5px 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #e4e4e7;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.mode-btn.active {
  background: rgba(34, 197, 94, 0.15);
  border-color: #22c55e;
  color: #4ade80;
}

.info-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 12px;
  border-radius: 8px;
  margin: 10px 0;
  font-size: 13px;
  line-height: 1.5;
  color: #d4d4d8;
}

.info-text {
  color: #a1a1aa;
  font-size: 13px;
  padding: 8px 0;
  line-height: 1.5;
}

/* Editor Buttons */
.editor-btn {
  width: 100%;
  padding: 12px 16px;
  margin: 6px 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #e4e4e7;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.editor-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.editor-btn.primary {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  border-color: transparent;
  color: #ffffff;
}

.editor-btn.primary:hover {
  background: linear-gradient(135deg, #16a34a, #15803d);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

.editor-btn.warning {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
}

.editor-btn.warning:hover {
  background: rgba(239, 68, 68, 0.3);
  border-color: rgba(239, 68, 68, 0.6);
}

.editor-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Track Name Input */
#track-name {
  width: 100%;
  padding: 12px;
  margin-bottom: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #e4e4e7;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s ease;
}

#track-name:focus {
  outline: none;
  border-color: #22c55e;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.1);
}

/* Grid Info */
#grid-info > div {
  margin: 8px 0;
  font-size: 13px;
  color: #d4d4d8;
}

#grid-info span {
  color: #4ade80;
  font-weight: 600;
}

/* Utility Classes */
.hidden {
  display: none !important;
}
