* { box-sizing: border-box; }
:root {
  color-scheme: light;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #24252a;
  background: #f6f5f2;
  --ink: #24252a;
  --muted: #515861;
  --accent: #8a432f;
  --accent-dark: #743623;
  --line: rgba(45, 47, 57, .13);
  --glass: rgba(255, 255, 255, .43);
  --gutter: clamp(12px, 2.4vw, 38px);
}
body {
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
}
button, select, input { font: inherit; }
button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0 14px;
  background: transparent;
  color: var(--ink);
  font-size: .875rem;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media (hover: hover) {
  button:hover { background: rgba(42, 44, 54, .07); }
  #panel .primary:hover { background: var(--accent-dark); }
}
button:active { filter: brightness(.93); }

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) var(--gutter) 10px;
  min-height: 64px;
}
.identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.planet {
  flex: 0 0 29px;
  height: 29px;
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 24% 24%, #f3b68a 0%, transparent 52%),
    repeating-linear-gradient(149deg, transparent 0 5px, #edb08338 6px 8px),
    linear-gradient(145deg, #ba6648, #78392e);
  box-shadow: inset 0 0 0 1px #65281736;
}
h1 { margin: 0; font-size: clamp(1rem, 2.15vw, 1.375rem); letter-spacing: -.04em; white-space: nowrap; }
.gesture { margin: 0; color: var(--muted); font-size: .8125rem; white-space: nowrap; }
.touch-hint { display: none; }
@media (pointer: coarse) {
  .mouse-hint { display: none; }
  .touch-hint { display: inline; }
}

main {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin-inline: var(--gutter);
}
#view {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 27px;
  background: radial-gradient(ellipse at 47% 32%, #f7f8fa 4%, #e9edf2 56%, #d9dfe7 100%);
  box-shadow: inset 0 0 0 1px rgba(55, 63, 80, .11);
}
#view canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.view-bar {
  position: absolute;
  z-index: 1;
  inset: 14px 14px auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.view-label, .view-tools {
  border: 1px solid rgba(255, 255, 255, .76);
  border-radius: 13px;
  background: rgba(255, 255, 255, .62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.view-label { padding: 7px 11px; color: #414854; font-size: .8125rem; font-weight: 650; white-space: nowrap; }
.view-tools { display: flex; gap: 1px; padding: 2px; pointer-events: auto; }
.view-tools[hidden] { display: none; }
.view-tools button { min-height: 40px; padding: 0 11px; border-radius: 10px; }
.view-tools button[aria-pressed=true] { background: #fff; border-color: var(--line); }
.view-tools .view-reset { position: relative; padding-inline: 11px; color: var(--muted); }
.view-tools .view-reset:not(:first-child)::before {
  content: "";
  position: absolute;
  inset: 10px auto 10px -2px;
  width: 1px;
  background: var(--line);
}
#loading {
  position: absolute;
  z-index: 1;
  top: 45%;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 32px);
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 12px 16px;
  color: #303641;
  background: rgba(255, 255, 255, .85);
  border: 1px solid #fff;
  border-radius: 14px;
  text-align: center;
}
#loading[data-error] { color: #8c3322; }

#panel {
  position: absolute;
  z-index: 2;
  bottom: 13px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 26px);
  padding: 10px;
  border-radius: 20px;
  background: var(--glass);
  border: 1px solid rgba(255, 255, 255, .89);
  box-shadow: 0 12px 38px rgba(30, 29, 35, .14), 0 2px 8px rgba(30, 29, 35, .08);
  backdrop-filter: blur(15px) saturate(135%);
  -webkit-backdrop-filter: blur(15px) saturate(135%);
}
#panel:empty { display: none; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
#panel[data-panel=drive] { min-width: min(580px, calc(100% - 26px)); }
.drive-strip { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.drive-actions, .manual-actions, .joint-reset { display: flex; align-items: center; gap: 4px; }
#panel .primary {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  min-width: 121px;
  box-shadow: 0 2px 6px #7c361f2d;
}
.play-glyph { width: 11px; height: 12px; background: currentColor; clip-path: polygon(0 0, 100% 50%, 0 100%); }
.primary[data-playing=true] .play-glyph { clip-path: polygon(0 0, 32% 0, 32% 100%, 0 100%, 0 0, 66% 0, 100% 0, 100% 100%, 66% 100%, 66% 0); }
.quiet { background: rgba(255, 255, 255, .63); border-color: rgba(34, 37, 49, .08); }
.manual-actions {
  gap: 0;
  padding: 2px;
  border: 1px solid rgba(51, 55, 65, .11);
  border-radius: 14px;
  background: rgba(255, 255, 255, .46);
}
.manual-actions button { min-width: 53px; padding-inline: 10px; }
.progress-track {
  height: 3px;
  margin: 9px 3px 1px;
  border-radius: 10px;
  background: #75554324;
  overflow: hidden;
}
.progress-track span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent);
  transform: scaleX(var(--progress, 0));
  transform-origin: left;
}
.readout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  padding: 0 3px;
}
#drive-status { margin: 0; font-size: .8125rem; line-height: 1.4; font-weight: 650; font-variant-numeric: tabular-nums; }
#drive-status[data-level=warning] { color: #7a2c1e; }
.readout details { flex: none; }
.readout summary { padding: 9px 4px; font-size: .8125rem; color: #3d444f; font-weight: 650; cursor: pointer; white-space: nowrap; }
#telemetry {
  position: absolute;
  bottom: calc(100% + 9px);
  right: 0;
  width: min(340px, 100%);
  max-height: 36dvh;
  overflow: auto;
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid #ffffffdd;
  border-radius: 16px;
  background: rgba(253, 253, 254, .9);
  backdrop-filter: blur(13px);
  -webkit-backdrop-filter: blur(13px);
  box-shadow: 0 6px 22px #20223624;
  font-size: .8125rem;
  font-variant-numeric: tabular-nums;
}
#telemetry div:first-child { font-weight: 750; }

#panel[data-panel=rig] { width: min(540px, calc(100% - 26px)); }
.joint-controls {
  display: grid;
  grid-template-columns: minmax(84px, auto) minmax(45px, 1fr) 35px auto;
  align-items: center;
  gap: 8px;
}
select {
  appearance: none;
  min-width: 0;
  min-height: 44px;
  padding: 0 28px 0 10px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 11px;
  background: linear-gradient(45deg, transparent 50%, #575d67 50%) right 13px center/5px 5px no-repeat,
    linear-gradient(135deg, #575d67 50%, transparent 50%) right 8px center/5px 5px no-repeat,
    #ffffffa6;
  font-size: .875rem;
}
input[type=range] { min-width: 0; width: 100%; margin: 0; min-height: 36px; accent-color: var(--accent); }
output { font-variant-numeric: tabular-nums; }
.joint-controls output { text-align: right; color: #363c47; font-size: .875rem; }

#panel[data-panel=learn] { width: min(820px, calc(100% - 26px)); max-height: 48%; overflow: auto; }
.lesson-rail { display: flex; gap: 5px; overflow-x: auto; padding: 2px; scrollbar-width: thin; scrollbar-color: #77798655 transparent; }
.lesson-rail button { flex: none; background: rgba(255, 255, 255, .58); border-color: rgba(34, 37, 49, .09); padding-inline: 10px; }
.lesson-rail button[aria-pressed=true] { background: #2c323d; border-color: #2c323d; color: #fff; }
.lesson-copy { margin: 8px 3px 2px; font-size: .875rem; color: #353b46; }
.signal { display: block; margin: 4px 3px 2px; font-size: .8125rem; color: #365271; font-weight: 700; }
.signal:empty, .experiment:empty { display: none; }
.experiment { display: flex; align-items: center; gap: 6px; margin: 4px 3px 0; }
.experiment label { flex: 1; display: grid; grid-template-columns: auto minmax(35px, 1fr) auto; align-items: center; gap: 8px; font-size: .8125rem; }
.experiment button { min-height: 40px; padding-inline: 8px; }

footer { display: flex; align-items: center; justify-content: center; padding: 9px var(--gutter) max(10px, env(safe-area-inset-bottom)); }
footer nav {
  --selection: 0;
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: min(100%, 422px);
  padding: 4px;
  border: 1px solid #deddd9;
  border-radius: 16px;
  background: #ebeae6;
}
footer nav::before {
  content: "";
  position: absolute;
  inset: 4px auto 4px 4px;
  width: calc((100% - 8px) / 3);
  z-index: -1;
  border: 1px solid #fff;
  border-radius: 11px;
  background: #fff;
  box-shadow: 0 1px 6px #31333b1c;
  transform: translateX(calc(var(--selection) * 100%));
  transition: transform 260ms cubic-bezier(.22,.76,.25,1);
}
footer nav button { width: 100%; padding: 0 4px; color: #4c5057; }
footer nav button[aria-pressed=true] { color: #27232a; background: transparent; }

@media (max-width: 640px) {
  :root { --gutter: 9px; }
  .masthead { min-height: 55px; padding-inline: 14px; }
  .identity { gap: 8px; }
  .planet { flex-basis: 23px; height: 23px; }
  .gesture { font-size: .75rem; }
  #view { border-radius: 20px; }
  .view-bar { inset: 8px 8px auto; }
  .view-label { padding-inline: 8px; }
  .view-tools button { min-height: 44px; padding-inline: 7px; }
  #panel, #panel[data-panel] { bottom: 8px; max-width: calc(100% - 16px); }
  #panel[data-panel=drive] { width: min(400px, calc(100% - 16px)); min-width: 0; padding: 7px 8px 4px; }
  .drive-strip { display: grid; grid-template-columns: 1fr; gap: 5px; }
  .drive-actions { display: grid; grid-template-columns: minmax(0,1fr) auto; }
  .drive-actions .primary { min-width: 0 !important; }
  .manual-actions { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); }
  .manual-actions button { min-width: 0; }
  .progress-track { margin-top: 6px; }
  #drive-status { font-size: .75rem; }
  .readout summary { font-size: .75rem; }
  footer { padding-block-start: 6px; }
}
@media (max-width: 365px) {
  .gesture { display: none; }
  .view-label, .view-tools button { font-size: .75rem; }
  .joint-controls { gap: 4px; }
  .joint-controls button { padding-inline: 7px; }
  #panel { padding-inline: 7px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  :root { --gutter: 10px; }
  .masthead { min-height: 40px; padding-block: 5px; }
  h1 { font-size: 1rem; }
  .planet { flex-basis: 23px; height: 23px; }
  #view { border-radius: 17px; }
  .view-bar { inset: 6px 9px auto; }
  #panel { bottom: 6px; padding: 6px; }
  .drive-strip { display: flex; }
  #panel[data-panel=drive] { width: max-content; min-width: 0; }
  #panel[data-panel=learn] {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, .8fr);
    column-gap: 9px;
    max-height: 44%;
  }
  .lesson-rail { grid-column: 1 / -1; }
  .lesson-rail button { min-height: 36px; }
  .lesson-copy { grid-column: 1; margin-top: 4px; }
  .signal { grid-column: 1; margin-top: 0; }
  .experiment { grid-column: 2; grid-row: 2 / span 2; align-self: center; margin-top: 0; }
  .experiment button { min-height: 36px; }
  footer { padding-block: 4px max(4px, env(safe-area-inset-bottom)); }
  footer button { min-height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { transition-duration: 0s !important; }
}
