/* ============================================
   BEYOND WORDS — APP PAGE STYLES
   Mobile-first
   ============================================ */

/* Use dynamic viewport height to handle iOS address bar correctly */
.app-body {
  background: var(--bg);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* APP HEADER */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: rgba(13,13,15,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  gap: 10px;
  min-height: 56px;
  flex-shrink: 0;
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  text-decoration: none;
  transition: all 0.2s;
  flex-shrink: 0;
  touch-action: manipulation;
}

.back-btn:hover { background: var(--card2); border-color: var(--border2); }
.back-btn:active { transform: scale(0.93); }

.app-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  justify-content: center;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 50px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text2);
  white-space: nowrap;
  flex-shrink: 0;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text3);
  transition: background 0.3s;
}

.status-dot.ready    { background: var(--success); animation: pulse 2s infinite; }
.status-dot.detecting { background: var(--accent);  animation: pulse 1s infinite; }
.status-dot.loading  { background: var(--warning);  animation: pulse 0.8s infinite; }
.status-dot.error    { background: var(--accent3); }

/* ── CAMERA SECTION ── */
.camera-section {
  padding-top: 56px;   /* header height */
  position: relative;
  flex-shrink: 0;
}

.camera-wrapper {
  position: relative;
  width: 100%;
  /* Mobile: compact so the panel is easily visible without scrolling */
  height: 42vw;
  min-height: 180px;
  max-height: 44vh;
  background: #000;
  overflow: hidden;
}

#videoFeed {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  display: block;
}

#overlayCanvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  transform: scaleX(-1);
  pointer-events: none;
}

/* BRACKETS */
.bracket {
  position: absolute;
  width: 24px; height: 24px;
  border-color: rgba(79,138,255,0.7);
  border-style: solid;
  z-index: 10;
  transition: border-color 0.3s;
}

.bracket.tl { top: 10px;  left: 10px;  border-width: 2px 0 0 2px; }
.bracket.tr { top: 10px;  right: 10px; border-width: 2px 2px 0 0; }
.bracket.bl { bottom: 56px; left: 10px;  border-width: 0 0 2px 2px; }
.bracket.br { bottom: 56px; right: 10px; border-width: 0 2px 2px 0; }

.camera-wrapper.hand-detected .bracket {
  border-color: var(--success);
  animation: bracketPulse 0.5s ease;
}

@keyframes bracketPulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.12); }
}

/* SCAN OVERLAY */
.scan-overlay {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0;
  pointer-events: none;
  z-index: 10;
}

.scan-overlay.active {
  opacity: 1;
  animation: scanDown 2s ease-in-out infinite;
}

@keyframes scanDown {
  0%   { top: 0;                  opacity: 0; }
  5%   {                           opacity: 1; }
  95%  {                           opacity: 1; }
  100% { top: calc(100% - 56px); opacity: 0; }
}

/* PERMISSION / LOADING OVERLAYS */
.permission-overlay, .loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(13,13,15,0.93);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  flex-direction: column;
}

.permission-overlay.hidden, .loading-overlay.hidden { display: none; }

.perm-content, .load-content {
  text-align: center;
  padding: 20px;
  max-width: 280px;
}

.perm-icon { font-size: 2.6rem; margin-bottom: 14px; }

.perm-content h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.perm-content p {
  color: var(--text2);
  font-size: 0.85rem;
  margin-bottom: 20px;
  line-height: 1.6;
}

.perm-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 14px 28px;
  border-radius: 50px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  min-height: 52px;
  transition: all 0.2s;
  touch-action: manipulation;
}

.perm-btn:active { transform: scale(0.97); }

.load-spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}

.load-content p { color: var(--text2); font-size: 0.85rem; }

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

/* DETECTION BADGE */
.detection-badge {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(13,13,15,0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  z-index: 20;
}

.badge-icon { font-size: 1.6rem; flex-shrink: 0; }
.badge-info { flex: 1; min-width: 0; }
.badge-label {
  font-size: 0.6rem;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.badge-gesture {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.2s;
}

.confidence-bar {
  width: 52px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}

.confidence-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
}

/* ── TRANSLATION PANEL ── */
.translation-panel {
  flex: 1;
  min-height: 0;          /* required for flex overflow */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  /* bottom safe area for iPhone home indicator */
  padding-bottom: env(safe-area-inset-bottom);
}

/* CURRENT DETECTION */
.current-detection {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  flex-shrink: 0;
}

.detect-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.detect-block { flex: 1; }
.detect-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text3);
  margin-bottom: 3px;
}

.detect-word {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--en);
  min-height: 1.6rem;
  transition: all 0.2s;
}

.detect-word-en { color: var(--en); }

.detect-divider {
  font-size: 1rem;
  color: var(--text3);
  flex-shrink: 0;
}

.detect-confidence {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--success);
  background: rgba(79,204,138,0.12);
  padding: 4px 9px;
  border-radius: 50px;
  flex-shrink: 0;
  min-width: 48px;
  text-align: center;
}

/* SENTENCE SECTION */
.sentence-section {
  padding: 14px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sentence-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sentence-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text2);
}

.sentence-actions { display: flex; gap: 8px; }

/* Touch-friendly action buttons — 44×44 minimum */
.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
}

.action-btn:hover  { background: var(--card2); color: var(--text); }
.action-btn:active { transform: scale(0.92); }

.action-btn.danger:hover {
  background: rgba(255,107,107,0.15);
  border-color: rgba(255,107,107,0.3);
  color: var(--accent3);
}

.sentence-display {
  min-height: 56px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--en);
  line-height: 1.5;
  word-break: break-word;
}

.sentence-placeholder {
  color: var(--text3);
  font-size: 0.82rem;
  font-weight: 400;
  font-style: italic;
}

.sentence-en {
  margin-top: 6px;
  font-size: 0.84rem;
  color: var(--en);
  min-height: 18px;
  padding: 0 2px;
  opacity: 0.8;
}

/* Word chips */
.word-chip {
  display: inline-block;
  background: rgba(79,138,255,0.12);
  border: 1px solid rgba(79,138,255,0.2);
  border-radius: 6px;
  padding: 3px 9px;
  margin: 2px 3px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--en);
  animation: chipIn 0.2s ease both;
}

@keyframes chipIn {
  from { opacity: 0; transform: scale(0.8) translateY(4px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}

/* CONTROLS */
.controls {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.voice-selector {
  display: flex;
  align-items: center;
  gap: 10px;
}

.voice-selector label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text2);
  white-space: nowrap;
}

.voice-selector select {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 10px 12px;
  min-height: 44px;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}

.voice-selector select:focus { border-color: var(--accent); }

.speak-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  border: none;
  padding: 16px 20px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s;
  box-shadow: 0 4px 20px rgba(79,138,255,0.35);
  min-height: 52px;
  width: 100%;
  touch-action: manipulation;
}

.speak-btn:active { transform: scale(0.97); }

.speak-btn.speaking {
  background: linear-gradient(135deg, var(--success), #2fa870);
  animation: speakPulse 1s ease-in-out infinite;
}

@keyframes speakPulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(79,204,138,0.35); }
  50%       { box-shadow: 0 4px 32px rgba(79,204,138,0.7); }
}

.add-word-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 14px 20px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 52px;
  width: 100%;
  touch-action: manipulation;
}

.add-word-btn:active {
  background: var(--card2);
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(0.98);
}

/* SIGN REFERENCE */
.sign-reference {
  padding: 14px 16px;
  padding-bottom: 20px;
  flex-shrink: 0;
}

.sign-reference summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text2);
  list-style: none;
  user-select: none;
  padding: 10px 0;
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  touch-action: manipulation;
}

.sign-reference summary::-webkit-details-marker { display: none; }

.ref-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.ref-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 6px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  min-height: var(--tap-min);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.ref-item:active {
  background: var(--card2);
  border-color: var(--accent);
  transform: scale(0.96);
}

.ref-item .ref-emoji { font-size: 1.4rem; margin-bottom: 4px; }
.ref-item .ref-en    { font-size: 0.62rem; color: var(--text2); font-weight: 600; }

/* ── DESKTOP LAYOUT ── */
@media (min-width: 768px) {
  .app-body {
    flex-direction: row;
    height: 100vh;
    height: 100dvh;
  }

  .camera-section {
    flex: 1;
    padding-top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    min-height: 0;
  }

  .camera-wrapper {
    width: 100%;
    height: 100%;
    max-height: none;
    min-height: unset;
  }

  .translation-panel {
    width: 380px;
    flex-shrink: 0;
    border-left: 1px solid var(--border);
    padding-top: 65px;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
  }

  .app-header { z-index: 200; }

  .ref-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── SMALL PHONES (< 380px) ── */
@media (max-width: 380px) {
  .app-header { padding: 8px 12px; min-height: 52px; }
  .app-title  { font-size: 0.85rem; }

  .camera-section { padding-top: 52px; }
  .camera-wrapper { max-height: 38vh; }

  .detect-word { font-size: 1.15rem; }
  .ref-grid    { grid-template-columns: repeat(3, 1fr); gap: 6px; }
}

/* ── ANIMATIONS ── */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.85); }
}

.gesture-flash { animation: gestureFlash 0.3s ease; }

@keyframes gestureFlash {
  0%   { opacity: 1; }
  50%  { opacity: 0.5; transform: scale(1.04); }
  100% { opacity: 1; transform: scale(1); }
}
