/* ========================================
   KEMIX DEMO — Neumorphic Video Call UI
   ======================================== */

/* ─── Design Tokens ─────────────────────────────────── */
:root {
  --color-bg: #E4E2E0;
  --color-bg-secondary: #E4E2E0;
  --color-bg-tertiary: #D6D4D2;
  --color-text: #1D1D1F;
  --color-text-secondary: #6B7280;
  --color-text-tertiary: #9CA3AF;
  --color-accent: #E50914;
  --color-green: #34C759;
  --color-red: #E50914;

  /* Neumorphic shadows */
  --nm-shadow-dark: rgba(175, 172, 168, 0.5);
  --nm-shadow-light: rgba(255, 255, 254, 0.6);
  --nm-raised: 6px 6px 12px var(--nm-shadow-dark), -6px -6px 12px var(--nm-shadow-light);
  --nm-raised-sm: 3px 3px 6px var(--nm-shadow-dark), -3px -3px 6px var(--nm-shadow-light);
  --nm-raised-lg: 10px 10px 20px var(--nm-shadow-dark), -10px -10px 20px var(--nm-shadow-light);
  --nm-pressed: inset 3px 3px 6px var(--nm-shadow-dark), inset -3px -3px 6px var(--nm-shadow-light);
  --nm-pressed-sm: inset 2px 2px 4px var(--nm-shadow-dark), inset -2px -2px 4px var(--nm-shadow-light);

  /* Blue-lavender glow ring under buttons */
  --nm-glow: 0 4px 14px 3px rgba(160, 178, 253, 0.3), 0 10px 32px rgba(160, 178, 253, 0.15);
  --nm-glow-sm: 0 3px 10px 2px rgba(160, 178, 253, 0.25), 0 8px 24px rgba(160, 178, 253, 0.12);

  --font-sans: 'Google Sans Flex', -apple-system, BlinkMacSystemFont, 'SF Pro Display', system-ui, sans-serif;

  --max-w-app: 448px;
  --radius-full: 9999px;
  --radius-2xl: 16px;
  --radius-3xl: 24px;
  --radius-xl: 12px;
}

/* ─── Reset ─────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Utility ───────────────────────────────────────── */
.hidden { display: none !important; }

.glass {
  background: var(--color-bg);
  border: none;
  box-shadow: var(--nm-raised);
}

/* ─── App Shell ─────────────────────────────────────── */
#kemix-app {
  position: relative;
  width: 100%;
  max-width: var(--max-w-app);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--color-bg);
}

/* ─── View ──────────────────────────────────────────── */
.view {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
  flex-direction: column;
}

.view.active {
  display: flex;
}

/* ========================================
   VIDEO CALL (3D AVATAR)
   ======================================== */

#view-video {
  position: absolute;
  inset: 0;
}

.video-canvas-container {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.video-canvas-container canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Gradient overlay */
.video-gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom,
    rgba(0, 0, 0, 0.35) 0%,
    transparent 25%,
    transparent 65%,
    rgba(0, 0, 0, 0.50) 100%);
  pointer-events: none;
  z-index: 1;
}

/* Loading / blur overlay */
.video-loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(228, 226, 224, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: backdrop-filter 0.6s ease, -webkit-backdrop-filter 0.6s ease, background 0.6s ease, opacity 0.6s ease;
}

.video-loading .spinner {
  display: flex;
  align-items: center;
  gap: 12px;
}

.video-loading .spinner .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-bg);
  box-shadow: var(--nm-raised-sm);
  animation: dot-pulse 1.4s ease-in-out infinite;
}

.video-loading .spinner .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.video-loading .spinner .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dot-pulse {
  0%, 80%, 100% {
    transform: scale(1);
    box-shadow: var(--nm-raised-sm);
  }
  40% {
    transform: scale(1.4);
    box-shadow: var(--nm-pressed-sm);
  }
}

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

.video-loading .loading-label {
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
}

.video-loading.fade-out {
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  background: rgba(228, 226, 224, 0);
  opacity: 0;
  pointer-events: none;
}

/* Idle state — hide spinner/label, show controls */
.video-loading.idle .spinner {
  display: none;
}

.video-loading.idle .loading-label {
  display: none;
}

/* Calling state (spin) */
.video-loading.calling .spinner {
  animation: spin 1s linear infinite;
}

/* Top info overlay */
.video-top-info {
  position: absolute;
  top: 48px;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 10;
  pointer-events: none;
}

.video-name {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 1.125rem;
  color: var(--color-text);
}

.video-timer {
  font-family: monospace;
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

/* Bottom controls */
.video-bottom {
  position: absolute;
  bottom: 48px;
  left: 24px;
  right: 24px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}

.video-controls {
  display: flex;
  align-items: center;
  gap: 28px;
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
}

.video-bottom.pip-active .video-controls {
  transform: translateX(-56px);
}

.video-ctrl-btn {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.15s;
  color: var(--color-text-secondary);
  border: none;
  background: var(--color-bg);
  box-shadow: var(--nm-raised), var(--nm-glow);
}

.video-ctrl-btn:hover {
  color: var(--color-text);
  transform: scale(1.08);
  box-shadow: 8px 8px 16px var(--nm-shadow-dark), -8px -8px 16px var(--nm-shadow-light), 0 5px 16px 4px rgba(160, 178, 253, 0.35), 0 12px 36px rgba(160, 178, 253, 0.2);
}

.video-ctrl-btn:active {
  transform: scale(0.98);
  box-shadow: var(--nm-pressed);
}

.video-ctrl-btn.muted {
  box-shadow: var(--nm-pressed);
}

.video-ctrl-btn.muted:hover {
  transform: scale(1.08);
  box-shadow: var(--nm-pressed);
}

.video-ctrl-btn.muted svg {
  color: var(--color-red);
}

.video-ctrl-btn.muted::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 55%;
  height: 2px;
  background: var(--color-red);
  border-radius: 1px;
  transform: translate(-50%, -50%) rotate(-45deg);
  pointer-events: none;
}

.video-ctrl-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.32, 0.72, 0, 1), color 0.25s ease;
}

.video-ctrl-btn.transitioning {
  pointer-events: none;
}

.video-ctrl-btn.transitioning svg {
  opacity: 0.3;
  transform: scale(0.8);
}

.video-ctrl-btn.transitioning::before {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  border-top-color: var(--color-text);
  animation: btn-spin 0.6s linear infinite;
  z-index: 2;
}

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

/* End call button */
.end-call-btn {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-full);
  background: var(--color-bg);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.15s;
  box-shadow: var(--nm-raised), var(--nm-glow);
  color: var(--color-red);
}

.end-call-btn:hover {
  transform: scale(1.05);
  box-shadow: 8px 8px 16px var(--nm-shadow-dark), -8px -8px 16px var(--nm-shadow-light), 0 5px 16px 4px rgba(160, 178, 253, 0.35), 0 12px 36px rgba(160, 178, 253, 0.2);
}

.end-call-btn:active {
  transform: scale(0.98);
  box-shadow: var(--nm-pressed);
}

.end-call-btn svg {
  width: 28px;
  height: 28px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.end-call-btn.transitioning {
  pointer-events: none;
}

.end-call-btn.transitioning svg {
  opacity: 0.3;
  transform: scale(0.8);
}

.end-call-btn.transitioning::before {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  border-top-color: var(--color-red);
  animation: btn-spin 0.6s linear infinite;
  z-index: 2;
}

.end-call-btn.small {
  width: 64px;
  height: 64px;
}

.end-call-btn.small svg {
  width: 28px;
  height: 28px;
}

/* Idle state — end-call-btn becomes green "start call" button */
.end-call-btn.idle-mode {
  color: #fff;
  background: var(--color-green);
  box-shadow: var(--nm-raised), 0 4px 14px 3px rgba(52, 199, 89, 0.3), 0 10px 32px rgba(52, 199, 89, 0.15);
}
.end-call-btn.idle-mode:hover {
  transform: scale(1.08);
  box-shadow: 8px 8px 16px var(--nm-shadow-dark), -8px -8px 16px var(--nm-shadow-light), 0 5px 16px 4px rgba(52, 199, 89, 0.4), 0 12px 36px rgba(52, 199, 89, 0.2);
}

/* Idle state — hide mic/cam buttons */
.video-ctrl-btn.idle-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

/* User camera PIP */
.user-camera-pip {
  width: 96px;
  height: 128px;
  border-radius: var(--radius-xl);
  overflow: hidden;
  border: none;
  opacity: 0;
  transform: scale(0) translateX(40px);
  transform-origin: right center;
  will-change: transform, opacity;
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1),
              opacity 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  pointer-events: none;
  box-shadow: var(--nm-raised);
  position: absolute;
  right: 0;
  bottom: 0;
}

.video-bottom.pip-active .user-camera-pip {
  opacity: 1;
  transform: scale(1) translateX(0);
  pointer-events: auto;
}

.user-camera-pip video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.3s ease 0.15s;
}

.video-bottom.pip-active .user-camera-pip video {
  opacity: 1;
}

.user-camera-pip .pip-placeholder {
  display: none;
}

/* PIP flip camera button */
.pip-flip-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  transition: transform 0.2s, background 0.2s;
}

.pip-flip-btn svg {
  width: 16px;
  height: 16px;
  stroke: white;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pip-flip-btn:active {
  transform: scale(0.9);
  background: rgba(0, 0, 0, 0.65);
}

.pip-flip-btn.transitioning {
  pointer-events: none;
  opacity: 0.5;
}

/* ========================================
   LOGIN MODAL
   ======================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  width: 360px;
  max-width: calc(100% - 40px);
  padding: 32px;
  border-radius: var(--radius-2xl);
  animation: modal-pop 0.25s ease;
  background: var(--color-bg);
  border: none;
  box-shadow: var(--nm-raised-lg);
}

@keyframes modal-pop {
  from { opacity: 0; transform: translateY(-16px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-title {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 1.5rem;
  text-align: center;
  margin-bottom: 24px;
  color: var(--color-text);
}

.modal-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.modal-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--color-bg);
  border: none;
  border-radius: var(--radius-xl);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  outline: none;
  transition: box-shadow 0.2s;
  margin-bottom: 16px;
  box-shadow: var(--nm-pressed);
}

.modal-input::placeholder {
  color: var(--color-text-tertiary);
}

.modal-input:focus {
  box-shadow: inset 4px 4px 8px var(--nm-shadow-dark), inset -4px -4px 8px var(--nm-shadow-light);
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.modal-btn {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-xl);
  border: none;
  background: var(--color-bg);
  box-shadow: var(--nm-raised-sm);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: box-shadow 0.2s;
}

.modal-btn:hover {
  box-shadow: var(--nm-raised);
}

.modal-btn:active {
  box-shadow: var(--nm-pressed-sm);
}

.modal-btn.primary {
  background: var(--color-accent);
  color: #FFFFFF;
  box-shadow: 4px 4px 8px rgba(163, 177, 198, 0.5), -2px -2px 4px var(--nm-shadow-light);
}

.modal-btn.primary:hover {
  background: #E0342B;
  box-shadow: 6px 6px 12px rgba(163, 177, 198, 0.5), -3px -3px 6px var(--nm-shadow-light);
}

.modal-btn.primary:active {
  box-shadow: inset 3px 3px 6px rgba(200, 30, 20, 0.3), inset -3px -3px 6px rgba(255, 100, 90, 0.2);
}

/* ========================================
   BUTTON WAITING STATE (signaling)
   ======================================== */

.end-call-btn.waiting,
.video-ctrl-btn.waiting {
  pointer-events: none;
  box-shadow: var(--nm-pressed);
  opacity: 0.4;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (min-width: 449px) {
  #kemix-app {
    box-shadow: var(--nm-raised-lg);
  }
}
