:root {
  --bar: #20303f;
  --bar-text: #ffffff;
  --accent: #f2a900;
  --go: #2e9e4f;
  --stop: #d64541;
  --panel: #f6f7f9;
  --line: #d5d9de;
  --text: #1d2730;
  --muted: #5d6b78;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; font-family: system-ui, sans-serif; color: var(--text); background: var(--panel); overscroll-behavior: none; }

header { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.6rem; background: var(--bar); color: var(--bar-text); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 0.45rem; font-weight: 700; font-size: 1.1rem; margin-right: 0.4rem; }
.brand svg { width: 2rem; height: 2rem; }
#name { width: 9.5rem; font-size: 1rem; padding: 0.55rem 0.6rem; border-radius: 0.6rem; border: 0; }
.spacer { flex: 1; }

button { font: inherit; font-weight: 600; border: 0; border-radius: 0.7rem; padding: 0.6rem 0.9rem; min-height: 2.75rem; cursor: pointer; display: inline-flex; align-items: center; gap: 0.4rem; color: var(--text); background: #e9edf1; }
[hidden] { display: none !important; }
button svg { width: 1.2rem; height: 1.2rem; }
button:disabled { opacity: 0.45; cursor: default; }
#run { background: var(--go); color: #fff; }
#stop { background: var(--stop); color: #fff; }
#connect.connected { background: #cfeeda; }
/* Battery symbol on the connect button: kids see how full it is without reading a voltage */
.battery { position: relative; width: 1.7rem; height: 0.95rem; border: 2px solid currentColor; border-radius: 0.2rem; padding: 1px; margin-left: 0.2rem; }
.battery::after { content: ""; position: absolute; right: -0.3rem; top: 0.2rem; width: 0.15rem; height: 0.35rem; background: currentColor; border-radius: 0 0.1rem 0.1rem 0; }
.battery > span { display: block; height: 100%; border-radius: 0.1rem; background: var(--go); }
.battery.low > span { background: var(--stop); }
button.on { background: var(--accent); }

.menu { position: relative; }
.menu-items { position: absolute; right: 0; top: calc(100% + 0.3rem); z-index: 100; background: #fff; border: 1px solid var(--line); border-radius: 0.8rem; padding: 0.4rem; display: none; flex-direction: column; gap: 0.3rem; min-width: 15rem; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); }
.menu.open .menu-items { display: flex; }
.menu-items button { justify-content: flex-start; width: 100%; }
/* Big coloured icons in the connect menu, recognisable without reading */
#connectMenu .menu-items button { gap: 0.75rem; padding: 0.45rem 0.9rem 0.45rem 0.45rem; text-align: left; }
.menu-icon { flex: none; width: 2.6rem; height: 2.6rem; border-radius: 0.6rem; display: grid; place-items: center; color: #fff; }
.menu-icon svg { width: 1.7rem; height: 1.7rem; }
.menu-icon.usb { background: #4a5563; }
.menu-icon.bt { background: #1f6fe0; }
.menu-icon.off { background: var(--stop); }
.menu-icon.demo { background: #8A5BD0; }
.menu-items small { color: var(--muted); padding: 0.2rem 0.5rem 0.4rem; font-weight: 400; }
.menu-items a { color: var(--muted); padding: 0.4rem 0.5rem; font-size: 0.9rem; }

main { flex: 1; display: flex; min-height: 0; }
#blockly { flex: 1; min-width: 0; }
#codePanel { width: min(26rem, 45vw); border-left: 1px solid var(--line); background: #fff; display: none; flex-direction: column; }
#codePanel.open { display: flex; }
#codePanel h2 { margin: 0; padding: 0.6rem 0.8rem; font-size: 0.95rem; border-bottom: 1px solid var(--line); }
#code { margin: 0; padding: 0.8rem; overflow: auto; flex: 1; font: 0.85rem/1.45 ui-monospace, monospace; }

#status { padding: 0.55rem 0.8rem; background: #fff; border-top: 1px solid var(--line); min-height: 2.6rem; display: flex; align-items: center; gap: 0.5rem; }
#status.error { background: #fdecea; color: #8a1f17; }
#status.ok { background: #e8f6ec; color: #17602f; }
#status.busy::before { content: ""; width: 1rem; height: 1rem; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--bar); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
footer { font-size: 0.75rem; color: var(--muted); padding: 0.25rem 0.8rem 0.4rem; background: #fff; }

/* Bigger toolbox rows for fingers */
.blocklyToolboxCategory { height: auto !important; min-height: 2.75rem; display: flex; align-items: center; padding: 0 0.8rem !important; margin: 0 0.35rem 0.35rem; border-radius: 0.7rem; }
.blocklyToolboxCategoryLabel { font-size: 1.05rem !important; font-weight: 700; color: #fff; }

@media (max-width: 700px) {
  .brand span, button .label-wide { display: none; }
  #name { width: 7rem; }
  #codePanel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 50; width: 85vw; }
  main { position: relative; }
}

/* --- menus: examples and languages fold out inside the "more" menu */
.menu-items details { border-radius: 0.7rem; background: #f1f3f6; }
.menu-items summary { padding: 0.75rem 0.9rem; font-weight: 600; cursor: pointer; }
.menu-items details button { background: transparent; font-weight: 500; text-align: left; border-radius: 0; }
.menu-items details button.current { font-weight: 700; }
#moreMenu .menu-items { max-height: 80vh; overflow-y: auto; min-width: 17rem; }

/* --- robot panel: live sensor values and the programs on the brick */
#robotPanel { width: min(24rem, 90vw); border-left: 1px solid var(--line); background: #fff; display: none; flex-direction: column; }
#robotPanel.open { display: flex; }
#robotPanel h2 { margin: 0; padding: 0.5rem 0.8rem; font-size: 1rem; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
#robotPanel h3 { font-size: 0.9rem; margin: 1rem 0 0.4rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
#robotPanel h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.panel-body { padding: 0 0.8rem 1rem; overflow-y: auto; overflow-x: hidden; flex: 1; }
.note { background: #fff6dd; border-radius: 0.6rem; padding: 0.5rem 0.7rem; font-size: 0.85rem; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
#motorCards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { border: 1px solid var(--line); border-radius: 0.8rem; padding: 0.5rem 0.6rem; display: flex; flex-direction: column; gap: 0.3rem; }
.card .label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.card .value { font-size: 1.5rem; white-space: nowrap; font-weight: 700; min-height: 2.2rem; font-variant-numeric: tabular-nums; }
.card select { width: 100%; min-width: 0; font: inherit; padding: 0.35rem; border-radius: 0.5rem; border: 1px solid var(--line); background: #fff; min-height: 2.4rem; }
.rename { display: flex; gap: 0.4rem; }
.rename input { flex: 1; min-width: 0; font: inherit; font-size: 1.1rem; font-weight: 700; padding: 0.4rem 0.6rem; border-radius: 0.6rem; border: 1px solid var(--line); }
.program-row { display: flex; align-items: center; gap: 0.4rem; padding: 0.35rem 0; border-bottom: 1px solid var(--line); }
.program-row .file { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.program-row .file small { display: block; font-weight: 400; color: var(--muted); }
.program-row.running .file::before { content: "▶ "; color: var(--go); }
.program-row button { padding: 0.4rem 0.7rem; min-height: 2.4rem; }
button.danger { color: #8a1f17; background: #fdecea; }
@media (max-width: 700px) { #robotPanel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 50; } }
