/* ===== CSS Custom Properties ===== */
:root {
  --bg-primary: #1a1614;
  --bg-secondary: #231f1b;
  --bg-glass: rgba(255, 255, 255, 0.05);
  --bg-glass-hover: rgba(255, 255, 255, 0.08);
  --border-glass: rgba(255, 255, 255, 0.1);
  --text-primary: #f0e6d3;
  --text-secondary: #b8a99a;
  --text-muted: #7a6b60;
  --accent: #c9a96e;
  --accent-hover: #d4b87e;
  --accent-dim: rgba(201, 169, 110, 0.15);
  --danger: #e07070;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.3);
  --transition: 0.2s ease;
  --font-ui: 'Cairo', 'Tajawal', system-ui, sans-serif;
}

.light-mode {
  --bg-primary: #f5f0ea;
  --bg-secondary: #ede7df;
  --bg-glass: rgba(0, 0, 0, 0.04);
  --bg-glass-hover: rgba(0, 0, 0, 0.07);
  --border-glass: rgba(0, 0, 0, 0.1);
  --text-primary: #1a1614;
  --text-secondary: #5a4a3a;
  --text-muted: #9a8a7a;
  --accent: #a07840;
  --accent-hover: #b08850;
  --accent-dim: rgba(160, 120, 64, 0.12);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.08);
}

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

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

body {
  font-family: var(--font-ui);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  direction: rtl;
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
}

/* ===== Glass Card ===== */
.glass-card {
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: var(--bg-glass);
  border-bottom: 1px solid var(--border-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.app-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
  direction: ltr;
  text-align: right;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

/* ===== Buttons ===== */
.btn-icon {
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  color: var(--text-primary);
}

.btn-icon:hover {
  background: var(--bg-glass-hover);
  border-color: var(--accent);
}

.btn-pill {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--accent);
  font-family: var(--font-ui);
  transition: var(--transition);
}

.btn-pill:hover, .btn-pill.active {
  background: var(--accent);
  color: var(--bg-primary);
}

.btn-primary {
  width: 100%;
  padding: 0.65rem 1rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--bg-primary);
  font-size: 0.9rem;
  font-family: var(--font-ui);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-preset {
  padding: 0.3rem 0.7rem;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: var(--transition);
}

.btn-preset:hover, .btn-preset.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== Main Layout ===== */
.app-main {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  padding: 1.5rem 2rem;
  min-height: calc(100vh - 80px);
  max-width: 1600px;
  margin: 0 auto;
}

/* ===== Controls Panel ===== */
.controls-panel {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  height: fit-content;
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-glass) transparent;
}

.controls-panel::-webkit-scrollbar {
  width: 4px;
}
.controls-panel::-webkit-scrollbar-track { background: transparent; }
.controls-panel::-webkit-scrollbar-thumb {
  background: var(--border-glass);
  border-radius: 2px;
}

.control-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.section-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.val-badge {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
  background: var(--accent-dim);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  letter-spacing: 0;
}

/* ===== Form Controls ===== */
.text-input {
  width: 100%;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: 'Amiri', serif;
  resize: vertical;
  min-height: 90px;
  transition: var(--transition);
  direction: rtl;
  line-height: 1.8;
}

.text-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-glass-hover);
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.preset-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 100%;
}

.select-control {
  width: 100%;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='%237a6b60'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.75rem center;
  padding-left: 2rem;
}

.select-control:focus {
  outline: none;
  border-color: var(--accent);
}

.select-sm {
  font-size: 0.8rem;
  padding: 0.4rem 0.6rem;
}

/* ===== Range Inputs ===== */
.range-control {
  width: 100%;
  appearance: none;
  height: 4px;
  background: var(--border-glass);
  border-radius: 2px;
  cursor: pointer;
  transition: var(--transition);
}

.range-control::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 6px rgba(201, 169, 110, 0.4);
  transition: var(--transition);
}

.range-control::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 12px rgba(201, 169, 110, 0.6);
}

.range-control::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

/* ===== Color Pickers ===== */
.color-row {
  display: flex;
  gap: 1rem;
}

.color-label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  flex: 1;
  cursor: pointer;
}

.color-label input[type="color"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 2px;
  background: var(--bg-glass);
  cursor: pointer;
}

/* ===== Toggles ===== */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border-glass);
  border-radius: 999px;
  transition: var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background: var(--accent);
}

/* ===== CSS Output ===== */
.css-output {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.75rem;
  font-family: 'Courier New', monospace;
  color: var(--accent);
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 160px;
  overflow-y: auto;
  margin-top: 0.5rem;
}

/* ===== Preview Area ===== */
.preview-area {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.preview-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.preview-header {
  padding: 0.65rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.font-name-badge {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
}

.preview-box {
  padding: 2.5rem;
  min-height: 280px;
  line-height: 1.8;
  word-break: break-word;
  overflow-wrap: break-word;
  transition: font-family 0.3s ease, font-size 0.15s ease, color 0.15s ease, background 0.15s ease;
  white-space: pre-wrap;
}

/* ===== Compare Mode ===== */
.compare-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.compare-top {
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.compare-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
}

.compare-selects {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.compare-selects span {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.compare-selects .select-control {
  width: 180px;
}

.compare-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.compare-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.compare-label {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  background: var(--accent-dim);
  border-radius: var(--radius-sm);
  text-align: center;
}

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

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--accent);
  color: var(--bg-primary);
  padding: 0.65rem 1.5rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font-ui);
  box-shadow: var(--shadow);
  z-index: 999;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.toast.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
}

/* ===== Utility ===== */
.hidden { display: none !important; }

/* ===== Scrollbar ===== */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-glass) transparent;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .app-main {
    grid-template-columns: 1fr;
    padding: 1rem;
  }

  .controls-panel {
    position: static;
    max-height: none;
    overflow-y: visible;
  }

  .compare-panels {
    grid-template-columns: 1fr;
  }

  .compare-selects .select-control {
    width: 140px;
  }
}

@media (max-width: 500px) {
  .app-header {
    padding: 0.75rem 1rem;
  }

  .app-title {
    font-size: 1.2rem;
  }

  .preview-box {
    padding: 1.5rem;
  }
}
