*, *::before, *::after {
  box-sizing: border-box;
}
html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

main#main-content {
  width: 100%;
  overflow-x: hidden;
}


body {
  margin: 0;
  font-family: 'IBM Plex Sans Arabic', sans-serif;
  background: linear-gradient(to bottom, #ffffff, #fafafa); /* Gradient from white to grey */
  color: #fff;
  overflow-x: hidden;
  transition: background 0.25s ease, color 0.25s ease;
}

body.dark-mode {
  background: #000;
  color: #f7f7f7;
}

    header {
      text-align: center;
      padding-top: 1.5rem;
    }
    header img {
      height: 115px;
      max-width: 100%;
    }
    .grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
      gap: 1rem;
      padding: 1.2rem;
    }
    .grid.search-results {
      grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
      align-items: start;
    }
    .grid-item {
      position: relative;
      border-radius: 1.9rem;
      overflow: hidden;
      min-height: 300px;
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      box-shadow: 0 0 10px rgba(200, 200, 200, 0.25);
      transition: box-shadow 0.3s ease;
    }
    .grid-item.cat-السعودية { background-color: #eef4ee; color: #000; }
    .grid-item.cat-الإمارات { background-color: #eceff7; color: #000; }
    .grid-item.cat-شركات-وأعمال { background-color: #f3f1df; color: #000; }
    .grid-item.cat-أسلوب-حياة { background-color: #f8f2fb; color: #000; }
    .grid-item.cat-رياضة { background-color: #e6f2f5; color: #000; }
    .grid-item.cat-إقتصاد { background-color: #f7ebeb; color: #000; }
    .grid-item.cat-منوعات { background-color: #ede8f7; color: #000; }
    .grid-item.cat-ثقافة-وفن { background-color: #f7ede6; color: #000; }
    .grid-item.cat-تكنولوجيا { background-color: #eff1f9; color: #000; }
    .grid-item.cat-بودكاست { background-color: #eceff7; color: #000; }
    .grid-item.cat-default { background-color: #000; color: #fff; }

.grid-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

.grid-link:hover .grid-item {
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.10);
}

.grid-item:hover,
.grid-item:focus-visible {
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.10);
}

.grid-item:focus-visible,
.card-actions button:focus-visible,
.site-header input:focus-visible {
  outline: 2px solid rgba(0, 0, 0, 0.25);
  outline-offset: 3px;
}

.bg-layer {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-size: 100%;
  background-position: top center;
  background-repeat: no-repeat;
  /* Round the image to the card radius — the layer is composited
     (will-change: transform), so the parent's overflow:hidden won't clip it. */
  border-radius: 1.9rem;
  opacity: 0;
  transform: scale(1.05);
  will-change: transform, opacity;
  transform-origin: center center;
  transition: opacity 1.5s ease-in-out, transform 2s ease;
  z-index: 0;
  filter: blur(0px);
-webkit-mask-image: linear-gradient(
  to bottom,
  rgba(0, 0, 0, 1) 0%,
  rgba(0, 0, 0, 1) 35%,
  rgba(0, 0, 0, 0) 55%
);
mask-image: linear-gradient(
  to bottom,
  rgba(0, 0, 0, 1) 0%,
  rgba(0, 0, 0, 1) 35%,
  rgba(0, 0, 0, 0) 55%
);

}


    .bg-layer.show {
      opacity: 1;
      transform: scale(1);
    }
    .overlay {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: #000;
      opacity:0;
      z-index: 1;
    }

.content {
  position: relative;
  z-index: 2;
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 1.5s ease, transform 1.5s ease;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center; /* Center horizontally */
  text-align: center;  /* Center text */
}

    .content.show {
      opacity: 1;
      transform: translateY(0);
    }
    .category, .title, .date {
      opacity: 0;
      transform: translateY(20px);
      transition: opacity 1s ease, transform 1s ease;
    }
    .content.show .category,
    .content.show .title,
    .content.show .date {
      opacity: 1;
      transform: translateY(0);
    }
    .category {
      padding: 0.2rem 0.8rem;
      border-radius: 999px;
      display: inline-block;
      margin-bottom: 0.5rem;
      font-size: 1rem;
    }
    .cat-السعودية { background-color: #cae3ca; color: #000; }
    .cat-الإمارات { background-color: #eceff7; color: #000; }
    .cat-شركات-وأعمال { background-color: #e8e0a7; color: #000; }
    .cat-أسلوب-حياة { background-color: #f5e3ff; color: #000; }
    .cat-رياضة { background-color: #bfe8f2; color: #000; }
    .cat-إقتصاد { background-color: #ffcfcf; color: #000; }
    .cat-منوعات { background-color: #e0d4ff; color: #000; }
    .cat-ثقافة-وفن { background-color: #ffdabf; color: #000; }
    .cat-تكنولوجيا { background-color: #dbe0ff; color: #000; }
    .cat-بودكاست { background-color: #eceff7; color: #000; }
    .cat-default { background-color: #000; color: #fff; }

    .title {
      font-size: 1.3rem;
      font-weight: 600;
      margin-bottom: 0.4rem;
      color: #000;
      text-decoration: none;
      display: block;
    }
    .date {
      font-size: 0.9rem;
      color: #000;
    }

    .card-actions {
      position: absolute;
      top: 1rem;
      left: 1rem;
      z-index: 3;
      display: flex;
      flex-direction: column;
      justify-content: center;
      gap: 0.45rem;
      opacity: 0;
      pointer-events: none;
      transform: translateY(10px);
      transition: opacity 0.7s ease, transform 0.7s ease;
    }

    .card-actions.show {
      opacity: 1;
      pointer-events: auto;
      transform: translateY(0);
    }

    .card-actions button {
      width: 34px;
      height: 34px;
      box-sizing: border-box;
      border: 1px solid rgba(0, 0, 0, 0.18);
      border-radius: 50%;
      background: rgba(0, 0, 0, 0.72);
      color: #fff;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      transition: opacity 0.3s ease, transform 0.3s ease, background 0.2s ease;
    }

    .card-actions button:hover {
      background: #000;
      color: #fff;
    }

    /* AI button: keeps the same dark circle as the share button when idle.
       The animated gradient fills the button only while the summary is active. */
    .card-actions .ai-btn {
      position: relative;
      overflow: hidden;
    }

    .card-actions .ai-btn::before {
      content: "";
      position: absolute;
      inset: 0;
      border-radius: 50%;
      background-image: linear-gradient(135deg, #a05fd0 0%, #6b78e0 35%, #33a0e8 70%, #a05fd0 100%);
      background-size: 220% 220%;
      background-position: 0% 0%;
      opacity: 0;
      transition: opacity 0.4s ease;
      z-index: 0;
    }

    .card-actions .ai-btn[aria-expanded="true"]::before {
      opacity: 1;
      animation: aiSparkleWave 3.2s ease-in-out infinite;
    }

    /* No ring around the gradient when active — let it fill edge to edge */
    .card-actions .ai-btn[aria-expanded="true"] {
      border: none;
    }

    .ai-icon {
      --sparkle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0c0 6.627-5.373 12-12 12 6.627 0 12 5.373 12 12 0-6.627 5.373-12 12-12-6.627 0-12-5.373-12-12z' fill='%23000'/%3E%3C/svg%3E");
      position: relative;
      z-index: 1;
      display: block;
      width: 19px;
      height: 19px;
      background-color: #fff;
      -webkit-mask-image: var(--sparkle);
      -webkit-mask-repeat: no-repeat;
      -webkit-mask-position: center;
      -webkit-mask-size: contain;
      mask-image: var(--sparkle);
      mask-repeat: no-repeat;
      mask-position: center;
      mask-size: contain;
    }

    @keyframes aiSparkleWave {
      0%   { background-position: 0% 0%; }
      50%  { background-position: 100% 100%; }
      100% { background-position: 0% 0%; }
    }

    /* AI summary overlay */
    .ai-summary {
      position: absolute;
      inset: 0;
      z-index: 2;
      display: flex;
      align-items: center;
      justify-content: center;
      /* Extra top padding so long text always starts below the AI icon */
      padding: 3.6rem 1.6rem 1.6rem;
      border-radius: 1.9rem;
      /* Fallback tint; per-category colors below override this */
      background: rgba(240, 240, 240, 0.88);
      -webkit-backdrop-filter: blur(5px);
      backdrop-filter: blur(5px);
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
      transition: opacity 0.4s ease, visibility 0.4s ease;
    }

    .ai-summary.show {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
    }

    /* Summary overlay adopts each category's lighter (card-background) scheme color */
    .grid-item.cat-السعودية   .ai-summary { background: rgba(238, 244, 238, 0.88); }
    .grid-item.cat-الإمارات    .ai-summary { background: rgba(236, 239, 247, 0.88); }
    .grid-item.cat-شركات-وأعمال .ai-summary { background: rgba(243, 241, 223, 0.88); }
    .grid-item.cat-أسلوب-حياة  .ai-summary { background: rgba(248, 242, 251, 0.88); }
    .grid-item.cat-رياضة       .ai-summary { background: rgba(230, 242, 245, 0.88); }
    .grid-item.cat-إقتصاد      .ai-summary { background: rgba(247, 235, 235, 0.88); }
    .grid-item.cat-منوعات      .ai-summary { background: rgba(237, 232, 247, 0.88); }
    .grid-item.cat-ثقافة-وفن   .ai-summary { background: rgba(247, 237, 230, 0.88); }
    .grid-item.cat-تكنولوجيا   .ai-summary { background: rgba(239, 241, 249, 0.88); }
    .grid-item.cat-بودكاست     .ai-summary { background: rgba(236, 239, 247, 0.88); }

    /* Dark mode: keep the original dark summary for every card
       (the light category pastels don't suit dark mode). */
    body.dark-mode .grid-item .ai-summary {
      background: rgba(0, 0, 0, 0.72);
    }

    body.dark-mode .ai-summary-text {
      color: #fff;
      scrollbar-color: rgba(255, 255, 255, 0.4) transparent;
    }

    body.dark-mode .ai-summary-text::-webkit-scrollbar-thumb {
      background: rgba(255, 255, 255, 0.35);
    }

    .ai-summary-text {
      margin: 0;
      max-height: 100%;
      overflow-y: auto;
      color: #000;
      font-family: 'IBM Plex Sans Arabic', sans-serif;
      font-size: 1rem;
      line-height: 1.8;
      text-align: center;
      opacity: 0;
      /* Soft top-to-bottom reveal: a feathered mask that grows downward,
         so the leading edge fades in gently instead of a hard cutting line. */
      -webkit-mask-image: linear-gradient(to bottom, #000 60%, transparent 100%);
      mask-image: linear-gradient(to bottom, #000 60%, transparent 100%);
      -webkit-mask-repeat: no-repeat;
      mask-repeat: no-repeat;
      -webkit-mask-position: top;
      mask-position: top;
      -webkit-mask-size: 100% 0%;
      mask-size: 100% 0%;
      transition: opacity 0.9s ease,
                  -webkit-mask-size 1.6s cubic-bezier(0.65, 0, 0.35, 1) 0.1s,
                  mask-size 1.6s cubic-bezier(0.65, 0, 0.35, 1) 0.1s;
      scrollbar-width: thin;
      scrollbar-color: rgba(0, 0, 0, 0.35) transparent;
    }

    .ai-summary.show .ai-summary-text {
      opacity: 1;
      -webkit-mask-size: 100% 165%;
      mask-size: 100% 165%;
    }

    @media (prefers-reduced-motion: reduce) {
      .card-actions .ai-btn::before { animation: none; }
      .ai-summary-text {
        -webkit-mask-image: none;
        mask-image: none;
        transition: opacity 0.25s ease;
      }
    }

    .ai-summary-text::-webkit-scrollbar {
      width: 5px;
    }

    .ai-summary-text::-webkit-scrollbar-thumb {
      background: rgba(0, 0, 0, 0.3);
      border-radius: 999px;
    }

    /* When the summary is open: hide the badge/title/date and the share button */
    .grid-item.summary-open .content {
      opacity: 0;
      pointer-events: none;
    }

    .grid-item.summary-open .share-btn {
      opacity: 0;
      transform: scale(0.8);
      pointer-events: none;
    }

.live-badge {
  display: inline-flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.09);
  color: #000;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem 0.15rem 0.7rem;
  border-radius: 999px;
  margin-right: 0.5rem;
  margin-inline-start: 0.5rem;
  vertical-align: middle;
}


.live-dot {
  width: 6px;
  height: 6px;
  margin-left: 6px;
  background-color: black;
  border-radius: 50%;
  animation: blink 1.5s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}


.site-header {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 1.5rem;
  gap: 1rem;
}

.site-header img {
  height: 115px;
  max-width: 100%;
  transition: opacity 0.3s ease;
}

.header-control {
  position: absolute;
  top: 58%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  z-index: 5;
}

.header-search {
  left: 50px;
}

.header-theme {
  right: 50px;
}

.search-control {
  position: relative;
  display: flex;
  align-items: center;
}

.site-header input {
  position: absolute;
  left: calc(100% + 0.6rem);
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  opacity: 0;
  pointer-events: none;
  padding: 0.3rem 0.5rem;
  font-size: 1rem;
  font-family: 'IBM Plex Sans Arabic', sans-serif;
  border-radius: 20px;
  border: 1px solid #ccc;
  outline: none;
  transition: width 0.4s ease, opacity 0.3s ease;
}

.site-header input.open {
  width: 200px;
  opacity: 1;
  pointer-events: auto;
}

.site-header input[type="search"]::-webkit-search-cancel-button,
.site-header input[type="search"]::-webkit-search-decoration {
  display: none;
}

.site-header button {
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.3s, color 0.3s;
}

#searchToggle {
  width: 46px;
  height: 46px;
  color: #111;
  border-radius: 50%;
}

.site-header button:hover {
  background: rgba(0, 0, 0, 0.06);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  padding: 0.14rem;
  border: 1px solid #e5e5e5;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.theme-option {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #111;
}

.theme-option.active {
  background: #111;
  color: #fff;
}

body.dark-mode #searchToggle {
  color: #f7f7f7;
}

body.dark-mode .site-header input {
  background: #111;
  border-color: rgba(255, 255, 255, 0.16);
  color: #fff;
}

body.dark-mode .site-header input::placeholder {
  color: #bdbdbd;
}

body.dark-mode .theme-toggle,
body.dark-mode .category-tabs button {
  background: #111;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.32);
}

body.dark-mode .footer-social a {
  background: #111;
  border: none;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.32);
}

body.dark-mode .theme-option {
  color: #f7f7f7;
}

body.dark-mode .theme-option.active {
  background: #1f1f1f;
  color: #fff;
}

body.dark-mode .category-tabs button,
body.dark-mode footer,
body.dark-mode .footer-links a {
  color: #f7f7f7;
}

body.dark-mode .footer-social i {
  color: #888;
}

body.dark-mode .category-tabs button.active.default-active {
  background: #2a2a2a;
  color: #f7f7f7;
}

body.dark-mode .category-tabs button.active:not(.default-active) {
  color: #000;
}

body.dark-mode .footer-note {
  color: #c9c9c9;
}

body.dark-mode .card-actions button {
  background: #111;
  border-color: rgba(255, 255, 255, 0.16);
  color: #fff;
}

body.dark-mode .card-actions button:hover {
  background: #1f1f1f;
}

body.dark-mode .grid-item {
  background-color: #111 !important;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.46);
  color: #fff;
}

body.dark-mode .title,
body.dark-mode .date {
  color: #fff;
}

body.dark-mode .grid-item:hover,
body.dark-mode .grid-item:focus-visible {
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.62);
}

body.dark-mode .grid-item.skeleton {
  background-color: #111 !important;
}

body.dark-mode .grid-item.skeleton::before {
  background: linear-gradient(90deg, #111 25%, #1f1f1f 50%, #111 75%);
  background-size: 200% 100%;
}

.grid-item.skeleton {
  background-color: #f0f0f0;
  position: relative;
  min-height: 300px;
  border-radius: 1.9rem;
  overflow: hidden;
  animation: pulse 1.5s infinite ease-in-out;
}

.grid-item.skeleton::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(90deg, #f0f0f0 25%, #eaeaea 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.fallback-message {
  grid-column: 1 / -1;
  background: #fff;
  color: #000;
  border-radius: 1.9rem;
  box-shadow: 0 0 10px rgba(200, 200, 200, 0.25);
  padding: 2rem 1.5rem;
  text-align: center;
}

.fallback-message h2 {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
}

.fallback-message p {
  margin: 0;
  color: #333;
  line-height: 1.7;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.8; }
  100% { opacity: 1; }
}

/* categories tab */

/* Category tab container */
.category-tabs {
  display: flex;
  justify-content: center; /* Center on desktop */
  gap: 0.5rem;
  overflow-x: auto; /* Enable horizontal scrolling */
  padding: 0 1rem; /* Add some padding to avoid buttons touching the edges */
  margin-bottom: 1rem;
  flex-wrap: nowrap; /* Prevent wrapping */
  width: 100%; /* Ensure the container spans the full width of the screen */
  box-sizing: border-box; /* Ensure padding is included in total width */
}

/* Category button styles */
.category-tabs button {
  flex: none; /* Prevent buttons from stretching */
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 2rem;
  background: #f6f6f6;
  color: #333;
  font-size: 0.95rem;
  font-family: 'IBM Plex Sans Arabic', sans-serif;
  cursor: pointer;
  transition: background 0.3s;
  min-width: 100px; /* Ensure the buttons have a minimum width for clarity */
}

.category-tabs button.active.default-active {
  background: #fff;
}

@media (max-width: 768px) {
  .category-tabs {
        justify-content: flex-start; /* Align to start on mobile */
  }
}

.category-tabs .skeleton-btn {
  flex: none;
  height: 36px;
  min-width: 100px;
  border-radius: 2rem;
  background: linear-gradient(90deg, #f0f0f0 25%, #eaeaea 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border: none;
}

body.dark-mode .category-tabs .skeleton-btn {
  background: linear-gradient(90deg, #1f1f1f 25%, #2a2a2a 50%, #1f1f1f 75%);
  background-size: 200% 100%;
}



.category-nav {
  display: flex;
  justify-content: center;    /* center all buttons */
  gap: 0.5rem;
  margin: 1rem 0;
  flex-wrap: wrap;            /* wrap on narrow screens */
}

.category-nav button {
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 1.5rem;
  background: white;
  color: #000;
  font-size: 1rem;
  font-family: 'IBM Plex Sans Arabic', sans-serif;
  cursor: pointer;
  transition: background 0.3s;
}

.category-nav button.active {
  background: #fff;
  color: #000;
}

.category-nav button:hover {
  background: white;
}

/* Footer Styles */
footer {
  background: transparent;
  color: #000;
  text-align: center;
  padding: 2rem 1rem;
  font-family: 'IBM Plex Sans Arabic', sans-serif;
  font-size: 0.8rem;
  margin-top: 1rem;
}

.footer-container {
  max-width: 900px;
  margin: auto;
}

.footer-social a {
  margin-bottom: 15px;
  margin-inline-start: 0.7rem;
  display: inline-block;
  width: 35px;
  height: 35px;
  background-color: #fff;
  border-radius: 50%;
  text-align: center;
  line-height: 35px;
  box-shadow: 0 0px 2px rgba(0, 0, 0, 0.1);
}

.footer-social i {
  font-size: 20px;
  color: #000;
  vertical-align: middle;
}

.footer-links a {
  color: #000;
  font-size: 14px;
  margin: 0 0.1rem;
  text-decoration: none;
}

@media (max-width: 768px) {
  .footer-links a {
  font-size: 12.5px;
  margin: 0 0.1rem;
}
}

.footer-note {
  color: #494949;
  font-size: 0.9rem;
  margin-top: 0.3rem;
  margin-bottom: 1.1rem;
  min-height: 40px;
}

.footer-download img {
  height: 47px;
  margin-top: 0rem;
  margin-bottom: 1.3rem;
}

  /* Hide App Store button by default */
  #footer-appstore {
    display: none;
  }


/* NewsGrid Space */
#newsGrid {
  min-height: 650px; /* desktop */
  width: 100%;
}

#newsGrid.search-results {
  min-height: 0;
}

@media (max-width: 600px) {
  .header-search {
    left: 16px;
  }

  .header-theme {
    right: 16px;
  }

  .theme-option {
    width: 26px;
    height: 26px;
  }

  #searchToggle {
    width: 42px;
    height: 42px;
  }

  .site-header input.open {
    width: min(190px, 50vw);
  }

  /* Set a large min-height to cover typical stacked content height */
  #newsGrid {
    min-height: 2600px; /* or slightly less/more depending on average content length */
  }

  #newsGrid.search-results {
    min-height: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
