/* ============================================================
   GazePainter — css/style.css
   Dark-mode, glassmorphism UI, responsive layout
   ============================================================ */

/* ── Custom Properties ─────────────────────────────────────── */
:root {
  /* Palette */
  --bg-base:        #0a0b0f;
  --bg-surface:     #11131a;
  --bg-elevated:    #1a1d28;
  --glass-bg:       rgba(255, 255, 255, 0.04);
  --glass-border:   rgba(255, 255, 255, 0.08);
  --glass-shadow:   0 8px 32px rgba(0, 0, 0, 0.6);

  --accent:         #6ee7f7;   /* cyan */
  --accent-dim:     rgba(110, 231, 247, 0.15);
  --accent-glow:    rgba(110, 231, 247, 0.35);
  --danger:         #ff5f6d;
  --danger-dim:     rgba(255, 95, 109, 0.15);
  --success:        #4ecca3;

  --text-primary:   #e8eaf0;
  --text-secondary: #7a8099;
  --text-muted:     #3e4259;

  /* Toolbar dimensions */
  --header-h:       52px;
  --toolbar-w:      62px;
  --panel-w:        220px;

  /* Border radii */
  --radius-sm:      6px;
  --radius-md:      12px;
  --radius-lg:      18px;
  --radius-xl:      28px;

  /* Transitions */
  --ease:           cubic-bezier(0.4, 0, 0.2, 1);
  --duration-fast:  140ms;
  --duration-med:   260ms;

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

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 2px; }

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

/* ── Glass Surface ──────────────────────────────────────────── */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

/* ────────────────────────────────────────────────────────────
   OVERLAY / MODAL (Calibration + Dialogs)
──────────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 9, 14, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* ── Calibration Screens ────────────────────────────────────── */
.cal-screen {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: fadeIn var(--duration-med) var(--ease);
}
.cal-screen.active { display: flex; }

/* Welcome / Complete cards */
.cal-card {
  width: min(460px, 90vw);
  padding: 48px 40px;
  border-radius: var(--radius-xl);
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  box-shadow: 0 24px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.04);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.cal-logo {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}
.cal-logo .material-symbols-outlined {
  font-size: 30px;
  color: var(--accent);
  font-variation-settings: 'FILL' 1, 'wght' 300;
}
.cal-logo.success {
  background: rgba(78, 204, 163, 0.12);
  border-color: rgba(78, 204, 163, 0.35);
}
.cal-logo.success .material-symbols-outlined { color: var(--success); }

.cal-card h1 {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--text-primary);
  margin: 0;
}
.cal-card h2 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

.cal-subtitle {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--accent);
  font-weight: 400;
  letter-spacing: 0.5px;
}

.cal-divider {
  width: 100%;
  border: none;
  border-top: 1px solid var(--glass-border);
  margin: 4px 0;
}

.cal-body {
  font-size: 13px;
  line-height: 1.8;
  color: var(--text-secondary);
  max-width: 340px;
}
.cal-body strong { color: var(--text-primary); font-weight: 500; }

/* Camera permission status */
.cal-permissions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  font-size: 12px;
  color: var(--text-secondary);
  width: 100%;
}
.cal-permissions .material-symbols-outlined {
  font-size: 16px;
  color: var(--text-muted);
  font-variation-settings: 'FILL' 0, 'wght' 300;
}
.cal-permissions.granted { border-color: rgba(78,204,163,0.3); }
.cal-permissions.granted .material-symbols-outlined { color: var(--success); }
.cal-permissions.denied { border-color: rgba(255,95,109,0.3); }
.cal-permissions.denied .material-symbols-outlined { color: var(--danger); }

/* Calibration dot screen overlay elements */
.cal-instructions {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 10px 24px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  z-index: 10;
}

.cal-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--text-muted);
  z-index: 10;
}
#cal-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 0.4s var(--ease);
  border-radius: 0 2px 2px 0;
}

.cal-counter {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 2px;
  z-index: 10;
}

/* Individual calibration dots */
#cal-dots-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.cal-dot {
  position: absolute;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  cursor: pointer;
  pointer-events: all;
}
.cal-dot::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.2;
  border: 2px solid var(--accent);
  transition: all 0.2s var(--ease);
}
.cal-dot::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 8px; height: 8px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--accent);
  transition: all 0.2s var(--ease);
}
.cal-dot:hover::before,
.cal-dot.active::before {
  opacity: 0.5;
  transform: scale(1.4);
}
.cal-dot.done::before { background: var(--success); border-color: var(--success); opacity: 0.15; }
.cal-dot.done::after  { background: var(--success); width: 6px; height: 6px; }

/* Ripple animation for dot click */
.cal-dot .ripple {
  position: absolute;
  top: 50%; left: 50%;
  width: 22px; height: 22px;
  transform: translate(-50%, -50%) scale(0);
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: rippleOut 0.5s var(--ease) forwards;
}
@keyframes rippleOut {
  to { transform: translate(-50%, -50%) scale(3.5); opacity: 0; }
}

/* ────────────────────────────────────────────────────────────
   CONFIRM DIALOG
──────────────────────────────────────────────────────────── */
.dialog-overlay { z-index: 2000; }

.dialog-card {
  width: min(380px, 90vw);
  padding: 36px 32px;
  border-radius: var(--radius-lg);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: scaleIn var(--duration-fast) var(--ease);
}

.dialog-icon {
  font-size: 36px;
  color: var(--danger);
  font-variation-settings: 'FILL' 0, 'wght' 300;
}

.dialog-card h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}
.dialog-card p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}
.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  width: 100%;
}
.dialog-actions > * { flex: 1; }

/* ────────────────────────────────────────────────────────────
   BUTTONS
──────────────────────────────────────────────────────────── */
button {
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all var(--duration-fast) var(--ease);
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 24px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #05090f;
  font-weight: 500;
  letter-spacing: 0.3px;
}
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); filter: brightness(0.95); }
.btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  filter: none;
}
.btn-primary .material-symbols-outlined { font-size: 18px; }

.btn-ghost {
  width: 100%;
  padding: 11px 24px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--glass-bg);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.15);
}

.btn-danger {
  padding: 11px 24px;
  border-radius: var(--radius-md);
  background: var(--danger);
  color: #fff;
  font-weight: 500;
}
.btn-danger:hover { filter: brightness(1.1); }

/* ────────────────────────────────────────────────────────────
   MAIN APP LAYOUT
──────────────────────────────────────────────────────────── */
.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-areas:
    "header  header  header"
    "tleft   canvas  tright";
  grid-template-rows: var(--header-h) 1fr;
  grid-template-columns: var(--toolbar-w) 1fr var(--panel-w);
  background: var(--bg-base);
}

/* ── Header ─────────────────────────────────────────────────── */
.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 0 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--glass-border);
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-icon {
  font-size: 20px;
  color: var(--accent);
  font-variation-settings: 'FILL' 0, 'wght' 300;
}
.brand-name {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Icon Buttons (header) */
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn .material-symbols-outlined {
  font-size: 19px;
  font-variation-settings: 'FILL' 0, 'wght' 300;
}
.icon-btn:hover {
  background: var(--glass-bg);
  border-color: var(--glass-border);
  color: var(--text-primary);
}
.icon-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent-glow);
  color: var(--accent);
}
.icon-btn.active .material-symbols-outlined {
  font-variation-settings: 'FILL' 1, 'wght' 400;
}
.icon-btn.accent {
  background: var(--accent-dim);
  border-color: var(--accent-glow);
  color: var(--accent);
}
.icon-btn.accent:hover {
  background: var(--accent);
  color: #05090f;
}

/* ── Canvas Wrapper ─────────────────────────────────────────── */
.canvas-wrapper {
  grid-area: canvas;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(110,231,247,0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(78,204,163,0.02) 0%, transparent 50%),
    /* subtle grid dots */
    radial-gradient(circle, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: auto, auto, 28px 28px;
  cursor: crosshair;
}

#drawing-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* Prevent scroll on touch devices */
}

/* ── Gaze Cursor ────────────────────────────────────────────── */
.gaze-cursor {
  position: absolute;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.3s var(--ease);
  will-change: transform;
}
.gaze-cursor.visible { opacity: 1; }

.gaze-ring {
  position: absolute;
  top: 50%; left: 50%;
  width: 32px; height: 32px;
  transform: translate(-50%, -50%);
  border: 1.5px solid rgba(110, 231, 247, 0.5);
  border-radius: 50%;
  animation: gazeRingPulse 2s ease-in-out infinite;
}
.gaze-dot {
  position: absolute;
  top: 50%; left: 50%;
  width: 6px; height: 6px;
  transform: translate(-50%, -50%);
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-glow);
}

@keyframes gazeRingPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.5; }
  50% { transform: translate(-50%, -50%) scale(1.2); opacity: 0.8; }
}

/* ── Left Toolbar ───────────────────────────────────────────── */
.toolbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  gap: 4px;
  overflow-y: auto;
  z-index: 50;
}

.toolbar-left {
  grid-area: tleft;
  border-right: 1px solid var(--glass-border);
  border-radius: 0;
}

.tool-label, .panel-label {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
}

.tool-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
}

.tool-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.tool-btn .material-symbols-outlined {
  font-size: 20px;
  font-variation-settings: 'FILL' 0, 'wght' 300;
  transition: font-variation-settings 0.1s;
}
.tool-btn:hover {
  background: var(--glass-bg);
  border-color: var(--glass-border);
  color: var(--text-primary);
}
.tool-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent-glow);
  color: var(--accent);
}
.tool-btn.active .material-symbols-outlined {
  font-variation-settings: 'FILL' 1, 'wght' 400;
}
.tool-btn.danger:hover {
  background: var(--danger-dim);
  border-color: rgba(255,95,109,0.3);
  color: var(--danger);
}

/* Tooltip via title is default; override cursor hint */
.tool-btn[title]:hover::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  pointer-events: none;
  z-index: 200;
}

.tool-separator, .panel-separator {
  width: 80%;
  height: 1px;
  background: var(--glass-border);
  margin: 6px 0;
  flex-shrink: 0;
}

/* ── Right Panel ────────────────────────────────────────────── */
.toolbar-right {
  grid-area: tright;
  border-left: 1px solid var(--glass-border);
  padding: 16px 14px;
  gap: 0;
  align-items: stretch;
  overflow-y: auto;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 0;
}

.panel-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  margin-bottom: 0;
}
.panel-value {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  min-width: 36px;
  text-align: right;
}

/* Color picker */
.color-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#color-picker {
  width: 100%;
  height: 40px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  padding: 2px;
}
#color-picker::-webkit-color-swatch-wrapper { padding: 0; }
#color-picker::-webkit-color-swatch {
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
}

/* Color presets grid */
.color-presets {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
}
.preset-dot {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}
.preset-dot:hover { transform: scale(1.15); }
.preset-dot.selected { border-color: var(--text-primary); }

/* Range sliders */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-elevated);
  outline: none;
  cursor: pointer;
  position: relative;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-surface);
  box-shadow: 0 0 6px var(--accent-glow);
  cursor: grab;
  transition: transform var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
}
.slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.2);
  box-shadow: 0 0 12px var(--accent-glow);
}
.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-surface);
  cursor: grab;
}

/* Brush shape buttons */
.brush-shapes {
  display: flex;
  gap: 6px;
}
.shape-btn {
  flex: 1;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.shape-btn:hover {
  background: rgba(255,255,255,0.07);
  color: var(--text-primary);
}
.shape-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent-glow);
  color: var(--accent);
}

/* ────────────────────────────────────────────────────────────
   TOAST NOTIFICATION
──────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius-xl);
  font-size: 12px;
  letter-spacing: 0.3px;
  box-shadow: var(--glass-shadow);
  z-index: 3000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ────────────────────────────────────────────────────────────
   KEYFRAME ANIMATIONS
──────────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: scale(1); }
}

/* ────────────────────────────────────────────────────────────
   RESPONSIVE: Tablet (<=900px)
──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root {
    --panel-w: 180px;
  }
  .brand-name { font-size: 14px; }
  .panel-section { padding: 8px 0; }
}

/* ────────────────────────────────────────────────────────────
   RESPONSIVE: Mobile (<=600px)
──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  :root {
    --header-h: 46px;
    --toolbar-w: 50px;
    --panel-w: 0px;
  }

  .app {
    grid-template-areas:
      "header  header"
      "tleft   canvas";
    grid-template-columns: var(--toolbar-w) 1fr;
  }

  /* Hide right panel on mobile to save space */
  .toolbar-right {
    display: none;
  }

  /* Floating mobile panel trigger could be added later */
  .tool-btn { width: 38px; height: 38px; }
  .cal-card { padding: 32px 24px; }
  .cal-card h1 { font-size: 26px; }
}

/* ────────────────────────────────────────────────────────────
   WebGazer VIDEO FEED — reposition to corner
──────────────────────────────────────────────────────────── */
/* WebGazer injects a <video> and <canvas> for face detection;
   we reposition them to not obstruct the canvas */
#webgazerVideoFeed,
#webgazerFaceOverlay,
#webgazerVideoContainer {
  position: fixed !important;
  bottom: 12px !important;
  right: 12px !important;
  top: auto !important;
  left: auto !important;
  width: 140px !important;
  height: 100px !important;
  border-radius: var(--radius-md) !important;
  overflow: hidden !important;
  opacity: 0.75 !important;
  z-index: 999 !important;
  border: 1px solid var(--glass-border) !important;
}
#webgazerGazeDot { display: none !important; } /* We use our own gaze cursor */
