/**
 * The count step (spec 4.2): the photo at full column width with a numbered outline on
 * each detected check. The photo is the payload; the header is one line and the
 * outlines are thin. Confident outlines are the accent green, the rest amber, so a
 * glance says which ones to look at.
 */

.count-step {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing-unit) * 1.5);
}

.count-step-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: calc(var(--spacing-unit) * 2);
}

.count-step-heading {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 500;
}

/* Two lines are always reserved: the note changes with what she is doing (drawing, a check
   selected), and a note that grew mid-drag would shift the photo under the pointer. */
.count-step-note {
  margin: calc(var(--spacing-unit) * 0.25) 0 0;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  max-width: 78ch;
  min-height: 3em;
}

.count-step-actions {
  display: flex;
  gap: var(--spacing-unit);
}

.count-photo-frame {
  position: relative;
  width: 100%;
  margin: 0 auto; /* centred when count_step.js caps its width to fit the window height */
  line-height: 0;
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
}

.count-photo-canvas {
  width: 100%;
  height: auto;
  display: block;
}

.count-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.count-overlay--drawing {
  cursor: crosshair;
}

.count-outline {
  fill: rgba(63, 111, 91, 0.06);
  stroke: var(--color-outline-confident);
  stroke-width: 2.5;
  cursor: pointer;
}

.count-outline--unsure {
  stroke: var(--color-outline-unsure);
  fill: rgba(217, 154, 43, 0.06);
}

.count-outline--selected {
  stroke: #ffffff;
  stroke-width: 3.5;
  fill: rgba(255, 255, 255, 0.12);
}

.count-outline--pending {
  stroke-dasharray: 8 6;
}

/* A white ring keeps the number readable on dark wood, bedsheets and checks alike. */
.count-number-badge {
  fill: rgba(28, 26, 24, 0.88);
  stroke: #ffffff;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.count-number-text {
  fill: #ffffff;
  font-family: var(--font-body);
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.count-corner-handle {
  fill: #ffffff;
  stroke: rgba(28, 26, 24, 0.7);
  stroke-width: 1.5;
  cursor: grab;
}

.count-quad .count-corner-handle {
  opacity: 0;
  transition: opacity 100ms ease;
}

.count-quad:hover .count-corner-handle,
.count-quad--selected .count-corner-handle {
  opacity: 1;
}

.count-corner-handle:active {
  cursor: grabbing;
}

.count-remove-button {
  cursor: pointer;
}

.count-remove-button circle {
  fill: var(--color-error);
  stroke: #ffffff;
  stroke-width: 2;
}

.count-remove-button path {
  stroke: #ffffff;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.count-draw-rectangle {
  fill: rgba(255, 255, 255, 0.15);
  stroke: #ffffff;
  stroke-width: 2;
  stroke-dasharray: 6 4;
  pointer-events: none;
}

.count-step--locked .count-overlay {
  pointer-events: none;
}

/* After Continue: only the busy Continue stays ("Straightening…"), then the actions fold away. */
.count-step--locked #add-check-button,
.count-step--locked .count-corner-handle,
.count-step--settled .count-step-actions {
  display: none;
}

.primary-button--busy,
.primary-button--busy:disabled {
  opacity: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: progress;
}

.primary-button--busy::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* The overlay's viewBox is in full-resolution photo pixels; keep strokes in screen pixels. */
.count-outline,
.count-corner-handle,
.count-draw-rectangle,
.count-remove-button circle,
.count-remove-button path {
  vector-effect: non-scaling-stroke;
}

/* ---------- Scanning (the checks are being found) and the reveal ---------- */

/* The heading block and the progress panel that stands in for it are the same height,
   so the heading replaces the panel with no jump. */
.count-step-header,
.count-step > .progress-panel {
  min-height: 92px;
}

.count-step > .progress-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative; /* not sticky here: it sits exactly where the heading will be */
  top: auto;
}

.count-step > .progress-panel .progress-panel-body {
  flex: 1 1 auto;
}

.count-step--scanning .count-step-header {
  display: none;
}

.count-step--scanning .count-photo-canvas {
  opacity: 0.55;
}

.count-photo-canvas {
  transition: opacity 450ms var(--ease-out);
}

/* A soft band of light sweeping across her photo while the checks are found. */
.count-step--scanning .count-photo-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(100deg, rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0.38) 50%, rgba(255, 255, 255, 0) 70%) 0 0 / 250% 100% no-repeat;
  animation: photo-sweep 1.6s ease-in-out infinite;
}

@keyframes photo-sweep {
  from { background-position: 150% 0; }
  to { background-position: -50% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .count-step--scanning .count-photo-frame::after {
    display: none;
  }
}

/* The outlines and their numbers fade in one after another (120 ms apart). */
.count-overlay--revealing .count-quad,
.count-overlay--revealing .count-number-badge,
.count-overlay--revealing .count-number-text {
  animation: outline-reveal 380ms var(--ease-out) both;
  animation-delay: calc(var(--quad-index, 0) * 120ms);
}

@keyframes outline-reveal {
  from { opacity: 0; }
  to { opacity: 1; }
}

.count-outline:focus {
  outline: none;
}

.count-outline:focus-visible {
  stroke: #ffffff;
  stroke-width: 4;
  stroke-dasharray: 6 4;
}

/* Nothing is running while the panel shows an error: stop the sweep so the page does not imply work. */
.count-step:has(> .progress-panel[data-tone="error"]) .count-photo-frame::after {
  display: none;
}
