:root {
  --ink: #f8f1d2;
  --muted: rgba(248, 241, 210, 0.72);
  --panel: rgba(12, 40, 50, 0.82);
  --panel-strong: rgba(18, 58, 67, 0.92);
  --gold: #ffd46a;
  --cyan: #62ecff;
  --green: #9bf3a2;
  --stone: #9a6741;
  --deep: #04121c;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background:
    radial-gradient(circle at 82% 20%, rgba(85, 216, 234, 0.22), transparent 28%),
    radial-gradient(circle at 22% 16%, rgba(255, 226, 143, 0.28), transparent 24%),
    linear-gradient(180deg, #eefcf6 0%, #d8f4f2 52%, #eef7df 100%);
}

button,
a {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.cave-app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
  height: 100%;
  padding: 12px 16px 10px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(170px, 0.62fr) repeat(3, minmax(132px, 0.46fr)) auto;
  gap: 10px;
  align-items: center;
}

.brand,
.status-card,
.topbar-actions a,
.guide-card,
.hand-panel,
.timeline-panel,
.feedback-pill,
.play-panel,
.overlay-card {
  border: 1px solid rgba(255, 207, 142, 0.42);
  background:
    linear-gradient(180deg, rgba(28, 75, 82, 0.9), rgba(12, 35, 46, 0.86));
  box-shadow:
    0 16px 34px rgba(0, 0, 0, 0.24),
    inset 0 0 0 2px rgba(255, 220, 142, 0.08);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
  min-height: 58px;
  padding: 9px 13px;
  border-radius: 14px;
  color: var(--ink);
  text-decoration: none;
}

.brand-icon,
.status-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: radial-gradient(circle at 35% 28%, #fff0a4, #f39d42 58%, #79451f);
  color: #073342;
  font-size: 23px;
  font-weight: 1000;
  box-shadow: 0 0 20px rgba(255, 184, 70, 0.35);
}

.brand small,
.status-card small,
.play-panel span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.brand strong {
  display: block;
  margin-top: 3px;
  font-size: 22px;
  line-height: 1.05;
}

.status-card {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
  min-height: 58px;
  padding: 9px 12px;
  border-radius: 14px;
}

.status-card strong {
  display: block;
  margin-top: 3px;
  color: var(--gold);
  font-size: 24px;
  line-height: 1;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.topbar-actions a {
  display: grid;
  place-items: center;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}

.stage-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 66px;
  gap: 12px;
  min-height: 0;
}

.guide-card {
  position: absolute;
  z-index: 6;
  left: 18px;
  top: 18px;
  width: min(230px, 32vw);
  padding: 12px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 229, 185, 0.9), rgba(242, 196, 129, 0.86));
  color: #35220f;
  box-shadow:
    0 14px 30px rgba(48, 31, 12, 0.16),
    inset 0 0 0 1px rgba(255, 246, 206, 0.44);
}

.guide-mark {
  display: none;
  color: #b87a21;
  font-size: 26px;
  text-align: center;
}

.guide-card h1 {
  margin: 0 0 8px;
  font-size: clamp(18px, 1.45vw, 24px);
  line-height: 1.16;
}

.guide-card p {
  margin: 0;
  color: rgba(53, 34, 15, 0.78);
  font-size: 14px;
  font-weight: 750;
  line-height: 1.62;
}

.guide-cues {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 8px 0 10px;
}

.guide-cues article {
  display: grid;
  gap: 3px;
  min-height: 46px;
  padding: 7px 8px;
  border-radius: 11px;
  background: rgba(255, 249, 226, 0.62);
}

.guide-cues article:last-child {
  grid-column: 1 / -1;
  min-height: 38px;
}

.guide-cues strong {
  color: #8d5c17;
  font-size: 13px;
  line-height: 1.1;
}

.guide-cues span {
  color: rgba(53, 34, 15, 0.84);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.35;
}

#cameraButton {
  width: 100%;
  min-height: 36px;
  border-radius: 10px;
  background: linear-gradient(180deg, #13d6d1, #108ca2);
  color: #052736;
  font-size: 14px;
  font-weight: 1000;
  box-shadow: 0 12px 22px rgba(9, 108, 120, 0.26);
}

.fallback-note {
  display: none;
  margin-top: 10px !important;
  font-size: 13px !important;
}

.score-rubric {
  display: grid;
  gap: 5px;
  margin-top: 12px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(255, 249, 226, 0.54);
}

.score-rubric strong {
  color: #8d5c17;
  font-size: 17px;
  line-height: 1.1;
}

.score-rubric span {
  color: rgba(53, 34, 15, 0.84);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.28;
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 26px;
  background: #e7f8f2;
  box-shadow:
    0 30px 60px rgba(42, 105, 121, 0.18),
    inset 0 0 0 1px rgba(255, 255, 255, 0.58);
  touch-action: none;
}

#camera,
#gameCanvas,
.stage-shade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.guide-overlay,
.result-overlay,
.calibration-overlay {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 42%, rgba(11, 38, 50, 0.38), rgba(3, 11, 17, 0.72));
}

.guide-overlay.is-hidden,
.result-overlay.is-hidden,
.calibration-overlay.is-hidden {
  display: none;
}

.overlay-card {
  width: min(650px, 92%);
  padding: 24px;
  border-radius: 20px;
  text-align: center;
}

.overlay-card:has(.prestart-demo) {
  width: min(760px, 94%);
  padding: 22px;
}

.overlay-card:has(.prestart-demo) h1 {
  margin-bottom: 14px;
  font-size: clamp(28px, 3vw, 42px);
}

.sync-guide-card {
  width: min(860px, 94%);
  padding: 18px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  max-height: min(84dvh, 690px);
  overflow: hidden;
}

.sync-guide-card h1 {
  margin: 10px 0 12px;
  font-size: clamp(24px, 2.6vw, 36px);
}

.sync-guide {
  position: relative;
  min-height: 0;
  height: min(46dvh, 430px);
  overflow: hidden;
  border: 1px solid rgba(255, 211, 107, 0.28);
  border-radius: 18px;
  background: rgba(10, 49, 58, 0.78);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), 0 18px 60px rgba(0, 0, 0, 0.26);
}

.sync-guide video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: rgba(8, 34, 45, 0.9);
}

.sync-guide audio {
  display: none;
}

.sync-guide-card .overlay-actions {
  position: relative;
  z-index: 8;
  margin-top: 12px;
  padding: 12px 8px 0;
  border-top: 1px solid rgba(255, 211, 107, 0.18);
  background: linear-gradient(180deg, rgba(9, 43, 54, 0.96), rgba(9, 43, 54, 1));
}

.sync-dim {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(5, 18, 25, 0.03), rgba(5, 18, 25, 0.24));
}

.sync-status {
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 4;
  border-radius: 999px;
  background: rgba(255, 247, 214, 0.9);
  color: #7b5c10;
  padding: 7px 12px;
  font-size: 14px;
  font-weight: 1000;
}

.sync-caption {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 5%;
  z-index: 4;
  display: grid;
  gap: 8px;
  border: 2px solid rgba(255, 211, 107, 0.44);
  border-radius: 16px;
  background: rgba(5, 24, 31, 0.82);
  color: #ffffff;
  padding: clamp(14px, 2vw, 22px);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
}

.sync-caption.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.sync-caption strong {
  color: var(--gold);
  font-size: clamp(22px, 3vw, 40px);
  line-height: 1.05;
  font-weight: 1000;
}

.sync-caption span {
  font-size: clamp(16px, 1.8vw, 25px);
  font-weight: 900;
  line-height: 1.38;
}

.overlay-kicker {
  display: inline-grid;
  place-items: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 211, 107, 0.18);
  color: var(--gold);
  font-size: 14px;
  font-weight: 1000;
}

.overlay-card h1 {
  margin: 14px auto 16px;
  max-width: 520px;
  font-size: clamp(30px, 3.3vw, 44px);
  line-height: 1.12;
}

.overlay-steps,
.result-grid {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}

.overlay-steps {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.overlay-card:has(.prestart-demo) .overlay-steps {
  display: none;
}

.result-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.overlay-steps article,
.result-grid article,
.result-advice {
  padding: 16px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.09);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.overlay-steps strong {
  color: var(--gold);
  font-size: 24px;
}

.result-advice strong {
  color: var(--gold);
  font-size: 18px;
}

.overlay-steps p,
.result-card p,
.result-advice p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.5;
}

.overlay-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

.overlay-actions button {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  background: linear-gradient(180deg, #13d6d1, #108ca2);
  color: #052736;
  font-weight: 1000;
}

.overlay-actions button + button {
  background: rgba(255, 255, 255, 0.16);
  color: var(--ink);
}

.prestart-demo {
  position: relative;
  height: min(42vh, 330px);
  min-height: 248px;
  overflow: hidden;
  border: 1px solid rgba(255, 207, 142, 0.34);
  border-radius: 20px;
  background:
    radial-gradient(circle at 35% 70%, rgba(98, 236, 255, 0.2), transparent 34%),
    linear-gradient(180deg, rgba(16, 55, 65, 0.9), rgba(8, 29, 39, 0.92));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 18px 38px rgba(0, 0, 0, 0.18);
}

.cave-title-open,
.cave-title-close {
  position: absolute;
  z-index: 8;
  left: 22px;
  top: 18px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 211, 107, 0.2);
  color: var(--gold);
  font-size: 16px;
  font-weight: 1000;
}

.cave-title-close {
  opacity: 0;
}

.overlay-card:has(.prestart-demo) .cave-title-open {
  animation: caveDemoOpenTitle 12s linear infinite;
}

.overlay-card:has(.prestart-demo) .cave-title-close {
  animation: caveDemoCloseTitle 12s linear infinite;
}

.demo-cave-roof-line {
  position: absolute;
  z-index: 1;
  left: -4%;
  right: -4%;
  top: 32%;
  height: 72px;
  border-radius: 0 0 44% 44%;
  background:
    linear-gradient(180deg, rgba(103, 64, 39, 0.94), rgba(55, 35, 25, 0.96));
  box-shadow:
    0 12px 0 rgba(25, 16, 12, 0.7),
    inset 0 -12px 24px rgba(0, 0, 0, 0.18);
  animation: caveDemoRoof 12s ease-in-out infinite;
}

.demo-cave-roof-line::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -5px;
  border-bottom: 5px dashed rgba(255, 211, 107, 0.88);
  filter: drop-shadow(0 0 8px rgba(255, 211, 107, 0.55));
}

.demo-cave-floor-line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 28px;
  height: 38px;
  background: linear-gradient(180deg, rgba(114, 79, 51, 0.8), rgba(64, 44, 36, 0.96));
}

.demo-cave-gate {
  position: absolute;
  z-index: 3;
  bottom: 48px;
  width: 74px;
  border: 6px solid rgba(255, 211, 107, 0.86);
  border-bottom: 0;
  border-radius: 34px 34px 0 0;
  box-shadow: 0 0 18px rgba(255, 211, 107, 0.28);
}

.demo-cave-gate.gate-large {
  left: 46%;
  height: 142px;
  animation: caveDemoGateLargeGlow 12s linear infinite;
}

.demo-cave-gate.gate-small {
  left: 73%;
  height: 82px;
  animation: caveDemoGateSmallGlow 12s linear infinite;
}

.demo-cave-character {
  position: absolute;
  z-index: 5;
  left: 18%;
  bottom: 48px;
  width: 78px;
  height: 110px;
  border-radius: 42px 42px 30px 30px;
  background:
    radial-gradient(circle at 58% 22%, #1a2f3c 0 4px, transparent 5px),
    radial-gradient(circle at 68% 34%, #ff9f82 0 8px, transparent 9px),
    linear-gradient(180deg, #58cdbd, #218e88);
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.22);
  transform-origin: bottom center;
  animation: caveDemoCharacter 12s ease-in-out infinite;
}

.demo-cave-target {
  position: absolute;
  z-index: 6;
  right: 30px;
  top: 46%;
  width: 20px;
  height: 20px;
  border: 4px solid rgba(255, 247, 215, 0.96);
  border-radius: 50%;
  background: #ffd46a;
  box-shadow: 0 0 20px rgba(255, 211, 107, 0.68);
  animation: caveDemoTarget 12s ease-in-out infinite;
}

.demo-cave-caption {
  position: absolute;
  z-index: 8;
  right: 22px;
  bottom: 18px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 247, 215, 0.86);
  color: #35220f;
  font-size: 14px;
  font-weight: 1000;
}

.demo-cave-pass {
  position: absolute;
  z-index: 9;
  bottom: 18px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(155, 243, 162, 0.9);
  color: #073342;
  font-size: 13px;
  font-weight: 1000;
  opacity: 0;
  box-shadow: 0 0 18px rgba(155, 243, 162, 0.58);
}

.pass-large {
  left: 42%;
  animation: caveDemoPassLarge 12s linear infinite;
}

.pass-small {
  left: 68%;
  animation: caveDemoPassSmall 12s linear infinite;
}

.demo-cave-hand {
  position: absolute;
  z-index: 7;
  right: 70px;
  top: 112px;
  width: 48px;
  height: 56px;
  border-radius: 18px 18px 22px 22px;
  background: linear-gradient(180deg, #ffe0a6, #ef9d55);
  box-shadow: 0 12px 22px rgba(0, 0, 0, 0.18);
  animation: caveDemoPalm 12s ease-in-out infinite;
}

.demo-cave-hand .finger {
  position: absolute;
  bottom: 44px;
  width: 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe9bd, #f2a864);
  transform-origin: bottom center;
}

.demo-cave-hand .f1 { left: 8px; height: 34px; transform: rotate(-5deg); animation: caveDemoFinger1 12s ease-in-out infinite; }
.demo-cave-hand .f2 { left: 17px; height: 36px; animation: caveDemoFinger2 12s ease-in-out infinite; }
.demo-cave-hand .f3 { left: 27px; height: 36px; animation: caveDemoFinger3 12s ease-in-out infinite; }
.demo-cave-hand .f4 { left: 36px; height: 32px; transform: rotate(6deg); animation: caveDemoFinger4 12s ease-in-out infinite; }

.demo-cave-hand b {
  position: absolute;
  left: -6px;
  top: 22px;
  width: 24px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #f1a45e, #ffe1aa);
  transform: rotate(-18deg);
  animation: caveDemoThumb 12s ease-in-out infinite;
}

@keyframes caveDemoOpenTitle {
  0%, 48% { opacity: 1; }
  56%, 100% { opacity: 0; }
}

@keyframes caveDemoCloseTitle {
  0%, 50% { opacity: 0; }
  58%, 84% { opacity: 1; }
  92%, 100% { opacity: 0; }
}

@keyframes caveDemoRoof {
  0%, 14% { transform: translateY(38px); }
  34%, 48% { transform: translateY(-42px); }
  68%, 84% { transform: translateY(42px); }
  100% { transform: translateY(38px); }
}

@keyframes caveDemoCharacter {
  0%, 10% {
    left: 16%;
    transform: scale(0.72);
  }
  28% {
    left: 39%;
    transform: scale(1.12);
  }
  38%, 46% {
    left: 47%;
    transform: scale(1.22);
    filter: drop-shadow(0 0 16px rgba(155, 243, 162, 0.75));
  }
  58% {
    left: 61%;
    transform: scale(1.02);
    filter: none;
  }
  72%, 82% {
    left: 74%;
    transform: scale(0.76);
    filter: drop-shadow(0 0 16px rgba(155, 243, 162, 0.75));
  }
  92%, 100% {
    left: 88%;
    transform: scale(0.72);
    filter: none;
  }
}

@keyframes caveDemoTarget {
  0%, 14% { top: 62%; }
  34%, 48% { top: 30%; }
  68%, 84% { top: 64%; }
  100% { top: 62%; }
}

@keyframes caveDemoGateLargeGlow {
  0%, 30%, 52%, 100% {
    box-shadow: 0 0 18px rgba(255, 211, 107, 0.28);
  }
  36%, 46% {
    box-shadow: 0 0 0 12px rgba(155, 243, 162, 0.22), 0 0 30px rgba(155, 243, 162, 0.72);
  }
}

@keyframes caveDemoGateSmallGlow {
  0%, 64%, 88%, 100% {
    box-shadow: 0 0 18px rgba(255, 211, 107, 0.28);
  }
  72%, 82% {
    box-shadow: 0 0 0 12px rgba(155, 243, 162, 0.22), 0 0 30px rgba(155, 243, 162, 0.72);
  }
}

@keyframes caveDemoPassLarge {
  0%, 34%, 52%, 100% {
    opacity: 0;
    transform: translateY(6px);
  }
  38%, 48% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes caveDemoPassSmall {
  0%, 68%, 88%, 100% {
    opacity: 0;
    transform: translateY(6px);
  }
  73%, 84% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes caveDemoPalm {
  0%, 14% { transform: scale(0.86); }
  34%, 48% { transform: scale(1.12); }
  68%, 84% { transform: scale(0.86); }
  100% { transform: scale(0.86); }
}

@keyframes caveDemoFinger1 {
  0%, 14% { left: 8px; height: 34px; transform: rotate(-5deg); }
  34%, 48% { left: 4px; height: 46px; transform: rotate(-28deg); }
  68%, 100% { left: 8px; height: 34px; transform: rotate(-5deg); }
}

@keyframes caveDemoFinger2 {
  0%, 14% { left: 17px; height: 36px; transform: rotate(0deg); }
  34%, 48% { left: 16px; height: 52px; transform: rotate(-7deg); }
  68%, 100% { left: 17px; height: 36px; transform: rotate(0deg); }
}

@keyframes caveDemoFinger3 {
  0%, 14% { left: 27px; height: 36px; transform: rotate(0deg); }
  34%, 48% { left: 28px; height: 48px; transform: rotate(13deg); }
  68%, 100% { left: 27px; height: 36px; transform: rotate(0deg); }
}

@keyframes caveDemoFinger4 {
  0%, 14% { left: 36px; height: 32px; transform: rotate(6deg); }
  34%, 48% { left: 39px; height: 38px; transform: rotate(30deg); }
  68%, 100% { left: 36px; height: 32px; transform: rotate(6deg); }
}

@keyframes caveDemoThumb {
  0%, 14% { left: -6px; top: 22px; width: 24px; transform: rotate(-18deg); }
  34%, 48% { left: -14px; top: 16px; width: 32px; transform: rotate(-42deg); }
  68%, 100% { left: -6px; top: 22px; width: 24px; transform: rotate(-18deg); }
}

.result-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.result-grid strong {
  display: block;
  margin-top: 5px;
  color: var(--green);
  font-size: 34px;
  line-height: 1;
}

.segment-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 16px;
}

.segment-list article {
  display: grid;
  gap: 4px;
  min-height: 54px;
  padding: 9px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07);
}

.segment-list span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 950;
}

.segment-list strong {
  color: #ffd36b;
  font-size: 15px;
  line-height: 1.12;
}

.segment-list article.is-good strong {
  color: var(--green);
}

.segment-list article.is-ok strong {
  color: #c8fbff;
}

.result-advice {
  text-align: left;
}

.calibration-card {
  width: min(560px, 92%);
  padding: 28px;
  border: 1px solid rgba(255, 207, 142, 0.48);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(28, 75, 82, 0.94), rgba(12, 35, 46, 0.92));
  box-shadow:
    0 18px 46px rgba(0, 0, 0, 0.34),
    inset 0 0 0 2px rgba(255, 220, 142, 0.08);
  text-align: center;
}

.calibration-card h1 {
  margin: 14px 0 8px;
  color: var(--gold);
  font-size: clamp(30px, 4vw, 52px);
  line-height: 1.08;
}

.calibration-card p {
  margin: 0 auto;
  max-width: 420px;
  color: var(--muted);
  font-size: 17px;
  font-weight: 850;
  line-height: 1.5;
}

.calibration-meter {
  position: relative;
  height: 24px;
  margin: 24px auto 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.calibration-meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #62ecff, #9bf3a2, #ffd46a);
  box-shadow: 0 0 18px rgba(98, 236, 255, 0.42);
  transition: width 120ms linear;
}

.calibration-card > strong {
  display: block;
  color: var(--green);
  font-size: 24px;
  line-height: 1.1;
}

#camera {
  z-index: 1;
  object-fit: cover;
  opacity: 0;
  transform: scaleX(-1);
  filter: saturate(0.86) contrast(1.02) brightness(1.08) blur(0.2px);
  transition: opacity 180ms ease;
}

#camera.is-live {
  opacity: 0;
}

#gameCanvas {
  z-index: 2;
}

.stage-shade {
  z-index: 3;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(248, 255, 236, 0.28), transparent 22%, transparent 78%, rgba(141, 226, 242, 0.18)),
    radial-gradient(circle at 52% 42%, transparent 0 58%, rgba(255, 255, 255, 0.2) 100%);
}

.feedback-pill {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 96px;
  display: grid;
  justify-items: center;
  min-width: 210px;
  padding: 12px 18px;
  border-radius: 18px;
  transform: translateX(-50%);
  text-align: center;
}

.feedback-pill strong {
  color: var(--green);
  font-size: 25px;
  line-height: 1.05;
}

.feedback-pill span {
  margin-top: 3px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 850;
}

.feedback-pill.is-warning strong {
  color: #ffd36b;
}

.feedback-pill.is-danger strong {
  color: #ff736a;
}

.countdown-overlay {
  position: absolute;
  z-index: 7;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: radial-gradient(circle at 50% 48%, rgba(255, 229, 121, 0.26), rgba(4, 18, 28, 0.46) 42%, rgba(4, 18, 28, 0.08) 72%);
}

.countdown-overlay.is-hidden {
  display: none;
}

.countdown-overlay strong {
  display: grid;
  place-items: center;
  width: min(26vw, 190px);
  height: min(26vw, 190px);
  border: 4px solid rgba(255, 238, 172, 0.92);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 249, 196, 0.98), rgba(255, 181, 59, 0.96) 62%, rgba(119, 72, 24, 0.98));
  color: #17220a;
  font-size: clamp(64px, 13vw, 126px);
  font-weight: 1000;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.38);
  box-shadow:
    0 0 42px rgba(255, 211, 107, 0.52),
    0 18px 40px rgba(0, 0, 0, 0.3);
  animation: countdown-pop 860ms ease both;
}

.countdown-overlay span {
  position: absolute;
  top: calc(50% + min(15vw, 118px));
  padding: 8px 18px;
  border-radius: 14px;
  background: rgba(6, 29, 39, 0.82);
  color: var(--ink);
  font-size: clamp(18px, 2vw, 26px);
  font-weight: 1000;
  box-shadow: 0 0 22px rgba(98, 236, 255, 0.24);
}

@keyframes countdown-pop {
  0% {
    opacity: 0;
    transform: scale(0.72);
  }

  18% {
    opacity: 1;
    transform: scale(1.06);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.play-panel {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 16px;
  transform: translateX(-50%);
}

#playButton {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #fff2a3, #ffb33b 62%, #87531d);
  color: #1d2208;
  font-size: 22px;
  font-weight: 1000;
}

#playButton:disabled {
  cursor: wait;
  opacity: 0.72;
}

.play-panel strong {
  display: block;
  min-width: 98px;
  color: var(--gold);
  font-size: 18px;
}

.hand-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  justify-items: center;
  gap: 8px;
  padding: 10px 7px;
  border-radius: 18px;
  opacity: 0.95;
}

.hand-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid rgba(98, 236, 255, 0.5);
  color: var(--cyan);
  font-size: 18px;
  font-weight: 1000;
  box-shadow: 0 0 22px rgba(98, 236, 255, 0.24);
}

.hand-panel strong {
  color: var(--gold);
  font-size: 12px;
  writing-mode: vertical-rl;
  letter-spacing: 0;
}

.hand-slider {
  position: relative;
  width: 36px;
  height: 100%;
  min-height: 190px;
  touch-action: none;
  outline: none;
}

.target-label {
  position: absolute;
  z-index: 2;
  left: -80px;
  top: 50%;
  width: 70px;
  color: rgba(248, 241, 210, 0.9);
  font-size: 12px;
  font-weight: 1000;
  line-height: 1.2;
  text-align: right;
  transform: translateY(-50%);
}

.hand-track,
.hand-fill {
  position: absolute;
  left: 50%;
  width: 6px;
  border-radius: 999px;
  transform: translateX(-50%);
}

.hand-track {
  inset-block: 0;
  background: rgba(255, 255, 255, 0.18);
}

.hand-fill {
  bottom: 0;
  height: 50%;
  background: linear-gradient(0deg, #ffbc49, #9ff8a6, #62ecff);
  box-shadow: 0 0 18px rgba(98, 236, 255, 0.42);
}

.hand-knob {
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255, 246, 194, 0.95);
  border-radius: 50%;
  background: #a7ffad;
  transform: translate(-50%, 50%);
  box-shadow: 0 0 18px rgba(167, 255, 173, 0.64);
}

.timeline-panel {
  align-self: end;
  display: grid;
  grid-template-rows: auto 48px auto;
  gap: 2px;
  width: min(1320px, calc(100% - 80px));
  margin: 0 auto;
  padding: 6px 14px;
  border-radius: 16px;
  opacity: 0.74;
}

.timeline-labels {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  color: #c9efff;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(18px, 2.1vw, 32px);
  font-style: italic;
  font-weight: 700;
  text-align: center;
}

#timelineCanvas {
  width: 100%;
  height: 48px;
}

.timeline-caption {
  display: flex;
  justify-content: center;
  gap: min(7vw, 80px);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.orientation-lock {
  display: none;
}

@media (max-width: 980px), (orientation: portrait) {
  .cave-app {
    padding: 12px;
  }

  .topbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage-shell {
    grid-template-columns: minmax(0, 1fr) 80px;
  }

  .guide-card {
    display: none;
  }

  .timeline-panel {
    width: 100%;
  }

  .overlay-steps,
  .result-grid,
  .segment-list {
    grid-template-columns: 1fr;
  }

  .sync-guide-card {
    max-height: calc(100dvh - 28px);
    overflow: auto;
  }

  .sync-guide {
    height: min(48dvh, 390px);
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  .orientation-lock {
    position: fixed;
    z-index: 20;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 28px;
    background: linear-gradient(180deg, #061827, #092636);
    text-align: center;
  }

  .orientation-lock div {
    max-width: 360px;
    padding: 28px;
    border-radius: 20px;
    background: rgba(255, 229, 185, 0.94);
    color: #35220f;
  }

  .orientation-lock span {
    font-size: 54px;
    font-weight: 1000;
  }

  .orientation-lock h1 {
    margin: 8px 0;
  }
}

/* v88: mobile and in-app browser fit layer for small landscape viewports. */
html,
body {
  height: var(--pml-app-height, 100dvh);
  min-height: var(--pml-app-height, 100dvh);
}

.cave-app {
  height: var(--pml-app-height, 100dvh);
  min-height: var(--pml-app-height, 100dvh);
  padding-right: max(10px, env(safe-area-inset-right));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  padding-left: max(10px, env(safe-area-inset-left));
}

body.pml-mobile-game .guide-overlay,
body.pml-mobile-game .result-overlay,
body.pml-mobile-game .calibration-overlay {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

body.pml-mobile-game .overlay-card,
body.pml-mobile-game .sync-guide-card,
body.pml-mobile-game .result-card,
body.pml-mobile-game .calibration-card {
  max-height: calc(var(--pml-app-height, 100dvh) - 20px);
  overflow: auto;
}

body.pml-mobile-game .overlay-actions,
body.pml-mobile-game .result-actions {
  position: sticky;
  bottom: 0;
  z-index: 3;
  padding-top: 10px;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(12, 35, 46, 0), rgba(12, 35, 46, 0.9) 34%);
}

body.pml-compact-game .cave-app {
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 5px;
  padding-top: max(6px, env(safe-area-inset-top));
  padding-bottom: max(6px, env(safe-area-inset-bottom));
}

body.pml-compact-game .brand {
  display: none;
}

body.pml-compact-game .topbar {
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 5px;
}

body.pml-compact-game .status-card {
  min-height: 38px;
  padding: 4px 6px;
  border-radius: 10px;
  gap: 5px;
}

body.pml-compact-game .status-icon {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  font-size: 14px;
}

body.pml-compact-game .status-card small {
  font-size: 9px;
}

body.pml-compact-game .status-card strong {
  font-size: 12px;
  line-height: 1.05;
}

body.pml-compact-game .topbar-actions a,
body.pml-compact-game #cameraButton {
  min-height: 30px;
  padding: 0 8px;
  border-radius: 9px;
  font-size: 11px;
}

body.pml-compact-game .stage-shell {
  grid-template-columns: minmax(0, 1fr) 60px;
  gap: 6px;
}

body.pml-compact-game .guide-card {
  display: none;
}

body.pml-compact-game .hand-panel {
  gap: 4px;
  padding: 6px 5px;
  border-radius: 12px;
}

body.pml-compact-game .hand-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 14px;
}

body.pml-compact-game .hand-slider {
  width: 26px;
  min-height: 120px;
}

body.pml-compact-game .target-label {
  display: none;
}

body.pml-compact-game .timeline-panel {
  width: 100%;
  grid-template-rows: auto 30px;
  padding: 4px 8px;
  border-radius: 12px;
}

body.pml-compact-game .timeline-labels,
body.pml-compact-game .timeline-caption {
  display: none;
}

body.pml-compact-game #timelineCanvas {
  height: 30px;
}

body.pml-compact-game .feedback-pill {
  bottom: 58px;
  min-width: 160px;
  padding: 8px 12px;
}

body.pml-compact-game .feedback-pill strong {
  font-size: 18px;
}

body.pml-compact-game .sync-guide-card {
  width: min(760px, calc(100vw - 20px));
  padding: 12px;
  border-radius: 16px;
}

body.pml-compact-game .sync-guide-card h1,
body.pml-compact-game .overlay-card h1 {
  font-size: clamp(22px, 5.2vw, 30px);
}

body.pml-compact-game .sync-guide {
  height: clamp(150px, 44dvh, 250px);
}

body.pml-compact-game .sync-caption {
  right: 10px;
  bottom: 10px;
  left: 10px;
  max-width: none;
  padding: 9px 11px;
}

body.pml-compact-game .overlay-actions button,
body.pml-compact-game .result-actions button,
body.pml-compact-game .result-actions a {
  min-height: 42px;
  padding: 0 16px;
  font-size: 15px;
}

/* v89: immersive play mode for phone browsers and in-app browsers */
body.pml-game-immersive .cave-app {
  grid-template-rows: minmax(0, 1fr) 40px;
  gap: 6px;
  height: var(--pml-app-height, 100dvh);
  min-height: var(--pml-app-height, 100dvh);
  padding:
    max(8px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
}

body.pml-game-immersive .topbar {
  position: fixed;
  z-index: 20;
  top: max(6px, env(safe-area-inset-top));
  right: max(6px, env(safe-area-inset-right));
  left: auto;
  display: flex;
  justify-content: flex-end;
  gap: 5px;
  pointer-events: none;
}

body.pml-game-immersive .brand,
body.pml-game-immersive .topbar-actions {
  display: none;
}

body.pml-game-immersive .status-card {
  min-height: 38px;
  max-width: 28vw;
  gap: 5px;
  padding: 5px 8px;
  border-radius: 12px;
  pointer-events: auto;
}

body.pml-game-immersive .status-icon {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  font-size: 13px;
}

body.pml-game-immersive .status-card small {
  font-size: 9px;
}

body.pml-game-immersive .status-card strong {
  font-size: clamp(13px, 2.2vw, 18px);
}

body.pml-game-immersive .stage-shell {
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 6px;
  min-height: 0;
}

body.pml-game-immersive .guide-card {
  display: none;
}

body.pml-game-immersive .stage {
  border-radius: 18px;
}

body.pml-game-immersive .hand-panel {
  gap: 4px;
  padding: 6px 5px;
  border-radius: 12px;
}

body.pml-game-immersive .hand-icon {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  font-size: 13px;
}

body.pml-game-immersive .hand-slider {
  width: 24px;
  min-height: 120px;
}

body.pml-game-immersive .target-label {
  display: none;
}

body.pml-game-immersive .feedback-pill {
  right: max(10px, env(safe-area-inset-right));
  bottom: 56px;
  left: auto;
  min-width: min(330px, 46vw);
  max-width: 46vw;
  padding: 8px 12px;
  border-radius: 14px;
}

body.pml-game-immersive .feedback-pill strong {
  font-size: clamp(15px, 2.4vw, 20px);
}

body.pml-game-immersive .feedback-pill span {
  font-size: clamp(11px, 1.7vw, 14px);
}

body.pml-game-immersive .play-panel {
  right: max(10px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  padding: 6px 10px;
  border-radius: 14px;
}

body.pml-game-immersive .play-panel button {
  width: 34px;
  height: 34px;
}

body.pml-game-immersive .timeline-panel {
  width: 100%;
  grid-template-rows: 30px;
  padding: 4px 8px;
  border-radius: 12px;
}

body.pml-game-immersive .timeline-labels,
body.pml-game-immersive .timeline-caption {
  display: none;
}

body.pml-game-immersive #timelineCanvas {
  height: 30px;
}

body.pml-game-immersive .guide-overlay,
body.pml-game-immersive .result-overlay,
body.pml-game-immersive .calibration-overlay {
  padding:
    max(8px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
}

body.pml-game-immersive .result-card,
body.pml-game-immersive .calibration-card {
  max-height: calc(var(--pml-app-height, 100dvh) - 20px);
  overflow: auto;
}

@media (max-height: 430px) and (orientation: landscape) {
  body.pml-game-immersive .topbar .status-card:nth-of-type(2) {
    display: none;
  }

  body.pml-game-immersive .feedback-pill {
    bottom: 48px;
    max-width: 40vw;
  }

  body.pml-game-immersive .timeline-panel {
    display: none;
  }
}

/* v90: proportional stage scaling during active play */
:root {
  --pml-game-design-width: 1366px;
  --pml-game-design-height: 768px;
}

body.pml-game-proportional {
  width: 100%;
  height: var(--pml-app-height, 100dvh);
  min-height: var(--pml-app-height, 100dvh);
  overflow: hidden;
  background:
    radial-gradient(circle at 82% 20%, rgba(85, 216, 234, 0.22), transparent 28%),
    radial-gradient(circle at 22% 16%, rgba(255, 226, 143, 0.28), transparent 24%),
    linear-gradient(180deg, #eefcf6 0%, #d8f4f2 52%, #eef7df 100%);
}

body.pml-game-proportional .cave-app {
  position: fixed;
  top: 50%;
  left: 50%;
  width: var(--pml-game-design-width);
  height: var(--pml-game-design-height);
  min-height: 0;
  padding: 12px 16px 10px;
  transform: translate(-50%, -50%) scale(var(--pml-game-scale, 1));
  transform-origin: center center;
}
