/* OpenMindstorms Workbench styles - shared by the RCX and NXT apps */
/* Layout: a bench. Top strip = brick vitals, left rail = workstations, main = the bench surface.
   Colour: cool slate neutrals so the RCX yellow and the grey-green LCD read as the only warm things. */
:root {
  --bg: #e9ecf0;          /* bench */
  --surface: #ffffff;     /* panels */
  --surface-2: #f4f6f8;   /* inset wells */
  --ink: #18212b;
  --muted: #5e6b7a;
  --line: #cfd6de;
  --accent: #f5b800;      /* RCX yellow */
  --accent-ink: #2b2000;
  --accent-soft: #fff1bf;
  --lcd: #c8d2b6;         /* RCX LCD glass */
  --lcd-ink: #1f2a1a;
  --good: #1f8a4c;
  --warn: #c7760a;
  --bad: #c0392b;
  --focus: #1d6fd1;
  --display: "Chakra Petch", "Segoe UI", system-ui, sans-serif;
  --body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", Consolas, "Courier New", monospace;
  --radius: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161b; --surface: #1b2129; --surface-2: #232b35; --ink: #e5e9ee; --muted: #98a4b2;
    --line: #313b47; --accent: #f5b800; --accent-ink: #2b2000; --accent-soft: #3d3300;
    --lcd: #2a3324; --lcd-ink: #cfe3b8; --good: #3ccf7a; --warn: #f2a93b; --bad: #ff6b5b; --focus: #6aa7ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161b; --surface: #1b2129; --surface-2: #232b35; --ink: #e5e9ee; --muted: #98a4b2;
  --line: #313b47; --accent: #f5b800; --accent-ink: #2b2000; --accent-soft: #3d3300;
  --lcd: #2a3324; --lcd-ink: #cfe3b8; --good: #3ccf7a; --warn: #f2a93b; --bad: #ff6b5b; --focus: #6aa7ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--body); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--display); margin: 0; text-wrap: balance; letter-spacing: .01em; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
code, .mono { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.app { display: grid; grid-template-rows: auto 1fr; height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 700; font-size: 18px; }
.brand .brick { width: 26px; height: 18px; background: var(--accent); border-radius: 3px; position: relative; box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.brand .brick::after { content: ""; position: absolute; left: 6px; top: 4px; width: 14px; height: 7px; background: var(--lcd); border-radius: 1px; }
.vitals { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-left: auto; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.on .dot { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
.pill.err .dot { background: var(--bad); }
.pill.busy .dot { background: var(--accent); animation: blink .6s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .pill.busy .dot { animation: none; } }

.shell { display: grid; grid-template-columns: 200px 1fr; min-height: 0; }
.rail { background: var(--surface); border-right: 1px solid var(--line); padding-block: 12px; padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: 12px; display: flex; flex-direction: column; gap: 4px; }
.rail button { text-align: left; background: none; border: 0; padding: 9px 12px; border-radius: var(--radius); font-family: var(--display); font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.rail button:hover { background: var(--surface-2); color: var(--ink); }
.rail button.active { background: var(--accent); color: var(--accent-ink); }
.rail button .k { font: 11px var(--mono); opacity: .55; }
.rail .spacer { flex: 1; }
.rail .foot { font-size: 11.5px; color: var(--muted); padding: 8px 12px; line-height: 1.4; }
.main { overflow: auto; padding-block: 18px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.view { display: none; max-width: 1100px; }
.view.active { display: block; }
.view.wide { max-width: none; }   /* the Program section uses the whole width */
.view > header { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.view > header p { margin: 0; color: var(--muted); }

.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.panel > h3 { margin-bottom: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
/* A row holding labelled fields: line buttons up with the inputs, under the labels. */
.row:has(> label.f) { align-items: flex-end; }
.row.tight { gap: 6px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); min-width: 0; }
label.f > span { text-transform: uppercase; letter-spacing: .06em; font-size: 11px; }
input[type=text], input[type=number], select, textarea {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; color: var(--ink); min-width: 0;
}
input[type=number] { width: 7em; font-variant-numeric: tabular-nums; }
select { padding-right: 24px; }
.btn { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 12px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-family: var(--display); font-weight: 700; letter-spacing: .02em; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.run { background: var(--good); color: #fff; border-color: transparent; }
.btn.stop { background: var(--bad); color: #fff; border-color: transparent; }
.btn.icon { width: 36px; padding: 7px 0; text-align: center; font-family: var(--mono); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; min-width: 0; margin: 0; }
legend { font-family: var(--display); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 0 6px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; background: var(--surface-2); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 3px; }
.choice b { font-family: var(--display); }
.choice small { display: block; color: var(--muted); }
.choice.disabled { opacity: .5; cursor: not-allowed; }

.lcd { background: var(--lcd); color: var(--lcd-ink); font-family: var(--mono); border-radius: 4px; padding: 6px 10px; font-size: 22px; font-weight: 500; letter-spacing: .06em; font-variant-numeric: tabular-nums; text-align: right; box-shadow: inset 0 2px 6px rgba(0,0,0,.18); min-width: 6ch; }
.lcd small { font-size: 11px; letter-spacing: .1em; display: block; text-align: left; opacity: .7; font-family: var(--display); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; }

.progress { height: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }
.progress-text { font-family: var(--mono); font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin-left: auto; }
.seg button { background: var(--surface); border: 0; padding: 6px 14px; cursor: pointer; font-family: var(--display); font-weight: 600; color: var(--muted); }
.seg button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.blockly-host { height: max(420px, calc(100vh - 300px)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface-2); }
.gen { margin-top: 8px; }
.gen summary { cursor: pointer; font-family: var(--display); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.gen pre { margin-top: 6px; max-height: 260px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 12px; }
.api { display: grid; grid-template-rows: auto 1fr; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); height: max(360px, calc(100vh - 320px)); min-width: 0; overflow: hidden; }
.api-head { display: grid; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
.api-head input { width: 100%; }
.api-list { overflow: auto; font-size: 12.5px; }
.api-list h4 { margin: 0; padding: 8px 10px 4px; font-family: var(--display); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); position: sticky; top: 0; background: var(--surface); }
.api-list button { display: block; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid transparent; padding: 5px 10px; cursor: pointer; color: var(--ink); }
.api-list button:hover, .api-list button:focus-visible { background: var(--accent-soft); outline: none; }
.api-list button b { font-family: var(--mono); font-weight: 500; display: block; }
.api-list button span { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.35; }
.api-list .none { padding: 12px; color: var(--muted); }
.editor { display: grid; grid-template-columns: auto 1fr; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); overflow: hidden; height: max(360px, calc(100vh - 320px)); min-width: 0; }
.editor .gutter { font-family: var(--mono); font-size: 13px; line-height: 1.45; color: var(--muted); padding: 10px 8px; text-align: right; user-select: none; overflow: hidden; border-right: 1px solid var(--line); white-space: pre; }
.editor .gutter .err { color: var(--bad); font-weight: 600; }
.editor textarea { border: 0; border-radius: 0; resize: none; font-family: var(--mono); font-size: 13px; line-height: 1.45; padding: 10px; white-space: pre; overflow: auto; tab-size: 4; background: transparent; }
.editor textarea:focus { outline: none; }
.out { font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; max-height: 180px; overflow: auto; margin: 0; }
.out .e { color: var(--bad); } .out .ok { color: var(--good); }

.motor { display: grid; gap: 8px; }
.motor .name { font-family: var(--display); font-size: 26px; font-weight: 700; line-height: 1; }
.motor input[type=range] { width: 100%; accent-color: var(--accent); }
.motor .state { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.sensor { display: grid; gap: 8px; }
.sounds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
th { font-family: var(--display); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.tablewrap { overflow-x: auto; max-height: 420px; overflow-y: auto; }

.console { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; height: 360px; overflow: auto; white-space: pre; }
.console .tx { color: var(--focus); } .console .rx { color: var(--good); } .console .note { color: var(--muted); } .console .err { color: var(--bad); }

.banner { padding: 10px 12px; border-radius: var(--radius); border: 1px solid; margin-bottom: 14px; }
.banner.warn { background: color-mix(in srgb, var(--warn) 12%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.banner.bad { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
.toasts { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; z-index: 20; max-width: min(420px, 90vw); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 13.5px; }
.toast.bad { background: var(--bad); color: #fff; } .toast.good { background: var(--good); color: #fff; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.help { margin-top: 10px; font-size: 12.5px; }
.help summary { cursor: pointer; font-family: var(--display); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.help p { margin: 8px 0 0; color: var(--muted); line-height: 1.45; }
.help a { color: var(--focus); }
.help code { font-size: 11.5px; }
.sim-only { display: none; } body.sim .sim-only { display: block; }
.disconnected .needs-link { opacity: .5; pointer-events: none; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .rail { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding-block: 6px; }
  .rail .spacer, .rail .foot { display: none; }
  .rail button { white-space: nowrap; }
  .editor { height: 300px; }
  .blockly-host { height: 420px; }
  .workspace { grid-template-columns: 1fr; }
  .api { height: 260px; }
}

/* link back to the OpenMindstorms home page, in the top bar brand */
.brand .home { text-decoration: none; color: var(--muted); font-size: 18px; line-height: 1; margin-right: 2px; }
.brand .home:hover { color: var(--ink); }
