:root {
    --bg: #f7f5f3;
    --bg-secondary: #efece8;
    --card: #faf8f6;
    --card-hover: #f2f0ed;
    --border: #ddd9d3;
    --border-active: #c4a574;
    --text-primary: #3c3c3c;
    --text-secondary: #5a5a5a;
    --text-muted: #8a8a8a;
    --accent: #6366f1;
    --accent-light: #7c3aed;
    --accent-lighter: #a78bfa;
    --accent-bg: #f1f0ff;
    --success: #16a34a;
    --success-bg: #dcfce7;
    --warning: #ea580c;
    --warning-bg: #fed7aa;
    --danger: #dc2626;
    --gold: #d4af37;
    --gold-light: #f4e7a1;
    --shadow: 0 4px 16px rgba(99, 102, 241, 0.06);
    --shadow-hover: 0 8px 24px rgba(99, 102, 241, 0.10);
    --shadow-card: 0 2px 8px rgba(60, 60, 60, 0.04);
    --gradient: linear-gradient(135deg, #f7f5f3 0%, #efece8 100%);
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #7c3aed 100%);
    
    /* Typography Scale */
    --font-xs: 12px;
    --font-sm: 14px;
    --font-base: 16px;
    --font-lg: 18px;
    --font-xl: 20px;
    --font-2xl: 24px;
    --font-3xl: 30px;
    --font-4xl: 36px;
    
    /* Spacing Scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;
    
    /* Border Radius */
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 999px;
  }

  /* Dark Theme - ألوان داكنة أنيقة */
  [data-theme="dark"] {
    --bg: #0f0f23;
    --bg-secondary: #1a1a3a;
    --card: #212147;
    --card-hover: #2a2a5a;
    --border: #3a3a6b;
    --border-active: #d4af37;
    --text-primary: #f1f1f6;
    --text-secondary: #d4d4e8;
    --text-muted: #a8a8c8;
    --accent: #818cf8;
    --accent-light: #a5b4fc;
    --accent-lighter: #c7d2fe;
    --accent-bg: #2d2d4f;
    --success: #10b981;
    --success-bg: #1a3a32;
    --warning: #f59e0b;
    --warning-bg: #3d2a1a;
    --danger: #ef4444;
    --gold: #fbbf24;
    --gold-light: #4d3d1a;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.2);
    --gradient: linear-gradient(135deg, #0f0f23 0%, #1a1a3a 100%);
    --accent-gradient: linear-gradient(135deg, #818cf8 0%, #a5b4fc 100%);
  }

  /* High Contrast Theme for Seniors */
  [data-theme="contrast"] {
    --bg: #ffffff;
    --bg-secondary: #f0f0f0;
    --card: #ffffff;
    --card-hover: #f5f5f5;
    --border: #000000;
    --border-active: #000000;
    --text-primary: #000000;
    --text-secondary: #333333;
    --text-muted: #555555;
    --accent: #0000aa;
    --accent-light: #0000cc;
    --accent-lighter: #3333dd;
    --accent-bg: #f0f0ff;
    --success: #006600;
    --success-bg: #f0fff0;
    --warning: #cc6600;
    --warning-bg: #fff8f0;
    --danger: #cc0000;
    --gold: #996600;
    --gold-light: #fff8e0;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    --shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.15);
    --gradient: linear-gradient(135deg, #ffffff 0%, #f0f0f0 100%);
    --accent-gradient: linear-gradient(135deg, #0000aa 0%, #0000cc 100%);
  }
  
  [data-theme="dark"] .back-btn {
    background: var(--card);
    border-color: var(--border);
  }
  
  [data-theme="dark"] .back-btn:hover {
    background: var(--card-hover);
    border-color: var(--accent);
  }

  /* Base Styles */
  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  html {
    font-size: 16px;
    scroll-behavior: smooth;
  }

  /* Senior Mode Font Scaling */
  [data-senior="true"] {
    font-size: 18px;
  }

  [data-senior="true"] .card {
    padding: var(--space-8);
  }

  [data-senior="true"] .btn {
    padding: var(--space-5) var(--space-8);
    font-size: var(--font-lg);
    min-height: 56px;
  }

  body {
    font-family: "Tajawal", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--gradient);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: all 0.3s ease;
  }

  .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-6);
  }

  /* SVG Icon Styles */
  .icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    flex-shrink: 0;
  }

  .icon-lg {
    width: 24px;
    height: 24px;
  }

  .icon-xl {
    width: 32px;
    height: 32px;
  }

  /* Header Styles */
  .header {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    margin-bottom: var(--space-8);
    box-shadow: var(--shadow-card);
    backdrop-filter: blur(10px);
  }

  .header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-6);
    margin-bottom: var(--space-6);
  }

  

  .title-section h1 {
    font-size: clamp(var(--font-2xl), 4vw, var(--font-4xl));
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--space-2);
  }

  .subtitle {
    color: var(--text-muted);
    font-size: var(--font-base);
    font-weight: 400;
  }

  /* Control Panel */
  .control-panel {
    display: flex;
    gap: var(--space-4);
    flex-wrap: wrap;
    align-items: center;
  }

  .theme-controls {
    display: flex;
    gap: var(--space-2);
    align-items: center;
    background: var(--bg-secondary);
    padding: var(--space-1);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
  }

  .control-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    font-size: var(--font-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
  }

  .control-btn:hover {
    background: var(--accent-bg);
    color: var(--accent);
    transform: translateY(-1px);
  }

  .control-btn.active {
    background: var(--accent);
    color: white;
  }

  .senior-mode-btn {
    background: var(--warning);
    color: white;
    border: 1px solid var(--warning);
    border-radius: var(--radius-lg);
    font-weight: 600;
    box-shadow: var(--shadow);
  }

  .senior-mode-btn:hover {
    background: #ea580c;
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
  }

  /* Search Section */
  .search-section {
    margin-bottom: var(--space-8);
  }

  .search-wrapper {
    position: relative;
    max-width: 600px;
    margin: 0 auto var(--space-6);
  }
  .back-navigation {
    margin-bottom: 1rem;
    padding: 0 1rem;
  }
  
  .back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    box-shadow: var(--shadow-card);
  }
  
  .back-btn:hover {
    background: var(--card-hover);
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
  }
  
  .back-btn .icon {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .search-input {
    width: 100%;
    padding: var(--space-5) var(--space-5) var(--space-5) var(--space-16);
    font-size: var(--font-lg);
    border: 2px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--card);
    color: var(--text-primary);
    transition: all 0.3s ease;
    box-shadow: var(--shadow-card);
  }

  .search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-bg), var(--shadow);
    transform: translateY(-1px);
  }

  .search-icon {
    position: absolute;
    left: var(--space-5);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
  }

  /* Category Filter */
  .category-filter {
    display: flex;
    justify-content: center;
    gap: var(--space-4);
    flex-wrap: wrap;
  }

  .category-chip {
    background: var(--card);
    border: 2px solid var(--border);
    color: var(--text-secondary);
    padding: var(--space-4) var(--space-6);
    border-radius: var(--radius-full);
    font-size: var(--font-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    box-shadow: var(--shadow-card);
  }

  .category-chip:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
  }

  .category-chip.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    box-shadow: var(--shadow-hover);
  }

  /* Statistics */
  .stats-section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    margin-bottom: var(--space-8);
    box-shadow: var(--shadow-card);
    backdrop-filter: blur(10px);
  }

  .stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-8);
    text-align: center;
  }

  .stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
  }

  .stat-icon {
    width: 48px;
    height: 48px;
    background: var(--accent-bg);
    border-radius: var(--radius-lg);
    display: grid;
    place-items: center;
    margin-bottom: var(--space-3);
    color: var(--accent);
  }

  .stat-number {
    font-size: var(--font-3xl);
    font-weight: 700;
    color: var(--accent);
    margin-bottom: var(--space-1);
  }

  .stat-label {
    font-size: var(--font-sm);
    color: var(--text-muted);
    font-weight: 500;
  }

  .progress-bar {
    width: 100%;
    height: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-top: var(--space-4);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
  }

  .progress-fill {
    height: 100%;
    background: var(--accent-gradient);
    transition: width 0.6s ease;
    border-radius: var(--radius-full);
    position: relative;
  }

  .progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: shimmer 2s infinite;
  }

  @keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
  }

  /* Grid Layout */
  .riddles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: var(--space-8);
    margin-bottom: var(--space-12);
  }

  @media (max-width: 768px) {
    .riddles-grid {
      grid-template-columns: 1fr;
      gap: var(--space-6);
    }
  }

  .back-btn {
    font-size: 0.85rem;
    padding: 0.6rem 0.8rem;
  }
  
  .back-btn .icon {
    width: 16px;
    height: 16px;
  }
  /* Card Styles */
  .riddle-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-card);
    transition: all 0.4s ease;
    position: relative;
    backdrop-filter: blur(10px);
  }

  .riddle-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    border-color: var(--accent-lighter);
  }

  .riddle-card.solved {
    border-color: var(--success);
    background: linear-gradient(135deg, var(--card) 0%, var(--success-bg) 100%);
  }

  .riddle-card.solved::before {
    content: "";
    position: absolute;
    top: var(--space-5);
    right: var(--space-5);
    width: 40px;
    height: 40px;
    background: var(--success);
    border-radius: 50%;
    display: grid;
    place-items: center;
    z-index: 1;
    box-shadow: var(--shadow);
  }

  .riddle-card.solved::after {
    content: "";
    position: absolute;
    top: var(--space-5);
    right: var(--space-5);
    width: 40px;
    height: 40px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20,6 9,17 4,12'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    z-index: 2;
  }

  .card-header {
    padding: var(--space-8);
    padding-bottom: var(--space-6);
  }

  .question-text {
    font-size: var(--font-lg);
    font-weight: 500;
    line-height: 1.8;
    color: var(--text-primary);
    margin-bottom: var(--space-6);
  }

  .card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-4);
  }

  .tags {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
  }

  .tag {
    background: var(--accent-bg);
    color: var(--accent);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    font-size: var(--font-xs);
    font-weight: 600;
    border: 1px solid var(--accent-lighter);
    display: flex;
    align-items: center;
    gap: var(--space-1);
  }

  .difficulty-indicator {
    display: flex;
    gap: var(--space-1);
    align-items: center;
  }

  .difficulty-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
    transition: all 0.3s ease;
  }

  .difficulty-dot.active {
    background: var(--gold);
    box-shadow: 0 0 8px var(--gold);
  }

  /* Answer Section */
  .answer-section {
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    padding: var(--space-8);
    display: none;
    animation: slideDown 0.5s ease;
  }

  .answer-section.show {
    display: block;
  }

  @keyframes slideDown {
    from {
      opacity: 0;
      transform: translateY(-20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .answer-text {
    font-size: var(--font-base);
    line-height: 1.9;
    color: var(--text-primary);
    font-weight: 400;
  }

  /* Action Buttons */
  .card-actions {
    padding: var(--space-6) var(--space-8);
    border-top: 1px solid var(--border);
    background: var(--card);
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
  }

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-6);
    border-radius: var(--radius-lg);
    font-size: var(--font-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    text-decoration: none;
    min-height: 48px;
    position: relative;
    overflow: hidden;
  }

  .btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
  }

  .btn:hover::before {
    left: 100%;
  }

  .btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: var(--shadow);
  }

  .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
  }

  .btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
  }

  .btn-secondary:hover {
    background: var(--accent-bg);
    border-color: var(--accent);
    color: var(--accent);
  }

  .btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
  }

  .btn-ghost:hover {
    background: var(--bg-secondary);
    color: var(--text-secondary);
  }

  /* Empty State */
  .empty-state {
    text-align: center;
    padding: var(--space-16);
    color: var(--text-muted);
  }

  .empty-icon {
    width: 96px;
    height: 96px;
    margin: 0 auto var(--space-6);
    color: var(--accent-lighter);
  }

  .empty-state h3 {
    font-size: var(--font-2xl);
    margin-bottom: var(--space-4);
    color: var(--text-secondary);
  }

  /* Toast Notifications */
  .toast {
    position: fixed;
    bottom: var(--space-8);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: var(--card);
    padding: var(--space-4) var(--space-8);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-hover);
    z-index: 1000;
    animation: toastIn 0.4s ease;
    backdrop-filter: blur(10px);
    font-weight: 500;
  }

  @keyframes toastIn {
    from {
      opacity: 0;
      transform: translateX(-50%) translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateX(-50%) translateY(0);
    }
  }

  /* PWA Install Prompt */
  .install-prompt {
    position: fixed;
    bottom: var(--space-8);
    left: var(--space-8);
    right: var(--space-8);
    max-width: 420px;
    margin: 0 auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    box-shadow: var(--shadow-hover);
    transform: translateY(100px);
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s ease;
    z-index: 1001;
    backdrop-filter: blur(20px);
  }

  .install-prompt.show {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .install-header {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
  }

  .install-icon {
    width: 48px;
    height: 48px;
    background: var(--accent-gradient);
    border-radius: var(--radius-lg);
    display: grid;
    place-items: center;
    color: white;
  }

  .install-title {
    font-size: var(--font-lg);
    font-weight: 600;
    color: var(--text-primary);
  }

  .install-description {
    font-size: var(--font-sm);
    color: var(--text-muted);
    margin-bottom: var(--space-6);
    line-height: 1.6;
  }

  .install-actions {
    display: flex;
    gap: var(--space-3);
  }

  /* Offline Indicator */
  .offline-indicator {
    position: fixed;
    top: var(--space-6);
    left: 50%;
    transform: translateX(-50%);
    background: var(--warning);
    color: white;
    padding: var(--space-4) var(--space-8);
    border-radius: var(--radius-full);
    font-size: var(--font-sm);
    font-weight: 600;
    z-index: 1002;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  .offline-indicator.show {
    opacity: 1;
  }

  /* Footer */
  .footer {
    text-align: center;
    padding: var(--space-12) 0;
    color: var(--text-muted);
    font-size: var(--font-sm);
    border-top: 1px solid var(--border);
    margin-top: var(--space-12);
    background: var(--bg-secondary);
  }

  /* Responsive Design */
  @media (max-width: 768px) {
    .container {
      padding: var(--space-4);
    }

    .header {
      padding: var(--space-6);
    }

    .header-top {
      flex-direction: column;
      text-align: center;
      gap: var(--space-4);
    }

    .control-panel {
      justify-content: center;
      flex-direction: column;
      gap: var(--space-3);
    }

    .theme-controls {
      order: 2;
    }

    .stats-grid {
      grid-template-columns: repeat(2, 1fr);
      gap: var(--space-6);
    }

    .card-actions {
      flex-direction: column;
    }

    .btn {
      justify-content: center;
    }

    .riddles-grid {
      grid-template-columns: 1fr;
    }
  }

  @media (max-width: 480px) {
    .stats-grid {
      grid-template-columns: 1fr;
    }

    .category-filter {
      gap: var(--space-2);
    }

    .category-chip {
      padding: var(--space-3) var(--space-5);
      font-size: var(--font-xs);
    }

    .header {
      margin-bottom: var(--space-6);
    }

    .search-section, .stats-section {
      margin-bottom: var(--space-6);
    }
  }

  /* Print Styles */
  @media print {
    .header .control-panel, .search-section, .stats-section, .card-actions, .install-prompt, .offline-indicator {
      display: none;
    }

    .riddle-card {
      break-inside: avoid;
      page-break-inside: avoid;
      margin-bottom: var(--space-4);
    }

    .answer-section {
      display: block !important;
    }
  }

  /* Focus Styles for Accessibility */
  .btn:focus,
  .search-input:focus,
  .category-chip:focus,
  .control-btn:focus {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
  }

  /* Reduced Motion */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }