:root {
  --bg: transparent;
  --card: #1a0f08;
  --gold: #f1c40f;
  --red: #e74c3c;
  --green: #2ecc71;
  --text: #f3e5ab;
}

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

* { box-sizing: border-box; }

html {
  overflow-y: auto;
  scrollbar-gutter: stable;
}

html.modal-open,
body.modal-open {
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: linear-gradient(rgba(6, 13, 24, 0.45), rgba(6, 13, 24, 0.57)), url('images/backgrounds/bg-menu.jpg');
  font-family: 'Press Start 2P', monospace;
  color: var(--text);
  margin: 0;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  background-size: cover !important;
  background-position: center !important;
  background-repeat: no-repeat !important;
  background-attachment: fixed !important;
}

/* Clases dinámicas de fondo inyectadas desde showScreen() */
body.bg-menu {
  background: linear-gradient(rgba(6, 13, 24, 0.45), rgba(6, 13, 24, 0.57)), url('images/backgrounds/bg-menu.jpg');
}

body.bg-cabin {
  background: linear-gradient(rgba(6, 13, 24, 0.54), rgba(6, 13, 24, 0.66)), url('images/backgrounds/bg-cabin.jpg');
}

body.bg-game {
  background: linear-gradient(rgba(6, 13, 24, 0.54), rgba(6, 13, 24, 0.66)), url('images/backgrounds/bg-game.jpg');
}

body.bg-treasure {
  background: linear-gradient(rgba(6, 13, 24, 0.48), rgba(6, 13, 24, 0.6)), url('images/backgrounds/bg-treasure.jpg');
}

.app-container {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  border-radius: 6px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#screen-main-menu > p {
  text-shadow: 1px 2px 2px rgba(0, 0, 0, 0.75);
}

#screen-create-room,
#screen-join-room,
#screen-game-over,
.custom-modal-card {
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.75);
}

.card-game {
  background-color: rgba(26, 15, 8, 0.90) !important;
  border: 2px solid #8b5a2b !important;
  box-shadow: 0 0 25px rgba(0, 0, 0, 0.9), inset 0 0 20px rgba(0, 0, 0, 0.8) !important;
  border-radius: 6px !important;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#game-view {
  border-radius: 6px;
  padding: 12px;
}

#game-view .card {
  background-color: rgba(26, 15, 8, 0.80) !important; 
}

h2, h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 1rem;
  letter-spacing: 1px;
  margin: 0;
  color: var(--gold);
  text-align: center;
  text-shadow: 2px 2px #000000;
  line-height: 1.4;
}

.typing-effect::after {
  content: "|";
  animation: blink 0.7s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label { 
  font-size: 0.6rem; 
  color: #d4ac0d; 
  text-transform: uppercase; 
  line-height: 1.4;
}

input[type="text"] {
  padding: 12px;
  border-radius: 4px;
  border: 2px solid #5d4037;
  background: #000;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.65rem;
  width: 100%;
}

input[type="text"]::placeholder {
  color: #666;
  font-size: 0.6rem;
}

.btn-action {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.85rem;
  background: linear-gradient(to bottom, #d4ac0d, #b7950b);
  border: 3px solid #7d6608;
  color: #2c1e05;
  padding: 19px !important;
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
  text-shadow: 1px 1px rgba(255, 255, 255, 0.4);
  box-shadow: 0 4px 0 #5f4c04;
  text-transform: uppercase;
  transition: transform 0.05s ease, box-shadow 0.05s ease, background 0.05s ease;
}

.btn-action:hover:not(:disabled) {
  background: linear-gradient(to bottom, #f1c40f, #d4ac0d);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #5f4c04;
}

.btn-action:active:not(:disabled) {
  transform: scale(0.97) translateY(3px);
  box-shadow: 0 1px 0 #5f4c04;
}

.btn-action:disabled {
  background: #333;
  color: #666;
  border-color: #222;
  cursor: not-allowed;
  box-shadow: 0 2px 0 #111;
}

.btn-secondary {
  background: linear-gradient(to bottom, #34495e, #2c3e50);
  border: 3px solid #1a252f;
  color: #ecf0f1;
  text-shadow: 1px 1px #000;
  box-shadow: 0 4px 0 #11171d;
  transition: transform 0.05s ease, box-shadow 0.05s ease, background 0.05s ease;
}

.btn-secondary:hover {
  background: linear-gradient(to bottom, #415b76, #34495e);
  box-shadow: 0 6px 0 #11171d;
}

.btn-secondary:active:not(:disabled) {
  transform: scale(0.97) translateY(3px);
  box-shadow: 0 1px 0 #11171d;
}

.btn-action.btn-achievements {
  background: linear-gradient(to bottom, #36736a, #28584f);
  border-color: #193b35;
  color: #f3e5ab;
  text-shadow: 1px 1px #142e29;
  box-shadow: 0 4px 0 #142e29;
}

.btn-action.btn-achievements:hover:not(:disabled) {
  background: linear-gradient(to bottom, #43877c, #36736a);
  box-shadow: 0 6px 0 #142e29;
}

.btn-action.btn-achievements:active:not(:disabled) {
  transform: scale(0.97) translateY(3px);
  box-shadow: 0 1px 0 #142e29;
}

.btn-danger {
  background: linear-gradient(to bottom, #c0392b, #962d22);
  border: 2px solid #641e16;
  color: #fff;
  padding: 9px 17px;
  font-size: 0.75rem;
  font-family: 'Press Start 2P', monospace;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 3px 0 #4a150f;
  transition: transform 0.05s ease, box-shadow 0.05s ease;
}

.btn-danger:active {
  transform: scale(0.97) translateY(2px);
  box-shadow: 0 1px 0 #4a150f;
}

.btn-group {
  display: flex;
  gap: 8px;
  width: 100%;
}

.btn-option {
  flex: 1;
  font-family: 'Press Start 2P', monospace;
  background: #110703;
  border: 2px solid #5d4037;
  color: #888;
  padding: 10px;
  border-radius: 4px;
  font-size: 0.6rem;
  cursor: pointer;
  text-align: center;
  transition: transform 0.05s ease, background 0.05s ease;
}

.btn-option:active {
  transform: scale(0.95);
  background: #251208;
}

.btn-option.selected {
  background: #3d2212;
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 6px rgba(241, 196, 15, 0.4);
}

.number-picker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #000;
  border: 2px solid #5d4037;
  border-radius: 4px;
  padding: 4px;
}

.btn-step {
  font-family: 'Press Start 2P', monospace;
  background: #3d2212;
  color: var(--gold);
  border: 2px solid var(--gold);
  width: 38px;
  height: 38px;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.05s ease, background 0.05s ease;
}

.btn-step:active {
  transform: scale(0.92);
  background: #5a351b;   
}

.number-display {
  font-size: 0.7rem;
  color: var(--gold);
  text-align: center;
  flex-grow: 1;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.6rem;
  border-bottom: 2px solid #3d2212;
  padding-bottom: 8px;
}

.chest-box {
  box-shadow: 0 0 12px rgba(241, 196, 15, 0.25), inset 0 0 8px rgba(0, 0, 0, 0.8);
  padding: 8px 10px;
  border-radius: 4px;
  color: var(--gold);
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.chest-content-wrapper {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 40px;
  width: 100%;
}

.chest-pixel-img {
  width: 130px;
  height: 130px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
  animation: floatButton 3s ease-in-out infinite;
}

.chest-text-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
  flex-grow: 1;
}

.chest-title {
  font-size: clamp(0.42rem, 2.2vw, 0.85rem); 
  color: var(--gold);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.chest-amount-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: #fff;
}

#chest-coins-value {
  font-size: 1.5rem !important;
  font-weight: bold !important;
}

.coin-icon-inline {
  width: 16px;
  height: 16px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-btn {
  font-size: 1rem;
  background: #000;
  border: 2px solid var(--gold);
  border-radius: 4px;
  padding: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-grid {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  background: #000;
  padding: 8px;
  border-radius: 4px;
  border: 2px solid #5d4037;
  max-height: 180px;
  overflow-y: auto;
}

.avatar-opt {
  text-align: center;
  padding: 4px;
  background: #1a0f08;
  border: 1px solid #5d4037;
  cursor: pointer;
  border-radius: 4px;
  transition: transform 0.1s ease;
}

.avatar-opt img {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
}

.avatar-opt:hover {
  transform: scale(1.1);
  border-color: var(--gold);
  background: #3d2212;
}

.table-section, .diary-section {
  background: rgba(17, 7, 3, 0.9);
  border: 2px solid #3d2212;
  border-radius: 6px;
  padding: 10px;
}

.table-title, .diary-title {
  font-size: 0.75rem;
  color: #d4ac0d;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.players-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.player-chip {
  background: #000;
  border: 2px solid #5d4037;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 0.6rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.player-chip.voted {
  border-color: var(--green);
  background: #05190c;
}

.cards-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-card {
  background: rgba(17, 7, 3, 0.9);
  border: 3px solid #5d4037;
  border-radius: 6px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.1s ease;
}

.action-card.selected {
  border-color: var(--gold);
  background: #3d2414;
  box-shadow: 0 0 10px rgba(241, 196, 15, 0.4);
}

.action-card.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.card-text h4 { margin: 0; color: var(--gold); font-size: 0.65rem; }
.card-text p { margin: 4px 0 0 0; font-size: 0.55rem; color: #aaa; line-height: 1.4; }

select {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.6rem;
}

.log-box {
  background: #000;
  border: 2px solid #3d2212;
  border-radius: 4px;
  padding: 8px;
  height: 110px;
  overflow-y: auto;
  font-size: 0.55rem;
  color: #aaa;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-entry { margin: 0; border-bottom: 1px dotted #222; padding-bottom: 2px; }

.ranking-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.ranking-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #000;
  border: 2px solid #5d4037;
  padding: 10px;
  border-radius: 4px;
  font-size: 0.65rem;
}

.ranking-item.first {
  border-color: var(--gold);
  background: #2a1f06;
}

.ranking-item.second {
  border-color: #bdc3c7;
  background: #15161a;
}

.ranking-item.third {
  border-color: #e67e22;
  background: #24140b;
}

.ranking-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ranking-pos {
  font-size: 0.8rem;
  width: 25px;
  text-align: center;
}

.btn-audio-bottom {
  background: #1a0f08;
  border: 3px solid var(--gold);
  color: var(--gold);
  font-size: 1rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  flex-shrink: 0;
  margin: 12px 0 16px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.8);
  transition: transform 0.05s ease;
}

.btn-audio-bottom:active {
  transform: scale(0.9);
}

.menu-logo-container {
  text-align: center;
  margin-bottom: 12px;
  padding: 5px;
}

.main-menu-logo {
  width: 100%;
  max-width: 400px;
  height: auto;
  display: block;
  margin: 0 auto;
  filter: drop-shadow(0px 4px 6px rgba(0, 0, 0, 0.7));
  animation: floatLogo 3.5s ease-in-out infinite;
}

@keyframes floatLogo {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px);
  }
}

.btn-floating-anim {
  position: relative;
  animation: floatButton 2s ease-in-out infinite;
  overflow: visible;
  transition: transform 0.05s ease, box-shadow 0.05s ease, background 0.05s ease;
}

.btn-floating-anim:active:not(:disabled) {
  animation: none;
  transform: scale(0.97) translateY(3px) !important;
  box-shadow: 0 1px 0 #5f4c04 !important;
}

@keyframes floatButton {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px);
  }
}

@keyframes vaiven {
  0% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-35deg); 
  }
  55% {
    transform: rotate(0deg); 
  }
  75% {
    transform: rotate(15deg);  
  }
  100% {
    transform: rotate(0deg);
  }
}

@keyframes vaiven2 {
  0% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(10deg); 
  }
  55% {
    transform: rotate(0deg); 
  }
  75% {
    transform: rotate(10deg);  
  }
  100% {
    transform: rotate(0deg);
  }
}

.btn-corner-icon {
  position: absolute;
  top: -8px;
  right: -6px;
  font-size: 1.1rem;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: vaiven 3s ease-in-out infinite;
}

#create-avatar-img, #join-avatar-img {
  animation: vaiven2 3s ease-in-out infinite;
}

.custom-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.8);
  z-index: 10000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 30px 20px;
  overflow-y: auto;
}

.custom-modal-card {
  background: #1a0f08;
  border: 4px solid var(--gold);
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.9), inset 0 0 15px rgba(0, 0, 0, 0.8);
  border-radius: 6px;
  padding: 20px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  margin-top: 30px;
}

.custom-modal-card h3 {
  color: var(--gold);
  font-size: 0.8rem;
  margin: 0;
  text-shadow: 2px 2px #000;
}

.custom-modal-card p {
  font-size: 0.55rem;
  color: #ccc;
  margin: 0;
  line-height: 1.5;
}

.custom-modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}