:root {
  --bg-primary: #05080f;
  --bg-secondary: #091426;
  --accent: #4fc3f7;
  --text-primary: #f1f5ff;
  --text-secondary: #8ea1c7;
  --warning: #fbc02d;
  --focus-outline: 3px solid rgba(79, 195, 247, 0.65);
  --progress-height: 8px;
  --progress-bg: rgba(255, 255, 255, 0.2);
  --progress-fill: linear-gradient(90deg, var(--accent), #7ed957);
  --font-family: "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at top, #0e1b33 0%, var(--bg-primary) 60%, #03060c 100%);
  color: var(--text-primary);
  font-family: var(--font-family);
  letter-spacing: 0.02em;
  overflow: hidden;
}

#roi-canvas {
  position: absolute;
  width: 0;
  height: 0;
  top: -9999px;
  left: -9999px;
  pointer-events: none;
  visibility: hidden;
}

#gaze-cursor {
  width: clamp(18px, 2.1vmin, 26px);
  height: clamp(18px, 2.1vmin, 26px);
  border-radius: 50%;
  box-shadow: 0 0 18px rgba(255, 79, 79, 0.4);
  border: 2px solid rgba(255, 79, 79, 0.8);
  background: radial-gradient(circle, rgba(255, 0, 0, 0.75) 0%, rgba(255, 0, 0, 0.2) 65%, transparent 100%);
  transition: opacity 0.18s ease, transform 0.12s ease;
  opacity: 0.8;
  display: block;
}

#gaze-cursor[data-active='false'] {
  opacity: 0;
}

#gaze-cursor[data-active='true'] {
  opacity: 1;
}

#gaze-cursor[data-quality='low'] {
  border-color: rgba(251, 192, 45, 0.75);
  box-shadow: 0 0 12px rgba(251, 192, 45, 0.35);
  background: radial-gradient(circle, rgba(251, 192, 45, 0.6) 0%, rgba(251, 192, 45, 0.18) 65%, transparent 100%);
}

#animated-eye-container {
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.28s ease;
}

#animated-eye-container[data-visible='true'] {
  display: block !important;
  opacity: 1;
}

#animated-eye-container svg {
  filter: drop-shadow(0 16px 24px rgba(5, 10, 20, 0.45));
}

#animated-eye-container[data-blink='closed'] #upper-eyelid {
  transform-origin: 131px 90px;
  transform: translateY(45px);
}

#animated-eye-container[data-blink='closed'] #lower-eyelid {
  transform-origin: 131px 150px;
  transform: translateY(-45px);
}

#animated-eye-container #upper-eyelid,
#animated-eye-container #lower-eyelid {
  transition: transform 0.12s ease-in-out;
}

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

.noscript {
  padding: 1rem 1.5rem;
  margin: 1rem;
  border-radius: 0.75rem;
  background: #ef5350;
  color: #030305;
  font-weight: 600;
  text-align: center;
}


.stage {
  position: relative;
  flex: 1;
  display: block;
  width: 100%;
  min-height: 0;
}

#pizza-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  filter: none;
}

#heatmap-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: 0.85;
  z-index: 6;
}

.stage-center {
  position: absolute;
  top: 50%;
  left: 50%;
  width: clamp(180px, 16vmin, 220px);
  height: clamp(180px, 16vmin, 220px);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(6, 14, 26, 0.65) 0%, rgba(1, 4, 9, 0.85) 80%);
  border: 2px solid rgba(79, 195, 247, 0.28);
  box-shadow: 0 18px 45px rgba(5, 12, 24, 0.5);
  display: grid;
  place-items: center;
  overflow: hidden;
  pointer-events: none;
  z-index: 10;
}

.stage-center::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  border: 1px solid rgba(79, 195, 247, 0.18);
  pointer-events: none;
  z-index: 11;
}

#webcam {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  filter: saturate(110%);
  pointer-events: none;
  background: #000;
}

.control-button {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: clamp(120px, 18vmin, 200px);
  height: clamp(120px, 18vmin, 200px);
  border-radius: 50%;
  border: 2px solid rgba(79, 195, 247, 0.45);
  background: radial-gradient(circle, rgba(6, 20, 40, 0.9) 0%, rgba(6, 14, 26, 0.75) 65%, rgba(3, 6, 12, 0.65) 100%);
  color: var(--text-primary);
  font-size: clamp(2rem, 5vmin, 3rem);
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  gap: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  z-index: 5;
}

.control-button .control-label {
  font-size: clamp(0.75rem, 1.8vmin, 1rem);
}

.control-button .control-progress {
  position: absolute;
  inset: auto 18% 18% 18%;
  height: var(--progress-height);
  border-radius: var(--progress-height);
  background: var(--progress-bg);
  overflow: hidden;
  transform-origin: left center;
}

.control-button .control-progress::after {
  content: "";
  position: absolute;
  inset: 0;
  width: calc(var(--progress, 0) * 100%);
  background: var(--progress-fill);
  border-radius: inherit;
  transition: width 0.12s ease;
}

.control-button.is-busy {
  pointer-events: none;
  opacity: 0.65;
}

.control-button:is(:focus-visible, .is-focus) {
  outline: var(--focus-outline);
  outline-offset: 6px;
  border-color: rgba(79, 195, 247, 0.95);
  background: radial-gradient(circle, rgba(79, 195, 247, 0.2) 0%, rgba(6, 14, 26, 0.8) 65%, rgba(3, 6, 12, 0.7) 100%);
}

.control-button.is-awaiting {
  border-color: var(--warning);
  background: radial-gradient(circle, rgba(251, 192, 45, 0.25) 0%, rgba(6, 14, 26, 0.85) 70%);
}

.control-button:active {
  transform: translate(-50%, -50%) scale(0.97);
}

#gaze-dot {
  position: absolute;
  width: clamp(16px, 1.8vmin, 22px);
  height: clamp(16px, 1.8vmin, 22px);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  --gaze-border: rgba(79, 195, 247, 0.8);
  --gaze-fill: radial-gradient(circle, rgba(79, 195, 247, 0.85) 0%, rgba(79, 195, 247, 0.2) 65%, transparent 100%);
  border: 2px solid var(--gaze-border);
  background: var(--gaze-fill);
  box-shadow: 0 0 16px rgba(79, 195, 247, 0.35);
  transition: opacity 0.15s ease, transform 0.14s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

#gaze-dot::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(79, 195, 247, 0.25);
  opacity: 0;
  transform: scale(0.35);
}

#gaze-dot[data-state='idle'],
#gaze-dot[data-state='tracking'] {
  --gaze-border: rgba(79, 195, 247, 0.8);
  --gaze-fill: radial-gradient(circle, rgba(79, 195, 247, 0.9) 0%, rgba(79, 195, 247, 0.25) 60%, transparent 100%);
}

#gaze-dot[data-state='control'] {
  --gaze-border: rgba(79, 247, 142, 0.85);
  --gaze-fill: radial-gradient(circle, rgba(79, 247, 142, 0.9) 0%, rgba(79, 247, 142, 0.22) 60%, transparent 100%);
  transform: translate(-50%, -50%) scale(1.08);
  box-shadow: 0 0 20px rgba(79, 247, 142, 0.45);
}

#gaze-dot[data-state='confirm'] {
  --gaze-border: rgba(251, 192, 45, 0.95);
  --gaze-fill: radial-gradient(circle, rgba(251, 192, 45, 0.95) 0%, rgba(251, 192, 45, 0.28) 65%, transparent 100%);
  transform: translate(-50%, -50%) scale(1.15);
  box-shadow: 0 0 24px rgba(251, 192, 45, 0.45);
}

#gaze-dot[data-state='lost'] {
  --gaze-border: rgba(142, 161, 199, 0.6);
  --gaze-fill: radial-gradient(circle, rgba(142, 161, 199, 0.6) 0%, rgba(142, 161, 199, 0.18) 60%, transparent 100%);
  box-shadow: 0 0 12px rgba(142, 161, 199, 0.3);
}

#gaze-dot[data-state='low'] {
  --gaze-border: rgba(251, 192, 45, 0.65);
  --gaze-fill: radial-gradient(circle, rgba(251, 192, 45, 0.6) 0%, rgba(251, 192, 45, 0.18) 60%, transparent 100%);
  opacity: 0.75;
  box-shadow: 0 0 14px rgba(251, 192, 45, 0.25);
}

#gazeCursor[data-quality='low'] {
  border-color: rgba(251, 192, 45, 0.6);
  background: radial-gradient(circle, rgba(251, 192, 45, 0.4) 0%, rgba(251, 192, 45, 0.12) 60%, transparent 100%);
  box-shadow: 0 0 12px rgba(251, 192, 45, 0.22);
}

#gaze-dot[data-flash='true']::after {
  opacity: 0.55;
  animation: gaze-ripple 360ms ease-out;
}

@keyframes gaze-ripple {
  0% {
    opacity: 0.55;
    transform: scale(0.35);
  }
  100% {
    opacity: 0;
    transform: scale(1.75);
  }
}

.status-bar {
  margin: 0;
  padding: 0.75rem clamp(1.5rem, 4vw, 3rem);
  background: rgba(5, 10, 20, 0.8);
  border-top: 1px solid rgba(79, 195, 247, 0.2);
  font-size: clamp(0.9rem, 2vw, 1.05rem);
  letter-spacing: 0.04em;
  min-height: 3.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

#status-text {
  flex: 1 1 auto;
  min-width: 240px;
}

.calibration-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5, 8, 15, 0.45);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 6;
  pointer-events: auto;
}

.passive-bootstrap-overlay {
  position: absolute;
  inset: 0;
  display: block;
  pointer-events: none;
  z-index: 7;
  font-family: var(--font-family);
}

.passive-bootstrap-instruction {
  position: absolute;
  top: clamp(1.5rem, 6vh, 3rem);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.75rem 1.75rem;
  border-radius: 999px;
  background: rgba(5, 14, 26, 0.78);
  border: 1px solid rgba(79, 195, 247, 0.35);
  box-shadow: 0 16px 32px rgba(5, 10, 20, 0.45);
  font-size: clamp(0.95rem, 2.3vw, 1.1rem);
  letter-spacing: 0.05em;
  pointer-events: auto;
  text-align: center;
}

.passive-bootstrap-dots {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.passive-bootstrap-dot {
  position: absolute;
  width: clamp(28px, 4vw, 44px);
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, var(--dot-color, #4fc3f7) 0%, rgba(255, 255, 255, 0.12) 85%, transparent 100%);
  border: 2px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 0 18px rgba(79, 195, 247, 0.32);
  pointer-events: none;
  opacity: 0.92;
  transition: transform 0.3s ease, opacity 0.3s ease, box-shadow 0.3s ease;
}

.passive-bootstrap-dot::after {
  content: '';
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
  opacity: 0.6;
}

.passive-bootstrap-dot[data-state='visited'] {
  opacity: 0.25;
  transform: translate(-50%, -50%) scale(0.82);
  box-shadow: 0 0 12px rgba(110, 230, 150, 0.3);
  border-color: rgba(110, 230, 150, 0.6);
}

.calibration-overlay::after {
  content: "";
  position: absolute;
  inset: 10% 8%;
  border: 2px dashed rgba(79, 195, 247, 0.35);
  border-radius: 1rem;
  pointer-events: none;
}

.calibration-instruction {
  margin: 0;
  font-size: clamp(0.95rem, 2.2vw, 1.1rem);
  padding: 0.5rem 1.25rem;
  border-radius: 999px;
  background: rgba(5, 12, 24, 0.75);
  box-shadow: 0 0 18px rgba(79, 195, 247, 0.25);
}


.calibration-target {
  position: absolute;
  width: clamp(36px, 5.2vw, 68px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid rgba(79, 195, 247, 0.9);
  background: radial-gradient(circle, rgba(79, 195, 247, 0.9) 0%, rgba(79, 195, 247, 0.18) 65%, transparent 100%);
  transform: translate(-50%, -50%);
  transition: transform 0.2s ease, opacity 0.18s ease, border-color 0.22s ease, background 0.22s ease, box-shadow 0.22s ease;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: clamp(1.4rem, 2.6vw, 2rem);
  font-weight: 600;
  color: rgba(5, 12, 24, 0.85);
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.65);
}

.calibration-target:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.7);
  outline-offset: 6px;
}


.calibration-overlay[data-state='active'] .calibration-target {
  box-shadow: 0 0 22px rgba(79, 195, 247, 0.35);
}

.calibration-overlay[data-state='collecting'] .calibration-target {
  border-color: rgba(251, 192, 45, 0.95);
  background: radial-gradient(circle, rgba(251, 192, 45, 0.95) 0%, rgba(251, 192, 45, 0.2) 65%, transparent 100%);
  box-shadow: 0 0 24px rgba(251, 192, 45, 0.45);
  transform: translate(-50%, -50%) scale(0.94);
  animation: calibration-pulse 1.05s ease-in-out infinite;
}

.calibration-overlay[data-state='cooldown'] .calibration-target {
  border-color: rgba(110, 230, 150, 0.95);
  background: radial-gradient(circle, rgba(110, 230, 150, 0.95) 0%, rgba(110, 230, 150, 0.25) 65%, transparent 100%);
  box-shadow: 0 0 24px rgba(110, 230, 150, 0.4);
  transform: translate(-50%, -50%) scale(0.9);
  opacity: 1;
}

@keyframes calibration-pulse {
  0%,
  100% {
    box-shadow: 0 0 22px rgba(251, 192, 45, 0.35), 0 0 0 0 rgba(251, 192, 45, 0.15);
  }
  50% {
    box-shadow: 0 0 22px rgba(251, 192, 45, 0.35), 0 0 0 14px rgba(251, 192, 45, 0);
  }
}

.calibration-overlay[data-state='collecting'] .calibration-target {
  cursor: wait;
  transform: translate(-50%, -50%) scale(0.9);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-primary: #e9edf8;
    --bg-secondary: #dce3f3;
    --text-primary: #081020;
    --text-secondary: #40506c;
  }

  body {
    background: radial-gradient(circle at top, #f4f7ff 0%, #e0e9fb 65%, #d0dcf1 100%);
    color: var(--text-primary);
  }

  .status-bar {
    background: rgba(235, 241, 255, 0.85);
    color: var(--text-primary);
  }

  .control-button {
    border-color: rgba(36, 73, 109, 0.25);
    background: radial-gradient(circle, rgba(235, 241, 255, 0.9) 0%, rgba(211, 223, 247, 0.9) 85%);
    color: #0f1b32;
  }
}
