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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1.2rem;
    opacity: 0.9;
}

.main-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}

/* Input Section */
.input-section {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
    flex-wrap: wrap;
}

.input-section label {
    font-weight: 600;
    color: #495057;
}

.input-section input {
    padding: 10px 15px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 16px;
    min-width: 200px;
    transition: border-color 0.3s ease;
}

.input-section input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#start-btn {
    background: linear-gradient(135deg, #28a745, #20c997);
    color: white;
}

#start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.4);
}

#reset-btn {
    background: linear-gradient(135deg, #dc3545, #e83e8c);
    color: white;
}

#reset-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(220, 53, 69, 0.4);
}

/* Visualization Area */
.visualization-area {
    margin-bottom: 30px;
}

.string-display, .transformed-display, .p-array-display {
    margin-bottom: 25px;
}

.string-display h3, .transformed-display h3, .p-array-display h3 {
    color: #495057;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.string-container, .array-container {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    min-height: 60px;
    align-items: center;
}

.char-box, .array-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background: white;
    font-weight: 600;
    font-size: 16px;
    transition: all 0.5s ease;
    position: relative;
}

.array-item {
    flex-direction: column;
    font-size: 12px;
}

.array-item.current {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    transform: scale(1.2);
    box-shadow: 0 0 25px rgba(102, 126, 234, 0.7);
    border-color: #667eea;
    animation: currentPulse 2s infinite;
}

.char-box.current {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-color: #667eea;
    transform: scale(1.3);
    box-shadow: 0 0 30px rgba(102, 126, 234, 0.8);
    animation: currentPulse 2s infinite;
    z-index: 10;
}

.char-box.center {
    background: linear-gradient(135deg, #28a745, #20c997);
    color: white;
    border-color: #28a745;
    transform: scale(1.25);
    box-shadow: 0 0 35px rgba(40, 167, 69, 0.9);
    animation: centerGlow 2s infinite;
    z-index: 9;
}

.char-box.right-boundary {
    background: linear-gradient(135deg, #ffc107, #fd7e14);
    color: white;
    border-color: #ffc107;
    transform: scale(1.2);
    box-shadow: 0 0 30px rgba(255, 193, 7, 0.8);
    animation: rightBoundaryPulse 2s infinite;
    z-index: 8;
}

.char-box.palindrome-range {
    background: linear-gradient(135deg, #17a2b8, #6f42c1);
    color: white;
    border-color: #17a2b8;
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(23, 162, 184, 0.6);
    animation: palindromeWave 2s infinite;
}

.char-box.mirror {
    background: linear-gradient(135deg, #e83e8c, #dc3545);
    color: white;
    border-color: #e83e8c;
    transform: scale(1.2);
    box-shadow: 0 0 30px rgba(232, 62, 140, 0.8);
    animation: mirrorFlash 1.5s infinite;
    z-index: 8;
}

.char-box.expansion-left, .char-box.expansion-right {
    background: linear-gradient(135deg, #17a2b8, #6f42c1);
    color: white;
    border-color: #17a2b8;
    animation: expansionBounce 1s infinite;
}

/* Enhanced Animations */
@keyframes currentPulse {
    0%, 100% { 
        transform: scale(1.3);
        box-shadow: 0 0 30px rgba(102, 126, 234, 0.8);
    }
    50% { 
        transform: scale(1.4);
        box-shadow: 0 0 40px rgba(102, 126, 234, 1);
    }
}

@keyframes centerGlow {
    0%, 100% { 
        transform: scale(1.25);
        box-shadow: 0 0 35px rgba(40, 167, 69, 0.9);
    }
    50% { 
        transform: scale(1.35);
        box-shadow: 0 0 45px rgba(40, 167, 69, 1);
    }
}

@keyframes rightBoundaryPulse {
    0%, 100% { 
        transform: scale(1.2);
        box-shadow: 0 0 30px rgba(255, 193, 7, 0.8);
    }
    50% { 
        transform: scale(1.3);
        box-shadow: 0 0 40px rgba(255, 193, 7, 1);
    }
}

@keyframes mirrorFlash {
    0%, 100% { 
        transform: scale(1.2);
        box-shadow: 0 0 30px rgba(232, 62, 140, 0.8);
    }
    25% { 
        transform: scale(1.3);
        box-shadow: 0 0 40px rgba(232, 62, 140, 1);
    }
    50% { 
        transform: scale(1.25);
        box-shadow: 0 0 35px rgba(232, 62, 140, 0.9);
    }
    75% { 
        transform: scale(1.3);
        box-shadow: 0 0 40px rgba(232, 62, 140, 1);
    }
}

@keyframes palindromeWave {
    0%, 100% { 
        transform: scale(1.1);
        box-shadow: 0 0 20px rgba(23, 162, 184, 0.6);
    }
    50% { 
        transform: scale(1.15);
        box-shadow: 0 0 25px rgba(23, 162, 184, 0.8);
    }
}

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

/* Connection Lines and Visual Indicators */
.char-box.center::before {
    content: "CENTER";
    position: absolute;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: #28a745;
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: bold;
    animation: centerLabel 2s infinite;
    z-index: 15;
}

.char-box.mirror::before {
    content: "MIRROR";
    position: absolute;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: #dc3545;
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: bold;
    animation: mirrorLabel 1.5s infinite;
    z-index: 15;
}

.char-box.right-boundary::before {
    content: "RIGHT";
    position: absolute;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: #ffc107;
    color: #212529;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: bold;
    animation: rightLabel 2s infinite;
    z-index: 15;
}

.char-box.current::after {
    content: "CURRENT";
    position: absolute;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: #667eea;
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: bold;
    animation: currentLabel 2s infinite;
    z-index: 15;
}

@keyframes centerLabel {
    0%, 100% { 
        transform: translateX(-50%) translateY(0);
        opacity: 0.9;
    }
    50% { 
        transform: translateX(-50%) translateY(-5px);
        opacity: 1;
    }
}

@keyframes mirrorLabel {
    0%, 100% { 
        transform: translateX(-50%) translateY(0);
        opacity: 0.9;
    }
    25%, 75% { 
        transform: translateX(-50%) translateY(-8px);
        opacity: 1;
    }
    50% { 
        transform: translateX(-50%) translateY(-3px);
        opacity: 0.95;
    }
}

@keyframes rightLabel {
    0%, 100% { 
        transform: translateX(-50%) translateY(0);
        opacity: 0.9;
    }
    50% { 
        transform: translateX(-50%) translateY(-5px);
        opacity: 1;
    }
}

@keyframes currentLabel {
    0%, 100% { 
        transform: translateX(-50%) translateY(0);
        opacity: 0.9;
    }
    50% { 
        transform: translateX(-50%) translateY(-8px);
        opacity: 1;
    }
}

/* Additional animations for enhanced visual effects */
@keyframes connectionPulse {
    0%, 100% { 
        opacity: 0.7;
        box-shadow: 0 0 10px rgba(220, 53, 69, 0.5);
    }
    50% { 
        opacity: 1;
        box-shadow: 0 0 20px rgba(220, 53, 69, 0.8);
    }
}

@keyframes labelFloat {
    0% { 
        transform: translateX(-50%) translateY(10px);
        opacity: 0;
    }
    20% { 
        transform: translateX(-50%) translateY(-5px);
        opacity: 1;
    }
    80% { 
        transform: translateX(-50%) translateY(-5px);
        opacity: 1;
    }
    100% { 
        transform: translateX(-50%) translateY(-15px);
        opacity: 0;
    }
}

@keyframes explanationFloat {
    0% { 
        transform: translateX(-50%) translateY(20px);
        opacity: 0;
        scale: 0.8;
    }
    15% { 
        transform: translateX(-50%) translateY(-10px);
        opacity: 1;
        scale: 1;
    }
    85% { 
        transform: translateX(-50%) translateY(-10px);
        opacity: 1;
        scale: 1;
    }
    100% { 
        transform: translateX(-50%) translateY(-30px);
        opacity: 0;
        scale: 0.8;
    }
}

/* Enhanced slide-in animation */
.slide-in {
    animation: slideInFromRight 0.5s ease-out;
}

@keyframes slideInFromRight {
    0% {
        transform: translateX(100%);
        opacity: 0;
    }
    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

.array-item {
    flex-direction: column;
    font-size: 12px;
}

.array-item .index {
    font-size: 10px;
    color: #6c757d;
    margin-bottom: 2px;
}

.array-item .value {
    font-weight: bold;
    font-size: 14px;
}

/* Algorithm State */
.algorithm-state {
    margin: 25px 0;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 10px;
    border-left: 5px solid #667eea;
}

.state-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.state-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.state-item .label {
    font-weight: 600;
    color: #495057;
}

.state-item .value {
    font-weight: bold;
    color: #667eea;
    font-size: 1.1rem;
}

/* Code Section */
.code-section {
    margin-bottom: 30px;
}

.code-section h3 {
    color: #495057;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.code-container {
    background: #2d3748;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    overflow-x: auto;
}

.code-container pre {
    color: #e2e8f0;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    margin: 0;
}

.code-line {
    display: block;
    padding: 2px 0;
    transition: all 0.3s ease;
}

.code-line.current {
    background: rgba(102, 126, 234, 0.3);
    border-left: 4px solid #667eea;
    padding-left: 10px;
    margin-left: -10px;
}

/* Current Code Line Display */
.current-code-section {
    margin-bottom: 30px;
    padding: 20px;
    background: linear-gradient(135deg, #e8f5e8, #f0f8f0);
    border-radius: 10px;
    border-left: 5px solid #28a745;
}

.current-code-section h3 {
    color: #155724;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.current-code-container {
    background: #1a202c;
    border-radius: 8px;
    padding: 15px;
    border: 2px solid #28a745;
    box-shadow: 0 4px 8px rgba(40, 167, 69, 0.2);
}

.current-code-container pre {
    color: #68d391;
    font-family: 'Courier New', monospace;
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    text-shadow: 0 0 5px rgba(104, 211, 145, 0.3);
    transition: all 0.3s ease;
}

.current-code-container.highlight {
    animation: codeHighlight 1s ease-in-out;
}

@keyframes codeHighlight {
    0% { transform: scale(1); box-shadow: 0 4px 8px rgba(40, 167, 69, 0.2); }
    50% { transform: scale(1.02); box-shadow: 0 8px 16px rgba(40, 167, 69, 0.4); }
    100% { transform: scale(1); box-shadow: 0 4px 8px rgba(40, 167, 69, 0.2); }
}

.explanation {
    padding: 20px;
    background: #e3f2fd;
    border-radius: 10px;
    border-left: 5px solid #2196f3;
}

.explanation h4 {
    color: #1976d2;
    margin-bottom: 10px;
}

.explanation div {
    color: #424242;
    line-height: 1.6;
}

/* Controls */
.controls {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
    flex-wrap: wrap;
}

.controls button {
    background: linear-gradient(135deg, #6c757d, #495057);
    color: white;
}

.controls button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(108, 117, 125, 0.4);
}

.controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#play-btn {
    background: linear-gradient(135deg, #28a745, #20c997);
}

#pause-btn {
    background: linear-gradient(135deg, #ffc107, #fd7e14);
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.speed-control label {
    font-weight: 600;
    color: #495057;
}

.speed-control input[type="range"] {
    width: 100px;
}

/* Result Section */
.result-section {
    padding: 20px;
    background: linear-gradient(135deg, #d4edda, #c3e6cb);
    border-radius: 10px;
    border-left: 5px solid #28a745;
}

.result-section h3 {
    color: #155724;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

#result-display {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.result-item .label {
    font-weight: 600;
    color: #495057;
}

.result-item .value {
    font-weight: bold;
    color: #28a745;
    font-size: 1.1rem;
}

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

.pulse {
    animation: pulse 1s infinite;
}

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

.slide-in {
    animation: slideIn 0.5s ease-out;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .main-content {
        padding: 20px;
    }
    
    .input-section {
        flex-direction: column;
        align-items: stretch;
    }
    
    .input-section input {
        min-width: auto;
        width: 100%;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .speed-control {
        margin-left: 0;
        justify-content: center;
    }
    
    .state-info {
        grid-template-columns: 1fr;
    }
    
    #result-display {
        grid-template-columns: 1fr;
    }
}

