/* ============================================================================
   Robot Kinematics Teaching Platform — UI styles
   Light, high-contrast, projector-friendly. Colours match the Colab lab so a
   student sees the same blue links and red TCP in both places.
   ========================================================================= */

:root {
  --link: #2a78d6;
  --joint: #0b0b0b;
  --tcp: #e34948;
  --axis: #4a3aa7;
  --ghost: #eb6834;
  --x: #e34948;
  --y: #008300;
  --z: #2a78d6;

  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --border: #dbe1e8;
  --border-strong: #c3ccd6;
  --ink: #131920;
  --ink-2: #4a5563;
  --muted: #6b7684;

  --ok: #0f7a45;
  --ok-bg: #e7f6ee;
  --bad: #c62f28;
  --bad-bg: #fdeceb;
  --warn: #9a6206;
  --warn-bg: #fdf3e2;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(19, 25, 32, .06), 0 4px 14px rgba(19, 25, 32, .05);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 16px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
em { font-style: normal; font-family: var(--mono); }

/* ------------------------------------------------------------------ topbar */

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 34px; height: 34px; object-fit: contain; display: block; }
.brand-sub { margin: 0; font-size: 11.5px; color: var(--muted); }

.topbar-controls { display: flex; align-items: center; gap: 14px; }

.field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.field > span { text-transform: uppercase; letter-spacing: .05em; font-size: 11px; }

select, input[type="text"], input[type="number"] {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
}
select:focus-visible, input:focus-visible, button:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 1px;
}

.unit-switch {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.unit-btn {
  font: inherit;
  font-size: 12px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
}
.unit-btn { padding: 2px 8px; font-size: 11px; }
.unit-btn.is-active {
  background: var(--ink);
  color: #fff;
}

.topbar-link {
  font-size: 12px;
  color: var(--link);
  text-decoration: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  white-space: nowrap;
}
.topbar-link:hover { background: var(--surface-2); text-decoration: underline; }

/* "get this yourself" snippet block in the DH tab */
.snippet { margin-top: 6px; }
.snippet pre {
  margin: 0;
  padding: 9px 10px;
  background: #10151c;
  color: #e6edf3;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.snippet-head { display: flex; align-items: center; gap: 6px; margin: 12px 0 4px; }
.snippet-head .seg { margin: 0; }
.snippet-head .seg button { font-size: 11px; padding: 3px 8px; }
.btn-copy { margin-left: auto; }
.copied { color: var(--ok); font-size: 11px; }

.status {
  font-size: 11.5px;
  font-family: var(--mono);
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.status.is-ok { color: var(--ok); background: var(--ok-bg); border-color: #bfe5d1; }
.status.is-live { color: #7b3fbf; background: #f4ecfd; border-color: #ddc9f5; }
.toggle.is-live { color: #7b3fbf; font-weight: 600; }

.status.is-bad { color: var(--bad); background: var(--bad-bg); border-color: #f3c9c6; }

/* ------------------------------------------------------------------ layout */

.layout {
  height: calc(100% - 56px);
  display: grid;
  grid-template-columns: 310px minmax(320px, 1fr) 420px;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-y: auto;
  overflow-x: hidden;
}
.panel-left { padding: 14px; }

/* The admin entrance: bottom-left corner, deliberately quiet.  It is not part
   of teaching a lesson, so it sits outside the panels rather than competing
   with them, and session.js removes it for students along with everything
   else marked lecture-only. */
.corner-link {
  position: fixed;
  left: 10px;
  bottom: 8px;
  z-index: 5;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
}
.corner-link:hover { color: var(--ink-2); border-color: var(--border); background: var(--surface); }

.block { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.block:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 8px; }

.params { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 8px 0 0; font-size: 12px; }
.params dt { font-family: var(--mono); color: var(--muted); }
.params dd { margin: 0; font-family: var(--mono); }

/* ------------------------------------------------------------------ joints */

.joints { display: flex; flex-direction: column; gap: 12px; }

.joint {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "head value" "slider slider";
  gap: 4px 8px;
  align-items: center;
}
.joint-head { grid-area: head; display: flex; align-items: baseline; gap: 6px; }
.joint-label { font-family: var(--mono); font-weight: 600; }
.joint-name { font-size: 11px; color: var(--muted); }
.joint-value { grid-area: value; }
.joint-value input {
  width: 84px;
  text-align: right;
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 3px 6px;
}
.joint input[type="range"] { grid-area: slider; width: 100%; accent-color: var(--link); margin: 0; }
.joint.is-out-of-range .joint-value input { border-color: var(--bad); background: var(--bad-bg); }

.button-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }

.btn {
  font: inherit;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-small { font-size: 11.5px; padding: 3px 8px; }
.btn-primary { background: var(--link); border-color: var(--link); color: #fff; }
.btn-primary:hover { background: #2266bb; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.warning { color: var(--warn); background: var(--warn-bg); border: 1px solid #f0dcb5;
           padding: 6px 8px; border-radius: var(--radius-sm); font-size: 12px; margin: 10px 0 0; }
.error-text { color: var(--bad); font-size: 12px; margin: 8px 0 0; }

/* -------------------------------------------------------------- DH editor */

.table-scroll { overflow-x: auto; }
table.dh-editor { width: 100%; border-collapse: collapse; font-size: 12px; }
table.dh-editor th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11px; padding: 2px 3px; }
table.dh-editor td { padding: 2px 3px; }
table.dh-editor input { width: 100%; min-width: 52px; font-family: var(--mono); font-size: 12px; padding: 3px 4px; }
table.dh-editor select { font-size: 11px; padding: 3px 2px; }
.row-remove { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1; }
.row-remove:hover { color: var(--bad); }

/* ---------------------------------------------------------------- viewport */

.viewport {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 320px;
}
#scene { display: block; width: 100%; height: 100%; touch-action: none; }

.hud {
  position: absolute;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  pointer-events: none;
}
.hud-top-left { top: 10px; left: 10px; font-family: var(--mono); }
.hud-top-right { top: 10px; right: 10px; display: flex; gap: 4px; pointer-events: auto; padding: 4px; }
.hud-bottom { bottom: 10px; left: 10px; display: flex; gap: 12px; flex-wrap: wrap; pointer-events: auto; }
.hud-row { display: flex; gap: 8px; white-space: nowrap; }
.hud-label { color: var(--muted); min-width: 22px; }

.toggle { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--ink-2); cursor: pointer; }
/* an explicit display beats the [hidden] attribute, so restate it */
.toggle[hidden] { display: none; }
.toggle input { accent-color: var(--link); margin: 0; }

/* The gripper's opening: a slider in the same row as the toggles, so the tool
   is controlled where it is switched on. */
.toggle-range { gap: 6px; }
.toggle-range input[type="range"] { width: 78px; accent-color: var(--link); cursor: grab; }
.toggle-range output { font-family: var(--mono); font-size: 11px; color: var(--muted); min-width: 42px; }

.viewport-legend {
  position: absolute; bottom: 10px; right: 10px;
  display: flex; gap: 10px; font-size: 11px; color: var(--ink-2);
  background: rgba(255,255,255,.88); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 4px 8px;
}
.viewport-legend span { display: inline-flex; align-items: center; gap: 4px; }
.viewport-legend span[hidden] { display: none; }
.swatch { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.swatch-link { background: var(--link); }
.swatch-tcp { background: var(--tcp); }
.swatch-axis { background: var(--axis); }
.swatch-ghost { background: var(--ghost); }

/* Author credit, in the subtitle under the title. Deliberately not placed in
   the viewport: .hud-bottom already owns bottom-left and would overlap it. */
.credit { color: var(--link); text-decoration: none; }
.credit:hover { text-decoration: underline; }

/* -------------------------------------------------------------------- tabs */

.tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--border);
        position: sticky; top: 0; background: var(--surface); z-index: 2; }
.tab {
  font: inherit; font-size: 12.5px; border: 0; background: transparent;
  color: var(--muted); padding: 7px 12px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--link); font-weight: 600; }
.tab-student.is-active { border-bottom-color: var(--ghost); }

/* The worked reference, for the projector. Marked rather than grouped, because
   the tab order follows the course and these sit inside it — a student never
   sees them at all, so the marker is for the lecturer's benefit. */
.tab-reference { color: var(--axis); }
.tab-reference::before { content: "·"; margin-right: 4px; opacity: .55; }
.tab-reference:hover { color: var(--axis); }
.tab-reference.is-active { color: var(--axis); border-bottom-color: var(--axis); }
.tabs { flex-wrap: wrap; }

.tab-panel { display: none; padding: 14px; }
.tab-panel.is-active { display: block; }

.note {
  font-size: 12px; color: var(--ink-2); background: var(--surface-2);
  border-left: 3px solid var(--link); padding: 8px 10px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* ------------------------------------------------------------ data tables */

table.data { width: 100%; border-collapse: collapse; font-size: 12px; }
table.data th, table.data td { padding: 5px 6px; text-align: right; border-bottom: 1px solid var(--border); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th { color: var(--muted); font-weight: 600; font-size: 11px; letter-spacing: .02em; }
table.data td { font-family: var(--mono); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .sym { color: var(--muted); font-style: italic; }

/* ---------------------------------------------------------------- matrices */

.matrix-card { margin-bottom: 14px; }
.matrix-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; }
.matrix-name { font-family: var(--mono); font-weight: 600; font-size: 13px; }
.matrix-caption { font-size: 11px; color: var(--muted); }

.matrix {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-family: var(--mono);
  font-size: 11.5px;
}
.matrix span {
  background: var(--surface);
  padding: 5px 6px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.matrix .cell-rot { background: #f4f8fd; }
.matrix .cell-pos { background: #fdf3f3; }
.matrix .cell-zero { color: #9aa4b0; }

.pose-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 12.5px; margin-bottom: 14px; }
.pose-grid dt { color: var(--muted); }
.pose-grid dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------- student panel */

.student-intro {
  font-size: 12px; color: var(--ink-2); background: #fff7f1;
  border-left: 3px solid var(--ghost); padding: 8px 10px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 12px;
}

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm);
       overflow: hidden; margin-bottom: 10px; }
.seg button { font: inherit; font-size: 12px; border: 0; background: var(--surface);
              padding: 5px 10px; cursor: pointer; color: var(--ink-2); border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.is-active { background: var(--ink); color: #fff; }

.matrix-input { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; margin-bottom: 8px; }
.matrix-input input {
  width: 100%; font-family: var(--mono); font-size: 11.5px; padding: 4px 4px; text-align: right;
}
.vector-input { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.vector-input label { font-size: 11px; color: var(--muted); }
.vector-input input { width: 100%; font-family: var(--mono); font-size: 12px; padding: 4px 6px; text-align: right; }

textarea.paste {
  width: 100%; min-height: 64px; font-family: var(--mono); font-size: 11.5px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 6px; resize: vertical;
}

.result-banner {
  border-radius: var(--radius-sm); padding: 10px 12px; margin: 12px 0 10px;
  font-weight: 600; font-size: 13px; border: 1px solid transparent;
}
.result-banner.pass { background: var(--ok-bg); color: var(--ok); border-color: #bfe5d1; }
.result-banner.fail { background: var(--bad-bg); color: var(--bad); border-color: #f3c9c6; }
.result-banner .score { float: right; font-family: var(--mono); font-weight: 500; }

.check-list { list-style: none; margin: 0 0 12px; padding: 0; }
.check-item {
  display: grid; grid-template-columns: 16px 1fr auto; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; align-items: baseline;
}
.check-mark { font-weight: 700; }
.check-item.pass .check-mark { color: var(--ok); }
.check-item.fail .check-mark { color: var(--bad); }
.check-label { font-family: var(--mono); }
.check-msg { grid-column: 2 / -1; color: var(--muted); font-size: 11.5px; }
.check-value { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); white-space: nowrap; }

.diagnostic {
  background: var(--warn-bg); border: 1px solid #f0dcb5; border-radius: var(--radius-sm);
  padding: 9px 11px; margin-bottom: 8px; font-size: 12.5px;
}
.diagnostic h4 { margin: 0 0 3px; font-size: 12.5px; color: var(--warn); }
.diagnostic p { margin: 0; color: var(--ink-2); font-size: 12px; }
.diagnostic .confidence { float: right; font-size: 10.5px; text-transform: uppercase;
                          letter-spacing: .05em; color: var(--muted); }

.exercise-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.exercise-row input[type="number"] { width: 72px; }
.case-list { list-style: none; margin: 8px 0 0; padding: 0; font-size: 12px; }
.case-list li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 6px;
                border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 4px; cursor: pointer; }
.case-list li:hover { background: var(--surface-2); }
.case-list li.is-active { border-color: var(--link); background: #f2f7fd; }
.case-list .case-q { font-family: var(--mono); }
.case-state { font-size: 11px; }
.case-state.pass { color: var(--ok); }
.case-state.fail { color: var(--bad); }

.spacer { height: 14px; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }

/* ------------------------------------------------------------- responsive */

/* ---------------------------------------------------- lecture password gate */

.lecture-dialog {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--surface);
  color: var(--ink);
  padding: 20px 22px;
  width: min(22rem, calc(100vw - 32px));
}
.lecture-dialog::backdrop { background: rgba(19, 25, 32, .45); }
.lecture-dialog h2 { margin: 0 0 4px; font-size: 15px; }
.lecture-dialog p { margin: 0 0 12px; }
.lecture-dialog input[type="password"] {
  font: inherit;
  font-size: 13px;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
}
.lecture-dialog .button-row { margin-top: 12px; }

@media (max-width: 1280px) {
  .layout { grid-template-columns: 280px 1fr 360px; }
}
@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 420px auto;
    overflow-y: auto;
  }
  .panel { max-height: 520px; }
  .viewport { min-height: 420px; }
}
@media (max-width: 620px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .brand-sub { display: none; }
}

@media print {
  .panel-left, .tabs, .hud, .view-buttons, .corner-link { display: none; }
}

/* ------------------------------------------------------ transform lab */
.step-list { display: grid; gap: 4px; margin: 10px 0; }

.step-row {
  display: grid;
  grid-template-columns: 16px 62px 46px minmax(0, 1fr) 26px 74px 24px;
  gap: 4px;
  align-items: center;
  padding: 3px 4px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.step-row:hover { background: var(--surface-2); }
.step-row.is-active { border-color: var(--link); background: var(--surface-2); }
.step-row select,
.step-row input { min-width: 0; font-size: 12px; padding: 3px 4px; }
.step-number { font: 600 11px var(--mono); color: var(--muted); text-align: center; }
.step-unit { font-size: 11px; color: var(--muted); }

.lesson-list { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 9px; }
.lesson p { margin: 2px 0 0; font-size: 12px; color: var(--ink-2); }
.lesson.is-done > label strong { text-decoration: line-through; color: var(--muted); }
.lesson code { font: 11px var(--mono); background: var(--surface-2); padding: 1px 3px;
               border-radius: 3px; }

/* ------------------------------------------------------- teach pendant */
.point-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.point-list > li {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 8px;
  background: var(--surface);
}
.point-head { display: flex; align-items: center; gap: 6px; }
.point-head input[type="text"] {
  flex: 1; min-width: 0; font: inherit; font-size: 12px; font-weight: 600;
  border: 1px solid transparent; background: transparent; padding: 2px 4px;
  border-radius: 4px; color: var(--ink);
}
.point-head input[type="text"]:hover,
.point-head input[type="text"]:focus { border-color: var(--border); background: var(--surface-2); }
.point-tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px;
}
.point-actions { display: flex; gap: 5px; margin-top: 5px; }

.branch-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 5px; }
.branch-list > li { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

.note.bad { color: var(--bad); }

/* ------------------------------------------------- IK answer (student tab) */
.ik-solution {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 6px;
  align-items: start;
  margin-bottom: 6px;
}
.ik-solution .step-number { padding-top: 16px; }
.ik-solution .vector-input { margin-bottom: 0; }

#carry-robot-toggle { display: inline-flex; align-items: center; gap: 6px;
                      margin: 2px 0 10px; font-size: 12px; color: var(--ink-2); }
