/**
 * style.css — Fluid Hand Painting
 *
 * Aesthetic: "Ink Studio" — near-black depths, ghost controls,
 * editorial typography. The canvas is the hero; UI dissolves into shadow.
 *
 * Layout:
 *   #fluid-canvas         fills the viewport (z:0)
 *   #toolbar              centred pill, bottom, frosted glass (z:10)
 *   #webcam-panel         bottom-right corner preview (z:20)
 *   #status-bar           top-centre ephemeral text (z:30)
 *   #loader               full-screen boot overlay (z:100)
 */

/* ── Google Fonts ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garant:wght@300;400;500&family=Azeret+Mono:wght@300;400&display=swap');

/* ── Reset + Base ─────────────────────────────────────────────────────────── */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-void);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  cursor: crosshair;
}

/* ── Canvas ───────────────────────────────────────────────────────────────── */

#fluid-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: var(--z-canvas);
  touch-action: none;        /* prevent browser scroll/zoom from stealing touch events */
  -webkit-user-select: none; /* disable iOS text selection on long press */
  user-select: none;

  /* Subtle vignette burned in via CSS — WebGL handles the real one too */
  box-shadow: inset 0 0 180px rgba(0,0,0,0.6);
}

/* ── Status Bar ───────────────────────────────────────────────────────────── */

#status-bar {
  position: fixed;
  top: var(--sp-5);
  left: 50%;
  translate: -50% 0;
  z-index: var(--z-status);
  pointer-events: none;
  text-align: center;
}

#status-text {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 300;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-secondary);

  background: var(--glass-fill);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-pill);
  padding: var(--sp-1) var(--sp-4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  /* Fade in/out driven by JS textContent changes */
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}

/* Show when non-empty — JS sets textContent, we detect via :not(:empty) */
#status-text:not(:empty) {
  opacity: 1;
}

/* ── Toolbar ──────────────────────────────────────────────────────────────── */

#toolbar {
  position: fixed;
  bottom: var(--sp-6);
  left: 50%;
  translate: -50% 0;
  z-index: var(--z-ui);

  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);

  background: var(--glass-fill);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-pill);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  box-shadow: var(--shadow-md), inset 0 1px 0 var(--glass-shine);

  /* Subtle appear on load */
  animation: toolbar-rise var(--dur-xslow) var(--ease-ink) both;
}

@keyframes toolbar-rise {
  from { opacity: 0; translate: -50% 12px; }
  to   { opacity: 1; translate: -50% 0;    }
}

/* Thin separator between groups */
.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--glass-border);
  margin: 0 var(--sp-1);
  flex-shrink: 0;
}

/* ── Toolbar Buttons ──────────────────────────────────────────────────────── */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);

  height: var(--toolbar-h);
  padding: 0 var(--sp-4);
  border: none;
  border-radius: var(--r-pill);
  cursor: pointer;

  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 400;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  white-space: nowrap;

  color: var(--text-label);
  background: transparent;
  transition:
    background  var(--dur-fast) var(--ease-out),
    color       var(--dur-fast) var(--ease-out),
    box-shadow  var(--dur-fast) var(--ease-out),
    scale       var(--dur-fast) var(--ease-spring);
}

.btn:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.06);
  scale: 1.04;
}

.btn:active {
  scale: 0.96;
}

.btn:disabled {
  opacity: 0.38;
  pointer-events: none;
}

/* Icon-only compact buttons */
.btn-icon {
  padding: 0;
  width: 40px;
}

/* ── Clear Button ─────────────────────────────────────────────────────────── */

#btn-clear:hover {
  color: var(--ink-white);
  background: rgba(255,255,255,0.06);
}

/* ── Export PNG ───────────────────────────────────────────────────────────── */

#btn-export-png {
  color: var(--ink-cyan);
}

#btn-export-png:hover {
  color: var(--ink-cyan);
  background: rgba(34, 211, 238, 0.10);
  box-shadow: 0 0 16px rgba(34, 211, 238, 0.12);
}

/* ── Record Button ────────────────────────────────────────────────────────── */

#btn-record {
  color: var(--text-label);
  transition: background var(--dur-fast) var(--ease-out),
              color     var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out),
              scale     var(--dur-fast) var(--ease-spring);
}

#btn-record:hover {
  color: var(--rec-red);
  background: rgba(255, 34, 85, 0.08);
}

/* Recording state — glowing red pill */
#btn-record.recording {
  color: #fff;
  background: rgba(255, 34, 85, 0.18);
  box-shadow: 0 0 0 1px rgba(255, 34, 85, 0.5),
              0 0 24px rgba(255, 34, 85, 0.25);
}

/* Pulsing dot prefix for recording state */
#btn-record.recording::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--rec-red);
  margin-right: var(--sp-2);
  animation: rec-pulse 1.2s ease-in-out infinite;
}

@keyframes rec-pulse {
  0%, 100% { opacity: 1;    scale: 1;    }
  50%       { opacity: 0.3; scale: 0.7;  }
}

/* Processing state */
#btn-record.processing {
  color: var(--ink-amber);
  background: rgba(245, 158, 11, 0.08);
  cursor: wait;
}

/* ── Fullscreen Button ────────────────────────────────────────────────────── */

#btn-fullscreen:hover { color: var(--ink-violet); }
#btn-fullscreen.active { color: var(--ink-violet); }

/* ── Palette Buttons ──────────────────────────────────────────────────────── */

.palette-group {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.btn-palette {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.12);
  cursor: pointer;
  position: relative;
  transition:
    scale      var(--dur-fast) var(--ease-spring),
    border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

.btn-palette:hover {
  scale: 1.18;
  border-color: rgba(255,255,255,0.30);
}

.btn-palette.active {
  scale: 1.12;
  border-color: rgba(255,255,255,0.70);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.12);
}

.btn-palette[data-palette="INK"]    { background: var(--pal-ink);    }
.btn-palette[data-palette="NEON"]   { background: var(--pal-neon);   }
.btn-palette[data-palette="FIRE"]   { background: var(--pal-fire);   }
.btn-palette[data-palette="OCEAN"]  { background: var(--pal-ocean);  }
.btn-palette[data-palette="SAKURA"] { background: var(--pal-sakura); }

/* Tooltip via aria-label + ::after (no JS needed) */
.btn-palette::after {
  content: attr(aria-label);
  position: absolute;
  bottom: calc(100% + var(--sp-2));
  left: 50%;
  translate: -50% 0;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-sm);
  padding: 3px var(--sp-2);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  scale: 0.88;
  transition:
    opacity var(--dur-fast) var(--ease-out),
    scale   var(--dur-fast) var(--ease-out);
}

.btn-palette:hover::after {
  opacity: 1;
  scale: 1;
}

/* ── Webcam Panel ─────────────────────────────────────────────────────────── */

#webcam-panel {
  position: fixed;
  bottom: calc(var(--sp-6) + var(--toolbar-h) + var(--sp-4));
  right: var(--sp-6);
  z-index: var(--z-webcam);
  width: var(--webcam-size);

  background: var(--glass-fill);
  border: var(--webcam-border) solid var(--glass-border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);

  /* Appear from bottom-right */
  animation: webcam-appear var(--dur-xslow) var(--ease-ink) 0.4s both;

  /* Fade on hover so it doesn't obstruct painting */
  opacity: 0.72;
  transition: opacity var(--dur-base) var(--ease-out);
}

#webcam-panel:hover {
  opacity: 1.0;
}

@keyframes webcam-appear {
  from { opacity: 0; translate: 10px 10px; }
  to   { opacity: 0.72; translate: 0 0;    }
}

/* Label strip above mirror */
#webcam-panel::before {
  content: 'HAND TRACKING';
  display: block;
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--text-xs);
  font-weight: 300;
  letter-spacing: var(--tracking-wider);
  color: var(--text-muted);
  background: rgba(0,0,0,0.4);
  text-align: center;
}

/* The hidden raw video feed (MediaPipe reads this) */
#webcam-video {
  display: none;
}

/* The annotated canvas mirror */
#webcam-mirror {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4/3;
  border-radius: 0 0 calc(var(--r-lg) - 2px) calc(var(--r-lg) - 2px);
}

/* ── Loader ───────────────────────────────────────────────────────────────── */

#loader {
  position: fixed;
  inset: 0;
  z-index: var(--z-loader);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-6);

  background: var(--bg-void);
  transition: opacity var(--dur-slow) var(--ease-out);
}

/* Animated ink drop */
.loader-drop {
  position: relative;
  width: 56px;
  height: 56px;
}

.loader-drop::before,
.loader-drop::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid transparent;
}

.loader-drop::before {
  border-top-color: var(--ink-violet);
  border-right-color: var(--ink-violet);
  animation: spin 1.1s linear infinite;
}

.loader-drop::after {
  inset: 10px;
  border-top-color: var(--ink-cyan);
  border-left-color: var(--ink-cyan);
  animation: spin 0.7s linear infinite reverse;
}

@keyframes spin {
  to { rotate: 360deg; }
}

/* Inner dot */
.loader-dot {
  position: absolute;
  inset: 22px;
  border-radius: 50%;
  background: var(--ink-violet);
  opacity: 0.6;
  animation: dot-pulse 1.4s ease-in-out infinite;
}

@keyframes dot-pulse {
  0%, 100% { scale: 1; opacity: 0.6; }
  50%       { scale: 0.4; opacity: 0.15; }
}

/* Wordmark under spinner */
.loader-title {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: var(--text-2xl);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-primary);
  opacity: 0.7;
}

.loader-sub {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: calc(var(--sp-2) * -1);
}

/* Error state injected by JS */
.loader-error {
  text-align: center;
  color: var(--ink-crimson);
  font-size: var(--text-base);
}

.loader-error small {
  display: block;
  margin-top: var(--sp-2);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* ── Keyboard Hint ────────────────────────────────────────────────────────── */

/* Small hint panel, visible briefly on first paint */
#key-hint {
  position: fixed;
  top: var(--sp-5);
  right: var(--sp-6);
  z-index: var(--z-ui);
  pointer-events: none;

  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: var(--sp-3) var(--sp-4);

  background: var(--glass-fill);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  animation: hint-show 8s var(--ease-out) 1.5s both;
}

@keyframes hint-show {
  0%   { opacity: 0; translate: 6px 0; }
  10%  { opacity: 1; translate: 0 0;   }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

.hint-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.hint-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 18px;
  padding: 0 var(--sp-1);
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 4px;
  font-size: 10px;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  flex-shrink: 0;
}

/* ── Scrollbar (unlikely to appear, but just in case) ────────────────────── */

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg-void); }
::-webkit-scrollbar-thumb { background: var(--bg-raised); border-radius: 2px; }

/* ── Selection ────────────────────────────────────────────────────────────── */

::selection {
  background: rgba(124, 92, 252, 0.35);
  color: var(--ink-white);
}

/* ── Focus Visible ────────────────────────────────────────────────────────── */

:focus-visible {
  outline: 2px solid var(--ink-violet);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}

/* ── Reduced Motion ───────────────────────────────────────────────────────── */

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