.practice {
  --coach-w: clamp(200px, 29.86%, 300px);
  --coach-top: 14px;
  --coach-right: 16px;
  --coach-bottom: 12px;
  --coach-left: 20px;
  --band-h: 46px;
  --progress-safe: env(safe-area-inset-bottom, 0px);
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--coach-w);
  grid-template-rows: 48px minmax(0, 1fr) calc(6px + var(--progress-safe));
  width: 100%;
  max-width: 844px;
  height: min(390px, 100vh);
  height: min(390px, 100dvh);
  margin-inline: auto;
  overflow: hidden;
}

.practice__top {
  grid-area: 1 / 1 / 2 / -1;
  display: flex;
  align-items: center;
  min-width: 0;
  gap: var(--v2-space-16);
  padding-inline: max(var(--v2-space-16), env(safe-area-inset-left, 0px))
    max(var(--v2-space-16), env(safe-area-inset-right, 0px));
}

.practice__camera {
  grid-area: 2 / 1;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.practice__camera > :is(video, img) {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.practice__camera > video[data-mirrored] {
  transform: scaleX(-1);
}

.practice__camera-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.practice__coach {
  grid-area: 2 / 2;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: var(--coach-top) max(var(--coach-right), env(safe-area-inset-right, 0px))
    var(--coach-bottom) var(--coach-left);
}

.practice__center {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  gap: 6px;
}

.practice__prompt,
.practice__caption {
  flex: none;
}

.practice__signal-lost {
  display: grid;
  place-items: center;
  flex: none;
  width: clamp(44px, 32cqw, 84px);
  aspect-ratio: 1;
  border: 2.5px dashed var(--v2-text-secondary);
  border-radius: var(--v2-radius-16);
  color: var(--v2-text-secondary);
}

.practice__checklist {
  list-style: none;
  margin: 0;
  padding: 0;
}

.practice__check + .practice__check {
  margin-top: var(--v2-space-4);
}

.practice__check-content {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  gap: var(--v2-space-8);
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--v2-radius-8);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}

button.practice__check-content {
  border-color: var(--v2-border-default);
  cursor: pointer;
}

button.practice__check-content:hover {
  border-color: var(--v2-text-brand);
}

button.practice__check-content:focus-visible {
  outline: 3px solid var(--v2-border-focus);
  outline-offset: 2px;
}

.practice__check-icon {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  line-height: 1;
}

.practice__check[data-status="unknown"] .practice__check-icon {
  border: 0;
}

.practice[data-state="calibrating"] .practice__coach {
  justify-content: center;
  gap: var(--v2-space-12);
}

.practice[data-state="calibrating"] .practice__center {
  flex: none;
  align-items: stretch;
}

.practice__align-icon {
  display: none;
  align-self: flex-start;
  width: 56px;
  height: 56px;
  color: var(--v2-text-brand);
}

.practice[data-state="calibrating"] .practice__align-icon {
  display: block;
}

.practice[data-state="calibrating"] .practice__prompt.p-l {
  font-size: clamp(16px, 8.75cqw, 20px);
  text-align: left;
  text-wrap: wrap;
}

.practice[data-state="calibrating"] .practice__band-slot {
  display: none;
}

.practice__actions {
  display: grid;
  gap: var(--v2-space-12);
  margin-block: var(--v2-space-4);
}

.practice__band-slot {
  flex: 0 0 var(--band-h);
  margin-inline: calc(-1 * var(--coach-left)) calc(-1 * var(--coach-right));
  margin-bottom: calc(-1 * var(--coach-bottom));
}

.practice__band-slot > .practice-band {
  min-height: 100%;
}

.practice__progress.session-progress {
  grid-area: 3 / 1 / 4 / -1;
  position: static;
  display: grid;
  height: auto;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  padding-bottom: var(--progress-safe);
}

.practice__fatal,
.practice__fatal > .session-danger-overlay {
  position: absolute;
  inset: 0;
}

.practice__fatal {
  z-index: 10;
}

.practice__fatal > .session-danger-overlay {
  border: 0;
  padding: var(--v2-space-16) var(--v2-space-24) max(var(--v2-space-16), var(--progress-safe));
  gap: var(--v2-space-8);
}

.practice[data-state="hold"] {
  --coach-w: clamp(200px, 35.5%, 300px);
}

.practice[data-state="stopped"] .practice__camera {
  visibility: hidden;
}

.practice[data-state="stopped"] .practice__coach {
  grid-column: 1 / -1;
  padding-inline: clamp(20px, 6vw, 56px);
}

.practice[data-state="stopped"] .practice__actions {
  grid-template-columns: repeat(2, minmax(0, 160px));
  justify-content: center;
  align-items: center;
}

.practice[data-state="stopped"] .practice__coach .practice__prompt {
  font-size: clamp(30px, 13vh, 64px);
  line-height: 1.1;
}

@media (max-height: 380px) {
  .practice {
    --coach-top: 10px;
    --coach-right: 12px;
    --coach-bottom: 8px;
    --coach-left: 16px;
    --band-h: 40px;
  }

  .practice__actions {
    gap: var(--v2-space-8);
  }

  .practice__check-content {
    min-height: var(--v2-size-touch-min);
    font-size: 13px;
  }

  .practice__align-icon {
    width: 36px;
    height: 36px;
  }
}

@media (max-width: 640px) {
  .practice[data-state="calibrating"] {
    --coach-w: 240px;
  }
}

@media (max-width: 620px), (max-height: 340px) {
  .practice {
    --coach-top: 8px;
    --coach-right: 8px;
    --coach-left: 14px;
    --band-h: 36px;
  }

  .practice__top {
    gap: var(--v2-space-8);
    padding-inline: max(10px, env(safe-area-inset-left, 0px)) max(10px, env(safe-area-inset-right, 0px));
  }

  .practice__center {
    gap: 2px;
  }

  .practice__align-icon {
    width: 28px;
    height: 28px;
  }
}

/* ==========================================================================
   B6 theo spec 5.3 (UI/UX MVP): camera phủ cả màn + lớp tối 74%,
   vòng nhịp bên trái, MỘT lời nhắc bên phải, dải cảnh báo ngay trên viền tiến độ.
   Căn chỉnh (calibrating) và Phiên đã dừng (stopped) giữ bố cục riêng ở trên.
   ========================================================================== */
.practice:is([data-state="measuring"], [data-state="correct"], [data-state="warning"],
  [data-state="thermal"], [data-state="lost"], [data-state="paused"],
  [data-state="unscored"], [data-state="l3"], [data-state="hold"]) {
  --band-h: 40px;
  grid-template-columns: minmax(0, 1fr);
}

.practice:is([data-state="measuring"], [data-state="correct"], [data-state="warning"],
  [data-state="thermal"], [data-state="lost"], [data-state="paused"],
  [data-state="unscored"], [data-state="l3"], [data-state="hold"]) .practice__camera {
  grid-area: 1 / 1 / -1 / -1;
  z-index: 0;
}

.practice:is([data-state="measuring"], [data-state="correct"], [data-state="warning"],
  [data-state="thermal"], [data-state="lost"], [data-state="paused"],
  [data-state="unscored"], [data-state="l3"], [data-state="hold"]) .practice__top {
  position: relative;
  z-index: 2;
}

.practice:is([data-state="measuring"], [data-state="correct"], [data-state="warning"],
  [data-state="thermal"], [data-state="lost"], [data-state="paused"],
  [data-state="unscored"], [data-state="l3"], [data-state="hold"]) .practice__coach {
  grid-area: 2 / 1 / 3 / 2;
  z-index: 1;
  padding: var(--v2-space-16) max(40px, env(safe-area-inset-right, 0px))
    0 max(40px, env(safe-area-inset-left, 0px));
}

.practice:is([data-state="measuring"], [data-state="correct"], [data-state="warning"],
  [data-state="thermal"], [data-state="lost"], [data-state="paused"],
  [data-state="unscored"], [data-state="l3"], [data-state="hold"]) .practice__step {
  display: none;
}

.practice:is([data-state="measuring"], [data-state="correct"], [data-state="warning"],
  [data-state="thermal"], [data-state="lost"], [data-state="paused"],
  [data-state="unscored"], [data-state="l3"], [data-state="hold"]) .practice__center {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-content: center;
  justify-items: start;
  column-gap: 40px;
  row-gap: var(--v2-space-8);
  padding-bottom: var(--band-h);
}

.practice:is([data-state="measuring"], [data-state="correct"], [data-state="warning"],
  [data-state="thermal"], [data-state="lost"], [data-state="paused"],
  [data-state="unscored"], [data-state="l3"], [data-state="hold"])
  :is(.practice__ring-slot, .practice__signal-lost) {
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: center;
}

.practice__center:not(:has(.practice__caption:not([hidden]))) > :is(.practice__ring-slot, .practice__signal-lost) {
  grid-row: 1;
}

.practice:is([data-state="measuring"], [data-state="correct"], [data-state="warning"],
  [data-state="thermal"], [data-state="lost"], [data-state="paused"],
  [data-state="unscored"], [data-state="l3"], [data-state="hold"])
  :is(.practice__prompt, .practice__caption) {
  grid-column: 2;
  text-align: left;
}

.practice:is([data-state="measuring"], [data-state="correct"], [data-state="warning"],
  [data-state="thermal"], [data-state="lost"], [data-state="paused"],
  [data-state="unscored"], [data-state="l3"], [data-state="hold"]) .practice__actions {
  grid-template-columns: repeat(2, minmax(0, 180px));
  justify-content: start;
  margin-bottom: calc(var(--band-h) + var(--v2-space-8));
}

.practice:is([data-state="measuring"], [data-state="correct"], [data-state="warning"],
  [data-state="thermal"], [data-state="lost"], [data-state="paused"],
  [data-state="unscored"], [data-state="l3"], [data-state="hold"]) .practice__band-slot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--band-h);
  margin: 0;
}

@media (max-width: 620px), (max-height: 340px) {
  .practice:is([data-state="measuring"], [data-state="correct"], [data-state="warning"],
    [data-state="thermal"], [data-state="lost"], [data-state="paused"],
    [data-state="unscored"], [data-state="l3"], [data-state="hold"]) .practice__coach {
    padding-inline: max(20px, env(safe-area-inset-left, 0px)) max(20px, env(safe-area-inset-right, 0px));
  }

  .practice:is([data-state="measuring"], [data-state="correct"], [data-state="warning"],
    [data-state="thermal"], [data-state="lost"], [data-state="paused"],
    [data-state="unscored"], [data-state="l3"], [data-state="hold"]) .practice__center {
    column-gap: var(--v2-space-24);
  }
}
