/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 500px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header styles */
header {
    text-align: center;
    margin-bottom: 1rem;
    color: white;
}

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

header p {
    font-size: 1rem;
    opacity: 0.9;
    font-weight: 300;
}

/* Main content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.grid-container {
    background: white;
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 100%;
    max-width: 450px;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Grid section */
.grid-section {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Grid styles */
.grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 1rem;
    justify-content: center;
}

.grid-cell {
    width: 60px;
    height: 60px;
    border: 2px solid #3b82f6;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    background: #f9fafb;
    display: flex;
    align-items: center;
    justify-content: center;
}

.grid-cell:hover {
    border-color: #667eea;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.grid-cell.active {
    background: #667eea;
    border-color: #4f46e5;
}

.grid-cell.active::after {
    content: '';
    width: 30px;
    height: 30px;
    background: #3b82f6;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
    animation: dotAppear 0.3s ease-out;
}

/* Triangle in top-left corner of first cell */
.grid-cell[data-row="0"][data-col="0"]::before {
    content: '';
    position: absolute;
    top: 0px;
    left: 0px;
    width: 0;
    height: 0;
    border-left: 20px solid #3b82f6;
    border-bottom: 20px solid transparent;
    z-index: 2;
}

/* Results section */
.results-section {
    width: 100%;
}

.results-section h3 {
    color: #374151;
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
    text-align: center;
    font-weight: 600;
}

.result-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.375rem;
    background: #f8fafc;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.result-row:hover {
    background: #f1f5f9;
    transform: translateX(5px);
}

.row-label {
    font-weight: 600;
    color: #4b5563;
    min-width: 60px;
}

.binary-display {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-weight: 600;
    color: #667eea;
    letter-spacing: 2px;
    font-size: 1.1rem;
    min-width: 80px;
    text-align: center;
}

.arrow {
    color: #6b7280;
    font-weight: bold;
    margin: 0 1rem;
}

.decimal-display {
    font-weight: 700;
    color: #059669;
    font-size: 1.2rem;
    min-width: 40px;
    text-align: right;
    transition: all 0.3s ease;
}

.decimal-display.updated {
    color: #dc2626;
    animation: highlight 0.5s ease-out;
}

/* Controls */
.controls {
    text-align: center;
    width: 100%;
}

.clear-btn {
    padding: 0.75rem 2rem;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    background: #f3f4f6;
    color: #374151;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.clear-btn:hover {
    background: #e5e7eb;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Footer */
footer {
    text-align: center;
    margin-top: 1rem;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.8rem;
}

/* Animations */
@keyframes dotAppear {
    0% { 
        transform: scale(0);
        opacity: 0;
    }
    50% { 
        transform: scale(1.2);
        opacity: 0.8;
    }
    100% { 
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes highlight {
    0% { 
        background: #fef2f2;
        transform: scale(1);
    }
    50% { 
        background: #fee2e2;
        transform: scale(1.05);
    }
    100% { 
        background: transparent;
        transform: scale(1);
    }
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .grid-container {
        padding: 1.5rem;
    }
    
    .grid-cell {
        width: 60px;
        height: 60px;
    }
    
    .grid-cell.active::after {
        width: 30px;
        height: 30px;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.6rem;
    }
    
    header p {
        font-size: 0.9rem;
    }
    
    .container {
        padding: 0.75rem;
    }
    
    .grid-container {
        padding: 1rem;
        gap: 1rem;
    }
    
    .grid-cell {
        width: 45px;
        height: 45px;
    }
    
    .grid-cell.active::after {
        width: 22px;
        height: 22px;
    }
    
    /* Better mobile layout for result rows */
    .result-row {
        padding: 0.75rem 0.5rem;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 0.25rem;
        font-size: 0.9rem;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        margin-bottom: 0.5rem;
    }
    
    .row-label {
        font-size: 0.85rem;
        min-width: 50px;
        flex-shrink: 0;
    }
    
    .binary-display {
        font-size: 1rem;
        letter-spacing: 1px;
        min-width: 65px;
        background: #667eea;
        color: white;
        padding: 0.25rem 0.5rem;
        border-radius: 4px;
        text-align: center;
    }
    
    .arrow {
        margin: 0 0.25rem;
        font-size: 0.9rem;
    }
    
    .decimal-display {
        font-size: 1.1rem;
        min-width: 35px;
        background: #10b981;
        color: white;
        padding: 0.25rem 0.5rem;
        border-radius: 4px;
        text-align: center;
    }
    
    .decimal-display.updated {
        background: #ef4444;
        animation: mobileHighlight 0.5s ease-out;
    }
    
    /* Touch-friendly grid spacing */
    .grid {
        gap: 6px;
        margin-bottom: 1.25rem;
    }
    
    /* Better footer on mobile */
    footer {
        font-size: 0.75rem;
        margin-top: 1.5rem;
        padding: 0.5rem;
    }
}

/* Extra small screens */
@media (max-width: 360px) {
    .container {
        padding: 0.5rem;
    }
    
    .grid-container {
        padding: 0.75rem;
    }
    
    .grid-cell {
        width: 40px;
        height: 40px;
    }
    
    .grid-cell.active::after {
        width: 20px;
        height: 20px;
    }
    
    .result-row {
        padding: 0.5rem;
        font-size: 0.85rem;
    }
    
    .binary-display {
        font-size: 0.9rem;
        min-width: 60px;
        padding: 0.2rem 0.4rem;
    }
    
    .decimal-display {
        font-size: 1rem;
        min-width: 30px;
        padding: 0.2rem 0.4rem;
    }
    
    .row-label {
        font-size: 0.8rem;
        min-width: 45px;
    }
    
    header h1 {
        font-size: 1.4rem;
    }
}

/* Mobile-specific animation */
@keyframes mobileHighlight {
    0% { 
        background: #ef4444;
        transform: scale(1);
    }
    50% { 
        background: #dc2626;
        transform: scale(1.02);
    }
    100% { 
        background: #10b981;
        transform: scale(1);
    }
}