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

html {
    scroll-behavior: smooth;
    color-scheme: dark;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-family: 'Inter', system-ui, sans-serif;
    color: #f3f4f6;
    background-color: #0a0e1a;
}

h1,
h2,
h3,
h4 {
    font-family: 'Fira Sans', system-ui, sans-serif !important;
}

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

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

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

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.converter-mode {
    animation: scaleIn 0.3s ease-out;
}

.history-item {
    animation: slideIn 0.3s ease-out;
}

.mode-btn.active {
    background: linear-gradient(135deg, #06b6d4, #3b82f6);
    color: #ffffff;
    box-shadow: 0 0 20px rgba(6, 182, 212, 0.4);
    border-color: #06b6d4;
}

.mode-btn {
    transition: all 0.2s ease;
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #9ca3af;
}

.mode-btn:hover:not(.active) {
    background: rgba(51, 65, 85, 0.8);
    color: #f3f4f6;
}

input[type="text"],
input[type="number"] {
    font-variant-numeric: tabular-nums;
}

.result-display {
    animation: pulse 0.5s ease-in-out;
}

button {
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

button:active {
    transform: scale(0.98);
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #0a0e1a;
}

::-webkit-scrollbar-thumb {
    background: rgba(6, 182, 212, 0.4);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #06b6d4;
}

/* Switch Styles */
.bit-switch {
    width: 60px;
    height: 100px;
    border-radius: 30px;
    position: relative;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.6);
}

.bit-switch.active {
    background: linear-gradient(180deg, #06b6d4, #3b82f6);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.5), inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

.bit-switch.inactive {
    background-color: #334155;
}

.bit-knob {
    width: 48px;
    height: 48px;
    background-color: #f8fafc;
    border-radius: 50%;
    position: absolute;
    left: 6px;
    transition: all 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.bit-switch.active .bit-knob {
    top: 6px;
}

.bit-switch.inactive .bit-knob {
    top: 46px;
}

/* Hover effects */
.bit-switch:hover .bit-knob {
    box-shadow: 0 0 12px rgba(6, 182, 212, 0.8);
    transform: scale(1.05);
}

/* Theory Animations */
@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

.animate-float {
    animation: float 3s ease-in-out infinite;
}

.perspective-1000 {
    perspective: 1000px;
}

.flip-card {
    background-color: transparent;
    perspective: 1000px;
}

.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.flip-card:hover .flip-card-inner {
    transform: rotateY(180deg);
}

.flip-card-front,
.flip-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 1rem;
}

.flip-card-front {
    background: #1e293b;
    border: 2px solid #475569;
    color: #94a3b8;
}

.flip-card-back {
    background: linear-gradient(135deg, #06b6d4, #3b82f6);
    border: 2px solid #38bdf8;
    color: white;
    transform: rotateY(180deg);
}

.ladder-bar {
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom;
}

.ladder-bar:hover {
    transform: scaleY(1.1);
    filter: brightness(1.2);
}

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

.byte-container {
    animation: slideLeft 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Mobile optimization */
@media (max-width: 640px) {
    .converter-mode {
        animation: scaleIn 0.2s ease-out;
    }

    .mode-btn {
        font-size: 0.875rem;
        padding: 0.5rem 1rem;
    }

    .bit-switch {
        width: 38px;
        height: 64px;
        border-radius: 20px;
    }

    .bit-knob {
        width: 30px;
        height: 30px;
        left: 4px;
    }

    .bit-switch.active .bit-knob {
        top: 4px;
    }

    .bit-switch.inactive .bit-knob {
        top: 30px;
    }

    .byte-label {
        font-size: 0.7rem;
    }

    .bit-value-label {
        font-size: 0.7rem;
    }
}

@media (max-width: 375px) {
    body {
        font-size: 14px;
    }

    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* Toggle Checkbox Custom Styling */
.toggle-checkbox {
    appearance: none;
    -webkit-appearance: none;
    position: absolute;
    z-index: 10;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.toggle-label {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: #334155;
    border-radius: 9999px;
    transition: background-color 0.2s;
    pointer-events: none;
}

.toggle-label:after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background-color: #f8fafc;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    transition: transform 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
    display: block !important;
}

.toggle-checkbox:checked + .toggle-label {
    background-color: #10b981;
}

.toggle-checkbox:checked + .toggle-label:after {
    transform: translateX(16px);
}

.gate-output-on {
    background-color: #f59e0b !important;
    box-shadow: 0 0 15px #f59e0b, inset 0 0 5px #d97706 !important;
    border-color: #fbbf24 !important;
    transition: all 0.2s ease;
}

/* Pixel Art Grid */
.pixel-cell {
    width: 24px;
    height: 24px;
    background-color: #1e293b;
    border-radius: 4px;
    transition: all 0.1s ease;
    border: 1px solid #334155;
}

@media (min-width: 640px) {
    .pixel-cell {
        width: 32px;
        height: 32px;
    }
}

.pixel-cell:hover {
    background-color: #334155;
    transform: scale(1.1);
    z-index: 10;
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.3);
    cursor: pointer;
}

.pixel-cell.active {
    background-color: #06b6d4;
    border-color: #38bdf8;
    box-shadow: 0 0 12px rgba(6, 182, 212, 0.8);
}

/* Integer Overflow Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.animate-shake {
    animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both;
}

.overflow-alert {
    transition: all 0.3s ease;
    opacity: 0;
    transform: scale(0.9);
}

.overflow-alert.visible {
    opacity: 1;
    transform: scale(1);
}

.overflow-bg {
    transition: background-color 0.2s ease;
}

.overflow-bg.danger {
    background-color: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
}

/* Memory Architecture Styles */
.stack-frame {
    width: 90%;
    background-color: rgba(99, 102, 241, 0.15);
    border: 1px solid #6366f1;
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 4px;
    text-align: center;
    font-size: 0.8rem;
    font-weight: bold;
    color: #c7d2fe;
    animation: slideInLeft 0.3s ease-out;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.heap-block {
    width: 60%;
    height: 40px;
    background-color: rgba(168, 85, 247, 0.15);
    border: 1px dashed #a855f7;
    border-radius: 8px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: #e9d5ff;
    animation: fadeIn 0.4s ease-out;
}

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

/* Visual Register Bits */
.memory-bit {
    width: 24px;
    height: 32px;
    background-color: #1e293b;
    border: 1px solid #475569;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'JetBrains Mono', monospace;
    font-weight: bold;
    color: #94a3b8;
    transition: all 0.2s;
}

.memory-bit.on {
    background-color: #06b6d4;
    color: #030712;
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.7);
    border-color: #38bdf8;
    transform: translateY(-2px);
}

/* Carry Bit Animation */
.carry-bit {
    position: absolute;
    width: 24px;
    height: 32px;
    background-color: #ef4444;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-weight: bold;
    font-family: 'JetBrains Mono', monospace;
    animation: dropOff 1s forwards ease-in;
}

@keyframes dropOff {
    0% {
        transform: translate(0, 0) rotate(0);
        opacity: 1;
    }
    20% {
        transform: translate(10px, -10px) rotate(45deg);
    }
    100% {
        transform: translate(20px, 100px) rotate(180deg);
        opacity: 0;
    }
}

/* Powers Section Animations */
@keyframes powerSlideIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes powerPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.4);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 20px 5px rgba(6, 182, 212, 0.3);
    }
}

.power-card {
    animation: powerSlideIn 0.5s ease-out forwards;
    opacity: 0;
}

.power-card:nth-child(1) { animation-delay: 0.1s; }
.power-card:nth-child(2) { animation-delay: 0.2s; }
.power-card:nth-child(3) { animation-delay: 0.3s; }
.power-card:nth-child(4) { animation-delay: 0.4s; }
.power-card:nth-child(5) { animation-delay: 0.5s; }

.power-value {
    transition: all 0.3s ease;
}

.power-value:hover {
    animation: powerPulse 0.6s ease-in-out;
}