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

:root {
  --bg:       #000;
  --surface:  #0c0c0e;
  --surface2: #141416;
  --surface3: #1c1c1e;
  --border:   rgba(255,255,255,0.07);
  --border2:  rgba(255,255,255,0.12);
  --accent:   #0071e3;
  --cyan:     #00c8ff;
  --green:    #30d158;
  --gray:     #86868b;
  --gray2:    #48484a;
  --font:     'Inter', -apple-system, sans-serif;
  --ease:     cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: #fff;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Nav ── */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 48px;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
  position: relative;
}

.nav-back {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  transition: opacity 0.2s;
  min-width: 80px;
}
.nav-back:hover { opacity: 0.7; }

.nav-center {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-title {
  font-size: 13px;
  color: var(--gray);
  font-weight: 500;
}

.nav-phase-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--green);
  background: rgba(48,209,88,0.12);
  border: 1px solid rgba(48,209,88,0.25);
  border-radius: 4px;
  padding: 2px 6px;
}

.nav-status {
  font-size: 12px;
  color: var(--gray);
  text-align: right;
  min-width: 120px;
}
.nav-status.ready { color: var(--green); }
.nav-status.error { color: #ff453a; }

/* ── Main layout ── */
.main {
  display: grid;
  grid-template-columns: 1fr 300px;
  flex: 1;
  overflow: hidden;
}

/* ── Viewport ── */
.viewport-wrap {
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 10px;
  background: #050507;
  overflow: hidden;
}

.viewport {
  position: relative;
  flex: 1;
  border-radius: 14px;
  overflow: hidden;
  background: #08080c;
  box-shadow:
    0 0 0 1px var(--border),
    0 0 60px rgba(0,100,200,0.06);
}

#video {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  border-radius: 14px;
  visibility: hidden; /* active for MediaPipe; drawn on canvas instead */
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
}

/* Corner brackets */
.bracket {
  position: absolute;
  width: 20px; height: 20px;
  z-index: 5;
  pointer-events: none;
}
.br-tl { top: 10px; left: 10px;  border-top:    1.5px solid rgba(0,200,255,0.4); border-left:   1.5px solid rgba(0,200,255,0.4); }
.br-tr { top: 10px; right: 10px; border-top:    1.5px solid rgba(0,200,255,0.4); border-right:  1.5px solid rgba(0,200,255,0.4); }
.br-bl { bottom: 10px; left: 10px;  border-bottom: 1.5px solid rgba(0,200,255,0.4); border-left:  1.5px solid rgba(0,200,255,0.4); }
.br-br { bottom: 10px; right: 10px; border-bottom: 1.5px solid rgba(0,200,255,0.4); border-right: 1.5px solid rgba(0,200,255,0.4); }

/* Scan line */
.scan-line {
  position: absolute;
  left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0,200,255,0.45), transparent);
  pointer-events: none;
  z-index: 4;
  animation: scan 4s ease-in-out infinite;
}
@keyframes scan {
  0%   { top: 0%;   opacity: 0; }
  5%   { opacity: 1; }
  95%  { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

/* Tracking badge */
.track-badge {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 11px;
  color: var(--gray);
  z-index: 6;
  pointer-events: none;
  transition: border-color 0.3s;
}
.track-badge.tracking {
  border-color: rgba(0,200,255,0.35);
  color: rgba(0,200,255,0.8);
}

.track-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gray2);
  transition: background 0.3s;
}
.track-badge.tracking .track-dot {
  background: var(--cyan);
  box-shadow: 0 0 8px rgba(0,200,255,0.7);
  animation: dot-pulse 1.2s ease-in-out infinite;
}
@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* Command toast */
.cmd-toast {
  position: absolute;
  bottom: 20px; left: 50%;
  transform: translateX(-50%) translateY(12px);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.82);
  backdrop-filter: blur(16px);
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 10px 18px;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  white-space: nowrap;
}
.cmd-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.cmd-toast-icon {
  font-size: 20px;
  font-style: normal;
  line-height: 1;
}
.cmd-toast-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
}
.cmd-toast-desc {
  font-size: 12px;
  color: rgba(255,255,255,0.45);
}

/* No camera */
.no-camera {
  display: none;
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.88);
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  z-index: 15;
  pointer-events: all;
}
.no-camera.visible { display: flex; }

.no-camera-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.no-camera-inner p { font-size: 16px; color: rgba(255,255,255,0.7); }
.no-camera-sub { font-size: 13px !important; color: var(--gray) !important; }

.btn-allow {
  margin-top: 4px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 980px;
  padding: 10px 24px;
  font-size: 15px;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-allow:hover { opacity: 0.85; }

/* Viewport stats bar */
.viewport-stats {
  display: flex;
  gap: 0;
  background: var(--surface2);
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

.vstat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  border-right: 1px solid var(--border);
}
.vstat:last-child { border-right: none; }

.vstat-label {
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gray);
  margin-bottom: 4px;
}

.vstat-val {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.3px;
  font-variant-numeric: tabular-nums;
}

/* ── Panel ── */
.panel {
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--gray2) transparent;
}

.panel-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.section-label {
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--gray);
  font-weight: 600;
  margin-bottom: 10px;
}

/* Gesture display */
.gesture-section { background: var(--surface2); }

/* Emotion display */
.emotion-section { background: var(--surface2); }
.emotion-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
}
.emotion-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  transition: color 0.25s;
}
.emotion-conf {
  font-size: 11px;
  color: var(--gray);
  font-variant-numeric: tabular-nums;
}

.gesture-name {
  display: block;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 10px;
  min-height: 34px;
  transition: color 0.2s;
}
.gesture-name.activated {
  animation: g-flash 0.55s var(--ease) both;
}
@keyframes g-flash {
  0%   { color: #fff; }
  35%  { color: rgba(0,240,140,1); text-shadow: 0 0 20px rgba(0,240,140,0.6); }
  100% { color: #fff; text-shadow: none; }
}

.conf-row { display: flex; align-items: center; gap: 8px; }

.conf-track {
  flex: 1; height: 3px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px; overflow: hidden;
}
.conf-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--cyan));
  border-radius: 2px;
  transition: width 0.12s var(--ease);
}
.conf-val {
  font-size: 11px; color: var(--gray);
  font-variant-numeric: tabular-nums;
  min-width: 30px; text-align: right;
}

/* Command output */
.cmd-section { background: #0a0f0a; }

.cmd-output {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.cmd-output.flash {
  animation: cmd-flash 0.5s var(--ease) both;
}
@keyframes cmd-flash {
  0%   { opacity: 0.4; transform: scale(0.95); }
  50%  { opacity: 1;   transform: scale(1.04); }
  100% { opacity: 1;   transform: scale(1); }
}

.cmd-idle { font-size: 12px; font-weight: 400; color: var(--gray); }

.cmd-icon { font-style: normal; font-size: 18px; }
.cmd-name { font-size: 20px; }

/* Finger state */
.finger-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.fi-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.fi-pip {
  width: 100%;
  height: 36px;
  border-radius: 6px;
  background: var(--surface3);
  border: 1px solid rgba(255,255,255,0.06);
  transition: background 0.1s, border-color 0.1s, box-shadow 0.1s;
  position: relative;
  overflow: hidden;
}

.fi-pip::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.05), transparent);
  border-radius: inherit;
}

.fi-pip.extended {
  background: rgba(0,113,227,0.4);
  border-color: rgba(0,180,255,0.5);
  box-shadow: 0 0 10px rgba(0,180,255,0.25);
}

.fi-lbl {
  font-size: 9px;
  color: var(--gray);
  letter-spacing: 0.03em;
}

/* Command history */
.history-section { flex-shrink: 0; }

.cmd-history {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 110px;
  overflow-y: auto;
}

.cmd-history li {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  padding: 3px 0;
}
.ch-icon { font-style: normal; font-size: 13px; }
.ch-cmd  { flex: 1; font-weight: 600; color: rgba(255,255,255,0.75); }
.ch-time { font-size: 10px; color: var(--gray); font-variant-numeric: tabular-nums; }

/* Gesture map */
.map-section { flex-shrink: 0; }

.gesture-map {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gm-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 7px;
  background: var(--surface3);
  font-size: 12px;
  transition: background 0.15s;
}
.gm-row.active { background: rgba(0,113,227,0.18); }

.gm-emoji { font-size: 14px; width: 20px; text-align: center; }
.gm-gesture { flex: 1; color: rgba(255,255,255,0.6); }
.gm-arrow { color: var(--gray2); font-size: 10px; }
.gm-cmd {
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.04em;
}

/* Signal log */
.log-section { flex: 1; min-height: 80px; }

.log-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 120px;
  overflow-y: auto;
}

.log-list li {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--gray);
  gap: 8px;
}
.log-gesture { color: rgba(0,200,255,0.75); font-weight: 500; }
.log-time    { font-variant-numeric: tabular-nums; opacity: 0.5; }

/* ── Mode Toggle ── */
.mode-toggle {
  display: flex;
  gap: 6px;
}
.mode-btn {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border2);
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  color: var(--gray);
  font: 500 12px/1 var(--font);
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, color 0.18s;
}
.mode-btn:hover { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.8); }
.mode-btn--active {
  background: rgba(0,170,255,0.14);
  border-color: rgba(0,170,255,0.5);
  color: #00aaff;
}

/* ── ASL Word Builder ── */
.asl-word-wrap { display: flex; flex-direction: column; gap: 10px; }

.asl-typed-word {
  font: 700 30px/1.1 var(--font);
  color: #fff;
  letter-spacing: 0.1em;
  min-height: 38px;
  word-break: break-all;
}

.asl-word-btns { display: flex; gap: 6px; }

.asl-btn {
  padding: 6px 12px;
  border: 1px solid var(--border2);
  border-radius: 6px;
  background: rgba(255,255,255,0.05);
  color: var(--gray);
  font: 500 12px var(--font);
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, color 0.18s;
}
.asl-btn:hover {
  background: rgba(255,80,60,0.14);
  border-color: rgba(255,80,60,0.4);
  color: rgba(255,120,100,0.9);
}
.asl-btn--clear:hover {
  background: rgba(255,160,0,0.12);
  border-color: rgba(255,160,0,0.4);
  color: rgba(255,180,60,0.9);
}

/* ── ASL Letter Grid ── */
.asl-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.asl-num-grid {
  grid-template-columns: repeat(5, 1fr);
}

.asl-num-grid .asl-cell {
  font-size: 16px;
}

.asl-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 6px;
  font: 600 12px/1 var(--font);
  color: rgba(255,255,255,0.55);
  background: rgba(255,255,255,0.03);
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  user-select: none;
}

.asl-unsupported { opacity: 0.18; }

.asl-cell.asl-active {
  background: rgba(0,170,255,0.18);
  border-color: rgba(0,170,255,0.65);
  color: #00aaff;
  box-shadow: 0 0 10px rgba(0,170,255,0.28);
}

.asl-cell.asl-typed {
  animation: asl-pop 0.55s var(--ease) both;
}

@keyframes asl-pop {
  0%   { background: rgba(0,240,140,0.40); border-color: rgba(0,240,140,0.8); color: #00f08c; transform: scale(1.15); }
  60%  { transform: scale(1.05); }
  100% { background: rgba(255,255,255,0.03); border-color: rgba(255,255,255,0.07); color: rgba(255,255,255,0.55); transform: scale(1); }
}

/* ── Responsive ── */
@media (max-width: 860px) {
  body { overflow: auto; }

  .main {
    grid-template-columns: 1fr;
    overflow: visible;
    height: auto;
  }

  .viewport-wrap {
    height: auto;
    min-height: unset;
  }

  .viewport {
    aspect-ratio: 4 / 3;
  }

  .panel {
    width: 100%;
    max-height: none;
    border-left: none;
    border-top: 1px solid var(--border);
    overflow: visible;
  }

  .panel-section {
    padding: 12px 16px;
  }

  .gesture-display {
    padding: 12px 0 4px;
  }

  .gesture-name {
    font-size: 22px;
  }

  .finger-row {
    gap: 8px;
  }

  .asl-grid {
    grid-template-columns: repeat(9, 1fr);
  }

  .mode-toggle {
    width: 100%;
  }

  .mode-btn {
    flex: 1;
  }
}
