/**
 * ============================================================================
 * TaijiFlow AI - App Styles
 * ============================================================================
 *
 * Stylesheet สำหรับ App Page (app.html)
 * Imports base.css for shared styles
 *
 * ============================================================================
 */

/* Import base styles */
@import url("base.css");

/* =============================================================================
   APP PAGE SPECIFIC STYLES
   ============================================================================= */

/* 
 * Theme Background Colors
 * 
 * JS toggle uses:
 * - Dark mode: body.dark + bg-gray-900 class
 * - Light mode: no dark class + bg-f3f4f6 class
 * 
 * We use body.dark selector to override Tailwind classes
 */

/* Dark mode (when body has 'dark' class) */
body.dark {
  background-color: #000 !important;
  color: #fff;
}

/* Light mode (default, when body doesn't have 'dark' class) */
body:not(.dark) {
  background-color: #f8fafc !important;
  color: #1e293b;
}

/* Main card - Dark mode */
body.dark #main-card {
  background: rgba(168, 85, 247, 0.1) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  border-radius: 16px;
}

/* Main card - Light mode */
body:not(.dark) #main-card {
  background: rgba(255, 255, 255, 0.95) !important;
  border: 1px solid rgba(168, 85, 247, 0.2) !important;
  border-radius: 16px;
}

/* --- Notification System --- */
.notification {
  transition:
    opacity 0.3s ease-in-out,
    transform 0.3s ease-in-out;
  transform: translateX(100%);
  opacity: 0;
}

.notification.show {
  transform: translateX(0);
  opacity: 1;
}

/* --- Canvas Styling --- */
canvas {
  border-radius: var(--radius-md);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* pulse-btn animation is now in base.css */

/* --- Fullscreen Handling --- */
/* ปรับให้รองรับหลาย Browser Engine */
canvas:fullscreen {
  object-fit: contain;
  background: black;
  -webkit-transform: scaleX(-1);
  -moz-transform: scaleX(-1);
  -ms-transform: scaleX(-1);
  transform: scaleX(-1);
}

canvas:-webkit-full-screen {
  object-fit: contain;
  background: black;
  -webkit-transform: scaleX(-1);
  transform: scaleX(-1);
}

canvas:-moz-full-screen {
  object-fit: contain;
  background: black;
  -moz-transform: scaleX(-1);
  transform: scaleX(-1);
}

/* --- Canvas Container Fullscreen (ใช้ container เพื่อให้ overlay แสดงด้วย) --- */
.canvas-container:fullscreen {
  width: 100vw;
  height: 100vh;
  background: black;
}

.canvas-container:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  background: black;
}

.canvas-container:-moz-full-screen {
  width: 100vw;
  height: 100vh;
  background: black;
}

/* --- App Title Purple Gradient --- */
#app-title {
  background: linear-gradient(135deg, #a855f7, #6366f1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Dark mode: slightly lighter purple */
.dark #app-title {
  background: linear-gradient(135deg, #c084fc, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* --- Instructions Box Purple Theme --- */
/* Default (Dark Mode) */
.instructions-box {
  background-color: rgba(147, 51, 234, 0.2);
  border: 1px solid rgba(147, 51, 234, 0.4);
  color: #e9d5ff;
}

.instructions-box h3,
.instructions-box strong {
  color: #c4b5fd;
}

/* Light Mode Override */
body:not(.dark) .instructions-box,
body.light .instructions-box {
  background-color: rgba(147, 51, 234, 0.1);
  border: 1px solid rgba(147, 51, 234, 0.3);
  color: #581c87;
}

body:not(.dark) .instructions-box h3,
body:not(.dark) .instructions-box strong,
body.light .instructions-box h3,
body.light .instructions-box strong {
  color: #7c3aed;
}

/* --- Canvas Container (Full Width Video) --- */
.canvas-container {
  position: relative;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16/9;
  margin: 0 auto;
}

.canvas-container video,
.canvas-container canvas:not(#instructor-thumbnail) {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
  object-fit: contain; /* เปลี่ยนจาก cover เป็น contain เพื่อรักษา aspect ratio */
}

/* Normal View (Undo Mirror) */
.canvas-container.normal-view video,
.canvas-container.normal-view canvas:not(#instructor-thumbnail) {
  transform: scaleX(1);
}

/* --- Status Dot (Recording Indicator) --- */
.status-dot {
  height: 12px;
  width: 12px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.recording {
  background-color: #ef4444;
  animation: status-pulse 1s infinite;
}

.status-dot.idle {
  background-color: #9ca3af;
}

@keyframes status-pulse {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 1;
  }
}

/* --- Countdown Overlay --- */
.countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 30;
  border-radius: 0.5rem;
}

.countdown-number {
  font-size: 10rem;
  font-weight: bold;
  color: white;
  animation: status-pulse 1s infinite;
}

/* --- Instructor Thumbnail (มุมขวาบน) --- */
#instructor-thumbnail {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 100%; /* 20% ของ parent container */
  min-width: 150px;
  max-width: 400px;
  height: auto;
  aspect-ratio: 16/9; /* รักษาสัดส่วนเหมือนวิดีโอหลัก */
  z-index: 40;
  border-radius: 8px;
  background: transparent;
  transform: none; /* ไม่ต้อง mirror */
  mix-blend-mode: lighten; /* ทำให้พื้นดำโปร่งใส */
}

#instructor-thumbnail.hidden {
  display: none;
}

/* =============================================================================
   RESPONSIVE - Tablet Support
   ============================================================================= */

/* Tablet Landscape (1024px and below) */
@media (max-width: 1024px) {
  /* Main container */
  #main-card {
    padding: 1rem;
    max-width: 100%;
  }

  /* App title */
  #app-title {
    font-size: 1.5rem;
    text-align: center;
  }

  /* Top bar - wrap controls */
  #main-card > div:first-of-type {
    flex-direction: column;
    gap: 0.75rem;
  }

  /* Dropdowns row */
  #main-card .flex.gap-4 {
    flex-wrap: wrap;
    justify-content: center;
  }

  /* Instructor thumbnail smaller */
  #instructor-thumbnail {
    max-width: 200px;
    min-width: 120px;
  }

  /* Countdown number smaller */
  .countdown-number {
    font-size: 6rem;
  }
}

/* Tablet Portrait (768px and below) */
@media (max-width: 768px) {
  /* Body padding */
  body {
    padding: 0.5rem;
  }

  /* Main card */
  #main-card {
    padding: 0.75rem;
    border-radius: 0.5rem;
  }

  /* App title */
  #app-title {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
  }

  /* Dropdown selects */
  select {
    padding: 0.5rem;
    font-size: 0.875rem;
  }

  /* Settings buttons */
  button {
    padding: 0.5rem 0.75rem;
  }

  /* Instructor thumbnail */
  #instructor-thumbnail {
    max-width: 150px;
    min-width: 100px;
    top: 5px;
    right: 5px;
  }

  /* Countdown number */
  .countdown-number {
    font-size: 4rem;
  }

  /* Overlays text */
  #start-overlay h2 {
    font-size: 1.25rem;
  }

  #start-overlay p {
    font-size: 0.875rem;
  }

  /* Training controls (bottom left) */
  .training-controls {
    left: 5px;
    bottom: 5px;
  }
}

/* Small Tablet / Large Phone (640px and below) */
@media (max-width: 640px) {
  /* Stack dropdowns vertically */
  #main-card .flex.gap-4.flex-wrap {
    flex-direction: column;
    width: 100%;
  }

  /* Full width dropdowns */
  select {
    width: 100%;
  }

  /* Settings buttons - smaller */
  #main-card .flex.gap-2 {
    justify-content: center;
  }

  /* Instructor thumbnail even smaller */
  #instructor-thumbnail {
    max-width: 120px;
    min-width: 80px;
  }

  /* Hide some overlay text on very small screens */
  #start-overlay .space-y-3 {
    max-width: 90%;
  }
}

/* --- Quick Fix: Rules Menu Visibility (iPad/Mobile) --- */
#rules-menu {
  /* Ensure scrollbar space */
  scrollbar-gutter: stable;
  /* Visual cue: Border highlight */
  border: 1px solid rgba(107, 114, 128, 0.5);
}

/* Force visible scrollbar for Webkit (Chrome/Safari/iPad) */
#rules-menu::-webkit-scrollbar {
  width: 6px; /* Width of vertical scrollbar */
  display: block; /* Force display */
}

#rules-menu::-webkit-scrollbar-track {
  background: rgba(31, 41, 55, 0.5); /* Dark background */
  border-radius: 0 4px 4px 0;
}

#rules-menu::-webkit-scrollbar-thumb {
  background: rgba(156, 163, 175, 0.6); /* Visible gray thumb */
  border-radius: 4px;
}

#rules-menu::-webkit-scrollbar-thumb:hover {
  background: rgba(209, 213, 219, 0.8); /* Lighter on hover */
}

/* =============================================================================
   SIDE-BY-SIDE MODE
   ============================================================================= */

/* Main Container when Side-by-Side is active */
body.side-by-side-mode .canvas-container {
  display: flex !important;
  flex-direction: row !important;
  width: 100% !important;
  max-width: 100% !important;
  aspect-ratio: auto !important; /* Allow height to adjust */
  height: 80vh; /* Fixed height for splitting */
  background: black;
  gap: 4px; /* Small gap between videos */
}

/* 1. Instructor Video (Hidden by default, shown in Side-by-Side) */
/* We assume a <video id="instructor-video"> is injected or enabled */
body.side-by-side-mode #instructor-video-container {
  display: block !important; /* Show it */
  position: relative !important;
  width: 50% !important;
  height: 100% !important;
  overflow: hidden;
}

body.side-by-side-mode #instructor-video-container video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* 2. User Canvas (Right Side) */
body.side-by-side-mode canvas#output_canvas {
  position: relative !important;
  width: 50% !important;
  height: 100% !important;
  left: auto !important;
  top: auto !important;
  transform: scaleX(-1); /* Keep mirror effect for user */
  object-fit: contain;
}

/* Hide Instructor Thumbnail in Side-by-Side (Redundant) */
body.side-by-side-mode #instructor-thumbnail {
  display: none !important;
}

/* Ensure controls overlay sits on top correctly */
body.side-by-side-mode #feedback-overlay,
body.side-by-side-mode #debug-overlay {
  z-index: 50;
}
