/* Wizard styles are scoped; the camera/detection/scoring UI is unchanged. */
/* Guided screens have one continuation path; retain legacy Next in classic mode. */
body[data-setup-guided-screen="true"] #step1Next,
body[data-setup-guided-screen="true"] #step2Next,
body[data-setup-guided-screen="true"] #step3Next {
  display: none !important;
}
#setupWizard, #setupWizard * { box-sizing: border-box; }
#setupWizard {
  --sw-muted: #a3ad9c;
  color: #f0f2e9; background: #111411;
  max-width: 1110px; margin: 0 auto; padding: 38px 24px 48px;
}
#setupWizard[hidden], #setupWizardBar[hidden],
body[data-setup-wizard="open"] #main, body[data-setup-wizard="open"] #stepper { display: none !important; }
#setupWizardBar { max-width: 900px; margin: 12px auto 0; padding: 0 24px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
#setupWizardBar small { color: var(--muted); }
.sw-top { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 20px; }
.sw-kicker { color: #a5d95a; font: 600 .66rem monospace; letter-spacing: .1em; }
#setupWizard h1 { font-size: clamp(2rem, 5vw, 3.4rem); letter-spacing: -.04em; margin: 12px 0 8px; }
#setupWizard p { font-size: .87rem; color: var(--sw-muted); line-height: 1.6; }
#setupWizard button { color: #daebc6; background: #222b20; border: 1px solid #506744; padding: 8px 12px; font-size: .79rem; }
#setupWizard button:hover:not(:disabled) { background: #30402a; }
#setupWizard .sw-format[aria-pressed="true"] { border-color: #a5d95a; background: #263121; }
#setupWizard button:focus-visible, #setupWizard input:focus-visible, #setupWizard summary:focus-visible { outline: 2px solid #c1eb7a; outline-offset: 3px; }
.sw-levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px; border: 1px solid #30372f; border-radius: 13px; margin: 26px 0; }
#setupWizard .sw-levels button { min-width: 0; text-align: left; padding: 12px 13px; background: #191d19; border-color: transparent; }
#setupWizard .sw-levels button[aria-pressed="true"] { border-color: #a5d95a; background: #263121; }
.sw-level { position: relative; display: flex; align-items: center; gap: 10px; }
.sw-level-number { display: grid; width: 29px; height: 29px; flex: 0 0 29px; place-items: center; border: 1px solid #58614f; border-radius: 50%; color: #b8c3ac; font: 600 .67rem monospace; }
.sw-level[aria-pressed="true"] .sw-level-number { color: #192016; border-color: #a5d95a; background: #a5d95a; }
.sw-level-name { display: block; min-width: 0; padding-right: 20px; }
.sw-level strong, .sw-level small { display: block; overflow-wrap: anywhere; }
.sw-level strong { font-size: .84rem; }
.sw-level small { margin-top: 5px; color: var(--sw-muted); font-size: .69rem; }
.sw-level-arrow { position: absolute; right: -15px; z-index: 1; color: #a5d95a; font-size: 1.25rem; line-height: 1; pointer-events: none; }
.sw-layout { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(230px, .8fr); gap: 18px; align-items: start; }
.sw-panel, .sw-aside { padding: 24px; background: #191d19; border: 1px solid #30372f; border-radius: 13px; }
#setupWizard h2 { margin: 0 0 8px; font-size: 1.65rem; color: #f0f2e9; text-transform: none; letter-spacing: -.02em; }
/*
 * Open Setup Wizard and the guided Return action share the screen-title row.
 * Header placement is independent of guided mode: classic controls stay classic.
 */
body:not([data-setup-step-header="true"]) .sw-step-heading { display: contents; }
body[data-setup-step-header="true"] .sw-step-heading {
  position: sticky;
  top: 8px;
  z-index: 20;
  background: #111411;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  width: 100%;
  min-width: 0;
  align-items: center;
  column-gap: 16px;
  margin: 0 0 12px;
}
body[data-setup-step-header="true"] .sw-step-heading > h2 {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  margin: 0;
}
#setupWizardBar {
  --sw-accent: #a5d95a;
  --sw-ink: #182016;
  width: 100%;
  max-width: 900px;
  min-width: 0;
  margin: 10px auto 18px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
#setupWizardBar[hidden] { display: none !important; }
body[data-setup-step-header="true"] #setupWizardBar {
  display: contents;
}
body[data-setup-step-header="true"] #setupWizardBar .sw-return {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
}
body[data-setup-step-header="true"] #setupWizardBar .sw-return-hint {
  grid-column: 3;
  grid-row: 1;
  justify-self: start;
  min-width: 0;
  margin: 0;
  padding: 0;
}
#setupWizardBar .sw-return {
  position: relative;
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 10px 17px;
  border: 1px solid #a5d95a;
  border-radius: 8px;
  background: #a5d95a;
  color: var(--sw-ink);
  box-shadow: 0 3px 0 #66893a, 0 0 0 1px rgb(165 217 90 / 16%);
  font-family: inherit;
  font-size: .88rem;
  font-weight: 750;
  line-height: 1.15;
  letter-spacing: .005em;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}
#setupWizardBar .sw-return::before {
  content: "←";
  font: 700 1rem/1 sans-serif;
}
#setupWizardBar .sw-return:hover {
  background: #c1eb7a;
  border-color: #c1eb7a;
  box-shadow: 0 3px 0 #789d46, 0 0 0 3px rgb(165 217 90 / 18%);
  transform: translateY(-1px);
}
#setupWizardBar .sw-return:active {
  box-shadow: 0 1px 0 #66893a;
  transform: translateY(2px);
}
#setupWizardBar .sw-return:focus-visible {
  outline: 3px solid #d9f5ad;
  outline-offset: 4px;
}
#setupWizardBar .sw-return-hint {
  max-width: 185px;
  color: #c1d0b4;
  font-size: .72rem;
  line-height: 1.35;
}
#setupWizardBar[data-ready="true"] .sw-return {
  border-color: #c1eb7a;
  background: #c1eb7a;
  box-shadow: 0 3px 0 #789d46, 0 0 0 3px rgb(165 217 90 / 22%);
  animation: sw-return-arrival 520ms cubic-bezier(.2,.8,.25,1.1) 2 both;
}
#setupWizardBar[data-ready="true"] .sw-return-hint { color: #d5e8c1; }
@keyframes sw-return-arrival {
  0%, 100% { transform: translateY(0) scale(1); }
  38% { transform: translateY(-3px) scale(1.025); }
  70% { transform: translateY(0) scale(1); }
}
.sw-task[data-current="true"] {
  position: relative;
  border: 1px solid #8dbb4b;
  background: linear-gradient(110deg, #263220 0%, #1d251b 75%);
  box-shadow: inset 3px 0 0 #a5d95a, 0 5px 16px rgb(0 0 0 / 13%);
}
.sw-task[data-current="true"] h3 { color: #e9f5d8; }
.sw-task .sw-current-label {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  margin: 0 0 0 auto;
  padding: 4px 7px;
  border: 1px solid #87aa54;
  border-radius: 999px;
  background: #33452a;
  color: #d5f09e;
  font: 700 .6rem/1.1 monospace;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.sw-task:not([data-current="true"]) .sw-current-label { display: none; }
.sw-task[data-current="true"] .sw-task-check { border-color: #b4df72; }
.sw-progress { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--sw-muted); font-size: .7rem; }
.sw-progress progress { width: 100%; height: 7px; accent-color: #a5d95a; }
.sw-group { border: 1px solid #353d33; border-radius: 9px; margin: 10px 0; overflow: hidden; }
.sw-group > summary { padding: 14px; background: #222820; cursor: pointer; font-weight: 600; font-size: .88rem; }
.sw-task { margin: 8px; padding: 13px; border: 1px solid #343b32; border-radius: 8px; background: #141814; }
.sw-task h3 { font-size: .9rem; margin: 0 0 7px; }
.sw-task h3 { display: flex; align-items: flex-start; gap: 9px; }
.sw-task h3 .sw-task-title {
  flex: 1 1 12rem;
  min-width: 0;
  overflow-wrap: anywhere;
}
.sw-task-check { display: inline-grid; width: 17px; height: 17px; flex: 0 0 17px; place-items: center; margin-top: 1px; border: 1px solid #7a8573; border-radius: 3px; color: transparent; }
.sw-task[data-done="true"] .sw-task-check { border-color: #a5d95a; background: #a5d95a; color: #192016; }
.sw-task[data-done="true"] .sw-task-check::after { content: "✓"; font-size: .72rem; font-weight: 800; line-height: 1; }
.sw-task > p { margin: 0 0 9px; }
.sw-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sw-note { display: block; margin-top: 9px; color: var(--sw-muted); font-size: .74rem; line-height: 1.5; }
.sw-obs { margin-top: 10px; font-size: .8rem; }
.sw-source-help { margin: 12px 0; }
.sw-replay-feedback { margin-top: 12px; }
.sw-replay-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .75rem; }
.sw-replay-dot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: var(--muted, #a3ad9c); }
.sw-replay-dot[data-state="ready"] { background: var(--green, #4ade80); }
.sw-replay-dot[data-state="connecting"] { background: var(--yellow, #fbbf24); }
.sw-replay-dot[data-state="error"] { background: var(--red, #ef4444); }
.sw-replay-buffer { color: var(--sw-muted); }
#setupWizard .sw-replay-error { margin: 8px 0 0; color: #fca5a5; }
#setupWizard .sw-replay-warning { margin: 8px 0 0; color: #fbbf24; }
.sw-replay-feedback [hidden] { display: none !important; }
#setupWizard .sw-replay-try,
#setupWizard .sw-game-tip { margin: 12px 0 0; }
.sw-obs-option { margin: 14px 0; padding-top: 14px; border-top: 1px solid #3c4537; }
.sw-obs-option h4 { margin: 0; color: #e1ebd8; font-size: .9rem; }
.sw-next-step-ready {
  margin-top: 18px;
  padding: 18px;
  border: 2px solid #a5d95a;
  border-radius: 10px;
  background: linear-gradient(110deg, #293b20, #1d281a);
  box-shadow: 0 0 0 4px rgb(165 217 90 / 10%), 0 5px 20px rgb(165 217 90 / 12%);
}
.sw-next-step-label {
  display: block;
  margin-bottom: 12px;
  color: #dff5bf;
  font-size: .84rem;
}
#setupWizard .sw-next-step-ready button {
  min-height: 44px;
  color: #182016;
  background: #a5d95a;
  border-color: #a5d95a;
  border-radius: 7px;
  font-weight: 750;
}
#setupWizard .sw-next-step-ready button:hover { background: #b9ea70; }
.sw-obs summary { cursor: pointer; color: #c1eb7a; padding: 6px 0; }
.sw-obs ol { padding-left: 22px; line-height: 1.7; color: #bec8b6; }
.sw-url { display: flex; gap: 7px; margin: 9px 0; }
#setupWizard .sw-url input { width: 100%; min-width: 0; font-size: .73rem; }
.sw-url button { flex-shrink: 0; }
.sw-check { display: block; padding: 7px 0; font-size: .8rem; }
.sw-check input { margin-right: 7px; }
.sw-source { padding-top: 12px; border-top: 1px solid #343b32; }
.sw-status { min-height: 1.5em; font-size: .78rem; color: #c1eb7a; margin: 12px 0; }
.sw-aside ul { color: var(--sw-muted); font-size: .84rem; line-height: 1.9; padding-left: 18px; }
@media(max-width: 720px) {
  #setupWizard { padding: 25px 15px; }
  .sw-layout { grid-template-columns: 1fr; }
  .sw-panel, .sw-aside { padding: 18px; }
  #setupWizard .sw-levels { gap: 5px; padding: 6px; }
  #setupWizard .sw-levels button { padding: 10px 7px !important; }
  .sw-level { flex-direction: column; align-items: flex-start; gap: 7px; }
  .sw-level-number { width: 25px; height: 25px; flex-basis: 25px; font-size: .61rem; }
  .sw-level-name { padding-right: 0; width: 100%; }
  .sw-level strong { font-size: .71rem; }
  .sw-level small { font-size: .58rem; line-height: 1.3; }
  .sw-level-arrow { right: -10px; font-size: 1rem; }
  .sw-top { align-items: flex-start; }
}
@media(max-width: 600px) {
  body[data-setup-step-header="true"] .sw-step-heading {
    display: flex;
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 14px;
  }
  body[data-setup-step-header="true"] .sw-step-heading > h2 {
    font-size: clamp(1.28rem, 6vw, 1.55rem);
    line-height: 1.18;
    min-height: 2.36em;
  }
  body[data-setup-step-header="true"] #setupWizardBar {
    display: contents;
  }
  body[data-setup-step-header="true"] #setupWizardBar .sw-return {
    align-self: center;
    max-width: 100%;
    gap: 10px;
  }
  #setupWizardBar .sw-return {
    min-height: 42px;
    padding: 9px 13px;
    font-size: .82rem;
  }
  #setupWizardBar .sw-return-hint {
    align-self: center;
    flex: 0 1 auto;
    max-width: 180px;
    text-align: center;
  }
  .sw-task h3 { flex-wrap: wrap; min-width: 0; }
  .sw-task h3 .sw-task-title { flex-basis: 0; }
  .sw-task .sw-current-label { margin-left: 0; }
}
@media(max-width: 390px) {
  body[data-setup-step-header="true"] .sw-step-heading { gap: 9px; }
  #setupWizardBar .sw-return-hint { max-width: 100%; }
  .sw-task .sw-current-label { margin-left: 0; }
}
@media(prefers-reduced-motion: reduce) {
  #setupWizardBar .sw-return { transition: none; }
  #setupWizardBar[data-ready="true"] .sw-return { animation: none; }
}

/*
 * Guided setup points operators at the original control, never a proxy.
 * Outline and shadow stay outside the box model so controls and canvases
 * retain their exact dimensions and position.
 */
body[data-setup-guided-screen="true"] .sw-guided-target {
  outline: 3px solid #a5d95a;
  outline-offset: 4px;
  box-shadow: 0 0 0 1px rgb(193 235 122 / 42%), 0 0 18px rgb(165 217 90 / 34%);
  animation: sw-guided-arrival 1.15s ease-out 2;
}

@keyframes sw-guided-arrival {
  0%, 100% {
    box-shadow: 0 0 0 1px rgb(193 235 122 / 42%), 0 0 18px rgb(165 217 90 / 34%);
  }
  45% {
    box-shadow: 0 0 0 4px rgb(193 235 122 / 72%), 0 0 27px rgb(165 217 90 / 56%);
  }
}

/* Calibration guidance is drawn on the real handles, not the view border. */
body[data-setup-guided-screen="true"] .sw-guided-target.sw-guided-handles {
  outline: none;
  box-shadow: none;
  animation: none;
}

@media(max-width: 600px) {
  body[data-setup-guided-screen="true"] .sw-guided-target {
    outline-offset: 3px;
    box-shadow: 0 0 0 1px rgb(193 235 122 / 48%), 0 0 14px rgb(165 217 90 / 38%);
  }
}

@media(prefers-reduced-motion: reduce) {
  body[data-setup-guided-screen="true"] .sw-guided-target {
    animation: none;
  }
}
