html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  scroll-behavior: smooth; 
}

body {
    font-family: monospace;
    background: #0e0e10;
    color: #e5e5e5;
    margin: 0;
    padding: 10px;
    display: flex;
    min-height: 100vh;
    flex-direction: column;
    overflow-x: hidden;
}

h1 { margin: 8px 0 12px 0; }

/* --- Layout --- */
.main {
  flex: 1;               /* fills space above footer */
  display: flex;
  flex-direction: row;
  overflow: auto;
  scroll-behavior: smooth;
}

.panel {
    background: #18181b;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    overflow: visible; 
}

.left { flex: 1.2; }
.middle {
  flex: 1.2;
  overflow-y: auto;      
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 60px; /* ensures space below mem inspector */
}
.right { flex: 1; overflow-y: auto; }

/* --- Controls & Inputs --- */
textarea, input {
    background: #101013;
    color: #e5e5e5;
    border: 1px solid #333;
    padding: 6px;
    font-family: monospace;
    border-radius: 4px;
}

textarea { width: 100%; height: 240px; resize: vertical; }
button {
    margin: 3px;
    padding: 6px 10px;
    border: none;
    border-radius: 4px;
    background: #1e90ff;
    color: white;
    font-weight: bold;
    cursor: pointer;
}
button:hover { background: #0077ee; }

/* --- Tables --- */
table { border-collapse: collapse; width: 100%; font-family: monospace; }
td { padding: 4px 8px; border-bottom: 1px solid #333; }

/* --- Console --- */
#consoleOutput {
    background: #111;
    color: #ddd;
    font-family: monospace;
    padding: 8px;
    flex: 1;
    overflow-y: auto;
    border-radius: 6px;
    border: 1px solid #444;
    white-space: pre-wrap;
}
.console-info { color: #4ae; }
.console-error { color: #f55; }
.console-warning { color: #ff9933; }

/* --- Current instruction highlight --- */
#currInstr {
    color: #80ff80;
    font-weight: bold;
    margin-bottom: 10px;
    transition: background 0.3s;
}

/* Green highlight for changed memory/registers */
.changed {
background-color: #003300;
color: #80ff80;
transition: background 0.3s, color 0.3s;
}


#memTable {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}
#memTable th, #memTable td {
  padding: 4px 8px;
  border-bottom: 1px solid #333;
  text-align: left;
}

#memTable tr:nth-child(even) {
  background-color: #1a1a1a;
}
/* --- Horizontal Resizing --- */

.divider {
width: 5px;
background: #333;
cursor: col-resize;
user-select: none;
transition: background 0.2s;
}
.divider:hover { background: #1e90ff; }

/* --- Vertical Resizing (Console Split) --- */
.console-container {
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
}

#consoleOutput {
flex: 1;
min-height: 100px;
overflow-y: auto;
}

.divider-horizontal {
height: 5px;
background: #333;
cursor: row-resize;
user-select: none;
transition: background 0.2s;
}
.divider-horizontal:hover { background: #1e90ff; }

/* --- Smooth transitions --- */
.panel, #consoleOutput, #memTable, textarea {
transition: width 0.2s ease, height 0.2s ease;
} 

/* Red flash for memory warnings */
.warning-flash {
background-color: #550000 !important;
color: #ff6666 !important;
transition: background 0.5s, color 0.5s;
}


.footer {
  position: sticky;
  bottom: 0;
  left: 0;
  width: 100%;
  z-index: 1;
  background: #0e0e10;
  border-top: 1px solid #333;
  text-align: center;
  padding: 8px 0;
  transition: all 0.25s ease-in-out; 
  opacity:0.9;
  pointer-events: none; 
}
.footer * {
  pointer-events: auto;         
}



.footer a {
color: #1e90ff;
text-decoration: none;
font-weight: 600;
transition: color 0.2s ease;
}

.footer a:hover {
color: #4ea3ff;
text-decoration: underline;
}

.footer strong {
color: #ddd;
}

/* Highlighted center byte in memory inspector */
.mem-highlight {
  background-color: #1e90ff !important; /* bright blue */
  color: #fff !important;
  font-weight: bold;
  box-shadow: 0 0 6px #1e90ff;
  border-color: #4aa3ff;
  transition: background 0.2s ease, color 0.2s ease;
}

/* Slight hover effect for the table */
.mem-inspect-table td:hover {
  background-color: #444;
}

::-webkit-scrollbar {
  width: 6px;                  /* thin scrollbar */
}

::-webkit-scrollbar-track {
  background: #151515;         /* track (background) */
  border-radius: 3px;
}

::-webkit-scrollbar-thumb {
  background-color: #3a3a3a;   /* thumb (handle) */
  border-radius: 3px;
  border: 1px solid #222;      /* subtle contrast edge */
}

::-webkit-scrollbar-thumb:hover {
  background-color: #1e90ff;   /* hover color matches theme */
  border-color: #0077ee;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: #3a3a3a #151515;
}

.mem-inspect-scroll {
  overflow-x: auto;
  overflow-y: auto;    /* ✅ allow both directions */
  padding-bottom: 6px;
  margin-top: 4px;
  border-bottom: 1px solid #333;
  max-width: 100%;
  max-height: 300px;   /* ✅ cap the height so scrollbars appear */
}

.mem-inspect-table {
  border-collapse: collapse;
  margin: 0;
  white-space: nowrap;
  min-width: max-content;
  table-layout: fixed; /* ✅ ensures consistent column widths */
}

.mem-inspect-table th,
.mem-inspect-table td {
  border: 1px solid #666;
  text-align: center;
  font-family: monospace;
  background-color: #222;
  color: #0f0;
  padding: 4px 6px;
  width: 70px; /* ✅ fixed width for consistency */
  min-width: 70px;
  max-width: 80px;
}

.mem-inspect-table th {
  background-color: #181818;
  color: #ddd;
}

.mem-cell {
  width: 48px;
  text-align: center;
  padding: 4px;
  font-family: monospace;
  transition: background-color 0.25s ease;
}


.flash {
  animation: flashfade 0.3s ease;
}

@keyframes flashfade {
  0% { background-color: #ffe680; }
  100% { background-color: inherit; }
}


/* --- Mobile View --- */
@media (max-width: 900px) {
  .main {
    flex-direction: column;           /* stack panels vertically */
    height: auto;
  }

  .divider, .divider-horizontal {
    display: none;                   /* hide manual resize dividers */
  }

  .panel {
    width: 100%;
    min-height: auto;
    padding: 8px;
  }

  textarea#programInput {
    width: 100%;
    min-height: 300px;
    font-size: 14px;
  }

  button {
    flex: 1;
    margin: 4px 2px;
    padding: 10px;
    z-index: 5;  
    font-size: 14px;
  }

  #regTable, #memTable {
    font-size: 13px;
    overflow-x: auto;
    display: block;
    width: 100%;
  }

  #memInspectResult {
    overflow-x: auto;
    font-size: 13px;
  }

  .footer {
    font-size: 12px;
    text-align: center;
    flex-wrap: wrap;
    line-height: 1.5em;
  }
}

@media (max-width: 900px) {
  html, body {
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    padding: 0; /* remove global padding to avoid extra scrollbars */
  }

  .main {
    flex-direction: column;
    height: auto;
    overflow: visible; /* ✅ allow panels to flow naturally */
      .main {
    padding-bottom: 60px; /* add breathing room so footer doesn’t hide content */
  }
  }

  .panel {
    width: 100%;
    min-height: auto;
    padding: 10px;
    box-sizing: border-box;
  }

  textarea#programInput {
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;        /* small spacing between stacked panels */
    height: auto !important;    /* override any inherited flex height */
    flex: 0 0 auto !important;  /* don't stretch to fill */
    display: block;             /* natural flow height */
  }

  button {
    flex: 1;
    margin: 4px 2px;
    padding: 10px;
    font-size: 14px;
  }

  #regTable, #memTable {
    font-size: 13px;
    margin-top: 4px;
    display: block;
    width: 100%;
    overflow-x: auto;
    
  }

  #memInspectResult {
    overflow-x: auto;
    font-size: 13px;
  }

  /* ✅ Fix footer on mobile */
  .footer {
    position: fixed;          /* make footer always visible */
    bottom: 0;
    left: 0;
    width: 100%;
    font-size: 12px;
    text-align: center;
    background: #0e0e10;
    border-top: 1px solid #333;
    padding: 10px 4px;
    line-height: 1.4em;
    opacity: 0.95;
    z-index: 10;
  }

  #toggleRegNamesBtn {
    font-size: 12px;
    padding: 4px 8px;
    margin-left: 8px;
    border-radius: 4px;
    flex-shrink: 0;
    max-width: 90px;
    white-space: nowrap;   /* prevents wrapping to two lines */
  }

  /* Reduce vertical padding/margins in panels */
  .panel h3 {
    margin-top: 6px;
    margin-bottom: 6px;
    font-size: 14px;
  } 

  /* Make console output area shorter on mobile */
  #consoleOutput {
    min-height: 140px;      /* was 240+ */
    max-height: 220px;      /* cap height */
    font-size: 13px;
    padding: 6px;
    padding-bottom: 40px;   
    box-sizing: border-box;
  }

  /* Compact console container */
  .console-container {
    flex: 0 0 auto;
    max-height: 300px;
  }



  /* Remove dividers for small screens */
  .divider, .divider-horizontal {
    display: none;
  }

  /* Make text area height flexible but not huge */
  #panel-left textarea#programInput {
    min-height: 260px;         /* taller for comfort typing */
    max-height: 360px;
    margin-bottom: 8px;        /* small gap before buttons */
    display: block;
  }

  #panel-left {
  margin-bottom: 0;          /* remove extra gap between panels */
  padding-bottom: 6px;       /* keep small breathing space */
  height: auto !important;   /* don't stretch */
  flex: 0 0 auto !important;
}

/* Button area spacing under textarea */
#panel-left button {
  margin-top: 4px;
  margin-bottom: 0;          /* ✅ remove empty space below buttons */
}

/* Remove any large gaps before the next (middle) panel */
#panel-left + .panel {
  margin-top: 4px;           /* just a subtle visual divider */
}

/* Compact console section */
#panel-right {
  height: auto !important;
  flex: 0 0 auto !important;
  max-height: none;
}

/* Slightly reduce margins to tighten spacing visually */
h3 {
  margin-top: 4px;
  margin-bottom: 6px;
}
}


#consoleOutput, textarea {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

@media (min-width: 901px) {
  .footer {
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.05);
  }
}

#panel-left button {
  position: relative;
  z-index: 5;             /* ✅ ensures they're always clickable */
}

.middle,
.right {
  overflow-y: auto;       /* ✅ keep their intended scroll behavior */
  overflow-x: hidden;
}