/* Arduino Lab — /arduino/lab. Self-contained: every rule is under .alab-page. */

.alab-page {
  --alab-bg: #f6f3ee;
  --alab-card: #fffdf9;
  --alab-ink: #1f2328;
  --alab-mute: #6b7078;
  --alab-line: #e3ddd2;
  --alab-accent: #4f46e5;
  --alab-accent-soft: #eef0ff;
  --alab-ok: #059669;
  --alab-bad: #dc2626;
  --alab-warn: #b45309;
  --alab-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--alab-bg);
  color: var(--alab-ink);
  padding: 28px 16px 48px;
  min-height: 100vh;
}

.alab-head {
  max-width: 1500px;
  margin: 0 auto 18px;
}
.alab-kicker {
  font: 600 12px/1 var(--alab-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--alab-mute);
  margin: 0 0 8px;
}
.alab-head h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.1;
  margin: 0 0 8px;
}
.alab-head p {
  max-width: 760px;
  color: var(--alab-mute);
  margin: 0;
  font-size: 16px;
}

/* ---------------------------------------------------------------- shell */

.alab {
  max-width: 1500px;
  margin: 0 auto;
  background: var(--alab-card);
  border: 1px solid var(--alab-line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(40, 30, 10, 0.07);
  display: flex;
  flex-direction: column;
  height: min(860px, calc(100vh - 40px));
  min-height: 560px;
}
.alab:fullscreen {
  max-width: none;
  height: 100vh;
  border-radius: 0;
}

.alab-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--alab-line);
  flex-wrap: wrap;
}
.alab-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}
.alab-title b {
  font-size: 18px;
}
.alab-title span {
  font: 12px var(--alab-mono);
  color: var(--alab-mute);
}
.alab-spacer {
  flex: 1;
}

.alab-btn {
  font: 600 13px/1 inherit;
  font-family: inherit;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--alab-line);
  background: #fff;
  color: var(--alab-ink);
  cursor: pointer;
  white-space: nowrap;
}
.alab-btn:hover:not(:disabled) {
  border-color: #c9c1b2;
}
.alab-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.alab-btn.on {
  background: var(--alab-accent-soft);
  border-color: #c7cbff;
  color: var(--alab-accent);
}
.alab-btn.small {
  padding: 6px 10px;
  font-size: 12px;
}
.alab-run {
  background: #16181d;
  color: #fff;
  border-color: #16181d;
  padding: 8px 18px;
}
.alab-run:hover:not(:disabled) {
  background: #000;
}
.alab-run.stop {
  background: var(--alab-bad);
  border-color: var(--alab-bad);
}

.alab-seg {
  display: inline-flex;
  border: 1px solid var(--alab-line);
  border-radius: 999px;
  overflow: hidden;
}
.alab-seg button {
  font: 600 12px/1 inherit;
  font-family: inherit;
  padding: 8px 10px;
  border: 0;
  background: #fff;
  cursor: pointer;
  color: var(--alab-ink);
}
.alab-seg button.on {
  background: var(--alab-accent-soft);
  color: var(--alab-accent);
}

.alab-missionpick {
  position: relative;
}
.alab-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  background: #fff;
  border: 1px solid var(--alab-line);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
  padding: 6px;
  width: 260px;
}
.alab-menu button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  color: var(--alab-ink);
}
.alab-menu button:hover,
.alab-menu button.on {
  background: var(--alab-accent-soft);
}
.alab-menu span {
  font: 11px var(--alab-mono);
  color: var(--alab-mute);
}

/* ---------------------------------------------------------------- three columns */

.alab-body {
  flex: 1;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 360px;
  min-height: 0;
}

.alab-shelf {
  border-right: 1px solid var(--alab-line);
  overflow-y: auto;
  padding: 8px;
}
.alab-shelf h3 {
  font: 600 11px/1 var(--alab-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--alab-mute);
  margin: 14px 6px 6px;
}
.alab-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: none;
  padding: 7px 8px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  color: var(--alab-ink);
}
.alab-item:hover {
  background: #f3efe7;
}
.alab-item.on {
  background: var(--alab-accent-soft);
  border-color: #c7cbff;
}
.alab-item i {
  flex: none;
  width: 26px;
  height: 18px;
  border-radius: 3px;
  margin-top: 2px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.alab-item b {
  display: block;
  font-size: 13px;
  line-height: 1.2;
}
.alab-item small {
  display: block;
  font-size: 11px;
  color: var(--alab-mute);
  line-height: 1.3;
}
.alab-item .dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  margin-left: 4px;
  margin-right: 4px;
  background: #94a3b8;
}
.dot-led { background: #ef4444 !important; }
.dot-led-green { background: #22c55e !important; }
.dot-led-yellow { background: #facc15 !important; }
.dot-rgb { background: conic-gradient(#ef4444, #22c55e, #3b82f6, #ef4444) !important; }
.dot-buzzer { background: #111 !important; }
.dot-button { background: #dc2626 !important; border: 3px solid #222; box-sizing: border-box; }
.dot-pot { background: #e5e7eb !important; border: 3px solid #1e40af; box-sizing: border-box; }
.dot-ldr { background: #d97706 !important; }
.dot-hcsr04 { background: #1d4ed8 !important; border-radius: 4px !important; }
.dot-servo { background: #2563eb !important; border-radius: 3px !important; }
/* Breadboard kit */
.dot-breadboard { background: repeating-linear-gradient(90deg, #f3efe6 0 3px, #8b8270 3px 4px) !important; border: 2px solid #c9c0ae; border-radius: 3px !important; box-sizing: border-box; }
.dot-bb-led-red { background: #ef4444 !important; }
.dot-bb-led-green { background: #22c55e !important; }
.dot-bb-led-yellow { background: #facc15 !important; }
.dot-bb-led-blue { background: #3b82f6 !important; }
.dot-bb-led-white { background: #f8fafc !important; border: 1px solid #94a3b8; box-sizing: border-box; }
.dot-bb-rgb { background: conic-gradient(#ef4444, #22c55e, #3b82f6, #ef4444) !important; }
.dot-resistor { background: linear-gradient(90deg, #e3cfa3 0 20%, #d62828 20% 32%, #e3cfa3 32% 40%, #d62828 40% 52%, #e3cfa3 52% 60%, #7c3f12 60% 72%, #e3cfa3 72% 82%, #c9a227 82% 92%, #e3cfa3 92%) !important; border-radius: 6px !important; }
.dot-bb-button { background: #262626 !important; border: 3px solid #9ca3af; border-radius: 3px !important; box-sizing: border-box; }
.dot-piezo { background: #141414 !important; }
.dot-photoresistor { background: #c2410c !important; }
.dot-bb-pot { background: #1f2937 !important; border: 3px solid #1d4ed8; box-sizing: border-box; }
.dot-tilt { background: #2b2b2b !important; border: 3px solid #d1d5db; box-sizing: border-box; }
.dot-tmp36 { background: #1a1a1a !important; border-radius: 50% 50% 2px 2px !important; }

/* ---------------------------------------------------------------- the bench */

.alab-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #29333b;
}
.alab-canvas {
  position: absolute;
  inset: 0;
}
.alab-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #cbd5e1;
  font: 14px var(--alab-mono);
}
.alab-hint {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.78);
  color: #e2e8f0;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100% - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.alab-tip {
  position: absolute;
  pointer-events: none;
  background: #fff;
  color: #111;
  font: 600 12px var(--alab-mono);
  padding: 5px 8px;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  z-index: 5;
}
.alab-selected {
  position: absolute;
  top: 46px;
  left: 10px;
  display: flex;
  gap: 6px;
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  padding: 6px 8px;
  border-radius: 10px;
  font-size: 12px;
}
.alab-selected button {
  font: 600 11px inherit;
  font-family: inherit;
  border: 1px solid var(--alab-line);
  background: #fff;
  border-radius: 999px;
  padding: 4px 8px;
  cursor: pointer;
}
.alab-problems {
  position: absolute;
  bottom: 10px;
  right: 10px;
  max-width: min(340px, 42%);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.alab-problems p {
  margin: 0;
  background: rgba(255, 255, 255, 0.96);
  border-left: 4px solid var(--alab-warn);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  line-height: 1.35;
}
.alab-problems p.error {
  border-left-color: var(--alab-bad);
}
.alab-controls {
  position: absolute;
  left: 10px;
  max-width: 56%;
  bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.alab-hold {
  font: 700 13px inherit;
  font-family: inherit;
  padding: 10px 14px;
  border-radius: 10px;
  border: 0;
  background: #fff;
  cursor: pointer;
  user-select: none;
  touch-action: none;
}
.alab-hold.on {
  background: #fde68a;
}
.alab-slider {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.95);
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
}
.alab-slider small {
  color: var(--alab-mute);
}
.alab-slider input {
  width: 130px;
}
.alab-slider output {
  font: 600 12px var(--alab-mono);
  min-width: 48px;
  text-align: right;
}
.alab-clock {
  position: absolute;
  top: 10px;
  left: 10px;
  font: 600 11px var(--alab-mono);
  color: #a7f3d0;
  background: rgba(15, 23, 42, 0.7);
  padding: 5px 8px;
  border-radius: 6px;
}

/* ---------------------------------------------------------------- right panel */

.alab-panel {
  border-left: 1px solid var(--alab-line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.alab-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 10px 0;
  border-bottom: 1px solid var(--alab-line);
}
.alab-tabs button {
  font: 600 13px inherit;
  font-family: inherit;
  padding: 8px 12px;
  border: 0;
  background: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  color: var(--alab-mute);
}
.alab-tabs button.on {
  color: var(--alab-ink);
  border-bottom-color: var(--alab-ink);
}
.alab-tabs em {
  font-style: normal;
  margin-left: 4px;
  color: var(--alab-accent);
}
.alab-tabs em.bad {
  color: var(--alab-bad);
}

.alab-steps {
  overflow-y: auto;
  padding: 14px 16px 20px;
  font-size: 14px;
  line-height: 1.5;
}
.alab-steps h2 {
  font-size: 20px;
  margin: 0 0 6px;
}
.alab-steps h4 {
  font: 600 11px/1 var(--alab-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--alab-mute);
  margin: 16px 0 8px;
}
.alab-steps ol,
.alab-tips {
  padding-left: 20px;
  margin: 0;
}
.alab-steps li {
  margin-bottom: 6px;
}
.alab-goals {
  list-style: none;
  padding: 0;
  margin: 0;
}
.alab-goals li {
  position: relative;
  padding: 5px 0 5px 28px;
}
.alab-goals li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 7px;
  width: 16px;
  height: 16px;
  border: 2px solid #cbd5e1;
  border-radius: 50%;
  box-sizing: border-box;
}
.alab-goals li.done {
  color: var(--alab-ok);
}
.alab-goals li.done::before {
  background: var(--alab-ok);
  border-color: var(--alab-ok);
}
.alab-goals li.done::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 10px;
  width: 4px;
  height: 7px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.alab-win {
  margin-top: 10px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 600;
}
.alab-hintcard {
  background: #fffbeb;
  border: 1px solid #fde68a;
  padding: 8px 10px;
  border-radius: 8px;
  margin: 0 0 8px;
}
.alab-muted {
  color: var(--alab-mute);
  font-size: 13px;
}
.alab-muted a {
  color: var(--alab-accent);
}

.alab-code {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 10px;
  gap: 8px;
}
.alab-compile {
  margin: 0;
  font-size: 13px;
  color: var(--alab-ok);
}
.alab-compile.bad {
  color: var(--alab-bad);
}
.alab-errors {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 140px;
  overflow-y: auto;
  font: 12px/1.4 var(--alab-mono);
}
.alab-errors li {
  padding: 5px 8px;
  border-radius: 6px;
  background: #fef2f2;
  color: #991b1b;
  margin-bottom: 4px;
}
.alab-errors li.warning {
  background: #fffbeb;
  color: #92400e;
}
.alab-editor {
  flex: 1;
  min-height: 0;
  display: flex;
  border: 1px solid #2b2f36;
  border-radius: 10px;
  overflow: hidden;
  background: #1b1e24;
}
.alab-gutter {
  flex: none;
  width: 40px;
  overflow: hidden;
  padding: 10px 0;
  background: #15171c;
  color: #5c6370;
  font: 13px/20px var(--alab-mono);
  text-align: right;
}
.alab-gutter div {
  padding-right: 8px;
}
.alab-gutter div.bad {
  background: #7f1d1d;
  color: #fff;
}
.alab-editor textarea {
  flex: 1;
  border: 0;
  outline: 0;
  resize: none;
  padding: 10px 12px;
  background: transparent;
  color: #e6e6e6;
  font: 13px/20px var(--alab-mono);
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}
.alab-coderow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.alab-serial {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 10px;
  gap: 8px;
}
.alab-serial pre {
  flex: 1;
  margin: 0;
  overflow: auto;
  background: #0f1115;
  color: #a7f3d0;
  font: 13px/1.45 var(--alab-mono);
  padding: 10px 12px;
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}
.alab-serial form {
  display: flex;
  gap: 6px;
}
.alab-serial input {
  flex: 1;
  min-width: 0;
  font: 13px var(--alab-mono);
  padding: 7px 10px;
  border: 1px solid var(--alab-line);
  border-radius: 8px;
}

/* ---------------------------------------------------------------- narrow screens */

@media (max-width: 1100px) {
  .alab-body {
    grid-template-columns: 200px minmax(0, 1fr);
    grid-template-rows: minmax(380px, 1fr) 420px;
  }
  .alab-panel {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--alab-line);
  }
  .alab {
    height: auto;
  }
}
@media (max-width: 700px) {
  .alab-body {
    grid-template-columns: 1fr;
    grid-template-rows: 380px auto 420px;
  }
  .alab-shelf {
    grid-row: 2;
    border-right: 0;
    border-top: 1px solid var(--alab-line);
    max-height: 260px;
  }
  .alab-stage {
    grid-row: 1;
  }
  .alab-panel {
    grid-row: 3;
  }
}
