:root {
    /* Colores del juego */
    --color-correct: #6aaa64;     /* Verde - letra correcta */
    --color-present: #c9b458;     /* Amarillo - letra en palabra pero posición incorrecta */
    
    /* Espaciado y tamaños */
    --grid-gap: 5px;
    --cell-size: 62px;
    --border-radius: 4px;
    --animation-duration: 0.4s;
}

/* Variables para modo oscuro (por defecto) */
body {
    --color-absent: #787c7e;      /* Gris oscuro - letra no en palabra */
    --color-empty: #222;
    --color-border: #333;
    --color-border-focus: #565758;
    --color-text: #fff;
    --color-text-light: #787c7e;
    --color-background: #111;
    --color-key: #1a1a1a;
    --color-key-hover: #333;
}

/* Variables para modo claro */
body.light-mode {
    --color-absent: #a0a0a0;      /* Gris más suave - letra no en palabra */
    --color-empty: #ffffff;
    --color-border: #d3d6da;
    --color-border-focus: #565758;
    --color-text: #1a1a1b;
    --color-text-light: #787c7e;
    --color-background: #ffffff;
    --color-key: #e3e3e3;
    --color-key-hover: #b0b3b6;
}

* {
    box-sizing: border-box;
    font-family: 'JetBrains Mono', 'Courier New', Consolas, 'Liberation Mono', Monaco, monospace;
}

body {
    font-family: 'JetBrains Mono', 'Courier New', Consolas, 'Liberation Mono', Monaco, monospace;
    background-color: var(--color-background);
    color: var(--color-text);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for better mobile support */
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: background-color var(--animation-duration) ease-in-out, color var(--animation-duration) ease-in-out;
    /* Prevent bounce scrolling on iOS */
    overscroll-behavior: none;
    /* Improve text rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 500px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height */
    background-color: var(--color-background);
    color: var(--color-text);
    transition: background-color var(--animation-duration) ease-in-out, color var(--animation-duration) ease-in-out;
    /* Ensure container takes full height on mobile */
    position: relative;
}

/* Header moderno y simple */
.header {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 16px;
  border-bottom: none; /* elimina línea del header */
  margin-bottom: 0;    /* elimina margen negativo anterior */
}

/* Elimina el subrayado/acento bajo el título */
.title::after {
  display: none !important;
  content: none !important;
}

/* Toggles en la esquina superior derecha de la página */
.language-selector {
  position: fixed;
  top: 12px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 100;
}

/* Título ligeramente más pequeño y con menos tracking para look moderno */
.title {
    font-size: 34px; /* antes 36px */
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.16em; /* antes 0.2em */
    text-align: center;
    line-height: 1;
}

/* Game Container */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    gap: 20px;
    margin-top: 0px; /* Reduce este valor si existe */
}

/* Estilos para botones de tema e idioma */
.theme-toggle-btn, .lang-menu-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    transition: background var(--animation-duration) ease-in-out, transform var(--animation-duration) ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.theme-toggle-btn:hover, .lang-menu-btn:hover {
    background: var(--color-key-hover);
    transform: scale(1.05);
}

.theme-toggle-btn:active, .lang-menu-btn:active {
    transform: scale(0.95);
}

/* Dropdown de idioma */
.lang-dropdown {
    position: absolute;
    top: 48px;
    right: 0;
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 120px;
    z-index: 1000;
    overflow: hidden;
    transition: all var(--animation-duration) ease-in-out;
    transform-origin: top right;
}

.lang-dropdown.hidden {
    opacity: 0;
    transform: scale(0.9) translateY(-10px);
    pointer-events: none;
}

.lang-dropdown:not(.hidden) {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.lang-option {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    color: var(--color-text);
    transition: background var(--animation-duration) ease-in-out, color var(--animation-duration) ease-in-out;
    border-bottom: 1px solid var(--color-border);
}

.lang-option:last-child {
    border-bottom: none;
}

.lang-option:hover {
    background: var(--color-key-hover);
}

.lang-option.active {
    background: var(--color-key);
    font-weight: 600;
}

/* Ajustes específicos para modo claro */
body.light-mode .lang-dropdown {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-color: var(--color-border);
}

body.light-mode .theme-toggle-btn:hover, 
body.light-mode .lang-menu-btn:hover {
    background: var(--color-key-hover);
}

/* Message Container */
.message-container {
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message {
    background: var(--color-text);
    color: var(--color-background);
    padding: 8px 16px;
    border-radius: var(--border-radius);
    font-family: 'JetBrains Mono', 'Courier New', Consolas, 'Liberation Mono', Monaco, monospace;
    font-weight: 600;
    animation: fadeIn 0.3s ease;
    transition: background var(--animation-duration) ease-in-out, color var(--animation-duration) ease-in-out;
}

.message.success {
    background: var(--color-correct);
}

.message.error {
    background: #e74c3c;
}

/* Game Grid */
.game-grid {
    display: grid;
    grid-template-rows: repeat(6, var(--cell-size));
    grid-gap: var(--grid-gap);
    margin: 20px 0;
}

.grid-row {
    display: grid;
    grid-template-columns: repeat(5, var(--cell-size));
    grid-gap: var(--grid-gap);
}

.grid-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 700;
    text-transform: uppercase;
    background: var(--color-empty);
    transition: all var(--animation-duration) ease-in-out;
}

.grid-cell.filled {
    border-color: var(--color-border-focus);
    animation: cellFill var(--animation-duration) ease;
}

.grid-cell.correct {
    background: var(--color-correct);
    border-color: var(--color-correct);
    color: white;
}

.grid-cell.present {
    background: var(--color-present);
    border-color: var(--color-present);
    color: white;
}

.grid-cell.absent {
    background: var(--color-absent);
    border-color: var(--color-absent);
    color: white;
}

/* Keyboard */
.keyboard {
    margin: 30px auto 0 auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 400px;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 6px;
}

.key {
    background: var(--color-key);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    border-radius: 4px;
    margin: 4px;
    padding: 10px 14px;
    font-size: 1em;
    font-family: 'JetBrains Mono', 'Courier New', Consolas, 'Liberation Mono', Monaco, monospace;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--animation-duration) ease-in-out, 
                color var(--animation-duration) ease-in-out, 
                border-color var(--animation-duration) ease-in-out,
                opacity var(--animation-duration) ease-in-out,
                width var(--animation-duration) ease-in-out,
                margin var(--animation-duration) ease-in-out,
                padding var(--animation-duration) ease-in-out;
}

.key:hover {
    background: var(--color-key-hover);
}

.key:active {
    transform: scale(0.95);
}

.key-action {
    min-width: 65px;
    font-size: 12px;
}

.key.correct {
    background: var(--color-correct) !important;
    color: white !important;
    border-color: var(--color-correct) !important;
}

.key.present {
    background: var(--color-present) !important;
    color: white !important;
    border-color: var(--color-present) !important;
}

.key.absent {
    background: var(--color-absent) !important;
    color: white !important;
    border-color: var(--color-absent) !important;
}

/* Game Stats */
.game-stats {
    margin-top: 20px;
    text-align: center;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-label {
    font-size: 14px;
    color: var(--color-text-light);
    transition: color var(--animation-duration) ease-in-out;
}

.stat-value {
    font-size: 18px;
    font-weight: 600;
    transition: color var(--animation-duration) ease-in-out;
}

/* Footer */
.footer {
    text-align: center;
    padding: 20px 0;
    color: var(--color-text-light);
    font-size: 14px;
    border-top: 1px solid var(--color-border);
}

/* Animations */
@keyframes cellFill {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

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

@keyframes rowReveal {
    0% { transform: rotateX(0); }
    50% { transform: rotateX(-90deg); }
    100% { transform: rotateX(0); }
}

.row-reveal {
    animation: rowReveal 0.6s ease-in-out;
}

/* Responsive Design */

/* Tablet */
@media (max-width: 768px) and (min-width: 481px) {
    .container {
        max-width: 600px;
        padding: 0 20px;
    }
    
    :root {
        --cell-size: 58px;
        --grid-gap: 5px;
    }
    
    .title {
        font-size: 32px;
    }
    
    .game-container {
        gap: 24px;
        padding: 24px 0;
    }
    
    .keyboard {
        max-width: 500px;
        margin: 24px auto 0 auto;
    }
    
    .key {
        padding: 12px 16px;
        font-size: 0.95em;
        margin: 3px;
    }
    
    .key-action {
        min-width: 70px;
    }
}

/* Mobile phones */
@media (max-width: 480px) {
    :root {
        --cell-size: 46px;
        --grid-gap: 3px;
        --border-radius: 3px;
    }
    
    body {
        min-height: 100vh;
        min-height: 100dvh; /* Dynamic viewport height for mobile */
    }
    
    .container {
        padding: 0 12px;
        min-height: 100vh;
        min-height: 100dvh;
    }
    
    .header {
        padding: 16px 12px 12px 12px;
        margin-bottom: 0;
    }
    
    .title {
        font-size: 26px;
        letter-spacing: 0.12em;
    }
    
    .language-selector {
        top: 8px;
        right: 12px;
        gap: 8px;
    }
    
    .theme-toggle-btn, .lang-menu-btn {
        padding: 8px;
    }
    
    .theme-toggle-btn img, .lang-menu-btn img {
        height: 24px !important;
        width: 24px !important;
    }
    
    .game-container {
        gap: 16px;
        padding: 12px 0 20px 0;
        flex: 1;
        justify-content: space-between;
        /* Ensure everything fits in viewport */
        max-height: calc(100vh - 120px);
        max-height: calc(100dvh - 120px);
        overflow: hidden;
    }
    
    .message-container {
        height: 24px;
        margin-bottom: 8px;
    }
    
    .message {
        font-size: 13px;
        padding: 6px 12px;
    }
    
    .game-grid {
        margin: 8px 0;
        justify-self: center;
    }
    
    .grid-cell {
        font-size: 22px;
        font-weight: 600;
    }
    
    .game-stats {
        margin-top: 12px;
    }
    
    .stat-label {
        font-size: 12px;
    }
    
    .stat-value {
        font-size: 16px;
    }
    
    /* Optimized keyboard for mobile */
    .keyboard {
        margin: 12px auto 0 auto;
        max-width: 100%;
        width: 100%;
        padding: 0 2px;
        /* Ensure keyboard doesn't exceed viewport */
        max-height: 30vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    .keyboard-row {
        gap: 2px;
        margin-bottom: 3px;
        justify-content: center;
        width: 100%;
        display: flex;
        flex-wrap: nowrap;
    }
    
    .keyboard-row:last-child {
        margin-bottom: 0;
    }
    
    .key {
        height: 42px;
        min-width: 26px;
        font-size: 10px;
        font-weight: 600;
        padding: 6px 2px;
        margin: 1px;
        flex: 1;
        max-width: 30px;
        border-radius: 3px;
        transform: scale(1); /* Override the 1.1 scale for mobile */
        /* Ensure text fits */
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .key-action {
        min-width: 44px;
        max-width: 48px;
        font-size: 8px;
        padding: 6px 4px;
        flex: 1.4;
    }
    
    .key-action img {
        height: 14px !important;
        width: 14px !important;
    }
    
    /* Adjust keyboard layout for better mobile experience */
    .keyboard-row:first-child {
        max-width: 100%;
    }
    
    .keyboard-row:nth-child(2) {
        max-width: 95%;
        margin: 0 auto 4px auto;
    }
    
    .keyboard-row:last-child {
        max-width: 100%;
    }
    
    /* Language dropdown adjustments for mobile */
    .lang-dropdown {
        top: 40px;
        right: -4px;
        min-width: 100px;
        font-size: 13px;
    }
    
    .lang-option {
        padding: 10px 12px;
        font-size: 13px;
    }
}

/* Extra small phones */
@media (max-width: 360px) {
    :root {
        --cell-size: 40px;
        --grid-gap: 2px;
    }
    
    .container {
        padding: 0 6px;
    }
    
    .title {
        font-size: 22px;
        letter-spacing: 0.08em;
    }
    
    .game-container {
        gap: 10px;
        padding: 6px 0 12px 0;
    }
    
    .grid-cell {
        font-size: 18px;
    }
    
    .keyboard {
        margin: 8px auto 0 auto;
        padding: 0 1px;
        max-height: 28vh;
    }
    
    .keyboard-row {
        gap: 1px;
        margin-bottom: 2px;
    }
    
    .key {
        height: 38px;
        min-width: 22px;
        max-width: 26px;
        font-size: 9px;
        padding: 4px 1px;
        margin: 0.5px;
    }
    
    .key-action {
        min-width: 38px;
        max-width: 42px;
        font-size: 7px;
        padding: 4px 2px;
        flex: 1.3;
    }
    
    .key-action img {
        height: 12px !important;
        width: 12px !important;
    }
}

/* Landscape mode for phones */
@media (max-width: 850px) and (orientation: landscape) and (max-height: 500px) {
    body {
        min-height: 100vh;
        min-height: 100dvh;
    }
    
    .container {
        min-height: 100vh;
        min-height: 100dvh;
    }
    
    .header {
        padding: 8px 12px 4px 12px;
    }
    
    .title {
        font-size: 22px;
    }
    
    .language-selector {
        top: 4px;
        right: 8px;
    }
    
    .game-container {
        gap: 8px;
        padding: 4px 0 12px 0;
    }
    
    .message-container {
        height: 20px;
        margin-bottom: 4px;
    }
    
    .game-grid {
        margin: 4px 0;
    }
    
    :root {
        --cell-size: 38px;
        --grid-gap: 2px;
    }
    
    .grid-cell {
        font-size: 18px;
    }
    
    .keyboard {
        margin: 6px auto 0 auto;
        max-height: 25vh;
        padding: 0 2px;
    }
    
    .keyboard-row {
        gap: 2px;
        margin-bottom: 2px;
    }
    
    .key {
        height: 32px;
        font-size: 9px;
        padding: 4px 2px;
        margin: 0.5px;
        min-width: 24px;
        max-width: 28px;
    }
    
    .key-action {
        min-width: 36px;
        max-width: 40px;
        font-size: 7px;
        padding: 4px 3px;
    }
    
    .key-action img {
        height: 10px !important;
        width: 10px !important;
    }
    
    .game-stats {
        margin-top: 6px;
    }
}

/* Modo oscuro (estilos por defecto ya definidos arriba) */

/* Estilos duplicados removidos - ya están definidos arriba */

/* Aumentar el tamaño del teclado en un 10% solo en desktop */
@media (min-width: 481px) {
    .key {
        transform: scale(1.1);
        transform-origin: center;
    }
}

/* Mobile touch optimizations */
@media (max-width: 480px) {
    /* Ensure proper touch targets - adjusted for space constraints */
    .theme-toggle-btn, .lang-menu-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Keys need to be smaller to fit on screen but still usable */
    .key {
        min-height: 38px; /* Slightly smaller but still accessible */
        min-width: 22px;
    }
    
    /* Improve touch feedback */
    .key:active {
        transform: scale(0.92);
        background: var(--color-key-hover);
    }
    
    .theme-toggle-btn:active, .lang-menu-btn:active {
        transform: scale(0.92);
        background: var(--color-key-hover);
    }
    
    /* Prevent zoom on input focus (not applicable here but good practice) */
    input, select, textarea {
        font-size: 16px;
    }
    
    /* Smooth scrolling for better mobile experience */
    html {
        scroll-behavior: smooth;
    }
    
    /* Prevent horizontal scrolling */
    body {
        overflow-x: hidden;
    }
}

/* Animación para cambio de tema fluido en todos los elementos */
* {
    transition: background-color var(--animation-duration) ease-in-out,
                color var(--animation-duration) ease-in-out,
                border-color var(--animation-duration) ease-in-out,
                box-shadow var(--animation-duration) ease-in-out;
}

/* Estilos específicos para la tecla Ñ */
.key-esp {
    transition: opacity var(--animation-duration) ease-in-out,
                transform var(--animation-duration) ease-in-out,
                background var(--animation-duration) ease-in-out,
                color var(--animation-duration) ease-in-out,
                border-color var(--animation-duration) ease-in-out;
}

.key-hidden {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .grid-cell {
        border-width: 3px;
    }
    
    .key {
        border-width: 2px;
        font-weight: 700;
    }
}

/* Dark mode preference support - already using dark mode as default */

/* Focus styles for keyboard navigation */
.key:focus,
.theme-toggle-btn:focus,
.lang-menu-btn:focus,
.lang-option:focus {
    outline: 2px solid var(--color-correct);
    outline-offset: 2px;
}

/* Ultra compact for very small screens */
@media (max-width: 320px) {
    :root {
        --cell-size: 36px;
        --grid-gap: 1px;
    }
    
    .keyboard {
        margin: 6px auto 0 auto;
        max-height: 26vh;
    }
    
    .key {
        height: 34px;
        font-size: 8px;
        padding: 3px 1px;
        min-width: 20px;
        max-width: 24px;
        margin: 0.5px;
    }
    
    .key-action {
        font-size: 6px;
        min-width: 34px;
        max-width: 38px;
        padding: 3px 2px;
    }
    
    .key-action img {
        height: 10px !important;
        width: 10px !important;
    }
}

/* Very short screens (landscape phones, phones with large notches) */
@media (max-height: 600px) and (max-width: 480px) {
    .game-container {
        gap: 8px;
        padding: 4px 0 8px 0;
    }
    
    .keyboard {
        margin: 4px auto 0 auto;
        max-height: 22vh;
    }
    
    .keyboard-row {
        margin-bottom: 1px;
    }
    
    .key {
        height: 36px;
        font-size: 9px;
        padding: 4px 2px;
    }
    
    .key-action {
        font-size: 7px;
        padding: 4px 3px;
    }
}

/* Extra short screens */
@media (max-height: 500px) and (max-width: 480px) {
    .title {
        font-size: 20px;
    }
    
    .header {
        padding: 6px 12px 4px 12px;
    }
    
    .keyboard {
        max-height: 20vh;
        margin: 2px auto 0 auto;
    }
    
    .key {
        height: 32px;
        font-size: 8px;
        padding: 3px 2px;
    }
    
    .key-action {
        font-size: 6px;
        padding: 3px 2px;
    }
    
    .key-action img {
        height: 10px !important;
        width: 10px !important;
    }
}
