/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0c0c0c 0%, #1a1a1a 100%);
    color: #ffffff;
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Control Toolbar */
.control-toolbar {
    background: linear-gradient(135deg, #2d2d30 0%, #1e1e1e 100%);
    border-bottom: 2px solid #3e3e42;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 0;
    z-index: 100;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 2rem;
}

h1 {
    color: #64ffda;
    font-size: 1.5rem;
    font-weight: 300;
    display: flex;
    align-items: center;
}

.control-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-play {
    background: linear-gradient(135deg, #4caf50, #388e3c);
    color: white;
}

.btn-play:hover:not(:disabled) {
    background: linear-gradient(135deg, #66bb6a, #4caf50);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.btn-pause {
    background: linear-gradient(135deg, #ff9800, #f57c00);
    color: white;
}

.btn-pause:hover:not(:disabled) {
    background: linear-gradient(135deg, #ffb74d, #ff9800);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 152, 0, 0.3);
}

.btn-step {
    background: linear-gradient(135deg, #2196f3, #1976d2);
    color: white;
}

.btn-step:hover:not(:disabled) {
    background: linear-gradient(135deg, #42a5f5, #2196f3);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.btn-reset {
    background: linear-gradient(135deg, #9c27b0, #7b1fa2);
    color: white;
}

.btn-reset:hover:not(:disabled) {
    background: linear-gradient(135deg, #ba68c8, #9c27b0);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(156, 39, 176, 0.3);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.speed-control label {
    color: #cccccc;
    font-size: 0.9rem;
    font-weight: 500;
}

.speed-control input[type="range"] {
    width: 100px;
    accent-color: #64ffda;
}

.speed-value {
    min-width: 1.5rem;
    text-align: center;
    color: #64ffda;
    font-weight: 600;
    font-size: 1rem;
}

/* Step Info Bar */
.step-info {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-bottom: 1px solid #2a2a3e;
    padding: 0.65rem 2rem;
    min-height: 2.8rem;
    display: flex;
    align-items: center;
    font-size: 0.88rem;
}

.step-info-idle {
    color: rgba(255, 255, 255, 0.35);
    font-style: italic;
}

.step-info-content {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    animation: stepInfoIn 0.25s ease;
    width: 100%;
}

.step-counter {
    color: #64ffda;
    font-weight: 700;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    white-space: nowrap;
    background: rgba(100, 255, 218, 0.1);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    border: 1px solid rgba(100, 255, 218, 0.25);
    flex-shrink: 0;
}

.step-description {
    color: #d0d0e0;
    line-height: 1.45;
}

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

/* Main Content Layout */
.main-content {
    display: flex;
    flex: 1;
    gap: 1rem;
    padding: 1rem;
    min-height: 0;
}

.code-panel {
    flex: 1;
    min-width: 400px;
    display: flex;
    flex-direction: column;
}

.visualization-panels {
    flex: 1;
    min-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.visualization-row {
    display: flex;
    gap: 1rem;
    min-height: 0;
}

.visualization-row .panel {
    flex: 1;
}

/* Panel Styles */
.panel {
    background: #252526;
    border-radius: 8px;
    border: 1px solid #3e3e42;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.panel-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #3e3e42;
    display: flex;
    align-items: center;
    font-weight: 500;
    font-size: 0.9rem;
}

.panel-icon {
    margin-right: 0.5rem;
}

.panel-content {
    flex: 1;
    padding: 1rem;
    overflow: auto;
    min-height: 0;
}

/* Color-coded Panel Headers */
.call-stack-header {
    background: linear-gradient(135deg, #ff6b35, #f7931e);
    color: white;
}

.heap-header {
    background: linear-gradient(135deg, #4ecdc4, #44a08d);
    color: white;
}

.event-loop-header {
    background: linear-gradient(135deg, #a8e6cf, #7fcdcd);
    color: #2c3e50;
}

.microtask-header {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
    color: white;
}

.macrotask-header {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
}

.console-header {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    color: white;
}

/* Code Editor Specific */
.code-editor {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.code-container {
    display: flex;
    flex: 1;
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.6;
    background: #1e1e1e;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
}

.line-numbers {
    background: #252526;
    padding: 1rem 0.75rem 1rem 1rem;
    text-align: right;
    color: #858585;
    user-select: none;
    min-width: 3.5rem;
    border-right: 1px solid #2d2d30;
    font-weight: 400;
    overflow-y: auto;
}

.line-numbers .current-line {
    background: rgba(255, 213, 79, 0.1);
    color: #ffd54f;
    font-weight: 500;
}

.code-content {
    flex: 1;
    padding: 1rem 1.5rem;
    color: #d4d4d4;
    white-space: pre;
    overflow: auto;
    background: #1e1e1e;
    font-feature-settings: 'liga' 1, 'calt' 1;
}

.code-line {
    transition: all 0.3s ease;
    padding: 0.1rem 0.5rem;
    margin: 0 -0.5rem;
    border-radius: 4px;
    position: relative;
}

.code-line.current {
    background: rgba(255, 213, 79, 0.15);
    border-left: 3px solid #ffd54f;
    animation: pulse 1.5s ease-in-out infinite;
    box-shadow: 0 0 10px rgba(255, 213, 79, 0.3);
}

.code-line.executed {
    background: rgba(129, 199, 132, 0.1);
    border-left: 3px solid rgba(129, 199, 132, 0.5);
}

.code-line:hover {
    background: rgba(255, 255, 255, 0.05);
}

.code-line.current:hover {
    background: rgba(255, 213, 79, 0.25);
}

.code-line.executed:hover {
    background: rgba(129, 199, 132, 0.15);
}

/* Syntax Highlighting */
.syntax-keyword {
    color: #569cd6;
    font-weight: 500;
}

.syntax-string {
    color: #ce9178;
}

.syntax-number {
    color: #b5cea8;
}

.syntax-comment {
    color: #6a9955;
    font-style: italic;
}

.syntax-function {
    color: #dcdcaa;
}

.syntax-variable {
    color: #9cdcfe;
}

.syntax-operator {
    color: #d4d4d4;
}

.syntax-punctuation {
    color: #cccccc;
}

.syntax-property {
    color: #92c5f7;
}

.syntax-method {
    color: #dcdcaa;
}

.syntax-console {
    color: #4fc1ff;
}

.syntax-arrow {
    color: #569cd6;
    font-weight: bold;
}

/* Call Stack */
.call-stack {
    display: flex;
    flex-direction: column-reverse;
    gap: 0.5rem;
    min-height: 150px;
    align-items: stretch;
}

.stack-frame {
    background: linear-gradient(135deg, #ff6b35, #f7931e);
    color: white;
    padding: 0.75rem;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    text-align: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transform: translateY(10px);
    opacity: 0;
    animation: slideInStack 0.5s ease forwards;
    transition: all 0.3s ease;
}

.stack-frame:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

.stack-frame-exiting {
    position: fixed;
    pointer-events: none;
    z-index: 9998;
    /* animation and initial transform/opacity are set inline to override .stack-frame defaults */
}

@keyframes slideInStack {
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Heap */
.heap {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    min-height: 150px;
    align-content: start;
}

.heap-object {
    background: linear-gradient(135deg, #4ecdc4, #44a08d);
    color: white;
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    animation: bounceIn 0.6s ease;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.heap-number {
    background: linear-gradient(135deg, #b5cea8, #9bb59a);
    color: #2c3e50;
}

.heap-object.heap-object {
    background: linear-gradient(135deg, #4ecdc4, #44a08d);
}

.heap-array {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

.heap-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.heap-value {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    opacity: 0.9;
    word-break: break-all;
}

.heap-object:hover {
    transform: scale(1.05);
}

@keyframes bounceIn {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* Event Loop */
.event-loop {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    min-height: 80px;
}

.loop-indicator {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(100, 255, 218, 0.3);
    border-top: 3px solid #64ffda;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loop-indicator.active {
    animation-duration: 0.3s;
    border-color: #ffc107;
    border-top-color: #ff9800;
}

.loop-indicator.task-transit {
    animation-duration: 0.15s;
    border-color: #64ffda;
    border-top-color: #00e5ff;
    box-shadow: 0 0 18px rgba(100, 255, 218, 0.9);
    transition: box-shadow 0.1s ease, border-color 0.1s ease;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loop-status {
    color: #64ffda;
    font-weight: 500;
    font-size: 1.1rem;
}

/* Task Queues */
.task-queue {
    display: flex;
    gap: 0.5rem;
    min-height: 80px;
    align-items: center;
    flex-wrap: wrap;
}

.task-item {
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    animation: slideInTask 0.5s ease;
    transition: all 0.3s ease;
    color: white;
}

.task-item.microtask {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
}

.task-item.macrotask {
    background: linear-gradient(135deg, #3498db, #2980b9);
}

.task-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.task-flying {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    box-shadow:
        0 0 0 2px rgba(100, 255, 218, 0.8),
        0 0 20px rgba(100, 255, 218, 0.5),
        0 8px 32px rgba(0, 0, 0, 0.6);
    animation: flyingGlow 0.4s ease infinite alternate;
}

@keyframes flyingGlow {
    from { box-shadow: 0 0 0 2px rgba(100, 255, 218, 0.6), 0 0 12px rgba(100, 255, 218, 0.3), 0 6px 20px rgba(0, 0, 0, 0.5); }
    to   { box-shadow: 0 0 0 2px rgba(100, 255, 218, 1.0), 0 0 28px rgba(100, 255, 218, 0.7), 0 10px 36px rgba(0, 0, 0, 0.7); }
}

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

/* Console Panel */
.console-panel {
    background: #1e1e1e;
    border-radius: 8px;
    margin: 0 1rem 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    max-height: 200px;
    display: flex;
    flex-direction: column;
}

.console-output {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    overflow-y: auto;
    background: #0d1117;
    color: #f0f6fc;
    min-height: 120px;
    max-height: 160px;
}

.console-line {
    margin: 0.25rem 0;
    padding: 0.5rem 1rem;
    animation: fadeInConsole 0.5s ease;
    border-left: 3px solid #64ffda;
    transition: background-color 0.2s ease;
}

.console-line:hover {
    background: rgba(255, 255, 255, 0.05);
}

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

.console-line.log {
    color: #f0f6fc;
}

.console-line.error {
    color: #ff6b6b;
    border-left-color: #ff6b6b;
}

.console-line.warn {
    color: #ffc107;
    border-left-color: #ffc107;
}

/* Empty States */
.stack-empty,
.heap-empty,
.queue-empty,
.console-empty {
    color: rgba(255, 255, 255, 0.4);
    font-style: italic;
    text-align: center;
    padding: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: translateX(0);
    }
    50% {
        opacity: 0.8;
        transform: translateX(2px);
    }
}

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

::-webkit-scrollbar-track {
    background: #1e1e1e;
}

::-webkit-scrollbar-thumb {
    background: #424242;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #4a4a4a;
}

/* Responsive Design */
@media (max-width: 1400px) {
    .main-content {
        flex-direction: column;
    }

    .visualization-panels {
        min-width: unset;
    }

    .code-panel {
        min-width: unset;
        max-height: 400px;
    }
}

@media (max-width: 768px) {
    .control-toolbar {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .toolbar-section {
        flex-wrap: wrap;
        justify-content: center;
    }

    .control-group {
        flex-wrap: wrap;
        justify-content: center;
    }

    .visualization-row {
        flex-direction: column;
    }

    .main-content {
        padding: 0.5rem;
    }

    .console-panel {
        margin: 0 0.5rem 0.5rem;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.2rem;
    }

    .btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }

    .speed-control {
        flex-direction: column;
        text-align: center;
    }
}