:root {
    --bg-color: #1a1a2e;
    --container-bg: #16213e;
    --cell-bg: #2d3561;
    --cell-border: #4a5583;
    --text-color: #eee;
    --correct: #4caf50;
    --wrong-position: #ff9800;
    --wrong: #f44336;
    --locked: #666;
}

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

body {
    font-family: 'Fredoka', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.header-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1.5rem;
}

.header-container h1 {
    margin: 0;
}

.help-button {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: background-color 0.3s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.help-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-50%) scale(1.05);
}

.help-button:active {
    transform: translateY(-50%) scale(0.95);
}

.container {
    background-color: var(--container-bg);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    max-width: 600px;
    width: 100%;
}

h1 {
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 3.5rem;
    color: #fff;
    font-family: 'Bungee Shade', cursive;
    letter-spacing: 0.05em;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
    animation: title-glow 2s ease-in-out infinite alternate;
}

@keyframes title-glow {
    from { text-shadow: 0 0 20px rgba(255, 255, 255, 0.3); }
    to { text-shadow: 0 0 30px rgba(255, 255, 255, 0.5), 0 0 40px rgba(76, 175, 80, 0.3); }
}

.slogan {
    text-align: center;
    font-size: 1.1rem;
    color: #bbb;
    margin-bottom: 1.5rem;
    margin-top: 0;
    font-style: italic;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

.puzzle-progress {
    margin-bottom: 2rem;
    text-align: center;
}

.progress-title {
    font-size: 1rem;
    color: #ccc;
    margin-bottom: 1rem;
    font-weight: 600;
}

.progress-container {
    display: flex;
    gap: 0;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
}

.progress-group {
    position: relative;
    background-color: rgba(45, 53, 97, 0.3);
    border: 1px solid var(--cell-border);
    border-radius: 0;
    padding: 0.5rem;
    padding-top: 0.75rem;
}

.progress-group:first-child {
    border-radius: 0.5rem 0 0 0.5rem;
    border-right: none;
    border-bottom: 1px solid var(--cell-border);
}

.progress-group:last-child {
    border-radius: 0 0.5rem 0.5rem 0;
    border-left: none;
    border-bottom: 1px solid var(--cell-border);
}

.progress-group:nth-child(2) {
    border-left: 1px solid var(--cell-border);
    border-right: 1px solid var(--cell-border);
    border-bottom: 1px solid var(--cell-border);
}

.progress-group-label {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--container-bg);
    padding: 0 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.progress-group:nth-child(1) .progress-group-label {
    color: var(--correct);
}

.progress-group:nth-child(2) .progress-group-label {
    color: var(--wrong-position);
}

.progress-group:nth-child(3) .progress-group-label {
    color: var(--wrong);
}

.progress-group-items {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.2rem;
}

.progress-item {
    aspect-ratio: 1;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
    border: 1px solid transparent;
    transition: all 0.3s ease;
    cursor: pointer;
    min-width: 26px;
    min-height: 26px;
}

.progress-item.completed {
    background-color: var(--correct);
    color: white;
    border-color: var(--correct);
}

.progress-item.in-progress {
    background-color: var(--wrong-position);
    color: white;
    border-color: var(--wrong-position);
}

.progress-item.not-started {
    background-color: var(--cell-bg);
    color: var(--text-color);
    border-color: var(--cell-border);
}

.progress-item.current {
    border-color: #fff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.progress-item:hover {
    transform: scale(1.05);
    opacity: 0.8;
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    margin-bottom: 1.5rem;
    gap: 0.5rem;
    position: relative;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.info-panel {
    flex: 1;
    background: linear-gradient(135deg, rgba(45, 53, 97, 0.4) 0%, rgba(45, 53, 97, 0.2) 100%);
    border: 1px solid rgba(74, 85, 131, 0.5);
    border-radius: 0.5rem;
    position: relative;
    overflow: hidden;
}

.info-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(76, 175, 80, 0.5), transparent);
    animation: scan 3s linear infinite;
}

@keyframes scan {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.panel-header {
    background: rgba(74, 85, 131, 0.3);
    padding: 0.25rem 0.75rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: #999;
    border-bottom: 1px solid rgba(74, 85, 131, 0.5);
}

.panel-content {
    padding: 0.75rem;
}

.puzzle-panel .panel-content {
    display: flex;
    align-items: stretch;
    gap: 0;
    padding: 0;
    height: 80px;
}

.puzzle-id {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 900;
    color: #fff;
    font-family: 'Courier New', monospace;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.1) 100%);
    padding: 0 1rem;
    position: relative;
    overflow: hidden;
}

.puzzle-id::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 10px,
        rgba(255, 255, 255, 0.02) 10px,
        rgba(255, 255, 255, 0.02) 20px
    );
    animation: stripes 20s linear infinite;
}

@keyframes stripes {
    0% { transform: translateX(0); }
    100% { transform: translateX(28px); }
}

.difficulty-indicator {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    position: relative;
    overflow: hidden;
    border: none;
    transition: all 0.3s ease;
}

.difficulty-indicator::before {
    content: '';
    position: absolute;
    inset: -2px;
    background: linear-gradient(45deg, currentColor, transparent, currentColor);
    opacity: 0.3;
    z-index: -1;
}

.difficulty-indicator::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, currentColor, transparent);
    opacity: 0;
}

@keyframes rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes sweep {
    0%, 100% { 
        transform: translateX(-100%);
        opacity: 0;
    }
    50% { 
        transform: translateX(0%);
        opacity: 0.3;
    }
}

.difficulty-indicator.difficulty-easy {
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.2), rgba(76, 175, 80, 0.4));
    color: #fff;
    text-shadow: 0 0 20px var(--correct);
}

.difficulty-indicator.difficulty-medium {
    background: linear-gradient(135deg, rgba(255, 152, 0, 0.2), rgba(255, 152, 0, 0.4));
    color: #fff;
    text-shadow: 0 0 20px var(--wrong-position);
}

.difficulty-indicator.difficulty-hard {
    background: linear-gradient(135deg, rgba(244, 67, 54, 0.2), rgba(244, 67, 54, 0.4));
    color: #fff;
    text-shadow: 0 0 20px var(--wrong);
}

.moves-display {
    font-size: 2rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    color: #fff;
    text-align: center;
    margin-bottom: 0.5rem;
}

.moves-separator {
    opacity: 0.5;
    margin: 0 0.25rem;
}

.moves-bar {
    width: 100%;
    height: 6px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.moves-bar::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 10px,
        rgba(255, 255, 255, 0.1) 10px,
        rgba(255, 255, 255, 0.1) 11px
    );
}

.moves-progress {
    height: 100%;
    background: var(--correct);
    transition: width 0.3s ease, background-color 0.3s ease;
    box-shadow: 0 0 10px currentColor;
}

.puzzle-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.puzzle-number {
    font-size: 1.4rem;
    font-weight: bold;
    color: #fff;
}

.moves-counter, .difficulty-display {
    font-size: 1.2rem;
}

.difficulty-display {
    font-size: 1rem;
}

.difficulty-display span {
    font-weight: bold;
    text-transform: capitalize;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    margin-left: 0.5rem;
}

.difficulty-easy {
    background-color: rgba(76, 175, 80, 0.2);
    color: var(--correct);
}

.difficulty-medium {
    background-color: rgba(255, 152, 0, 0.2);
    color: var(--wrong-position);
}

.difficulty-hard {
    background-color: rgba(244, 67, 54, 0.2);
    color: var(--wrong);
}

.btn {
    background-color: var(--correct);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn:hover {
    background-color: #45a049;
    transform: translateY(-2px);
}

.grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
    margin: 0 auto;
    max-width: 500px;
}

.cell {
    aspect-ratio: 1;
    background-color: var(--cell-bg);
    border: 2px solid var(--cell-border);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: grab;
    transition: all 0.3s ease;
    user-select: none;
    position: relative;
}

.cell[draggable="true"]:active {
    cursor: grabbing;
}

.cell.dragging {
    opacity: 0.5;
    transform: rotate(5deg);
    z-index: 1000;
}

.cell.drop-zone {
    border-color: #fff;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.7);
    background-color: rgba(255, 255, 255, 0.1);
}

.grid:not(.game-over) .cell:hover:not(.locked):not(.dragging) {
    transform: scale(1.02);
    background-color: #3d4671;
    border-color: #6a7aaa;
}


.cell.locked {
    background-color: var(--locked);
    cursor: not-allowed;
    font-size: 1.8rem;
}

.game-over .cell:not(.locked) {
    cursor: not-allowed;
}

.game-lost .cell {
    background-color: #555 !important;
    border-color: #666 !important;
    color: #999 !important;
    opacity: 0.6;
}

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

.cell.wrong-position {
    background-color: var(--wrong-position);
    border-color: var(--wrong-position);
}

.cell.wrong {
    background-color: var(--wrong);
    border-color: var(--wrong);
}

.cell.swapping {
    animation: swap 0.5s ease;
}

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

.win-message {
    text-align: center;
    margin-top: 2rem;
    padding: 2rem;
    background-color: rgba(76, 175, 80, 0.1);
    border-radius: 0.5rem;
    border: 2px solid var(--correct);
    animation: win-appear 0.5s ease-out;
}

@keyframes win-appear {
    from {
        transform: scale(0.8) translateY(20px);
        opacity: 0;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.win-message h2 {
    margin-bottom: 1rem;
    color: var(--correct);
    font-size: 2rem;
    animation: win-bounce 1s ease-in-out infinite;
}

@keyframes win-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.win-message p {
    margin-bottom: 1.5rem;
    font-size: 1.2rem;
}

.game-won .cell.correct {
    animation: cell-celebrate 0.6s ease-out;
}

@keyframes cell-celebrate {
    0% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.2) rotate(5deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.hidden {
    display: none;
}

.loading {
    text-align: center;
    padding: 2rem;
    font-size: 1.2rem;
    color: #999;
}

.lose-message {
    text-align: center;
    margin-top: 2rem;
    padding: 2rem;
    background-color: rgba(244, 67, 54, 0.1);
    border-radius: 0.5rem;
    border: 2px solid var(--wrong);
}

.lose-message h2 {
    margin-bottom: 1rem;
    color: var(--wrong);
}

.lose-message p {
    margin-bottom: 1.5rem;
    font-size: 1.2rem;
}

.all-completed-message {
    text-align: center;
    margin-top: 2rem;
    padding: 2rem;
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.1), rgba(33, 150, 243, 0.1));
    border-radius: 1rem;
    border: 2px solid var(--correct);
    animation: completion-glow 2s ease-in-out infinite alternate;
}

@keyframes completion-glow {
    from { 
        box-shadow: 0 0 20px rgba(76, 175, 80, 0.3);
        border-color: var(--correct);
    }
    to { 
        box-shadow: 0 0 30px rgba(76, 175, 80, 0.5), 0 0 40px rgba(33, 150, 243, 0.3);
        border-color: #2196f3;
    }
}

.completion-celebration h2 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: var(--correct);
    text-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.completion-celebration p {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    line-height: 1.6;
}

.completion-stats {
    background-color: rgba(76, 175, 80, 0.1);
    padding: 1rem;
    border-radius: 0.5rem;
    margin: 1.5rem 0;
    border: 1px solid var(--correct);
}

.completion-stats p {
    font-weight: bold;
    font-size: 1.2rem;
    margin: 0;
    color: var(--correct);
}

.all-completed-message .btn {
    margin: 0.5rem;
}

.reset-btn {
    background-color: var(--wrong) !important;
}

.reset-btn:hover {
    background-color: #d32f2f !important;
}

.countdown-container {
    margin-top: 2rem;
    padding: 1.5rem;
    background: rgba(76, 175, 80, 0.1);
    border-radius: 0.5rem;
    border: 1px solid var(--correct);
}

.countdown-label {
    font-size: 1rem;
    color: #999;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.countdown-timer {
    font-size: 2.5rem;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    color: var(--correct);
    margin: 0;
    text-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease-out;
}

.tutorial-overlay.hidden {
    display: none !important;
}

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

.tutorial-content {
    background-color: var(--container-bg);
    padding: 2.5rem;
    border-radius: 1rem;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: slideIn 0.3s ease-out;
}

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

.tutorial-logo {
    text-align: center;
    margin-bottom: 1rem;
    font-size: 2.5rem;
    color: #fff;
    font-family: 'Bungee Shade', cursive;
    letter-spacing: 0.05em;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
    animation: title-glow 2s ease-in-out infinite alternate;
}

.tutorial-content h2 {
    text-align: center;
    margin-bottom: 2rem;
    color: #fff;
    font-size: 1.5rem;
}

.tutorial-step {
    margin-bottom: 2rem;
    animation: stepIn 0.5s ease-out;
}

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

.step-number {
    width: 40px;
    height: 40px;
    background-color: var(--correct);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
    margin-bottom: 1rem;
}

.tutorial-step p {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    line-height: 1.6;
}

.tutorial-grid-preview {
    background-color: var(--cell-bg);
    padding: 1rem;
    border-radius: 0.5rem;
    text-align: center;
}

.equation-example {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--correct);
}

.tutorial-animation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    padding: 2rem;
}

.demo-cell {
    width: 60px;
    height: 60px;
    background-color: var(--cell-bg);
    border: 2px solid var(--cell-border);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
}

.dragging-demo {
    animation: dragDemo 2s ease-in-out infinite;
}

@keyframes dragDemo {
    0%, 100% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
    50% { transform: translate(30px, -10px) rotate(5deg); opacity: 0.5; }
}

.drop-zone-demo {
    animation: dropZoneDemo 2s ease-in-out infinite;
}

@keyframes dropZoneDemo {
    0%, 100% { border-color: var(--cell-border); box-shadow: none; }
    50% { border-color: #fff; box-shadow: 0 0 15px rgba(255, 255, 255, 0.7); }
}

.arrow {
    font-size: 2rem;
    color: #999;
}

.color-guide {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.color-example {
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-weight: bold;
    text-align: center;
}

.color-example.correct {
    background-color: var(--correct);
    color: white;
}

.color-example.wrong-position {
    background-color: var(--wrong-position);
    color: white;
}

.color-example.wrong {
    background-color: var(--wrong);
    color: white;
}

.tutorial-tip {
    font-size: 1.1rem;
    color: #bbb;
    font-style: italic;
    margin-top: 1rem;
}

.tutorial-controls {
    display: flex;
    justify-content: space-between;
    margin-top: 2rem;
    gap: 1rem;
}

.btn-secondary {
    background-color: #666;
}

.btn-secondary:hover {
    background-color: #777;
}

.floating-tile {
    position: fixed;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 1001;
    border-radius: 0.75rem;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.5);
    transform: scale(1.2);
    opacity: 0.85;
    transition: none;
    font-size: 2rem !important;
}

.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    top: -10px;
    z-index: 9999;
    animation: confetti-fall 3s linear forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.footer {
    text-align: center;
    padding: 2rem 1rem;
    margin-top: auto;
    border-top: 1px solid var(--cell-border);
    background-color: var(--bg-color);
    width: 100%;
}

.footer p {
    margin: 0;
    font-size: 0.9rem;
    color: #999;
}

.footer a {
    color: var(--correct);
    text-decoration: none;
    transition: color 0.3s ease;
}

.footer a:hover {
    color: #45a049;
    text-decoration: underline;
}

@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }
    
    h1 {
        font-size: 2.5rem;
    }
    
    .slogan {
        font-size: 1rem;
        margin-bottom: 1.5rem;
    }
    
    .cell {
        font-size: 1.2rem;
    }
    
    .game-info {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .info-panel {
        width: 100%;
    }
    
    .panel-header {
        font-size: 0.65rem;
    }
    
    .panel-content {
        padding: 0.5rem;
    }
    
    .puzzle-panel .panel-content {
        height: 50px;
    }
    
    .puzzle-id {
        font-size: 1.8rem;
    }
    
    .difficulty-indicator {
        font-size: 0.8rem;
        letter-spacing: 0.1em;
    }
    
    .moves-display {
        font-size: 1.5rem;
    }
    
    .tutorial-content {
        padding: 1.5rem;
    }
    
    .tutorial-content h2 {
        font-size: 1.5rem;
    }
    
    .tutorial-step p {
        font-size: 1rem;
    }
    
    .demo-cell {
        width: 50px;
        height: 50px;
    }
    
    .progress-grid {
        gap: 0.15rem;
        padding: 0 0.25rem;
    }
    
    .progress-item {
        font-size: 0.6rem;
        min-width: 18px;
        min-height: 18px;
        width: 18px;
        height: 18px;
    }
    
    .progress-group-items {
        gap: 0.15rem;
    }
    
    .progress-container {
        flex-wrap: wrap;
        gap: 0;
    }
    
    .progress-group-label {
        font-size: 0.65rem;
        top: -8px;
    }
}