:root {
  --bg-light: #e0f2fe;
  --bg-gradient-1: #f0f9ff;
  --bg-gradient-2: #dbeafe;
  --primary-blue: #1e3a8a;
  --primary-blue-hover: #1e40af;
  --accent-orange: #f97316;
  --accent-orange-hover: #ea580c;
  --text-dark: #0f172a;
  --text-light: #475569;
  --white: #ffffff;
  --success: #10b981;
  --danger: #ef4444;
  --border-light: #e2e8f0;
  --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --card-red: #dc2626;
  --card-black: #1e293b;
}

* { box-sizing: border-box; }

body {
  font-family: 'Manrope', sans-serif;
  background: linear-gradient(135deg, var(--bg-gradient-1) 0%, var(--bg-gradient-2) 100%);
  min-height: 100vh;
  color: var(--text-dark);
  overflow-x: hidden;
}

body::before, body::after { display: none; }
.display-font { font-family: 'Manrope', sans-serif; font-weight: 800; }
.app-container { position: relative; z-index: 2; }

.header-logo { height: 45px; width: auto; max-width: 150px; object-fit: contain; }
.timer-display {
  font-family: 'Manrope', sans-serif; font-weight: 800; font-size: 22px;
  color: var(--primary-blue); background: var(--white); padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--border-light); box-shadow: var(--shadow-soft);
}
.timer-display.warning { color: var(--danger); border-color: var(--danger); animation: pulse-warn 1s infinite; }
@keyframes pulse-warn { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

.game-header {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-light);
  box-shadow: var(--shadow-soft);
}

.title-glow {
  background: linear-gradient(90deg, var(--primary-blue) 0%, var(--accent-orange) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent; letter-spacing: -0.02em; font-weight: 900;
}

.scoreboard {
  background: var(--white); border: 1px solid var(--border-light); border-radius: 12px; box-shadow: var(--shadow-soft);
}
.score-num {
  font-family: 'Manrope', sans-serif; font-weight: 900; font-size: 32px; line-height: 1; color: var(--primary-blue); transition: all 0.3s ease;
}
.score-num.losing { color: #cbd5e1; }
.score-num.bump { animation: score-bump 0.5s ease-out; }
@keyframes score-bump { 0% { transform: scale(1); } 50% { transform: scale(1.2); color: var(--accent-orange); } 100% { transform: scale(1); } }

.game-table {
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  border-radius: 16px; border: 4px solid var(--primary-blue);
  box-shadow: var(--shadow-hover); position: relative; min-height: 620px; padding: 24px 16px; overflow: hidden;
}

.card {
  width: 105px; height: 150px; background: var(--white); border-radius: 8px; border: 1px solid var(--border-light);
  box-shadow: var(--shadow-soft); position: relative; cursor: pointer; transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex; flex-direction: column; padding: 0 !important; user-select: none; flex-shrink: 0; overflow: hidden;
}
.card.red { color: var(--card-red); }
.card.black { color: var(--card-black); }
.card img {
  display: block; 
  width: calc(100% - 4px); 
  height: calc(100% - 8px); 
  object-fit: contain; pointer-events: none; 
  margin: 4px 2px; border-radius: 6px;
}
.card.playable:hover { transform: translateY(-12px); box-shadow: var(--shadow-hover); border-color: var(--accent-orange); z-index: 10; }
.card.disabled { opacity: 0.6; cursor: not-allowed; filter: grayscale(0.3); }

.card.flipped {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  cursor: default; border-color: var(--primary-blue);
  display: flex; align-items: center; justify-content: center;
}
.card.flipped img { width: calc(100% - 8px); height: calc(100% - 16px); margin: 8px 4px; }
.card.flipped::before { display: none; }
.card-corner, .card-center, .card-num, .suit-svg { display: none; }

.played-area { display: flex; justify-content: center; align-items: center; min-height: 340px; z-index: 2; }
.played-center-wrap { display: flex; flex-direction: row; gap: 15px; align-items: center; justify-content: center; width: 100%; max-width: 400px; }
.played-round { display: flex; flex-direction: column; align-items: center; position: relative; width: 105px; height: 215px; }
.played-round > *:nth-child(2) { margin-top: -85px; z-index: 2; }
.played-card-wrapper { position: relative; width: 105px; height: 150px; }
.played-card-wrapper.winner .card { box-shadow: 0 0 0 3px var(--success), var(--shadow-hover); transform: scale(1.03); z-index: 3; }
.played-card-wrapper.loser .card { opacity: 0.5; filter: grayscale(0.5); }

.empty-slot {
  width: 105px; height: 150px; border: 2px dashed #cbd5e1; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; color: #94a3b8; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; font-weight: 700; background: rgba(255,255,255,0.5);
}

.deck-container { position: absolute; width: 105px; height: 150px; transition: all 0.5s ease; z-index: 1; display: flex; justify-content: center; align-items: center; }
.deck-container.top-left { left: 30px; top: 30px; }
.deck-container.bottom-right { right: 30px; bottom: 30px; }
.deck-container .card.flipped { position: absolute; width: 105px; height: 150px; }
.deck-label {
  position: absolute; top: -22px; font-size: 10px; color: var(--primary-blue); text-transform: uppercase; letter-spacing: 1px;
  font-weight: 700; white-space: nowrap; background: var(--white); padding: 2px 8px; border-radius: 4px; box-shadow: var(--shadow-soft);
}

.opponent-avatar {
  position: absolute; top: 10px; right: 10px; width: 80px; height: 80px; border-radius: 50%; border: 3px solid var(--primary-blue); background-size: cover; background-position: center; box-shadow: var(--shadow-soft); z-index: 5;
}

/*
@keyframes deal-top { 0% { transform: translate(0, -300px) rotate(180deg) scale(0.5); opacity: 0; } 100% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; } }
@keyframes deal-bottom { 0% { transform: translate(0, 300px) rotate(-180deg) scale(0.5); opacity: 0; } 100% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; } }
.deal-top { animation: deal-top 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards; }
.deal-bottom { animation: deal-bottom 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards; }
*/
@keyframes play-card { 0% { transform: scale(0.5) rotate(-90deg); opacity: 0; } 60% { transform: scale(1.1) rotate(5deg); opacity: 1; } 100% { transform: scale(1) rotate(0); opacity: 1; } }
.play-anim { animation: play-card 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes message-pop { 0% { transform: scale(0.5); opacity: 0; } 50% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
.message-pop { animation: message-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }

.btn-canto {
  background: var(--white); color: var(--primary-blue); border: 1px solid var(--border-light); padding: 10px 16px; border-radius: 4px;
  font-family: 'Manrope', sans-serif; font-weight: 700; font-size: 13px; letter-spacing: 0.5px; cursor: pointer; transition: all 0.2s ease; text-transform: uppercase; box-shadow: var(--shadow-soft);
}
.btn-canto:hover:not(:disabled) { transform: translateY(-2px); box-shadow: var(--shadow-hover); color: var(--primary-blue-hover); border-color: var(--primary-blue); }
.btn-canto:active:not(:disabled) { transform: translateY(0); }
.btn-canto:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; background: #f8fafc; }
.btn-canto.danger { background: var(--danger); border-color: var(--danger); color: var(--white); box-shadow: var(--shadow-soft); }
.btn-canto.danger:hover:not(:disabled) { background: #dc2626; color: var(--white); border-color: #dc2626; }
.btn-canto.primary { background: var(--primary-blue); border-color: var(--primary-blue); color: var(--white); box-shadow: var(--shadow-soft); }
.btn-canto.primary:hover:not(:disabled) { background: var(--primary-blue-hover); color: var(--white); border-color: var(--primary-blue-hover); }
.btn-canto.success { background: var(--success); border-color: var(--success); color: var(--white); box-shadow: var(--shadow-soft); }
.btn-canto.success:hover:not(:disabled) { background: #059669; color: var(--white); border-color: #059669; }

.opponent-card {
  border: 2px solid var(--border-light); border-radius: 12px; padding: 16px; cursor: pointer; transition: all 0.2s; background: #fff; text-align: center;
}
.opponent-card:hover { border-color: var(--primary-blue); transform: translateY(-4px); box-shadow: var(--shadow-hover); }
.opponent-img { 
  width: 100px; 
  height: 100px; 
  max-width: 100%; /* Evita que se desborde en celular */
  border-radius: 50%; 
  object-fit: cover; 
  margin: 0 auto; 
  border: 3px solid var(--primary-blue); 
}
.ranking-entry { display: flex; justify-content: space-between; padding: 8px; border-bottom: 1px solid var(--border-light); font-size: 14px; }
.ranking-entry:nth-child(1) { color: var(--accent-orange); font-weight: 900; }

.panel { background: var(--white); border: 1px solid var(--border-light); border-radius: 12px; box-shadow: var(--shadow-soft); }
.panel-title { font-weight: 800; letter-spacing: 1px; text-transform: uppercase; font-size: 11px; color: var(--text-light); text-align: center; padding: 10px 0; border-bottom: 1px solid var(--border-light); }

.log-area { max-height: 280px; overflow-y: auto; padding: 8px; }
.log-area::-webkit-scrollbar { width: 6px; }
.log-area::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 3px; }
.log-area::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.log-entry { padding: 8px 12px; border-left: 3px solid var(--border-light); margin-bottom: 6px; font-size: 12px; background: #f8fafc; border-radius: 0 6px 6px 0; animation: slide-in 0.3s ease-out; line-height: 1.4; color: var(--text-dark); }
.log-entry.player { border-left-color: var(--accent-orange); }
.log-entry.opponent { border-left-color: var(--primary-blue); }
.log-entry.system { border-left-color: var(--text-light); color: var(--text-light); font-style: italic; }
.log-entry.win { border-left-color: var(--success); color: var(--success); font-weight: 700; }
.log-entry.lose { border-left-color: var(--danger); color: var(--danger); }

@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.toast-wrapper { position: fixed; z-index: 400; pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.toast { background: var(--primary-blue); color: var(--white); padding: 14px 32px; border-radius: 8px; border: none; font-weight: 800; font-size: 24px; letter-spacing: 1px; text-transform: uppercase; box-shadow: var(--shadow-hover); animation: toast-anim 2.5s ease-out forwards; max-width: 90vw; text-align: center; box-sizing: border-box; }
.toast-comic { background: var(--white); color: var(--text-dark); border: 2px solid var(--primary-blue); border-radius: 16px; padding: 12px 18px; font-size: 14px; font-weight: 600; max-width: 280px; width: max-content; max-width: 80vw; text-align: center; box-shadow: var(--shadow-soft); line-height: 1.4; animation: toast-anim-long 4s ease-out forwards; position: relative; }
.toast-comic.tail-down::after { content: ''; position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%) rotate(45deg); width: 12px; height: 12px; background: var(--white); border-right: 2px solid var(--primary-blue); border-bottom: 2px solid var(--primary-blue); }
.toast-comic.tail-up::before { content: ''; position: absolute; top: -8px; left: 50%; transform: translateX(-50%) rotate(45deg); width: 12px; height: 12px; background: var(--white); border-left: 2px solid var(--primary-blue); border-top: 2px solid var(--primary-blue); }
.toast.toast-long { font-size: 18px; padding: 12px 20px; }

@keyframes toast-anim { 0% { transform: scale(0.3); opacity: 0; } 15% { transform: scale(1.1); opacity: 1; } 20% { transform: scale(1); opacity: 1; } 85% { transform: scale(1); opacity: 1; } 100% { transform: scale(0.9) translateY(-30px); opacity: 0; } }
@keyframes toast-anim-long { 0% { transform: scale(0.3); opacity: 0; } 10% { transform: scale(1.1); opacity: 1; } 15% { transform: scale(1); opacity: 1; } 85% { transform: scale(1); opacity: 1; } 100% { transform: scale(0.9) translateY(-30px); opacity: 0; } }

.modal-overlay { 
  position: fixed; 
  inset: 0; 
  background: rgba(15, 23, 42, 0.35); 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  z-index: 300; 
  animation: fade-in 0.3s ease-out; 
  padding: 20px; 
  box-sizing: border-box; 
  overflow-y: auto; /* Permite scrollear si el contenido es más alto que la pantalla */
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-content { background: var(--white); border: 1px solid var(--border-light); border-radius: 12px; padding: 32px 40px; max-width: 90%; width: auto; text-align: center; box-shadow: var(--shadow-hover); animation: modal-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes modal-pop { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.modal-title { font-weight: 900; font-size: 28px; color: var(--primary-blue); margin-bottom: 12px; }
.modal-text { font-size: 16px; margin-bottom: 24px; color: var(--text-light); }
.modal-buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.status-message { font-weight: 700; font-size: 15px; color: var(--primary-blue); text-align: center; padding: 12px 24px; background: rgba(255,255,255,0.8); border-radius: 8px; border: 1px solid var(--border-light); margin: 0 auto; max-width: 90%; min-height: 50px; display: flex; align-items: center; justify-content: center; }

.round-indicators { display: flex; gap: 8px; justify-content: center; margin: 6px 0; position: relative; z-index: 3; }
.round-dot { width: 12px; height: 12px; border-radius: 50%; background: #e2e8f0; border: 1px solid #cbd5e1; transition: all 0.3s ease; }
.round-dot.won { background: var(--success); border-color: var(--success); box-shadow: 0 0 8px rgba(16, 185, 129, 0.5); }
.round-dot.lost { background: var(--danger); border-color: var(--danger); box-shadow: 0 0 8px rgba(239, 68, 68, 0.5); }

.mano-indicator { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 4px; font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--primary-blue); }
.mano-indicator .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-orange); animation: pulse-dot 1.5s infinite; }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.info-display { position: absolute; background: var(--white); border-radius: 6px; padding: 6px 12px; font-weight: 700; font-size: 11px; letter-spacing: 0.5px; text-transform: uppercase; box-shadow: var(--shadow-soft); z-index: 5; border: 1px solid var(--border-light); }
.truco-display { top: 16px; left: 50%; transform: translateX(-50%); border-color: var(--accent-orange); color: var(--accent-orange); }
.envido-display { bottom: 16px; left: 50%; transform: translateX(-50%); border-color: var(--primary-blue); color: var(--primary-blue); }

.hand-area { display: flex; justify-content: center; gap: 15px; min-height: 160px; align-items: center; padding: 4px; border-radius: 12px; transition: background 0.4s ease; position: relative; z-index: 3; }
.hand-area.opponent { margin-bottom: 8px; }
.hand-area.player { margin-top: 8px; }
.hand-area.active { background: radial-gradient(ellipse at center, rgba(30, 58, 138, 0.05) 0%, transparent 70%); }

@media (max-width: 1024px) { 
  .game-table { min-height: 540px; padding: 16px 10px; } 
  .card { width: 85px; height: 120px; } 
  .empty-slot { width: 85px; height: 120px; } 
  .played-round { width: 85px; height: 165px; }
  .played-round > *:nth-child(2) { margin-top: -75px; } 
  .played-card-wrapper { width: 85px; height: 120px; }
  .deck-container { width: 85px; height: 120px; } 
  .deck-container .card.flipped { width: 85px; height: 120px; } 
  .hand-area { min-height: 130px; }
  .opponent-avatar { width: 60px; height: 60px; }
}
@media (max-width: 640px) {
  .modal-overlay {
    align-items: flex-start;
  }
  .modal-content {
    width: 100%;
    max-width: 100%;
    margin-top: 20px;
  }
}

.hidden { display: none !important; }