:root {
  --primary-navy: #2A2B66;
  --primary-violet: #6C5CE7;
  --violet-light: #A29BFE;
  --gold: #FDCB6E;
  --amber: #FFA502;
  --cream: #FAF8F5;
  --mint: #00B894;
  --coral: #FF7675;
  --surface: #FFFFFF;
  --text-primary: #2D3436;
  --text-secondary: #636E72;
  --card-border: rgba(108, 92, 231, 0.12);
  --shadow-sm: 0 4px 12px rgba(42, 43, 102, 0.08);
  --shadow-md: 0 8px 24px rgba(42, 43, 102, 0.12);
  --shadow-lg: 0 16px 36px rgba(42, 43, 102, 0.16);
  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 28px;
  --font-family: 'Cairo', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background: var(--cream);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  transition: background 0.3s;
}

/* Header */
.app-header {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--card-border);
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  cursor: pointer;
}

.brand-icon {
  font-size: 28px;
  background: linear-gradient(135deg, var(--primary-violet), var(--primary-navy));
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: #fff;
  box-shadow: 0 4px 10px rgba(108, 92, 231, 0.3);
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary-navy);
  line-height: 1.1;
}

.brand-text span {
  font-size: 0.75rem;
  color: var(--primary-violet);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.child-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(108, 92, 231, 0.08);
  padding: 6px 14px;
  border-radius: 30px;
  cursor: pointer;
  border: 1px solid var(--card-border);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary-navy);
  transition: all 0.2s;
}

.child-badge:hover {
  background: rgba(108, 92, 231, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary-violet);
  color: #fff;
}
.btn-primary:hover {
  background: #5b4cc4;
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.35);
}

.btn-gold {
  background: var(--gold);
  color: var(--primary-navy);
}
.btn-gold:hover {
  background: var(--amber);
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--primary-violet);
  color: var(--primary-violet);
}
.btn-outline:hover {
  background: rgba(108, 92, 231, 0.08);
}

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  padding: 0;
  font-size: 1.2rem;
  background: #f1eff9;
  color: var(--primary-navy);
}
.btn-icon:hover {
  background: #e2def5;
}

/* Nav Tabs */
.nav-bar {
  background: #fff;
  border-bottom: 1px solid var(--card-border);
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  padding: 6px 20px;
  overflow-x: auto;
}

.nav-tab {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  background: none;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-tab.active {
  color: var(--primary-violet);
  background: rgba(108, 92, 231, 0.1);
}

/* Main Content */
.main-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
  flex: 1;
  width: 100%;
}

/* Hero AI Banner */
.hero-banner {
  background: linear-gradient(135deg, var(--primary-navy), var(--primary-violet));
  border-radius: var(--radius-lg);
  padding: 32px 36px;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-md);
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}

.hero-banner::after {
  content: '✨';
  position: absolute;
  top: -10px;
  right: 20px;
  font-size: 120px;
  opacity: 0.08;
  pointer-events: none;
}

.hero-content {
  max-width: 600px;
}

.badge-tag {
  display: inline-block;
  background: rgba(253, 203, 110, 0.25);
  color: var(--gold);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 800;
  margin-bottom: 12px;
}

.hero-title {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.hero-subtitle {
  font-size: 0.95rem;
  opacity: 0.9;
  line-height: 1.5;
  margin-bottom: 20px;
}

/* Filters & Search */
.filters-bar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.search-box {
  width: 100%;
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 14px 20px 14px 44px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--card-border);
  background: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border 0.2s;
  box-shadow: var(--shadow-sm);
}

[dir="rtl"] .search-box input {
  padding: 14px 44px 14px 20px;
}

.search-box input:focus {
  border-color: var(--primary-violet);
}

.search-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 16px;
  font-size: 1.1rem;
  color: var(--text-secondary);
}

[dir="rtl"] .search-icon {
  left: auto;
  right: 16px;
}

.chips-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.filter-chip {
  padding: 8px 16px;
  background: #fff;
  border: 1.5px solid var(--card-border);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.filter-chip.active {
  background: var(--primary-violet);
  color: #fff;
  border-color: var(--primary-violet);
}

/* Story Grid */
.stories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 22px;
}

.story-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  transition: all 0.25s;
  cursor: pointer;
}

.story-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.card-cover {
  height: 180px;
  position: relative;
  overflow: hidden;
  background: #eee;
}

.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s;
}

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

.card-age-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: var(--primary-violet);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 12px;
}

[dir="rtl"] .card-age-badge {
  left: auto;
  right: 12px;
}

.card-status-badge {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: var(--mint);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

[dir="rtl"] .card-status-badge {
  right: auto;
  left: 12px;
}

.card-fav-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background 0.2s;
}

[dir="rtl"] .card-fav-btn {
  right: auto;
  left: 10px;
}

.card-fav-btn.active {
  color: var(--gold);
}

.card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 8px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary-navy);
  margin-bottom: 6px;
  line-height: 1.3;
}

.card-summary {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 14px;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  border-top: 1px solid #f1f2f6;
}

/* Modal / Reader Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 21, 41, 0.8);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
}

.reader-container {
  background: #fff;
  width: 100%;
  max-width: 900px;
  height: 90vh;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: scaleIn 0.25s ease-out;
}

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

.reader-header {
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid var(--card-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.reader-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.reader-page-card {
  width: 100%;
  max-width: 760px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  gap: 20px;
  transition: all 0.3s;
}

.page-illustration {
  width: 100%;
  height: 320px;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.page-illustration img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.page-text {
  font-size: 1.35rem;
  line-height: 2.1;
  font-weight: 600;
  color: var(--text-primary);
  text-align: justify;
}

.page-discussion {
  background: rgba(108, 92, 231, 0.08);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  border-left: 4px solid var(--primary-violet);
}

[dir="rtl"] .page-discussion {
  border-left: none;
  border-right: 4px solid var(--primary-violet);
}

.reader-footer {
  padding: 14px 24px;
  background: #FAF8F5;
  border-top: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reader-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Generator & Dashboard Panels */
.panel-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--card-border);
  margin-bottom: 24px;
}

.panel-card h3 {
  color: var(--primary-navy);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 8px;
  color: var(--primary-navy);
}

.form-input, .form-select {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--card-border);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
}

.form-input:focus, .form-select:focus {
  border-color: var(--primary-violet);
}

/* Footer */
.app-footer {
  background: #fff;
  border-top: 1px solid var(--card-border);
  padding: 24px 20px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: auto;
}

/* Responsive */
@media (max-width: 768px) {
  .hero-banner {
    flex-direction: column;
    align-items: flex-start;
    padding: 24px;
    gap: 16px;
  }
  .page-illustration {
    height: 220px;
  }
  .page-text {
    font-size: 1.15rem;
    line-height: 1.8;
  }
}
