/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

header p {
    font-size: 1.1em;
    opacity: 0.9;
}

/* File controls section */
.file-controls {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 30px;
}

.sample-program-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}

.sample-program-selector label {
    font-weight: bold;
    margin-bottom: 0;
    white-space: nowrap;
}

#sample-programs {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
}

#sample-programs:focus {
    outline: none;
    border-color: #667eea;
}

#load-sample {
    margin-right: 0;
    white-space: nowrap;
}

.file-controls label {
    display: block;
    font-weight: bold;
    margin-bottom: 10px;
}

#assembly-input {
    width: 100%;
    height: 120px;
    border: 2px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    margin-bottom: 10px;
    resize: vertical;
}

#assembly-input:focus {
    outline: none;
    border-color: #667eea;
}

button {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin-right: 10px;
    transition: background-color 0.2s;
}

button:hover {
    background: #5a6fd8;
}

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

.file-buttons {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

/* Main content */
.main-content {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 20px;
    margin-bottom: 20px;
}

.cpu-state, .memory-views {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.cpu-state {
    padding: 20px;
}

.cpu-state h2 {
    color: #667eea;
    margin-bottom: 20px;
}

/* Registers */
.registers {
    position: relative;
}

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

.registers h3 {
    margin: 0;
    color: #333;
}

.format-toggle {
    display: flex;
    background: #c7c9cb;
    border-radius: 4px;
    border: 1px solid #dee2e6;
}

.format-toggle button {
    background: transparent;
    border: none;
    padding: 5px 10px;
    font-size: 12px;
    cursor: pointer;
    border-radius: 3px;
    margin: 2px;
    transition: background-color 0.2s;
}

.format-toggle button.active {
    background: #667eea;
    color: white;
}

.format-toggle button:hover:not(.active) {
    background: #e9ecef;
}

.register-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.register {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #dee2e6;
    font-family: 'Courier New', monospace;
}

.register.modified {
    background: #fff3cd;
    border-color: #ffc107;
    animation: highlight 0.5s ease;
}

@keyframes highlight {
    0% { background: #28a745; color: white; }
    100% { background: #fff3cd; }
}

.special-registers {
    margin-bottom: 20px;
}

.special-reg {
    background: #e9ecef;
    padding: 10px;
    margin-bottom: 5px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
}

.current-instruction {
    border-top: 2px solid #dee2e6;
    padding-top: 15px;
}

.current-instruction h3 {
    margin-bottom: 10px;
    color: #333;
}

#current-inst {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 4px;
    border: 1px solid #dee2e6;
    font-family: 'Courier New', monospace;
    font-size: 16px;
    margin-bottom: 10px;
}

#current-inst.executing {
    background: #d1ecf1;
    border-color: #17a2b8;
}

#current-inst-binary {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    color: #666;
}

/* Memory views */
.memory-views {
    display: flex;
    flex-direction: column;
}

.view-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
    padding: 10px 20px;
    border-bottom: 1px solid #dee2e6;
}

.view-tabs {
    display: flex;
}

.execution-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.execution-controls button {
    padding: 8px 16px;
    font-size: 13px;
    margin-right: 0;
    position: relative;
}

.shortcut {
    display: inline-block;
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.8);
    font-size: 10px;
    font-weight: bold;
    padding: 2px 4px;
    border-radius: 3px;
    margin-left: 6px;
    min-width: 12px;
    text-align: center;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 15px;
}

.speed-control label {
    font-size: 13px;
    color: #666;
    margin-bottom: 0;
}

#speed {
    width: 80px;
}

.tab-button {
    background: #c7c9cb;
    border: none;
    padding: 10px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s;
    margin-right: 5px;
}

.tab-button:hover {
    background: #e9ecef;
    color: #667eea;
}

.tab-button.active {
    background: white;
    color: #667eea;
}

.memory-content {
    flex: 1;
    background: white;
    padding: 20px;
    border-radius: 0 0 8px 8px;
}

.memory-view {
    display: none;
}

.memory-view.active {
    display: block;
}

.memory-table {
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

.memory-header {
    display: grid;
    grid-template-columns: 80px 100px 1fr 120px 1fr;
    gap: 10px;
    padding: 10px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px 4px 0 0;
    font-weight: bold;
}

#binary-view .memory-header {
    grid-template-columns: 80px 120px 280px 100px;
}

.fields-header {
    grid-template-columns: 80px 200px 80px 80px 1fr !important;
}

.memory-rows {
    border: 1px solid #dee2e6;
    border-top: none;
    border-radius: 0 0 4px 4px;
    min-height: 200px;
    height: 400px;
    overflow-y: auto;
    resize: vertical;
}

/* Custom resize handle styling */
.memory-rows::-webkit-resizer,
.pipeline-stages::-webkit-resizer {
    background: linear-gradient(135deg, transparent 0%, transparent 40%, #007bff 40%, #007bff 60%, transparent 60%);
    border-radius: 0 0 4px 0;
}

/* Subtle resize indicator */
.memory-rows,
.pipeline-stages {
    position: relative;
}

.memory-rows::after {
    content: "⋮⋮";
    position: absolute;
    bottom: 4px;
    right: 8px;
    color: #adb5bd;
    font-size: 10px;
    line-height: 0.5;
    pointer-events: none;
    opacity: 0.7;
    letter-spacing: -2px;
    transition: opacity 0.2s ease;
}

.memory-rows:hover::after {
    opacity: 1;
    color: #007bff;
}

/* Resize cursor hint */
.memory-rows:hover,
.pipeline-stages:hover {
    cursor: ns-resize;
}

.memory-row {
    display: grid;
    grid-template-columns: 80px 100px 1fr 120px 1fr;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s;
}

#binary-view .memory-row {
    grid-template-columns: 80px 120px 280px 100px;
}

#fields-view .memory-row {
    grid-template-columns: 80px 200px 80px 80px 1fr;
}

.memory-row:hover {
    background: #f8f9fa;
}

.memory-row.current-pc {
    background: #d1ecf1;
    border-left: 4px solid #17a2b8;
}

.memory-row.modified {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    animation: highlight-row 0.5s ease;
}

@keyframes highlight-row {
    0% { background: #28a745; color: white; }
    100% { background: #fff3cd; }
}

/* Pipeline visual effects */
@keyframes pipeline-flush {
    0% { 
        background: #dc3545; 
        color: white; 
        border-color: #dc3545;
        transform: scale(1.05);
    }
    50% { 
        background: #f8d7da; 
        border-color: #f5c6cb;
        transform: scale(1.02);
    }
    100% { 
        background: #f6f6f6; 
        color: #6c757d;
        border-color: #6c757d;
        transform: scale(1);
    }
}

@keyframes data-forward {
    0% { 
        background: #ffc107; 
        color: #212529; 
        border-color: #ffc107;
        box-shadow: 0 0 10px rgba(255, 193, 7, 0.5);
    }
    50% { 
        background: #fff3cd; 
        border-color: #ffeaa7;
        box-shadow: 0 0 15px rgba(255, 193, 7, 0.7);
    }
    100% { 
        background: #e3f2fd; 
        border-color: #007bff;
        box-shadow: none;
    }
}

@keyframes register-write {
    0% { 
        background: #28a745; 
        color: white; 
        transform: scale(1.1);
        box-shadow: 0 0 8px rgba(40, 167, 69, 0.6);
    }
    100% { 
        background: #fff3cd; 
        transform: scale(1);
        box-shadow: none;
    }
}

.pipeline-stage.flushed {
    animation: pipeline-flush 0.8s ease-out;
}

.pipeline-stage.forwarding {
    animation: data-forward 0.6s ease-out;
}

.pipeline-stage.writing {
    animation: register-write 0.5s ease-out;
}

.address {
    font-weight: bold;
    color: #666;
}

.label {
    color: #e83e8c;
    font-weight: bold;
}

.instruction {
    color: #333;
}

.hex-value {
    font-family: 'Courier New', monospace;
    color: #495057;
    font-weight: bold;
}

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

.instruction-type {
    font-weight: bold;
    color: #007bff;
}

.opcode-field {
    font-family: 'Courier New', monospace;
    color: #dc3545;
    font-weight: bold;
}

.field-details {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #495057;
}

.field-name {
    color: #28a745;
    font-weight: bold;
}

.field-value {
    color: #6f42c1;
}

/* Pipeline visualization */
.pipeline-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
}

.forwarding-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.forwarding-path {
    stroke-width: 3;
    opacity: 0;
    animation: fade-in-path 0.5s ease-in-out forwards;
}

.forwarding-path.ex-to-ex {
    stroke: #dc3545;
    marker-end: url(#arrowhead-red);
}

.forwarding-path.mem-to-ex {
    stroke: #6f42c1;
    marker-end: url(#arrowhead-purple);
}

.forwarding-path.mem-to-id {
    stroke: #28a745;
    marker-end: url(#arrowhead-green);
}

@keyframes fade-in-path {
    from {
        opacity: 0;
        stroke-dasharray: 200;
        stroke-dashoffset: 200;
    }
    to {
        opacity: 0.8;
        stroke-dasharray: 200;
        stroke-dashoffset: 0;
    }
}

.control-signals {
    display: flex;
    justify-content: space-around;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 15px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.control-label {
    font-weight: bold;
    color: #495057;
}

.control-indicator {
    padding: 4px 8px;
    border-radius: 3px;
    font-weight: bold;
    min-width: 60px;
    text-align: center;
    transition: all 0.3s ease;
}

.control-indicator.active {
    background: #dc3545;
    color: white;
    transform: scale(1.1);
    box-shadow: 0 2px 4px rgba(220, 53, 69, 0.3);
}

.control-indicator.warning {
    background: #ffc107;
    color: #212529;
    transform: scale(1.1);
    box-shadow: 0 2px 4px rgba(255, 193, 7, 0.3);
}

.control-indicator.success {
    background: #28a745;
    color: white;
    transform: scale(1.1);
    box-shadow: 0 2px 4px rgba(40, 167, 69, 0.3);
}

.pipeline-stages {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
    margin-bottom: 20px;
    min-height: 180px;
    resize: vertical;
    overflow: hidden;
}

.pipeline-stage {
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    transition: all 0.3s ease;
    min-height: 140px;
    display: flex;
    flex-direction: column;
}

.pipeline-stage.active {
    border-color: #007bff;
    background: #e3f2fd;
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.2);
}

.pipeline-stage.stalled {
    border-color: #ffc107;
    background: #fff8e1;
}

.pipeline-stage.empty {
    border-color: #6c757d;
    background: #f6f6f6;
    opacity: 0.7;
}

.pipeline-stage h4 {
    font-size: 18px;
    font-weight: bold;
    color: #495057;
    margin: 0 0 5px 0;
}

.stage-label {
    font-size: 12px;
    color: #6c757d;
    margin-bottom: 10px;
    font-weight: 500;
}

.stage-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stage-info {
    font-size: 10px;
    color: #6c757d;
    margin-bottom: 8px;
    line-height: 1.3;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.stage-instruction {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #495057;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.8);
    padding: 8px;
    border-radius: 4px;
    min-height: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    margin-bottom: 8px;
}

.stage-registers {
    background: rgba(248, 249, 250, 0.9);
    border-radius: 3px;
    padding: 6px;
    font-family: 'Courier New', monospace;
    font-size: 10px;
}

.register-data {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
    color: #495057;
}

.register-data:last-child {
    margin-bottom: 0;
}

.register-data span {
    font-weight: bold;
    color: #007bff;
}

.mux-indicator {
    background: #e9ecef;
    border: 1px solid #adb5bd;
    border-radius: 2px;
    padding: 1px 4px;
    font-size: 8px;
    font-weight: bold;
    color: #495057;
    min-width: 20px;
    text-align: center;
    transition: all 0.3s ease;
}

.mux-indicator.forwarded {
    background: #ffc107;
    color: #212529;
    border-color: #ffca2c;
    transform: scale(1.1);
    box-shadow: 0 1px 3px rgba(255, 193, 7, 0.4);
}

.pipeline-controls {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.pipeline-mode-toggle {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.pipeline-mode-toggle label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: bold;
}

.pipeline-mode-toggle input[type="checkbox"] {
    transform: scale(1.2);
}

.pipeline-mode-toggle small {
    color: #6c757d;
    font-style: italic;
}

.pipeline-info {
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 20px;
    font-size: 14px;
}

.pipeline-info span {
    color: #495057;
}

.pipeline-info strong {
    color: #007bff;
}

/* Status bar */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#status {
    font-weight: bold;
    color: #28a745;
}

#status.error {
    color: #dc3545;
}

#status.running {
    color: #17a2b8;
}

#error-messages {
    color: #dc3545;
    font-weight: bold;
}

/* Responsive design */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .sample-program-selector {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .sample-program-selector label {
        text-align: center;
    }
    
    .view-controls {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
    }
    
    .execution-controls {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .shortcut {
        display: none; /* Hide shortcuts on mobile to save space */
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    header h1 {
        font-size: 1.8em;
    }
    
    .register-grid {
        grid-template-columns: 1fr;
    }
    
    .memory-header, .memory-row {
        font-size: 12px;
        grid-template-columns: 60px 80px 1fr 100px;
        gap: 5px;
    }
    
    #binary-view .memory-header,
    #binary-view .memory-row {
        grid-template-columns: 60px 100px 200px 80px;
    }
    
    #fields-view .memory-header,
    #fields-view .memory-row {
        grid-template-columns: 60px 150px 60px 1fr;
        gap: 3px;
    }
    
    .pipeline-stages {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .pipeline-stage {
        min-height: 80px;
        padding: 10px;
    }
    
    .pipeline-info {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
}