/*
  Pose Editor: a dark, neutral tool shell so the only colour on screen is the
  OpenPose skeleton. Graphite greys for chrome, light fill for whatever is
  active or primary, orange only for pins (matches OVERLAY.pinColor).
*/

:root {
  --bg: #16181c;
  --panel: #1d2025;
  --raised: #272b31;
  --raised-hover: #31363d;
  --line: #2e3238;
  --text: #e3e6ea;
  --muted: #8b929c;
  --active-bg: #e3e6ea;
  --active-text: #16181c;
  --pin: #f97316;

  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --text-sm: 12px;
  --text-md: 13px;
  --radius: 6px;
  --control-h: 30px;
  --toolbar-h: 48px;
  --panel-w: 280px;
  --gap: 8px;
  --pad: 16px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--text-md) / 1.4 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

body {
  overflow: hidden;
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

[hidden] {
  display: none !important;
}

/* ---- Shell ------------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  grid-template-rows: var(--toolbar-h) minmax(0, 1fr);
  grid-template-areas:
    "toolbar toolbar"
    "workspace panel";
  height: 100dvh;
}

.toolbar {
  grid-area: toolbar;
  display: flex;
  align-items: center;
  gap: var(--pad);
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.wordmark {
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.tool-group-end {
  margin-left: auto;
  gap: var(--gap);
}

.workspace {
  grid-area: workspace;
  container-type: size;
  display: grid;
  place-items: center;
  min-height: 0;
}

.panel {
  grid-area: panel;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

/* ---- Canvas ------------------------------------------------------------ */

/* Largest square that fits the workspace, with breathing room around it. */
.canvas-frame {
  --frame-padding: 0px;
  position: relative;
  width: min(100cqw - 2 * var(--pad), 100cqh - 2 * var(--pad));
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

/* Pan / zoom stage (canvasViewport.js): transformed from its top left corner. */
.canvas-stage {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  touch-action: none;
}

/* Empty space pans once zoomed in, and anywhere while the pan key is held. */
.canvas-frame.is-zoomed #poseCanvas,
.canvas-frame.is-panning #poseCanvas {
  cursor: grab;
}

/* Three stacked layers (see SkeletonCanvas): grid below, pose canvas, then
   the interaction overlay. Only the pose canvas takes input. */
.canvas-frame canvas {
  position: absolute;
  inset: var(--frame-padding);
  display: block;
  width: calc(100% - 2 * var(--frame-padding));
  height: calc(100% - 2 * var(--frame-padding));
}

#poseCanvas {
  z-index: 1;
  /* Pointer Events handle touch; stop the browser from scrolling/zooming. */
  touch-action: none;
}

canvas.pose-overlay {
  z-index: 2;
  pointer-events: none;
}

/* Tool shelf: a column of tool buttons over the canvas's top left corner,
   outside the pan / zoom stage so it stays put; the active tool lit. */
.tool-shelf {
  position: absolute;
  top: var(--gap);
  left: var(--gap);
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  background: var(--panel);
}

/* :hover too, so a tapped button (touch keeps :hover) still shows as active. */
.tool-shelf .icon-btn[aria-pressed="true"],
.tool-shelf .icon-btn[aria-pressed="true"]:hover {
  background: var(--active-bg);
  color: var(--active-text);
}

/* Shelf tooltips open to the right, over the canvas. */
.tool-shelf [data-tip]:hover::after,
.tool-shelf [data-tip]:focus-visible::after {
  top: 50%;
  left: calc(100% + 8px);
  transform: translateY(-50%);
}

/* ---- Controls ---------------------------------------------------------- */

.btn,
.icon-btn,
.segmented-btn {
  appearance: none;
  height: var(--control-h);
  border: 0;
  border-radius: var(--radius);
  background: var(--raised);
  cursor: pointer;
  touch-action: manipulation;
}

.btn {
  padding: 0 12px;
  font-weight: 500;
  white-space: nowrap;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: var(--control-h);
  padding: 0;
  background: transparent;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn:hover:not(:disabled),
.icon-btn:hover:not(:disabled),
.segmented-btn:hover:not([aria-pressed="true"]) {
  background: var(--raised-hover);
}

.btn:disabled,
.icon-btn:disabled {
  color: var(--muted);
  opacity: 0.5;
  cursor: default;
}

.btn-primary,
.btn-primary:hover:not(:disabled) {
  background: var(--active-bg);
  color: var(--active-text);
}

.btn-pin {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--pin);
  color: var(--pin);
}

/* Segmented switch: one track, the pressed option lit. */
.segmented {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: calc(var(--radius) + 2px);
  background: var(--bg);
}

.segmented-btn {
  min-width: 52px;
  padding: 0 12px;
  background: transparent;
  font-weight: 500;
  color: var(--muted);
}

.segmented-btn[aria-pressed="true"] {
  background: var(--active-bg);
  color: var(--active-text);
}

.field {
  width: 100%;
  height: var(--control-h);
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}

/* Tooltips: name + shortcut for controls, shown on hover or keyboard focus. */
[data-tip] {
  position: relative;
}

[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--text);
  color: var(--bg);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: pre;
  pointer-events: none;
}

/* ---- Properties panel -------------------------------------------------- */

.panel-section {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--pad);
  border-bottom: 1px solid var(--line);
}

.panel-title {
  margin: 0 0 4px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--muted);
}

.btn-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
}

.key-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--gap);
}

.key-row .btn {
  display: inline-flex;
  align-items: center;
  color: var(--text);
  text-decoration: none;
}

.slider-row {
  display: grid;
  grid-template-columns: 48px 1fr 28px;
  align-items: center;
  gap: var(--gap);
}

.slider-row output {
  text-align: right;
  color: var(--muted);
}

/* Collapsible section: the title is the toggle. */
.panel-details > summary {
  margin: 0;
  cursor: pointer;
}

.panel-details:not([open]) {
  gap: 0;
}

.panel-details > .btn {
  width: 100%;
}

.view-sliders {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* Depth sliders: longer labels ("Right hand") and signed values. */
.view-sliders .slider-row {
  grid-template-columns: 72px 1fr 32px;
}

.panel-note {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--muted);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--text);
}

.check-row {
  display: flex;
  align-items: center;
  gap: var(--gap);
  color: var(--muted);
}

.check-row input {
  accent-color: var(--text);
}

/* Reference image: the whole tile is the file picker and a drop target. */
.drop-zone {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  overflow: hidden;
}

.drop-zone:hover,
.drop-zone.is-over,
.drop-zone:focus-within {
  border-color: var(--muted);
  color: var(--text);
}

.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-zone img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.drop-zone img:not([hidden]) + .drop-zone-empty {
  display: none;
}

.status:empty {
  display: none;
}

.status {
  color: var(--muted);
  font-size: var(--text-sm);
}

.result-image {
  width: 100%;
  border-radius: var(--radius);
}

/* ---- Shortcuts popover ------------------------------------------------- */

.shortcuts-panel {
  margin: calc(var(--toolbar-h) + 4px) 12px auto auto;
  padding: var(--pad);
  width: min(360px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.45);
}

.shortcut-list {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px var(--pad);
  margin: 0;
}

.shortcut-list dt {
  color: var(--text);
}

.shortcut-list dd {
  margin: 0;
  color: var(--muted);
  text-align: right;
}

/* ---- Narrow screens: canvas on top, panel scrolls below ----------------- */

@media (max-width: 768px) {
  :root {
    --pad: 12px;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--toolbar-h) min(100vw, 60dvh) minmax(0, 1fr);
    grid-template-areas:
      "toolbar"
      "workspace"
      "panel";
  }

  .toolbar {
    gap: var(--gap);
    padding: 0 8px;
  }

  /* Tight enough that the toolbar shares one row at 390px. */
  .segmented-btn {
    min-width: 0;
    padding: 0 6px;
  }

  /* Finger-sized tool buttons. */
  .tool-shelf .icon-btn {
    width: 36px;
    height: 36px;
  }

  /* Keyboard shortcuts panel: no keyboard on phones. */
  .shortcuts-btn {
    display: none;
  }

  .wordmark {
    display: none;
  }

  .panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  /* Hover tooltips don't exist on touch. */
  [data-tip]::after {
    display: none;
  }
}

/* The 3D surface occupies the same square framing as the 2D canvas. */
#scene3d { position: relative; width: 100%; aspect-ratio: 1; }

/* 2D-only tools (TOOLS scope) leave the shelf in 3D. */
.app[data-mode="3d"] .tool-shelf [data-tool="free"] { display: none; }

/* Corner axis gizmo (mode3d/axisGizmo.js): world axes as the camera sees them;
   click an end to look from that side. */
.axis-gizmo {
  position: absolute;
  top: var(--gap);
  right: var(--gap);
  z-index: 3;
  border-radius: 50%;
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  overflow: visible;
}
.axis-gizmo line { stroke-width: 2; }
.axis-gizmo-end { cursor: pointer; }
.axis-gizmo text {
  fill: var(--bg);
  font: 600 10px var(--font);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}
#scene3d[hidden] { display: none; }
#scene3d canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* Small phones (360px): a little less spacing so the toolbar stays on one row. */
@media (max-width: 380px) {
  .toolbar {
    gap: 4px;
  }

  .toolbar .icon-btn {
    width: 26px;
  }

  .btn {
    padding: 0 8px;
  }
}
