:root {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --surface-hover: #2d2d2d;
    --primary-color: #bb86fc;
    --secondary-color: #03dac6;
    --error-color: #cf6679;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --border-radius: 8px;
    --node-size: 50px;
    --transition-speed: 0.3s;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

aside {
    width: 250px;
    background-color: var(--surface-color);
    display: flex;
    flex-direction: column;
    padding: 20px;
    border-right: 1px solid #333;
    z-index: 10;
}

h1 {
    font-size: 1.2rem;
    margin-bottom: 2rem;
    color: var(--primary-color);
    font-weight: 600;
    letter-spacing: 1px;
}

nav button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    text-align: left;
    padding: 12px 16px;
    cursor: pointer;
    border-radius: var(--border-radius);
    margin-bottom: 8px;
    font-size: 1rem;
    transition: all var(--transition-speed);
    width: 100%;
}

nav button:hover {
    background-color: var(--surface-hover);
    color: var(--text-primary);
}

nav button.active {
    background-color: rgba(187, 134, 252, 0.12);
    color: var(--primary-color);
    font-weight: 500;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 2rem;
    display: none;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.page.active {
    display: flex;
    opacity: 1;
}

header {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h2 {
    font-weight: 300;
    font-size: 2rem;
}

.controls {
    background-color: var(--surface-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 2rem;
    border: 1px solid #333;
}

input[type='number'] {
    background-color: var(--bg-color);
    border: 1px solid #444;
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    width: 80px;
    outline: none;
}

input[type='number']:focus {
    border-color: var(--primary-color);
}

.btn {
    background-color: var(--surface-hover);
    color: white;
    border: 1px solid #444;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn:hover {
    background-color: #3d3d3d;
    border-color: #555;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--primary-color);
    color: black;
    border: none;
    font-weight: 600;
}

.btn-primary:hover {
    background-color: #a370db;
}

.btn-danger {
    background-color: transparent;
    color: var(--error-color);
    border: 1px solid var(--error-color);
}

.btn-danger:hover {
    background-color: rgba(207, 102, 121, 0.1);
}

.message-box {
    margin-left: auto;
    color: var(--text-secondary);
    font-size: 0.9rem;
    min-height: 20px;
}

.error-msg {
    color: var(--error-color);
}
.success-msg {
    color: var(--secondary-color);
}

.visual-container {
    flex: 1;
    background-color: #161616;
    border-radius: var(--border-radius);
    border: 1px dashed #333;
    position: relative;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.node {
    width: var(--node-size);
    height: var(--node-size);
    background-color: var(--surface-color);
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: white;
    position: relative;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation: popIn 0.4s ease-out;
    user-select: none;
    z-index: 2;
}

.node.highlight {
    background-color: var(--secondary-color);
    color: black;
    border-color: var(--secondary-color);
    box-shadow: 0 0 15px var(--secondary-color);
}

@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes slideOut {
    to {
        transform: scale(0);
        opacity: 0;
    }
}

.node.removing {
    animation: slideOut 0.25s forwards;
}

#stack-container {
    flex-direction: column-reverse;
    justify-content: flex-start;
    gap: 5px;
    padding-bottom: 50px;
}

#stack-container .node {
    width: 120px;
}

#queue-container {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
}

.ll-container {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 40px;
    justify-content: flex-start;
    width: 100%;
    padding-top: 30px;
}

.ll-node-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.ll-node-wrapper .node {
    border-radius: 50%;
}

.ll-arrow {
    position: absolute;
    right: -35px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 1.5rem;
}

.ll-null {
    font-size: 0.9rem;
    color: #666;
    margin-left: 10px;
    font-weight: normal;
    background: #222;
    padding: 4px 8px;
    border-radius: 4px;
}

.head-label {
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--secondary-color);
    color: black;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: bold;
    white-space: nowrap;
}

.head-label::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid var(--secondary-color);
}

.tree-container {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 400px;
}

.tree-node {
    position: absolute;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface-color);
    border: 2px solid var(--secondary-color);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
    font-weight: bold;
    z-index: 2;
    transition: all 0.5s ease;
    transform: translate(-50%, -50%);
    color: white;
}

.tree-edge {
    position: absolute;
    stroke: #444;
    stroke-width: 2px;
    z-index: 1;
}

.traversal-output {
    margin-top: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    font-family: monospace;
    color: var(--secondary-color);
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }
    aside {
        width: 100%;
        height: auto;
        flex-direction: row;
        overflow-x: auto;
        padding: 10px;
    }
    nav {
        display: flex;
        gap: 10px;
    }
    nav button {
        margin: 0;
        white-space: nowrap;
    }
    h1 {
        display: none;
    }
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    .controls input {
        width: 100%;
    }
}
