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

:root {
    --primary-color: #2c3e50;
    --secondary-color: #34495e;
    --accent-color: #3498db;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --light-color: #ecf0f1;
    --dark-color: #1a252f;
    --shadow-color: rgba(0, 0, 0, 0.1);
    
    --bit-size: clamp(60px, 8vw, 100px);
    --bit-gap: clamp(8px, 1vw, 16px);
    --border-radius: 8px;
    --transition-speed: 0.3s;
    --flip-duration: 0.6s;
}

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

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

/* Header Styles */
header {
    text-align: center;
    margin-bottom: 20px;
    color: white;
}

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

.subtitle {
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    opacity: 0.9;
    font-weight: 300;
}

/* Counter Section */
.counter-section {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 30px var(--shadow-color);
    padding: 5px 5px;
    margin-bottom: 20px;
}

.counter-container {
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
    min-height: calc(var(--bit-size) + 40px);
}

.bit-container {
    display: flex;
    flex-wrap: wrap;
    gap: var(--bit-gap);
    justify-content: center;
    align-items: center;
    perspective: 1000px;
}

/* Bit Styles */
.bit {
    position: relative;
    width: var(--bit-size);
    height: var(--bit-size);
    cursor: default;
}

.bit-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid var(--secondary-color);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    font-weight: bold;
    backface-visibility: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    transform-style: preserve-3d;
    transition: transform var(--flip-duration) ease-in-out;
}

.bit-front {
    background: linear-gradient(145deg, #ff6b6b, #ee5a52);
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    transform: rotateX(0deg);
}

.bit-back {
    background: linear-gradient(145deg, #4ecdc4, #44a08d);
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    transform: rotateX(180deg);
}

.bit-label {
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    color: var(--secondary-color);
    font-weight: 600;
}

/* Display Section */
.display-section {
    border-top: 2px solid var(--light-color);
    padding-top: 20px;
}

.value-display {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    text-align: center;
}

.display-item {
    background: var(--light-color);
    padding: 15px;
    border-radius: var(--border-radius);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.display-item label {
    display: block;
    font-size: 0.9rem;
    color: var(--secondary-color);
    margin-bottom: 5px;
    font-weight: 600;
}

.binary-value, .decimal-value, .max-value {
    font-size: clamp(1.2rem, 3vw, 1.8rem);
    font-weight: bold;
    font-family: 'Courier New', monospace;
}

.binary-value {
    color: var(--accent-color);
    letter-spacing: 2px;
}

.decimal-value {
    color: var(--success-color);
}

.max-value {
    color: var(--warning-color);
}

/* Controls Section */
.controls-section {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 30px var(--shadow-color);
    padding: 20px 5px;
    margin-bottom: 20px;
}

.control-group {
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    align-items: center;
}

.control-group:last-child {
    margin-bottom: 0;
}

/* Button Styles */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(145deg, var(--accent-color), #2980b9);
    color: white;
}

.btn-secondary {
    background: linear-gradient(145deg, var(--secondary-color), var(--primary-color));
    color: white;
}

.btn-accent {
    background: linear-gradient(145deg, var(--success-color), #229954);
    color: white;
}

.btn-warning {
    background: linear-gradient(145deg, var(--warning-color), #e67e22);
    color: white;
}

.btn-icon {
    font-size: 1.2em;
}

/* Bit Controls */
.bit-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.bit-controls label {
    font-weight: 600;
    color: var(--secondary-color);
}

.input-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.bit-input {
    padding: 8px 12px;
    border: 2px solid var(--light-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    width: 80px;
    text-align: center;
    transition: border-color var(--transition-speed);
}

.bit-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

/* Status Section */
.status-section {
    margin-top: 20px;
    text-align: center;
}

.status-message {
    min-height: 20px;
    font-weight: 600;
    margin-bottom: 15px;
    font-size: 1rem;
}

.status-message.success {
    color: var(--success-color);
}

.status-message.warning {
    color: var(--warning-color);
}

.status-message.error {
    color: var(--danger-color);
}

.overflow-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 20px;
    background: var(--light-color);
    border-radius: var(--border-radius);
    display: inline-flex;
}

.indicator-light {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--success-color);
    transition: background-color var(--transition-speed);
    box-shadow: 0 0 10px rgba(39, 174, 96, 0.5);
}

.overflow-indicator.ready .indicator-light {
    background: var(--warning-color);
    box-shadow: 0 0 10px rgba(243, 156, 18, 0.5);
    animation: pulse 2s infinite;
}

.indicator-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--secondary-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Info Section */
.info-section {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: 0 10px 30px var(--shadow-color);
    overflow: hidden;
}

.info-panel {
    cursor: pointer;
}

.info-panel summary {
    padding: 20px;
    background: var(--primary-color);
    color: white;
    font-weight: 600;
    font-size: 1.1rem;
    list-style: none;
    transition: background-color var(--transition-speed);
}

.info-panel summary:hover {
    background: var(--secondary-color);
}

.info-panel summary::before {
    content: "▶";
    margin-right: 10px;
    transition: transform var(--transition-speed);
}

.info-panel[open] summary::before {
    transform: rotate(90deg);
}

.info-content {
    padding: 20px;
    line-height: 1.8;
}

.info-content p {
    margin-bottom: 15px;
}

.info-content strong {
    color: var(--accent-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .counter-section, .controls-section {
        padding: 20px 15px;
    }
    
    .control-group {
        flex-direction: column;
        align-items: stretch;
    }
    
    .bit-controls {
        align-items: stretch;
    }
    
    .input-group {
        justify-content: center;
    }
    
    .value-display {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    :root {
        --bit-size: 50px;
        --bit-gap: 6px;
    }
    
    .bit-container {
        gap: var(--bit-gap);
    }
    
    .btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
}

/* Animation for bit addition */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.bit.new {
    animation: slideIn 0.5s ease-out;
}

/* Animation for bit removal */
@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.8);
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .bit-face {
        border-width: 4px;
    }
    
    .btn {
        border: 2px solid transparent;
    }
    
    .btn:focus {
        border-color: var(--dark-color);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .bit-face {
        transition: none !important;
    }
}
