/* ============================================
   Mobile Enhancements (max-width: 768px)
   ============================================ */

/* View Page System */
.view-page {
  display: none;
}

.view-page.is-active {
  display: block;
}

@media (min-width: 769px) {
  .view-page {
    display: block;
  }
  
  .view-page.view-home {
    display: none;
  }
  
  .mobile-bottom-nav {
    display: none !important;
  }
}

/* Mobile Bottom Navigation */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  /* Đảm bảo html và body không ảnh hưởng đến fixed positioning */
  html {
    overflow-x: hidden;
  }
  
  body {
    overflow-x: hidden;
    /* Đảm bảo body không có transform ảnh hưởng đến fixed */
    transform: none !important;
  }
  
  .mobile-bottom-nav {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 60px;
    background: rgba(15, 23, 42, 0.96);
    backdrop-filter: blur(12px);
    border-top: 1px solid rgba(148, 163, 184, 0.4);
    display: flex !important;
    align-items: center;
    justify-content: space-around;
    padding: 6px 8px 8px;
    z-index: 9999 !important;
    box-shadow: 0 -4px 12px rgba(15, 23, 42, 0.3);
    /* Đảm bảo luôn hiển thị trên cùng và không bị ảnh hưởng bởi scroll */
    pointer-events: auto;
    /* Đảm bảo fixed positioning hoạt động đúng với viewport */
    margin: 0;
    box-sizing: border-box;
    /* Đảm bảo không bị ảnh hưởng bởi parent transforms */
    transform: none !important;
  }

  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: transparent;
    color: #9ca3af; /* muted gray */
    font-size: 0.72rem;
    cursor: pointer;
    padding: 4px 0;
    transition: color 0.2s ease;
  }

  .mobile-nav-item .mobile-nav-icon {
    width: 26px;
    height: 26px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
    background: transparent;
    transition: background 0.2s ease, box-shadow 0.2s ease;
  }

  .mobile-nav-item .mobile-nav-label {
    font-size: 0.7rem;
    font-weight: 500;
    line-height: 1.2;
    transition: color 0.2s ease;
  }

  /* ACTIVE STATE - Softer, modern color scheme */
  .mobile-nav-item.is-active,
  .mobile-nav-item.bottom-nav-item--active {
    color: #e5f2ff;
    font-weight: 600;
  }

  .mobile-nav-item.is-active .mobile-nav-icon,
  .mobile-nav-item.bottom-nav-item--active .mobile-nav-icon {
    background: radial-gradient(circle at top, #3b82f6, #1d4ed8);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.8);
  }

  .mobile-nav-item.is-active .mobile-nav-label,
  .mobile-nav-item.bottom-nav-item--active .mobile-nav-label {
    color: #e5f2ff;
  }

  .mobile-nav-item:active {
    opacity: 0.7;
  }
}

/* Home View Styles */
@media (max-width: 768px) {
  .view-home {
    /*padding: 16px 16px 80px;  bottom padding for bottom nav */
    min-height: calc(100vh - 60px);
    background: #f3f4f6;
  }

  .home-section {
    margin-bottom: 24px;
  }

  .home-section-title {
    font-size: 13px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .home-card {
    border-radius: 16px;
    padding: 14px 16px;
    background: #ffffff;
    color: #0f172a;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
    border: 1px solid rgba(148, 163, 184, 0.25);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }

  .home-card:active {
    transform: scale(0.98);
  }

  .home-card-label {
    font-size: 10px;
    color: #6b7280;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .home-card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 6px;
    line-height: 1.4;
    color: #111827;
  }

  .home-card-meta {
    font-size: 11px;
    color: #374151;
  }

  .home-topic-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .home-topic-card {
    border-radius: 14px;
    padding: 12px 10px;
    background: #ffffff;
    border: 1px solid rgba(148, 163, 184, 0.35);
    color: #111827;
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: flex-start;
    text-align: left;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  }

  /* Colored left bar for mobile too */
  .home-topic-card::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: #2563eb;
  }

  .home-topic-card[data-topic="news"]::before {
    background: #22c55e;
  }

  .home-topic-card[data-topic="jlpt"]::before {
    background: #2563eb;
  }

  .home-topic-card[data-topic="story"]::before {
    background: #a855f7;
  }

  .home-topic-card[data-topic="mimikara"]::before {
    background: #f97316;
  }

  .home-topic-card:active {
    transform: scale(0.97);
  }

  .home-topic-accent {
    width: 32px;
    height: 3px;
    border-radius: 999px;
    margin-bottom: 2px;
  }

  .home-topic-accent.news {
    background: #22c55e;
  }

  .home-topic-accent.jlpt {
    background: #3b82f6;
  }

  .home-topic-accent.story {
    background: #a855f7;
  }

  .home-topic-accent.mimikara {
    background: #f97316;
  }

  .home-topic-name {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    color: #111827;
  }

  .home-topic-caption {
    font-size: 10px;
    color: #6b7280;
    line-height: 1.4;
  }
}

/* Add bottom padding to main content for mobile bottom nav */
@media (max-width: 768px) {
  .main-view {
    padding-bottom: 70px;
  }

  .view-lesson {
    padding-bottom: 70px;
  }

  .review-panel {
    padding-bottom: 70px;
  }
}

/* Improved Typography for JP/VI on Mobile */
@media (max-width: 768px) {
  .line .jp {
    font-size: 17px !important;
    line-height: 1.7 !important;
    color: #1f2937 !important;
    margin-bottom: 6px;
  }

  .line .vi {
    font-size: 14px !important;
    line-height: 1.6 !important;
    color: #475569 !important;
    margin-top: 4px;
  }

  .line {
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.98) !important;
    border: 1px solid rgba(148, 163, 184, 0.25);
    box-shadow: 0 4px 12px rgba(148, 163, 184, 0.15);
  }

  .line.active {
    background: rgba(59, 130, 246, 0.12) !important;
    border-color: rgba(59, 130, 246, 0.4);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.2);
  }
}

/* Optimize Recording Controls and Line Controls for Mobile */
@media (max-width: 768px) {
  .recording-controls {
    margin-top: 0 !important; /* No margin when inside line-controls */
    padding: 3px 8px !important; /* Reduced vertical padding: 3px vertical, 8px horizontal */
    border-radius: 6px !important;
    min-width: fit-content !important; /* Allow container to fit content */
    gap: 2px !important; /* Small gap between status and buttons */
  }

  .recording-status {
    font-size: 0.65rem !important; /* Smaller font */
    margin-bottom: 0 !important; /* No margin, use gap from parent */
    margin-top: 0 !important;
    padding: 0 !important;
    line-height: 1.1 !important; /* Tighter line height */
  }

  .recording-buttons {
    gap: 6px !important; /* Increased gap for better spacing */
    flex-wrap: wrap !important;
    min-width: fit-content !important; /* Allow buttons to fit properly */
  }

  .recording-controls .icon-btn {
    padding: 4px 8px !important; /* Match line-btn mobile padding */
    font-size: 0.75rem !important; /* Match line-btn mobile font-size */
    border-radius: 4px !important; /* Match line-btn mobile border-radius */
    height: 28px !important; /* Match line-btn mobile height */
    min-height: 28px !important;
  }

  .recording-controls .btn-play-original,
  .recording-controls .btn-play-user {
    min-width: 65px !important; /* Slightly wider for text */
    width: auto !important; /* Allow width to fit content */
    padding: 4px 8px !important; /* Match line-btn mobile padding */
    height: 28px !important; /* Match line-btn mobile height */
    font-size: 0.75rem !important; /* Match line-btn mobile font-size */
  }

  .recording-controls .btn-record,
  .recording-controls .btn-stop {
    padding: 4px 8px !important; /* Match line-btn mobile padding */
    font-size: 0.75rem !important; /* Match line-btn mobile font-size */
    height: 28px !important; /* Match line-btn mobile height */
  }

  /* Line Controls Optimization */
  .line-controls {
    gap: 4px !important;
    margin-top: 8px !important;
    padding-top: 8px !important;
    flex-wrap: wrap !important;
  }

  .line-btn {
    padding: 4px 8px !important;
    font-size: 0.75rem !important;
    min-width: 32px !important;
    height: 28px !important;
    border-radius: 4px !important;
  }

  .line-btn-furigana,
  .line-btn-vi {
    min-width: 55px !important;
    font-size: 0.65rem !important;
    padding: 4px 6px !important;
  }

  .line-btn-star,
  .line-btn-note,
  .line-btn-preview {
    min-width: 32px !important;
    font-size: 0.85rem !important;
    padding: 4px 6px !important;
  }

  .line-btn-repeat,
  .line-btn-loop,
  .line-btn-next {
    min-width: 32px !important;
    font-size: 0.85rem !important;
  }

  /* Very small screens - hide text labels, show only icons */
  @media (max-width: 480px) {
    .line-btn-furigana .chip-text,
    .line-btn-vi .chip-text {
      display: none;
    }

    .line-btn-furigana,
    .line-btn-vi {
      min-width: 36px !important;
      padding: 4px 6px !important;
    }

    .recording-controls .icon-btn {
      padding: 4px 6px !important; /* Match line-btn very small screen */
      font-size: 0.75rem !important;
      height: 28px !important;
    }

    .recording-controls .btn-play-original,
    .recording-controls .btn-play-user {
      min-width: 55px !important;
      width: auto !important;
      padding: 4px 6px !important;
      height: 28px !important;
    }

    .recording-controls .btn-record,
    .recording-controls .btn-stop {
      padding: 4px 6px !important;
      height: 28px !important;
    }
  }
}

/* Optimize Control Group Toggles for Mobile */
@media (max-width: 768px) {
  .control-group.toggles {
    gap: 6px !important;
    margin-top: 2px !important;
    flex-wrap: wrap;
  }

  button.toggle-chip {
    padding: 4px 8px !important;
    border-radius: 12px !important;
    font-size: 0.75rem !important;
    gap: 4px !important;
    min-height: 32px;
  }

  button.toggle-chip .chip-icon {
    width: 20px !important;
    height: 20px !important;
    border-radius: 8px !important;
    font-size: 0.7rem !important;
  }

  button.toggle-chip .chip-text {
    font-size: 0.7rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80px;
  }

  /* Hide text on very small screens, show only icon */
  @media (max-width: 480px) {
    button.toggle-chip .chip-text {
      display: none;
    }

    button.toggle-chip {
      padding: 6px 8px !important;
      min-width: 36px;
      justify-content: center;
    }

    button.toggle-chip .chip-icon {
      width: 22px !important;
      height: 22px !important;
    }
  }

  .control-group {
    gap: 6px !important;
  }
}

/* Enhanced Lesson Cards on Mobile */
@media (max-width: 768px) {
  .lesson-chip {
    border-radius: 14px !important;
    padding: 12px 14px !important;
    background: radial-gradient(circle at top left, rgba(37, 99, 235, 0.35), #020617) !important;
    border: 1px solid rgba(148, 163, 184, 0.4) !important;
    color: #e5e7eb !important;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }

  .lesson-chip:active {
    transform: scale(0.98);
  }

  .lesson-chip-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
  }

  .lesson-chip-name {
    font-size: 15px !important;
    font-weight: 600 !important;
    color: #e5e7eb !important;
    line-height: 1.4;
  }

  .lesson-chip-meta-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: #cbd5e1;
    flex-wrap: wrap;
  }

  .lesson-badge-level {
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.7);
    font-size: 10px;
    font-weight: 600;
    color: #cbd5e1;
  }

  .lesson-chip-tags {
    margin-top: 4px;
  }
}


