:root {
  --bg-dark: #101520;
  --bamboo-gold: #e8b347;
  --chile-red: #d92b3a;
  --chile-blue: #1a54a6;
  --panel-bg: #182030;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, #23334e 0%, #0d121c 75%);
  color: #f7f4ea;
  font-family: "Trebuchet MS", "Arial Black", Impact, system-ui, sans-serif;
}

#arcade-shell {
  width: 100vw;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  gap: 6px;
  touch-action: none;
}

#mobile-toggle-btn {
  background: #23334e;
  color: #ffe066;
  border: 1.5px solid #e8b347;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

#touch-controls button.pressed {
  transform: scale(0.9);
  filter: brightness(1.25);
}

#game-wrapper {
  position: relative;
  width: min(1280px, 98vw, calc((100vh - 102px) * 16 / 9));
  aspect-ratio: 16 / 9;
  height: auto;
  border: 4px solid var(--bamboo-gold);
  border-radius: 10px;
  box-shadow:
    0 0 0 3px #1b140a,
    0 18px 48px rgba(0, 0, 0, 0.72),
    0 0 32px rgba(232, 179, 71, 0.25);
  background: #0a0f18;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* Barra superior de sesión + contador diario */
#session-bar {
  width: min(1280px, 98vw, calc((100vh - 102px) * 16 / 9));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 14px;
  background: rgba(14, 20, 34, 0.92);
  border: 2px solid rgba(232, 179, 71, 0.55);
  border-radius: 999px;
  font-size: 13px;
  color: #f7f4ea;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.session-user {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  color: #ffe28a;
  white-space: nowrap;
}

.session-timer-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(24, 92, 56, 0.45);
  border: 1.5px solid #3dd68c;
  color: #e9fff3;
  font-weight: 900;
  letter-spacing: 0.3px;
}

.session-timer-pill.warn {
  background: rgba(168, 98, 12, 0.55);
  border-color: #ffbe3b;
  color: #fff2cc;
}

.session-timer-pill.danger {
  background: rgba(176, 22, 34, 0.7);
  border-color: #ff6b7a;
  color: #fff;
  animation: pulseTimer 1s infinite ease-in-out;
}

@keyframes pulseTimer {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.session-note {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.82;
}

#switch-code-btn {
  background: transparent;
  color: #c5d4ea;
  border: 1px solid rgba(232, 179, 71, 0.45);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

#switch-code-btn:hover {
  background: rgba(232, 179, 71, 0.18);
  color: #ffe28a;
}

/* Overlays de Código de Invitación y Tiempo Terminado */
.gate-overlay {
  position: absolute;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(10, 15, 28, 0.78) 0%, rgba(12, 16, 28, 0.92) 100%),
    url('assets/art/title_art.jpg') center / cover no-repeat;
  backdrop-filter: blur(4px);
}

.gate-card {
  width: min(500px, 94%);
  background: linear-gradient(180deg, rgba(22, 31, 50, 0.96) 0%, rgba(13, 18, 30, 0.98) 100%);
  border: 3px solid var(--bamboo-gold);
  border-radius: 16px;
  padding: 22px 26px;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.8),
    0 0 28px rgba(232, 179, 71, 0.25);
  text-align: center;
}

.gate-card-lock {
  border-color: #ff6b7a;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.85),
    0 0 28px rgba(217, 43, 58, 0.35);
}

.gate-kicker {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(217, 43, 58, 0.22);
  border: 1px solid rgba(255, 107, 122, 0.65);
  color: #ffd57e;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.2px;
  margin-bottom: 8px;
}

.gate-card h1,
.gate-card h2 {
  font-size: clamp(22px, 3vw, 30px);
  color: #ffe28a;
  text-shadow: 0 3px 0 #3a2305, 0 6px 18px rgba(0, 0, 0, 0.6);
  letter-spacing: 0.8px;
  margin-bottom: 4px;
}

.gate-subtitle {
  font-size: 13px;
  color: #cfe0f5;
  margin-bottom: 14px;
  line-height: 1.45;
}

.gate-rules {
  text-align: left;
  background: rgba(10, 15, 26, 0.72);
  border: 1px solid rgba(232, 179, 71, 0.35);
  border-radius: 10px;
  padding: 10px 13px;
  margin-bottom: 14px;
  font-size: 12px;
  line-height: 1.45;
  color: #e6ecf5;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

#invite-form {
  display: flex;
  flex-direction: column;
  gap: 7px;
  text-align: left;
}

.gate-label {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.9px;
  color: #f4c96b;
  margin-top: 2px;
}

#invite-form input {
  width: 100%;
  padding: 10px 13px;
  border-radius: 9px;
  border: 2px solid rgba(232, 179, 71, 0.55);
  background: #0c121e;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

#invite-form input:focus {
  border-color: #ffe28a;
  box-shadow: 0 0 0 3px rgba(232, 179, 71, 0.22);
}

#invite-nick-input {
  letter-spacing: 0.3px !important;
  font-weight: 700 !important;
}

.gate-error {
  margin-top: 4px;
  padding: 8px 11px;
  border-radius: 8px;
  background: rgba(217, 43, 58, 0.24);
  border: 1px solid #ff6b7a;
  color: #ffd9dd;
  font-size: 12.5px;
  font-weight: 700;
  text-align: center;
}

.gate-btn-primary {
  margin-top: 8px;
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #2b1d08;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffe28a 0%, #e59a24 100%);
  color: #1a1208;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.7px;
  cursor: pointer;
  box-shadow: 0 4px 0 #5b3808;
  transition: transform 0.08s ease, filter 0.12s ease;
}

.gate-btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.gate-btn-primary:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #5b3808;
}

.gate-btn-primary:disabled {
  opacity: 0.65;
  cursor: wait;
}

.gate-btn-secondary {
  margin-top: 8px;
  width: 100%;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1.5px solid rgba(232, 179, 71, 0.45);
  background: rgba(16, 24, 40, 0.8);
  color: #d4e2f4;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.gate-btn-secondary:hover {
  background: rgba(232, 179, 71, 0.16);
  color: #ffe28a;
}

.midnight-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 12px;
  margin: 12px 0;
  border-radius: 12px;
  background: rgba(10, 14, 24, 0.8);
  border: 1.5px solid rgba(255, 107, 122, 0.5);
}

.midnight-box span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #c5d4ea;
}

.midnight-box strong {
  font-size: 28px;
  color: #ffe28a;
  letter-spacing: 2px;
}

.gate-actions {
  display: flex;
  flex-direction: column;
}

#game-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
}

#controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 16px;
  padding: 6px 14px;
  background: rgba(16, 22, 34, 0.88);
  border: 2px solid rgba(232, 179, 71, 0.45);
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.3px;
  color: #e6ecf5;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.key {
  display: inline-block;
  padding: 2px 7px;
  background: linear-gradient(180deg, #ffe28a 0%, #d99726 100%);
  color: #1a1208;
  border: 1.5px solid #2b1d08;
  border-radius: 5px;
  font-weight: 900;
  font-size: 11px;
  box-shadow: 0 2px 0 #4d3209;
}

#touch-controls {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: 74px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  touch-action: none;
  -webkit-touch-callout: none;
  z-index: 999;
}

#touch-controls.hidden {
  display: none;
}

#touch-controls button {
  pointer-events: auto;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 3px solid rgba(255, 243, 207, 0.92);
  background: rgba(20, 30, 48, 0.72);
  color: #fff;
  font-weight: 900;
  font-size: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

.touch-dpad {
  display: flex;
  gap: 14px;
}

.touch-actions {
  display: grid;
  grid-template-columns: repeat(2, 62px);
  gap: 10px;
}

.btn-atk { background: rgba(217, 43, 58, 0.8) !important; }
.btn-spin { background: rgba(242, 134, 24, 0.8) !important; }
.btn-gary { background: rgba(26, 84, 166, 0.8) !important; }
.btn-jump { background: rgba(44, 150, 92, 0.8) !important; }

@media (max-width: 920px) {
  #controls-bar {
    display: none;
  }
  #session-bar {
    width: 98vw;
    font-size: 11px;
    padding: 4px 10px;
  }
  .session-note {
    display: none;
  }
  #touch-controls {
    bottom: 14px;
  }
  #game-wrapper {
    width: min(1280px, 100vw, calc((100dvh - 44px) * 16 / 9));
    border-width: 2px;
  }
}
