:root {
  color-scheme: light;
  --bg: #edf2f1;
  --surface: #ffffff;
  --surface-soft: #f7f9f7;
  --ink: #101820;
  --muted: #61707c;
  --line: #d1dbe0;
  --line-strong: #a8b8c0;
  --teal: #0e8f9c;
  --blue: #1677c7;
  --green: #2f9d55;
  --amber: #b7791f;
  --red: #c73a31;
  --violet: #7656b7;
  --charcoal: #1a232d;
  --accent: var(--teal);
  --shadow: 0 26px 70px rgba(16, 24, 32, 0.17);
  --shadow-soft: 0 14px 34px rgba(16, 24, 32, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(120deg, rgba(14, 143, 156, 0.1), transparent 30%),
    linear-gradient(145deg, transparent 48%, rgba(183, 121, 31, 0.09) 48% 49%, transparent 49%),
    var(--bg);
  color: var(--ink);
  font-family:
    "PingFang SC",
    "Microsoft YaHei",
    "Noto Sans CJK SC",
    system-ui,
    sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(16, 24, 32, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 24, 32, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  content: "";
  pointer-events: none;
}

button,
a {
  font: inherit;
}

button {
  border: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.gesture-shell {
  min-height: 100vh;
}

.gesture-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding: 24px 28px 20px;
  border-bottom: 1px solid rgba(168, 184, 192, 0.76);
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.98), rgba(247, 249, 247, 0.94)),
    var(--surface);
}

.gesture-topbar::before {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 10;
  height: 4px;
  background: linear-gradient(90deg, var(--teal), var(--blue), var(--amber), var(--green));
  content: "";
}

.title-block {
  min-width: 0;
}

.eyebrow,
.section-kicker,
.detail-kicker {
  margin-bottom: 7px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
}

h1 {
  margin-bottom: 8px;
  font-size: 30px;
  line-height: 1.14;
  letter-spacing: 0;
}

.lead {
  margin-bottom: 0;
  color: #42515c;
  font-size: 14px;
  line-height: 1.65;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.primary-btn,
.ghost-btn,
.ghost-link,
.manual-grid button,
.filter-grid button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.primary-btn {
  padding: 0 16px;
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
  box-shadow: 0 14px 26px rgba(14, 143, 156, 0.22);
}

.ghost-btn,
.ghost-link {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  background: #fff;
  color: #27333c;
}

.primary-btn:hover,
.primary-btn:focus-visible,
.ghost-btn:hover,
.ghost-btn:focus-visible,
.ghost-link:hover,
.ghost-link:focus-visible,
.manual-grid button:hover,
.manual-grid button:focus-visible,
.filter-grid button:hover,
.filter-grid button:focus-visible {
  outline: none;
  transform: translateY(-1px);
}

.command-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 410px);
  gap: 18px;
  padding: 18px;
}

.stage,
.control-panel > section {
  border: 1px solid rgba(168, 184, 192, 0.84);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 249, 247, 0.95)),
    var(--surface);
  box-shadow: var(--shadow-soft);
}

.stage {
  min-width: 0;
  padding: 14px;
}

.stage-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.stage-header h2,
.panel-title h2,
.detail-card h2 {
  margin-bottom: 0;
  letter-spacing: 0;
}

.stage-header h2 {
  font-size: 22px;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-strip span {
  min-height: 30px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: #34424d;
  font-size: 12px;
  font-weight: 800;
}

.status-strip span.is-live {
  border-color: color-mix(in srgb, var(--green), transparent 45%);
  background: color-mix(in srgb, var(--green), white 88%);
}

.status-strip span.is-alert {
  border-color: color-mix(in srgb, var(--amber), transparent 35%);
  background: color-mix(in srgb, var(--amber), white 88%);
}

.plan-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 1786 / 1266;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background:
    linear-gradient(rgba(22, 119, 199, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(22, 119, 199, 0.07) 1px, transparent 1px),
    #fbfcfc;
  background-size: 34px 34px;
  box-shadow: var(--shadow);
}

.plan-viewport::after {
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(16, 24, 32, 0.09);
  border-radius: 5px;
  content: "";
  pointer-events: none;
}

.plan-surface {
  position: absolute;
  inset: 0;
  transform: scale(var(--zoom, 1));
  transform-origin: center;
  transition: transform 240ms ease;
}

.plan-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: saturate(0.98) contrast(1.04);
  pointer-events: none;
  user-select: none;
}

.flow-overlay,
.hotspot-layer {
  position: absolute;
  inset: 0;
}

.flow-overlay {
  z-index: 2;
  overflow: visible;
  pointer-events: none;
}

.flow-path {
  fill: none;
  stroke: var(--accent);
  stroke-dasharray: 10 13;
  stroke-linecap: round;
  stroke-width: 8;
  opacity: 0.82;
  filter: drop-shadow(0 8px 16px rgba(16, 24, 32, 0.18));
}

.flow-dot {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 5;
}

.hotspot-layer {
  z-index: 3;
}

.hotspot {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  height: var(--h);
  min-width: 24px;
  min-height: 22px;
  border: 1px solid color-mix(in srgb, var(--hotspot-color), transparent 50%);
  border-radius: 7px;
  background: color-mix(in srgb, var(--hotspot-color), transparent 86%);
  cursor: pointer;
  transition:
    opacity 160ms ease,
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.hotspot::before {
  position: absolute;
  left: 8px;
  top: 8px;
  width: 11px;
  height: 11px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--hotspot-color);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--hotspot-color), transparent 84%);
  content: "";
}

.hotspot span {
  position: absolute;
  left: 27px;
  top: 5px;
  max-width: calc(100% - 35px);
  overflow: hidden;
  padding: 4px 7px;
  border: 1px solid rgba(255, 255, 255, 0.88);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 12px 24px rgba(16, 24, 32, 0.12);
  color: #15202a;
  font-size: 12px;
  font-weight: 800;
  opacity: 0;
  text-overflow: ellipsis;
  transform: translateY(-4px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  white-space: nowrap;
}

.hotspot.is-hover,
.hotspot.is-active,
.hotspot:hover,
.hotspot:focus-visible {
  z-index: 4;
  border-color: var(--hotspot-color);
  background: color-mix(in srgb, var(--hotspot-color), transparent 72%);
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.86),
    0 18px 36px rgba(16, 24, 32, 0.24);
  outline: none;
  transform: translateY(-1px);
}

.hotspot.is-hover span,
.hotspot.is-active span,
.hotspot:hover span,
.hotspot:focus-visible span {
  opacity: 1;
  transform: translateY(0);
}

.hotspot.is-dimmed {
  opacity: 0.12;
  pointer-events: none;
}

.gesture-cursor {
  position: absolute;
  z-index: 6;
  left: calc(var(--cursor-x, 50) * 1%);
  top: calc(var(--cursor-y, 50) * 1%);
  width: 58px;
  height: 58px;
  border: 1px solid rgba(14, 143, 156, 0.42);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition:
    opacity 160ms ease,
    border-color 160ms ease;
}

.gesture-cursor.is-visible {
  opacity: 1;
}

.gesture-cursor.is-locking {
  border-color: var(--amber);
}

.gesture-cursor span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--teal);
  box-shadow:
    0 0 0 7px rgba(14, 143, 156, 0.16),
    0 8px 20px rgba(16, 24, 32, 0.22);
  transform: translate(-50%, -50%);
}

.command-toast {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 7;
  max-width: min(340px, calc(100% - 36px));
  padding: 11px 13px;
  border: 1px solid rgba(16, 24, 32, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 16px 34px rgba(16, 24, 32, 0.18);
  color: #18232c;
  font-size: 13px;
  font-weight: 800;
}

.gesture-deck {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.gesture-deck div {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 3px 8px;
  align-items: center;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
}

.gesture-deck strong,
.gesture-deck small {
  min-width: 0;
}

.gesture-deck strong {
  font-size: 13px;
}

.gesture-deck small {
  grid-column: 2;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gesture-mark {
  position: relative;
  overflow: hidden;
  grid-row: span 2;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--teal);
  box-shadow: 0 0 0 5px rgba(14, 143, 156, 0.12);
}

.gesture-mark::before,
.gesture-mark::after {
  position: absolute;
  content: "";
}

.gesture-mark::before {
  inset: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
}

.gesture-mark::after {
  inset: 12px 6px 6px;
  border-top: 2px solid rgba(255, 255, 255, 0.86);
}

.gesture-mark.pinch {
  background: var(--amber);
  box-shadow: 0 0 0 5px rgba(183, 121, 31, 0.13);
}

.gesture-mark.pinch::before {
  inset: 7px 13px 13px 7px;
}

.gesture-mark.pinch::after {
  inset: 13px 7px 7px 13px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.88);
}

.gesture-mark.swipe {
  background: var(--blue);
  box-shadow: 0 0 0 5px rgba(22, 119, 199, 0.12);
}

.gesture-mark.swipe::before {
  inset: 12px 6px;
  border-radius: 99px;
}

.gesture-mark.swipe::after {
  inset: 8px 6px 8px auto;
  width: 9px;
  border: solid rgba(255, 255, 255, 0.88);
  border-width: 2px 2px 0 0;
  transform: rotate(45deg);
}

.gesture-mark.palm {
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(47, 157, 85, 0.12);
}

.gesture-mark.palm::before {
  inset: 6px;
  border-radius: 7px 7px 12px 12px;
}

.gesture-mark.palm::after {
  inset: 4px 8px auto;
  height: 9px;
  border: 0;
  border-right: 2px solid rgba(255, 255, 255, 0.72);
  border-left: 2px solid rgba(255, 255, 255, 0.72);
}

.gesture-mark.two {
  background: #4f8a2f;
  box-shadow: 0 0 0 5px rgba(79, 138, 47, 0.13);
}

.gesture-mark.two::before,
.gesture-mark.three::before {
  inset: 5px 8px auto;
  height: 18px;
  border-radius: 99px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.9) 0 38%, transparent 38% 62%, rgba(255, 255, 255, 0.9) 62%);
}

.gesture-mark.two::after {
  inset: auto 9px 5px;
  height: 7px;
  border: 0;
  border-radius: 0 0 99px 99px;
  background: rgba(255, 255, 255, 0.9);
}

.gesture-mark.three {
  background: var(--violet);
  box-shadow: 0 0 0 5px rgba(118, 86, 183, 0.13);
}

.gesture-mark.three::before {
  inset: 5px 6px auto;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.9) 0 25%, transparent 25% 37.5%, rgba(255, 255, 255, 0.9) 37.5% 62.5%, transparent 62.5% 75%, rgba(255, 255, 255, 0.9) 75%);
}

.gesture-mark.three::after {
  inset: auto 7px 5px;
  height: 7px;
  border: 0;
  border-radius: 0 0 99px 99px;
  background: rgba(255, 255, 255, 0.9);
}

.gesture-mark.fist {
  background: var(--charcoal);
  box-shadow: 0 0 0 5px rgba(26, 35, 45, 0.13);
}

.gesture-mark.fist::before {
  inset: 7px 6px 8px;
  border-radius: 8px 8px 10px 10px;
}

.gesture-mark.fist::after {
  inset: 8px 8px auto;
  height: 6px;
  border: 0;
  border-bottom: 2px solid rgba(16, 24, 32, 0.32);
  background: transparent;
}

.gesture-mark.zoom {
  background: var(--red);
  box-shadow: 0 0 0 5px rgba(199, 58, 49, 0.13);
}

.gesture-mark.zoom::before {
  inset: 5px 11px;
  border-radius: 99px;
}

.gesture-mark.zoom::after {
  inset: 6px auto auto 8px;
  width: 10px;
  height: 10px;
  border: solid rgba(255, 255, 255, 0.86);
  border-width: 2px 2px 0 0;
  transform: rotate(-45deg);
}

.control-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.control-panel > section {
  padding: 16px;
}

.panel-title {
  margin-bottom: 12px;
}

.panel-title.compact {
  margin-bottom: 10px;
}

.panel-title h2 {
  font-size: 18px;
}

.camera-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(14, 143, 156, 0.16), transparent 44%),
    #18232c;
}

.input-video,
#handCanvas,
.camera-mask {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.input-video,
#handCanvas {
  object-fit: cover;
  transform: scaleX(-1);
}

.input-video {
  opacity: 0.55;
}

.camera-mask {
  display: grid;
  place-items: center;
  background: rgba(16, 24, 32, 0.68);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  transition: opacity 160ms ease;
}

.camera-mask.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.permission-panel {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  background: color-mix(in srgb, var(--amber), white 92%);
}

.permission-panel.is-ok {
  border-left-color: var(--green);
  background: color-mix(in srgb, var(--green), white 93%);
}

.permission-panel.is-error {
  border-left-color: var(--red);
  background: color-mix(in srgb, var(--red), white 94%);
}

.permission-panel strong {
  color: #17222c;
  font-size: 13px;
}

.permission-panel span {
  color: #44525e;
  font-size: 12px;
  line-height: 1.55;
}

.detail-card {
  --detail-color: var(--teal);
  border-top: 4px solid var(--detail-color) !important;
}

.detail-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.category-pill,
.node-index {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: #27333c;
  font-size: 12px;
  font-weight: 800;
}

.category-pill {
  border-color: color-mix(in srgb, var(--detail-color), transparent 54%);
}

.detail-card h2 {
  margin-bottom: 10px;
  font-size: 26px;
  line-height: 1.18;
}

.detail-card p:last-of-type {
  margin-bottom: 0;
  color: #354451;
  font-size: 15px;
  line-height: 1.72;
}

.node-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 16px 0 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.node-metrics div {
  min-width: 0;
  padding: 11px 8px 11px 0;
}

.node-metrics div + div {
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.node-metrics dt {
  color: var(--muted);
  font-size: 11px;
}

.node-metrics dd {
  overflow: hidden;
  margin: 4px 0 0;
  color: #111820;
  font-size: 14px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.filter-grid button {
  --filter-color: var(--charcoal);
  min-width: 0;
  padding: 0 7px;
  background: #fff;
  color: #3d4953;
  font-size: 12px;
}

.filter-grid button.is-active {
  border-color: var(--filter-color);
  background: var(--filter-color);
  color: #fff;
}

.manual-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.manual-grid button {
  min-width: 0;
  padding: 0 7px;
  background: #fff;
  color: #26313b;
  font-size: 12px;
}

.manual-grid button:nth-child(6) {
  border-color: var(--teal);
  background: color-mix(in srgb, var(--teal), white 90%);
}

.manual-grid button.is-running {
  border-color: var(--red);
  background: color-mix(in srgb, var(--red), white 90%);
  color: #8f211b;
}

.command-log {
  display: grid;
  gap: 7px;
  max-height: 120px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  scrollbar-width: thin;
}

.command-log li {
  padding: 8px 9px;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: rgba(247, 249, 247, 0.88);
  color: #3d4a54;
  font-size: 12px;
  line-height: 1.45;
}

@media (prefers-reduced-motion: no-preference) {
  .flow-path {
    animation: flow-move 1.6s linear infinite;
  }

  .hotspot.is-active::before {
    animation: pulse 1.8s ease-in-out infinite;
  }
}

@keyframes flow-move {
  to {
    stroke-dashoffset: -46;
  }
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 10px color-mix(in srgb, var(--hotspot-color), transparent 92%);
  }
}

@media (max-width: 1180px) {
  .gesture-topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .top-actions {
    flex-wrap: wrap;
  }

  .command-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .gesture-topbar,
  .command-grid {
    padding-left: 12px;
    padding-right: 12px;
  }

  h1 {
    font-size: 24px;
  }

  .stage-header {
    align-items: stretch;
    flex-direction: column;
  }

  .status-strip {
    justify-content: stretch;
  }

  .status-strip span {
    flex: 1;
    text-align: center;
  }

  .gesture-deck,
  .filter-grid,
  .manual-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hotspot span {
    display: none;
  }

  .node-metrics {
    grid-template-columns: 1fr;
  }

  .node-metrics div {
    padding: 10px 0;
  }

  .node-metrics div + div {
    padding-left: 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}
