* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Segoe UI", sans-serif;
}

body {
  background: #f9f9f9;
  color: #222;
}

/* ===== Navbar ===== */
.navbar {
  background-color: #e53935;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: white;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.navbar.scrolled {
  transform: translateY(-100%);
}

.navbar .logo {
  font-size: 20px;
  font-weight: bold;
  transition: transform 0.3s ease;
}

.navbar .logo:hover {
  transform: scale(1.05);
}

.navbar .menu {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.navbar .menu a {
  color: white;
  text-decoration: none;
  font-size: 14px;
  position: relative;
  transition: color 0.3s ease;
}

.navbar .menu a::after {
  content: '';
  position: absolute;
  width: 0;
  height: 2px;
  bottom: -4px;
  left: 0;
  background-color: white;
  transition: width 0.3s ease;
}

.navbar .menu a:hover::after {
  width: 100%;
}

.navbar .menu a:hover {
  color: #ffebee;
}

.navbar .menu-toggle {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
}

/* ===== Search Form ===== */
.search-form {
  display: flex;
  align-items: center;
  flex: 1;
  margin: 0 10px;
}

.search-form input {
  padding: 8px;
  width: 100%;
  max-width: 300px;
  border-radius: 4px 0 0 4px;
  border: 1px solid #ccc;
  border-right: none;
}

.search-form .search-btn {
  padding: 8px 12px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.3s ease;
}

.search-form .search-btn:hover {
  background-color: #0056b3;
  transform: scale(1.05);
}

/* ===== Admin Navigation Menu ===== */
.admin-nav {
  background-color: #f1f1f1;
  padding: 10px 20px;
  display: flex;
  gap: 15px;
  border-bottom: 1px solid #ddd;
  position: sticky;
  top: 60px;
  z-index: 900;
}

.admin-nav a {
  text-decoration: none;
  color: #333;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 4px;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.admin-nav a:hover {
  background-color: #e53935;
  color: white;
}

.admin-nav a.active {
  background-color: #e53935;
  color: white;
  font-weight: bold;
}

/* ===== Sidebar (Left) ===== */
.sidebar {
  width: 200px;
  background-color: #f1f1f1;
  padding: 20px;
  height: calc(100vh - 60px);
  position: sticky;
  top: 60px;
  overflow-y: auto;
  transition: transform 0.3s ease;
}

.sidebar h3 {
  margin-bottom: 10px;
  color: #d32f2f;
  font-size: 15px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 4px;
  transition: color 0.3s ease;
}

.sidebar ul {
  list-style: none;
  margin-bottom: 20px;
}

.sidebar ul li {
  margin: 8px 0;
  transform: translateX(0);
  transition: transform 0.3s ease, color 0.3s ease;
}

.sidebar ul li:hover {
  transform: translateX(8px);
}

.sidebar ul li a {
  text-decoration: none;
  color: #333;
  font-size: 14px;
}

.sidebar ul li a:hover {
  color: #e53935;
}

/* ===== Right Sidebar ===== */
.right-sidebar {
  width: 250px;
  background-color: #f1f1f1;
  padding: 20px;
  height: calc(100vh - 60px);
  position: sticky;
  top: 60px;
  overflow-y: auto;
}

.right-sidebar h3 {
  margin-bottom: 10px;
  color: #d32f2f;
  font-size: 15px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 4px;
}

.right-sidebar ul {
  list-style: none;
  margin-bottom: 20px;
}

.right-sidebar ul li.rank-item {
  margin: 8px 0;
  transition: transform 0.3s ease;
}

.right-sidebar ul li a {
  text-decoration: none;
  color: #333;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
  border-radius: 4px;
  transition: background-color 0.3s ease, transform 0.3s ease;
}

.right-sidebar ul li a:hover {
  background-color: #e5e7eb;
  transform: translateX(4px);
}

.right-sidebar .rank-number {
  width: 20px;
  font-size: 18px;
  font-weight: bold;
  color: #7c3aed;
  text-align: center;
  margin-top: 4px;
  flex-shrink: 0;
}

.right-sidebar .rank-image {
  width: 48px;
  height: 64px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.right-sidebar ul li a:hover .rank-image {
  transform: scale(1.05);
}

.right-sidebar .rank-info {
  width: 154px;
  flex-shrink: 0;
}

.right-sidebar .rank-title {
  font-size: 14px;
  font-weight: medium;
  color: #374151;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.right-sidebar .rank-views {
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
}

.right-sidebar ul li a:hover .rank-title,
.right-sidebar ul li a:hover .rank-views {
  color: #e53935;
}

/* ===== Layout Container ===== */
.container {
  display: flex;
}

.content {
  flex: 1;
  margin-left: 200px;
  margin-right: 250px;
  padding: 24px;
  margin-top: 60px;
  transition: margin 0.3s ease;
}

/* ===== Story Cards ===== */
.section-title {
  font-size: 20px;
  margin-bottom: 16px;
  color: #333;
  position: relative;
}

.section-title::after {
  content: '';
  position: absolute;
  width: 50px;
  height: 3px;
  background-color: #e53935;
  bottom: -8px;
  left: 0;
  transition: width 0.3s ease;
}

.section-title:hover::after {
  width: 100px;
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  position: relative;
  z-index: 1;
}

.story-card {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  min-height: 280px;
  text-align: center;
  position: relative;
  z-index: 1;
}

.story-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.story-card-image {
  position: relative;
}

.story-card img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  object-position: center;
  display: block;
  transition: transform 0.3s ease;
}

.story-card:hover img {
  transform: scale(1.05);
}

.story-card .status {
  position: absolute;
  top: 6px;
  left: 6px;
  background: #43a047;
  color: white;
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 4px;
  transform: translateX(-10px);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.story-card:hover .status {
  transform: translateX(0);
  opacity: 1;
}

.story-card .view-count {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transform: translateY(10px);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.story-card:hover .view-count {
  transform: translateY(0);
  opacity: 1;
}

.story-card .view-count::before {
  content: '👀';
  margin-right: 4px;
}

.story-card h4 {
  font-size: 0.9rem;
  margin: 8px 8px 4px;
  padding: 0 8px;
  color: #222;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  flex-grow: 1;
  font-weight: 600;
  transition: color 0.3s ease;
}

.story-card h4:hover {
  color: #e53935;
}

.story-card p {
  font-size: 0.8rem;
  color: #666;
  margin: 0 8px 10px;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

.pagination a {
  padding: 6px 12px;
  background: #fff;
  color: #e53935;
  text-decoration: none;
  border-radius: 4px;
  font-size: 14px;
  transition: background 0.3s ease, transform 0.3s ease;
}

.pagination a:hover {
  background: #e53935;
  color: white;
  transform: scale(1.1);
}

.pagination a.active {
  background: #e53935;
  color: white;
  font-weight: bold;
  transform: scale(1.05);
}

.pagination-ellipsis {
  padding: 6px 12px;
  color: #666;
  font-size: 14px;
}

/* ===== Story Detail View ===== */
.story-detail {
  display: flex;
  gap: 24px;
  margin-bottom: 20px;
  align-items: flex-start;
  opacity: 0;
  transform: translateY(20px);
  animation: fadeInUp 0.5s ease forwards;
}

@keyframes fadeInUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.story-image {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
}

.story-image img {
  width: 180px;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: transform 0.3s ease;
}

.story-image img:hover {
  transform: scale(1.05);
}

.story-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  contain: content; /* Prevent AdSense from injecting ads */
}

.story-info ins {
  display: none !important; /* Block AdSense ads */
}

.story-info h1 {
  font-size: 24px;
  color: #d32f2f;
  margin-bottom: 4px;
  transition: color 0.3s ease;
}

.story-info h1:hover {
  color: #b71c1c;
}

.story-info p {
  font-size: 14px;
  margin: 2px 0;
}

.story-info .story-description-container {
  position: relative;
}

.story-info .story-description {
  font-size: 14px;
  line-height: 1.6;
  color: #333;
}

.story-info .story-description p {
  margin-bottom: 12px;
  line-height: 1.6;
}

.story-info .story-description.truncated {
  max-height: 4.8em;
  overflow: hidden;
  position: relative;
}

.story-info .story-description.truncated::after {
  content: '...';
  position: absolute;
  bottom: 0;
  right: 0;
  background: linear-gradient(to right, transparent, #f9f9f9 50%);
  padding-left: 10px;
}

.story-info .show-more-btn {
  background: none;
  border: none;
  color: #e53935;
  font-size: 14px;
  cursor: pointer;
  padding: 5px 0;
  text-align: left;
  transition: color 0.3s ease;
}

.story-info .show-more-btn:hover {
  color: #b71c1c;
  text-decoration: underline;
}

.story-info .story-views::before {
  content: '👀';
  margin-right: 4px;
}

#start-reading-btn {
  align-self: flex-start;
  padding: 14px 28px;
  font-size: 18px;
  background-color: #d32f2f;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 16px;
  transition: background-color 0.3s ease, transform 0.3s ease;
  font-weight: bold;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

#start-reading-btn:hover {
  background-color: #b71c1c;
  transform: translateY(-2px);
}

/* ===== Chapter List + Reader ===== */
#chapter-list ul {
  list-style: none;
  padding: 0;
}

#chapter-list ul li {
  margin: 4px 0;
  cursor: pointer;
  color: #007bff;
  transition: color 0.3s ease, transform 0.3s ease;
}

#chapter-list ul li:hover {
  color: #0056b3;
  transform: translateX(4px);
}

#chapter-reader {
  background: white;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
  margin-top: 30px;
  font-size: 18px;
  line-height: 1.8;
  opacity: 0;
  animation: fadeIn 0.5s ease forwards;
}

@keyframes fadeIn {
  to {
    opacity: 1;
  }
}

.chapter-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.chapter-controls button {
  padding: 8px 16px;
  font-size: 16px;
  background-color: #e53935;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.3s ease;
}

.chapter-controls button:hover {
  background-color: #c62828;
  transform: translateY(-2px);
}

#reading-chapter-title {
  font-weight: bold;
  font-size: 20px;
  color: #d32f2f;
}

/* ===== Popup Quảng Cáo ===== */
#popup-ad {
  display: none;
  background: transparent;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 99999;
  cursor: pointer;
}

#popup-ad[style*="display: none"] {
  background: none !important;
}

/* Ngăn AdSense tự động chèn quảng cáo */
.story-grid, .story-card {
  contain: content;
}

.story-grid ins, .story-card ins {
  display: none !important;
}

/* ===== Responsive (Mobile) ===== */
@media (max-width: 768px) {
  .container {
    flex-direction: column;
  }

  .sidebar, .right-sidebar {
    display: none;
  }

  .content {
    margin-left: 0;
    margin-right: 0;
    padding: 16px;
  }

  .navbar {
    flex-direction: row;
    align-items: center;
    padding: 8px 12px;
  }

  .navbar .logo {
    font-size: 18px;
  }

  .navbar .menu {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    width: 100%;
    background-color: #e53935;
    flex-direction: column;
    padding: 10px 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    z-index: 999;
  }

  .navbar .menu.active {
    display: flex;
  }

  .navbar .menu a {
    font-size: 16px;
    padding: 10px 0;
    width: 100%;
    text-align: left;
  }

  .navbar .menu-toggle {
    display: block;
  }

  .search-form {
    margin: 0 5px;
  }

  .search-form input {
    font-size: 14px;
    padding: 6px;
    border-radius: 4px 0 0 4px;
  }

  .search-form .search-btn {
    padding: 6px 10px;
    font-size: 14px;
  }

  .story-detail {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
  }

  .story-image {
    width: 100%;
    display: flex;
    justify-content: center;
  }

  .story-image img {
    width: 80%;
    max-width: 240px;
    margin-bottom: 12px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }

  .story-info h1 {
    font-size: 20px;
    margin-top: 8px;
  }

  .story-info p {
    font-size: 14px;
    margin: 4px 0;
  }

  .story-info .story-description-container {
    text-align: left;
  }

  .story-info .story-description p {
    margin-bottom: 10px;
    line-height: 1.6;
  }

  .story-info .story-description.truncated {
    max-height: 4.8em;
  }

  .story-info .show-more-btn {
    font-size: 13px;
  }

  #start-reading-btn {
    display: block;
    width: 100%;
    max-width: 300px;
    margin: 16px auto;
    font-size: 16px;
    padding: 12px;
    background-color: #e53935;
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  }

  .story-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
  }

  .story-card {
    min-height: 260px;
  }

  .story-card img {
    height: 180px;
  }

  .story-card .status,
  .story-card .view-count {
    padding: 2px 6px;
    font-size: 10px;
    margin: 4px;
  }

  .story-card h4 {
    font-size: 0.85rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .story-card p {
    font-size: 0.75rem;
  }

  .pagination a {
    padding: 4px 8px;
    font-size: 12px;
  }

  .pagination-ellipsis {
    padding: 4px 8px;
    font-size: 12px;
  }

  .chapter-controls button {
    font-size: 14px;
  }

  .admin-nav {
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }

  .admin-nav a {
    width: 100%;
    text-align: center;
  }
}

/* ===== Tối ưu văn bản chương ===== */
#reading-chapter-content p,
#chapter-content p {
  margin-bottom: 20px !important;
  line-height: 1.8 !important;
}

/* ===== Admin Styles ===== */
.admin-container {
  max-width: 1200px;
  margin: 20px auto;
  padding: 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  opacity: 0;
  animation: fadeIn 0.5s ease forwards;
}

.search-form {
  margin-bottom: 20px;
  transform: translateY(20px);
  opacity: 0;
  animation: slideIn 0.5s ease 0.2s forwards;
}

@keyframes slideIn {
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.search-form h2 {
  color: #d32f2f;
  margin-bottom: 10px;
}

.search-form input,
.search-form select {
  width: 300px;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-right: 10px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.search-form input:focus,
.search-form select:focus {
  border-color: #e53935;
  box-shadow: 0 0 5px rgba(229, 57, 53, 0.3);
}

.search-form button {
  background: #d32f2f;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.3s ease;
}

.search-form button:hover {
  background: #b71c1c;
  transform: translateY(-2px);
}

.admin-form {
  position: relative;
}

.admin-form h2 {
  color: #d32f2f;
  margin-bottom: 20px;
}

.admin-form label {
  display: block;
  margin: 10px 0 5px;
  font-weight: bold;
}

.admin-form input,
.admin-form textarea,
.admin-form select {
  width: 100%;
  padding: 8px;
  margin-bottom: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.admin-form input:focus,
.admin-form textarea:focus,
.admin-form select:focus {
  border-color: #e53935;
  box-shadow: 0 0 5px rgba(229, 57, 53, 0.3);
}

.admin-form textarea {
  height: 150px;
  resize: vertical;
}

.admin-form .save-top-btn {
  position: sticky;
  top: 20px;
  background: #d32f2f;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
  margin-bottom: 20px;
  font-weight: bold;
  transition: background-color 0.3s ease, transform 0.3s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.admin-form .save-top-btn:hover {
  background: #b71c1c;
  transform: translateY(-2px);
}

.admin-form button:not(.save-top-btn) {
  background: #d32f2f;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.3s ease;
}

.admin-form button:not(.save-top-btn):hover {
  background: #b71c1c;
  transform: translateY(-2px);
}

.story-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
  opacity: 0;
  animation: fadeIn 0.5s ease 0.4s forwards;
}

.story-table th,
.story-table td {
  border: 1px solid #ddd;
  padding: 10px;
  text-align: left;
  transition: background-color 0.3s ease;
}

.story-table th {
  background: #f1f1f1;
}

.story-table tr:hover {
  background-color: #f9f9f9;
}

.story-table img {
  width: 50px;
  height: auto;
  border-radius: 4px;
  transition: transform 0.3s ease;
}

.story-table img:hover {
  transform: scale(1.1);
}

.story-table .action-btn {
  padding: 5px 10px;
  margin: 0 5px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.3s ease;
}

.story-table .action-btn:hover {
  transform: translateY(-2px);
}

.story-table .edit-btn {
  background: #007bff;
  color: white;
}

.story-table .delete-btn {
  background: #dc3545;
  color: white;
}

.story-table .toggle-hidden-btn {
  background: #6c757d;
  color: white;
}

#preview-image-container {
  margin-top: 10px;
  max-width: 200px;
}

#preview-image {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  display: none;
}

.error-message {
  color: #dc3545;
  font-size: 14px;
  margin-top: 5px;
  opacity: 0;
  animation: fadeIn 0.3s ease forwards;
}

.success-message {
  color: #43a047;
  font-size: 14px;
  margin-top: 5px;
  opacity: 0;
  animation: fadeIn 0.3s ease forwards;
}