/* These legacy variables are kept for backward compatibility */
:root {
    --color-new: var(--color-new);
    --color-runnable: var(--color-runnable);
    --color-running: var(--color-running);
    --color-blocked: var(--color-blocked);
    --color-waiting: var(--color-waiting);
    --color-timed-waiting: var(--color-timed-waiting);
    --color-terminated: var(--color-terminated);
    --color-background: var(--bg-primary);
    --color-text: var(--text-primary);
    --color-header: var(--accent-primary);
    --color-border: var(--border-color);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    line-height: 1.6;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

header {
    background: var(--header-bg);
    color: var(--header-text);
    text-align: center;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.subtitle {
    font-style: italic;
    margin-top: 0.5rem;
    opacity: 0.9;
    font-weight: 300;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    display: grid;
    grid-template-columns: 1fr 2fr;
    grid-template-rows: auto auto auto auto auto;
    gap: 1.5rem;
    grid-template-areas: 
        "control viz"
        "info info"
        "diagram diagram"
        "scheduler scheduler"
        "contention contention"
        "shared-memory shared-memory";
    transition: all 0.3s ease;
}

.control-panel {
    grid-area: control;
    background: var(--card-bg);
    padding: 1.75rem;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    transition: all 0.3s ease;
}

.visualization-area {
    grid-area: viz;
    background: var(--card-bg);
    padding: 1.75rem;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    height: 500px;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.info-panel {
    grid-area: info;
    background: var(--card-bg);
    padding: 1.75rem;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    transition: all 0.3s ease;
}

.lifecycle-diagram-container {
    grid-area: diagram;
    background: var(--card-bg);
    padding: 1.75rem;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    transition: all 0.3s ease;
}

.scheduler-container {
    grid-area: scheduler;
    background: var(--card-bg);
    padding: 1.75rem;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    margin-top: 0;
    transition: all 0.3s ease;
}

.contention-section {
    grid-area: contention;
    background: var(--card-bg);
    padding: 1.75rem;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    margin-top: 0;
    transition: all 0.3s ease;
}

.shared-memory-container {
    grid-area: shared-memory;
    background: var(--card-bg);
    padding: 1.75rem;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    margin-top: 0;
    transition: all 0.3s ease;
}

h2 {
    margin-bottom: 1.25rem;
    color: var(--accent-primary);
    font-weight: 600;
}

.controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
}

.btn {
    padding: 0.6rem 1rem;
    border: none;
    background-color: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

.btn:hover {
    background-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn.disabled {
    background-color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
}

.btn.danger {
    background-color: var(--error-color);
}

.btn.danger:hover {
    background-color: var(--error-color);
    filter: brightness(90%);
}

.speed-control {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.speed-control label {
    font-weight: bold;
}

.thread-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.thread {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: bold;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
    z-index: 10;
    backdrop-filter: blur(5px);
}

.thread-id {
    font-size: 1.3rem;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.thread-state {
    position: absolute;
    bottom: -28px;
    font-size: 0.85rem;
    color: var(--text-primary);
    background-color: var(--card-bg);
    padding: 3px 10px;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    transition: all 0.3s ease;
}

.thread-actions {
    position: absolute;
    top: -10px;
    right: -10px;
    display: flex;
    gap: 5px;
}

.thread-action-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background-color: #fff;
    color: var(--color-header);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    font-size: 12px;
    transition: all 0.2s ease;
}

.thread-action-btn:hover {
    transform: scale(1.1);
    background-color: var(--color-header);
    color: #fff;
}

.thread.terminated .thread-action-btn,
.thread.new .thread-action-btn {
    opacity: 0.5;
    cursor: not-allowed;
}

.thread.new {
    background-color: var(--color-new);
}

.thread.runnable {
    background-color: var(--color-runnable);
}

.thread.running {
    background-color: var(--color-running);
    animation: pulse 1s infinite alternate;
}

.thread.blocked {
    background-color: var(--color-blocked);
}

.thread.waiting {
    background-color: var(--color-waiting);
}

.thread.timed-waiting {
    background-color: var(--color-timed-waiting);
    animation: sleep 3s infinite;
}

.thread.terminated {
    background-color: var(--color-terminated);
    opacity: 0.7;
}

.thread.scheduled-transition {
    animation: scheduled-pulse 1s ease;
    box-shadow: 0 0 25px rgba(255, 255, 255, 1);
}

.thread.demo-thread {
    border: 2px solid #673ab7;
    box-shadow: 0 0 20px rgba(103, 58, 183, 0.5);
}

@keyframes pulse {
    from {
        transform: scale(1);
    }
    to {
        transform: scale(1.05);
    }
}

@keyframes sleep {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

.state-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.state-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem;
    border-radius: 6px;
    background-color: #f9f9f9;
}

.state-color {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    flex-shrink: 0;
}

.state-color.new {
    background-color: var(--color-new);
}

.state-color.runnable {
    background-color: var(--color-runnable);
}

.state-color.running {
    background-color: var(--color-running);
}

.state-color.blocked {
    background-color: var(--color-blocked);
}

.state-color.waiting {
    background-color: var(--color-waiting);
}

.state-color.timed-waiting {
    background-color: var(--color-timed-waiting);
}

.state-color.terminated {
    background-color: var(--color-terminated);
}

.state-description h3 {
    font-size: 1.05rem;
    margin-bottom: 0.3rem;
    color: var(--text-primary);
    font-weight: 600;
}

.state-description p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.transition-info {
    margin-top: 2.5rem;
}

#transition-log {
    max-height: 200px;
    overflow-y: auto;
    background-color: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9rem;
}

.transition-entry {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

.transition-entry:last-child {
    border-bottom: none;
}

.transition-time {
    color: #666;
    margin-right: 0.5rem;
}

/* Thread info panel styling */
.thread-info-panel {
    margin-top: 20px;
    padding: 15px;
    background-color: #f9f9f9;
    border-radius: 6px;
    border-left: 4px solid var(--color-header);
}

.thread-info-panel h3 {
    margin-bottom: 15px;
    color: var(--color-header);
}

.thread-details {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.detail-row {
    display: flex;
    align-items: flex-start;
}

.detail-label {
    font-weight: bold;
    width: 120px;
    flex-shrink: 0;
}

.detail-value {
    flex-grow: 1;
}

/* Style state value */
#thread-detail-state {
    padding: 3px 8px;
    border-radius: 4px;
    color: white;
    display: inline-block;
}

#thread-detail-state.new { background-color: var(--color-new); }
#thread-detail-state.runnable { background-color: var(--color-runnable); }
#thread-detail-state.running { background-color: var(--color-running); }
#thread-detail-state.blocked { background-color: var(--color-blocked); }
#thread-detail-state.waiting { background-color: var(--color-waiting); }
#thread-detail-state.timed-waiting { background-color: var(--color-timed-waiting); }
#thread-detail-state.terminated { background-color: var(--color-terminated); }

.history-item {
    margin-bottom: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid #eee;
}

.history-item:last-child {
    border-bottom: none;
}

.history-time {
    color: #666;
    font-size: 0.8rem;
    margin-right: 10px;
}

/* Thread transition path styling */
.transition-path {
    pointer-events: none;
}

/* Thread particles styling */
.transition-particle {
    box-shadow: 0 0 8px rgba(255, 152, 0, 0.8);
    pointer-events: none;
}

footer {
    margin-top: 3rem;
    background-color: var(--color-header);
    color: white;
    text-align: center;
    padding: 1rem;
}

footer a {
    color: white;
    text-decoration: underline;
}

@media (max-width: 1200px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-areas: 
            "control"
            "viz"
            "info"
            "diagram"
            "scheduler"
            "contention"
            "shared-memory";
        gap: 1.5rem;
    }
    
    .visualization-area {
        height: 400px;
    }
    
    .scheduler-container,
    .contention-section,
    .shared-memory-container {
        margin-top: 0;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 0.5rem;
        gap: 1rem;
    }
    
    .controls {
        grid-template-columns: 1fr;
    }
    
    .state-info {
        grid-template-columns: 1fr;
    }
    
    .problem-cards {
        grid-template-columns: 1fr;
    }
    
    .memory-blocks {
        grid-template-columns: 1fr;
    }
    
    .visualization-area {
        height: 350px;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    h3 {
        font-size: 1.3rem;
    }
}

/* Additional optimizations for very small screens */
@media (max-width: 480px) {
    .container {
        gap: 0.8rem;
    }
    
    .control-panel, .visualization-area, .info-panel, 
    .lifecycle-diagram-container, .scheduler-container,
    .contention-section, .shared-memory-container {
        padding: 1rem;
    }
    
    .controls {
        gap: 0.5rem;
    }
    
    .btn {
        padding: 0.4rem 0.7rem;
        font-size: 0.9rem;
    }
    
    .state-item {
        padding: 0.6rem;
    }
    
    .state-description h3 {
        font-size: 0.9rem;
    }
    
    .state-description p {
        font-size: 0.8rem;
    }
    
    .visualization-area {
        height: 300px;
    }
    
    .thread {
        width: 80px;
        height: 80px;
    }
    
    .problem-card {
        padding: 0.8rem;
    }
    
    .header {
        padding: 1rem;
        margin-bottom: 1rem;
    }
}

/* Tooltip styles */
.tooltip {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    z-index: 100;
    pointer-events: none;
    transition: opacity 0.3s;
}

/* Transition animation */
.transition-animation {
    position: absolute;
    width: 20px;
    height: 20px;
    background-color: var(--warning-color);
    border-radius: 50%;
    z-index: 5;
}

/* Footer styling */
footer {
    background: var(--footer-bg);
    color: var(--footer-text);
    text-align: center;
    padding: 2rem 1rem;
    margin-top: 3rem;
    border-top: 1px solid var(--border-color);
}

footer a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

footer a:hover {
    text-decoration: underline;
    color: var(--accent-secondary);
}
