:root {
  --ink: #18304f;
  --muted: #60738b;
  --paper: rgba(255, 255, 255, 0.96);
  --line: rgba(0, 63, 136, 0.14);
  --accent: #003f88;
  --accent-dark: #003f88;
  --track: #e2e9f2;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #ffffff;
  color: var(--ink);
  font-family: "DM Sans", "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.model-label {
  display: flex;
  justify-content: space-between;
  margin: 16px 0 8px;
  font-size: 11px;
  color: var(--muted);
}

.model-label strong {
  color: var(--ink);
  font-weight: 500;
}

.quality-picker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 11px;
}

.quality-picker select {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  color-scheme: light;
}

#viewport {
  position: fixed;
  inset: 0;
}

#viewport canvas {
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.force-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.drag-force-help {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 10px;
  color: var(--muted);
}

.drag-force-help output {
  flex-shrink: 0;
  color: var(--accent-dark);
  font-variant-numeric: tabular-nums;
}

#fallback-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.grain {
  display: none;
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.25;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.07'/%3E%3C/svg%3E");
}

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  letter-spacing: 0.18em;
  font-weight: 600;
  pointer-events: auto;
}

.brand b {
  color: var(--accent);
}

.brand-mark {
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  transform: rotate(45deg);
}

.model-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a4afbd;
}

.model-status.online .live-dot {
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(0, 63, 136, 0.08);
}

.panel {
  position: fixed;
  top: 88px;
  left: 28px;
  width: 320px;
  max-height: calc(100vh - 112px);
  overflow-y: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 8px 32px rgba(0, 63, 136, 0.08);
  backdrop-filter: blur(18px);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.panel-actions {
  display: flex;
  gap: 8px;
}

.panel-toggle {
  display: none;
}

.panel-toggle[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 9px;
  letter-spacing: 0.17em;
  color: var(--muted);
}

h1 {
  color: var(--accent);
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  color: var(--ink);
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 22px 0;
  padding: 3px;
  border-radius: 5px;
  background: #edf2f8;
}

.mode-switch button {
  border: 0;
  border-radius: 3px;
  padding: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}

.mode-switch button.active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 63, 136, 0.12);
}

.pathology-panel {
  margin: 18px 0;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.pathology-panel summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}

.pathology-panel fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

.slider-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 9px 12px;
  margin: 17px 0;
  font-size: 12px;
}

.slider-row output {
  color: var(--accent-dark);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  height: 3px;
  margin: 5px 0;
  appearance: none;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) 50%, var(--track) 50%);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 63, 136, 0.25);
  cursor: grab;
}

.waypoint-help {
  margin: 16px 0;
  padding: 13px;
  border-left: 2px solid var(--accent);
  background: #f3f6fb;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
}

.muscle-legend {
  margin: 14px 0 4px;
  color: var(--ink);
  font-size: 11px;
  line-height: 1.6;
}

.fiber-swatch {
  width: 100%;
  height: 10px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.activation-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.render-mode-button {
  width: 100%;
  margin: 8px 0 14px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f7f9fc;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.05em;
  text-align: left;
  cursor: pointer;
}

.hidden {
  display: none;
}

.telemetry {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 20px 0;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.telemetry div {
  min-height: 61px;
  padding: 11px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.telemetry span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.05em;
}

.telemetry strong {
  font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.reset-button {
  width: 100%;
  padding: 10px;
  border: 1px solid rgba(0, 63, 136, 0.35);
  border-radius: 3px;
  background: transparent;
  color: var(--ink);
  font-size: 11px;
  cursor: pointer;
  transition: 150ms ease;
}

.reset-button:hover {
  background: #edf2f8;
  color: var(--accent);
}

.scope-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.55;
}

.camera-hint {
  position: fixed;
  right: 30px;
  bottom: 24px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.06em;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  padding: 10px 16px;
  border-radius: 4px;
  background: #003f88;
  color: #fff;
  font-size: 11px;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: #ffffff;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  transition: opacity 400ms ease;
}

.loading.ready {
  opacity: 0;
  pointer-events: none;
}

.loading-ring {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 700px), (max-width: 1024px) and (pointer: coarse) {
  .panel {
    top: auto;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
    width: auto;
    max-height: 44vh;
    max-height: 44dvh;
    padding: 0 16px 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  .panel-heading {
    position: sticky;
    top: 0;
    z-index: 2;
    align-items: center;
    gap: 8px;
    min-height: 68px;
    background: #ffffff;
  }

  .panel h1 {
    font-size: 18px;
    letter-spacing: -0.02em;
  }

  .panel .eyebrow {
    display: none;
  }

  .panel.is-collapsed {
    padding-bottom: 0;
  }

  .panel.is-collapsed > :not(.panel-heading) {
    display: none;
  }

  .panel-toggle {
    display: inline-grid;
    place-items: center;
  }

  .icon-button {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
  }

  .mode-switch button,
  .reset-button,
  .render-mode-button,
  .quality-picker select,
  .pathology-panel summary {
    min-height: 44px;
  }

  .pathology-panel summary {
    align-content: center;
  }

  input[type="range"] {
    height: 44px;
    margin: 0;
    border-radius: 0;
    background-size: 100% 4px !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    touch-action: pan-y;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 26px;
    height: 26px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    background: var(--accent);
  }

  .assistance-toggle input {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
  }

  .topbar {
    height: calc(56px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    gap: 12px;
  }

  .brand {
    flex-shrink: 0;
    gap: 8px;
    font-size: 11px;
    letter-spacing: 0.1em;
  }

  .model-status {
    min-width: 0;
    font-size: 9px;
    letter-spacing: 0;
  }

  #connection {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .live-dot {
    flex-shrink: 0;
  }

  .camera-hint {
    top: calc(64px + env(safe-area-inset-top));
    right: 12px;
    bottom: auto;
    left: 12px;
    font-size: 9px;
    text-align: center;
    pointer-events: none;
  }

  .toast {
    top: calc(88px + env(safe-area-inset-top));
    bottom: auto;
    width: max-content;
    max-width: calc(100% - 32px);
    text-align: center;
  }
}

@media (max-width: 1024px) and (max-height: 500px) and (orientation: landscape) {
  .panel {
    left: auto;
    width: min(320px, 43vw);
    max-height: calc(100vh - 88px - env(safe-area-inset-top));
    max-height: calc(100dvh - 88px - env(safe-area-inset-top));
  }
}

.assistance-panel {
  margin: 14px 0;
  padding: 12px;
  border: 1px solid #c5d5e8;
  border-radius: 10px;
  background: #f5f9ff;
}
.assistance-toggle, .assistance-forces {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}
.assistance-toggle input { accent-color: #003f88; cursor: pointer; }
.assistance-toggle input:disabled { cursor: wait; }
.assistance-forces { margin-top: 10px; }
.left-force { color: #be2341; }
.right-force { color: #1265c6; }
.assistance-force-overlay text {
  font: bold 13px sans-serif;
  paint-order: stroke;
  stroke: white;
  stroke-width: 3px;
}
