/* Author: Jesse Carpenter */
/* Website: carpentersoftware.com */
/* Page: Uno Breadboard Simulator (Experimental) */
/* Version: Carpenter Software 0.3.1 */
/* DATE: 20261120 */
/* 0.2.0: IDE layout (Build, Upload, Run, Stop, line numbers, Output */
/* and Serial Monitor tabs), focus outlines, larger touch targets, */
/* and the full letter g in the stamp. Components bar as a column at */
/* the left of the board on wide screens (760 pixels and wider), down */
/* to the IDE, with smaller controls when using a mouse. The */
/* Stop button sits beside Clear, above the Serial Monitor. A green */
/* Run LED beside Run blinks while the sketch runs. Knob, light */
/* sensor, buzzer, RGB LED, Sound box, and the Serial Plotter. */
/* Stamp: a red double circle around it, like a rubber stamp, and */
/* "Desktop Use, Under Development". Top to bottom: the board, then */
/* the IDE, up to 1200 pixels wide; a 60 column breadboard; scroll */
/* bars always shown; the stamp in a red double rectangle with round */
/* corners. Compact sizes (see COMPACT at the end). The components */
/* column runs beside the board and the IDE; one IDE toolbar; code */
/* left, Serial Monitor and Plotter right; the power supply. The */
/* Plotter is always shown at the top right; the editor grows down. */
/* 0.3.0: the multimeter buttons; the Examples menu with sub menus. */
/* 0.3.1: the Run LED flashes from unoMain.js; the editor, monitor, */
/* and plotter are fixed sizes with grips to make them taller. */
/* Designed: Jesse Carpenter and Claude (Anthropic) */
/* LICENSE: MIT */

/************************* MAIN *********************************/

/* Background: circular gradation of a light Uno board teal */
/* (#00878F family), white at the edges, as on the calculator page */
main {
  padding: 0;
  color: #1b1f3a;
  text-align: left;
  background: radial-gradient(rgb(160, 218, 222) 15%, white 70%);
}

/* The page uses the width it is given, up to 1200 pixels */
.unoPage {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1rem 1.5rem;
  position: relative;
}

/************************* BUG STAMP ****************************/

/* A stamp in the upper right corner, inside the main bars. Laid */
/* out like the logo: picture on the left, the two lines of words */
/* on the right with their right edges aligned. About the size of */
/* the logo (300px wide). The header logo itself is not changed. */
/* A red double rectangle with round corners, like a rubber stamp */
.bugStamp {
  float: right;
  width: 300px;
  margin: 1.4rem 1.4rem 2.4rem 1rem;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-sizing: border-box;
  border: 4px solid #b3261e;
  border-radius: 18px;
  outline: 2px solid #b3261e;
  outline-offset: 4px;
  transform: rotate(15deg);
}

.bugStamp img {
  width: auto;
  height: 100px;
  flex: none;
}

.stampText {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: Verdana, Geneva, sans-serif;
  font-weight: 700;
  line-height: 1.15;
}

/* Deep red gradient, like the blue gradient of the logo words */
/* The bottom padding keeps the tail of the g inside the clip */
.stampWord1,
.stampWord2 {
  padding: 0 0.04em 0.16em;
  margin-bottom: -0.16em;
  font-size: 2.05rem;
  background: linear-gradient(180deg, #e0463a 0%, #8e1410 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stampNote {
  margin-top: 3px;
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  color: #8e1410;
  text-align: right;
  line-height: 1.25;
}

/* Below the title and bar, everything starts under the stamp */
.hint,
.simArea {
  clear: both;
}

/************************* TITLE ********************************/

.unoTitle {
  margin: 0.25rem 0 0.4rem;
  text-align: left;
  font-size: 1.5rem;
  color: #1d167b;
}

.unoIntro {
  margin: 0 0 1rem;
  text-align: left;
  font-size: 0.95rem;
}

/************************* COMPONENTS BAR ***********************/

.componentsBar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(0, 135, 143, 0.4);
  border-radius: 10px;
  background: #ffffff;
}

.barLabel {
  font-weight: 700;
  color: #1d167b;
  margin-right: 4px;
}

.barSpacer {
  flex: 1;
}

.toolGroup {
  display: flex;
  align-items: center;
  gap: 4px;
}

button,
select {
  font: inherit;
  font-size: 0.9rem;
  touch-action: manipulation;
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 10px;
  border: 2px solid #3a79f7;
  border-radius: 8px;
  color: #1d167b;
  background: #eef3ff;
  cursor: pointer;
}

.tool svg {
  width: 28px;
  height: 18px;
}

.tool.plain.active {
  color: #ffffff;
  background: #b3261e;
  border-color: #b3261e;
}

.tool.active {
  color: #ffffff;
  background: #3a79f7;
}

.tool.plain,
.plain {
  border: 2px solid #888;
  border-radius: 8px;
  background: #f4f4f4;
  color: #333;
  cursor: pointer;
}

.small {
  min-height: 28px;
  padding: 2px 8px;
  font-size: 0.8rem;
}

select {
  min-height: 36px;
  border: 1px solid #999;
  border-radius: 6px;
  background: #ffffff;
}

.hint {
  margin: 6px 2px 8px;
  font-size: 0.85rem;
  color: #4a4f6a;
}

/************************* WORKSPACE ****************************/

/* Wide enough to tap the holes on a phone; scrolls sideways */
/* The board keeps a usable size; narrower, it scrolls sideways */
.workspace {
  overflow-x: scroll;
  border-radius: 10px;
  background: #f4fbfb;
  border: 1px solid rgba(0, 135, 143, 0.35);
}

#bench {
  display: block;
  width: 100%;
  min-width: 820px;
  height: auto;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#bench .hit {
  fill: transparent;
  cursor: pointer;
}

/* The visible hole sits on top; taps pass through to the target */
#bench .hole {
  pointer-events: none;
}

#bench .hit:hover + .hole,
#bench .hole.pick {
  fill: #3a79f7;
}

#bench .part {
  cursor: pointer;
}

.warnings {
  margin: 8px 0 0;
  padding-left: 1.2rem;
  color: #b3261e;
  font-size: 0.85rem;
}

/************************* IDE **********************************/

/* Laid out like the Arduino IDE: toolbar, sketch tab, editor with */
/* line numbers, and Output and Serial Monitor tabs at the bottom */
/* Overflow stays visible so the Examples menu can open over the */
/* code; the bar and the body round their own corners */
.ide {
  margin: 14px 0 0;
  border: 1px solid #0b5d61;
  border-radius: 10px;
  background: #1f2433;
}

.ideBar {
  border-radius: 9px 9px 0 0;
}

.ideBody {
  overflow: hidden;
  border-radius: 0 0 9px 9px;
}

.ideBar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #005c5f;
}

.ideBtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 4px 14px 4px 6px;
  border: none;
  border-radius: 20px;
  color: #ffffff;
  background: #00878f;
  font-weight: 700;
  cursor: pointer;
}

.ideBtn svg {
  width: 28px;
  height: 28px;
  padding: 3px;
  box-sizing: border-box;
  border-radius: 50%;
  background: #ffffff;
  fill: none;
  stroke: #00878f;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ideBtn svg .fill {
  fill: #00878f;
  stroke: none;
}

.ideBtn.run {
  background: #1e8e3e;
}

.ideBtn.run svg .fill {
  fill: #1e8e3e;
}

.ideBtn.stop {
  background: #b3261e;
}

.ideBtn.stop svg .fill {
  fill: #b3261e;
}

/* Stop beside Clear, above the Output and Serial Monitor */
.ideBtn.panelStop {
  min-height: 30px;
  margin-bottom: 4px;
  padding: 2px 10px 2px 4px;
  font-size: 0.8rem;
}

.ideBtn.panelStop svg {
  width: 22px;
  height: 22px;
}

.ideBtn:hover {
  filter: brightness(1.12);
}

.ideBtn:disabled {
  opacity: 0.45;
  cursor: default;
  filter: none;
}

/* Run LED: dark when stopped, blinks green while the sketch runs */
.runLed {
  width: 14px;
  height: 14px;
  margin: 0 4px;
  border-radius: 50%;
  background: #1d4d33;
  border: 2px solid #0a2a1a;
}

/* Lit while running; unoMain.js adds "dim" every other half second */
/* so it flashes, unlike the steady ON (power) LED on the Uno */
.runLed.on {
  background: #3ddc6b;
  box-shadow: 0 0 8px 2px #3ddc6b;
}

.runLed.on.dim {
  background: #1d4d33;
  box-shadow: none;
}

.ideState {
  margin-left: auto;
  color: #d8f3f4;
  font-size: 0.85rem;
}

.ideState b {
  color: #ffffff;
}

.ideBar select,
.fileBtn {
  min-height: 34px;
  border: 1px solid #7fc4c8;
  border-radius: 6px;
  color: #ffffff;
  background: #0b5d61;
  font-size: 0.85rem;
  cursor: pointer;
}

.ideBar select {
  width: 160px;
  padding: 0 6px;
}

.fileBtn {
  padding: 2px 9px;
}

.fileBtn.small {
  min-height: 28px;
  margin-bottom: 4px;
  padding: 0 10px;
}

.wireIt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #d8f3f4;
  font-size: 0.85rem;
  cursor: pointer;
}

.wireIt input {
  width: 20px;
  height: 20px;
}

.ideTab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: #2a3042;
  color: #ffffff;
  font-family: Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.changed {
  color: #ffcf6e;
  font-family: system-ui, sans-serif;
  font-size: 0.75rem;
}

.editor {
  display: flex;
  background: #1f2433;
}

/* The extra bottom padding lets the numbers scroll as far as the code, */
/* whose horizontal scroll bar takes room at the bottom */
.gutter {
  flex: none;
  min-width: 2.6em;
  margin: 0;
  padding: 10px 8px 40px 4px;
  overflow: hidden;
  text-align: right;
  color: #6d7590;
  background: #191d29;
  font-family: Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.4;
  user-select: none;
}

.gutter .errLine {
  color: #ffffff;
  background: #b3261e;
  border-radius: 3px;
  padding: 0 2px;
}

#code {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 10px;
  border: none;
  outline: none;
  resize: none;
  overflow: scroll;
  white-space: pre;
  font-family: Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.4;
  color: #e8ecff;
  background: #1f2433;
  tab-size: 2;
}

.panelTabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 0;
  background: #2a3042;
}

.ptab {
  white-space: nowrap;
  min-height: 34px;
  padding: 4px 14px;
  border: none;
  border-radius: 6px 6px 0 0;
  color: #b9c0d6;
  background: transparent;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.ptab.active {
  color: #ffffff;
  background: #10141f;
}

.panel {
  height: 150px;
  overflow-y: auto;
  margin: 0;
  padding: 8px 12px;
  font-family: Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.4;
  color: #cfd6ea;
  background: #10141f;
}

.panel.serial {
  color: #9fffa8;
  white-space: pre-wrap;
}

.panel .err {
  color: #ff8a80;
}

/* Keyboard users see where they are (WCAG 2.4.7 and 2.4.11) */
button:focus-visible,
select:focus-visible,
input:focus-visible,
#code:focus-visible,
.usbJack:focus-visible,
.resetBtn:focus-visible {
  outline: 3px solid #ffb000;
  outline-offset: 2px;
}

/* Touch screens: controls at least 44 by 44 pixels (WCAG 2.5.5) */
@media (pointer: coarse) {
  .tool,
  select,
  .fileBtn,
  .ptab,
  .ideBtn {
    min-height: 44px;
  }
}

/* The USB jack and reset button are buttons on the board */
#bench .usbJack,
#bench .resetBtn {
  cursor: pointer;
}

/************************* MORE COMPONENTS **********************/

.soundBox {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  color: #1d167b;
  cursor: pointer;
}

/* Knob and light sensor: drag to change them */
#bench .part.adjust {
  cursor: ew-resize;
}

/* Buzzer rings pulse while it plays a note */
#bench .buzzRings {
  animation: buzzPulse 0.5s ease-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes buzzPulse {
  from {
    opacity: 1;
    transform: scale(0.8);
  }
  to {
    opacity: 0;
    transform: scale(1.3);
  }
}

@media (prefers-reduced-motion: reduce) {
  #bench .buzzRings {
    animation: none;
  }
}

/************************* SERIAL PLOTTER ***********************/

.plotter {
  border-top: 2px solid #2a3042;
  background: #10141f;
}

.plotHead {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 6px 10px 2px;
  color: #e8ecff;
  font-size: 0.85rem;
}

.plotTitle {
  font-weight: 700;
}

.plotLegend {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 12px;
}

.plotKey {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.plotKey i {
  display: inline-block;
  width: 14px;
  height: 4px;
  border-radius: 2px;
}

#plotCanvas {
  display: block;
  width: 100%;
  height: 240px;
}

/************************* SCROLL BARS **************************/

/* Scroll bars always shown, so a narrow window shows that the page */
/* and the board scroll (Chrome, Edge, and Safari) */
html {
  overflow-y: scroll;
}

::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: #e3eeef;
}

::-webkit-scrollbar-thumb {
  border: 2px solid #e3eeef;
  border-radius: 6px;
  background: #7aa9ad;
}

.ide ::-webkit-scrollbar-track {
  background: #1f2433;
}

.ide ::-webkit-scrollbar-thumb {
  border-color: #1f2433;
  background: #4d5873;
}

/************************* WIDE SCREENS *************************/

/* The components bar becomes a column at the left of the board, */
/* and stays in view while the board scrolls */
@media screen and (min-width: 760px) {
  .simArea {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    gap: 8px;
    align-items: stretch;
  }

  /* The column runs down beside the board and the IDE */
  .componentsBar {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
  }

  .toolGroup {
    flex-direction: column;
    align-items: stretch;
  }

  .componentsBar .tool {
    justify-content: flex-start;
  }

  .barLabel {
    margin: 0 0 2px;
  }

  .componentsBar .barSpacer {
    flex: none;
    height: 6px;
  }
}

/* With a mouse, smaller controls leave room for more components; */
/* touch screens keep the 44 pixel targets */
@media screen and (min-width: 760px) and (pointer: fine) {
  .componentsBar .tool,
  .componentsBar select {
    min-height: 28px;
    padding-top: 2px;
    padding-bottom: 2px;
    font-size: 0.85rem;
  }

  .componentsBar .tool svg {
    height: 14px;
  }
}

/************************* NOTES ********************************/

.about {
  margin: 14px 0 0;
  font-size: 0.88rem;
}

.about summary {
  cursor: pointer;
  font-weight: 700;
  color: #1d167b;
}

.credit,
.trademark {
  margin: 10px 0 0;
  text-align: center;
  font-size: 0.8rem;
  color: #4a4f6a;
}

/************************* PHONES *******************************/

@media screen and (max-width: 420px) {
  .bugStamp {
    float: none;
    width: 240px;
    margin: 1.6rem 0.5rem 1.6rem auto;
  }

  .bugStamp img {
    height: 80px;
  }

  .stampWord1,
  .stampWord2 {
    font-size: 1.6rem;
  }

  .stampNote {
    font-size: 0.5rem;
  }

  .unoTitle {
    font-size: 1.25rem;
  }
}

/************************* COMPACT ******************************/

/* Smaller stamp, title, bars, and panels so more fits on a screen */
/* The tilted corners reach past the box; the bottom margin keeps */
/* them clear of the board */
.bugStamp {
  width: 230px;
  margin: 0.6rem 1rem 2.2rem 1rem;
  padding: 6px 10px;
  border-width: 3px;
  border-radius: 14px;
  outline-offset: 3px;
}

.bugStamp img {
  height: 70px;
}

.stampWord1,
.stampWord2 {
  font-size: 1.5rem;
}

.stampNote {
  font-size: 0.5rem;
}

.unoTitle {
  margin: 0.2rem 0 0.2rem;
  font-size: 1.35rem;
}

.unoIntro {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
}

.hint {
  margin: 4px 2px 6px;
}

.componentsBar {
  gap: 5px;
  padding: 6px;
}

.ide {
  margin-top: 10px;
}

.ideBar {
  padding-top: 5px;
  padding-bottom: 5px;
}

.ideBtn {
  min-height: 34px;
}

.ideBtn svg {
  width: 24px;
  height: 24px;
}

/* Fixed at 400 pixels; the code scrolls (scroll bar or mouse wheel). */
/* The grip in the lower right corner makes it taller or shorter. */
.editor {
  height: 400px;
  min-height: 200px;
  resize: vertical;
  overflow: hidden;
}

.panel {
  height: 110px;
}

#plotCanvas {
  height: 170px;
}

@media screen and (min-width: 760px) {
  .componentsBar .tool {
    white-space: nowrap;
  }
}

/* The hint sits at the bottom of the components column */
.componentsBar .hint {
  margin: 8px 0 0;
  font-size: 0.75rem;
  line-height: 1.35;
}

.ide {
  margin-top: 8px;
}

/************************* IDE: CODE LEFT, MONITOR RIGHT ********/

/* The code on the left (80 character lines); Output, the Serial */
/* Monitor, and the Plotter stacked on the right */
.ideBody {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
}

.ideRight {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 2px solid #2a3042;
  background: #10141f;
}

.ideRight .panelTabs {
  flex: none;
}

/* Output and Serial Monitor: fixed, with a grip to make them taller */
.ideRight .panel {
  flex: none;
  height: 200px;
  min-height: 100px;
  resize: vertical;
  overflow-y: scroll;
}

/* Serial Plotter: fixed, with a grip; the graph fills it */
.ideRight .plotter {
  flex: none;
  display: flex;
  flex-direction: column;
  height: 205px;
  min-height: 135px;
  resize: vertical;
  overflow: hidden;
}

.ideRight .plotter #plotCanvas {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
}

/* The code and the monitor column keep their own heights */
.ideBody {
  align-items: start;
}

/* Windows under 1200 pixels: the plotter and monitor below the code, */
/* so their buttons are not cut off */
@media screen and (max-width: 1199px) {
  .ideBody {
    grid-template-columns: minmax(0, 1fr);
  }

  .ideRight .panel {
    height: 160px;
  }

  .editor {
    height: 300px;
  }
}

/************************* POWER SUPPLY *************************/

#bench .busBtn {
  cursor: pointer;
}

#bench .busBtn:hover rect {
  stroke: #ffb000;
  stroke-width: 2;
}

#bench .meterBtn {
  cursor: pointer;
}

#bench .meterBtn:focus-visible,
#bench .busBtn:focus-visible {
  outline: 3px solid #ffb000;
}

/************************* EXAMPLES MENU ************************/

.menuWrap {
  position: relative;
  display: inline-block;
}

.menuBtn {
  min-width: 120px;
  text-align: left;
}

/* The menu and each sub menu: a list of white buttons */
.exampleMenu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
}

.menuList {
  margin: 0;
  padding: 4px 0;
  list-style: none;
  min-width: 200px;
  border: 1px solid #0b5d61;
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

.menuList li {
  position: relative;
}

.menuList button {
  display: block;
  width: 100%;
  padding: 5px 14px;
  border: none;
  background: transparent;
  color: #1b1f3a;
  font-size: 0.85rem;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}

.menuList button:hover,
.menuList button:focus-visible {
  background: #e3f2f3;
  outline: none;
}

/* A sub menu opens to the right of its group, on hover or focus */
.hasSub > button::after {
  content: "\25B8";
  float: right;
  margin-left: 12px;
  color: #00878f;
}

.hasSub > .menuList {
  display: none;
  position: absolute;
  top: -5px;
  left: 100%;
}

.hasSub:hover > .menuList,
.hasSub:focus-within > .menuList {
  display: block;
}
