/* ==========================================================================
   AirCanvas — styles.css
   Dark-theme, glass-morphism UI with a cinematic / terminal aesthetic.
   Fonts: Syne (display) + JetBrains Mono (monospace labels)
   Copyright © Nayebul Jannath Chowdhury
   ========================================================================== */

/* ── CSS Custom Properties ────────────────────────────────────────────────── */
:root {
  /* Core palette */
  --bg:          #0c0c0f;
  --surface:     #13131a;
  --surface-2:   #1c1c28;
  --border:      rgba(255, 255, 255, 0.07);
  --border-2:    rgba(255, 255, 255, 0.13);

  /* Accent — warm amber/gold */
  --accent:      #ffd166;
  --accent-dim:  rgba(255, 209, 102, 0.18);
  --accent-glow: rgba(255, 209, 102, 0.35);

  /* Text */
  --text-hi:     #f0ede8;
  --text-mid:    #9896a0;
  --text-lo:     #55535e;

  /* Mode colours */
  --mode-draw:   #4DFF91;
  --mode-erase:  #FF4D4D;
  --mode-idle:   #9896a0;
  --mode-clear:  #FFE24D;
  --mode-save:   #4DA6FF;

  /* Sizing */
  --ctrl-h:      68px;
  --header-h:    52px;
  --radius-sm:   6px;
  --radius-md:   12px;
  --radius-lg:   20px;
  --radius-pill: 999px;

  /* Glass morphism */
  --glass-bg:    rgba(19, 19, 26, 0.72);
  --glass-blur:  16px;

  /* Transitions */
  --t-fast: 0.15s ease;
  --t-med:  0.25s ease;
  --t-slow: 0.4s cubic-bezier(0.22, 1, 0.36, 1);

  /* Fonts */
  --font-display: 'Syne', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;
}

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

html {
  height: 100%;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text-hi);
  font-family: var(--font-mono);
  overflow: hidden;
  /* Subtle grain texture overlay */
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(255,209,102,0.06) 0%, transparent 70%);
}

/* ── Loading Screen ───────────────────────────────────────────────────────── */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--t-slow), visibility var(--t-slow);
}

.loading-screen.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.loader-logo {
  font-family: var(--font-display);
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}

.logo-air    { color: var(--accent); }
.logo-canvas { color: var(--text-hi); }

.loader-ring {
  width: 80px;
  height: 80px;
  position: relative;
}

.loader-ring svg { width: 100%; height: 100%; }

.ring-arc {
  transform-origin: 50% 50%;
  animation: spin-ring 1.4s linear infinite;
}

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

.loader-msg {
  font-size: 0.78rem;
  color: var(--text-mid);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  animation: pulse-text 1.6s ease-in-out infinite;
}

@keyframes pulse-text {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 1; }
}

/* ── App Layout ───────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.header-logo {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  cursor: default;
  user-select: none;
}

.header-tagline {
  font-size: 0.7rem;
  color: var(--text-lo);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* FPS badge */
.fps-badge {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-mid);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  display: flex;
  align-items: center;
  gap: 3px;
  transition: color var(--t-fast);
}

.fps-badge.warn { color: var(--mode-erase); }

#fps-value { font-weight: 600; }
.fps-unit  { color: var(--text-lo); }

/* Mode badge */
.mode-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  transition: border-color var(--t-med), background var(--t-med);
}

.mode-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mode-idle);
  transition: background var(--t-med);
  box-shadow: 0 0 0 0 transparent;
}

/* Mode state classes applied via JS */
.mode-badge.draw   { border-color: rgba(77,255,145,0.3); }
.mode-badge.draw   .mode-dot { background: var(--mode-draw); box-shadow: 0 0 6px var(--mode-draw); }
.mode-badge.erase  { border-color: rgba(255,77,77,0.3); }
.mode-badge.erase  .mode-dot { background: var(--mode-erase); box-shadow: 0 0 6px var(--mode-erase); }
.mode-badge.clear  { border-color: rgba(255,226,77,0.3); }
.mode-badge.clear  .mode-dot { background: var(--mode-clear); box-shadow: 0 0 6px var(--mode-clear); }
.mode-badge.save   { border-color: rgba(77,166,255,0.3); }
.mode-badge.save   .mode-dot { background: var(--mode-save); box-shadow: 0 0 6px var(--mode-save); }

/* ── Canvas Section ───────────────────────────────────────────────────────── */
.canvas-section {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #000;
}

/* Hidden video element used by MediaPipe */
.input-video {
  position: absolute;
  top: -9999px;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Drawing canvas fills the section */
.drawing-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: none; /* hide default cursor; we use our custom finger cursor */
}

/* Landmark overlay canvas (on top of drawing canvas) */
.landmark-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t-med);
}

.landmark-canvas.visible { opacity: 1; }

/* Custom finger cursor */
.finger-cursor {
  position: absolute;
  width: 28px;
  height: 28px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 20;
  transition: opacity var(--t-fast);
  opacity: 0;
}

.finger-cursor.visible { opacity: 1; }

.cursor-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: cursor-pulse 1.8s ease-in-out infinite;
}

.cursor-dot {
  position: absolute;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

@keyframes cursor-pulse {
  0%, 100% { transform: scale(1);   opacity: 0.9; }
  50%       { transform: scale(1.3); opacity: 0.5; }
}

/* ── Camera Error ─────────────────────────────────────────────────────────── */
.camera-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  padding: 40px 24px;
  text-align: center;
  z-index: 30;
}

.camera-error.hidden { display: none; }

.error-icon {
  font-size: 3rem;
  filter: grayscale(0.5);
}

.camera-error h3 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-hi);
}

.camera-error p {
  color: var(--text-mid);
  max-width: 360px;
  line-height: 1.6;
}

.error-hints {
  list-style: disc;
  text-align: left;
  color: var(--text-mid);
  padding-left: 20px;
  max-width: 360px;
  line-height: 2;
  font-size: 0.78rem;
}

/* ── Control Panel ────────────────────────────────────────────────────────── */
.control-panel {
  height: var(--ctrl-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 16px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-top: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.control-panel::-webkit-scrollbar { display: none; }

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.ctrl-divider {
  width: 1px;
  height: 28px;
  background: var(--border-2);
  flex-shrink: 0;
  margin: 0 8px;
}

/* ── Colour Swatches ──────────────────────────────────────────────────────── */
.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--c, #fff);
  border: 2px solid rgba(255,255,255,0.15);
  cursor: pointer;
  transition: transform var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
  flex-shrink: 0;
  outline: none;
}

.color-swatch:hover {
  transform: scale(1.18);
  border-color: rgba(255,255,255,0.5);
}

.color-swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.color-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow), 0 0 10px var(--accent-glow);
  transform: scale(1.12);
}

/* Custom colour swatch */
.color-custom {
  cursor: pointer;
  position: relative;
  background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
  display: flex;
  align-items: center;
  justify-content: center;
}

.color-custom input[type="color"] {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.custom-icon {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 0 4px rgba(0,0,0,0.8);
  pointer-events: none;
  line-height: 1;
}

/* ── Brush slider ─────────────────────────────────────────────────────────── */
.ctrl-label {
  font-size: 0.7rem;
  color: var(--text-lo);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.brush-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  outline: none;
  cursor: pointer;
  border: 1px solid var(--border);
}

.brush-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 6px var(--accent-glow);
  border: 2px solid rgba(255,255,255,0.2);
  transition: transform var(--t-fast);
}

.brush-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }

.brush-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

.brush-val {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  min-width: 18px;
  text-align: right;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 13px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-2);
  cursor: pointer;
  outline: none;
  transition: background var(--t-fast), border-color var(--t-fast),
              color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  white-space: nowrap;
  user-select: none;
  flex-shrink: 0;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:active { transform: scale(0.96); }

.btn-ghost {
  background: rgba(255,255,255,0.04);
  color: var(--text-mid);
}

.btn-ghost:hover {
  background: rgba(255,255,255,0.09);
  color: var(--text-hi);
  border-color: var(--border-2);
}

.btn-accent {
  background: var(--accent);
  color: #0c0c0f;
  border-color: transparent;
  font-weight: 700;
}

.btn-accent:hover {
  background: #ffe080;
  box-shadow: 0 0 14px var(--accent-glow);
}

.btn[aria-pressed="true"] {
  background: var(--accent-dim);
  border-color: rgba(255,209,102,0.4);
  color: var(--accent);
}

/* ── Calibration Overlay ──────────────────────────────────────────────────── */
.calibration-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 12, 15, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity var(--t-slow), visibility var(--t-slow);
}

.calibration-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.calib-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  max-width: 340px;
  text-align: center;
  padding: 40px 32px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  box-shadow: 0 32px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04) inset;
}

.calib-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-hi);
}

.calib-desc {
  font-size: 0.78rem;
  color: var(--text-mid);
  line-height: 1.6;
}

.calib-hand-wrap {
  position: relative;
  width: 160px;
  height: 200px;
  margin: 8px 0;
}

.calib-hand-svg {
  width: 100%;
  height: 100%;
}

.calib-outline {
  animation: calib-glow 2s ease-in-out infinite;
}

@keyframes calib-glow {
  0%, 100% { stroke-opacity: 0.5; filter: drop-shadow(0 0 3px var(--accent)); }
  50%       { stroke-opacity: 1;   filter: drop-shadow(0 0 10px var(--accent)); }
}

.calib-progress-ring {
  position: absolute;
  inset: -30px;
  width: calc(100% + 60px);
  height: calc(100% + 60px);
}

.calib-ring-arc {
  transform-origin: 50% 50%;
  transform: rotate(-90deg);
  transition: stroke-dashoffset 0.2s linear;
}

.calib-progress-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#calib-pct {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.calib-hint {
  font-size: 0.7rem;
  color: var(--text-lo);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--t-slow), visibility var(--t-slow);
}

.modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-box {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 36px 32px 28px;
  width: min(92vw, 420px);
  box-shadow: 0 40px 100px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.04) inset;
  animation: modal-in var(--t-slow) both;
}

@keyframes modal-in {
  from { transform: translateY(20px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0)    scale(1);    opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-lo);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: color var(--t-fast), background var(--t-fast);
}

.modal-close:hover { color: var(--text-hi); background: var(--surface-2); }

.modal-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-hi);
  margin-bottom: 22px;
}

/* Gesture list */
.gesture-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gesture-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--t-fast);
}

.gesture-item:hover { border-color: var(--border-2); }

.gesture-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
  line-height: 1;
}

.gesture-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gesture-info strong {
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-hi);
}

.gesture-info span {
  font-size: 0.72rem;
  color: var(--text-mid);
  line-height: 1.5;
}

/* ── Toast Notifications ──────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: calc(var(--ctrl-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9000;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-hi);
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  white-space: nowrap;
  animation: toast-in 0.3s var(--t-slow) both;
  pointer-events: auto;
}

.toast.removing {
  animation: toast-out 0.3s ease forwards;
}

.toast-icon { font-size: 1rem; }

@keyframes toast-in {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@keyframes toast-out {
  from { transform: translateY(0);     opacity: 1; }
  to   { transform: translateY(-10px); opacity: 0; }
}

/* ── Copyright Footer ─────────────────────────────────────────────────────── */
.copyright-footer {
  position: fixed;
  bottom: 0;
  right: 0;
  font-size: 0.58rem;
  color: var(--text-lo);
  padding: 3px 10px;
  z-index: 5;
  pointer-events: none;
  letter-spacing: 0.04em;
}

/* ── Utility ──────────────────────────────────────────────────────────────── */
.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ── Responsive — narrow screens ─────────────────────────────────────────── */
@media (max-width: 600px) {
  :root {
    --ctrl-h: 60px;
    --header-h: 46px;
  }

  .header-tagline { display: none; }

  .brush-slider { width: 64px; }

  .btn span:not(.btn > span:first-child) {
    /* hide text labels on very small screens, keep icons */
    display: none;
  }

  .ctrl-label { display: none; }
}

/* ── High Contrast Support ────────────────────────────────────────────────── */
@media (forced-colors: active) {
  .color-swatch,
  .btn,
  .mode-badge,
  .fps-badge {
    forced-color-adjust: none;
  }
}

/* ── Reduced Motion ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
