:root {
  --bg-0: #090b14;
  --bg-1: #111528;
  --surface: rgba(21, 27, 48, 0.82);
  --surface-strong: #171e36;
  --border: rgba(148, 163, 184, 0.16);
  --border-bright: rgba(129, 140, 248, 0.45);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --accent-glow: rgba(99, 102, 241, 0.35);
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.14);
  --danger: #f43f5e;
  --danger-bg: rgba(244, 63, 94, 0.14);
  --warning: #f59e0b;
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --font-fa: 'Vazirmatn', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-en: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  background-color: var(--bg-0);
  color: var(--text);
  font-family: var(--font-fa);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(99, 102, 241, 0.22), transparent),
    radial-gradient(ellipse 60% 45% at 100% 100%, rgba(139, 92, 246, 0.16), transparent),
    radial-gradient(ellipse 50% 40% at 0% 80%, rgba(16, 185, 129, 0.08), transparent);
  display: flex;
  flex-direction: column;
}

.ltr {
  direction: ltr;
  unicode-bidi: isolate;
  font-family: var(--font-en);
}

.hidden {
  display: none !important;
}

/* Top Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  background: rgba(9, 11, 20, 0.78);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--text);
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  box-shadow: 0 6px 18px var(--accent-glow);
}

.brand-title {
  font-weight: 800;
  font-size: clamp(0.95rem, 0.8rem + 0.6vw, 1.15rem);
  letter-spacing: -0.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.player-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.14);
  border: 1px solid rgba(99, 102, 241, 0.32);
  font-size: 0.85rem;
  font-weight: 600;
  color: #c7d2fe;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 38px;
  padding: 0.45rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--border-bright);
  background: #1f2746;
}

.icon-btn:active {
  transform: scale(0.97);
}

/* Main Container */
.main-wrap {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem) 1rem 2.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Glass Card */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: clamp(1.25rem, 3vw, 2.25rem);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  animation: fadeSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Onboarding / Entry Screen */
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #6ee7b7;
  font-size: 0.8rem;
  font-weight: 600;
}

.hero-title {
  margin: 1rem 0 0.5rem;
  font-size: clamp(1.55rem, 1.2rem + 1.5vw, 2.2rem);
  font-weight: 800;
  line-height: 1.3;
}

.hero-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: clamp(0.92rem, 0.85rem + 0.3vw, 1.05rem);
  line-height: 1.75;
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.rule-box {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.rule-box .rule-emoji {
  font-size: 1.3rem;
}

.rule-box strong {
  font-size: 0.9rem;
}

.rule-box span {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.entry-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 1.25rem;
}

.input-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #e2e8f0;
}

.name-input-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

@media (min-width: 520px) {
  .name-input-row {
    flex-direction: row;
  }
}

.text-input {
  flex: 1;
  min-height: 48px;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(9, 11, 20, 0.8);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.primary-btn {
  min-height: 48px;
  padding: 0.8rem 1.5rem;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 10px 26px var(--accent-glow);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.primary-btn:hover {
  filter: brightness(1.08);
}

.primary-btn:active {
  transform: scale(0.98);
}

.lock-warning {
  margin: 0;
  font-size: 0.82rem;
  color: #fbbf24;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.locked-welcome {
  margin-top: 1.25rem;
  padding: 1rem;
  border-radius: var(--radius-lg);
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

/* HUD */
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.hearts-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.heart {
  font-size: 1.35rem;
  transition: transform 0.25s ease, opacity 0.25s ease, filter 0.25s ease;
}

.heart.lost {
  opacity: 0.22;
  filter: grayscale(1);
  transform: scale(0.82);
}

.hud-center {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-strong);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.hud-score {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

.score-chip {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #6ee7b7;
  font-size: 0.85rem;
  font-weight: 700;
}

.streak-chip {
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fcd34d;
  font-size: 0.82rem;
  font-weight: 700;
}

/* Progress Bar */
.progress-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #34d399);
  transition: width 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Verb Card */
.verb-stage {
  text-align: center;
  padding: 1.5rem 1rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.6), rgba(15, 23, 42, 0.75));
  border: 1px solid var(--border);
  position: relative;
}

.verb-stage.shake {
  animation: shakeX 0.42s ease;
}

@keyframes shakeX {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

.verb-tag {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.verb-word-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.verb-word {
  margin: 0;
  font-size: clamp(1.85rem, 1.3rem + 2.2vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.speak-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(99, 102, 241, 0.18);
  color: #c7d2fe;
  font-size: 1.1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, background 0.15s ease;
}

.speak-btn:hover {
  background: rgba(99, 102, 241, 0.34);
  transform: scale(1.06);
}

/* Category Choices */
.choices-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.7rem;
  margin-top: 1.25rem;
}

@media (min-width: 560px) {
  .choices-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.choice-btn {
  position: relative;
  min-height: 64px;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: rgba(15, 23, 42, 0.75);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  transition: transform 0.14s ease, border-color 0.15s ease, background 0.15s ease;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--border-bright);
  background: rgba(30, 41, 59, 0.9);
  transform: translateY(-2px);
}

.choice-btn:disabled {
  cursor: default;
}

.choice-title {
  font-family: var(--font-en);
  font-weight: 700;
  font-size: 1rem;
}

.choice-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.choice-btn.correct {
  border-color: var(--success);
  background: var(--success-bg);
  color: #a7f3d0;
}

.choice-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
  color: #fecdd3;
}

/* Reveal Learning Panel (English Definition + Example + Scratch Persian) */
.reveal-box {
  margin-top: 1.25rem;
  padding: 1.15rem;
  border-radius: var(--radius-lg);
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  animation: fadeSlideUp 0.28s ease;
}

.feedback-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 700;
}

.feedback-banner.is-correct {
  background: var(--success-bg);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.feedback-banner.is-wrong {
  background: var(--danger-bg);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.35);
}

.english-info {
  text-align: left;
  direction: ltr;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.def-text {
  margin: 0;
  font-family: var(--font-en);
  font-size: 0.96rem;
  color: #e2e8f0;
  line-height: 1.5;
}

.example-text {
  margin: 0;
  font-family: var(--font-en);
  font-size: 0.92rem;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.1);
  border-left: 3px solid var(--accent);
  padding: 0.5rem 0.75rem;
  border-radius: 0 8px 8px 0;
}

.grammar-tip {
  margin: 0;
  font-family: var(--font-en);
  font-size: 0.82rem;
  color: #94a3b8;
}

/* Scratch-Off Persian Meaning Card */
.scratch-container {
  position: relative;
  width: 100%;
  min-height: 78px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px dashed rgba(148, 163, 184, 0.35);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.12), rgba(99, 102, 241, 0.12));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.85rem 1rem;
  user-select: none;
  -webkit-user-select: none;
}

.scratch-secret {
  font-size: clamp(1rem, 0.9rem + 0.4vw, 1.15rem);
  font-weight: 700;
  color: #f8fafc;
  text-align: center;
  line-height: 1.6;
}

.scratch-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  transition: opacity 0.35s ease;
}

.scratch-canvas:active {
  cursor: grabbing;
}

.scratch-canvas.revealed {
  opacity: 0;
  pointer-events: none;
}

.next-btn {
  width: 100%;
}

/* Results & Leaderboard */
.result-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.result-emoji {
  font-size: 3rem;
  line-height: 1;
}

.result-title {
  margin: 0.65rem 0 0.35rem;
  font-size: clamp(1.4rem, 1.1rem + 1.2vw, 1.9rem);
  font-weight: 800;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
  margin: 1.25rem 0;
}

.stat-card {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.85rem 0.5rem;
  text-align: center;
}

.stat-val {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  color: #a5b4fc;
}

.stat-lbl {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Leaderboard Table */
.section-heading {
  margin: 1.5rem 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 2px;
}

.lb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

.lb-row.is-me {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.16);
}

.lb-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.lb-rank {
  width: 28px;
  text-align: center;
  font-weight: 800;
}

.lb-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.lb-score {
  font-weight: 800;
  color: #6ee7b7;
  white-space: nowrap;
}

/* Mistakes Review */
.mistakes-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.5rem;
}

.mistake-item {
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-md);
  background: rgba(244, 63, 94, 0.08);
  border: 1px solid rgba(244, 63, 94, 0.25);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.mistake-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.mistake-verb {
  font-family: var(--font-en);
  font-weight: 700;
  color: #fff;
}

.mistake-cat {
  font-family: var(--font-en);
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.2);
  color: #c7d2fe;
}

.mistake-fa {
  font-size: 0.84rem;
  color: #cbd5e1;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.result-actions > * {
  flex: 1;
  min-width: 160px;
}

/* Native Modal Dialog */
dialog {
  width: min(92vw, 520px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--bg-1);
  color: var(--text);
  padding: 1.5rem;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(5, 7, 14, 0.72);
  backdrop-filter: blur(6px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.dialog-header h2,
.dialog-header h1 {
  margin: 0;
  font-size: 1.2rem;
}
