:root {
    --primary-bg-color: #f0f0f0;
    --secondary-bg-color: #cccccc;
    --primary-text-color: #333;
    --button-color: #333;
    --button-hover-color: #555;
    --button-active-color: #111;
    --card-bg: #ffffff;
    --card-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    --stack-bg: #fdcb6e;
    --stack-border: #e17055;
    --queue-bg: #74b9ff;
    --queue-border: #0984e3;
    --list-bg: #a8e6cf;
    --list-border: #3b9778;
    --tree-bg: #ffd3b6;
    --tree-border: #ff8367;
    --main-title-color: #333;
}

[data-theme="dark"] {
    --primary-bg-color: #1a1a1a;
    --secondary-bg-color: #2d2d2d;
    --primary-text-color: #fff;
    --card-bg: #333333;
    --card-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    --stack-bg: #b58c3c;
    --stack-border: #a65843;
    --queue-bg: #3a77b6;
    --queue-border: #0a4c7d;
    --list-bg: #5b9c89;
    --list-border: #2a6857;
    --tree-bg: #c17f5e;
    --tree-border: #b65843;
    --main-title-color: #fff;
}

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5px;
    background: linear-gradient(to bottom right, var(--primary-bg-color), var(--secondary-bg-color));
    font-family: 'Roboto', sans-serif;
    color: var(--primary-text-color);
    transition: background-color 0.3s ease;
    min-height: 100vh;
    margin: 0;
    overflow: hidden;
}
h1 {
    text-align: center;
    color: var(--main-title-color);
    margin: 2px 0;
    font-size: 2rem;
}
h2 {
    margin: 2px 0;
    font-size: 1.5rem;
    color: #333;
}
p {
    margin: 2px 0;
    font-size: 1.1rem;
    color: #333;
}

.tabs {
    text-align: center;
    margin-bottom: 10px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    padding: 0 20px;
}
.tab-button {
    padding: 12px 25px;
    margin-right: 5px;
    border: none;
    border-radius: 5px;
    background-color: #737373;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 1.1rem;
}
.tab-button.active {
    background-color: #333;
    color: #fff;
}
.tab-content {
    display: none;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: var(--card-shadow);
    border: none;
    padding: 10px;
    border-radius: 10px;
    margin-bottom: 15px;
    height: auto;
    overflow: hidden;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    transform-origin: top;
    animation: slideDown 0.3s ease;
    max-height: 85vh;
    padding: 10px;
    margin: 0 10px 10px 10px;
}
.tab-content.active {
    display: block;
}
.controls {
    margin-top: 5px;
    margin-bottom: 1px;
}
.button-container {
    text-align: center;
    margin: 10px 0;
    display: flex;
    gap: 10px;
    justify-content: center;
    margin: 15px 0;
}

button, select {
    color: white;
    background-color: var(--button-color);
    border: none;
    padding: 10px 20px;
    font-size: 1.1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    will-change: transform, background-color;
}

button:hover:before {
    width: 300%;
    height: 300%;
}

button:hover, select:hover {
    background-color: var(--button-hover-color);
    transform: translateY(-3px);
}

button:active {
    background-color: var(--button-active-color);
    transform: translateY(0);
}

button:focus, select:focus {
    outline: 2px solid #555;
    outline-offset: 2px;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

#stack-container {
    position: relative;
    width: 300px;
    height: 400px;
    margin: 0 auto 10px auto;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: var(--card-shadow);
    border: none;
    overflow-y: auto;
    padding-bottom: 10px;
    border-radius: 10px;
    display: flex;
    flex-direction: column-reverse;
}
.plate {
    width: 250px;
    height: 35px;
    background-color: var(--stack-bg);
    border: 2px solid var(--stack-border);
    border-radius: 50%;
    margin: 1px auto;
    text-align: center;
    line-height: 35px;
    font-weight: bold;
    color: #333;
    transition: all 0.3s ease;
    animation: scaleIn 0.3s ease;
    font-size: 1.1rem;
}

#queue-container {
    width: 100%;
    max-width: 800px;
    height: 100px;
    margin: 0 auto 10px auto;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: var(--card-shadow);
    border: none;
    display: flex;
    align-items: center;
    padding: 10px;
    overflow-x: auto;
    border-radius: 10px;
}

.queue-item {
    width: 70px;
    height: 70px;
    background-color: var(--queue-bg);
    border: 2px solid var(--queue-border);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    font-weight: bold;
    color: #333;
    flex-shrink: 0;
    transition: all 0.3s ease;
    animation: scaleIn 0.3s ease;
    font-size: 1.1rem;
}

#linkedlist-container {
    max-width: 1000px;
    height: 80px;
    display: flex;
    align-items: center;
    padding: 10px;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: var(--card-shadow);
    border: none;
    overflow-x: auto;
    border-radius: 10px;
    margin: 0 auto 10px auto;
}

.list-node {
    min-width: 80px;
    height: 45px;
    background-color: var(--list-bg);
    border: 2px solid var(--list-border);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #333;
    padding: 0 5px;
    flex-shrink: 0;
    transition: all 0.3s ease;
    animation: scaleIn 0.3s ease;
    font-size: 1.1rem;
}

.arrow {
    font-size: 24px;
    margin: 0 10px;
    flex-shrink: 0;
    color: #333 !important;
}

.null {
    color: #333 !important;
}

#binarytree-container {
    position: relative;
    width: 800px;
    height: 400px;
    margin: 0 auto 10px auto;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: var(--card-shadow);
    border: none;
    border-radius: 10px;
    overflow: auto;
}
.tree-node {
    position: absolute;
    width: 60px;
    height: 60px;
    background-color: var(--tree-bg);
    border: 2px solid var(--tree-border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #333;
    transition: all 0.3s ease;
    animation: scaleIn 0.3s ease;
    font-size: 1.1rem;
}

#binarytree-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
footer {
    text-align: center;
    padding: 5px;
    background-color: var(--primary-color);
    color: white;
    margin-top: 5px;
    font-size: 0.9rem;
}
.theme-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@media (max-width: 1024px) {
    .tab-content {
        height: calc(88vh - 100px);
        min-height: auto;
        max-width: 95%;
    }

    #binarytree-container {
        width: 100%;
        max-width: 700px;
    }

    .controls-panel {
        grid-template-columns: 1fr;
        max-width: 95%;
    }
}

@media (max-width: 768px) {
    body {
        overflow-y: auto;
    }

    .tab-content {
        overflow-y: auto;
    }

    .button-container {
        flex-wrap: wrap;
    }

    button, select {
        padding: 10px 20px;
        width: calc(50% - 10px);
    }

    #queue-container,
    #linkedlist-container {
        height: 100px;
    }

    #stack-container {
        width: 200px;
        height: 200px;
    }

    .plate {
        width: 160px;
    }

    #binarytree-container {
        height: 200px;
    }

    body {
        padding: 10px;
        overflow-y: auto;
    }

    .controls-panel {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .theme-toggle {
        position: fixed;
        top: auto;
        bottom: 20px;
        right: 20px;
        z-index: 1000;
    }

    .theme-toggle button {
        width: 40px;
        height: 40px;
        padding: 8px;
        border-radius: 50%;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }
}

@media (max-width: 480px) {
    body {
        padding: 5px;
    }

    h1 {
        font-size: 1.5rem;
        margin-bottom: 15px;
    }

    .tabs {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-gap: 5px;
        padding: 0 5px;
        width: 100%;
    }

    .tab-button {
        padding: 10px;
        font-size: 0.9rem;
        width: 100%;
        margin: 0;
    }

    #stack-container {
        width: 90%;
        max-height: 60vh;
    }

    #queue-container,
    #linkedlist-container {
        width: 90%;
        padding: 5px;
        margin: 10px auto;
    }

    #binarytree-container {
        width: 90%;
        height: 60vh;
        margin: 10px auto;
    }

    .controls {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 5px;
        padding: 0 10px;
        justify-content: center;
    }

    .controls button {
        width: calc(50% - 5px);
        margin: 0;
        padding: 10px;
    }

    .plate {
        width: 80%;
    }

    .tab-content {
        overflow-y: auto;
    }
}

@media (hover: none) {
    button {
        -webkit-tap-highlight-color: transparent;
    }

    button:active {
        background-color: var(--button-active-color);
        transform: scale(0.98);
    }
}
