/* ==========================================================================
   WebAR Interactive Interface Styling
   Glassmorphism HUD, 3D Canvas, Scanner Reticle, Audio & "ดูเพิ่ม" Modal
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;700;800&family=Prompt:wght@300;400;500;600;700&display=swap');

:root {
  --ar-bg: #030712;
  --ar-cyan: #06b6d4;
  --ar-blue: #38bdf8;
  --ar-red: #ef4444;
  --ar-red-bright: #ff3366;
  --ar-green: #10b981;
  --ar-glass-bg: rgba(15, 23, 42, 0.78);
  --ar-glass-border: rgba(255, 255, 255, 0.15);
  --ar-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Prompt', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--ar-bg);
  color: #f8fafc;
}

/* ==========================================================================
   AR Viewport Layers
   Layer 1: Video Feed (Camera)
   Layer 2: 3D Canvas (Three.js)
   Layer 3: UI HUD Overlay
   ========================================================================== */
#ar-app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#camera-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  transform: scaleX(1); /* standard camera */
}

/* Simulation backdrop when camera is off */
.simulated-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 40%, #1e1b4b 0%, #090d16 60%, #020617 100%);
  z-index: 1;
  display: block;
}

#webgl-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: auto;
}

/* UI Overlay Container */
.ar-hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none; /* children enable pointer events */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
}

/* ---------------- Top Bar HUD ---------------- */
.hud-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: auto;
}

.brand-badge {
  background: var(--ar-glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--ar-glass-border);
  padding: 8px 14px;
  border-radius: 12px;
  box-shadow: var(--ar-shadow);
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge .icon {
  font-size: 1.25rem;
  animation: heartPulse 1.2s infinite;
}

@keyframes heartPulse {
  0%, 100% { transform: scale(1); }
  15% { transform: scale(1.22); }
  28% { transform: scale(1); }
  42% { transform: scale(1.15); }
  70% { transform: scale(1); }
}

.brand-badge .text {
  display: flex;
  flex-direction: column;
}

.brand-badge .text-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.1;
}

.brand-badge .text-sub {
  font-size: 0.68rem;
  color: var(--ar-blue);
  font-family: 'Plus Jakarta Sans', sans-serif;
  letter-spacing: 0.5px;
}

/* Controls cluster on right */
.hud-actions {
  display: flex;
  gap: 8px;
}

.btn-hud-icon {
  background: var(--ar-glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--ar-glass-border);
  color: #ffffff;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--ar-shadow);
}

.btn-hud-icon:hover {
  background: rgba(56, 189, 248, 0.25);
  border-color: var(--ar-blue);
  transform: scale(1.05);
}

.btn-hud-icon.active {
  background: rgba(16, 185, 129, 0.25);
  border-color: var(--ar-green);
  color: #6ee7b7;
}

/* Tracking Status Pill */
.tracking-pill {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 6px 14px;
  border-radius: 30px;
  font-size: 0.78rem;
  font-weight: 600;
  box-shadow: var(--ar-shadow);
  pointer-events: auto;
  margin-top: 8px;
  transition: all 0.3s ease;
}

.tracking-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ar-cyan);
  box-shadow: 0 0 10px var(--ar-cyan);
}

.tracking-pill.found .tracking-dot {
  background: var(--ar-green);
  box-shadow: 0 0 10px var(--ar-green);
}

.tracking-pill.searching .tracking-dot {
  background: #f59e0b;
  box-shadow: 0 0 10px #f59e0b;
  animation: pulse 1s infinite;
}

/* ---------------- Scanning Reticle ---------------- */
.scanner-reticle-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 260px;
  height: 260px;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  opacity: 1;
}

.scanner-reticle-overlay.locked {
  opacity: 0.15;
  transform: translate(-50%, -50%) scale(0.9);
}

.reticle-box {
  width: 100%;
  height: 100%;
  position: relative;
  border: 1px dashed rgba(56, 189, 248, 0.4);
  border-radius: 16px;
}

.reticle-corner {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: var(--ar-blue);
  border-style: solid;
}

.rc-tl { top: -2px; left: -2px; border-width: 3px 0 0 3px; border-top-left-radius: 12px; }
.rc-tr { top: -2px; right: -2px; border-width: 3px 3px 0 0; border-top-right-radius: 12px; }
.rc-bl { bottom: -2px; left: -2px; border-width: 0 0 3px 3px; border-bottom-left-radius: 12px; }
.rc-br { bottom: -2px; right: -2px; border-width: 0 3px 3px 0; border-bottom-right-radius: 12px; }

/* Laser scanning beam */
.scanner-laser {
  position: absolute;
  left: 5%;
  right: 5%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #38bdf8 30%, #ef4444 50%, #38bdf8 70%, transparent);
  box-shadow: 0 0 12px #38bdf8, 0 0 20px #ef4444;
  animation: scanMove 2.2s ease-in-out infinite alternate;
}

@keyframes scanMove {
  0% { top: 5%; opacity: 0.3; }
  50% { opacity: 1; }
  100% { top: 95%; opacity: 0.3; }
}

.reticle-hint {
  position: absolute;
  bottom: -32px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 0.76rem;
  color: #e2e8f0;
  background: rgba(0, 0, 0, 0.65);
  padding: 4px 10px;
  border-radius: 6px;
  backdrop-filter: blur(4px);
}

/* ---------------- Subtitle / Narration Caption Bar ---------------- */
.hud-caption-bar {
  align-self: center;
  max-width: 600px;
  width: 90%;
  background: rgba(10, 15, 29, 0.88);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 14px;
  padding: 10px 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.3s ease;
}

.caption-wave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 18px;
  flex-shrink: 0;
}

.wave-bar {
  width: 3px;
  height: 100%;
  background: var(--ar-blue);
  border-radius: 2px;
  animation: audioWave 1s ease-in-out infinite;
}

.wave-bar:nth-child(2) { animation-delay: 0.15s; background: var(--ar-red); }
.wave-bar:nth-child(3) { animation-delay: 0.3s; }
.wave-bar:nth-child(4) { animation-delay: 0.45s; background: var(--ar-cyan); }

@keyframes audioWave {
  0%, 100% { transform: scaleY(0.2); }
  50% { transform: scaleY(1); }
}

.caption-wave.paused .wave-bar {
  animation: none;
  transform: scaleY(0.25);
  background: #64748b;
}

.caption-text-wrap {
  flex: 1;
}

.caption-time {
  font-size: 0.68rem;
  font-family: 'Plus Jakarta Sans', monospace;
  color: var(--ar-blue);
  font-weight: 700;
  margin-bottom: 2px;
}

.caption-text {
  font-size: 0.82rem;
  color: #f8fafc;
  line-height: 1.35;
  font-weight: 400;
}

/* ---------------- Bottom HUD Action Controls ---------------- */
.hud-bottombar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  pointer-events: auto;
  padding-bottom: 8px;
}

/* The primary "ดูเพิ่ม" CTA Button */
.btn-learn-more {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 50%, #b91c1c 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 12px 26px;
  border-radius: 30px;
  font-family: 'Prompt', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 6px 25px rgba(239, 68, 68, 0.5), 0 0 15px rgba(255, 255, 255, 0.2);
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.btn-learn-more:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 10px 32px rgba(239, 68, 68, 0.7);
}

.btn-learn-more:active {
  transform: translateY(0) scale(0.98);
}

.btn-hud-secondary {
  background: var(--ar-glass-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--ar-glass-border);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 24px;
  font-family: 'Prompt', sans-serif;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  box-shadow: var(--ar-shadow);
}

.btn-hud-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: #38bdf8;
  transform: translateY(-2px);
}

/* ---------------- 3D Screen Pin Annotations ---------------- */
.ar-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: pointer;
  z-index: 5;
  transition: opacity 0.2s ease;
}

.pin-content {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(56, 189, 248, 0.4);
  backdrop-filter: blur(8px);
  padding: 4px 10px;
  border-radius: 20px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
  font-size: 0.72rem;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
}

.pin-content.pin-red {
  border-color: var(--ar-red);
  color: #fca5a5;
}

.pin-content.pin-blue {
  border-color: var(--ar-cyan);
  color: #38bdf8;
}

.pin-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #38bdf8;
}

.pin-red .pin-dot { background: #ef4444; }

/* ==========================================================================
   "ดูเพิ่ม" Modal Drawer (Progressive Disclosure)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(2, 6, 23, 0.65);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-sheet {
  width: 100%;
  max-width: 680px;
  max-height: 82vh;
  background: linear-gradient(180deg, #131d36 0%, #0c1322 100%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  box-shadow: 0 -15px 40px rgba(0, 0, 0, 0.8), 0 0 30px rgba(56, 189, 248, 0.15);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.3, 1);
  overflow: hidden;
}

.modal-backdrop.open .modal-sheet {
  transform: translateY(0);
}

.sheet-handle {
  width: 40px;
  height: 5px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  margin: 10px auto 4px;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sheet-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sheet-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #ffffff;
}

.sheet-badge {
  font-size: 0.72rem;
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}

.btn-close-modal {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #cbd5e1;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-close-modal:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #ffffff;
  border-color: var(--ar-red);
}

/* Modal Tab Navigation */
.sheet-tabs {
  display: flex;
  padding: 10px 20px 0;
  gap: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(10, 15, 29, 0.4);
}

.tab-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-family: 'Prompt', sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 12px 12px;
  cursor: pointer;
  position: relative;
  transition: color 0.2s ease;
}

.tab-btn.active {
  color: #38bdf8;
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: #38bdf8;
  border-radius: 3px 3px 0 0;
}

/* Modal Content Scrollable Area */
.sheet-body {
  padding: 18px 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 14px;
  animation: fadeIn 0.3s ease;
}

.tab-panel.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Chamber Cards inside Modal */
.detail-card {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.detail-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.icon-blue-bg { background: rgba(6, 182, 212, 0.15); border: 1px solid rgba(6, 182, 212, 0.3); }
.icon-red-bg { background: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.3); }

.detail-card-content h4 {
  font-size: 0.95rem;
  color: #ffffff;
  margin-bottom: 2px;
}

.detail-card-content p {
  font-size: 0.82rem;
  color: #cbd5e1;
  line-height: 1.4;
}

/* Circulation Flow Diagram Box */
.flow-diagram {
  background: rgba(2, 6, 23, 0.6);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.flow-step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
}

.flow-arrow {
  color: var(--ar-blue);
  font-size: 0.8rem;
  padding-left: 14px;
}

/* Quick Facts Grid */
.facts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.fact-item {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 10px 12px;
}

.fact-item strong {
  display: block;
  font-size: 0.82rem;
  color: #38bdf8;
  margin-bottom: 2px;
}

.fact-item span {
  font-size: 0.76rem;
  color: #cbd5e1;
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */
@media (max-width: 600px) {
  .ar-hud {
    padding: 12px 10px;
  }

  .brand-badge .text-title {
    font-size: 0.78rem;
  }

  .hud-caption-bar {
    width: 96%;
    padding: 8px 12px;
    margin-bottom: 8px;
  }

  .caption-text {
    font-size: 0.76rem;
  }

  .btn-learn-more {
    padding: 10px 20px;
    font-size: 0.92rem;
  }

  .scanner-reticle-overlay {
    width: 220px;
    height: 220px;
  }
}
