:root {
  --bar: rgba(20, 20, 20, 0.82);
  --text: #f5f5f5;
  --accent: #ffd400;
  --handle: #ffd400;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

#stage {
  position: fixed;
  inset: 0;
  touch-action: none;
  overflow: hidden;
}

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #222;
}

#overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#overlayImg {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  max-width: none;
  display: none;
  opacity: 0.5;
  will-change: transform;
}
#overlayImg.lines { filter: grayscale(1) contrast(2.2); }

#guides {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#guides polygon { fill: rgba(255, 212, 0, 0.08); stroke: var(--accent); stroke-width: 2; stroke-dasharray: 8 6; }
#guides circle { fill: var(--accent); }
#guides text { fill: #111; font-size: 14px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }

#handles { position: absolute; inset: 0; pointer-events: none; }
.handle {
  position: absolute;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
}
.handle::after {
  content: "";
  position: absolute;
  inset: 16px;
  border-radius: 50%;
  background: var(--handle);
  border: 3px solid #111;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.7);
}

/* Pantalla de inicio */
.panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #111;
  z-index: 50;
  padding: 24px;
}
.card { max-width: 440px; text-align: center; }
.card h1 { font-size: 44px; margin: 0 0 8px; letter-spacing: -0.02em; }
.card p { color: #cfcfcf; margin: 0 0 24px; }
.primary {
  font: inherit;
  font-weight: 700;
  font-size: 18px;
  padding: 16px 28px;
  border-radius: 999px;
  border: 0;
  background: var(--accent);
  color: #111;
}
.error { color: #ff8a80 !important; margin-top: 16px !important; }

/* Barra */
#toolbar {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border-radius: 20px;
  background: var(--bar);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  z-index: 20;
  max-width: calc(100vw - 24px);
  overflow-x: auto;
}
#toolbar[hidden] { display: none; }
.tool {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 14px;
  padding: 8px 12px;
  min-width: 64px;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  white-space: nowrap;
  cursor: pointer;
}
.tool .ico { font-size: 20px; line-height: 1; }
.tool.active { background: rgba(255, 212, 0, 0.22); color: var(--accent); }
.tool.lock { background: var(--accent); color: #111; font-weight: 700; }
.tool.slider { flex-direction: row; gap: 8px; min-width: 210px; cursor: default; }
.tool.slider input { width: 120px; accent-color: var(--accent); }
.tool.slider span:last-child { width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

#more {
  position: fixed;
  right: 16px;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 84px);
  display: flex;
  flex-direction: column;
  padding: 6px;
  border-radius: 16px;
  background: var(--bar);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  z-index: 21;
  min-width: 260px;
}
#more[hidden] { display: none; }
#more button {
  font: inherit;
  color: var(--text);
  background: transparent;
  border: 0;
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
}
#more button.on::after { content: " ✓"; color: var(--accent); }
#more button:active { background: rgba(255,255,255,0.1); }

#hint {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bar);
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 22;
  font-weight: 600;
  pointer-events: none;
  text-align: center;
  max-width: calc(100vw - 32px);
}

/* Desbloqueo */
#btnUnlock {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: rgba(20, 20, 20, 0.55);
  z-index: 30;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
  opacity: 0.6;
  touch-action: none;
}
#btnUnlock[hidden] { display: none; }
#btnUnlock svg { position: absolute; inset: 6px; width: 44px; height: 44px; transform: rotate(-90deg); }
#btnUnlock .ring {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-dasharray: 126;
  stroke-dashoffset: 126;
}
#btnUnlock.holding { opacity: 1; }
#btnUnlock.holding .ring { transition: stroke-dashoffset 0.8s linear; stroke-dashoffset: 0; }

#toast {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bar);
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 40;
  pointer-events: none;
}
.panel[hidden] { display: none; }
