body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 20px;
    background-color: #f5f5f5;
    color: #333;
}

.container {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping on smaller screens if needed */
    max-width: 1500px; /* Adjusted width */
    margin: 20px auto; /* Add top/bottom margin */
    gap: 25px; /* Slightly more gap */
}

/* CPU and Memory Area */
.cpu-memory-container {
    flex: 3; /* Takes more space */
    min-width: 500px; /* Minimum width */
    background-color: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column; /* Stack CPU and Memory vertically */
}

/* Controls and Info Area */
.controls-container {
    flex: 2; /* Takes less space */
    min-width: 350px; /* Minimum width */
    background-color: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

h1, h2, h3 {
    color: #333;
    margin-top: 0; /* Remove default top margin for headings */
}
h1 {
    text-align: center;
    margin-bottom: 5px;
    color: #007399;
}
body > p { /* Style the intro paragraph */
    text-align: center;
    margin-bottom: 20px;
    color: #555;
    font-size: 0.9em;
}


/* CPU Box */
.cpu {
    display: flex;
    border: 2px solid #0099cc;
    border-radius: 8px;
    padding: 15px; /* Increased padding */
    padding-top: 25px; /* More padding top for title */
    margin-bottom: 0px;
    position: relative;
    background-color: #e6f7ff; /* Light blue background for CPU area */
}

.cpu-title {
    position: absolute;
    top: -12px;
    left: 20px;
    background-color: #e6f7ff; /* Match CPU background */
    padding: 2px 10px; /* Adjusted padding */
    font-weight: bold;
    color: #0099cc; /* Match border color */
    border-radius: 4px; /* Slight rounding */
    border: 1px solid #0099cc; /* Add border to title */
}

.cpu-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around; /* Space out ALU and Control */
    padding-right: 20px; /* Increased padding */
    border-right: 1px solid #b3e0ff; /* Separator line */
}

.cpu-right {
    flex: 2; /* More space for registers */
    padding-left: 20px; /* Increased padding */
    display: flex;
    flex-direction: column;
}

.alu, .control-unit {
    background-color: #cceeff; /* Slightly darker blue */
    border: 1px solid #99d6ff;
    border-radius: 5px;
    padding: 15px;
    margin: 10px 0;
    min-height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    text-align: center;
    transition: background-color 0.3s ease-in-out; /* For highlighting */
}

/* Registers */
.registers-section {
     display: flex;
     flex-direction: column;
     flex-grow: 1; /* Allow it to take space */
}

.registers, .special-registers {
    margin: 10px 0;
}

.registers h3, .special-registers h3 {
    margin-bottom: 10px;
    text-align: center;
    font-size: 1.1em;
    color: #007399;
}

.register-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); /* Responsive grid */
    gap: 8px; /* Increased gap */
}

.register {
    display: flex;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #fff;
    overflow: hidden; /* Ensure content fits */
    transition: background-color 0.3s ease-in-out; /* For highlighting */
}

.register-label {
    width: 25px;
    background-color: #f0f0f0;
    padding: 6px 5px; /* Adjusted padding */
    text-align: center;
    border-right: 1px solid #ccc;
    font-weight: bold;
    color: #555;
    flex-shrink: 0; /* Prevent shrinking */
}

.register-value {
    flex-grow: 1; /* Take remaining space */
    padding: 6px 5px; /* Adjusted padding */
    text-align: center;
    font-family: monospace;
    font-size: 1.8em; /* Slightly larger register values */
    min-width: 30px; /* Minimum width */
    overflow: hidden; /* Hide overflow */
    text-overflow: ellipsis; /* Add ellipsis if too long */
}

.special-register {
    display: flex;
    margin: 0 auto 10px auto; /* Center special registers */
    width: 60%; /* Control width */
    min-width: 120px; /* Min width */
    border: 1px solid #999;
    border-radius: 4px;
    background-color: #e0e0e0;
    transition: background-color 0.3s ease-in-out; /* For highlighting */
}

.special-register-label {
    width: 35px; /* Wider label */
    background-color: #c0c0c0;
    padding: 6px 5px;
    text-align: center;
    border-right: 1px solid #999;
    font-weight: bold;
    color: #444;
    flex-shrink: 0;
}

.special-register-value {
    flex-grow: 1;
    padding: 6px 5px;
    text-align: center;
    font-family: monospace;
    font-size: 1.8em;
}

/* Bus */
.bus {
    position: relative;
    height: 50px; /* More height for vertical wires */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

.bus-label {
    position: absolute;
    top: 40%;
    right: 60%;
    padding: 0 8px;
    font-size: 1.2em;
    font-weight: bold;
    color: #777;
    z-index: 2;
}


.bus-wires {
    position: relative;
    width: fit-content;
    height: 100%;
    display: flex;
    gap: 10px; /* Controls the spacing between wires */
    justify-content: center;
    align-items: stretch;
}


.bus-wire {
    width: 2px;
    height: 100%;
    background-color: #666;
    border-radius: 1px;
    opacity: 0.9;
}



/* Memory */
.memory {
    background-color: #fff;
    border: 2px solid #0099cc;
    border-radius: 8px;
    padding: 15px;
    padding-top: 25px; /* Space for title */
    position: relative;
    margin-top: 00px;
    flex-grow: 1; /* Allow memory to take remaining space */
    overflow-y: auto; /* Add scroll */
    max-height: 735px; /* Limit memory height */
    min-height: 200px; /* Ensure minimum height */
}

.memory-title {
    position: sticky; /* Keep title visible */
    top: -15px; /* Adjust position relative to padding */
    left: 20px;
    background-color: white; /* Cover content */
    padding: 2px 10px; /* Match CPU title style */
    font-weight: bold;
    z-index: 2; /* Keep title above grid */
    color: #0099cc;
    border-radius: 4px;
    border: 1px solid #0099cc;
    display: inline-block; /* Prevent stretching */
}

.memory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    padding-top: 10px;
}


.memory-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-start;
}

.memory-byte {
    display: flex;
    gap: 4px;
    border-right: 3px solid #0099cc;
    padding-right: 4px;
    width: 100%;         /* fill the grid cell */
    box-sizing: border-box;
}






.memory-address {
    background-color: #f0f0f0;
    padding: 5px 8px;
    text-align: right;
    border-radius: 4px;
    font-family: monospace;
    font-weight: bold;
    color: #555;
    font-size: 0.9em; /* Slightly smaller address */
    user-select: none; /* Prevent selection */
}

.memory-cell {
    border: 1px solid #ccc;
    padding: 0;
    text-align: center;
    border-radius: 4px;
    background-color: #fff;
    position: relative; /* For highlighting */
}

.memory-cell-input {
    width: 100%;
    box-sizing: border-box;
    border: none;
    text-align: center;
    font-family: monospace;
    font-size: 1em; /* Ensure readable size */
    padding: 4px; /* Input padding */
    border-radius: 3px; /* Match cell rounding */
    text-transform: uppercase;
    outline: none;
    background-color: transparent; /* Inherit from cell */
    transition: background-color 0.3s ease-in-out; /* For highlighting */
}
.memory-cell-input:focus {
    background-color: #e6f7ff; /* Highlight when editing */
    box-shadow: inset 0 0 2px #0099cc;
}
/* Style for highlighting memory cell during operations */
.memory-cell.highlight .memory-cell-input {
     background-color: #ffff99 !important;
}
.memory-cell.highlight-fetch .memory-cell-input {
      background-color: #ccffcc !important;
 }
.memory-cell.highlight-execute .memory-cell-input {
     background-color: #ffddcc !important;
 }


/* Data Flow Animation */
.data-flow {
    position: absolute;
    /* Make overlay cover the entire cpu-memory-container */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none; /* Allow clicks to pass through */
    z-index: 10;
    overflow: hidden; /* Prevent animations spilling out */
}

.animation-path {
    position: absolute;
    background-color: rgba(255, 204, 0, 0.8); /* Slightly more opaque */
    height: 4px;
    border-radius: 2px;
    opacity: 0;
    z-index: 100;
    pointer-events: none;
    transition: opacity 0.1s linear; /* Faster fade */
    box-shadow: 0 0 5px rgba(255, 204, 0, 0.5); /* Add glow */
}

.arrow-head {
     position: absolute;
     width: 12px; /* Larger arrow */
     height: 12px;
     background-color: rgba(255, 204, 0, 0.8);
     clip-path: polygon(0% 0%, 100% 50%, 0% 100%); /* Triangle */
     transform-origin: center center;
     opacity: 0;
     transition: opacity 0.1s linear; /* Faster fade */
     z-index: 101;
     pointer-events: none;
}

/* Highlighting */
.highlight {
    /* Applied directly via JS for specific elements */
    transition: background-color 0.2s ease-in-out;
    background-color: #ffff99 !important;
    box-shadow: 0 0 8px rgba(255, 255, 0, 0.7); /* Add glow */
}
.highlight-fetch {
     background-color: #ccffcc !important; /* Green for fetch */
     box-shadow: 0 0 8px rgba(0, 255, 0, 0.7);
}
.highlight-decode {
    background-color: #e6ccff !important; /* Purple for decode */
    box-shadow: 0 0 8px rgba(200, 150, 255, 0.7);
}
.highlight-execute {
    background-color: #ffddcc !important; /* Orange for execute */
     box-shadow: 0 0 8px rgba(255, 150, 50, 0.7);
}


/* Controls Area */
button {
    background-color: #0099cc;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 4px;
    cursor: pointer;
    margin: 5px;
    font-size: 14px;
    transition: background-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
}

button:hover {
    background-color: #007399;
    box-shadow: 0 3px 5px rgba(0, 0, 0, 0.15);
}
button:active {
    background-color: #005a7a;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}


button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    color: #666;
    box-shadow: none;
}

.control-panel {
    margin-bottom: 25px; /* Increased margin */
    text-align: center;
}
 .control-panel h2 {
     margin-bottom: 15px;
 }
 .control-panel button {
     margin: 5px 8px;
 }

/* Code Editor */
.code-editor {
    margin-bottom: 25px;
}
 .code-editor h2 {
     margin-bottom: 10px;
 }

textarea {
    width: calc(100% - 22px); /* Account for padding and border */
    min-height: 150px;
    max-height: 300px; /* Limit growth */
    font-family: monospace;
    font-size: 25px;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #ccc;
    resize: vertical;
    line-height: 1.5; /* Better line spacing */
}
textarea:focus {
    outline: none;
    border-color: #0099cc;
    box-shadow: 0 0 5px rgba(0, 153, 204, 0.5);
}
.code-editor p { /* Style the note below textarea */
     font-size: 0.85em;
     color: #666;
     margin-top: 8px;
     line-height: 1.3;
 }

/* Cycle Info Box */
.cycle-info {
    background-color: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    margin-top: 25px;
}
 .cycle-info h3 {
     margin-top: 0;
     margin-bottom: 10px;
     color: #007399;
 }
 .cycle-info p {
     margin: 8px 0;
     font-size: 0.95em;
 }
.cycle-step {
    font-weight: bold;
    color: #555; /* Consistent color */
    display: inline-block; /* Align better */
    min-width: 130px; /* Ensure alignment */
}
#current-phase, #current-instruction {
    font-family: monospace;
    color: #007399;
    font-weight: bold;
    font-size: 1.2em;
}

/* Description Box */
.description {
    margin-top: 15px;
    padding: 12px; /* More padding */
    background-color: #e6f7ff;
    border: 1px dashed #99d6ff;
    border-radius: 4px;
    color: #333;
    min-height: 45px; /* Increased height */
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 1.2em;
    font-style: normal; /* Remove italics for better readability */
    font-family: monospace; /* Use monospace for instruction details */
    line-height: 1.4;
}

/* Info Panel */
.info-panel {
    margin-top: 25px;
    padding: 15px;
    background-color: #f0f7ff;
    border-radius: 4px;
    border-left: 4px solid #0099cc;
}
 .info-panel h3 {
     margin-top: 0;
     margin-bottom: 15px;
     color: #007399;
 }

.instruction-set {
    font-family: monospace;
    margin-top: 10px;
    line-height: 1.7; /* Increase spacing */
    font-size: 0.9em; /* Slightly smaller */
}
 .instruction-set p {
    margin: 3px 0;
 }
 .instruction-set b { /* Style the opcode part */
    display: inline-block;
    width: 50px; /* Align opcodes */
    color: #005a7a;
 }
.info-panel p {
    font-size: 1.2em;
    color: #444;
    margin-top: 10px;
}

/* Utility class for active PC location */
.memory-cell-input.pc-highlight {
    background-color: #cceeff !important; /* Light blue highlight for PC */
    box-shadow: inset 0 0 0 2px #0099cc; /* Add an inset border */
}

.memory-register {
    display: flex;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #fff;
    overflow: hidden;
    flex-direction: column;
    transition: background-color 0.3s ease-in-out;
}

.memory-register-label {
    background-color: #f0f0f0;
    padding: 5px;
    text-align: center;
    font-weight: bold;
    font-family: monospace;
    font-size: 0.85em;
    color: #555;
}

.memory-register-input {
    width: 100%;
    box-sizing: border-box;
    border: none;
    text-align: center;
    font-family: monospace;
    font-size: 1.8em;
    padding: 6px;
    text-transform: uppercase;
    outline: none;
    background-color: transparent;
    transition: background-color 0.3s ease-in-out;
}
.memory-register-input:focus {
    background-color: #e6f7ff;
    box-shadow: inset 0 0 2px #0099cc;
}

/* For highlighting compatibility */
.memory-register.highlight .memory-register-input {
    background-color: #ffff99 !important;
}
.memory-register.highlight-fetch .memory-register-input {
    background-color: #ccffcc !important;
}
.memory-register.highlight-execute .memory-register-input {
    background-color: #ffddcc !important;
}
.memory-register-input.pc-highlight {
    background-color: #cceeff !important;
    box-shadow: inset 0 0 0 2px #0099cc;
}

.memory-spacer {
    width: 100%;
    height: 1px;
    grid-column: 1 / -1;
    background-color: transparent;
}

.memory-register.memory-divider {
    border-right: 3px solid #0099cc;
    padding-right: 3px;
}
