/* Rep Counter
   Direction: a measuring instrument, not a gym poster. Deep slate and chalk,
   hairline rules, and the only saturated colour on the page encodes range of
   motion using the international weight plate scale: green, yellow, blue, red. */

:root {
  --iron:    #101418;
  --iron-d:  #0B0E11;
  --panel:   #171D23;
  --panel-2: #1E262E;
  --line:    #2B353F;
  --line-b:  #3A4652;
  --chalk:   #ECE7DE;
  --steel:   #8E9AA6;
  --steel-d: #5C6772;

  /* IWF plate colours, used only as a data scale */
  --p10: #3B9E5C;
  --p15: #F2C230;
  --p20: #2E7CC4;
  --p25: #E4362C;

  --display: 'Archivo', ui-sans-serif, system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --gut: clamp(1.15rem, 4vw, 2.5rem);
  --rule: 1px solid var(--line);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--iron);
  color: var(--chalk);
  font-family: var(--display);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.03em; line-height: 1.02; }
p { margin: 0; }
ul, ol, dl, dd { margin: 0; padding: 0; list-style: none; }

a { color: var(--chalk); text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--p15);
  outline-offset: 3px;
}

.wrap {
  width: min(1180px, 100% - (var(--gut) * 2));
  margin-inline: auto;
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.label {
  font-family: var(--mono);
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--steel-d);
}

.skip {
  position: absolute; left: -9999px;
  background: var(--chalk); color: var(--iron);
  padding: .6rem 1rem; z-index: 20;
}
.skip:focus { left: 1rem; top: 1rem; }

/* ---------- masthead ---------- */

.masthead { border-bottom: var(--rule); }

.masthead-in {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; min-height: 62px; flex-wrap: wrap;
}

.mark {
  display: inline-flex; align-items: center; gap: .6rem;
  font-weight: 800; letter-spacing: -0.02em; font-size: .98rem;
}

/* a goniometer corner: two arms meeting at a measured joint */
.mark-glyph {
  width: 15px; height: 15px;
  border-left: 2px solid var(--p15);
  border-bottom: 2px solid var(--p15);
  position: relative;
}
.mark-glyph::after {
  content: ""; position: absolute; left: 0; bottom: 0;
  width: 15px; height: 2px; background: var(--steel-d);
  transform-origin: left center; transform: rotate(-42deg);
}

.mast-nav { display: flex; gap: clamp(.9rem, 2.4vw, 1.7rem); }
.mast-nav a {
  font-family: var(--mono); font-size: .74rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--steel);
  padding: .3rem 0; border-bottom: 1px solid transparent;
}
.mast-nav a:hover { color: var(--chalk); border-bottom-color: var(--line-b); }

/* ---------- hero ---------- */

.hero { padding: clamp(2.6rem, 8vw, 5.4rem) 0 clamp(1.8rem, 4vw, 2.8rem); }

.eyebrow {
  font-family: var(--mono); font-size: .7rem; font-weight: 500;
  letter-spacing: .2em; text-transform: uppercase; color: var(--p15);
  margin-bottom: 1.4rem;
}

h1 {
  font-size: clamp(2.7rem, 8.2vw, 5.4rem);
  letter-spacing: -0.045em;
  line-height: 0.95;
  max-width: 16ch;
}

.lede {
  margin-top: 1.5rem; max-width: 58ch;
  color: var(--steel);
  font-size: clamp(1rem, 1.25vw, 1.12rem);
}

/* ---------- the instrument ---------- */

.rig {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 322px;
  border: var(--rule);
  border-radius: 5px;
  background: var(--panel);
  overflow: hidden;
}

.stage { display: flex; flex-direction: column; min-width: 0; }

.stage-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--iron-d);
  overflow: hidden;
  /* faint measuring grid, like squared chart paper under the subject */
  background-image:
    linear-gradient(to right, rgba(255,255,255,.028) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,.028) 1px, transparent 1px);
  background-size: 44px 44px;
}

#video, #overlay {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
}
#video { opacity: 0; transition: opacity .35s ease; }
#video.is-live { opacity: 1; }

.stage-empty {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center;
  text-align: center; padding: 2rem; gap: .5rem;
}
.stage-empty[hidden] { display: none; }

.stage-empty-glyph {
  width: 44px; height: 44px; margin-bottom: .7rem;
  border: 2px solid var(--line-b);
  border-radius: 50%;
  position: relative;
}
.stage-empty-glyph::after {
  content: ""; position: absolute; inset: -2px;
  border-top: 2px solid var(--steel-d);
  border-radius: 50%;
  transform: rotate(38deg);
}

.stage-empty-title { font-weight: 700; font-size: 1.05rem; }
.stage-empty-note { color: var(--steel-d); font-size: .9rem; max-width: 34ch; }

.stage-status {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: .55rem .9rem;
  background: linear-gradient(to top, rgba(11,14,17,.92), rgba(11,14,17,0));
  font-family: var(--mono); font-size: .74rem; color: var(--steel);
}
.stage-status:empty { display: none; }
.stage-status.is-error { color: var(--p25); }

.stage-badge {
  position: absolute; top: .8rem; right: .8rem;
  font-family: var(--mono); font-size: .62rem; letter-spacing: .13em;
  text-transform: uppercase; color: var(--p10);
  border: 1px solid rgba(59,158,92,.4);
  background: rgba(59,158,92,.09);
  padding: .22rem .5rem; border-radius: 2px;
}

.controls {
  display: flex; flex-wrap: wrap; gap: .55rem;
  padding: .85rem; border-top: var(--rule);
  background: var(--panel);
}

.btn {
  font-family: var(--display); font-size: .875rem; font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--chalk); background: var(--panel-2);
  border: 1px solid var(--line-b); border-radius: 3px;
  padding: .58rem 1.05rem; cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { background: #27313a; border-color: #4a5763; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--chalk); color: var(--iron); border-color: var(--chalk);
}
.btn-primary:hover { background: #fff; border-color: #fff; }

.btn-quiet {
  background: transparent; border-color: transparent; color: var(--steel-d);
  margin-left: auto;
}
.btn-quiet:hover { background: transparent; color: var(--chalk); border-color: transparent; }

/* ---------- readout rail ---------- */

.readout {
  border-left: var(--rule);
  padding: 1.1rem 1.15rem 1.3rem;
  display: flex; flex-direction: column; gap: 1.15rem;
  background: var(--panel);
  min-width: 0;
}

.exercise { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }

.ex {
  font-family: var(--display); font-size: .82rem; font-weight: 600;
  color: var(--steel); background: transparent;
  border: 1px solid var(--line); border-radius: 3px;
  padding: .5rem .3rem; cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.ex:hover { color: var(--chalk); border-color: var(--line-b); }
.ex.is-on {
  color: var(--iron); background: var(--p15); border-color: var(--p15);
}

.reps { display: flex; flex-direction: column; gap: .1rem; }

.reps-value {
  font-size: clamp(3.6rem, 9vw, 4.6rem);
  font-weight: 800; letter-spacing: -0.06em; line-height: 0.9;
  font-variant-numeric: tabular-nums;
  display: block;
}
.reps-value.is-bump { animation: bump .34s cubic-bezier(.2,.9,.3,1); }
@keyframes bump {
  0%   { transform: scale(1); color: var(--chalk); }
  35%  { transform: scale(1.13); color: var(--p15); }
  100% { transform: scale(1); color: var(--chalk); }
}

.rom-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .5rem; }
.rom-pct { font-size: .82rem; color: var(--steel); }

.rom-track {
  position: relative; height: 9px; border-radius: 2px;
  background: var(--panel-2); border: 1px solid var(--line);
  overflow: hidden;
}
.rom-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--p10) 0%, var(--p15) 42%, var(--p20) 72%, var(--p25) 100%);
  background-size: calc(100% * (100 / max(var(--pct, 1), 1))) 100%;
  transition: width .09s linear;
}
.rom-tick {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: rgba(16,20,24,.75);
}

.stats { display: grid; gap: .1rem; }
.stat {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: .5rem 0; border-bottom: 1px dashed var(--line);
}
.stat:last-child { border-bottom: 0; }
.stat-v { font-size: 1.02rem; font-weight: 500; }

.form-state {
  display: flex; align-items: center; gap: .55rem;
  font-family: var(--mono); font-size: .74rem; color: var(--steel-d);
  border-top: var(--rule); padding-top: .9rem; margin-top: auto;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--steel-d); flex: none;
  transition: background .2s ease, box-shadow .2s ease;
}
.form-state.is-good .dot { background: var(--p10); box-shadow: 0 0 0 3px rgba(59,158,92,.16); }
.form-state.is-good { color: var(--p10); }
.form-state.is-work .dot { background: var(--p15); box-shadow: 0 0 0 3px rgba(242,194,48,.14); }
.form-state.is-work { color: var(--p15); }

/* ---------- content sections ---------- */

.section { padding: clamp(3rem, 7vw, 5rem) 0 0; }

.sec-title { font-size: clamp(1.55rem, 3.2vw, 2.15rem); }
.sec-lede { color: var(--steel-d); margin-top: .6rem; max-width: 56ch; font-size: .96rem; }

.steps {
  margin-top: 2rem;
  display: grid; gap: 1px;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  background: var(--line);
  border: var(--rule);
  border-radius: 5px;
  overflow: hidden;
}
.steps li { background: var(--panel); padding: 1.3rem 1.25rem 1.5rem; }
.step-n {
  font-size: .7rem; letter-spacing: .14em; color: var(--p15);
  display: block; margin-bottom: 1.6rem;
}
.steps h3 { font-size: 1.06rem; margin-bottom: .5rem; letter-spacing: -0.02em; }
.steps p { color: var(--steel-d); font-size: .89rem; line-height: 1.55; }

.table-scroll { overflow-x: auto; margin-top: 1.8rem; }

.spec { width: 100%; border-collapse: collapse; min-width: 620px; }
.spec th {
  text-align: left; padding: .7rem .9rem;
  font-family: var(--mono); font-size: .64rem; font-weight: 500;
  letter-spacing: .15em; text-transform: uppercase; color: var(--steel-d);
  border-bottom: 1px solid var(--line-b);
}
.spec td {
  padding: .85rem .9rem; border-bottom: var(--rule);
  font-size: .84rem; color: var(--steel);
}
.spec tbody tr:last-child td { border-bottom: 0; }
.spec td:first-child { color: var(--chalk); }

.note { margin-top: 1.4rem; color: var(--steel-d); font-size: .89rem; max-width: 62ch; }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: 1.6rem; }
.chips li {
  font-family: var(--mono); font-size: .74rem; color: var(--steel);
  border: var(--rule); border-radius: 2px; padding: .3rem .65rem;
  background: var(--panel);
}

.links { display: flex; flex-wrap: wrap; gap: 1.4rem; margin-top: 1.6rem; }
.links a {
  font-family: var(--mono); font-size: .8rem; color: var(--p15);
  border-bottom: 1px solid rgba(242,194,48,.28); padding-bottom: 2px;
}
.links a:hover { border-bottom-color: var(--p15); }

.foot {
  margin-top: clamp(3.5rem, 8vw, 6rem);
  padding: 1.4rem 0 2.2rem;
  border-top: var(--rule);
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  color: var(--steel-d); font-size: .8rem;
}

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .rig { grid-template-columns: 1fr; }
  .readout { border-left: 0; border-top: var(--rule); }
  .reps-value { font-size: 3.4rem; }
  .stage-frame { aspect-ratio: 3 / 4; }
  .btn-quiet { margin-left: 0; }
}

@media (max-width: 480px) {
  .mast-nav a:nth-child(2) { display: none; }
  .controls .btn { flex: 1 1 auto; }
}

/* ---------- entrance, kept quiet ---------- */

@media (prefers-reduced-motion: no-preference) {
  .hero > *, .rig {
    animation: rise .6s cubic-bezier(.2,.7,.3,1) backwards;
  }
  .hero > *:nth-child(1) { animation-delay: .02s; }
  .hero > *:nth-child(2) { animation-delay: .08s; }
  .hero > *:nth-child(3) { animation-delay: .14s; }
  .rig { animation-delay: .2s; }
  @keyframes rise {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* camera view is mirrored like a mirror; file playback is not */
#video.is-mirrored { transform: scaleX(-1); }
