/* Hand-control + tour UI layered on top of the Graphify viewer */
:root { --hg-accent: #7fdbca; --hg-warm: #ffd166; --hg-hot: #ff6b6b; }

#hg { position: fixed; left: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column-reverse; gap: 10px; align-items: flex-start; font-family: inherit; }
.hg-bar { display: flex; gap: 8px; }

.hg-btn {
  display: inline-flex; align-items: center; gap: 9px;
  min-height: 44px; padding: 0 18px 0 14px; border-radius: 999px;
  background: var(--panel); color: var(--text); border: 1px solid var(--input-border);
  font: 600 14px/1 inherit; letter-spacing: .01em; cursor: pointer;
  box-shadow: 0 6px 24px rgba(0,0,0,.35);
  transition: border-color .2s, transform .15s, background .2s;
}
.hg-btn:hover { border-color: var(--hg-accent); }
.hg-btn:active { transform: scale(.97); }
.hg-btn:focus-visible { outline: 2px solid var(--hg-accent); outline-offset: 3px; }
.hg-btn:disabled { opacity: .6; cursor: wait; }
.hg-btn[aria-pressed="true"] { border-color: var(--hg-accent); }
#hg-tour svg { color: var(--hg-accent); }
#hg-tour[aria-pressed="true"] { background: var(--hg-accent); color: #0f0f1a; }
#hg-tour[aria-pressed="true"] svg { color: #0f0f1a; }
.hg-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); transition: background .2s, box-shadow .2s; }
#hg.on .hg-dot { background: var(--hg-accent); box-shadow: 0 0 0 4px rgba(127,219,202,.22); animation: hg-pulse 1.6s ease-in-out infinite; }
@keyframes hg-pulse { 50% { box-shadow: 0 0 0 7px rgba(127,219,202,.08); } }

#hg-panel {
  width: 260px; max-height: calc(100dvh - 100px); overflow-y: auto; padding: 10px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--border);
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
#hg-panel[hidden], #hg-cam[hidden] { display: none; }
#hg-cam { position: relative; aspect-ratio: 4 / 3; border-radius: 9px; overflow: hidden; background: #000; margin-bottom: 8px; }
#hg-cam video, #hg-cam canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
#hg-cam video { opacity: .55; }
#hg-status { margin: 0 2px 6px; font-size: 12px; color: var(--text); min-height: 1.3em; }
#hg-help { list-style: none; font-size: 11.5px; line-height: 1.45; color: var(--text-2); display: grid; gap: 3px; padding: 0 2px; }
#hg-help b { color: var(--text); font-weight: 600; }

.hg-small-btn { width: 100%; margin-top: 8px; min-height: 36px; border-radius: 9px; border: 1px solid var(--input-border); background: var(--bg); color: var(--text); font: 600 12.5px inherit; cursor: pointer; }
.hg-small-btn:hover, .hg-small-btn:focus-visible { border-color: var(--hg-accent); outline: none; }
#hg-cal-state { color: var(--hg-accent); font-weight: 600; }
.hg-teach { margin-top: 8px; padding: 10px; border-radius: 10px; background: rgba(127,219,202,.1); border: 1px solid var(--hg-accent); font-size: 12.5px; color: var(--text); }
.hg-teach[hidden] { display: none; }
.hg-teach-bar { height: 6px; border-radius: 3px; background: var(--border); margin-top: 8px; overflow: hidden; }
.hg-teach-bar i { display: block; height: 100%; width: 0; background: var(--hg-accent); transition: width .1s linear; }
#hg-gestures { margin-top: 8px; font-size: 12px; color: var(--text-2); }
#hg-gestures summary { cursor: pointer; color: var(--text); font-weight: 600; padding: 4px 2px; list-style-position: inside; }
#hg-gestures ul { margin-top: 4px; }
#hg-settings { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; font-size: 12px; color: var(--text-2); }
#hg-settings summary { cursor: pointer; color: var(--text); font-weight: 600; padding: 4px 2px; list-style-position: inside; }
#hg-settings label { display: grid; grid-template-columns: 44px auto 1fr auto; align-items: center; gap: 6px; padding: 6px 2px; }
#hg-settings .hg-ends { font-size: 10.5px; color: var(--muted); }
#hg-settings input[type=range] { width: 100%; accent-color: var(--hg-accent); min-height: 24px; }
#hg-settings .hg-check { display: flex; gap: 8px; }
#hg-settings input[type=checkbox] { accent-color: var(--hg-accent); width: 16px; height: 16px; }

/* on-screen hand cursor */
.hg-cursor { position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none; width: 0; height: 0; will-change: transform; }
.hg-cursor[hidden] { display: none; }
.hg-cursor svg { position: absolute; width: 44px; height: 44px; left: -22px; top: -22px; overflow: visible; transition: transform .12s; }
.hg-ring { fill: rgba(127,219,202,.12); stroke: var(--hg-accent); stroke-width: 2.5; }
.hg-prog { fill: none; stroke: var(--hg-hot); stroke-width: 4; stroke-linecap: round;
  stroke-dasharray: 113.1; stroke-dashoffset: calc(113.1 * (1 - var(--prog, 0)));
  transform: rotate(-90deg); transform-origin: 22px 22px; }
.hg-cursor[data-prog="dwell"] .hg-prog { stroke: var(--hg-accent); }
.hg-cursor[data-prog=""] .hg-prog { stroke: none; }
.hg-cursor.is-node .hg-ring { stroke: #fff; fill: rgba(255,255,255,.18); }
/* the inner dot grows as your fingers close — you see the click coming */
.hg-fill { fill: var(--hg-warm); opacity: calc(.15 + var(--close, 0) * .55); transform: scale(calc(var(--close, 0) * .78)); transform-origin: 22px 22px; transition: transform .06s linear; }
.hg-cursor.is-ui .hg-ring { stroke: #fff; stroke-width: 3; fill: rgba(127,219,202,.22); }
.hg-ui-hover { outline: 2px solid var(--hg-accent) !important; outline-offset: 2px !important; box-shadow: 0 0 0 6px rgba(127,219,202,.22), 0 0 18px rgba(127,219,202,.45) !important; transition: box-shadow .12s, outline-color .12s; }
.hg-cursor.is-pinch svg { transform: scale(.62); }
.hg-cursor.is-pinch .hg-ring { fill: rgba(255,209,102,.35); stroke: var(--hg-warm); }
.hg-tip { position: absolute; left: 20px; top: 16px; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis;
  font-size: 12px; font-weight: 600; color: #fff; background: rgba(15,15,26,.88); padding: 3px 8px; border-radius: 6px; }
.hg-tip:empty { display: none; }

/* guided tour card */
#tour {
  position: fixed; z-index: 55; top: 16px; left: 16px; width: min(400px, calc(100vw - 32px - 280px));
  background: color-mix(in srgb, var(--panel) 94%, transparent); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-left: 4px solid var(--hg-accent); border-radius: 14px;
  padding: 14px 16px 12px; box-shadow: 0 12px 48px rgba(0,0,0,.45); color: var(--text);
  animation: tour-in .28s ease-out;
}
#tour[hidden] { display: none; }
@keyframes tour-in { from { opacity: 0; transform: translateY(-8px); } }
.tour-top { display: flex; align-items: center; gap: 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--hg-accent); font-weight: 700; }
.tour-count { color: var(--muted); font-weight: 600; margin-left: auto; }
.tour-x { background: none; border: 0; color: var(--text-2); font-size: 15px; cursor: pointer; width: 32px; height: 32px; border-radius: 8px; }
.tour-x:hover { background: var(--border); color: var(--text); }
.tour-title { font-size: 21px; line-height: 1.2; margin: 2px 0 4px; font-weight: 700; overflow-wrap: anywhere; }
.tour-sub { font-size: 12px; color: var(--text-2); margin-bottom: 8px; overflow-wrap: anywhere; }
.tour-body { font-size: 13px; line-height: 1.55; color: var(--text-3); }
.tour-body p + p { margin-top: 6px; }
.tour-body b { color: var(--text); }
.tour-chips { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tour-chips li { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tour-chips span { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.tour-nav { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.tour-nav button { min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--input-border); background: var(--bg); color: var(--text); font: 600 13px inherit; cursor: pointer; }
.tour-nav button:disabled { opacity: .4; cursor: default; }
.tour-next { background: var(--hg-accent) !important; color: #0f0f1a !important; border-color: var(--hg-accent) !important; margin-left: auto; }
.tour-hint { font-size: 11px; color: var(--muted); }
.tour-x:focus-visible, .tour-nav button:focus-visible { outline: 2px solid var(--hg-accent); outline-offset: 2px; }

/* phones: stack the sidebar under the graph instead of beside it */
@media (max-width: 760px) {
  body { flex-direction: column; height: 100dvh; }
  #graph { flex: 1 1 auto; min-height: 0; }
  #sidebar { width: 100%; height: 36dvh; border-left: 0; border-top: 1px solid var(--border); overflow-y: auto; }
  #sidebar > * { flex-shrink: 0; }
  #legend-wrap { flex: none; overflow: visible; }
  #hg { left: 12px; bottom: calc(36dvh + 12px); }
  #hg-panel { width: min(260px, calc(100vw - 24px)); max-height: calc(64dvh - 90px); }
  #tour { top: 10px; left: 10px; width: calc(100vw - 20px); padding: 12px 14px 10px; }
  .tour-title { font-size: 18px; }
  .tour-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  #hg.on .hg-dot, #tour { animation: none; }
  .hg-cursor svg { transition: none; }
}

/* which hand is which: 🖱 = mouse hand, ✋ = view hand (shown when both hands are in view) */
.hg-badge { position: absolute; left: 12px; top: -30px; font-size: 13px; line-height: 1; padding: 3px 5px; border-radius: 7px; background: rgba(15,15,26,.88); border: 1px solid var(--hg-accent); }
.hg-badge:empty { display: none; }
.hg-cursor.is-view .hg-ring { stroke: var(--hg-warm); stroke-dasharray: 5 5; fill: rgba(255,209,102,.08); }
.hg-cursor.is-view .hg-badge { border-color: var(--hg-warm); }
.hg-cursor.is-view .hg-fill { fill: var(--hg-warm); }

/* ghost hand: your fingers drawn live under the pointer */
.hg-ghost { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 58; pointer-events: none; }
.hg-state { position: absolute; left: 50%; top: 26px; transform: translateX(-50%); white-space: nowrap; font: 600 11.5px/1 var(--sans, system-ui); color: #fff;
  background: rgba(15,15,26,.85); padding: 4px 8px; border-radius: 999px; border: 1px solid rgba(255,255,255,.15); }
.hg-state:empty { display: none; }
.hg-state[data-k="ok"] { border-color: var(--hg-accent); color: var(--hg-accent); }
.hg-state[data-k="warm"] { border-color: var(--hg-warm); color: var(--hg-warm); }
.hg-state[data-k="bad"] { border-color: var(--hg-hot); color: #ff8fb0; }

/* 🎯 Train my gestures */
.hg-train { position: fixed; inset: 0; z-index: 57; display: grid; place-items: center; padding: 20px; background: rgba(5,8,18,.55); backdrop-filter: blur(2px); pointer-events: none; }
.hg-train[hidden] { display: none; }
.hg-train-card { pointer-events: auto; width: min(460px, 100%); padding: 20px 22px; border-radius: 18px; background: color-mix(in srgb, var(--panel) 96%, transparent);
  border: 1px solid var(--input-border); border-top: 4px solid var(--hg-accent); box-shadow: 0 30px 80px rgba(0,0,0,.55); color: var(--text); text-align: center; }
.hg-train-top { display: flex; align-items: center; justify-content: space-between; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--hg-accent); font-weight: 700; }
.hg-train-x { background: none; border: 0; color: var(--text-2); font-size: 16px; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; }
.hg-train-x:hover { background: var(--border); color: var(--text); }
.hg-train-big { font-size: 64px; line-height: 1.1; margin: 6px 0 2px; }
.hg-train-card h2 { font-size: 22px; }
.hg-train-how { color: var(--text); font-weight: 600; margin: 4px 0 8px; }
.hg-train-turn { color: var(--text-2); font-size: 13.5px; line-height: 1.5; }
.hg-spin { display: inline-block; color: var(--hg-accent); animation: hg-spin 2.4s linear infinite; }
@keyframes hg-spin { to { transform: rotate(360deg); } }
.hg-train-bar { height: 10px; border-radius: 5px; background: var(--border); overflow: hidden; margin: 14px 0 6px; }
.hg-train-bar i { display: block; height: 100%; background: var(--hg-accent); transition: width .15s linear; }
.hg-train-msg { font-size: 12.5px; color: var(--text-2); min-height: 1.4em; }
.hg-train-steps { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 12px; font-size: 12px; }
.hg-train-steps li { padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.hg-train-steps li.now { border-color: var(--hg-accent); color: var(--text); }
.hg-train-steps li.done { color: var(--hg-accent); }
.hg-train-score { font: 700 56px/1 var(--mono, monospace); margin: 10px 0 6px; }
.hg-train-score.ok { color: var(--hg-accent); } .hg-train-score.bad { color: #ff8fb0; }
.hg-train-acc { list-style: none; display: grid; gap: 6px; margin: 12px 0; text-align: left; }
.hg-train-acc li { display: grid; grid-template-columns: 130px 1fr 42px; gap: 8px; align-items: center; font-size: 12.5px; color: var(--text-2); }
.hg-train-acc i { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; } .hg-train-acc em { display: block; height: 100%; background: var(--hg-accent); }
.hg-train-acc b { text-align: right; color: var(--text); font-family: var(--mono, monospace); }
.hg-train-tips { text-align: left; font-size: 12.5px; color: var(--text-2); padding-left: 18px; display: grid; gap: 4px; }
.hg-train-actions { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.hg-train-actions .hg-small-btn { width: auto; padding: 0 16px; }
.hg-small-btn.hg-primary { background: var(--hg-accent); color: #0f0f1a; border-color: var(--hg-accent); }
#hg-train-state { color: var(--hg-accent); font-weight: 600; }
.hg-del { color: #ff8fb0; }
@media (prefers-reduced-motion: reduce) { .hg-spin { animation: none; } }
