/**
 * ATmega328P lab simulator — scoped to #embed-atmega328p-root (max-width 800px, dark theme)
 */
#embed-atmega328p-root {
  max-width: 800px;
  width: 100%;
  box-sizing: border-box;
  font-family: 'Courier New', Courier, monospace;
  font-size: 11px;
  background: #0a0a0a;
  color: #c8e6c9;
  padding: 10px;
  border-radius: 4px;
}

#embed-atmega328p-root * {
  box-sizing: border-box;
}

/* Scrollbars: thin, low-contrast so they blend with the dark panels */
#embed-atmega328p-root .embed328p-mem-scroll,
#embed-atmega328p-root .embed328p-op-desc,
#embed-atmega328p-root .embed328p-flash-hex,
#embed-atmega328p-root .embed328p-flash-list,
#embed-atmega328p-root .embed328p-reg-grid,
#embed-atmega328p-root #embed328p-asm.embed328p-asm-input {
  scrollbar-width: thin;
  scrollbar-color: #4d4d4d #0c0c0c;
}

#embed-atmega328p-root .embed328p-mem-scroll::-webkit-scrollbar,
#embed-atmega328p-root .embed328p-op-desc::-webkit-scrollbar,
#embed-atmega328p-root .embed328p-flash-hex::-webkit-scrollbar,
#embed-atmega328p-root .embed328p-flash-list::-webkit-scrollbar,
#embed-atmega328p-root .embed328p-reg-grid::-webkit-scrollbar,
#embed-atmega328p-root #embed328p-asm.embed328p-asm-input::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

#embed-atmega328p-root .embed328p-mem-scroll::-webkit-scrollbar-track,
#embed-atmega328p-root .embed328p-op-desc::-webkit-scrollbar-track,
#embed-atmega328p-root .embed328p-flash-hex::-webkit-scrollbar-track,
#embed-atmega328p-root .embed328p-flash-list::-webkit-scrollbar-track,
#embed-atmega328p-root .embed328p-reg-grid::-webkit-scrollbar-track,
#embed-atmega328p-root #embed328p-asm.embed328p-asm-input::-webkit-scrollbar-track {
  background: rgba(10, 10, 10, 0.6);
  border-radius: 4px;
}

#embed-atmega328p-root .embed328p-mem-scroll::-webkit-scrollbar-thumb,
#embed-atmega328p-root .embed328p-op-desc::-webkit-scrollbar-thumb,
#embed-atmega328p-root .embed328p-flash-hex::-webkit-scrollbar-thumb,
#embed-atmega328p-root .embed328p-flash-list::-webkit-scrollbar-thumb,
#embed-atmega328p-root .embed328p-reg-grid::-webkit-scrollbar-thumb,
#embed-atmega328p-root #embed328p-asm.embed328p-asm-input::-webkit-scrollbar-thumb {
  background: rgba(70, 70, 70, 0.75);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

#embed-atmega328p-root .embed328p-mem-scroll::-webkit-scrollbar-thumb:hover,
#embed-atmega328p-root .embed328p-op-desc::-webkit-scrollbar-thumb:hover,
#embed-atmega328p-root .embed328p-flash-hex::-webkit-scrollbar-thumb:hover,
#embed-atmega328p-root .embed328p-flash-list::-webkit-scrollbar-thumb:hover,
#embed-atmega328p-root .embed328p-reg-grid::-webkit-scrollbar-thumb:hover,
#embed-atmega328p-root #embed328p-asm.embed328p-asm-input::-webkit-scrollbar-thumb:hover {
  background: rgba(90, 90, 90, 0.9);
  background-clip: padding-box;
}

#embed-atmega328p-root .embed328p-mem-scroll::-webkit-scrollbar-corner,
#embed-atmega328p-root .embed328p-op-desc::-webkit-scrollbar-corner,
#embed-atmega328p-root .embed328p-flash-hex::-webkit-scrollbar-corner,
#embed-atmega328p-root .embed328p-flash-list::-webkit-scrollbar-corner,
#embed-atmega328p-root .embed328p-reg-grid::-webkit-scrollbar-corner,
#embed-atmega328p-root #embed328p-asm.embed328p-asm-input::-webkit-scrollbar-corner {
  background: transparent;
}

#embed-atmega328p-root .embed328p-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0;
}

#embed-atmega328p-root .embed328p-row label {
  color: #81c784;
  white-space: nowrap;
}

#embed-atmega328p-root button {
  font-family: 'Courier New', Courier, monospace;
  font-size: 11px;
  padding: 4px 10px;
  background: #1b3a1f;
  border: 1px solid #4caf50;
  color: #a5d6a7;
  cursor: pointer;
  border-radius: 3px;
}

#embed-atmega328p-root button:hover {
  background: #2e4a32;
}

#embed-atmega328p-root button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  border-color: #555;
  color: #78909c;
  background: #1a1a1a;
}

#embed-atmega328p-root button:disabled:hover {
  background: #1a1a1a;
}

#embed-atmega328p-root input[type="range"]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#embed-atmega328p-root .embed328p-asm-example-select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  border-color: #555;
  color: #78909c;
}

#embed-atmega328p-root input[type="range"] {
  width: 100px;
  vertical-align: middle;
}

#embed-atmega328p-root .embed328p-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

@media (max-width: 720px) {
  #embed-atmega328p-root .embed328p-main {
    grid-template-columns: 1fr;
  }
}

#embed-atmega328p-root .embed328p-panel {
  border: 1px solid #2e4a32;
  background: #111;
  padding: 8px;
  border-radius: 4px;
}

#embed-atmega328p-root .embed328p-panel h4 {
  margin: 0 0 8px 0;
  font-size: 11px;
  color: #69f0ae;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#embed-atmega328p-root .embed328p-asm-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-bottom: 8px;
}

#embed-atmega328p-root .embed328p-asm-panel-head h4 {
  margin-bottom: 0;
}

#embed-atmega328p-root .embed328p-asm-example-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

#embed-atmega328p-root .embed328p-asm-example-label {
  color: #81c784;
  font-size: 10px;
  white-space: nowrap;
}

#embed-atmega328p-root .embed328p-asm-example-select {
  font-family: 'Courier New', Courier, monospace;
  font-size: 10px;
  min-width: 14em;
  max-width: min(100%, 22em);
  padding: 4px 8px;
  border-radius: 3px;
  border: 1px solid #2e4a32;
  background: #0d0d0d;
  color: #a5d6a7;
  cursor: pointer;
}

#embed-atmega328p-root .embed328p-asm-example-select:focus {
  outline: 2px solid #4caf50;
  outline-offset: 1px;
}

#embed-atmega328p-root .embed328p-asm-example-select option {
  background: #1a1a1a;
  color: #c8e6c9;
}

#embed-atmega328p-root .embed328p-chip-wrap {
  display: flex;
  justify-content: center;
  padding: 8px 0;
}

#embed-atmega328p-root .embed328p-chip-svg {
  max-width: 100%;
  height: auto;
}

#embed-atmega328p-root .embed328p-chip-svg .embed328p-arduino-label {
  fill: #a5d6a7;
  font-size: 10px;
  font-family: 'Courier New', Courier, monospace;
  pointer-events: none;
}

#embed-atmega328p-root .embed328p-pin {
  fill: #546e7a;
  stroke: #37474f;
  stroke-width: 0.5;
  transition: fill 0.15s ease, filter 0.15s ease;
}

#embed-atmega328p-root .embed328p-pin.embed328p-pin-high {
  fill: #ff5252;
  filter: drop-shadow(0 0 4px #ff5252);
}

#embed-atmega328p-root .embed328p-body {
  fill: #263238;
  stroke: #4caf50;
  stroke-width: 1.5;
}

#embed-atmega328p-root .embed328p-notch {
  fill: #0a0a0a;
  stroke: #4caf50;
  stroke-width: 0.5;
}

#embed-atmega328p-root .embed328p-sreg-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

#embed-atmega328p-root .embed328p-sbit {
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border: 1px solid #444;
  font-size: 9px;
  color: #888;
}

#embed-atmega328p-root .embed328p-sbit.on {
  background: #1565c0;
  color: #fff;
  border-color: #42a5f5;
}

#embed-atmega328p-root .embed328p-reg-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  max-height: 140px;
  overflow-y: auto;
}

#embed-atmega328p-root .embed328p-reg-cell {
  background: #1a1a1a;
  border: 1px solid #333;
  padding: 4px 2px;
  font-size: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 2.5em;
}

#embed-atmega328p-root .embed328p-reg-name {
  display: block;
  font-size: 9px;
  color: #81c784;
  line-height: 1.15;
}

#embed-atmega328p-root .embed328p-reg-val {
  display: block;
  font-size: 10px;
  line-height: 1.15;
  font-weight: 600;
}

#embed-atmega328p-root .embed328p-reg-cell.embed328p-reg-hot {
  background: #1b3a5c;
  border-color: #42a5f5;
}

#embed-atmega328p-root .embed328p-reg-cell.embed328p-reg-hot .embed328p-reg-name {
  color: #90caf9;
}

#embed-atmega328p-root .embed328p-reg-cell.embed328p-reg-step {
  background: #4a3728;
  border-color: #ff9800;
  color: #ffe0b2;
}

#embed-atmega328p-root .embed328p-reg-cell.embed328p-reg-step .embed328p-reg-name {
  color: #ffe0b2;
}

#embed-atmega328p-root .embed328p-mem-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

#embed-atmega328p-root .embed328p-mem-tabs button {
  border-color: #555;
  color: #aaa;
}

#embed-atmega328p-root .embed328p-mem-tabs button.embed328p-tab-on {
  border-color: #4caf50;
  color: #a5d6a7;
}

#embed-atmega328p-root .embed328p-mem-scroll {
  max-height: 160px;
  overflow: auto;
  border: 1px solid #222;
}

#embed-atmega328p-root .embed328p-mem-map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-bottom: 6px;
  font-size: 9px;
  line-height: 1.3;
  color: #b0bec5;
}

#embed-atmega328p-root .embed328p-map-leg {
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  white-space: nowrap;
}

#embed-atmega328p-root .embed328p-map-leg-reg {
  background: #1e3a5c;
  color: #bbdefb;
}

#embed-atmega328p-root .embed328p-map-leg-io {
  background: #4a3820;
  color: #ffe0b2;
}

#embed-atmega328p-root .embed328p-map-leg-ext {
  background: #342447;
  color: #e1bee7;
}

#embed-atmega328p-root .embed328p-map-leg-sram {
  background: #153828;
  color: #c8e6c9;
}

#embed-atmega328p-root .embed328p-mem-grid {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  gap: 1px;
  background: #222;
  padding: 2px;
}

#embed-atmega328p-root .embed328p-mem-cell {
  aspect-ratio: 1;
  min-width: 0;
  min-height: 14px;
  font-size: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d0d0d;
  color: #fff;
  cursor: default;
}

/* AVR data-space regions (0x0000–0x08FF grid) */
#embed-atmega328p-root .embed328p-mem-cell.embed328p-mem-reg {
  background: #1e3a5c;
  color: #e3f2fd;
}

#embed-atmega328p-root .embed328p-mem-cell.embed328p-mem-io {
  background: #4a3820;
  color: #fff8e1;
}

#embed-atmega328p-root .embed328p-mem-cell.embed328p-mem-extio {
  background: #342447;
  color: #f3e5f5;
}

#embed-atmega328p-root .embed328p-mem-cell.embed328p-mem-sram {
  background: #153828;
  color: #e8f5e9;
}

#embed-atmega328p-root .embed328p-mem-cell.written {
  background: #1b4d1b;
  color: #fff;
}

#embed-atmega328p-root .embed328p-mem-cell.embed328p-mem-sram.written {
  background: #2e7d32;
  color: #fff;
}

#embed-atmega328p-root .embed328p-mem-cell.eep {
  background: #1a1a2e;
}

#embed-atmega328p-root .embed328p-mem-cell.eep.written {
  background: #311b4d;
  color: #fff;
}

#embed-atmega328p-root .embed328p-mem-cell.embed328p-mem-step {
  box-shadow: inset 0 0 0 2px #ff9800;
  color: #fff;
  z-index: 1;
}

#embed-atmega328p-root .embed328p-flash-bin-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-bottom: 6px;
  font-size: 9px;
  line-height: 1.3;
  color: #b0bec5;
}

#embed-atmega328p-root .embed328p-flash-leg {
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  white-space: nowrap;
}

#embed-atmega328p-root .embed328p-flash-bin-note {
  font-size: 9px;
  color: #78909c;
  margin: 0 0 8px;
  line-height: 1.35;
}

#embed-atmega328p-root .embed328p-flash-split {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(240px, 1.4fr);
  gap: 10px;
  align-items: start;
}

@media (max-width: 640px) {
  #embed-atmega328p-root .embed328p-flash-split {
    grid-template-columns: 1fr;
  }
}

#embed-atmega328p-root .embed328p-flash-col-title {
  font-size: 9px;
  color: #69f0ae;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

#embed-atmega328p-root .embed328p-flash-list {
  max-height: 220px;
  overflow-y: auto;
  font-size: 10px;
  border: 1px solid #222;
  padding: 4px;
  margin-top: 0;
  color: #fff;
}

#embed-atmega328p-root .embed328p-flash-hex {
  max-height: 220px;
  overflow-x: hidden;
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  font-size: 9px;
  line-height: 1.45;
  white-space: pre;
  word-break: keep-all;
  tab-size: 4;
  border: 1px solid #2e4a32;
  border-radius: 2px;
  background: #050508;
  color: #e0e0e0;
}

#embed-atmega328p-root .embed328p-flash-bin-addr {
  color: #78909c;
  font-weight: normal;
  margin-right: 2px;
}

#embed-atmega328p-root .embed328p-flash-bin-word {
  display: inline-block;
  min-width: 6.25ch;
  margin: 0 2px 2px 0;
  padding: 0 3px;
  border-radius: 2px;
  font-family: 'Courier New', Courier, monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  text-align: center;
}

#embed-atmega328p-root .embed328p-flash-bin-word.embed328p-flash-bin-prog {
  background: #1e3a5c;
  color: #bbdefb;
}

#embed-atmega328p-root .embed328p-flash-bin-word.embed328p-flash-bin-empty {
  background: #252525;
  color: #9e9e9e;
}

#embed-atmega328p-root .embed328p-flash-bin-word.embed328p-flash-bin-boot {
  background: #4a2340;
  color: #f8bbd0;
}

/* Current instruction word = same index as PC / orange asm bar / listing */
#embed-atmega328p-root .embed328p-flash-bin-word.embed328p-flash-hex-pc {
  box-shadow: inset 0 0 0 2px #ff9800;
  outline: 1px solid rgba(255, 183, 77, 0.6);
  z-index: 1;
  position: relative;
}

#embed-atmega328p-root .embed328p-flash-leg.embed328p-flash-bin-prog {
  background: #1e3a5c;
  color: #bbdefb;
}

#embed-atmega328p-root .embed328p-flash-leg.embed328p-flash-bin-empty {
  background: #252525;
  color: #bdbdbd;
}

#embed-atmega328p-root .embed328p-flash-leg.embed328p-flash-bin-boot {
  background: #4a2340;
  color: #f8bbd0;
}

#embed-atmega328p-root .embed328p-flash-line {
  padding: 1px 4px;
  color: #fff;
}

#embed-atmega328p-root .embed328p-flash-line.step-exec {
  background: #3e2723;
  color: #fff;
  border-left: 3px solid #ff9800;
  padding-left: 2px;
}

#embed-atmega328p-root .embed328p-sbit.embed328p-sreg-step {
  border-color: #ffb74d;
  color: #ffe0b2;
  box-shadow: 0 0 0 1px rgba(255, 152, 0, 0.5);
}

#embed-atmega328p-root .embed328p-sp.embed328p-step-line {
  color: #ffb74d;
  font-weight: bold;
}

#embed-atmega328p-root .embed328p-pin.embed328p-pin-step {
  stroke: #ffb74d;
  stroke-width: 1.2;
}

#embed-atmega328p-root .embed328p-cycle {
  font-size: calc(10px + 2pt);
  color: #ffb74d;
  margin: 4px 0;
  min-height: 1.2em;
}

#embed-atmega328p-root .embed328p-asm-wrap {
  position: relative;
  width: 100%;
  min-height: 160px;
  border: 1px solid #2e4a32;
  border-radius: 2px;
  background: #050505;
  box-sizing: border-box;
}

#embed-atmega328p-root .embed328p-asm-highlight {
  position: absolute;
  left: 0;
  top: 0;
  margin: 0;
  padding: 6px;
  border: none;
  box-sizing: border-box;
  overflow: auto;
  font-family: 'Courier New', Courier, monospace;
  font-size: calc(11px + 2pt);
  line-height: 1.45;
  /* Match textarea: one logical line = one visual line (no wrap), or highlights drift vs textarea */
  white-space: pre;
  tab-size: 4;
  color: transparent;
  pointer-events: none;
  scrollbar-width: none;
}

#embed-atmega328p-root .embed328p-asm-highlight::-webkit-scrollbar {
  display: none;
}

#embed-atmega328p-root .embed328p-asm-highlight .embed328p-asm-row {
  display: block;
  min-height: 1.45em;
  box-sizing: border-box;
}

/* Source lines above first Flash word (e.g. leading ;) — not executed; shown only when PC = 0 */
#embed-atmega328p-root .embed328p-asm-highlight .embed328p-asm-row-header {
  background: rgba(40, 40, 40, 0.85);
  box-shadow: inset 2px 0 0 #555;
  border-radius: 2px;
}

/* Same instruction as “FETCH → DECODE → EXECUTE : …” (current PC in Flash) */
#embed-atmega328p-root .embed328p-asm-highlight .embed328p-asm-row-cycle {
  background: rgba(62, 39, 35, 0.95);
  box-shadow: inset 3px 0 0 #ff9800;
  border-radius: 2px;
}

#embed-atmega328p-root #embed328p-asm.embed328p-asm-input {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 160px;
  margin: 0;
  background: transparent;
  color: #69f0ae;
  border: none;
  outline: none;
  font-family: 'Courier New', Courier, monospace;
  font-size: calc(11px + 2pt);
  line-height: 1.45;
  white-space: pre;
  tab-size: 4;
  padding: 6px;
  resize: vertical;
  box-sizing: border-box;
  scrollbar-gutter: stable;
}

#embed-atmega328p-root .embed328p-op-desc {
  margin-top: 8px;
  padding: 8px 10px;
  height: 11.5em;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: auto;
  scrollbar-gutter: stable;
  background: #0a0f0c;
  border: 1px solid #2e4a32;
  border-radius: 4px;
  font-family: 'Courier New', Courier, monospace;
  font-size: calc(10px + 2pt);
  line-height: 1.5;
  color: #e8f5e9;
  text-align: left;
}

#embed-atmega328p-root .embed328p-op-desc .embed328p-op-line {
  margin: 0 0 8px;
  padding: 0;
}

#embed-atmega328p-root .embed328p-op-desc .embed328p-op-line code {
  color: #81c784;
  font-size: calc(11px + 2pt);
}

#embed-atmega328p-root .embed328p-op-desc .embed328p-op-title {
  margin: 0 0 6px;
  font-size: calc(10px + 2pt);
  font-weight: 600;
  color: #69f0ae;
  letter-spacing: 0.02em;
}

#embed-atmega328p-root .embed328p-op-desc .embed328p-op-bullets {
  margin: 0;
  padding-left: 1.15em;
  color: #e0e0e0;
}

#embed-atmega328p-root .embed328p-op-desc .embed328p-op-bullets li {
  margin: 4px 0;
}

#embed-atmega328p-root .embed328p-op-desc .embed328p-op-bullets code {
  color: #a5d6a7;
  font-size: inherit;
}

#embed-atmega328p-root .embed328p-op-desc .embed328p-op-muted {
  margin: 0;
  color: #9e9e9e;
  font-size: calc(10px + 2pt);
}

#embed-atmega328p-root .embed328p-status {
  color: #ffab40;
  font-size: 10px;
  min-height: 1.2em;
  margin-top: 4px;
}

#embed-atmega328p-root .embed328p-sp {
  color: #90caf9;
  font-size: 10px;
  margin: 4px 0;
}
