/* ==========================================
   VARIABLES Y RESET
   ========================================== */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --secondary: #ec4899;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;

  --bg-dark: #0f0f1a;
  --bg-card: rgba(255, 255, 255, 0.05);
  --bg-card-hover: rgba(255, 255, 255, 0.08);

  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-muted: rgba(255, 255, 255, 0.4);

  --border-color: rgba(255, 255, 255, 0.1);
  --glow: 0 0 40px rgba(99, 102, 241, 0.3);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.5;
}

/* ==========================================
   APP CONTAINER
   ========================================== */
.app {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at top, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(236, 72, 153, 0.1) 0%, transparent 50%),
    var(--bg-dark);
  padding: 20px;
  padding-bottom: env(safe-area-inset-bottom, 20px);
  overflow-y: auto;
  height: 100vh;
}

/* ==========================================
   SCREENS
   ========================================== */
.screen {
  display: none;
  flex-direction: column;
  min-height: calc(100vh - 40px);
  animation: fadeIn 0.3s ease;
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================
   HOME SCREEN
   ========================================== */
.logo-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.logo {
  font-size: 80px;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-10px);
  }
}

.logo-container h1 {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-light), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.tagline {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

/* ==========================================
   BUTTONS
   ========================================== */
.button-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 40px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 24px;
  border: none;
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon {
  font-size: 1.3rem;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: var(--glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 50px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
}

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

.btn-full {
  width: 100%;
}

.btn-back {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  color: var(--text-primary);
  font-size: 1.3rem;
  cursor: pointer;
  transition: all 0.2s;
}

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

/* ==========================================
   FORMS
   ========================================== */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  transition: all 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

#create-screen,
#join-screen {
  padding-top: 80px;
}

#create-screen h2,
#join-screen h2 {
  font-size: 1.5rem;
  margin-bottom: 30px;
  text-align: center;
}

/* ==========================================
   LOBBY SCREEN
   ========================================== */
.room-header {
  text-align: center;
  padding: 30px 20px;
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-color);
  margin-bottom: 24px;
}

.room-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.room-code {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 8px;
  background: linear-gradient(135deg, var(--primary-light), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-top: 8px;
}

.players-section h3,
.settings-section h3 {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.players-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.players-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.player-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.player-name {
  flex: 1;
  font-weight: 500;
}

.host-badge {
  font-size: 0.75rem;
  padding: 4px 8px;
  background: var(--warning);
  color: #000;
  border-radius: 20px;
  font-weight: 600;
}

.settings-section {
  background: var(--bg-card);
  padding: 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.setting-row:last-of-type {
  border-bottom: none;
  margin-bottom: 16px;
}

.setting-row select {
  width: auto;
  min-width: 150px;
}

.waiting-message {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-secondary);
}

/* ==========================================
   SPINNER
   ========================================== */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.spinner.small {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================
   ROLE SCREEN
   ========================================== */
.role-reveal {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.role-card {
  width: 280px;
  height: 380px;
  perspective: 1000px;
  cursor: pointer;
  margin-bottom: 30px;
}

.role-card.flipped .role-front {
  transform: rotateY(180deg);
}

.role-card.flipped .role-back {
  transform: rotateY(0);
}

.role-front,
.role-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.6s ease;
  padding: 30px;
}

.role-front {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border: 2px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
}

.role-front>*,
.role-back>* {
  pointer-events: none;
  /* Asegura que el click vaya a la carta */
}

.role-front p {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 16px;
  color: white;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.tap-icon {
  font-size: 3rem;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
}

.role-back {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  transform: rotateY(-180deg);
}

.role-back.impostor {
  background: linear-gradient(135deg, #7f1d1d, #991b1b);
  border-color: #dc2626;
}

.role-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.role-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.role-word {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-light), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  padding: 16px 24px;
  border: 2px dashed var(--primary);
  border-radius: var(--radius-md);
}

.role-back.impostor .role-word {
  background: linear-gradient(135deg, #fca5a5, #f87171);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  border-color: #dc2626;
}

.role-hint {
  margin-top: 20px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.role-instruction {
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* ==========================================
   VOTING SCREEN
   ========================================== */
.word-reminder {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 20px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(236, 72, 153, 0.1));
  border: 1px solid var(--primary);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
}

.word-reminder.impostor {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(127, 29, 29, 0.2));
  border-color: var(--danger);
}

.reminder-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.reminder-word {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary-light);
}

.word-reminder.impostor .reminder-word {
  color: var(--danger);
}

#voting-screen h2 {
  text-align: center;
  margin-bottom: 8px;
}

.voting-subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 30px;
}

.vote-players {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.vote-player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
}

.vote-player:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
}

.vote-player.selected {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--primary);
}

.vote-player.voted {
  opacity: 0.5;
  pointer-events: none;
}

.vote-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
}

/* ==========================================
   RESULTS SCREEN
   ========================================== */
.results-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 40px;
  text-align: center;
}

.result-icon {
  font-size: 5rem;
  margin-bottom: 16px;
  animation: bounce 0.5s ease;
}

@keyframes bounce {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.2);
  }
}

.results-content h2 {
  font-size: 1.8rem;
  margin-bottom: 8px;
}

.result-eliminated {
  color: var(--text-secondary);
  margin-bottom: 30px;
}

.result-reveal {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
}

.reveal-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 0;
}

.reveal-item:not(:last-child) {
  border-bottom: 1px solid var(--border-color);
}

.reveal-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.reveal-word {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-light);
}

.reveal-impostors {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--danger);
}

.votes-breakdown {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 24px;
}

.votes-breakdown h4 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.votes-breakdown ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.votes-breakdown li {
  font-size: 0.9rem;
  color: var(--text-secondary);
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
}

/* ==========================================
   TOAST
   ========================================== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 14px 24px;
  background: var(--danger);
  color: white;
  border-radius: var(--radius-lg);
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  max-width: calc(100% - 40px);
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 380px) {
  .logo {
    font-size: 60px;
  }

  .logo-container h1 {
    font-size: 2rem;
  }

  .room-code {
    font-size: 2.5rem;
    letter-spacing: 6px;
  }

  .role-card {
    width: 250px;
    height: 340px;
  }
}

@media (min-width: 600px) {
  .app {
    max-width: 500px;
    margin: 0 auto;
  }
}

/* ==========================================
   LOCAL MODE & NEW FEATURES
   ========================================== */

.setting-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.toggle-checkbox {
  -webkit-appearance: none;
  appearance: none;
  width: 50px;
  height: 28px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  position: relative;
  cursor: pointer;
  transition: all 0.3s;
}

.toggle-checkbox::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.toggle-checkbox:checked {
  background: var(--primary);
  border-color: var(--primary);
}

.toggle-checkbox:checked::after {
  transform: translateX(22px);
  background: white;
}

/* Local Player Input */
.local-players-input {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.players-list.small li {
  padding: 10px 14px;
  font-size: 0.9rem;
}

.btn-remove-player {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px;
}

/* Pass Device Screen - Improved */
.app-center-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 20px;
  padding: 20px;
}

/* Redefinido para que funcione como cortina */
.pass-device-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-card);
  padding: 30px;
  text-align: center;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  width: 100%;
  margin-top: 50px;
  margin-bottom: 50px;
}

.icon-pulse {
  font-size: 5rem;
  animation: pulse 2s infinite;
  margin-bottom: 20px;
}

.pass-device-title {
  font-size: 2rem;
  color: var(--primary);
  margin-bottom: 10px;
  font-weight: bold;
}

.pass-player-name {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text-primary);
  background: var(--bg-body);
  padding: 15px 30px;
  border-radius: 50px;
  margin: 20px 0;
  border: 2px solid var(--primary);
  display: inline-block;
}

.pass-instruction {
  font-size: 1.1rem;
  opacity: 0.8;
  margin-bottom: 30px;
}

/* Vote Actions */
.vote-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

#btn-confirm-vote:disabled {
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
  border: 1px solid var(--border-color);
}

.round-indicator {
  text-align: center;
  margin-bottom: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.9rem;
}

/* ==========================================
   INSTRUCTIONS MODAL
   ========================================== */
.btn-text {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 10px;
  cursor: pointer;
  transition: color 0.2s;
}

.btn-text:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(15, 15, 26, 0.9);
  backdrop-filter: blur(5px);
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: #1e1e2d;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  padding: 24px;
  position: relative;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.3s ease;
}

.modal-content h2 {
  font-size: 1.5rem;
  margin-bottom: 20px;
  color: var(--primary-light);
  text-align: center;
}

.instructions-body {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.6;
}

.instructions-body h3 {
  color: var(--text-primary);
  margin-top: 20px;
  margin-bottom: 10px;
  font-size: 1.1rem;
}

.instructions-body ol,
.instructions-body ul {
  padding-left: 20px;
  margin-bottom: 10px;
}

.instructions-body li {
  margin-bottom: 6px;
}

.close-modal {
  position: absolute;
  top: 16px;
  right: 20px;
  font-size: 28px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
}

.close-modal:hover {
  color: var(--text-primary);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}