:root {
  --bg: #0c0e10;
  --panel: #161a1f;
  --accent: #c9a227;
  --accent-dim: #7a5e1a;
  --accent-glow: rgba(201,162,39,0.2);
  --text: #e8dcc0;
  --text-dim: #a09888;
  --green: #3d9e58;
  --blue: #5a8ec8;
  --red: #d13a35;
  --border: #2a2e35;
  --border-light: #3a3e45;
  --card-bg: #1e2228;
  --card-bg-hover: #252a32;
  --input-bg: #0c0e10;
  --danger: #c0392b;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'VT323', monospace;
}

input, button, textarea, select { font-family: inherit; }

button:focus-visible,
input:focus-visible,
.class-card:focus-visible,
.color-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* LOBBY — único scroll */
#lobby-screen {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background: radial-gradient(circle at 50% 30%, #1a1e24 0%, var(--bg) 70%);
  padding: 12px;
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
}

#lobby-screen.hidden {
  display: none !important;
  pointer-events: none;
}

.lobby-container {
  width: 720px;
  max-width: 100%;
  margin: 0 auto 24px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 20px 20px 0;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.03);
  position: relative;
}

.logo-area { text-align: center; margin-bottom: 12px; }
.logo-icon { font-size: 40px; line-height: 1; margin-bottom: 2px; }

h1 {
  font-family: 'Cinzel', serif;
  font-size: 28px;
  color: var(--accent);
  text-shadow: 0 2px 10px rgba(201,162,39,0.25);
  margin: 0 0 4px;
  letter-spacing: 1px;
}

.subtitle { color: var(--text-dim); font-size: 14px; margin: 0; }

.lobby-panel { display: none; }
.lobby-panel.active { display: block; }

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-family: 'Cinzel', serif;
  font-size: 18px;
  color: var(--accent);
}

.btn-icon {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.name-row { display: flex; justify-content: center; margin-bottom: 12px; }

#player-name {
  background: var(--input-bg);
  border: 1px solid var(--border-light);
  color: var(--text);
  padding: 10px 16px;
  font-size: 20px;
  border-radius: 8px;
  width: 260px;
  max-width: 100%;
  text-align: center;
}

#player-name::placeholder { color: var(--text-dim); }
#player-name:focus {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
  outline: none;
}

.section-title {
  font-family: 'Cinzel', serif;
  font-size: 14px;
  color: var(--accent);
  margin: 10px 0 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.class-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.class-card {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 10px 6px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.class-card.selected {
  border-color: var(--accent);
  background: var(--card-bg-hover);
  box-shadow: 0 0 14px var(--accent-glow);
}

.class-icon { font-size: 24px; line-height: 1.2; }
.class-name { font-size: 14px; font-weight: bold; color: var(--text); }
.class-tag { font-size: 11px; color: var(--text-dim); }
.class-ult { font-size: 10px; color: var(--accent); margin-top: 2px; font-weight: bold; }

.creator-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.creator-colors {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1 1 160px;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.color-row label {
  font-size: 12px;
  color: var(--text-dim);
  min-width: 32px;
}

.color-btn {
  width: 22px;
  height: 22px;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  margin: 0;
  -webkit-tap-highlight-color: transparent;
}

.color-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 6px rgba(201,162,39,0.5);
}

.preview-box {
  width: 72px;
  height: 72px;
  background: var(--input-bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  flex-shrink: 0;
}

.preview-box canvas {
  image-rendering: pixelated;
  max-width: 100%;
  max-height: 100%;
}

.tips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 10px;
}

.tip {
  background: rgba(201,162,39,0.08);
  border: 1px solid rgba(201,162,39,0.15);
  color: var(--text-dim);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
}

.button-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}

/* BOTONES SIEMPRE VISIBLES */
.lobby-actions {
  position: sticky;
  bottom: 0;
  z-index: 20;
  margin: 0 -20px;
  padding: 12px 20px max(14px, env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(22,26,31,0) 0%, var(--panel) 28%);
  border-top: 1px solid var(--border);
}

.btn-primary,
.btn-secondary,
.btn-small {
  font-family: 'VT323', monospace;
  font-size: 17px;
  padding: 13px 22px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.1s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.btn-primary {
  background: linear-gradient(180deg, #f0d870 0%, #c9a227 55%, #a8841c 100%);
  color: #1a1400;
  font-weight: bold;
  box-shadow:
    0 4px 14px rgba(201,162,39,0.3),
    inset 0 1px 0 rgba(255,255,200,0.35);
  border: 1px solid rgba(255,230,120,0.25);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow: 0 5px 18px rgba(201,162,39,0.4);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(201,162,39,0.25);
}

.btn-primary:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  filter: grayscale(0.3);
}

.btn-glow {
  animation: btnGlow 2s ease-in-out infinite;
}

@keyframes btnGlow {
  0%, 100% { box-shadow: 0 4px 14px rgba(201,162,39,0.3), inset 0 1px 0 rgba(255,255,200,0.35); }
  50% { box-shadow: 0 4px 22px rgba(201,162,39,0.55), 0 0 18px rgba(201,162,39,0.25), inset 0 1px 0 rgba(255,255,200,0.35); }
}

.btn-secondary {
  background: linear-gradient(180deg, #2a3038, var(--border));
  color: var(--text);
  border: 1px solid var(--border-light);
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.btn-secondary:hover {
  background: linear-gradient(180deg, #323840, #2a3038);
}

.btn-secondary:active {
  transform: scale(0.97);
}

.btn-small {
  font-size: 13px;
  padding: 7px 13px;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border-light);
  border-radius: 8px;
}

.btn-small:hover {
  background: var(--card-bg-hover);
}

.camp-search { margin-bottom: 10px; }

.camp-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  background: var(--input-bg);
  border-radius: 8px;
  max-height: 140px;
  overflow-y: auto;
  border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

.camp-list li {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.camp-list li:last-child { border-bottom: none; }

.camp-list .empty {
  color: var(--text-dim);
  text-align: center;
  padding: 18px;
  font-style: italic;
}

.camp-code {
  font-weight: bold;
  color: var(--accent);
  letter-spacing: 1px;
}

.or-divider {
  color: var(--text-dim);
  margin: 12px 0;
  font-size: 13px;
  text-align: center;
}

.flex-row {
  display: flex;
  gap: 8px;
  width: 100%;
  align-items: center;
}

.flex-row input {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border-light);
  color: var(--text);
  padding: 10px 12px;
  font-size: 18px;
  border-radius: 8px;
  text-align: center;
}

.error-msg {
  color: var(--red);
  font-size: 13px;
  text-align: center;
  margin-top: 8px;
  min-height: 18px;
}

.lobby-code-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--input-bg);
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.code-label { color: var(--text-dim); font-size: 14px; }

.code-value {
  color: var(--accent);
  font-size: 24px;
  letter-spacing: 3px;
  font-weight: bold;
}

.lobby-status {
  color: var(--text-dim);
  text-align: center;
  font-size: 14px;
  margin: 6px 0;
}

.player-roster {
  list-style: none;
  padding: 0;
  margin: 8px 0 14px;
  max-height: 160px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.player-roster li {
  padding: 6px 10px;
  background: var(--input-bg);
  margin-bottom: 4px;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.player-roster li.you {
  color: var(--accent);
  border-color: var(--accent-dim);
}

/* GAME */
#game-screen {
  position: fixed;
  inset: 0;
  z-index: 2;
  background: var(--bg);
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

#game-screen.hidden {
  display: none !important;
  pointer-events: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #1a2b1e;
  touch-action: none;
}

body.playing { overflow: hidden !important; }

.touch-zone {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: 5;
  touch-action: none;
}
.touch-zone--left { left: 0; }
.touch-zone--right { right: 0; }

.joystick {
  position: absolute;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: 2px solid rgba(255,255,255,0.12);
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transform: translate(-50%, -50%);
}

.joystick-knob {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(201,162,39,0.35);
  border: 2px solid rgba(201,162,39,0.55);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.weapon-bar {
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 20;
  background: rgba(12,14,16,0.85);
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.weapon-btn {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  background: linear-gradient(160deg, #252a32, var(--card-bg));
  border: 2px solid var(--border);
  color: var(--text);
  font-family: 'VT323', monospace;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

.weapon-btn:active {
  transform: scale(0.92);
}

.weapon-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow), 0 2px 8px rgba(0,0,0,0.35);
  background: linear-gradient(160deg, #3a3420, #252018);
}

.ability-btn {
  position: absolute;
  bottom: max(72px, calc(env(safe-area-inset-bottom, 0px) + 60px));
  right: max(14px, env(safe-area-inset-right, 0px));
  z-index: 30;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--accent), var(--danger));
  color: var(--bg);
  font-weight: bold;
  font-size: 14px;
  font-family: 'VT323', monospace;
  border: 3px solid rgba(255,255,255,0.2);
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.ability-btn.pressed { transform: scale(0.92); }

.countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  background: rgba(0,0,0,0.4);
  pointer-events: none;
}

.countdown-number {
  font-family: 'Cinzel', serif;
  font-size: 100px;
  color: var(--accent);
  text-shadow: 0 0 40px rgba(201,162,39,0.6);
}

.kill-streak-banner {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: linear-gradient(90deg, transparent, rgba(201,162,39,0.15), transparent);
  padding: 8px 28px;
  border-top: 1px solid rgba(201,162,39,0.3);
  border-bottom: 1px solid rgba(201,162,39,0.3);
}

.kill-streak-banner span {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  color: var(--accent);
}

.damage-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 45;
}

.damage-flash.active {
  box-shadow: inset 0 0 80px rgba(209,58,53,0.5);
}

.hidden { display: none !important; }

@media (max-width: 600px) {
  #lobby-screen {
    padding: 8px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }

  .lobby-container {
    padding: 14px 12px 0;
    border-radius: 10px;
  }

  h1 { font-size: 22px; }
  .logo-icon { font-size: 32px; }
  .subtitle { font-size: 13px; }

  .class-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .class-card { padding: 8px 4px; }
  .class-icon { font-size: 22px; }
  .preview-box { width: 64px; height: 64px; }
  .tips-row { display: none; }

  .lobby-actions {
    margin: 0 -12px;
    padding: 10px 12px max(12px, env(safe-area-inset-bottom, 0px));
  }

  .lobby-actions .btn-primary,
  .lobby-actions .btn-secondary {
    flex: 1 1 auto;
    min-width: 0;
    padding: 14px 10px;
    font-size: 16px;
  }
}

@media (pointer: fine) {
  .touch-zone,
  .joystick { display: none !important; }
}

@media (pointer: coarse) {
  .touch-zone { display: block; }
  .ability-btn { width: 76px; height: 76px; }
  .weapon-btn { width: 48px; height: 48px; }
}

@media screen and (orientation: portrait) and (max-width: 900px) {
  #game-screen:not(.hidden)::before {
    content: "🔄 Rotate to landscape";
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    background: rgba(0,0,0,0.8);
    color: var(--accent);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    pointer-events: none;
    white-space: nowrap;
  }
  }
