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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #333;
}

.container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    padding: 30px;
    max-width: 500px;
    width: 100%;
    text-align: center;
}

header h1 {
    color: #4a5568;
    margin-bottom: 10px;
    font-size: 2rem;
    font-weight: 300;
}

header p {
    color: #718096;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.controls {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.settings-row {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.permutation-input {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f7fafc;
    padding: 10px 15px;
    border-radius: 20px;
    border: 2px solid #e2e8f0;
    flex-wrap: wrap;
    justify-content: center;
}

.permutation-input input {
    padding: 8px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    background: white;
    font-size: 0.9rem;
    color: #4a5568;
    min-width: 120px;
}

.permutation-input input:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f7fafc;
    padding: 10px 15px;
    border-radius: 20px;
    border: 2px solid #e2e8f0;
}

.speed-control select {
    padding: 5px 10px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    background: white;
    font-size: 0.9rem;
    color: #4a5568;
    cursor: pointer;
}

.setting-label {
    font-weight: 600;
    color: #4a5568;
    margin-right: 5px;
    white-space: nowrap;
}

.buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.controls button {
    padding: 12px 24px;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.set-btn {
    background: linear-gradient(135deg, #805ad5, #6b46c1);
    color: white;
    padding: 8px 16px;
    font-size: 0.8rem;
}

.set-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(128, 90, 213, 0.4);
}

.start-btn {
    background: linear-gradient(135deg, #48bb78, #38a169);
    color: white;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(72, 187, 120, 0.4);
}

.start-btn:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.reset-btn {
    background: linear-gradient(135deg, #4299e1, #3182ce);
    color: white;
}

.reset-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(66, 153, 225, 0.4);
}

.ladder-container {
    background: #f7fafc;
    border-radius: 15px;
    padding: 20px;
    margin: 20px 0;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

#ladderSvg {
    max-width: 100%;
    height: auto;
}

.rail {
    stroke: #4a5568;
    stroke-width: 3;
    stroke-linecap: round;
}

.top-number-circle {
    fill: #4299e1;
    stroke: #2b6cb0;
    stroke-width: 2;
}

.bottom-number-circle {
    fill: #ed8936;
    stroke: #dd6b20;
    stroke-width: 2;
}

.working-number-circle {
    fill: #e53e3e;
    stroke: #c53030;
    stroke-width: 2;
}

.target-number-circle {
    fill: #9f7aea;
    stroke: #805ad5;
    stroke-width: 2;
}

.target-number-square {
    fill: #9f7aea;
    stroke: #805ad5;
    stroke-width: 2;
}

.working-number-square {
    fill: #e53e3e;
    stroke: #c53030;
    stroke-width: 2;
}

.number-text {
    fill: white;
    font-size: 16px;
    font-weight: bold;
    text-anchor: middle;
    dominant-baseline: middle;
}

.working-number-text {
    fill: white;
    font-size: 14px;
    font-weight: bold;
    text-anchor: middle;
    dominant-baseline: middle;
}

.target-number-text {
    fill: white;
    font-size: 14px;
    font-weight: bold;
    text-anchor: middle;
    dominant-baseline: middle;
}

.section-label {
    fill: #4a5568;
    font-size: 14px;
    font-weight: 600;
    text-anchor: middle;
    dominant-baseline: middle;
}

.rung {
    stroke: #48bb78;
    stroke-width: 4;
    stroke-linecap: round;
}

.highlighted-rung {
    stroke: #f56565;
    stroke-width: 6;
    stroke-linecap: round;
}

.status {
    background: #edf2f7;
    border-radius: 10px;
    padding: 15px;
    margin-top: 20px;
}

.status p {
    color: #4a5568;
    font-size: 0.9rem;
    margin: 0;
}

.info-panel {
    background: #f0fff4;
    border-radius: 10px;
    padding: 15px;
    margin-top: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 2px solid #c6f6d5;
}

.rung-count {
    font-weight: 600;
    color: #2d3748;
}

.step-info {
    font-size: 0.9rem;
    color: #4a5568;
}

/* Animation classes */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

.fade-out {
    animation: fadeOut 0.3s ease-out;
}

.highlight {
    animation: highlight 1s ease-in-out;
}

.swap-highlight {
    animation: swapHighlight 0.8s ease-in-out;
}

.working-number-square.swap-highlight {
    animation: squareSwapHighlight 0.6s ease-in-out;
}

.working-number-square.highlight {
    animation: squareHighlight 1s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes fadeOut {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.8); }
}

@keyframes highlight {
    0% { fill: #e53e3e; }
    50% { fill: #f56565; }
    100% { fill: #e53e3e; }
}

@keyframes squareHighlight {
    0% { fill: #e53e3e; }
    50% { fill: #f56565; }
    100% { fill: #e53e3e; }
}

@keyframes swapHighlight {
    0% { stroke-width: 4; }
    50% { stroke-width: 6; }
    100% { stroke-width: 4; }
}

@keyframes squareSwapHighlight {
    0% { fill: #e53e3e; }
    50% { fill: #f56565; transform: scale(1.1); }
    100% { fill: #e53e3e; transform: scale(1); }
}

/* Error popup styles */
.error-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 100px;
}

.error-content {
    background: white;
    border-radius: 10px;
    padding: 20px 30px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: relative;
    border-left: 5px solid #e53e3e;
}

.error-close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    font-weight: bold;
    color: #999;
    cursor: pointer;
    transition: color 0.3s;
}

.error-close:hover {
    color: #333;
}

.error-content p {
    margin: 0;
    color: #333;
    font-size: 16px;
    line-height: 1.4;
}

/* Success popup styles */
.success-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 100px;
}

.success-content {
    background: white;
    border-radius: 10px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: relative;
    border-left: 5px solid #48bb78;
    text-align: center;
}

.success-close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    font-weight: bold;
    color: #999;
    cursor: pointer;
    transition: color 0.3s;
}

.success-close:hover {
    color: #333;
}

.success-content h3 {
    margin: 0 0 15px 0;
    color: #48bb78;
    font-size: 20px;
    font-weight: bold;
}

.success-content p {
    margin: 0;
    color: #333;
    font-size: 16px;
    line-height: 1.4;
}

/* Responsive design */
@media (max-width: 600px) {
    .container {
        margin: 20px;
        padding: 20px;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
    .settings-row {
        flex-direction: column;
        gap: 10px;
    }
    
    .permutation-input, .speed-control {
        width: 100%;
        justify-content: center;
    }
    
    .buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .buttons button {
        width: 100%;
        max-width: 200px;
    }
    
    .info-panel {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
}
