:root {
  --ink: #03050c;
  --panel: rgba(10, 16, 32, 0.78);
  --panel-solid: #0b1224;
  --line: rgba(150, 185, 255, 0.18);
  --text: #eaf0ff;
  --muted: #9dabc9;
  --lamp: #ffc14d;
  --lamp-ink: #2a1c00;
  --glow: #7be0ff;
  --r-s: 10px;
  --r-m: 16px;
  --r-l: 24px;
  --font: "Readex Pro", system-ui, "Segoe UI", Tahoma, Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--ink); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.6;
  overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }
h1, h2, p { margin: 0; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#stage.grabbing { cursor: grabbing; }
#stage.pointing { cursor: pointer; }
#leaders { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#leaders line { stroke-width: 1; opacity: 0.55; }
#labels { position: fixed; inset: 0; pointer-events: none; }
.label {
  position: absolute; top: 0; left: 0; pointer-events: auto; white-space: nowrap; font-size: 12.5px; font-weight: 500; line-height: 1;
  padding: 6px 10px; border-radius: 999px; background: rgba(6, 10, 22, 0.82); border: 1px solid var(--c, var(--line)); color: var(--text);
  will-change: transform, opacity;
}
.label:hover { background: var(--panel-solid); }

/* hand cursor */
#cursor {
  position: fixed; top: 0; left: 0; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; pointer-events: none; z-index: 30;
  background: conic-gradient(var(--lamp) calc(var(--p, 0) * 1turn), rgba(255, 255, 255, 0.22) 0);
  -webkit-mask: radial-gradient(circle, transparent 15px, #000 16px); mask: radial-gradient(circle, transparent 15px, #000 16px);
}

/* top bar */
.bar {
  position: fixed; inset-inline: 0; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: linear-gradient(to bottom, rgba(3, 5, 12, 0.85), rgba(3, 5, 12, 0));
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 16px; }
.brand svg { color: var(--glow); }
.bar-actions { display: flex; gap: 8px; }
.chip-btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 7px 14px; font-size: 13.5px; font-weight: 500;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.chip-btn:hover { border-color: rgba(150, 185, 255, 0.45); }
.chip-btn.lamp { background: var(--lamp); color: var(--lamp-ink); border-color: transparent; font-weight: 600; }

/* model title */
.title { position: fixed; z-index: 5; top: calc(58px + var(--safe-t)); inset-inline: 16px; pointer-events: none; max-width: 30rem; }
.title-cat { color: var(--glow); font-size: 13px; font-weight: 500; }
.title h1 { font-size: clamp(26px, 5.2vw, 46px); font-weight: 300; line-height: 1.25; letter-spacing: 0; text-wrap: balance; }
.title-fact { color: var(--muted); font-size: 13.5px; margin-top: 4px; }

/* tool rail */
.tools {
  position: fixed; z-index: 9; display: flex; gap: 6px; padding: 6px; border-radius: var(--r-l); background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  inset-inline: 10px; bottom: calc(86px + var(--safe-b)); justify-content: space-between;
}
.tools button {
  flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 2px 6px; border: 0; background: transparent;
  border-radius: 18px; color: var(--muted); font-size: 11px; font-weight: 500; line-height: 1.2;
}
.tools svg, .round svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tools button[aria-pressed="true"] { color: var(--lamp-ink); background: var(--lamp); }
.tools button:hover:not([aria-pressed="true"]) { color: var(--text); background: rgba(150, 185, 255, 0.1); }

/* bottom dock */
.dock {
  position: fixed; z-index: 9; inset-inline: 10px; bottom: calc(10px + var(--safe-b)); padding: 8px 10px; border-radius: var(--r-l);
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.dock-row { display: flex; align-items: center; gap: 10px; }
.slice-row { padding: 2px 6px 8px; font-size: 12.5px; color: var(--muted); }
.slice-row input { flex: 1; }
.round { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); background: transparent; }
.round:hover { background: rgba(150, 185, 255, 0.1); }
[dir="rtl"] .round svg { transform: scaleX(-1); }
.explode { flex: 1; min-width: 0; }
.explode-ends { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); line-height: 1; margin-bottom: 2px; }
.models-btn { flex: none; padding: 11px 16px; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--glow), var(--lamp)); }
[dir="rtl"] input[type="range"]::-webkit-slider-runnable-track { background: linear-gradient(to left, var(--glow), var(--lamp)); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--glow), var(--lamp)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9px; border-radius: 50%; background: #fff; border: 4px solid var(--panel-solid); box-shadow: 0 0 0 1.5px var(--lamp); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 4px solid var(--panel-solid); box-shadow: 0 0 0 1.5px var(--lamp); }

/* part info */
.info {
  position: fixed; z-index: 12; inset-inline: 10px; bottom: calc(160px + var(--safe-b)); padding: 16px 18px 16px; border-radius: var(--r-m);
  background: var(--panel-solid); border: 1px solid var(--line); border-inline-start: 4px solid var(--c, var(--lamp));
  max-height: 42vh; overflow: auto;
}
.info-close { position: absolute; top: 8px; inset-inline-end: 8px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; }
.info-close:hover { color: var(--text); background: rgba(150, 185, 255, 0.1); }
.info-of { color: var(--muted); font-size: 12.5px; padding-inline-end: 36px; }
.info h2 { font-size: 22px; font-weight: 500; line-height: 1.35; margin-top: 2px; }
.info-alt { color: var(--c, var(--glow)); font-size: 13.5px; direction: ltr; unicode-bidi: plaintext; text-align: start; }
.info-text { margin: 10px 0 14px; max-width: 34rem; }

/* hand HUD */
.hand { position: fixed; z-index: 8; top: calc(58px + var(--safe-t)); inset-inline-end: 12px; width: 132px; text-align: center; }
.hand-video { position: relative; border-radius: var(--r-s); overflow: hidden; border: 1px solid var(--line); background: #000; aspect-ratio: 4 / 3; }
.hand-video video, .hand-video canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.hand-video video { opacity: 0.55; }
#handState { margin-top: 6px; font-size: 12.5px; font-weight: 500; padding: 4px 8px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); }

/* quiz */
.quiz {
  position: fixed; z-index: 11; top: calc(58px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: min(92vw, 30rem); text-align: center;
  padding: 14px 16px; border-radius: var(--r-m); background: var(--panel-solid); border: 1px solid var(--lamp);
}
#quizText { font-size: 18px; font-weight: 500; }
.quiz-score { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.quiz-actions { display: flex; gap: 8px; justify-content: center; }
body.quiz-on .title { display: none; }

/* sheets */
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; background: rgba(2, 4, 10, 0.6); }
.sheet-card {
  width: min(100%, 52rem); max-height: 82vh; overflow: auto; padding: 18px 18px calc(22px + var(--safe-b)); background: var(--panel-solid);
  border: 1px solid var(--line); border-bottom: 0; border-radius: var(--r-l) var(--r-l) 0 0;
}
.sheet-card.narrow { width: min(100%, 34rem); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: relative; margin-bottom: 12px; }
.sheet-head h2 { font-size: 20px; font-weight: 500; }
.sheet-head .info-close { position: static; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 12px; scrollbar-width: none; }
.tabs button { flex: none; border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 14px; font-size: 13.5px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--text); color: var(--ink); border-color: transparent; font-weight: 500; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card { text-align: start; padding: 14px; border-radius: var(--r-m); border: 1px solid var(--line); background: rgba(150, 185, 255, 0.05); display: flex; flex-direction: column; gap: 6px; min-height: 124px; }
.card:hover { border-color: rgba(150, 185, 255, 0.5); }
.card[aria-current="true"] { border-color: var(--lamp); }
.card-ico { font-size: 30px; line-height: 1; }
.card-name { font-weight: 500; line-height: 1.4; }
.card-meta { color: var(--muted); font-size: 12.5px; margin-top: auto; }
.help-list { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; align-items: baseline; }
.help-list dt { font-weight: 500; color: var(--lamp); white-space: nowrap; }
.help-list dd { margin: 0; color: var(--text); }
.credits { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; }

/* welcome */
.welcome { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at center, rgba(3, 5, 12, 0.55), rgba(3, 5, 12, 0.92)); overflow: auto; }
.welcome-card { width: min(100%, 36rem); padding: 26px 22px 20px; border-radius: var(--r-l); background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.welcome-card h2 { font-size: clamp(26px, 6vw, 38px); font-weight: 300; line-height: 1.3; text-wrap: balance; }
.welcome-lead { color: var(--muted); margin-top: 8px; max-width: 32rem; }
.gestures { list-style: none; margin: 18px 0; padding: 0; display: grid; gap: 12px; }
.gestures li { display: flex; gap: 12px; align-items: flex-start; }
.g-ico { flex: none; width: 42px; height: 42px; display: grid; place-items: center; font-size: 22px; border-radius: 50%; border: 1px solid var(--line); background: rgba(150, 185, 255, 0.06); }
.gestures strong { display: block; font-weight: 500; }
.gestures div span { color: var(--muted); font-size: 14px; }
.welcome-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.cta { flex: 1 1 12rem; padding: 13px 18px; border-radius: 999px; border: 0; background: var(--lamp); color: var(--lamp-ink); font-weight: 600; font-size: 16px; }
.cta.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
.cta:hover { filter: brightness(1.08); }
.welcome-note { color: var(--muted); font-size: 12.5px; margin-top: 12px; }

.toast {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(170px + var(--safe-b)); width: max-content; max-width: min(92vw, 34rem);
  padding: 10px 16px; border-radius: var(--r-m); background: var(--panel-solid); border: 1px solid var(--lamp); font-size: 14px; text-align: center;
}

/* wide screens: rail on the side, info as a side card */
@media (min-width: 820px) {
  .bar { padding-inline: 22px; }
  .title { inset-inline: 26px auto; top: calc(70px + var(--safe-t)); }
  .tools { inset-inline: auto 18px; top: 50%; bottom: auto; transform: translateY(-50%); flex-direction: column; width: 78px; }
  .tools button { padding: 10px 2px 8px; }
  .dock { inset-inline: 50% auto; width: min(44rem, calc(100vw - 240px)); transform: translateX(-50%); bottom: calc(18px + var(--safe-b)); padding: 10px 14px; }
  [dir="rtl"] .dock { transform: translateX(50%); }
  .info { inset-inline: 26px auto; bottom: auto; top: 50%; transform: translateY(-40%); width: 22rem; max-height: 60vh; padding: 20px 22px; }
  .hand { inset-inline-end: 112px; top: calc(70px + var(--safe-t)); width: 176px; }
  .sheet { align-items: center; }
  .sheet-card { border-radius: var(--r-l); border-bottom: 1px solid var(--line); padding-bottom: 22px; }
  .toast { bottom: calc(110px + var(--safe-b)); }
}
@media (max-width: 819px) {
  body.cam-on .title { padding-inline-end: 140px; }
}
@media (max-height: 520px) {
  .title h1 { font-size: 24px; }
  .gestures { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
