:root {
  color-scheme: dark;
  --bg: #05070b;
  --panel: #141822;
  --panel-glass: rgba(12, 15, 22, 0.62);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #e8ecf4;
  --text-dim: #8a92a6;
  --accent: #00e5ff;
  --accent-soft: rgba(0, 229, 255, 0.35);
  --danger: #ff2d55;
  --radius: 10px;
  --radius-lg: 18px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--panel-border);
  background: #090b10;
  flex: 0 0 auto;
  z-index: 20;
}

.topbar h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
  background: linear-gradient(90deg, #fff, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tag {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
  margin-left: 8px;
  -webkit-text-fill-color: var(--text-dim);
}

.status-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
}

.pill-loading {
  color: #ffd400;
  border-color: #4d4419;
}

.pill-ready {
  color: #4dff88;
  border-color: #1a4d2c;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: border-color 0.15s, transform 0.15s;
}

.icon-btn:hover {
  border-color: var(--accent);
  transform: scale(1.06);
}

/* --- Stage (fullscreen camera + gesture HUD) ---------------------------- */

.stage-shell {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.cam-wrap {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
}

#video,
#overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#video {
  object-fit: cover;
  /* The live feed is only ever a pose-detection / player-cutout source —
     it stays invisible except while picking trampoline corners. */
  opacity: 0;
  transition: opacity 0.2s ease;
}

.calibrating #video {
  opacity: 1;
}

.mirrored #video,
.mirrored #overlay {
  transform: scaleX(-1);
}

.cam-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(5, 7, 11, 0.92);
  z-index: 10;
}

.cam-placeholder p {
  color: var(--text-dim);
  margin: 0;
}

.btn {
  background: #1b2130;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #001318;
  border: none;
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
}

.btn-small {
  padding: 4px 9px;
  font-size: 11px;
}

.hint {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0;
}

.hidden {
  display: none !important;
}

.field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.field select {
  background: #0e121b;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 4px 8px;
  max-width: 220px;
}

.field.checkbox {
  cursor: pointer;
}

/* --- Floating glass HUD panels on top of the video ---------------------- */

.hud-panel {
  position: absolute;
  background: var(--panel-glass);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  padding: 14px 16px;
  z-index: 5;
}

.hud-panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0 0 8px;
}

.hud-topleft {
  top: 16px;
  left: 16px;
  width: 360px;
  max-height: calc(100% - 32px);
  overflow-y: auto;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-header h2 {
  margin: 0;
}

.panel-header-actions {
  display: flex;
  gap: 6px;
}

.photo-background-picker {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--panel-border);
}

.photo-background-picker button {
  flex: 1 1 0;
  padding: 0;
  border: 2px solid var(--panel-border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: none;
  aspect-ratio: 16 / 10;
}

.photo-background-picker button:hover {
  border-color: var(--accent);
}

.photo-background-picker img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-modal {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(720px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  z-index: 25;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.gallery-grid img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
}

.calibration-hint {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-glass);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius);
  padding: 8px 16px;
  backdrop-filter: blur(10px);
  max-width: 90%;
  text-align: center;
  z-index: 6;
}

/* --- Legend / scoreboard -------------------------------------------------- */

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.legend-empty {
  font-size: 15px;
  color: var(--text-dim);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
}

.legend-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
}

.presence-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

.presence-on {
  background: #4dff88;
  box-shadow: 0 0 6px #4dff88;
}

.presence-off {
  background: #3a4152;
}

.legend-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-status {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}

.legend-status.on-mat {
  color: #4dff88;
}

.legend-status.off-mat {
  color: var(--danger);
}

.legend-score {
  min-width: 52px;
  text-align: right;
  font-weight: 800;
  font-size: 32px;
  font-variant-numeric: tabular-nums;
}

@keyframes scoreFlash {
  0% {
    color: #ffffff;
    transform: scale(1.5);
  }
  100% {
    color: inherit;
    transform: scale(1);
  }
}

.score-flash {
  display: inline-block;
  animation: scoreFlash 500ms ease-out;
}

/* --- Pre-game gesture panel: carousel + start ring ----------------------- */

.pre-game-panel {
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: min(1400px, 96%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  padding: 22px 26px;
}

.detected-players-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 22px;
  min-height: 1px;
}

.detected-player-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.detected-player-badge canvas {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  display: block;
}

.detected-player-label {
  font-size: 15px;
  font-weight: 700;
}

.swipe-hint {
  font-size: 20px;
  color: var(--text-dim);
  margin: 0;
  letter-spacing: 0.02em;
}

.game-carousel {
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
}

.carousel-arrow {
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 32px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.carousel-arrow:hover:not(:disabled) {
  border-color: var(--accent);
  transform: scale(1.08);
}

.carousel-arrow:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.game-cards {
  flex: 1 1 auto;
  display: flex;
  gap: 18px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 6px;
  scrollbar-width: none;
}

.game-cards::-webkit-scrollbar {
  display: none;
}

.game-card {
  scroll-snap-align: center;
  flex: 0 0 auto;
  min-width: 220px;
  padding: 18px 26px 22px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.18s ease;
  opacity: 0.6;
  transform: scale(0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.game-card-icon {
  font-size: 56px;
  line-height: 1;
}

.game-card-title {
  font-size: 22px;
  font-weight: 700;
}

.game-card:hover:not(:disabled) {
  opacity: 0.85;
}

.game-card.active {
  color: var(--text);
  opacity: 1;
  transform: scale(1.08);
  border-color: var(--accent);
  background: rgba(0, 229, 255, 0.1);
  box-shadow: 0 0 32px rgba(0, 229, 255, 0.3);
}

.game-card:disabled {
  cursor: not-allowed;
}

.game-description {
  min-height: 22px;
  max-width: 800px;
  font-size: 18px;
}

.start-gesture {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.start-ring {
  --progress: 0;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--progress) * 1%), rgba(255, 255, 255, 0.12) 0);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 60ms linear;
}

.start-ring.active {
  animation: ringPulse 1s ease-in-out infinite;
}

@keyframes ringPulse {
  0%, 100% {
    box-shadow: 0 0 0 rgba(0, 229, 255, 0.5);
  }
  50% {
    box-shadow: 0 0 36px rgba(0, 229, 255, 0.65);
  }
}

.start-ring-inner {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  background: #05070b;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 700;
  color: var(--accent);
}

.start-gesture .hint {
  font-size: 18px;
}

/* --- During-game HUD ------------------------------------------------------ */

.during-game-panel {
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.game-hud {
  font-weight: 600;
  color: var(--accent);
  min-height: 16px;
  font-size: 26px;
}

/* --- Swipe direction indicators ------------------------------------------ */

.swipe-indicator {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 110px;
  color: var(--accent);
  text-shadow: 0 0 32px var(--accent-soft);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

.swipe-indicator-left {
  left: 24px;
}

.swipe-indicator-right {
  right: 24px;
}

.swipe-indicator.flash {
  animation: swipeFlash 450ms ease-out;
}

@keyframes swipeFlash {
  0% {
    opacity: 0;
    transform: translateY(-50%) scale(0.7);
  }
  30% {
    opacity: 1;
    transform: translateY(-50%) scale(1.15);
  }
  100% {
    opacity: 0;
    transform: translateY(-50%) scale(1);
  }
}

/* --- Results modal --------------------------------------------------------- */

.game-results {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 260px;
  text-align: center;
  z-index: 15;
}

.game-results h3 {
  font-size: 15px;
  margin: 0 0 10px;
}

.game-results ol {
  list-style: decimal;
  margin: 0 0 12px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  text-align: left;
}

.game-results li {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Settings drawer -------------------------------------------------------- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 29;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.drawer-backdrop:not(.hidden) {
  opacity: 1;
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(340px, 90vw);
  background: #0b0d13;
  border-left: 1px solid var(--panel-border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 30;
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.4);
}

.settings-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h2 {
  font-size: 15px;
  margin: 0;
}

.drawer-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0 0 2px;
}

.panel-muted p {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0;
}

.game-settings {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-block {
  flex-direction: column;
  align-items: flex-start !important;
  gap: 4px;
}

.field input[type="number"] {
  background: #0e121b;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 4px 8px;
  width: 100px;
}

.game-controls {
  display: flex;
  gap: 8px;
}

#minimap {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #0e121b;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  display: block;
}

@media (max-width: 700px) {
  .hud-topleft {
    width: 190px;
    padding: 10px 12px;
  }
  .game-card {
    min-width: 120px;
    padding: 10px 12px;
  }
  .swipe-indicator {
    font-size: 44px;
  }
}
