/**
 * ============================================
 * DDL-MOD: FLASHCARD STYLES - MOBILE-ONLY
 * ============================================
 * File: flashcard-style.css
 * Version: 4.0 - Mobile-First Architecture
 * Description: Mobile-optimized flashcard styles với CSS Nesting,
 * màu HSL, và các kỹ thuật CSS hiện đại cho mobile devices.
 */

/* ============================================
   VARIABLE DEFINITIONS (CUSTOM PROPERTIES)
   ============================================ */
:root {
  /* NÂNG CẤP: Hệ thống màu sắc với HSL - Light Mode */
  --fc-primary-h: 244;
  --fc-primary-s: 82%;
  --fc-secondary-h: 227;
  --fc-secondary-s: 70%;
  --fc-accent-blue-h: 212;
  --fc-accent-blue-s: 71%;
  --fc-neutral-h: 220;
  --fc-neutral-s: 15%;

  /* NÂNG CẤP: Chi tiết hóa các biến để dễ quản lý hơn */
  --fc-border-radius: 20px;
  --fc-border-radius-sm: 16px;
  --fc-shadow-color: hsl(var(--fc-neutral-h), 30%, 10%);
  --fc-shadow-elevation-low: 0 4px 12px rgba(0, 0, 0, 0.1);
  --fc-shadow-elevation-medium: 0 8px 28px rgba(0, 0, 0, 0.15);
  --fc-shadow-elevation-high: 0 12px 32px rgba(0, 0, 0, 0.2);
  --fc-transition-duration: 0.3s;
  --fc-transition-timing: ease;
  --fc-flip-duration: 0.8s;

  /* NÂNG CẤP: Kích thước linh hoạt với clamp() */
  --fc-width: 420px;
  --fc-height: 300px;
  --fc-title-font-size: 2.2rem;
  --fc-subtitle-font-size: 1rem;

  /* Colors - Light Mode */
  --fc-front-bg-gradient: linear-gradient(
    135deg,
    hsl(var(--fc-secondary-h), var(--fc-secondary-s), 97%) 0%,
    hsl(var(--fc-secondary-h), var(--fc-secondary-s), 94%) 100%
  );
  --fc-front-border-color: hsl(var(--fc-primary-h), var(--fc-primary-s), 90%);
  --fc-front-overlay-gradient: linear-gradient(
    135deg,
    rgba(99, 102, 241, 0.08) 0%,
    rgba(147, 51, 234, 0.05) 100%
  );
  --fc-front-title-color: hsl(var(--fc-primary-h), var(--fc-primary-s), 40%);
  --fc-front-subtitle-color: hsl(var(--fc-primary-h), var(--fc-primary-s), 65%);
  --fc-front-shadow: var(--fc-shadow-elevation-low);
  --fc-front-hover-shadow: var(--fc-shadow-elevation-medium);

  --fc-back-bg-gradient: linear-gradient(
    135deg,
    hsl(var(--fc-accent-blue-h), var(--fc-accent-blue-s), 60%) 0%,
    hsl(var(--fc-accent-blue-h), var(--fc-accent-blue-s), 50%) 100%
  );
  --fc-back-text-color: #ffffff;
  --fc-back-overlay-gradient: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.08) 0%,
    rgba(255, 255, 255, 0.03) 100%
  );
  --fc-back-shadow: var(--fc-shadow-elevation-low);
  --fc-back-hover-shadow: var(--fc-shadow-elevation-medium);
  --fc-back-title-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);

  --fc-controls-bg: linear-gradient(
    135deg,
    hsl(var(--fc-neutral-h), var(--fc-neutral-s), 98%) 0%,
    hsl(var(--fc-neutral-h), var(--fc-neutral-s), 90%) 100%
  );
  --fc-controls-border-color: hsl(
    var(--fc-neutral-h),
    var(--fc-neutral-s),
    90%
  );
  --fc-controls-shadow: var(--fc-shadow-elevation-medium);
  --fc-controls-toggle-bg: linear-gradient(
    135deg,
    #ffffff 0%,
    hsl(var(--fc-neutral-h), var(--fc-neutral-s), 95%) 100%
  );
  --fc-controls-toggle-btn-color: hsl(
    var(--fc-neutral-h),
    var(--fc-neutral-s),
    50%
  );
  --fc-controls-toggle-btn-hover-bg: rgba(99, 102, 241, 0.1);
  --fc-controls-toggle-btn-active-bg: linear-gradient(
    135deg,
    hsl(var(--fc-primary-h), 80%, 70%) 0%,
    hsl(280, 50%, 60%) 100%
  );
  --fc-controls-toggle-btn-active-color: white;
}

/* ============================================
       DARK MODE VARIABLE OVERRIDES
       ============================================ */
[data-bs-theme="dark"] {
  /* NÂNG CẤP: Hệ thống màu sắc với HSL - Dark Mode */
  --fc-shadow-color: hsl(var(--fc-neutral-h), 30%, 0%);

  --fc-front-bg-gradient: linear-gradient(
    135deg,
    hsl(var(--fc-primary-h), 50%, 20%) 0%,
    hsl(var(--fc-primary-h), 50%, 25%) 100%
  );
  --fc-front-border-color: hsl(var(--fc-primary-h), var(--fc-primary-s), 40%);
  --fc-front-title-color: hsl(var(--fc-primary-h), var(--fc-primary-s), 90%);
  --fc-front-subtitle-color: hsl(var(--fc-primary-h), var(--fc-primary-s), 80%);

  --fc-back-bg-gradient: linear-gradient(
    135deg,
    hsl(var(--fc-accent-blue-h), 60%, 30%) 0%,
    hsl(var(--fc-accent-blue-h), 60%, 25%) 100%
  );
  --fc-back-title-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);

  --fc-controls-bg: linear-gradient(
    135deg,
    hsl(var(--fc-neutral-h), 15%, 20%) 0%,
    hsl(var(--fc-neutral-h), 15%, 10%) 100%
  );
  --fc-controls-border-color: hsl(var(--fc-neutral-h), 15%, 30%);
  --fc-controls-toggle-bg: linear-gradient(
    135deg,
    hsl(var(--fc-neutral-h), 15%, 20%) 0%,
    hsl(var(--fc-neutral-h), 15%, 10%) 100%
  );
  --fc-controls-toggle-btn-color: hsl(var(--fc-neutral-h), 15%, 70%);
  --fc-controls-toggle-btn-hover-bg: rgba(99, 102, 241, 0.15);
}

/* ============================================
       FLASHCARD CORE STYLES
       ============================================ */
.flashcard {
  -webkit-perspective: 1200px;
  perspective: 1200px;
  cursor: pointer;
  height: var(--fc-height);
  max-width: var(--fc-width);
  -webkit-tap-highlight-color: transparent;
  margin: 1rem auto; /* NÂNG CẤP: 'auto' để tự căn giữa */
  border-radius: var(--fc-border-radius);
  overflow: hidden;
  box-shadow: var(--fc-front-shadow);
  position: relative;
  transition: all var(--fc-transition-duration) var(--fc-transition-timing);

  /* NÂNG CẤP: CSS Nesting cho pseudo-elements */
}

.flashcard::after {
  content: "👆 Tap to flip";
  position: absolute;
  bottom: -2rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: #6c757d;
  opacity: 0.7;
  font-weight: 500;
  pointer-events: none;
  transition: opacity var(--fc-transition-duration) ease;
}

.flashcard:hover::after {
  opacity: 1;
}

.flashcard.is-flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard.is-flipped::after {
  content: "👆 Tap to flip back";
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform var(--fc-flip-duration) var(--fc-transition-timing);
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  border-radius: inherit; /* NÂNG CẤP: Kế thừa border-radius từ cha */
}

/* Common styles for both front and back faces */
.flashcard-front,
.flashcard-back {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0; /* NÂNG CẤP: Dùng 'inset' thay cho top, left, width, height */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1.5rem;
  border-radius: inherit;
  transition: all var(--fc-transition-duration) var(--fc-transition-timing);
  overflow: hidden;

  /* NÂNG CẤP: CSS Nesting */
}

.flashcard-front::before,
.flashcard-back::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: inherit;
  pointer-events: none;
}

/* ============================================
       FLASHCARD FRONT SIDE
       ============================================ */
.flashcard-front {
  background: var(--fc-front-bg-gradient);
  border: 2px solid var(--fc-front-border-color);
  box-shadow: var(--fc-shadow-elevation-low);
}

.flashcard-front::before {
  background: var(--fc-front-overlay-gradient);
}

.flashcard-front:hover {
  box-shadow: var(--fc-front-hover-shadow);
  transform: translateY(-2px);
}

.flashcard-front .card-title {
  font-size: var(--fc-title-font-size);
  font-weight: 700;
  color: var(--fc-front-title-color);
  text-shadow: 0 2px 4px rgba(99, 102, 241, 0.1);
  margin-bottom: 0.75rem;
  line-height: 1.3;
  z-index: 2;
}

.flashcard-front .card-subtitle {
  font-size: var(--fc-subtitle-font-size);
  color: var(--fc-front-subtitle-color);
  font-weight: 600;
  opacity: 0.8;
  z-index: 2;
}

/* ============================================
       FLASHCARD BACK SIDE
       ============================================ */
.flashcard-back {
  transform: rotateY(180deg);
  background: var(--fc-back-bg-gradient);
  color: var(--fc-back-text-color);
  justify-content: space-between;
  box-shadow: var(--fc-shadow-elevation-low);
}

.flashcard-back::before {
  background: var(--fc-back-overlay-gradient);
}

.flashcard-back:hover {
  box-shadow: var(--fc-back-hover-shadow);
  transform: translateY(-2px) rotateY(180deg);
}

.flashcard-back .main-content-back {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.flashcard-back .main-content-back .card-title {
  font-size: var(--fc-title-font-size);
  font-weight: 700;
  text-shadow: var(--fc-back-title-shadow);
  margin-bottom: 0.75rem;
  line-height: 1.3;
  z-index: 2;
}

.flashcard-back .main-content-back .card-subtitle {
  font-size: var(--fc-subtitle-font-size);
  opacity: 0.9;
  font-weight: 500;
  z-index: 2;
}

/* ============================================
       FLASHCARD INDICATORS & CONTROLS
       ============================================ */
.flashcard-progress {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  overflow: hidden;
  z-index: 3;
}

.flashcard-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #51cf66, #40c057);
  border-radius: 4px;
  transition: width var(--fc-transition-duration) ease;
}

.flashcard-counter {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.1);
  color: #ffffff;
  padding: 0.25rem 0.75rem;
  border-radius: 99px; /* NÂNG CẤP: Dùng giá trị lớn để luôn tròn */
  font-size: 0.8rem;
  font-weight: 600;
  z-index: 3;
}

/* ============================================
       SRS FEEDBACK SYSTEM
       ============================================ */
.srs-feedback {
  display: flex;
  justify-content: space-around;
  gap: 10px;
  width: 100%;
  padding-top: 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  margin-top: auto; /* NÂNG CẤP: Đẩy xuống cuối */
  z-index: 3;
}

.srs-btn {
  flex-grow: 1;
  border: none;
  border-radius: 12px;
  padding: 0.875rem 0.5rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: #fff;
  cursor: pointer;
  transition: all var(--fc-transition-duration) var(--fc-transition-timing);
  position: relative;
  overflow: hidden;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
  text-transform: uppercase;
  letter-spacing: 0.3px;

  /* NÂNG CẤP: CSS Nesting */
}

.srs-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s;
}

.srs-btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.srs-btn:hover::before {
  left: 100%;
}

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

.srs-btn.srs-hard {
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
}

.srs-btn.srs-good {
  background: linear-gradient(135deg, #51cf66 0%, #40c057 100%);
}

.srs-btn.srs-easy {
  background: linear-gradient(135deg, #74c0fc 0%, #339af0 100%);
}

/* ============================================
       FLASHCARD CONTROLS SECTION
       ============================================ */
.flashcard-controls-section {
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 16px;
  padding: 1rem;
  margin: 0.5rem;
  margin-bottom: 1rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  z-index: 10;
  backdrop-filter: blur(10px);
}

.flashcard-mode-section {
  margin-bottom: 0.75rem;
}

.mode-toggle-container {
  display: flex;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  padding: 0.4rem;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.mode-toggle-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.75rem 1rem;
  border: none;
  background: transparent;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  color: #64748b;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
}

.mode-toggle-btn.active {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
  transform: translateY(-1px);
  font-weight: 700;
}

.mode-toggle-btn:hover:not(.active) {
  color: #374151;
  background: rgba(99, 102, 241, 0.1);
  transform: translateY(-1px);
}

.flashcard-progress-section {
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.progress-info {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

/* ============================================
       CARD ACTIONS & FURIGANA
       ============================================ */
.card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  display: flex;
  gap: 5px;
  align-items: center; /* Căn chỉnh các nút theo chiều dọc */

  .btn {
    /* NÂNG CẤP: CSS Nesting */
    padding: 0.25rem 0.5rem;
    font-size: 1rem;
    line-height: 1.5;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    color: #6366f1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
  }

  .btn:hover {
    background: #6366f1;
    color: white;
    transform: scale(1.1);
  }
}

rt {
  font-size: 0.7em;
}

/* ============================================
       MOBILE RESPONSIVE STYLES (Simplified by clamp())
       ============================================ */
@media (max-width: 480px) {
  /* NÂNG CẤP: Chỉ giữ lại những thay đổi thực sự cần thiết cho mobile
       vì nhiều thứ đã được xử lý bởi clamp() */

  :root {
    --fc-border-radius: 16px;
    --fc-border-radius-sm: 12px;
  }

  .flashcard-controls-section,
  .flashcard {
    margin-left: 0.75rem;
    margin-right: 0.75rem; /* NÂNG CẤP: Dùng logical property */
  }

  .flashcard-controls-section {
    padding: 0.75rem;
    margin: 0.25rem;
    margin-bottom: 0.75rem;
  }

  .mode-toggle-btn {
    padding: 0.6rem 0.8rem;
    font-size: 0.85rem;
  }

  .progress-info {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
  }

  .srs-feedback {
    gap: 8px;
    padding-top: 1rem;
    margin-top: 1rem;
  }

  .srs-btn {
    padding: 0.75rem 0.4rem;
    font-size: 0.85rem;
    border-radius: 10px;
  }
}
