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

body {
    font-family: 'Courier New', monospace;
    padding: 20px;
    background: #f8f9fa;
    color: #333;
}

h1 {
    margin-bottom: 30px;
    font-size: 28px;
    text-align: center;
    color: #2c3e50;
    font-weight: normal;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto 1fr;
    gap: 20px;
}

.editor-panel {
    grid-row: 1 / 3;
    grid-column: 1;
}

.controls-panel {
    grid-row: 1;
    grid-column: 2;
}

.metrics-panel {
    grid-row: 2;
    grid-column: 2;
}

.cpu-panel {
    grid-row: 3;
    grid-column: 1;
}

.io-panel {
    grid-row: 4;
    grid-column: 1;
}

.memory-panel {
    grid-row: 3 / 5;
    grid-column: 2;
}

.panel {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.panel h2 {
    font-size: 16px;
    margin: 0;
    padding: 12px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    border-radius: 8px 8px 0 0;
    color: #495057;
    font-weight: normal;
}

.panel h3 {
    font-size: 14px;
    margin: 0;
    padding: 10px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    color: #495057;
    font-weight: normal;
}

.cpu-state {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    margin-bottom: 15px;
}

.cpu-state label {
    font-weight: bold;
}

.cpu-state input {
    font-family: 'Courier New', monospace;
    padding: 5px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: #f8f9fa;
    transition: background-color 0.3s ease;
}

.cpu-state input.changed {
    animation: fadeToNormal 0.6s ease;
}

.io-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.io-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.io-group label {
    font-weight: bold;
}

.io-group input {
    font-family: 'Courier New', monospace;
    padding: 5px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: white;
}

.io-group input:focus {
    outline: none;
    border-color: #4a90e2;
}

.io-output {
    font-family: 'Courier New', monospace;
    padding: 10px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: #f8f9fa;
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
}

.memory-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    font-size: 14px;
    max-height: 550px;
    overflow-y: auto;
}

.memory-column {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.memory-cell {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 5px;
    align-items: center;
}

.memory-cell .addr {
    background: #f8f9fa;
    padding: 3px 8px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-weight: bold;
    text-align: right;
    min-width: 30px;
    color: #6c757d;
}

.memory-cell input {
    font-family: 'Courier New', monospace;
    padding: 3px 5px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    flex: 1;
    transition: background-color 0.3s ease;
}

.memory-cell input:focus {
    outline: none;
    border-color: #4a90e2;
}

.memory-cell input.changed {
    animation: fadeMemoryToNormal 0.6s ease !important;
    background-color: #ffffcc !important;
}

@keyframes fadeToNormal {
    0% {
        background-color: #ffffcc;
    }
    100% {
        background-color: #f8f9fa;
    }
}

@keyframes fadeMemoryToNormal {
    0% {
        background-color: #ffffcc !important;
    }
    100% {
        background-color: white !important;
    }
}

.memory-cell .decoded {
    background: #f8f9fa;
    padding: 3px 6px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    color: #6c757d;
    font-size: 12px;
    min-width: 40px;
    text-align: center;
}

.controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

button {
    font-family: 'Courier New', monospace;
    padding: 8px 16px;
    border: 1px solid #dee2e6;
    background: #e9ecef;
    cursor: pointer;
    font-size: 14px;
    border-radius: 4px;
    transition: all 0.2s;
}

button:hover {
    background: #d3d7db;
    border-color: #adb5bd;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Primary action buttons */
#loadProgram,
#startStop {
    background: #4a90e2;
    color: white;
    border-color: #4a90e2;
    font-weight: normal;
}

#loadProgram:hover,
#startStop:hover {
    background: #357abd;
    border-color: #357abd;
}

/* Step button - secondary but important */
#step {
    background: #6c757d;
    color: white;
    border-color: #6c757d;
}

#step:hover {
    background: #5a6268;
    border-color: #5a6268;
}

select {
    font-family: 'Courier New', monospace;
    padding: 5px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 14px;
}

select:hover {
    border-color: #adb5bd;
}

select:focus {
    outline: none;
    border-color: #4a90e2;
}

input[type="number"] {
    font-family: 'Courier New', monospace;
    padding: 5px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    text-align: center;
}

input[type="number"]:focus {
    outline: none;
    border-color: #4a90e2;
}

.metrics-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    padding: 12px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 14px;
    align-items: center;
}

.metric-label {
    font-weight: bold;
    color: #6c757d;
    padding-right: 10px;
}

.metric-values {
    display: flex;
    gap: 15px;
}

.metric-values strong {
    color: #4a90e2;
    font-family: 'Courier New', monospace;
}

.status {
    margin-top: 10px;
    padding: 8px 12px;
    background: #e7f3ff;
    border-left: 3px solid #4a90e2;
    border-radius: 4px;
    font-size: 13px;
    color: #495057;
}

.editor-container {
    position: relative;
    width: 100%;
    min-height: 350px;
    border: 1px solid #dee2e6;
    border-radius: 0 0 8px 8px;
    background: #fafafa;
    overflow: hidden;
}

.highlight-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 10px;
    margin: 0;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow: hidden;
    pointer-events: none;
    z-index: 1;
    tab-size: 4;
}

.edit-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    min-height: 350px;
    padding: 10px;
    margin: 0;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.4;
    background: transparent;
    color: transparent;
    caret-color: #333;
    border: none;
    outline: none;
    resize: vertical;
    z-index: 2;
    tab-size: 4;
    overflow: auto;
}

.edit-layer::selection {
    background: rgba(74, 144, 226, 0.3);
}

.edit-layer::placeholder {
    color: #999;
}

/* Syntax highlighting colors */
.hl-directive {
    color: #0066cc;
    font-weight: bold;
}

.hl-instruction {
    color: #cc0066;
}

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

.hl-number {
    color: #009900;
}

.hl-comment {
    color: #999;
    font-style: italic;
}

.hl-identifier {
    color: #333;
}
