:root {
  --bg-color: #0c0f14;
  --panel-bg: rgba(24, 28, 38, 0.75);
  --panel-border: rgba(255, 255, 255, 0.12);
  --accent: #00b4ff;
  --accent-glow: rgba(0, 180, 255, 0.35);
  --success: #3dd68c;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-body);
}

.app-container {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: radial-gradient(circle at 50% 20%, #171d2b 0%, #0c0f14 100%);
}

.canvas-wrapper {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

#gameCanvas {
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  aspect-ratio: 16 / 9;
  object-fit: contain;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 1px rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  cursor: grab;
  touch-action: none;
  -webkit-touch-callout: none;
}

#gameCanvas:active {
  cursor: grabbing;
}

#webcam {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.glass-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 18, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.loading-card {
  background: rgba(26, 32, 44, 0.85);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 40px 48px;
  text-align: center;
  max-width: 520px;
  width: 90%;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6), 0 0 30px var(--accent-glow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: popIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popIn {
  0% { transform: scale(0.92); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.spinner {
  width: 52px;
  height: 52px;
  border: 4px solid rgba(0, 180, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  box-shadow: 0 0 15px var(--accent-glow);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loadingTitle {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

#loadingMsg {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.credits-box {
  margin-top: 10px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  font-size: 0.85rem;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.credits-box strong {
  color: var(--accent);
  font-weight: 600;
}

.btn {
  font-family: var(--font-heading);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.3);
}

.top-hud-bar {
  position: absolute;
  top: max(10px, calc((100vh - min(100vh, calc(100vw * 9 / 16))) / 2 + 12px));
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100vw - 20px), calc(min(100vw, calc(100vh * 16 / 9)) - 24px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  z-index: 20;
}

.hud-left, .hud-right, .hud-center {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-center {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 8px 22px;
  border-radius: 30px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.logo-pill {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  padding: 8px 16px;
  border-radius: 30px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
}

.dot-live {
  width: 9px;
  height: 9px;
  background-color: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--accent);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

.stat-val {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.1rem;
  color: #ffffff;
}

.stat-divider {
  width: 1px;
  height: 22px;
  background: rgba(255, 255, 255, 0.12);
  margin: 0 6px;
}

.icon-btn {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  color: #e2e8f0;
  height: 40px;
  padding: 0 14px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-family: var(--font-heading);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--accent);
  color: #fff;
  transform: translateY(-1px);
}

.icon-btn svg {
  flex-shrink: 0;
}

.bottom-hint {
  position: absolute;
  bottom: max(10px, calc((100vh - min(100vh, calc(100vw * 9 / 16))) / 2 + 10px));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 18, 25, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 18px;
  border-radius: 20px;
  color: #94a3b8;
  font-size: 0.8rem;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 960px) {
  .top-hud-bar {
    gap: 8px;
  }
  .hud-center {
    padding: 6px 14px;
    gap: 8px;
  }
  .stat-val {
    font-size: 0.95rem;
  }
  .stat-label {
    font-size: 0.55rem;
  }
  .stat-divider {
    height: 16px;
    margin: 0 2px;
  }
}

@media (max-width: 768px) {
  .logo-pill {
    padding: 6px 12px;
    font-size: 0.85rem;
  }
  .icon-btn {
    height: 36px;
    padding: 0 10px;
  }
  .icon-btn span {
    display: none;
  }
  .loading-card {
    padding: 28px 24px;
    max-width: 92%;
  }
  #loadingTitle {
    font-size: 1.35rem;
  }
}

@media (max-width: 520px) {
  .hud-left {
    gap: 6px;
  }
  .hud-right {
    gap: 6px;
  }
  .hud-center {
    padding: 4px 10px;
  }
  .stat-val {
    font-size: 0.85rem;
  }
  .bottom-hint {
    display: none;
  }
}
