:root {
  --bg: #0f1226;
  --bg-soft: #181c3a;
  --card-front: linear-gradient(145deg, #2a2f5e, #1c2046);
  --card-back: linear-gradient(145deg, #14532d, #0b3d22);
  --accent: #4ade80;
  --accent-2: #38bdf8;
  --text: #f1f5f9;
  --text-dim: #aab2d5;
  --tag-bg: rgba(56, 189, 248, 0.15);
  --tag-text: #7dd3fc;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --persian-font: "Vazirmatn", "Noto Naskh Arabic", "Tahoma", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Vazirmatn", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 50% -10%, #232a5c 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------- Header ---------- */
.site-header {
  text-align: center;
  padding: 2.5rem 1rem 1rem;
}
.site-header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle {
  color: var(--text-dim);
  max-width: 42rem;
  margin: 0.5rem auto 0;
  font-size: 1.05rem;
}

/* ---------- Intro ---------- */
.intro {
  display: flex;
  justify-content: center;
  padding: 1rem;
}
.intro-card {
  background: var(--bg-soft);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  max-width: 48rem;
  box-shadow: var(--shadow);
}
.intro-card h2 { margin-top: 0; font-size: 1.25rem; }
.legend {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.4rem;
}
.legend li { color: var(--text-dim); }
.legend-tag, .form-label {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.tip {
  margin-bottom: 0;
  color: var(--text);
}

/* ---------- Toolbar ---------- */
.toolbar {
  max-width: 1100px;
  margin: 1.5rem auto 0.5rem;
  padding: 0 1rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}
.search { flex: 1 1 260px; }
#search {
  width: 100%;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}
#search:focus { border-color: var(--accent-2); }
.ghost-btn {
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.92rem;
  transition: background 0.15s, border-color 0.15s;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.07); border-color: var(--accent-2); }

/* ---------- Card grid ---------- */
.card-grid {
  max-width: 1100px;
  margin: 1rem auto 3rem;
  padding: 0 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1.1rem;
}
.no-results {
  text-align: center;
  color: var(--text-dim);
  margin: 2rem;
}

/* ---------- Flashcard (3D flip) ---------- */
.flashcard {
  perspective: 1200px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  text-align: inherit;
  height: 320px;
}
.flashcard:focus-visible .card-inner {
  outline: 3px solid var(--accent-2);
  outline-offset: 3px;
  border-radius: var(--radius);
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
}
.flashcard.flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

/* Front */
.card-front {
  background: var(--card-front);
  align-items: center;
  justify-content: space-between;
}
.front-letter {
  font-family: var(--persian-font);
  font-size: 4.5rem;
  line-height: 1.1;
  margin-top: 0.4rem;
  direction: rtl;
}
.front-name {
  color: var(--text-dim);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: lowercase;
}
.forms {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.3rem;
  margin-top: auto;
}
.form-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 10px;
  padding: 0.4rem 0.2rem;
}
.form-glyph {
  font-family: var(--persian-font);
  font-size: 1.9rem;
  direction: rtl;
  min-height: 2.2rem;
  display: flex;
  align-items: center;
}
.form-label { font-size: 0.62rem; padding: 0.05rem 0.4rem; }
.flip-hint {
  position: absolute;
  top: 0.6rem; right: 0.7rem;
  font-size: 0.7rem;
  color: var(--text-dim);
  opacity: 0.8;
}

/* Back */
.card-back {
  background: var(--card-back);
  transform: rotateY(180deg);
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.45rem;
}
.back-letter {
  font-family: var(--persian-font);
  font-size: 2.6rem;
  direction: rtl;
}
.back-sound {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
}
.back-hint {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0 0 0.2rem;
}
.example-box {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
  padding: 0.6rem 0.8rem;
  width: 100%;
}
.example-fa {
  font-family: var(--persian-font);
  font-size: 1.5rem;
  direction: rtl;
}
.example-latin { color: var(--accent-2); font-size: 0.9rem; }
.example-en { color: var(--text-dim); font-size: 0.85rem; }

.speak-btn {
  margin-top: 0.4rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #07210f;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.12s, filter 0.12s;
}
.speak-btn:hover { filter: brightness(1.08); }
.speak-btn:active { transform: scale(0.96); }
.speak-btn.speaking { animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
}

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 1rem 1.5rem 3rem;
  max-width: 46rem;
  margin: 0 auto;
}

@media (prefers-reduced-motion: reduce) {
  .card-inner { transition: none; }
  .speak-btn.speaking { animation: none; }
}
