/* ============ RESET & BASE ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', 'Arial', sans-serif;
  background: #1a1a2e;
  color: #fff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ============ SCREENS ============ */
.screen {
  display: none;
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}
.screen.active { display: flex; }

/* ============ BUTTONS ============ */
.btn {
  border: none; outline: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  padding: 12px 24px;
  transition: transform 0.1s, box-shadow 0.1s;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.btn:active { transform: scale(0.95); }
.btn-primary {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}
.btn-large {
  width: 280px;
  padding: 18px 32px;
  font-size: 20px;
  margin: 8px 0;
  border-radius: 16px;
}
.btn-play {
  background: linear-gradient(135deg, #11998e, #38ef7d);
  color: #fff;
  box-shadow: 0 4px 15px rgba(56, 239, 125, 0.3);
}
.btn-editor {
  background: linear-gradient(135deg, #f093fb, #f5576c);
  color: #fff;
  box-shadow: 0 4px 15px rgba(245, 87, 108, 0.3);
}
.btn-logout {
  background: linear-gradient(135deg, #4a4a4a, #6a6a6a);
  color: #fff;
}
.btn-small {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 8px;
  background: linear-gradient(135deg, #434343, #6b6b6b);
  color: #fff;
}
.btn-small:active { background: linear-gradient(135deg, #555, #888); }
.btn-small.active-tool {
  background: linear-gradient(135deg, #f5576c, #ff6b6b);
  box-shadow: 0 0 10px rgba(245, 87, 108, 0.5);
}
.btn-back {
  background: linear-gradient(135deg, #636363, #888);
  color: #fff;
}

/* ============ LOGIN ============ */
#screen-login {
  justify-content: center; align-items: center;
  background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
}
.login-container {
  text-align: center;
  padding: 40px;
}
.logo-title { margin-bottom: 40px; }
.logo-crash {
  font-size: 52px;
  font-weight: 900;
  letter-spacing: 4px;
  text-shadow: 0 0 20px rgba(102, 126, 234, 0.5), 0 4px 8px rgba(0,0,0,0.5);
}
.logo-highlight { color: #f5576c; }
.logo-subtitle {
  font-size: 16px;
  color: #aaa;
  margin-top: 8px;
  font-style: italic;
}
#login-form input {
  display: block;
  width: 260px;
  margin: 12px auto;
  padding: 14px 18px;
  border: 2px solid #444;
  border-radius: 12px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 18px;
  text-align: center;
}
#login-form input:focus { border-color: #667eea; outline: none; }
#login-form .btn { width: 260px; margin: 20px auto 0; display: block; }
.error-msg { color: #f5576c; margin-top: 12px; min-height: 20px; font-size: 14px; }

/* ============ MENU ============ */
#screen-menu {
  justify-content: center; align-items: center;
  background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
  flex-direction: column;
}
.menu-container { text-align: center; }
.menu-buttons { display: flex; flex-direction: column; align-items: center; margin-top: 30px; }
.version-info { color: #555; font-size: 12px; margin-top: 30px; }

/* ============ MAP SELECT ============ */
#screen-mapselect {
  justify-content: center; align-items: center;
  background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
  flex-direction: column;
}
.mapselect-container {
  text-align: center;
  width: 90%;
  max-width: 600px;
}
.mapselect-container h2 { margin-bottom: 20px; }
.map-list {
  max-height: 60vh;
  overflow-y: auto;
  margin-bottom: 20px;
}
.map-item {
  background: rgba(255,255,255,0.08);
  border: 2px solid #444;
  border-radius: 12px;
  padding: 14px 20px;
  margin: 8px 0;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color 0.2s;
}
.map-item:hover, .map-item:active { border-color: #667eea; }
.map-item-name { font-weight: 700; font-size: 18px; }
.map-item-info { font-size: 13px; color: #aaa; }
.map-item-actions { display: flex; gap: 6px; }
.map-item-delete {
  background: #f5576c;
  border: none;
  color: #fff;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.no-maps { color: #888; font-size: 16px; padding: 40px; }

/* ============ EDITOR ============ */
#screen-editor {
  flex-direction: column;
  background: #16213e;
}
.editor-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.editor-topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(0,0,0,0.4);
  align-items: center;
  min-height: 44px;
  z-index: 10;
}
.map-name-input {
  border: 2px solid #444;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  padding: 6px 12px;
  font-size: 14px;
  width: 140px;
  margin-left: auto;
}
.map-name-input:focus { border-color: #667eea; outline: none; }
.editor-msg {
  padding: 4px 10px;
  font-size: 13px;
  min-height: 24px;
  background: rgba(0,0,0,0.3);
  color: #f5576c;
  display: flex;
  align-items: center;
}
.editor-msg.success { color: #38ef7d; }
.editor-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0a1628;
}
#editor-canvas {
  display: block;
  position: absolute;
  top: 0; left: 0;
}
.editor-palette {
  display: flex;
  flex-direction: column;
  background: rgba(0,0,0,0.5);
  max-height: 160px;
  overflow: hidden;
}
.palette-tabs {
  display: flex;
  gap: 2px;
  padding: 4px 6px;
  background: rgba(0,0,0,0.3);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  flex-shrink: 0;
}
.palette-tab {
  border: none;
  outline: none;
  background: rgba(255,255,255,0.08);
  color: #aaa;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 8px;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.palette-tab:active, .palette-tab.active {
  background: rgba(102, 126, 234, 0.4);
  color: #fff;
}
.palette-items-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 8px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  flex: 1;
  align-content: flex-start;
}
.palette-item {
  width: 62px;
  height: 62px;
  border: 2px solid #444;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 10px;
  color: #ccc;
  flex-shrink: 0;
  transition: border-color 0.15s;
  padding: 2px;
}
.palette-item:active, .palette-item.selected {
  border-color: #38ef7d;
  background: rgba(56, 239, 125, 0.15);
}
.palette-item canvas {
  width: 36px;
  height: 36px;
}

/* ============ MODAL ============ */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: #1a1a2e;
  border: 2px solid #444;
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-content h3 { margin-bottom: 16px; text-align: center; }

/* ============ GAME ============ */
#screen-game {
  flex-direction: column;
  background: #0a1628;
}
.game-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}
.game-hud-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 6px 12px;
  background: rgba(0,0,0,0.6);
  min-height: 44px;
  z-index: 10;
}
.score-blue, .score-red {
  font-size: 28px;
  font-weight: 900;
  min-width: 50px;
  text-align: center;
  padding: 4px 16px;
  border-radius: 10px;
}
.score-blue { background: rgba(66, 133, 244, 0.3); color: #4285f4; }
.score-red { background: rgba(234, 67, 53, 0.3); color: #ea4335; }
.game-info {
  font-size: 16px;
  font-weight: 700;
  color: #ccc;
  min-width: 100px;
  text-align: center;
}
#btn-game-back { margin-left: auto; }
.game-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
  pointer-events: none;
}
.game-overlay.hidden { display: none; }
.game-overlay-text {
  font-size: 72px;
  font-weight: 900;
  text-shadow: 0 0 30px rgba(0,0,0,0.8), 0 4px 8px rgba(0,0,0,0.6);
  color: #fff;
  animation: pulse-overlay 0.5s ease-in-out;
}
@keyframes pulse-overlay {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}
.game-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#game-canvas {
  display: block;
  position: absolute;
  top: 0; left: 0;
}
.game-controls {
  display: flex;
  height: 100px;
  background: rgba(0,0,0,0.6);
  z-index: 10;
}
.controls-left, .controls-right {
  flex: 1;
  display: flex;
  gap: 4px;
  padding: 6px;
}
.controls-left { border-right: 2px solid #333; }
.ctrl-btn {
  flex: 1;
  border: none;
  border-radius: 12px;
  font-size: 36px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.05s;
  min-height: 80px;
}
.ctrl-btn:active { transform: scale(0.93); }
.ctrl-blue {
  background: linear-gradient(135deg, #1a5276, #2980b9);
  color: #85c1e9;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,0.3);
}
.ctrl-blue:active { background: linear-gradient(135deg, #2980b9, #3498db); }
.ctrl-red {
  background: linear-gradient(135deg, #922b21, #e74c3c);
  color: #f5b7b1;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,0.3);
}
.ctrl-red:active { background: linear-gradient(135deg, #cb4335, #ec7063); }

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .logo-crash { font-size: 36px; }
  .btn-large { width: 220px; padding: 14px 24px; font-size: 17px; }
  .game-overlay-text { font-size: 48px; }
  .ctrl-btn { font-size: 28px; min-height: 70px; }
  .game-controls { height: 85px; }
}
@media (max-height: 500px) {
  .game-controls { height: 70px; }
  .ctrl-btn { min-height: 58px; font-size: 24px; }
  .editor-palette { min-height: 58px; }
  .palette-item { min-width: 50px; height: 50px; }
}
