:root {
    --bg-primary: #667eea;
    --bg-secondary: #764ba2;
    --container-bg: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --cell-bg: #ffffff;
    --cell-border: #cccccc;
    --cell-hover: #ffa500;
    --grid-bg: #e0e0e0;
    --sun-bg: #ffe066;
    --sun-border: #ffd700;
    --moon-bg: #b8c5d6;
    --moon-border: #7b8ea3;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-light: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --container-bg: #0f3460;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --cell-bg: #1a1a2e;
    --cell-border: #2d3561;
    --cell-hover: #ffb84d;
    --grid-bg: #16213e;
    --sun-bg: #ffb84d;
    --sun-border: #ff9500;
    --moon-bg: #6c7a89;
    --moon-border: #4a5568;
    --shadow: rgba(0, 0, 0, 0.5);
    --shadow-light: rgba(0, 0, 0, 0.2);
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    transition: background 0.3s ease;
}

.container {
    background: var(--container-bg);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px var(--shadow);
    max-width: 700px;
    width: 100%;
    transition: all 0.3s ease;
}

h1 {
    color: var(--text-primary);
    margin: 0 0 20px 0;
    font-size: 2.2em;
    animation: fadeInDown 0.6s ease;
    text-align: center;
}

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

.info {
    text-align: center;
    margin-bottom: 30px;
    color: var(--text-secondary);
    line-height: 1.6;
    animation: fadeIn 0.8s ease 0.2s both;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.game-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeInUp 0.8s ease 0.6s both;
    margin-bottom: 20px;
}

.center-content {
    display: flex;
    justify-content: center;
}

.controls-top {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
    animation: fadeIn 0.6s ease 0.2s both;
}

.level-selector {
    display: flex;
    justify-content: center;
    margin-bottom: 25px;
    animation: fadeIn 0.8s ease 0.4s both;
}

.completed-counter {
    display: inline-flex;
    align-items: center;
    margin-left: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    background: var(--grid-bg);
    padding: 8px 12px;
    border-radius: 12px;
    box-shadow: 0 2px 6px var(--shadow-light);
    font-size: 0.95em;
}

.completed-counter #completedCount {
    margin-left: 8px;
    color: var(--text-primary);
    font-weight: 800;
}

.icon-btn {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 12px;
    background: var(--grid-bg);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5em;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px var(--shadow-light);
}

.icon-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 5px 15px var(--shadow-light);
}

.icon-btn:active {
    transform: translateY(-1px) scale(0.98);
}

.icon-btn.muted {
    opacity: 0.5;
}

.info p {
    margin: 5px 0;
}

.game-container {
    display: flex;
    justify-content: center;
}

.grid {
    display: grid;
    grid-template-columns: repeat(6, 60px);
    grid-template-rows: repeat(6, 60px);
    gap: 5px;
    background: var(--grid-bg);
    padding: 10px;
    border-radius: 10px;
    box-shadow: inset 0 2px 10px var(--shadow-light);
    position: relative;
}

.cell {
    width: 60px;
    height: 60px;
    background: var(--cell-bg);
    border: 2px solid var(--cell-border);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2em;
    transition: all 0.2s ease;
    user-select: none;
    box-shadow: 0 2px 5px var(--shadow-light);
}

.cell:hover {
    border-color: var(--cell-hover);
    box-shadow: 0 4px 12px var(--shadow-light);
}

.cell.sun {
    animation: popIn 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.cell.moon {
    animation: popIn 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.cell.locked {
    cursor: not-allowed;
    background: #9e9e9e !important;
    opacity: 1;
    border-color: #757575 !important;
}

.cell.locked:hover {
    transform: none !important;
    border-color: #757575 !important;
    box-shadow: 0 2px 5px var(--shadow-light);
}

[data-theme="dark"] .cell.locked {
    background: #424242 !important;
    border-color: #616161 !important;
}

@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Estilos para restricciones */
.constraint {
    position: absolute;
    background: white;
    color: #333;
    font-weight: bold;
    font-size: 1.1em;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 3px solid #667eea;
    border-radius: 50%;
    transition: all 0.3s ease;
    z-index: 10;
    pointer-events: none;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
    width: 35px;
    height: 35px;
    transform: translate(-50%, -50%);
    line-height: 1;
    padding-bottom: 2px;
}

[data-theme="dark"] .constraint {
    background: #0f3460;
    color: white;
    border-color: #667eea;
}

.constraint.error {
    /* Sin estilos adicionales - solo marcar las celdas */
}

.cell.error {
    animation: shake 0.4s ease;
    border-color: #ff4444 !important;
    background: linear-gradient(135deg, #ff6b6b, #ee5a6f) !important;
    box-shadow: 0 0 15px rgba(255, 68, 68, 0.6) !important;
}

.cell.success {
    animation: celebration 0.6s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    25% { transform: translateX(-8px) rotate(-5deg); }
    50% { transform: translateX(8px) rotate(5deg); }
    75% { transform: translateX(-8px) rotate(-5deg); }
}

@keyframes celebration {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.15) rotate(-10deg); }
    50% { transform: scale(0.95) rotate(10deg); }
    75% { transform: scale(1.1) rotate(-5deg); }
}

.controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
    margin-bottom: 20px;
    animation: fadeInUp 1s ease 0.5s both;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px var(--shadow-light);
}

.btn-reset {
    background: linear-gradient(135deg, #f44336, #da190b);
    color: white;
}

.btn-reset:hover {
    background: linear-gradient(135deg, #da190b, #c41808);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(244, 67, 54, 0.4);
}

.btn-check {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
}

.btn-check:hover {
    background: linear-gradient(135deg, #45a049, #3d8b40);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.btn-undo {
    background: linear-gradient(135deg, #667eea, #5a67d8);
    color: white;
}

.btn-undo:hover:not(:disabled) {
    background: linear-gradient(135deg, #5a67d8, #4c51bf);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-undo:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: linear-gradient(135deg, #9ca3af, #6b7280);
}

.btn:active {
    transform: translateY(-1px) scale(0.98);
}

.message {
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
    min-height: 30px;
    padding: 10px;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.message.success {
    color: #4CAF50;
    background: #e8f5e9;
    animation: slideInUp 0.5s ease;
}

.message.error {
    color: #f44336;
    background: #ffebee;
    animation: slideInUp 0.5s ease;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .container {
        padding: 15px;
        max-width: 100%;
    }
    
    .game-wrapper {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }
    
    .center-content {
        width: 100%;
        padding-right: 0;
    }
    
    .controls-top {
        flex-direction: row;
        margin-top: 15px;
        gap: 8px;
    }

    .icon-btn {
        width: 45px;
        height: 45px;
        font-size: 1.3em;
    }
    
    h1 {
        font-size: 1.8em;
        margin-bottom: 15px;
    }
    
    .grid {
        grid-template-columns: repeat(6, 45px);
        grid-template-rows: repeat(6, 45px);
        gap: 4px;
        padding: 8px;
    }
    
    .cell {
        width: 45px;
        height: 45px;
        font-size: 1.5em;
    }

    .constraint {
        width: 28px;
        height: 28px;
        font-size: 0.9em;
        border-width: 2px;
    }
    
    .btn {
        padding: 10px 20px;
        font-size: 0.9em;
    }

    .controls {
        gap: 10px;
        margin-top: 20px;
        flex-wrap: wrap;
    }
}

/* Estilos de Modales */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: var(--container-bg);
    border-radius: 20px;
    padding: 0;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px var(--shadow);
    animation: slideInScale 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes slideInScale {
    from {
        opacity: 0;
        transform: scale(0.7) translateY(-50px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    padding: 25px;
    border-bottom: 2px solid var(--grid-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.8em;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2em;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close-btn:hover {
    background: var(--grid-bg);
    color: var(--text-primary);
    transform: rotate(90deg);
}

.modal-body {
    padding: 25px;
    color: var(--text-primary);
    line-height: 1.6;
}

.modal-body h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body p {
    margin: 8px 0;
    color: var(--text-secondary);
}

.rules-list {
    list-style: none;
    padding: 0;
    margin: 15px 0;
}

.rules-list li {
    padding: 10px;
    margin: 8px 0;
    background: var(--grid-bg);
    border-radius: 8px;
    border-left: 4px solid var(--cell-hover);
    transition: all 0.3s ease;
}

.rules-list li:hover {
    transform: translateX(5px);
    box-shadow: 0 2px 8px var(--shadow-light);
}

.modal-footer {
    padding: 20px 25px;
    border-top: 2px solid var(--grid-bg);
    display: flex;
    gap: 15px;
    justify-content: center;
}

/* Estilos específicos del modal de victoria */
.modal-content.victory {
    text-align: center;
}

.modal-content.victory .modal-header {
    border-bottom: none;
    justify-content: center;
}

.victory-text {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--text-primary);
    margin: 20px 0 10px 0;
}

.victory-subtext {
    font-size: 1.1em;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.victory-icons {
    font-size: 3em;
    margin: 20px 0;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* Responsive modales */
@media (max-width: 600px) {
    .modal-content {
        width: 95%;
        max-height: 85vh;
    }
    
    .modal-header {
        padding: 20px;
    }
    
    .modal-header h2 {
        font-size: 1.5em;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .modal-footer {
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
    }
}
