/* ============================================
   Generator Wafaq — Design System
   ============================================ */

:root {
  --font-main: 'Inter', system-ui, sans-serif;
  --font-arabic: 'Amiri', 'Noto Naskh Arabic', serif;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 8px 32px rgba(0,0,0,0.12);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.18);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --grid-gap: 2px;
}

/* -- Dark Theme -- */
[data-theme="dark"] {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-panel: rgba(17, 24, 39, 0.85);
  --bg-panel-solid: #111827;
  --bg-input: #1e293b;
  --bg-cell: #1a2236;
  --bg-cell-center: #2a1a3e;
  --border-color: rgba(148, 163, 184, 0.15);
  --border-accent: rgba(139, 92, 246, 0.4);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-1: #8b5cf6;
  --accent-2: #6366f1;
  --accent-3: #a78bfa;
  --accent-gradient: linear-gradient(135deg, #8b5cf6, #6366f1);
  --success: #34d399;
  --error: #f87171;
  --warning: #fbbf24;
  --glow: 0 0 30px rgba(139, 92, 246, 0.2);
  --cell-text: #e2e8f0;
  --cell-border: rgba(139, 92, 246, 0.25);
  --header-bg: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
}

/* -- Light Theme -- */
[data-theme="light"] {
  --bg-primary: #f0f4f8;
  --bg-secondary: #ffffff;
  --bg-panel: rgba(255, 255, 255, 0.9);
  --bg-panel-solid: #ffffff;
  --bg-input: #f1f5f9;
  --bg-cell: #f8fafc;
  --bg-cell-center: #ede9fe;
  --border-color: rgba(100, 116, 139, 0.15);
  --border-accent: rgba(99, 102, 241, 0.35);
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent-1: #6366f1;
  --accent-2: #4f46e5;
  --accent-3: #818cf8;
  --accent-gradient: linear-gradient(135deg, #6366f1, #4f46e5);
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --glow: 0 0 20px rgba(99, 102, 241, 0.1);
  --cell-text: #1e293b;
  --cell-border: rgba(99, 102, 241, 0.2);
  --header-bg: linear-gradient(135deg, #667eea, #764ba2);
}

/* -- Parchment Theme -- */
[data-theme="parchment"] {
  --bg-primary: #f5e6c8;
  --bg-secondary: #faf0dc;
  --bg-panel: rgba(250, 240, 220, 0.92);
  --bg-panel-solid: #faf0dc;
  --bg-input: #f0e0c0;
  --bg-cell: #f8eed5;
  --bg-cell-center: #e8d5b0;
  --border-color: rgba(139, 90, 43, 0.2);
  --border-accent: rgba(139, 90, 43, 0.4);
  --text-primary: #3d2b1f;
  --text-secondary: #6b4c30;
  --text-muted: #9a7b5a;
  --accent-1: #8b5a2b;
  --accent-2: #6b3a1b;
  --accent-3: #b07840;
  --accent-gradient: linear-gradient(135deg, #8b5a2b, #6b3a1b);
  --success: #5a8a3c;
  --error: #c0392b;
  --warning: #d4a017;
  --glow: 0 0 20px rgba(139, 90, 43, 0.1);
  --cell-text: #3d2b1f;
  --cell-border: rgba(139, 90, 43, 0.3);
  --header-bg: linear-gradient(135deg, #8b6914, #6b3a1b);
}

/* ============================================
   Base Reset & Typography
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* Subtle animated bg pattern */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 50%, rgba(139, 92, 246, 0.04) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(99, 102, 241, 0.04) 0%, transparent 50%),
    radial-gradient(circle at 50% 80%, rgba(167, 139, 250, 0.03) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ============================================
   Theme Switcher
   ============================================ */
.theme-switcher {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  gap: 4px;
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 4px;
  box-shadow: var(--shadow-sm);
}

.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.theme-btn:hover { color: var(--accent-1); background: var(--bg-input); }
[data-theme="dark"] .theme-btn[data-theme="dark"],
[data-theme="light"] .theme-btn[data-theme="light"],
[data-theme="parchment"] .theme-btn[data-theme="parchment"] {
  color: var(--accent-1);
  background: var(--bg-input);
}

/* ============================================
   Header
   ============================================ */
.app-header {
  position: relative;
  background: var(--header-bg);
  padding: 48px 24px 40px;
  text-align: center;
  overflow: hidden;
}
.app-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-3), transparent);
}

.header-ornament {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 120px;
  height: 120px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 50%;
}
.header-ornament-left { left: -30px; }
.header-ornament-right { right: -30px; }

.header-content { position: relative; z-index: 1; }

.header-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.9);
  margin-bottom: 16px;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.12);
  animation: pulse-glow 3s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 20px rgba(255,255,255,0.05); }
  50% { box-shadow: 0 0 40px rgba(255,255,255,0.12); }
}

.app-title {
  font-size: 2rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.app-subtitle {
  font-size: 0.95rem;
  color: rgba(255,255,255,0.65);
  font-weight: 400;
}

/* ============================================
   Main Layout
   ============================================ */
.app-main {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}
@media (max-width: 900px) {
  .app-main { grid-template-columns: 1fr; }
}

/* ============================================
   Panel Styling
   ============================================ */
.panel {
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border var(--transition);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}
.panel-title svg { color: var(--accent-1); flex-shrink: 0; }

/* ============================================
   Control Panel
   ============================================ */
.control-panel { align-self: start; position: sticky; top: 24px; }

.control-group {
  margin-bottom: 16px;
  animation: fadeInUp 0.3s ease-out both;
}
.control-group-hidden { display: none; }

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

.control-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.control-input,
.control-select,
.control-textarea {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font-main);
  font-size: 0.9rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  transition: all var(--transition);
}
.control-input:focus,
.control-select:focus,
.control-textarea:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
}

.control-select { cursor: pointer; }
.control-textarea { resize: vertical; min-height: 60px; }

.text-info {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

/* Toggle Groups */
.toggle-group { display: flex; gap: 4px; }

.toggle-btn {
  flex: 1;
  padding: 8px 12px;
  font-family: var(--font-main);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}
.toggle-btn:hover { color: var(--text-primary); border-color: var(--accent-1); }
.toggle-btn.active {
  color: #fff;
  background: var(--accent-gradient);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.25);
}

/* Action Buttons */
.control-actions { display: flex; gap: 10px; margin-top: 24px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  flex: 1;
  color: #fff;
  background: var(--accent-gradient);
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.3);
}
.btn-primary:hover {
  box-shadow: 0 6px 24px rgba(139, 92, 246, 0.45);
  transform: translateY(-1px);
}

.btn-secondary {
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--accent-1);
}

/* ============================================
   Info Bar
   ============================================ */
.info-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.info-item {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-align: center;
  transition: all var(--transition);
}

.info-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.info-value {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-1);
}

/* ============================================
   Validation Badge
   ============================================ */
.validation-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  transition: all var(--transition);
}
.validation-badge.valid {
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.3);
  color: var(--success);
}
.validation-badge.invalid {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.3);
  color: var(--error);
}

/* ============================================
   Grid
   ============================================ */
.grid-wrapper {
  display: flex;
  justify-content: center;
  padding: 20px 0;
}

.grid-container { display: inline-block; }

.grid-placeholder {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.wafaq-grid {
  display: grid;
  gap: var(--grid-gap);
  border: 2px solid var(--cell-border);
  border-radius: var(--radius-sm);
  padding: var(--grid-gap);
  background: var(--cell-border);
  box-shadow: var(--glow);
  transition: all var(--transition);
}

.wafaq-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-cell);
  border-radius: 3px;
  font-weight: 600;
  color: var(--cell-text);
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
  animation: cellAppear 0.4s ease-out both;
}
.wafaq-cell:hover {
  background: var(--accent-1);
  color: #fff;
  transform: scale(1.05);
  z-index: 2;
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.3);
}

@keyframes cellAppear {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

.wafaq-cell.center-cell {
  background: var(--bg-cell-center);
  border: 1px solid var(--border-accent);
}

.cell-number { font-size: 1rem; line-height: 1.2; }
.cell-letter {
  font-size: 0.95rem;
  line-height: 1.2;
  font-family: var(--font-main);
}
.cell-letter.arabic-letter { font-family: var(--font-arabic); font-size: 1.1rem; }

/* Combo mode */
.wafaq-cell.combo .cell-number { font-size: 0.8rem; color: var(--accent-3); }
.wafaq-cell.combo .cell-letter { font-size: 0.75rem; margin-top: 2px; }

/* RTL */
.wafaq-grid.rtl { direction: rtl; }

/* Grid sizes */
.wafaq-grid.grid-3 { grid-template-columns: repeat(3, 80px); }
.wafaq-grid.grid-3 .wafaq-cell { width: 80px; height: 80px; font-size: 1.3rem; }
.wafaq-grid.grid-4 { grid-template-columns: repeat(4, 72px); }
.wafaq-grid.grid-4 .wafaq-cell { width: 72px; height: 72px; font-size: 1.1rem; }
.wafaq-grid.grid-5 { grid-template-columns: repeat(5, 64px); }
.wafaq-grid.grid-5 .wafaq-cell { width: 64px; height: 64px; }
.wafaq-grid.grid-6 { grid-template-columns: repeat(6, 58px); }
.wafaq-grid.grid-6 .wafaq-cell { width: 58px; height: 58px; font-size: 0.9rem; }
.wafaq-grid.grid-7 { grid-template-columns: repeat(7, 52px); }
.wafaq-grid.grid-7 .wafaq-cell { width: 52px; height: 52px; font-size: 0.85rem; }
.wafaq-grid.grid-8 { grid-template-columns: repeat(8, 48px); }
.wafaq-grid.grid-8 .wafaq-cell { width: 48px; height: 48px; font-size: 0.8rem; }

/* Frame styles for export */
.grid-container.frame-simple {
  border: 3px double var(--accent-1);
  padding: 12px;
  border-radius: var(--radius-md);
}
.grid-container.frame-ornate {
  border: 2px solid var(--accent-1);
  padding: 16px;
  border-radius: var(--radius-md);
  box-shadow: inset 0 0 0 4px var(--bg-panel-solid), inset 0 0 0 5px var(--accent-1);
  position: relative;
}
.grid-container.frame-ornate::before,
.grid-container.frame-ornate::after {
  content: '✦';
  position: absolute;
  color: var(--accent-1);
  font-size: 1rem;
}
.grid-container.frame-ornate::before { top: -8px; left: 50%; transform: translateX(-50%); }
.grid-container.frame-ornate::after { bottom: -8px; left: 50%; transform: translateX(-50%); }

/* ============================================
   Export Actions
   ============================================ */
.export-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.export-options { flex: 1; min-width: 200px; }
.export-buttons { display: flex; gap: 8px; }

.btn-export {
  padding: 10px 18px;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
}
.btn-export:hover:not(:disabled) {
  color: var(--accent-1);
  border-color: var(--accent-1);
  transform: translateY(-1px);
}
.btn-export:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================
   Footer
   ============================================ */
.app-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 24px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  margin-top: 24px;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 600px) {
  .app-header { padding: 32px 16px 28px; }
  .app-title { font-size: 1.5rem; }
  .app-main { padding: 16px; gap: 16px; }
  .panel { padding: 16px; }
  .control-panel { position: static; }
  .info-bar { grid-template-columns: repeat(2, 1fr); }
  .wafaq-grid.grid-3 { grid-template-columns: repeat(3, 64px); }
  .wafaq-grid.grid-3 .wafaq-cell { width: 64px; height: 64px; }
  .wafaq-grid.grid-4 { grid-template-columns: repeat(4, 56px); }
  .wafaq-grid.grid-4 .wafaq-cell { width: 56px; height: 56px; }
  .wafaq-grid.grid-5 { grid-template-columns: repeat(5, 50px); }
  .wafaq-grid.grid-5 .wafaq-cell { width: 50px; height: 50px; }
  .wafaq-grid.grid-6 { grid-template-columns: repeat(6, 44px); }
  .wafaq-grid.grid-6 .wafaq-cell { width: 44px; height: 44px; font-size: 0.75rem; }
  .wafaq-grid.grid-7 { grid-template-columns: repeat(7, 40px); }
  .wafaq-grid.grid-7 .wafaq-cell { width: 40px; height: 40px; font-size: 0.7rem; }
  .wafaq-grid.grid-8 { grid-template-columns: repeat(8, 36px); }
  .wafaq-grid.grid-8 .wafaq-cell { width: 36px; height: 36px; font-size: 0.65rem; }
  .export-actions { flex-direction: column; align-items: stretch; }
  .theme-switcher { top: 8px; right: 8px; }
}
