:root {
  --black: #0a0a0a;
  --black-soft: #121212;
  --black-card: #161616;
  --gold: #c9a227;
  --gold-light: #e8c547;
  --gold-dark: #8a6f1a;
  --gold-glow: rgba(201, 162, 39, 0.25);
  --text: #f5f0e6;
  --text-muted: #a89f8a;
  --border: rgba(201, 162, 39, 0.2);
  --radius: 14px;
  --font: "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--black);
  color: var(--text);
  min-height: 100vh;
  direction: rtl;
  line-height: 1.7;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, var(--gold-glow), transparent),
    radial-gradient(circle at 100% 100%, rgba(138, 111, 26, 0.08), transparent 40%);
  pointer-events: none;
  z-index: 0;
}

.container {
  width: min(1200px, 92%);
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

/* Header */
.header {
  padding: 2.5rem 0 1.5rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.logo-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--gold);
  margin-bottom: 1rem;
  background: rgba(201, 162, 39, 0.06);
}

.header h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  background: linear-gradient(135deg, var(--gold-light), var(--gold), var(--gold-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.header .subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  max-width: 520px;
  margin: 0 auto 1.5rem;
}

.how-it-works {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.how-it-works span {
  padding: 0.4rem 0.85rem;
  background: var(--black-card);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.how-it-works strong {
  color: var(--gold);
  font-weight: 600;
}

/* Categories */
.categories {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  padding: 2rem 0 1.5rem;
}

.category-btn {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.65rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--black-card);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.25s ease;
}

.category-btn:hover {
  border-color: var(--gold);
  color: var(--gold-light);
}

.category-btn.active {
  background: linear-gradient(135deg, rgba(201, 162, 39, 0.2), rgba(138, 111, 26, 0.15));
  border-color: var(--gold);
  color: var(--gold-light);
  box-shadow: 0 0 20px var(--gold-glow);
}

/* Subcategories */
.subcategories {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  padding: 0 0 1.25rem;
}

.subcategories.hidden {
  display: none;
}

.subcategory-btn {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  border: 1px dashed var(--border);
  border-radius: 999px;
  background: rgba(201, 162, 39, 0.04);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.25s ease;
}

.subcategory-btn:hover,
.subcategory-btn.active {
  border-color: var(--gold);
  border-style: solid;
  color: var(--gold-light);
  background: rgba(201, 162, 39, 0.1);
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  padding-bottom: 4rem;
}

.card {
  background: var(--black-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.card:hover {
  transform: translateY(-4px);
  border-color: rgba(201, 162, 39, 0.45);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 30px var(--gold-glow);
}

.card-image-wrap {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--black-soft);
}

.card-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}

.card:hover .card-image-wrap img {
  transform: scale(1.04);
}

.card-category {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  padding: 0.25rem 0.65rem;
  background: rgba(10, 10, 10, 0.85);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.72rem;
  color: var(--gold);
}

.card-body {
  padding: 1.1rem 1.15rem 1.25rem;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.65rem;
  color: var(--text);
}

.prompt-preview {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 1rem;
  min-height: 3.9em;
}

.card-actions {
  display: flex;
  gap: 0.5rem;
}

.btn {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  flex: 1;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: var(--black);
  font-weight: 600;
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 16px var(--gold-glow);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--gold);
}

.btn-secondary:hover {
  border-color: var(--gold);
  background: rgba(201, 162, 39, 0.08);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
  grid-column: 1 / -1;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--black-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(640px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform 0.3s ease;
}

.modal-overlay.open .modal {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.15rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.1rem;
  color: var(--gold-light);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
}

.modal-close:hover {
  color: var(--gold);
}

.modal-image {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  background: var(--black-soft);
}

.modal-body {
  padding: 1.25rem;
}

.modal-body label {
  display: block;
  font-size: 0.8rem;
  color: var(--gold);
  margin-bottom: 0.5rem;
}

.modal-prompt {
  width: 100%;
  min-height: 140px;
  padding: 0.85rem;
  background: var(--black-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  line-height: 1.6;
}

.modal-footer {
  padding: 0 1.25rem 1.25rem;
}

.modal-footer .btn-primary {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--gold);
  color: var(--black);
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 200;
  opacity: 0;
  transition: transform 0.35s ease, opacity 0.35s ease;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Footer */
.footer {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.35rem 0.5rem;
}

.footer-link {
  color: var(--gold-light);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  transition: color 0.2s ease, background 0.2s ease;
}

.footer-link:hover,
.footer-link:focus-visible {
  color: var(--gold);
  background: rgba(201, 162, 39, 0.1);
}

/* Image placeholder */
.img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  background: linear-gradient(145deg, #1a1a1a, #0f0f0f);
}

.img-placeholder svg {
  width: 48px;
  height: 48px;
  opacity: 0.4;
  stroke: var(--gold);
}

@media (max-width: 480px) {
  .header {
    padding: 1.5rem 0 1rem;
  }

  .how-it-works {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .how-it-works span {
    text-align: center;
  }

  .categories {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(8px);
    padding: 0.75rem 0 0.5rem;
    margin: 0 -4%;
    padding-inline: 4%;
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .subcategories {
    position: sticky;
    top: 3.2rem;
    z-index: 19;
    background: rgba(10, 10, 10, 0.92);
    padding: 0.5rem 4% 0.75rem;
    margin: 0 -4%;
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
  }

  .categories::-webkit-scrollbar {
    display: none;
  }

  .category-btn {
    flex-shrink: 0;
    white-space: nowrap;
    min-height: 44px;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 1.1rem;
    padding-bottom: calc(2rem + env(safe-area-inset-bottom));
  }

  .card-actions {
    flex-direction: column;
  }

  .btn {
    min-height: 48px;
    font-size: 0.95rem;
  }

  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    max-height: 96vh;
    border-radius: 16px 16px 0 0;
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--black-card);
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }

  .modal-footer .btn-primary {
    min-height: 52px;
    font-size: 1.05rem;
  }

  .toast {
    bottom: calc(1rem + env(safe-area-inset-bottom));
    max-width: 90%;
    text-align: center;
  }

  .footer-link {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
