/* RetroLCD Arcade - single dark "workbench" look, chosen deliberately:
   the OLED needs a dark surround to read like the real module. */
:root {
  color-scheme: dark;
  --bench: #0d1014;
  --bench-2: #151a21;
  --line: #262e39;
  --pcb: #1c4f8c;        /* blue solder mask of the common SSD1306 modules */
  --pcb-edge: #143b69;
  --silk: #e8ecf1;       /* silkscreen */
  --gold: #d6a84e;       /* header pins / accent */
  --gold-dim: #8a6d33;
  --text: #dfe4ea;
  --muted: #8b95a3;
  --danger: #ff8a7a;
  --radius: 10px;
  --display: 'Chakra Petch', 'Segoe UI', system-ui, sans-serif;
  --body: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bench);
  color: var(--text);
  font: 15px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: 16px 32px;
  display: grid;
  gap: 20px;
  grid-template-columns: 220px minmax(0, 1fr) 300px;
  grid-template-areas:
    "top top top"
    "list stage side";
  align-items: start;
}

/* ---------------------------------------------------------------- header */
.top {
  grid-area: top;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
  margin: 0;
  text-wrap: balance;
}
.brand span { color: var(--gold); }
.tagline { margin: 0; color: var(--muted); font-size: 0.9rem; }

/* ----------------------------------------------------------- sketch list */
.list { grid-area: list; display: grid; gap: 18px; }
.group h2 {
  margin: 0 0 6px;
  font: 600 0.72rem/1 var(--body);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.group ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sketch-btn {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  color: var(--text);
  font: 500 0.95rem/1.3 var(--body);
  text-align: left;
  cursor: pointer;
}
.sketch-btn small { color: var(--muted); font: 0.7rem var(--mono); }
.sketch-btn:hover { background: var(--bench-2); }
.sketch-btn[aria-current="true"] {
  background: var(--bench-2);
  border-color: var(--gold-dim);
  color: var(--silk);
}
.sketch-btn[aria-current="true"] small { color: var(--gold); }
.sketch-btn:focus-visible, .ctl:focus-visible, .tool:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* --------------------------------------------------------------- stage */
.stage { grid-area: stage; display: grid; gap: 14px; justify-items: center; min-width: 0; }
.stage-box { width: 100%; min-width: 0; display: flex; justify-content: center; overflow: hidden; padding-bottom: 24px; margin-bottom: -24px; }

/* The OLED breakout board */
.module {
  position: relative;
  background: var(--pcb);
  border: 1px solid var(--pcb-edge);
  border-radius: 12px;
  padding: 34px 18px 20px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08) inset, 0 18px 40px rgba(0, 0, 0, 0.45);
  max-width: 100%;
}
.module::before, .module::after { /* mounting holes */
  content: '';
  position: absolute;
  top: 9px;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--bench);
  box-shadow: 0 0 0 3px #c9ccd1;
}
.module::before { left: 10px; }
.module::after { right: 10px; }
.header-pins {
  position: absolute;
  top: 6px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
}
.pin { display: grid; justify-items: center; gap: 2px; }
.pin i {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 2px var(--pcb-edge);
}
.pin b { font: 600 8px/1 var(--mono); color: var(--silk); letter-spacing: 0.04em; }
.glass {
  background: #000;
  padding: 6px;
  border-radius: 3px;
  border: 1px solid #000;
  box-shadow: 0 0 0 4px #0b0d10;
  line-height: 0;
}
#screen { display: block; width: 256px; height: 128px; image-rendering: pixelated; touch-action: none; }
.silk {
  margin: 10px 0 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font: 600 10px/1 var(--mono);
  color: var(--silk);
  letter-spacing: 0.08em;
  opacity: 0.85;
}

.lcd-panel {
  background: #3b4a2a;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #1f2717;
  line-height: 0;
  max-width: 100%;
}
.lcd-panel canvas { max-width: 100%; height: auto; image-rendering: pixelated; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bench-2);
  color: var(--text);
  font: 500 0.85rem var(--body);
  cursor: pointer;
}
.tool:hover { border-color: var(--gold-dim); }
.tool[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); }

.status {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 18px;
  font: 0.78rem var(--mono);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.status b { color: var(--text); font-weight: 500; }

.error {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--danger);
  border-radius: 8px;
  color: var(--danger);
  font: 0.85rem var(--mono);
  white-space: pre-wrap;
}

.serial {
  width: 100%;
  margin: 0;
  height: 240px;
  overflow: auto;
  padding: 10px 12px;
  background: #07090b;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: 0.8rem/1.45 var(--mono);
  color: #cfe3d4;
  white-space: pre-wrap;
}

/* ---------------------------------------------------------------- side */
.side { grid-area: side; display: grid; gap: 18px; }
.info h2 {
  margin: 0;
  font: 600 1.35rem/1.2 var(--display);
  color: var(--silk);
  text-wrap: balance;
}
.info .src { margin: 4px 0 8px; font: 0.75rem var(--mono); color: var(--gold); overflow-wrap: anywhere; }
.info p { margin: 0; color: var(--text); max-width: 60ch; }
.info .hint { margin-top: 8px; color: var(--muted); font-size: 0.88rem; }

.controls h3 {
  margin: 0 0 8px;
  font: 600 0.72rem/1 var(--body);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.ctl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ctl {
  display: grid;
  gap: 4px;
  align-content: start;
  padding: 8px 10px;
  min-height: 52px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bench-2);
  color: var(--text);
  font: 500 0.82rem/1.25 var(--body);
  text-align: left;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.ctl.held { border-color: var(--gold); background: #231d10; }
.keys { display: flex; flex-wrap: wrap; gap: 3px; }
kbd {
  font: 600 0.68rem/1 var(--mono);
  padding: 3px 5px;
  border-radius: 4px;
  border: 1px solid #3a4452;
  border-bottom-width: 2px;
  color: var(--silk);
  background: #0f1318;
}
.no-controls { margin: 0; color: var(--muted); font-size: 0.88rem; }

.about {
  font-size: 0.82rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.about p { margin: 0 0 6px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1060px) {
  .app {
    grid-template-columns: 200px minmax(0, 1fr);
    grid-template-areas:
      "top top"
      "list stage"
      "list side";
  }
}
@media (max-width: 720px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "top" "stage" "side" "list";
  }
  .list { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .module { padding: 30px 10px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
