html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}

#gallery {
  width: 100%;
  padding: 0;
  margin: 0 auto;
}

/* Đảm bảo gallery Masonry layout không bị ảnh hưởng bởi các selector khác */
#gallery.grid-masonry {
  display: block !important;
  position: relative;
}
/* Giữ nguyên width responsive cho .media-item ngoài gallery */
.media-item {
  width: calc(20% - 13px);
  margin-bottom: 16px;
  position: relative;
}

/* Responsive columns */
@media (min-width: 1200px) {
  .media-item {
    width: calc(20% - 13px);
  }
}

@media (min-width: 992px) and (max-width: 1199px) {
  .media-item {
    width: calc(25% - 12px);
  }
}

@media (min-width: 768px) and (max-width: 991px) {
  .media-item {
    width: calc(33.333% - 11px);
  }
}

@media (min-width: 576px) and (max-width: 767px) {
  .media-item {
    width: calc(50% - 8px);
  }
}

@media (max-width: 575px) {
  .media-item {
    width: 100%;
  }
}

.media-item-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  transition: transform 0.3s ease;
  width: 100%;
}

.media-item img,
.media-item video {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  transition: transform 0.3s ease;
}

.media-item:hover .media-item-wrapper {
  transform: scale(1.02);
}

.media-item-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
  padding: 1rem;
  z-index: 1;
}

.media-item:hover .media-item-overlay {
  opacity: 1;
}

/* Global loading spinner */
#globalLoading .loader {
  border: 6px solid #ccc;
  border-top: 6px solid #3498db;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  animation: spin 1s linear infinite;
}

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

#mediaPreview, #globalLoading, #backToTop {
  position: fixed !important;
  z-index: 9999 !important;
}

#mediaPreview {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
#mediaPreviewContent {
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
#mediaPreviewContent img,
#mediaPreviewContent video {
  max-width: 100%;
  max-height: 90vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
}
#closePreview {
  position: absolute;
  top: 20px;
  right: 20px;
  color: white;
  font-size: 24px;
  cursor: pointer;
}
.navBtn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  z-index: 1;
  display: none;
}
#prevBtn { left: 20px; }
#nextBtn { right: 20px; }

@media (min-width: 768px) {
  .navBtn {
    display: block;
  }
}
.line-clamp-2 {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

#readerSection {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  overflow-y: auto;
}

#readerSection .min-h-screen {
  background: white;
  margin: 2rem auto;
  border-radius: 12px;
  overflow: hidden;
}

#readerNav {
  position: sticky;
  bottom: 0;
  top: unset;
  left: 0;
  width: 52%;
  background: white;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  transition: transform 0.3s, opacity 0.3s;
}

#readerNav.hide {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}
#readerNav.show {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

#readerImages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: block;
}
#readerImages img {
  display: block;
  width: auto;
  max-width: 90%;
  height: auto;
  margin: 0 auto 16px auto;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border-radius: 8px;
}

#globalModal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  display: none;
  z-index: 9999;
  align-items: center;
  justify-content: center;
}

#globalModal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

#globalModal > .min-h-screen, #globalModal > div {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
}

#modalContent {
  background: transparent;
  border-radius: 0;
}

/* Image/Video Preview */
#modalContent .relative {
  position: relative;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  padding: 1rem;
}

#modalContent .close-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 20px;
  cursor: pointer;
  z-index: 1;
}

#modalContent img,
#modalContent video {
  max-width: 100%;
  max-height: 80vh;
  display: block;
  margin: 0 auto;
}

/* Reader Modal */
#modalContent.reader-modal {
  background: white;
  border-radius: 0;
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
}

#modalContent.reader-modal .min-h-screen {
  background: white;
  border-radius: 0;
  overflow: auto;
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
}

#modalContent #readerNav {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  /* background: rgba(30,30,30,0.85); */
  color: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  padding: 8px 15px;
  min-width: 320px;
  max-width: 80vw;
  z-index: 1001;
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: center;
  font-size: 1.25rem;
}

#modalContent #readerNav button {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 8px;
}
#modalContent #readerNav button img {
  width: 24px;
  height: 24px;
  max-width: 24px;
  max-height: 24px;
  display: block;
  margin: auto;
}
#modalContent #readerNav select {
  color: #222 !important;
  background: #fff;
  width: 100%;
  text-align: left;
  padding: 0 10px;
  border-radius: 8px;
  margin: 0 8px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
}

#modalContent #readerImages {
  padding: 1rem;
}

#modalContent #readerImages img {
  max-width: 90%;
  height: auto;
  margin: 0 auto;
  display: block;
}

/* Animation */
#globalModal.show {
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Modal Types */
#modalContent.video-modal,
#modalContent.image-modal,
#modalContent.audio-modal,
#modalContent.tiktok-modal {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  padding: 1rem;
  max-width: 90vw;
  max-height: 90vh;
  border: 1px solid #eee;
}

#modalContent.video-modal video,
#modalContent.image-modal img {
  max-width: 100%;
  max-height: 80vh;
  display: block;
  margin: 0 auto;
}

#modalContent.audio-modal audio {
  width: 100%;
  margin: 1rem 0;
}

#modalContent.tiktok-modal {
  width: 100%;
  max-width: 500px;
}

#modalContent .manga-modal {
  overflow-y:auto;
}

#readerImages img {
  max-height: 100%;
  max-width: 90%;
}

.modal-inner {
  background: white;
  border-radius: 18px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  margin: auto;
  width: auto;
  max-height: 100%;
  padding: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* Ebook reader nav luôn ở TOP */
.ebook-nav {
  position: sticky;
  top: 0;
  left: 0;
  width: 100%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  gap: 18px;
  min-height: 54px;
  border-bottom: 1px solid #eee;
}

.ebook-nav select,
.ebook-nav input,
.ebook-nav button {
  margin-right: 8px;
}

.ebook-nav label {
  margin-bottom: 0;
}

@media (max-width: 600px) {
  .ebook-nav {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 7px 5px;
  }
}

/* Đảm bảo readerContent không bị che */
#readerContent {
  margin-top: 0px;
  padding-bottom: 48px;
  background: #fff;
  min-height: 70vh;
}
.bg-yellow-200 { background: #fef08a; transition: background 0.2s; }

/* --- SPEECH PLAYER UI --- */
.speech-player {
  width: 100%;
  margin-top: 10px;
  margin-bottom: 10px;
  gap: 14px;
}
.speech-progress-row {
  width: 100%;
  max-width: 500px;
  margin: 0 auto 4px auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.speech-progress {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.sp-seekbar-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  min-width: 0;
}
.speech-progress input[type=range] {
  width: 100%;
  accent-color: #2563eb;
  height: 4px;
  margin: 0 8px;
}
.speech-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 8px;
}
@media (max-width: 600px) {
  .speech-player {
    gap: 10px;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    box-sizing: border-box;
    display: block;
  }
  .speech-progress-row {
    max-width: 100vw;
    gap: 0;
    margin-bottom: 8px;
    align-items: center;
  }
  .speech-progress {
    max-width: 100vw;
    gap: 6px;
    font-size: 1rem;
    justify-content: center;
    align-items: center;
    width: 100%;
  }
  .sp-seekbar-wrap {
    min-width: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .speech-controls {
    flex-wrap: nowrap;
    gap: 10px;
    margin-top: 0;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 0 8px;
    box-sizing: border-box;
  }
  .speech-controls button,
  .speech-controls input[type=number] {
    font-size: 1.3rem;
    min-width: 36px;
    min-height: 36px;
  }
  .speech-controls > * {
    margin-bottom: 0 !important;
  }
}
.ebook-nav .chapter-nav img,
.speech-controls .speech-speed-btn img,
.speech-controls .speech-ctrl-btn img,
.speech-controls .speech-play-btn img,
.speech-controls .text-xl img {
  width: 35px !important;
  height: 35px !important;
  max-width: 35px !important;
  display: block;
}

.speech-controls .speech-play-btn {
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px #0001;
  transition: background 0.2s;
}
.speech-controls .speech-play-btn:active {
  background: #1d4ed8;
}
.speech-controls input[type=number] {
  width: 40px;
  text-align: center;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
  padding: 2px 4px;
}

/* Popup modal cho speed/timer */
.speed-menu-modal, .timer-menu-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
  opacity: 0;
}
.speed-menu-modal.show, .timer-menu-modal.show {
  display: flex;
  opacity: 1;
  animation: modalFadeIn 0.2s;
}
.speed-menu-content, .timer-menu-content {
  background: #222;
  color: #fff;
  border-radius: 18px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  padding: 32px 38px 18px 38px;
  min-width: 240px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  position: relative;
  animation: popupScaleIn 0.18s;
}
@keyframes popupScaleIn {
  from { transform: scale(0.96); opacity: 0.7; }
  to { transform: scale(1); opacity: 1; }
}
.speed-menu-title, .timer-menu-title {
  font-size: 1.35rem;
  font-weight: bold;
  margin-bottom: 18px;
  text-align: center;
  letter-spacing: 0.01em;
}
.speed-item, .timer-item {
  padding: 13px 0;
  font-size: 1.18rem;
  cursor: pointer;
  border-bottom: 1px solid #333;
  text-align: center;
  transition: background 0.18s, color 0.18s;
  border-radius: 8px 8px 0 0;
}
.speed-item:last-child, .timer-item:last-child {
  border-bottom: none;
}
.speed-item:hover, .timer-item:hover {
  background: #2563eb;
  color: #fff;
}
.speed-item[style*="font-weight: bold"],
.timer-item[style*="font-weight: bold"] {
  background: #2563eb;
  color: #fff;
}
.speed-menu-close, .timer-menu-close {
  margin-top: 18px;
  padding: 10px 0;
  font-size: 1.08rem;
  color: #aaa;
  cursor: pointer;
  text-align: center;
  border-top: 1px solid #333;
  transition: color 0.18s;
  border-radius: 0 0 8px 8px;
}
.speed-menu-close:hover, .timer-menu-close:hover {
  color: #fff;
}

/* --- END SPEECH PLAYER UI --- */

.profile-faker-center {
  max-width: 700px;
  margin: 0 auto;
}

.media-title {
  font-size: 28px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 20px;
}

.media-search-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.media-search-input {
  flex-grow: 1;
  padding: 10px 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
}

.media-search-btn {
  padding: 8px 12px;
  border: none;
  background-color: #3182ce;
  color: white;
  border-radius: 8px;
  cursor: pointer;
}

.media-search-btn:hover {
  background-color: #2b6cb0;
}

.loader {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #3498db;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.media-history-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.media-history-table th,
.media-history-table td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid #eee;
}

.media-history-table th {
  background: #f8fafc;
  font-weight: 600;
  color: #1e293b;
}

.media-history-table tr:last-child td {
  border-bottom: none;
}

.media-history-table tr:hover td {
  background: #f8fafc;
}

.media-history-empty {
  text-align: center;
  padding: 40px;
  color: #64748b;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.nav-icon {
  filter: brightness(0) invert(1); /* This will make the SVG icons white */
}

#modalContent .modal-inner {
  position: relative;
  padding: 0;
  background: transparent;
}

.nav-buttons-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.navBtn {
  pointer-events: auto;
  background: rgba(0,0,0,0.5);
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 11;
  transition: background 0.2s;
  cursor: pointer;
}
.navBtn:hover {
  background: rgba(0,0,0,0.8);
}
#prevBtn { left: 16px; }
#nextBtn { right: 16px; }

/* Đặt các nút prev/next/close sát lề modal */
#modalContent .gallery-nav-btn {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10001;
  width: 48px;
  height: 48px;
  /* background: rgba(0,0,0,0.5); */
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  transition: background 0.2s;
  cursor: pointer;
}
#modalContent .gallery-nav-btn:hover {
  background: rgba(0,0,0,0.8);
}
#modalContent .gallery-prev-btn { left: 24px; }
#modalContent .gallery-next-btn { right: 24px; }
#modalContent .gallery-close-btn {
  position: fixed;
  top: 32px;
  right: 32px;
  left: auto;
  transform: none;
  z-index: 10002;
  width: 40px;
  height: 40px;
  background: rgba(0,0,0,0.5);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: pointer;
}
#modalContent .gallery-close-btn:hover {
  background: rgba(0,0,0,0.8);
}
#backToTop {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 32px;
  height: 32px;
  background: rgba(0,0,0,0.6);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  cursor: pointer;
  transition: background 0.2s;
}
#backToTop:hover {
  background: rgba(0,0,0,0.85);
}
#backToTop img {
  width: 20px;
  height: 20px;
  filter: brightness(0) invert(1);
}

#ebookReaderNav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #e3f0fc;
}

@media (max-width: 600px) {
  #modalContent #readerNav {
    max-width: 98vw;
    min-width: 0;
    padding: 6px 2vw;
    gap: 8px;
  }
  #modalContent #readerNav button {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    border-radius: 6px;
  }
  #modalContent #readerNav button img {
    width: 18px;
    height: 18px;
    max-width: 18px;
    max-height: 18px;
  }
  #modalContent #readerNav select {
    height: 28px;
    min-height: 28px;
    font-size: 0.95rem;
    border-radius: 6px;
    padding: 0 6px;
    margin: 0 4px;
  }
}