:root {
    --bg-color: #121213;
    --text-color: #ffffff;
    --tile-border: #3a3a3c;
    --key-bg: #818384;
    --green: #538d4e;
    --yellow: #b59f3b;
    --gray: #3a3a3c;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: system-ui, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* HEADER */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #333;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: bold;
    font-size: 1.4rem;
}

.logo-icon {
    color: #4ade80;
}

.logo-img {
    height: 32px;
    width: auto;
}

.header-buttons button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
    margin-left: 0.5rem;
}

.header-buttons button:hover {
    opacity: 0.7;
}

/* GAME */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
}

/* BOARD */
.board {
    display: grid;
    gap: 0.4rem;
    margin: 1rem 0;
}

.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.4rem;
}

.tile {
    width: 58px;
    height: 58px;
    border: 2px solid var(--tile-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    text-transform: uppercase;
}

/* TILE STATES */
.tile.correct {
    background-color: var(--green);
    border-color: var(--green);
    color: white;
}

.tile.present {
    background-color: var(--yellow);
    border-color: var(--yellow);
    color: white;
}

.tile.absent {
    background-color: var(--gray);
    border-color: var(--gray);
    color: white;
}

/* ANIMACIONES DE TILES */
.tile.pop {
    animation: pop 0.1s ease-in-out;
}

.tile.flip {
    animation: flip 0.5s ease-in-out;
}

@keyframes pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes flip {
    0% {
        transform: rotateX(0deg);
    }
    50% {
        transform: rotateX(90deg);
    }
    100% {
        transform: rotateX(0deg);
    }
}

.tile.shake {
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* CONFETI */
.confetti-piece {
    position: fixed;
    width: 10px;
    height: 10px;
    z-index: 10000;
    pointer-events: none;
    animation: confetti-fall 3s ease-out forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translate(0, 0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) rotate(var(--rotation));
        opacity: 0;
    }
}

/* KEYBOARD */
.keyboard {
    margin-top: 1rem;
}

.key-row {
    display: flex;
    justify-content: center;
    margin-bottom: 0.4rem;
}

.keyboard button {
    background-color: var(--key-bg);
    border: none;
    color: white;
    padding: 0.6rem;
    margin: 0.15rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.keyboard .wide {
    padding: 0.6rem 1rem;
}

.keyboard button.correct {
    background-color: var(--green);
}

.keyboard button.present {
    background-color: var(--yellow);
}

.keyboard button.absent {
    background-color: var(--gray);
}

/* OTROS JUEGOS */

.other-games {
    width: 100%;
    max-width: 1200px;
    padding: 2rem 1rem;
    margin-top: 2rem;
}

.other-games-title {
    text-align: center;
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

.games-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.2rem;
    max-width: 900px;
    margin: 0 auto;
}

.game-card {
    background: #2a2a2c;
    border-radius: 16px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    transition: all 0.3s ease;
    text-decoration: none;
    color: inherit;
    border: 2px solid transparent;
}

.game-card:not(.coming-soon):hover {
    transform: translateY(-4px);
    border-color: #538d4e;
    box-shadow: 0 8px 20px rgba(83, 141, 78, 0.3);
}

.game-card.coming-soon {
    opacity: 0.6;
    cursor: not-allowed;
}

.game-icon {
    width: 120px;
    height: 120px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.game-icon-image {
    width: 120px;
    height: 120px;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 2px solid #538d4e;
}

.game-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.binary-soup-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    font-family: 'Courier New', monospace;
    font-size: 2rem;
    color: #2e7d32;
    font-weight: bold;
}

.coming-soon-icon {
    font-size: 4rem;
    color: #666;
}

.game-info {
    text-align: center;
    flex: 1;
}

.game-title {
    font-size: 1.3rem;
    font-weight: bold;
    margin-bottom: 0.4rem;
    color: var(--text-color);
}

.game-description {
    font-size: 0.9rem;
    color: #9ca3af;
}

.game-play-btn {
    background: #538d4e;
    color: white;
    border: none;
    padding: 0.7rem 2rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    max-width: 150px;
}

.game-play-btn:not(:disabled):hover {
    background: #6aaa64;
    transform: scale(1.05);
}

.game-play-btn:disabled {
    background: #4a4a4c;
    cursor: not-allowed;
    opacity: 0.5;
}

/* FOOTER */
.footer {
    border-top: 1px solid #333;
    padding: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.footer-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.footer-logo img {
    height: 24px;
    width: auto;
}

.footer-links a {
    color: #9ca3af;
    text-decoration: none;
    margin-left: 1rem;
}

.footer-links a:hover {
    color: white;
}

/* ===============================
   Modal base
   =============================== */

#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#modal-overlay:not(.hidden) {
  display: flex;
}

#modal {
  background: var(--bg-color);
  color: var(--text-color);
  padding: 1.5rem;
  border-radius: 8px;
  width: min(90%, 400px);
  position: relative;
}

#modal-close {
  position: absolute;
  top: .5rem;
  right: .5rem;
  background: none;
  border: none;
  color: inherit;
  font-size: 1.2rem;
  cursor: pointer;
}

.hidden {
  display: none;
}

/* ===============================
   Modal fin de juego
   =============================== */

.endgame-modal {
  text-align: center;
}

.endgame-modal h2 {
  font-size: 1.8rem;
  margin-bottom: 0.4rem;
}

.modal-subtitle {
  color: #d1d5db;
  margin-bottom: 1rem;
}

.modal-word {
  font-size: 2.2rem;
  font-weight: bold;
  letter-spacing: 0.3rem;
  margin-bottom: 1.5rem;
}

.restart-btn {
  background-color: #6aaa64;
  color: white;
  border: none;
  padding: 0.7rem 1.6rem;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
}

.restart-btn:hover {
  opacity: 0.9;
}

.modal-hint {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: #9ca3af;
}

/* ===============================
   Modal Estadísticas
   =============================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden {
  display: none;
}

.modal.stats-modal {
  background: var(--bg-color);
  color: var(--text-color);
  border-radius: 8px;
  border: 1px solid #333;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid #333;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: bold;
}

.modal-header button {
  background: none;
  border: none;
  color: var(--text-color);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.modal-header button:hover {
  opacity: 1;
}

/* Grid de estadísticas */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.8rem;
  padding: 1.5rem;
}

.stat-box {
  background: #1a1a1b;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 2rem;
  font-weight: bold;
  color: var(--green);
  margin-bottom: 0.25rem;
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Distribución de intentos */
.distribution {
  padding: 0 1.5rem 1.5rem;
}

.distribution h3 {
  margin: 0 0 1rem 0;
  font-size: 1rem;
  color: var(--text-color);
  font-weight: 600;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.dist-label {
  width: 24px;
  text-align: center;
  font-weight: bold;
  color: #9ca3af;
  font-size: 0.9rem;
}

.dist-bar {
  flex: 1;
  background: #1a1a1b;
  border: 1px solid #333;
  border-radius: 4px;
  height: 28px;
  overflow: hidden;
  position: relative;
}

.dist-fill {
  height: 100%;
  background: var(--green);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  min-width: 28px;
  transition: width 0.3s ease;
  color: white;
  font-size: 0.85rem;
  font-weight: bold;
}

.dist-value {
  width: 32px;
  text-align: center;
  font-weight: bold;
  color: var(--text-color);
  font-size: 0.9rem;
}

/* ===============================
   Modal Configuración
   =============================== */

.modal.settings-modal {
  background: var(--bg-color);
  color: var(--text-color);
  border-radius: 8px;
  border: 1px solid #333;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.settings-content {
  padding: 1.5rem;
}

.setting-group {
  margin-bottom: 2rem;
}

.setting-group:last-of-type {
  margin-bottom: 1rem;
}

.setting-group h3 {
  margin: 0 0 1rem 0;
  font-size: 1rem;
  color: var(--text-color);
  font-weight: 600;
}

.setting-options {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.setting-option {
  display: flex;
  align-items: center;
  padding: 1rem;
  background: #1a1a1b;
  border: 2px solid #333;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.setting-option:hover {
  border-color: #555;
}

.setting-option input[type="radio"] {
  margin-right: 1rem;
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--green);
}

.setting-option input[type="radio"]:checked + .option-content {
  color: var(--green);
}

.option-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.option-title {
  font-size: 1rem;
  font-weight: 600;
}

.option-desc {
  font-size: 0.85rem;
  color: #9ca3af;
}

.apply-btn {
  width: 100%;
  background-color: var(--green);
  color: white;
  border: none;
  padding: 0.9rem;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  margin-top: 1rem;
  transition: opacity 0.2s;
}

.apply-btn:hover {
  opacity: 0.9;
}

/* ===============================
   Modal Información
   =============================== */

.modal.info-modal {
  background: var(--bg-color);
  color: var(--text-color);
  border-radius: 8px;
  border: 1px solid #333;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.info-content {
  padding: 1.5rem;
}

.info-intro {
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 1.5rem;
  color: #d1d5db;
}

.info-section {
  margin-bottom: 1.5rem;
}

.info-section h3 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  color: var(--text-color);
  font-weight: 600;
}

.info-section p {
  line-height: 1.6;
  color: #d1d5db;
}

.info-section ul {
  list-style: none;
  padding-left: 0;
}

.info-section ul li {
  padding: 0.5rem 0;
  padding-left: 1.5rem;
  position: relative;
  line-height: 1.6;
  color: #d1d5db;
}

.info-section ul li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--green);
  font-weight: bold;
}

.color-examples {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.color-example {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.example-tiles {
  display: flex;
  gap: 0.3rem;
}

.example-tiles .tile {
  width: 40px;
  height: 40px;
  border: 2px solid var(--tile-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: bold;
}

.green-text {
  color: var(--green);
}

.yellow-text {
  color: var(--yellow);
}

.gray-text {
  color: #9ca3af;
}

.info-footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #333;
  text-align: center;
  font-size: 1rem;
  color: var(--text-color);
  font-weight: 500;
}

/* ===============================
   Tema claro
   =============================== */

body.light-theme {
  --bg-color: #ffffff;
  --text-color: #1a1a1a;
  --tile-border: #d3d6da;
  --key-bg: #d3d6da;
  --gray: #787c7e;
}

body.light-theme .header,
body.light-theme .footer {
  border-color: #d3d6da;
}

body.light-theme .modal {
  background: #ffffff;
  border-color: #d3d6da;
}

body.light-theme .stat-box,
body.light-theme .dist-bar,
body.light-theme .setting-option {
  background: #f9fafb;
  border-color: #d3d6da;
}

body.light-theme .modal-header,
body.light-theme .distribution h3,
body.light-theme .info-footer {
  border-color: #d3d6da;
}

body.light-theme .option-desc,
body.light-theme .info-intro,
body.light-theme .info-section p,
body.light-theme .info-section ul li {
  color: #4b5563;
}

body.light-theme .keyboard button {
  background-color: #d3d6da;
  color: #1a1a1a;
}

body.light-theme .keyboard button.correct {
  background-color: var(--green);
  color: white;
}

body.light-theme .keyboard button.present {
  background-color: var(--yellow);
  color: white;
}

body.light-theme .keyboard button.absent {
  background-color: var(--gray);
  color: white;
}