/* R1 control station: a lab test bench.
   Cool bench-grey chrome, white work surfaces, a dark test cell for the robot.
   Red and safety yellow are reserved for stopping and hardware warnings. */

@font-face { font-family: "Barlow"; font-weight: 400; font-display: swap; src: url(../vendor/fonts/barlow-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-display: swap; src: url(../vendor/fonts/barlow-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-display: swap; src: url(../vendor/fonts/barlow-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 600; font-display: swap; src: url(../vendor/fonts/barlow-condensed-latin-600-normal.woff2) format("woff2"); }

:root {
  --bench: #eef0f4;        /* chrome */
  --surface: #fbfcfd;      /* work surfaces */
  --sunk: #f2f4f8;         /* inset controls, tiles */
  --ink: #1d2230;
  --ink-2: #4a5265;
  --muted: #697185;
  --line: #d9dde5;
  --line-strong: #c4cad6;
  --cell: #1b2130;         /* the 3D test cell */
  --accent: #4351d6;       /* R1 indigo: interactive */
  --accent-soft: #e6e8fb;
  --stop: #d3261c;
  --safety: #f5c400;
  --ok: #1f9d6b;
  --warn-ink: #8a5a00;
  --radius: 10px;
  --font: "Barlow", system-ui, sans-serif;
  --font-head: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bench); color: var(--ink); font: 400 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, kbd { font-family: var(--font); }
.muted, .note { color: var(--muted); }
.note { font-size: 13px; line-height: 1.45; }
.error-text { color: var(--stop); margin: 0; }
.error-text:empty { display: none; }

/* ---------- top bar ---------- */
#topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--bench); }
.brand { font: 600 26px/1 var(--font-head); letter-spacing: -0.01em; margin-right: 10px; }
.spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 13px;
  font-weight: 500; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); }
.pill.ok::before { background: var(--ok); }
.pill.bad { color: var(--stop); } .pill.bad::before { background: var(--stop); }
.pill.subtle::before { display: none; }
.pill.busy { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill.busy::before { background: #fff; animation: blink 1s steps(2) infinite; }
.pill.safe { background: var(--safety); border-color: #d9ad00; color: var(--ink); }
.pill.safe::before { background: var(--ink); }
.pill.warm { background: #fff4d6; border-color: #e7b84a; color: var(--warn-ink); }
.pill.warm::before { background: #e39b00; }
.pill.hot { background: var(--stop); border-color: var(--stop); color: #fff; }
.pill.hot::before { background: #fff; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* ---------- layout ---------- */
#layout { display: grid; grid-template-columns: minmax(0, 1fr) 430px; gap: 12px; padding: 0 12px 12px;
  height: calc(100vh - 56px); height: calc(100dvh - 56px); }
#stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; min-height: 0; }
#viewer { position: relative; flex: 1; min-height: 260px; background: var(--cell); border-radius: 14px; overflow: hidden; }
#viewer canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.viewer-msg { position: absolute; inset: 0; display: grid; place-items: center; color: #9aa3b8; pointer-events: none; }
#slot-bottom { background: var(--surface); border-radius: 14px; border: 1px solid var(--line); }
#sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-radius: 14px; border: 1px solid var(--line); }
#tabs { display: flex; gap: 2px; padding: 6px 8px 0; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
#tabs button { flex: 1 0 auto; background: none; border: 0; padding: 10px 10px 9px; color: var(--muted); font-weight: 500;
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
#tabs button:hover { color: var(--ink); }
#tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
#slot-side { flex: 1; overflow-y: auto; padding: 4px 18px 24px; }

/* 3D cell tools */
.cell-tools { position: absolute; left: 12px; top: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.cell-btn { background: rgba(255, 255, 255, .08); color: #d9deea; border: 1px solid rgba(255, 255, 255, .14); border-radius: 8px;
  padding: 5px 11px; font-size: 13px; font-weight: 500; cursor: pointer; backdrop-filter: blur(6px); }
.cell-btn:hover { background: rgba(255, 255, 255, .16); color: #fff; }
.cell-check { display: inline-flex; align-items: center; gap: 6px; }
.cell-check input { accent-color: #8f9aff; margin: 0; }

/* ---------- the emergency stop ---------- */
/* Desktop: in the corner of the 3D cell, always visible, never over a control. Phone: fixed at the thumb. */
.estop { position: absolute; right: 26px; bottom: 26px; z-index: 40;
  width: 92px; height: 92px; border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  font: 600 19px/1 var(--font-head); letter-spacing: .04em; color: #fff;
  background: radial-gradient(circle at 38% 32%, #f0564d 0%, #d3261c 46%, #9e1610 100%);
  box-shadow: 0 0 0 9px var(--safety), 0 0 0 10px #c79f00, 0 10px 26px rgba(29, 34, 48, .38), inset 0 -6px 10px rgba(0, 0, 0, .25);
  transition: transform .08s ease, box-shadow .08s ease; text-shadow: 0 1px 1px rgba(0, 0, 0, .35); }
.estop:hover { filter: brightness(1.05); }
.estop:active, .estop.pressed { transform: scale(.94); box-shadow: 0 0 0 9px var(--safety), 0 0 0 10px #c79f00,
  0 4px 10px rgba(29, 34, 48, .35), inset 0 4px 10px rgba(0, 0, 0, .35); }
.estop:focus-visible { outline: 3px solid var(--ink); outline-offset: 14px; }

/* ---------- sections (panels) ---------- */
.card { padding: 16px 0; border-top: 1px solid var(--line); }
.panel > .card:first-child, .panel > div:first-child > .card:first-child,
.panel > [hidden]:first-child + .card { border-top: 0; }   /* no divider above the first visible section */
.card h3 { margin: 0 0 10px; font: 600 19px/1.15 var(--font-head); color: var(--ink); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row + .row { margin-top: 10px; }
.grow { flex: 1; min-width: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 6px 14px;
  border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 500;
  cursor: pointer; transition: background .12s, border-color .12s; }
.btn:hover:not(:disabled) { border-color: var(--ink-2); background: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #3542c0; border-color: #3542c0; }
.btn.danger { color: var(--stop); border-color: #e9b4b0; }
.btn.danger:hover:not(:disabled) { border-color: var(--stop); background: #fdf1f0; }
.btn.small { min-height: 28px; padding: 3px 9px; font-size: 13px; }

input[type=text], input[type=number], input:not([type]), select {
  min-height: 36px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line-strong); background: #fff; min-width: 0; }
input[type=number] { width: 84px; }
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
label.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
label.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; flex: none; }

/* range sliders: thin track, solid thumb */
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
input[type=range]:disabled { cursor: not-allowed; opacity: .4; }

.warnbox { position: relative; padding: 10px 12px 10px 18px; border-radius: 8px; background: #fff8dc; color: var(--ink); font-size: 14px;
  border: 1px solid #ecd27a; overflow: hidden; }
.warnbox::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 7px;
  background: repeating-linear-gradient(-45deg, var(--ink) 0 5px, var(--safety) 5px 10px); }   /* hazard stripe */
kbd { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 5px; background: var(--sunk); border: 1px solid var(--line-strong);
  border-bottom-width: 2px; font-size: 13px; line-height: 20px; text-align: center; font-weight: 500; }
code { background: var(--sunk); padding: 1px 5px; border-radius: 4px; font-size: 14px; }

/* ---------- login ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: var(--cell); }
.login-card { width: min(340px, 88vw); display: flex; flex-direction: column; gap: 12px; text-align: left;
  background: var(--surface); padding: 28px; border-radius: 16px; border: 0; }
.login-card h1 { margin: 0; font: 600 34px/1 var(--font-head); }
.login-card p { margin: 0; }
.login-card input { font-size: 26px; letter-spacing: .32em; text-align: center; padding: 10px; min-height: 54px; }
.login-card button { min-height: 46px; border: 0; border-radius: 8px; font-weight: 600; font-size: 16px; cursor: pointer; }

/* ---------- gestures: keys ---------- */
.search-row { position: sticky; top: 0; z-index: 2; background: var(--surface); padding: 12px 0 10px; margin-bottom: 2px; }
.gesture-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 8px; align-items: start; }
.gesture { position: relative; display: flex; flex-direction: column; background: var(--sunk); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; }
.gesture-run { all: unset; box-sizing: border-box; display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 11px 12px 9px; cursor: pointer; }
.gesture-run:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--radius); }
.gesture .name { font: 600 19px/1.1 var(--font-head); color: var(--ink); }
.gesture .play { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface);
  border: 1px solid var(--line-strong); color: var(--accent); font-size: 11px; }
.gesture:hover:not(.disabled) { border-color: var(--line-strong); background: #eceff5; }
.gesture:hover:not(.disabled) .play { background: var(--accent); border-color: var(--accent); color: #fff; }
.gesture.disabled .gesture-run { cursor: not-allowed; }
.gesture.disabled:not(.running) { opacity: .55; }
.gesture.running { border-color: var(--accent); background: var(--accent-soft); }
.gesture.running .play { background: var(--accent); border-color: var(--accent); color: #fff; }
.gesture.running::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 40% 100%; background-repeat: no-repeat;
  animation: sweep 1.1s linear infinite; }
@keyframes sweep { from { background-position: -40% 0; } to { background-position: 140% 0; } }
.gesture .params { display: grid; grid-template-columns: auto 1fr; gap: 6px 8px; align-items: center; font-size: 13px; color: var(--ink-2);
  padding: 0 12px 11px; }
.gesture .params select, .gesture .params input[type=number] { width: 100%; min-height: 30px; padding: 3px 8px; font-size: 14px; }
.gesture .footer { display: flex; justify-content: space-between; align-items: center; padding: 0 12px 10px; margin-top: -2px; }
.badge { font-size: 12px; color: var(--muted); }

/* ---------- joints ---------- */
details.group { border-top: 1px solid var(--line); }
details.group:first-of-type { border-top: 0; }
details.group summary { padding: 13px 0; cursor: pointer; font: 600 19px/1.1 var(--font-head); list-style: none;
  display: flex; justify-content: space-between; align-items: center; }
details.group summary::-webkit-details-marker { display: none; }
details.group summary::after { content: "+"; font: 500 20px/1 var(--font); color: var(--muted); }
details.group[open] summary::after { content: "–"; }
details.group > .joint:last-child { margin-bottom: 12px; }
.joint { display: grid; grid-template-columns: 112px 1fr 50px; gap: 10px; align-items: center; padding: 3px 0; font-size: 14px; }
.joint .name { color: var(--ink-2); line-height: 1.15; }
.joint .name small { display: block; color: var(--muted); font-size: 12px; }
.joint .name small.warm { color: var(--warn-ink); font-weight: 600; }
.joint .name small.hot { color: var(--stop); font-weight: 600; }
.joint .val { text-align: right; font-weight: 600; }

/* ---------- editor ---------- */
.steps { margin: 0; padding-left: 20px; color: var(--ink-2); }
.steps li + li { margin-top: 4px; }
.kf { display: grid; grid-template-columns: 26px 1fr auto; gap: 4px 8px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.kf .idx { width: 24px; height: 24px; border-radius: 50%; background: var(--sunk); border: 1px solid var(--line-strong);
  display: grid; place-items: center; font-size: 13px; font-weight: 600; }
.kf .times { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--ink-2); }
.kf .times input { width: 62px; min-height: 30px; padding: 3px 6px; }
.kf .ops { display: flex; gap: 3px; }
.kf .joints-list { grid-column: 2 / 4; font-size: 13px; color: var(--muted); }

/* ---------- log ---------- */
.log { max-height: 240px; overflow-y: auto; font-size: 13px; line-height: 1.6; color: var(--ink-2); }
.log .warn { color: var(--warn-ink); } .log .error { color: var(--stop); }
.log time { color: var(--muted); margin-right: 8px; }

/* ---------- charts ---------- */
.charts { padding: 10px 14px 12px; }
.charts-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.charts-head b { font: 600 19px/1 var(--font-head); margin-right: 4px; }
.charts-head select { min-height: 30px; padding: 3px 8px; font-size: 14px; }
.chart-wrap { position: relative; }
.charts canvas { width: 100%; height: 168px; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; background: var(--sunk);
  border: 1px solid var(--line); font-size: 13px; color: var(--ink); cursor: pointer; }
.legend-item:hover { border-color: var(--line-strong); }
.legend-item .swatch { width: 10px; height: 3px; border-radius: 2px; }
.legend-item.off { opacity: .5; text-decoration: line-through; }   /* body tilt on a non-degree chart */
.legend-item .x { color: var(--muted); }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; border-radius: 8px; padding: 6px 9px;
  font-size: 13px; line-height: 1.45; white-space: nowrap; transform: translate(12px, -50%); z-index: 3; }
.chart-tip .swatch { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

/* ---------- walk pad ---------- */
.pad { position: relative; width: 190px; height: 190px; border-radius: 50%; margin: 6px auto 0; touch-action: none; user-select: none;
  background: radial-gradient(circle, var(--surface) 0 30%, var(--sunk) 31% 100%); border: 1px solid var(--line-strong); }
.pad::before, .pad::after { content: ""; position: absolute; background: var(--line); }
.pad::before { left: 50%; top: 12px; bottom: 12px; width: 1px; }
.pad::after { top: 50%; left: 12px; right: 12px; height: 1px; }
.pad .knob { position: absolute; z-index: 1; width: 62px; height: 62px; left: 64px; top: 64px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 4px 12px rgba(67, 81, 214, .35); pointer-events: none; }
.pad-label { text-align: center; font-size: 13px; color: var(--muted); margin-top: 6px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column;
  gap: 6px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 8px; max-width: min(520px, 76vw);
  box-shadow: 0 8px 24px rgba(29, 34, 48, .25); }
.toast.error { background: var(--stop); }

/* ---------- phone ---------- */
@media (max-width: 900px) {
  #layout { display: flex; flex-direction: column; height: auto; padding: 0 10px 10px; gap: 10px; }
  #stage { display: contents; }
  #viewer { order: 1; height: 44vh; flex: none; border-radius: 12px; }
  #sidebar { order: 2; }
  #slot-bottom { order: 3; }
  #slot-side { overflow: visible; padding: 4px 14px 24px; }
  #layout { padding-bottom: 120px; }    /* the last control can always scroll above the stop dock */
  .brand { font-size: 22px; }
  .estop { position: fixed; right: max(22px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom));
    width: 78px; height: 78px; font-size: 17px; }
  body::after { content: ""; position: fixed; left: 0; right: 0; bottom: 0; height: 112px; z-index: 30; pointer-events: none;
    background: linear-gradient(rgba(238, 240, 244, 0), var(--bench) 45%); }   /* dock: content fades out under the stop button */
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
