.proposal .proposal-modal {
  --calibration-glass: radial-gradient(ellipse at top left, #e5fbff30, transparent 58%),
    linear-gradient(145deg, #1c4d5966, #102833a6);
}

.proposal[data-screen="calibration"] .proposal-modal {
  --calibration-feed-ratio: 1.6;
  --modal-width: min(1160px, calc((var(--modal-height) - 2px) * var(--calibration-feed-ratio)));
  border: 0;
  background: #1237424d;
  -webkit-backdrop-filter: blur(16px) saturate(1.35);
  backdrop-filter: blur(16px) saturate(1.35);
  box-shadow: 0 20px 65px #041d2b93;
}

.proposal[data-screen="calibration"] .proposal-modal::after {
  content: "";
  position: absolute;
  z-index: 4;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(129deg, #edfaff26, transparent 15% 89%, #ddf6ff1c);
}

.proposal[data-screen="calibration"] .proposal-modal-close {
  background: #19364275;
  border-color: #effdff77;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: inset 0 1px 0 #effdff6b, 0 2px 9px #07162055;
}

.calibration {
  position: relative;
  isolation: isolate;
  width: 100%;
  aspect-ratio: var(--calibration-feed-ratio);
  color: #fffaf0;
}

.calibration-view {
  position: absolute;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
  container-type: inline-size;
  background: #091c23;
  --frame-accent: #ffd575;
}

.calibration-view[data-framing="aligned"] { --frame-accent: #acf3a0; }

.calibration-view > :is(canvas, video) {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.calibration-reference { object-fit: fill; }
.calibration-video { object-fit: cover; transform: scaleX(-1); }
.calibration-video[data-fit="contain"] { object-fit: contain; }
.calibration-overlay { transform: scaleX(-1); }

.calibration-projection {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.calibration-frame {
  position: absolute;
  inset: var(--frame-top) var(--frame-side) var(--frame-bottom);
  outline: 1px solid color-mix(in srgb, var(--frame-accent) 38%, transparent);
}

.calibration-view[data-target-side="left"] .calibration-frame { border-left: 2px solid var(--frame-accent); }
.calibration-view[data-target-side="right"] .calibration-frame { border-right: 2px solid var(--frame-accent); }

.calibration-frame i {
  position: absolute;
  width: clamp(14px, 2vw, 31px);
  height: clamp(14px, 2vw, 31px);
  border: 3px solid var(--frame-accent);
  filter: drop-shadow(0 1px 1px #0d27399c);
}

.calibration-frame i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 6px 0 0; }
.calibration-frame i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 6px 0 0; }
.calibration-frame i:nth-child(3) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 6px; }
.calibration-frame i:nth-child(4) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 6px; }

.calibration-center-line {
  position: absolute;
  top: var(--frame-top);
  bottom: var(--frame-bottom);
  left: var(--center-x);
  border-left: 1px dashed #f4ffffae;
}

.calibration-target, .calibration-tracker, .calibration-direction {
  position: absolute;
  transform: translateX(-50%);
}

.calibration-target {
  bottom: calc(var(--frame-bottom) + 6px);
  left: var(--target-x);
  width: var(--target-width);
  height: 9px;
  border-radius: 20px;
  border: 1px solid var(--frame-accent);
  background: color-mix(in srgb, var(--frame-accent) 40%, transparent);
}

.calibration-tracker {
  bottom: calc(var(--frame-bottom) + 4px);
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid #15303d;
  background: #fff;
}

.calibration-direction {
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #ffd575;
  text-shadow: 0 2px 2px #102832, 0 0 9px #0e233a;
  font-size: clamp(28px, 4.4vw, 52px);
  font-weight: 850;
  line-height: 1;
}

.calibration-overlays {
  position: absolute;
  z-index: 3;
  top: clamp(13px, 3vh, 28px);
  inset-inline: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.calibration-caption {
  width: min(88%, 34rem);
  margin-top: 20px;
  text-align: center;
}

.calibration-feedback {
  display: inline-block;
  max-width: 100%;
  margin: 0;
  padding: 3px 10px;
  border-radius: 8px;
  color: #fffdf4;
  text-shadow: 0 2px 4px #06111c, 0 0 10px #05121c, 0 0 2px #06121d;
  font-size: clamp(18px, 2.3vw, 32px);
  font-weight: 760;
  line-height: 1.18;
  text-wrap: balance;
}

.calibration-view[data-caption-scrim="true"] .calibration-feedback {
  background: #0b1c2665;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.calibration-view[data-framing="aligned"] .calibration-feedback { color: #ddffca; }

.proposal:is([data-screen="calibration"], [data-screen="hand-guide"]) .proposal-modal:has(.calibration-guide),
.proposal:is([data-screen="difficulty"], [data-screen="runner"]) .proposal-modal:has(.proposal-selection) {
  --modal-width: 900px;
  border: 0;
  box-shadow: 0 20px 50px #0418218c;
  background: var(--calibration-glass);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  backdrop-filter: blur(20px) saturate(1.4);
}

.proposal:is([data-screen="calibration"], [data-screen="hand-guide"]) .proposal-modal:has(.calibration-guide)::after {
  content: none;
}

.proposal:is([data-screen="calibration"], [data-screen="hand-guide"]) .proposal-modal:has(.calibration-guide)::backdrop,
.proposal:is([data-screen="difficulty"], [data-screen="runner"]) .proposal-modal:has(.proposal-selection)::backdrop {
  background: #071c267d;
}

.calibration-guide {
  padding: clamp(18px, 4vw, 38px);
  padding-block-end: 10px;
  text-align: center;
  color: #fffaf0;
}

.calibration-guide h1 { margin: 0 42px 18px; font-size: clamp(1.25rem, 4vw, 2rem); }
.calibration-sheet-handle { display: none; }

.calibration-examples {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(8px, 2vw, 18px);
}

.calibration-examples figure {
  margin: 0;
}

.calibration-examples img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.calibration-instructions {
  position: absolute;
  z-index: 3;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 12px;
  padding: 13px clamp(10px, 2vw, 20px) 10px;
  background: linear-gradient(transparent, #081724bf 50%, #081724e0);
  pointer-events: none;
}

.calibration-instructions:has(.calibration-error:not([hidden])) { padding-top: 24px; }

.calibration-step {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-inline-end: auto;
  color: var(--gold);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.calibration-step progress { width: clamp(48px, 8vw, 110px); }

.calibration progress {
  appearance: none;
  height: 5px;
  border: 0;
  border-radius: 50px;
  overflow: hidden;
  background: #d8f7ff56;
  accent-color: var(--gold);
}

.calibration progress::-webkit-progress-bar { background: #d8f7ff56; }
.calibration progress::-webkit-progress-value { background: var(--gold); }
.calibration progress::-moz-progress-bar { background: var(--gold); }

.calibration-error {
  flex-basis: 100%;
  order: -1;
  width: fit-content;
  margin: 0;
  color: #ffd2c2;
  font-size: 12px;
  line-height: 1.28;
  text-shadow: 0 1px 3px #0b151d;
}

.calibration-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  pointer-events: auto;
}

.calibration-controls button {
  min-height: 38px;
  padding: 5px 10px;
  border: 1px solid #ddf8ff66;
  border-radius: 9px;
  background: #18394794;
  color: #faffff;
  font: inherit;
  font-size: 12px;
  font-weight: 730;
  line-height: 1.2;
}

.calibration-controls button:is([data-calibration-action="allow"], [data-calibration-action="advance"]) {
  background: var(--gold);
  border-color: #ffe2a6;
  color: var(--ink);
}

.calibration-controls button[data-calibration-action="skip"] {
  color: #fff;
  border-color: transparent;
  background: transparent;
  font-weight: 400;
}

.calibration-controls button[data-calibration-action="skip"]:hover { text-decoration: underline; }
.calibration-controls button:enabled:hover { filter: brightness(1.13); }
.calibration-controls button:disabled { cursor: wait; opacity: .75; }
.calibration-controls button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

@container (max-width: 615px) {
  .calibration-overlays {
    top: 13px;
    gap: 8px;
  }
  .calibration-caption { min-height: 29px; }
  .calibration-feedback { font-size: clamp(16px, 4.6vw, 22px); }
}

@media (max-width: 680px) and (orientation: portrait),
       (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  .proposal:is([data-screen="calibration"], [data-screen="hand-guide"]) .proposal-modal:has(:is(.calibration-guide, .calibration)),
  .proposal:is([data-screen="difficulty"], [data-screen="runner"]) .proposal-modal:has(.proposal-selection) {
    --modal-width: 500px;
    --modal-height: calc(100dvh - 16px - env(safe-area-inset-top));
    width: min(100%, var(--modal-width));
    margin: auto auto 0;
    border-radius: 24px 24px 0 0;
  }

  .proposal:is([data-screen="calibration"], [data-screen="hand-guide"]) .proposal-modal:has(:is(.calibration-guide, .calibration))::backdrop,
  .proposal:is([data-screen="difficulty"], [data-screen="runner"]) .proposal-modal:has(.proposal-selection)::backdrop {
    background: #071c26c2;
  }

  .proposal:is([data-screen="calibration"], [data-screen="hand-guide"]) .proposal-modal:has(.calibration-guide) .proposal-modal-close,
  .proposal:is([data-screen="difficulty"], [data-screen="runner"]) .proposal-modal:has(.proposal-selection) .proposal-modal-close {
    right: calc(12px + env(safe-area-inset-right));
  }

  .calibration-guide {
    padding-block-start: 28px;
    padding-inline: calc(16px + env(safe-area-inset-left)) calc(16px + env(safe-area-inset-right));
    padding-block-end: calc(10px + env(safe-area-inset-bottom));
  }
  .calibration-sheet-handle {
    position: absolute;
    top: 0;
    left: 50%;
    z-index: 4;
    width: 112px;
    height: 28px;
    transform: translateX(-50%);
    display: grid;
    place-items: center;
    touch-action: none;
    cursor: grab;
  }
  .calibration-sheet-handle::before {
    content: "";
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: #e7f5fa9c;
  }
  .calibration-examples { grid-template-columns: minmax(0, 1fr); }

  .proposal[data-screen="calibration"] .proposal-modal:has(.calibration) {
    background: var(--calibration-glass);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    backdrop-filter: blur(20px) saturate(1.4);
    box-shadow: 0 20px 50px #0418218c;
  }

  .proposal[data-screen="calibration"] .proposal-modal:has(.calibration)::after {
    background: none;
  }

  .proposal[data-screen="calibration"] .proposal-modal:has(.calibration) .proposal-modal-close {
    top: 8px;
    right: calc(8px + env(safe-area-inset-right));
    border-radius: 50%;
    border-color: #e4fff438;
    background: #09232c9e;
    box-shadow: none;
  }

  .calibration {
    display: flex;
    flex-direction: column;
    max-height: calc(var(--modal-height) - 2px);
    aspect-ratio: auto;
  }

  .calibration-view {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    aspect-ratio: clamp(.72, var(--calibration-feed-ratio), .8);
    background: transparent;
    mask-image: linear-gradient(#000 calc(100% - 36px), transparent);
  }

  .calibration-overlays {
    top: 0;
    gap: 9px;
  }

  .calibration-caption {
    display: grid;
    width: 100%;
    min-height: 55px;
    margin-top: 0;
    padding: 28px 53px 5px;
    padding-inline: calc(53px + env(safe-area-inset-left)) calc(53px + env(safe-area-inset-right));
    place-items: center;
    background: linear-gradient(#081d2be0, #081d2b99 65%, transparent);
  }

  .calibration-feedback {
    padding: 0;
    font-size: clamp(16px, 4.75cqw, 20px);
    letter-spacing: -.02em;
  }

  .calibration-view[data-caption-scrim="true"] .calibration-feedback {
    background: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .calibration-instructions {
    position: relative;
    flex: none;
    display: block;
    padding-block: 16px calc(12px + env(safe-area-inset-bottom));
    padding-inline: calc(12px + env(safe-area-inset-left)) calc(12px + env(safe-area-inset-right));
    background: transparent;
  }

  .calibration-step { position: absolute; inset: auto auto calc(100% + 8px) calc(12px + env(safe-area-inset-left)); }
  .calibration-step progress { width: clamp(42px, 13vw, 68px); }

  .calibration-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
  }

  .calibration-controls button {
    min-width: 0;
    min-height: 44px;
    padding: 6px 9px;
    border-radius: 11px;
    border-color: #ddf8ff45;
    background: #e1faff0d;
    font-size: 13px;
    text-wrap: balance;
  }

}

@media (max-width: 680px) and (orientation: portrait) {
  .calibration { min-height: min(84dvh, calc(var(--modal-height) - 2px)); }
}

@media (prefers-reduced-motion: no-preference) {
  @media (max-width: 680px) and (orientation: portrait),
         (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
    .proposal:is([data-screen="calibration"], [data-screen="hand-guide"]) .proposal-modal[open]:has(:is(.calibration-guide, .calibration)),
    .proposal:is([data-screen="difficulty"], [data-screen="runner"]) .proposal-modal[open]:has(.proposal-selection) {
      animation: calibration-sheet-in 300ms cubic-bezier(.2, .75, .3, 1) both;
    }
  }
}

@keyframes calibration-sheet-in {
  from { transform: translateY(100%); }
  to { transform: none; }
}

@media (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  .proposal:is([data-screen="calibration"], [data-screen="hand-guide"]) .proposal-modal:has(:is(.calibration-guide, .calibration)),
  .proposal:is([data-screen="difficulty"], [data-screen="runner"]) .proposal-modal:has(.proposal-selection) {
    width: 100%;
  }

  .calibration-guide {
    --guide-actions-gap: 12px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: calc(var(--modal-height) - 2px);
  }

  .calibration-guide h1 { margin-bottom: 10px; }
  .calibration-examples {
    container-type: size;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }
  .calibration-examples figure { width: min(100%, 150cqh); }
  .calibration-examples figure:first-child { justify-self: end; }

  .calibration { height: calc(var(--modal-height) - 2px); }
  .calibration-view {
    --calibration-fit: contain;
    aspect-ratio: auto;
    mask-image: none;
  }
  .calibration-feedback { font-size: clamp(15px, 4cqw, 18px); }

  .calibration-instructions {
    position: absolute;
    padding-block: 0 calc(4px + env(safe-area-inset-bottom));
    background: radial-gradient(ellipse at bottom, #06121bb3, transparent 74%)
      center bottom / min(100%, 420px) 100% no-repeat;
  }

  .calibration-controls { max-width: 420px; margin-inline: auto; }
  .calibration-controls button[data-calibration-action="skip"] { text-shadow: 0 1px 4px #06121b; }

  .calibration-controls:has([data-calibration-action="advance"]) {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .calibration-controls button { font-size: 12px; }
}

.proposal[data-screen="calibration"] .proposal-modal:has(.camera-permission) {
  --modal-width: 550px;
  border: 0;
  background:
    radial-gradient(ellipse at 15% 3%, #edfeff2e, transparent 65%),
    linear-gradient(145deg, #22495ab0, #132a3cd9);
  -webkit-backdrop-filter: blur(25px) saturate(1.45) brightness(.85);
  backdrop-filter: blur(25px) saturate(1.45) brightness(.85);
  box-shadow: 0 20px 52px #020e1d60;
}

.proposal[data-screen="calibration"] .proposal-modal:has(.camera-permission)::after {
  background: radial-gradient(ellipse at 105% 100%, #c8eaff0f, transparent 64%);
  box-shadow: none;
}

.proposal[data-screen="calibration"] .proposal-modal:has(.camera-permission) .proposal-modal-close {
  border: 0;
  background: #e6faff19;
  box-shadow: none;
}

.camera-permission {
  padding: 23px clamp(15px, 4vw, 32px) 20px;
  color: #fffaf0;
  text-align: center;
}

.camera-permission h1 {
  margin: 0 34px 12px;
  font-size: clamp(20px, 4.6vw, 30px);
  line-height: 1.08;
  letter-spacing: -.035em;
}

.camera-permission-art {
  width: 100%;
  aspect-ratio: 576 / 258;
  visibility: hidden;
}

.camera-permission-art:not([data-platform="desktop"]) {
  width: min(100%, 205px);
  margin-inline: auto;
  aspect-ratio: 252 / 258;
}

.camera-permission-art:has(img[src]) { visibility: visible; }
.camera-permission-art img { display: block; width: 100%; height: auto; }

.camera-permission-next {
  margin: 13px 0 5px;
  font-size: 15px;
  font-weight: 680;
}

.camera-permission-privacy {
  max-width: 37ch;
  margin: 0 auto;
  color: #d9edeb;
  font-size: 13px;
  line-height: 1.38;
}

.camera-permission .calibration-error { margin: 8px auto 0; }
.camera-permission-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.camera-permission-actions button {
  min-height: 42px;
  padding: 6px 11px;
  border: 1px solid #dbf5ff6b;
  border-radius: 8px;
  background: #1c4050af;
  color: #fff;
  font-size: 13px;
  font-weight: 730;
}

.camera-permission-actions button[data-calibration-action="allow"] {
  border-color: #ffe4a2;
  background: var(--gold);
  color: var(--ink);
}

.calibration-guide .camera-permission-actions {
  display: grid;
  grid-template-columns: minmax(0, 240px);
  margin-top: var(--guide-actions-gap, 26px);
}

.calibration-guide .camera-permission-actions button[data-calibration-action="skip"] {
  border-color: transparent;
  background: transparent;
  font-weight: 400;
  text-align: center;
}

.calibration-guide .camera-permission-actions button[data-calibration-action="skip"]:hover {
  text-decoration: underline;
}

.camera-permission-actions button:disabled { opacity: .72; cursor: wait; }

.camera-permission-demo {
  min-height: 38px;
  margin-top: 4px;
  padding: 5px 7px;
  border: 0;
  background: transparent;
  color: #c9e8e8;
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.hand-guide-video {
  display: block;
  width: min(100%, 720px);
  aspect-ratio: 16 / 9;
  max-height: 54dvh;
  margin-inline: auto;
  border-radius: 8px;
  background: #071c26;
  object-fit: contain;
}

.hand-guide-footer p {
  margin: 12px 0 0;
  text-wrap: balance;
}

.hand-guide-footer[data-practice="true"] p {
  color: #ffe4a2;
  font-weight: 750;
}

.hand-guide-footer[data-practice="true"] button {
  box-shadow: 0 0 0 2px #fff1ba, 0 0 18px #ffc54fa6;
}

.hand-guide-click {
  position: absolute;
  width: 48px;
  height: 48px;
  top: -24px;
  left: -24px;
  border-radius: 50%;
  border: 3px solid #ffd567;
  transform: scale(var(--guide-click-scale, 1));
  opacity: var(--guide-click-opacity, 0);
}

.hand-guide .camera-permission-actions { margin-top: 12px; }

@media (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  .hand-guide-video { height: 100%; min-height: 0; width: auto; max-width: 100%; }
  .hand-guide-footer p { margin-top: 6px; }
  .hand-guide .camera-permission-actions { margin-top: 6px; }
}
