:root {
  --bg: #06080d;
  --glass: rgba(10, 14, 24, 0.62);
  --glass-border: rgba(255, 255, 255, 0.16);
  --glass-hover: rgba(255, 255, 255, 0.14);
  --text: #f4f7ff;
  --muted: rgba(232, 239, 255, 0.72);
  --cyan: #66f7ff;
  --green: #6bff8e;
  --red: #ff3b5c;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #11182b 0%, var(--bg) 75%);
}

/* Keep video element rendered (tiny & nearly transparent) so iOS Safari decodes frames */
#camera {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0.001;
  pointer-events: none;
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* Floating HUD */
.hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: calc(env(safe-area-inset-left, 0px) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 10px);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}

.hud-left,
.hud-right {
  pointer-events: auto;
}

.glass-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
  box-shadow: 0 0 8px rgba(100, 116, 139, 0.6);
  transition: background 180ms ease, box-shadow 180ms ease;
}

.dot.active {
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
}

.dot.busy {
  background: #ffe866;
  box-shadow: 0 0 10px #ffe866;
}

.sep {
  opacity: 0.4;
}

#mode-summary {
  color: var(--muted);
  font-weight: 500;
}

.hud-right {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: min(68vw, 620px);
}

.glass-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 36px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 100ms ease, background 150ms ease, border-color 150ms ease;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

.glass-btn:active {
  transform: scale(0.94);
}

.glass-btn.active {
  border-color: rgba(102, 247, 255, 0.65);
  background: rgba(102, 247, 255, 0.16);
}

.btn-icon {
  font-size: 14px;
  line-height: 1;
}

.rec-btn .rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 8px rgba(255, 59, 92, 0.75);
}

.rec-btn.recording {
  border-color: rgba(255, 59, 92, 0.9);
  background: rgba(255, 59, 92, 0.28);
  animation: recPulse 1.1s ease-in-out infinite;
}

@keyframes recPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 59, 92, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(255, 59, 92, 0); }
}

/* Progress Bar (Start card + Live stage loader pill) */
.progress-card {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(102, 247, 255, 0.22);
  text-align: left;
  transition: border-color 200ms ease, background 200ms ease;
}

.progress-card.ready {
  background: rgba(107, 255, 142, 0.10);
  border-color: rgba(107, 255, 142, 0.45);
}

.progress-card.error {
  background: rgba(255, 59, 92, 0.10);
  border-color: rgba(255, 59, 92, 0.45);
}

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 12px;
  line-height: 1.25;
}

.progress-stage {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-meta {
  flex: none;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--cyan);
}

.progress-card.ready .progress-meta {
  color: var(--green);
}

.progress-track {
  position: relative;
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.10);
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--green));
  box-shadow: 0 0 12px rgba(102, 247, 255, 0.55);
  transition: width 140ms linear;
}

.progress-fill.compiling {
  background: linear-gradient(90deg, var(--cyan), #ffffff, var(--green), var(--cyan));
  background-size: 200% 100%;
  animation: progressShimmer 1.1s linear infinite;
}

@keyframes progressShimmer {
  0% { background-position: 100% 0%; }
  100% { background-position: -100% 0%; }
}

.ai-loader-pill {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 60px);
  left: 50%;
  transform: translateX(-50%);
  width: min(340px, calc(100vw - 24px));
  padding: 11px 14px;
  border-radius: 16px;
  background: rgba(10, 14, 24, 0.78);
  border: 1px solid rgba(102, 247, 255, 0.35);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  z-index: 15;
}

.retry-ai-btn {
  margin-top: 9px;
  width: 100%;
  height: 32px;
  border: 1px solid rgba(255, 59, 92, 0.55);
  border-radius: 10px;
  background: rgba(255, 59, 92, 0.18);
  color: #ffd6de;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

/* Bottom Hint */
.hint-banner {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-radius: 16px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
  z-index: 10;
  transition: opacity 350ms ease;
}

.hint-banner p {
  margin: 0;
}

.hint-banner strong {
  color: var(--text);
}

.hint-close {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

/* Toast */
.toast {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 64px);
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(12, 18, 32, 0.88);
  border: 1px solid rgba(102, 247, 255, 0.45);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  z-index: 20;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* Start Overlay */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  background: radial-gradient(circle at 50% 35%, rgba(20, 32, 58, 0.88), rgba(6, 8, 13, 0.96));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 30;
  overflow-y: auto;
}

.start-card {
  width: 100%;
  max-width: 440px;
  padding: 26px 22px;
  border-radius: 24px;
  background: rgba(15, 20, 34, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  text-align: center;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--cyan);
  background: rgba(102, 247, 255, 0.12);
  border: 1px solid rgba(102, 247, 255, 0.3);
}

.start-card h1 {
  margin: 12px 0 6px;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(120deg, #ffffff 15%, var(--cyan) 60%, var(--green) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
}

.gesture-guide {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.gesture-guide li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 13px;
  line-height: 1.35;
  color: var(--muted);
}

.g-pill {
  flex: none;
  min-width: 74px;
  padding: 5px 8px;
  border-radius: 9px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  background: rgba(102, 247, 255, 0.14);
  border: 1px solid rgba(102, 247, 255, 0.28);
}

.start-btn {
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 16px;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  color: #041019;
  background: linear-gradient(135deg, var(--cyan), var(--green));
  box-shadow: 0 10px 28px rgba(102, 247, 255, 0.32);
  cursor: pointer;
  transition: transform 120ms ease, opacity 150ms ease;
}

.start-btn:active {
  transform: scale(0.98);
}

.start-btn:disabled {
  opacity: 0.72;
  cursor: wait;
}

.start-note {
  margin: 12px 0 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: rgba(232, 239, 255, 0.56);
}

.error-box {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 59, 92, 0.14);
  border: 1px solid rgba(255, 59, 92, 0.45);
  color: #ffd6de;
  font-size: 12.5px;
  line-height: 1.4;
}

/* Portrait compactness on small phones */
@media (max-width: 640px) {
  .hud {
    flex-direction: column;
    align-items: stretch;
  }

  .hud-left {
    display: flex;
    justify-content: flex-start;
  }

  .hud-right {
    max-width: 100%;
    justify-content: flex-start;
  }

  .glass-btn {
    height: 33px;
    padding: 0 9px;
    font-size: 11px;
  }

  #mode-summary,
  .sep {
    display: none;
  }

  .ai-loader-pill {
    top: calc(env(safe-area-inset-top, 0px) + 132px);
  }
}

/* Short landscape height */
@media (max-height: 460px) and (orientation: landscape) {
  .start-card {
    padding: 14px 16px;
    max-width: 520px;
  }

  .start-card h1 {
    font-size: 22px;
    margin: 4px 0 3px;
  }

  .subtitle {
    margin-bottom: 8px;
    font-size: 12.5px;
  }

  .gesture-guide {
    gap: 5px;
    margin-bottom: 10px;
  }

  .gesture-guide li {
    padding: 5px 10px;
    font-size: 11.5px;
  }

  .progress-card {
    margin-bottom: 10px;
    padding: 7px 10px;
  }

  .progress-head {
    margin-bottom: 5px;
    font-size: 11.5px;
  }

  .start-btn {
    height: 42px;
  }
}
