:root {
    --cpp-blue: #004482;
    --cpp-light: #659ad2;
    --bg-color: #f8f9fa;
    --pointer-color: #e67e22;
    --node-color: #2ecc71;
    --highlight-color: #f39c12;
    --negative-color: #e74c3c;
    --positive-color: #2ecc71;
    --and-color: #9b59b6;
    --or-color: #3498db;
    --xor-color: #e74c3c;
    --not-color: #1abc9c;
    --shift-color: #f39c12;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-color);
    margin: 0;
    color: #333;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px;
    flex: 1;
}

header {
    text-align: center;
    padding: 40px 0;
    background: var(--cpp-blue);
    color: white;
    margin-bottom: 30px;
    border-radius: 0 0 20px 20px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.logo {
    height: 80px;
    margin-bottom: 10px;
    transition: transform 0.3s;
}

.logo:hover {
    transform: scale(1.05);
}

.footer {
    text-align: center;
    padding: 30px;
    color: #888;
    font-size: 0.9em;
    margin-top: 50px;
    border-top: 1px solid #e0e0e0;
    background: white;
    position: relative;
    z-index: 1;
    clear: both;
}

/* Navigation in header */
.home-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    padding: 8px 15px;
    border-radius: 5px;
    text-decoration: none;
    font-size: 0.9em;
    transition: background 0.3s;
}

.home-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

section {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    margin-bottom: 30px;
}

h2 {
    border-left: 5px solid var(--cpp-blue);
    padding-left: 15px;
    color: var(--cpp-blue);
}

h3 {
    color: var(--cpp-blue);
    margin-top: 20px;
}

/* Common UI Elements */
.example-box {
    background: #f0f7f0;
    border-left: 4px solid var(--node-color);
    padding: 15px;
    margin: 15px 0;
}

.note-box {
    background: #fff3cd;
    border-left: 4px solid var(--highlight-color);
    padding: 15px;
    margin: 15px 0;
}

.warning-box {
    background: #fde8e8;
    border-left: 4px solid var(--negative-color);
    padding: 15px;
    margin: 15px 0;
}

.formula {
    font-family: 'Times New Roman', serif;
    font-size: 1.2em;
    text-align: center;
    margin: 15px 0;
    padding: 15px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Visualization - Bits */
.bit-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin: 15px 0;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.bit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 35px;
    height: 50px;
    font-size: 1.4em;
    font-weight: bold;
    border: 2px solid var(--cpp-blue);
    border-radius: 6px;
    background: white;
    position: relative;
    flex-shrink: 0;
    transition: all 0.3s;
}

.bit.sign-bit {
    background: var(--pointer-color);
    color: white;
    border-color: var(--pointer-color);
}

.bit.one {
    border-color: var(--pointer-color);
    color: var(--pointer-color);
}

.bit.zero {
    border-color: #ccc;
    color: #999;
}

.bit.highlight {
    background: var(--highlight-color);
    color: white;
    animation: pulse 0.5s;
    border-color: var(--highlight-color);
}

.bit.changed {
    background: var(--node-color);
    color: white;
    border-color: var(--node-color);
}

.bit.operator {
    border-color: var(--cpp-blue);
    background: var(--cpp-blue);
    color: white;
}

.bit.result {
    background: var(--node-color);
    color: white;
    border-color: var(--node-color);
}

.bit-label {
    font-size: 0.6em;
    position: absolute;
    bottom: -20px;
    left: 0;
    right: 0;
    color: #888;
    text-align: center;
}

/* Controls */
.controls {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

button {
    padding: 10px 20px;
    cursor: pointer;
    background: var(--cpp-blue);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    transition: all 0.2s;
}

button:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

button:active {
    transform: translateY(0);
}

input,
select {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
}

/* Steps Display */
.steps-container {
    background: #282c34;
    color: #abb2bf;
    padding: 20px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    max-height: 400px;
    overflow-y: auto;
}

.step-line {
    margin: 8px 0;
    padding: 8px;
    border-radius: 4px;
    border-left: 3px solid transparent;
}

.step-line.current {
    background: #444;
    color: white;
    border-left-color: var(--highlight-color);
}

pre {
    background: #282c34;
    color: #abb2bf;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
}

code {
    font-family: 'Courier New', monospace;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* Specific to Arrays/Bars */
.bar-container {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    height: 250px;
    gap: 5px;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 8px;
    margin: 20px 0;
}

.bar {
    background: var(--cpp-blue);
    width: 30px;
    text-align: center;
    color: white;
    font-weight: bold;
    border-radius: 5px 5px 0 0;
    transition: height 0.3s, background 0.3s, transform 0.3s;
    display: flex;
    flex-direction: column-reverse;
    /* Text at bottom */
    padding-bottom: 5px;
    position: relative;
}

.bar.sorted {
    background: var(--node-color);
}

.bar.comparing {
    background: var(--highlight-color);
}

.bar.swapping {
    background: var(--negative-color);
}


/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

th,
td {
    border: 1px solid #ddd;
    padding: 12px;
    text-align: center;
}

th {
    background: var(--cpp-blue);
    color: white;
}

tr:nth-child(even) {
    background: #f9f9f9;
}

.truth-table {
    display: inline-table;
    width: auto;
    margin: 10px;
}

.arrow-vertical {
    font-size: 2em;
    color: var(--pointer-color);
    text-align: center;
    margin: 10px 0;
}

/* Code Highlighting */
.code-container {
    background: #1e1e1e;
    border-radius: 8px;
    margin: 20px 0;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.code-container pre {
    margin: 0;
    padding: 20px;
    overflow-x: auto;
}

.code-container code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
}

/* Prism.js Customization */
pre[class*="language-"] {
    margin: 0 !important;
    padding: 20px !important;
    border-radius: 8px !important;
}

code[class*="language-"] {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace !important;
}

/* Line highlighting */
.highlight-line {
    background: #3a3d41 !important;
    display: block;
    margin: 0 -20px;
    padding: 0 20px;
}

/* Code block title */
.code-title {
    background: #2d2d2d;
    color: #9cdcfe;
    padding: 10px 20px;
    font-size: 0.9em;
    font-weight: bold;
    border-bottom: 1px solid #3c3c3c;
}

/* Copy button */
.copy-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--cpp-blue);
    color: white;
    border: none;
    padding: 5px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.3s;
}

.copy-button:hover {
    background: var(--cpp-light);
}

.copy-button.copied {
    background: var(--node-color);
}