/* ==========================================================================
   Nateq - Arabic typing trainer
   ========================================================================== */

:root {
  color-scheme: dark;

  --bg: #000000;
  --bg-elevated: #0A0A0B;
  --panel: #101012;
  --panel-raised: #161618;
  --panel-soft: rgba(255, 255, 255, 0.035);

  --text: #F5F5F7;
  --text-soft: #D1D1D6;
  --muted: #8E8E93;
  --faint: #8E8E93;

  --accent: #10B981;
  --accent-strong: #34D399;
  --accent-soft: rgba(16, 185, 129, 0.11);
  --accent-line: rgba(16, 185, 129, 0.32);
  --accent-glow: rgba(16, 185, 129, 0.35);

  --correct: #10B981;
  --error: #F43F5E;
  --error-strong: #FB7185;
  --error-soft: rgba(244, 63, 94, 0.09);
  --error-line: rgba(244, 63, 94, 0.28);
  --error-glow: rgba(244, 63, 94, 0.35);

  --next: rgba(255, 255, 255, 0.22);

  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --border-glass: rgba(255, 255, 255, 0.07);
  --border-hover: rgba(255, 255, 255, 0.16);

  --surface-top: rgba(255, 255, 255, 0.04);
  --surface-bottom: rgba(255, 255, 255, 0.01);
  --surface-gradient: linear-gradient(180deg, var(--surface-top) 0%, var(--surface-bottom) 100%);
  --surface-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.12), 0 2px 8px -2px rgba(0, 0, 0, 0.8);
  --raised-surface: linear-gradient(180deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.07) 100%);
  --raised-shadow: 0 1px 3px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.15);

  /* Three-tier spatial depth: OLED base, recessed mid surfaces, floating glass. */
  --mid-surface: rgba(255, 255, 255, 0.02);
  --mid-border: rgba(255, 255, 255, 0.06);
  --mid-shadow: 0 8px 32px -8px rgba(0, 0, 0, 0.8), inset 0 1px 0 0 rgba(255, 255, 255, 0.08);
  --top-surface: rgba(14, 14, 16, 0.82);
  --top-border: rgba(255, 255, 255, 0.11);
  --top-shadow: 0 24px 64px -12px rgba(0, 0, 0, 0.95), 0 0 0 1px rgba(255, 255, 255, 0.05);
  --typed-gradient: linear-gradient(180deg, #FFFFFF 0%, #D4D4D8 100%);
  --mode-spring: cubic-bezier(0.16, 1, 0.3, 1);

  /* Directional specular light: bright top rim, shadowed lower lip, soft drop. */
  --specular-border: rgba(255, 255, 255, 0.08);
  --specular-rim:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 -1px 0 rgba(0, 0, 0, 0.6),
    0 4px 16px rgba(0, 0, 0, 0.5);
  --specular-rim-hover:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    inset 0 -1px 0 rgba(0, 0, 0, 0.6),
    0 4px 16px rgba(0, 0, 0, 0.5);

  --font-ui: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-arabic-modern: "IBM Plex Sans Arabic", "Noto Sans Arabic", "SF Arabic", "Segoe UI", sans-serif;
  --font-arabic-classical: "Amiri", "Noto Naskh Arabic", "Traditional Arabic", serif;
  --font-arabic-display: "Readex Pro", -apple-system, sans-serif;
  --font-arabic: var(--font-arabic-modern);
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;

  --radius-sm: 0.45rem;
  --radius-md: 0.8rem;
  --radius-lg: 1.15rem;

  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --shadow-soft: 0 30px 80px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  --content-width: 1120px;
}

/* Arabic typeface modes. The class lives on <html> so every `[lang="ar"]`
   surface, the stage word, queue, modals, and results switch together. */
html.font-modern {
  --font-arabic: var(--font-arabic-modern);
}

html.font-classical {
  --font-arabic: var(--font-arabic-classical);
}

html.font-display {
  --font-arabic: var(--font-arabic-display);
}

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

html {
  min-width: 320px;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -15%, rgba(16, 185, 129, 0.05) 0%, transparent 55%),
    radial-gradient(circle at 80% 120%, rgba(244, 63, 94, 0.025) 0%, transparent 45%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

::selection {
  background: rgba(16, 185, 129, 0.35);
  color: var(--text);
}

[lang="ar"] {
  font-family: var(--font-arabic);
}

[hidden] {
  display: none !important;
}

svg {
  display: block;
}

kbd {
  display: inline-block;
  min-width: 1.25rem;
  padding: 2px 5px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  color: #8E8E93;
  font-family: ui-monospace, monospace;
  font-size: 0.7rem;
  line-height: 1.35;
  text-align: center;
  white-space: nowrap;
}

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

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 1000;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #000000;
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-200%);
  transition: transform 160ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

/* --------------------------------------------------------------------------
   Shell
   -------------------------------------------------------------------------- */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
  padding: 0 clamp(1.1rem, 4vw, 3rem);
}

.site-header,
.main-content {
  width: min(100%, var(--content-width));
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.6rem 0 1.15rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  user-select: none;
}

.brand-arabic {
  color: var(--accent);
  font-family: var(--font-arabic);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1;
  transform: translateY(-1px);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  padding-left: 0.8rem;
  border-left: 1px solid var(--border-strong);
}

.brand-name {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  line-height: 1.1;
}

.brand-subtitle {
  color: var(--faint);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: uppercase;
}

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

.icon-button {
  display: inline-grid;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  place-items: center;
  border: 1px solid var(--mid-border);
  border-radius: 999px;
  background: var(--mid-surface);
  color: var(--muted);
  box-shadow: var(--mid-shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition:
    color 150ms ease,
    background-color 150ms ease,
    border-color 150ms ease,
    transform 120ms var(--ease-out-expo);
}

.icon-button:hover {
  border-color: var(--border-hover);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.02) 100%);
  color: var(--text);
  transform: translateY(-1px);
}

.icon-button:active {
  transform: scale(0.94);
}

.icon-button svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.65;
}

.icon-button--compact {
  width: 2.15rem;
  height: 2.15rem;
}

.icon-button--help {
  border-color: var(--border-glass);
  background: var(--surface-gradient);
}

.hint-mark {
  display: grid;
  width: 1.3rem;
  height: 1.3rem;
  place-items: center;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1;
}

/* Machined typeface switcher pill */
.font-selector {
  display: flex;
  align-items: center;
}

.font-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  min-height: 2.15rem;
  padding: 0.34rem 0.62rem 0.34rem 0.5rem;
  border: 1px solid var(--specular-border);
  border-radius: 999px;
  background: var(--mid-surface);
  box-shadow: var(--specular-rim);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition:
    color 150ms ease,
    border-color 150ms ease,
    background-color 150ms ease,
    transform 120ms var(--ease-out-expo);
}

.font-pill:hover {
  border-color: var(--border-hover);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.02) 100%);
  box-shadow: var(--specular-rim-hover);
  color: var(--text);
  transform: translateY(-1px);
}

.font-pill:active {
  transform: scale(0.985);
}

.font-pill-mark {
  display: grid;
  width: 1.45rem;
  height: 1.45rem;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  color: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.font-pill-name {
  min-width: 3.9rem;
  max-width: 6.2rem;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
}

.font-pill-chevron {
  width: 0.62rem;
  height: 0.62rem;
  fill: none;
  stroke: var(--faint);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 160ms var(--ease-out-expo);
}

.font-pill:hover .font-pill-chevron {
  stroke: var(--text-soft);
}

.main-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  padding-bottom: 0.7rem;
}

/* --------------------------------------------------------------------------
   Controls
   -------------------------------------------------------------------------- */

.control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.45rem;
}

.mode-tabs {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.18rem;
  min-width: 0;
  padding: 3px;
  overflow-x: auto;
  border: 1px solid var(--specular-border);
  border-radius: 9999px;
  background: var(--mid-surface);
  box-shadow: var(--specular-rim);
  isolation: isolate;
  scrollbar-width: none;
  transition: box-shadow 160ms ease;
}

.mode-tabs:hover {
  box-shadow: var(--specular-rim-hover);
}

.mode-tabs::-webkit-scrollbar {
  display: none;
}

.mode-sliding-pill {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  z-index: 0;
  width: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.22s var(--mode-spring),
    width 0.22s var(--mode-spring),
    opacity 120ms ease;
  will-change: transform, width;
}

.mode-sliding-pill.is-ready {
  opacity: 1;
}

.mode-sliding-pill.is-instant {
  transition: none !important;
}

.mode-tab {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  padding: 0.42rem 0.78rem;
  border: 1px solid transparent;
  border-radius: 9999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition:
    color 130ms ease,
    background-color 160ms var(--ease-out-expo),
    border-color 160ms var(--ease-out-expo),
    box-shadow 180ms var(--ease-out-expo),
    transform 120ms var(--ease-out-expo);
}

.mode-tab:hover {
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.035);
}

.mode-tab:active {
  transform: scale(0.985);
}

.mode-tab.is-active {
  border-color: transparent;
  background: transparent;
  color: #FFFFFF;
  font-weight: 500;
  box-shadow: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.mode-tab.is-active::before {
  display: none;
}

.test-options {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.script-control {
  display: flex;
  gap: 0.12rem;
  padding: 3px;
  border: 1px solid var(--mid-border);
  border-radius: 999px;
  background: var(--mid-surface);
  box-shadow: var(--mid-shadow);
}

.script-tab {
  min-width: 2.6rem;
  padding: 0.26rem 0.6rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.4;
  letter-spacing: 0.02em;
  transition:
    color 150ms ease,
    background-color 150ms ease,
    transform 120ms var(--ease-out-expo);
}

.script-tab--arabic {
  font-family: var(--font-arabic);
  font-size: 0.82rem;
  letter-spacing: 0;
}

.script-tab:hover {
  color: var(--text-soft);
}

.script-tab.is-active {
  background: var(--raised-surface);
  color: var(--text);
  box-shadow: var(--raised-shadow);
}

.script-tab--arabic.is-active {
  color: var(--accent);
}

.count-control {
  display: flex;
  gap: 0.12rem;
  padding: 3px;
  border: 1px solid var(--mid-border);
  border-radius: 999px;
  background: var(--mid-surface);
  box-shadow: var(--mid-shadow);
}

.count-button {
  min-width: 2.35rem;
  padding: 0.28rem 0.55rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.4;
  transition:
    color 150ms ease,
    background-color 150ms ease,
    transform 120ms var(--ease-out-expo);
}

.count-button:hover {
  color: var(--text-soft);
}

.count-button.is-active {
  background: var(--raised-surface);
  color: var(--text);
  box-shadow: var(--raised-shadow);
}

.script-tab:active,
.count-button:active {
  transform: scale(0.985);
}

/* --------------------------------------------------------------------------
   Live stats
   -------------------------------------------------------------------------- */

.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(4rem, auto)) minmax(8rem, 1fr);
  align-items: center;
  gap: clamp(1rem, 2.4vw, 2.2rem);
  margin-top: 1.15rem;
  padding: 0.86rem 1.35rem 0.78rem;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
  box-shadow:
    inset 0 2px 10px rgba(0, 0, 0, 0.6),
    inset 0 -1px 0 rgba(255, 255, 255, 0.04),
    0 1px 0 rgba(255, 255, 255, 0.03);
}

.stat-cell {
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  min-width: 0;
}

.stat-value {
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 1.22rem;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  line-height: 1.15;
  transition: color 160ms ease;
  transform: none;
  animation: none;
}

.stat-value.has-value {
  color: var(--text);
}

#statWpm.has-value {
  color: var(--accent);
  text-shadow: 0 0 18px rgba(16, 185, 129, 0.28);
}

#statAccuracy.is-warning {
  color: var(--error-strong);
  text-shadow: 0 0 18px rgba(244, 63, 94, 0.22);
}

.stat-label {
  color: var(--faint);
  font-size: 0.63rem;
  font-weight: 500;
  letter-spacing: 0.13em;
  line-height: 1.2;
  text-transform: uppercase;
}

.stat-progress {
  min-width: 0;
}

.progress-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.progress-meta > span:first-child {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 3px;
  overflow: hidden;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.55);
}

.progress-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #10B981 0%, #34D399 100%);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.6);
  transition: width 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* --------------------------------------------------------------------------
   Data loading and recovery
   -------------------------------------------------------------------------- */

.data-error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.9rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--error-line);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(244, 63, 94, 0.09) 0%, rgba(244, 63, 94, 0.035) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 8px 28px -12px rgba(0, 0, 0, 0.9);
  animation: fade-up 180ms ease both;
}

.data-error-copy {
  min-width: 0;
}

.data-error-copy strong {
  display: block;
  margin-bottom: 0.15rem;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
}

.data-error-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
}

.data-error-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.55rem;
}

.data-error-switch {
  color: var(--faint);
  font-size: 0.72rem;
}

.data-error-select {
  min-height: 2.15rem;
  padding: 0.35rem 1.7rem 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--panel);
  color: var(--text-soft);
  font-size: 0.76rem;
}

.typing-skeleton {
  display: flex;
  width: 100%;
  min-height: clamp(10rem, 24vh, 15rem);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: 1rem;
}

.skeleton-line,
.skeleton-arabic {
  border-radius: 999px;
  background:
    linear-gradient(
      100deg,
      rgba(255, 255, 255, 0.045) 20%,
      rgba(255, 255, 255, 0.1) 40%,
      rgba(255, 255, 255, 0.045) 60%
    );
  background-size: 240% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

.skeleton-line--meta {
  width: 9rem;
  height: 0.55rem;
  opacity: 0.7;
}

.skeleton-arabic {
  width: min(48%, 15rem);
  height: clamp(2.2rem, 5vw, 3rem);
  border-radius: 0.7rem;
}

.skeleton-line--input {
  width: min(38%, 11rem);
  height: 1.15rem;
}

.skeleton-caption {
  margin: 0.15rem 0 0;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 120% 0;
  }
  100% {
    background-position: -120% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-line,
  .skeleton-arabic {
    animation: none;
  }
}

@media (max-width: 700px) {
  .data-error-banner {
    align-items: stretch;
    flex-direction: column;
  }

  .data-error-actions {
    flex-wrap: wrap;
  }
}

/* --------------------------------------------------------------------------
   Test stage and words
   -------------------------------------------------------------------------- */

.test-stage {
  position: relative;
  display: flex;
  min-height: clamp(20rem, 40vh, 27rem);
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  margin-top: 1rem;
  padding: 48px 32px;
  isolation: isolate;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 24px;
  background:
    radial-gradient(circle 260px at 50% 38%, rgba(16, 185, 129, 0.035) 0%, transparent 80%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02) 0%, rgba(255, 255, 255, 0.005) 100%);
  box-shadow:
    0 30px 80px -20px rgba(0, 0, 0, 0.9),
    inset 0 1px 0 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  outline: none;
}

.prompt {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0 0;
}

.prompt-head {
  display: flex;
  width: min(100%, 52rem);
  align-items: center;
  gap: 0.65rem;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.prompt-counter {
  color: var(--muted);
}

.prompt-mode {
  padding-left: 0.65rem;
  border-left: 1px solid var(--border);
  color: var(--faint);
  font-family: var(--font-ui);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.prompt-tools {
  display: flex;
  align-items: center;
  gap: 0.32rem;
  margin-left: auto;
}

.hint-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.24rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--faint);
  font-family: var(--font-ui);
  font-size: 0.66rem;
  letter-spacing: 0.02em;
  transition:
    border-color 150ms ease,
    color 150ms ease,
    background-color 150ms ease,
    opacity 150ms ease;
}

.hint-button:hover {
  border-color: var(--border-strong);
  background: var(--panel-soft);
  color: var(--text-soft);
}

.hint-button kbd {
  font-size: 0.7rem;
}

.hint-button--clear {
  color: rgba(244, 63, 94, 0.72);
}

.hint-button--clear:hover {
  border-color: rgba(244, 63, 94, 0.3);
  background: rgba(244, 63, 94, 0.06);
  color: var(--error);
}

.hint-button:disabled {
  cursor: default;
  opacity: 0.38;
}

.hint-button:disabled:hover {
  border-color: var(--border);
  background: transparent;
  color: rgba(244, 63, 94, 0.72);
}

.prompt-arabic {
  max-width: 100%;
  min-height: 1.65em;
  margin: clamp(1.5rem, 3.6vh, 2.6rem) 0 clamp(0.9rem, 2vh, 1.3rem);
  padding-block: 0.08em;
  color: var(--text);
  font-family: var(--font-arabic);
  font-size: clamp(2.8rem, 1.55rem + 3.4vw, 4.05rem);
  font-weight: 600;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  letter-spacing: 0;
  line-height: 1.65;
  overflow: visible;
  overflow-wrap: anywhere;
  text-align: center;
  text-rendering: optimizeLegibility;
  text-shadow: 0 0 55px rgba(245, 245, 247, 0.07);
  text-wrap: balance;
  transition: color 180ms ease;
}

.prompt-arabic.is-word-switch {
  animation: word-focus 90ms ease-out both;
}

html.font-classical .prompt-arabic {
  font-weight: 700;
}

html.font-display .prompt-arabic {
  font-weight: 600;
}

html.font-classical .queue-ar,
html.font-classical .mapping-arabic {
  font-weight: 400;
}

html.font-classical .brand-arabic,
html.font-classical .onboarding-arabic,
html.font-classical .prompt-latin[lang="ar"] {
  font-weight: 700;
}

.prompt-input-wrap {
  position: relative;
  display: flex;
  width: 100%;
  min-height: 2.8rem;
  align-items: baseline;
  justify-content: center;
}

.prompt-latin {
  display: flex;
  min-height: 1.7em;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: clamp(1.3rem, 1.05rem + 0.85vw, 1.7rem);
  font-variant-ligatures: none;
  letter-spacing: 0.11em;
  line-height: 1.6;
  text-align: center;
  unicode-bidi: isolate;
  white-space: pre-wrap;
  transition: color 160ms ease;
}

/* Arabic letters are matched against the word, not the transliteration, so
   they must be laid out right-to-left. `isolate` keeps that direction from
   leaking into the surrounding headers and stats. */
.prompt-latin[dir="rtl"] {
  direction: rtl;
  justify-content: center;
}

.prompt-latin.is-error {
  animation: word-nudge 180ms ease;
}

.prompt-hint {
  position: absolute;
  bottom: calc(100% + 0.55rem);
  left: 50%;
  z-index: 4;
  max-width: min(90vw, 22rem);
  padding: 0.38rem 0.68rem;
  transform: translate(-50%, 0.35rem);
  border: 1px solid var(--top-border);
  border-radius: 0.45rem;
  background: rgba(14, 14, 16, 0.9);
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
  white-space: nowrap;
}

.prompt-hint::after {
  position: absolute;
  bottom: -0.32rem;
  left: 50%;
  width: 0.5rem;
  height: 0.5rem;
  transform: translateX(-50%) rotate(45deg);
  border-right: 1px solid var(--top-border);
  border-bottom: 1px solid var(--top-border);
  background: rgba(14, 14, 16, 0.9);
  content: "";
}

.prompt-hint.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.prompt-hint.is-auto {
  border-color: rgba(16, 185, 129, 0.4);
  color: var(--correct);
}

.prompt-hint.is-auto::after {
  border-color: rgba(16, 185, 129, 0.4);
}

/* --------------------------------------------------------------------------
   Real-Time Word Completion Feedback Banner
   -------------------------------------------------------------------------- */

.word-feedback {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 2.35rem;
  height: 2.35rem;
  margin: 0.35rem 0 0.2rem;
  pointer-events: none;
  overflow: hidden;
}

.word-feedback-content {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  max-width: min(94vw, 38rem);
  padding: 6px 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 9999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.01) 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  opacity: 0;
  transform: translateY(2px);
  transition:
    opacity 120ms ease-in-out,
    transform 160ms var(--mode-spring),
    border-color 180ms ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.word-feedback.is-visible .word-feedback-content {
  opacity: 1;
  transform: translateY(0);
}

.word-feedback.is-word-change .word-feedback-content {
  animation: subtitle-refresh 120ms ease-in-out both;
}

.word-feedback-dialect {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Dialect tag themes */
.word-feedback-dialect.is-levantine,
.review-dialect-tag.is-levantine {
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #34D399;
}

.word-feedback-dialect.is-msa,
.review-dialect-tag.is-msa {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-soft);
}

.word-feedback-dialect.is-both,
.review-dialect-tag.is-both {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34D399;
}

.word-feedback-translation {
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.84rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.word-feedback-notes {
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  max-width: 20rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.word-feedback-notes::before {
  content: "•";
  margin-right: 0.45rem;
  opacity: 0.55;
}

.prompt-help {
  margin: 0.9rem 0 0;
  color: var(--faint);
  font-size: 0.7rem;
  line-height: 1.6;
  text-align: center;
}

.prompt-help kbd {
  font-size: 0.7rem;
}

.queue-wrap {
  display: flex;
  width: 100%;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: clamp(0.75rem, 2vh, 1.2rem);
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  overflow: hidden;
}

.queue-label {
  flex: 0 0 auto;
  color: var(--faint);
  font-size: 0.58rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.words {
  display: flex;
  min-width: 0;
  max-width: 100%;
  flex: 1 1 0;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.25rem 0.8rem;
  direction: rtl;
  padding: 0.15rem 0;
  mask-image: linear-gradient(to right, transparent, black 15%, black 85%, transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, black 15%, black 85%, transparent);
}

.queue-item {
  display: inline-flex;
  align-items: center;
  color: var(--next);
  opacity: 1;
  transition: color 180ms ease;
}

.queue-ar {
  font-family: var(--font-arabic);
  font-size: 1.2rem;
  font-weight: 500;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  letter-spacing: 0;
  line-height: 1.65;
  white-space: nowrap;
}

.queue-more {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.66rem;
}

.review-line {
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.6rem;
  max-width: 100%;
  margin: 0.85rem auto 0;
  padding: 0.42rem 0.8rem;
  border: 1px solid var(--error-line);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(244, 63, 94, 0.09) 0%, rgba(244, 63, 94, 0.03) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.5;
  animation: fade-up 180ms ease both;
}

.review-line .review-arabic {
  color: var(--error);
  font-family: var(--font-arabic);
  font-size: 1.02rem;
  font-weight: 500;
  letter-spacing: 0;
}

.review-line code {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.latin-typed {
  background: var(--typed-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  font-weight: 500;
  text-shadow: none;
}

/* Arabic script mode: the typed word stays connected across spans via ZWJ. */
.prompt-latin[lang="ar"] {
  display: inline-block;
  gap: 0;
  font-family: var(--font-arabic);
  font-size: clamp(1.75rem, 1.35rem + 1.2vw, 2.3rem);
  font-variant-ligatures: normal;
  font-feature-settings: "liga" 1, "calt" 1;
  font-weight: 600;
  letter-spacing: 0;
}

.prompt-latin[lang="ar"].is-long {
  font-size: clamp(1.4rem, 1.1rem + 0.95vw, 1.85rem);
}

.arabic-letter {
  display: inline;
  color: rgba(255, 255, 255, 0.15);
  transition: color 120ms ease;
  font-feature-settings: "liga" 1, "calt" 1, "ccmp" 1;
}

.arabic-space {
  display: inline-block;
  width: 0.38em;
  white-space: pre;
}

.arabic-letter.is-typed {
  background: var(--typed-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  text-shadow: none;
}

.arabic-letter.is-wrong {
  color: var(--error);
  text-decoration: none;
  text-shadow: 0 0 10px rgba(244, 63, 94, 0.45);
  animation: error-flash 180ms ease-out both;
}

.arabic-letter.is-extra {
  color: var(--error);
  text-decoration: none;
  text-shadow: 0 0 10px rgba(244, 63, 94, 0.45);
  animation: error-flash 180ms ease-out both;
}

.prompt-latin[lang="ar"] .caret {
  display: inline-block;
  width: 2.5px;
  height: 1.18em;
  margin: 0 0.08em;
  border-radius: 2px;
  border-left: none;
  background: #FFFFFF;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
  vertical-align: middle;
  animation: caret-pulse 0.95s ease-in-out infinite;
}

.prompt-hint.is-arabic {
  font-family: var(--font-arabic);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0;
}

.review-line .review-arabic-answer,
.results-review .review-arabic-answer {
  color: var(--correct);
  font-family: var(--font-arabic);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0;
}

.results-review .review-arabic-answer {
  font-size: 1.15rem;
}

.latin-placeholder {
  color: rgba(255, 255, 255, 0.15);
  opacity: 1;
}

.latin-error {
  color: var(--error);
  text-decoration: none;
  text-shadow: 0 0 10px rgba(244, 63, 94, 0.45);
  animation: error-flash 180ms ease-out both;
}

.caret {
  display: inline-block;
  width: 2.5px;
  height: 1.18em;
  margin: 0 0.08em;
  border-radius: 2px;
  background: #FFFFFF;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
  vertical-align: middle;
  animation: caret-pulse 0.95s ease-in-out infinite;
  transition: transform 70ms ease-out;
}

.is-paused .caret {
  opacity: 0.25;
  animation-play-state: paused;
}

.focus-badge {
  position: static;
  display: inline-flex;
  align-self: center;
  align-items: center;
  gap: 0.48rem;
  margin: 0.8rem auto 0;
  padding: 0.38rem 0.7rem;
  border: 1px solid var(--border-glass);
  border-radius: 999px;
  background: var(--surface-gradient);
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: var(--surface-shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.focus-dot {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
}

.instruction-line {
  min-height: 1.5em;
  margin: 0.1rem 0 0;
  color: var(--faint);
  font-size: 0.78rem;
  text-align: center;
}

/* --------------------------------------------------------------------------
   Results
   -------------------------------------------------------------------------- */

.results {
  width: 100%;
  max-height: min(92svh, 52rem);
  margin: 0;
  padding: clamp(1.25rem, 4vw, 1.9rem);
  overflow-y: auto;
  text-align: center;
  scrollbar-width: thin;
  animation: fade-up 280ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.results-dialog {
  position: fixed;
  inset: 0;
  width: min(92vw, 46rem);
  max-width: min(92vw, 46rem);
  height: fit-content;
  max-height: min(92svh, 52rem);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--top-border);
  border-radius: var(--radius-lg);
  background: var(--top-surface);
  box-shadow: var(--top-shadow);
  backdrop-filter: blur(24px) saturate(190%);
  -webkit-backdrop-filter: blur(24px) saturate(190%);
}

.results-dialog[open] {
  animation: modal-in 140ms ease-out both;
}

.results-kicker {
  margin: 0 0 0.7rem;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.results-hero {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.results-wpm {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: clamp(4rem, 9vw, 6.4rem);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.07em;
  line-height: 0.95;
  text-shadow: 0 0 50px rgba(16, 185, 129, 0.22);
}

.results-unit {
  color: var(--accent);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.06em;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin: 0 auto 1.6rem;
  padding: 1rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.results-grid .stat-badge {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--surface-gradient);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 0.85rem 0.65rem;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.results-grid .stat-badge:hover {
  border-color: var(--border-hover);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.02) 100%);
  transform: translateY(-1px);
}

.result-label {
  color: var(--faint);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.results-grid strong {
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.results-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.results-review {
  width: min(100%, 36rem);
  margin: 0 auto 1.4rem;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  background: var(--surface-gradient);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  text-align: left;
}

.results-review-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

.results-review-tabs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

#reviewMistakesCount {
  color: var(--error-strong);
}

.review-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 150ms ease;
}

.review-tab:hover {
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.04);
}

.review-tab.is-active {
  background: var(--raised-surface);
  border-color: rgba(255, 255, 255, 0.09);
  color: var(--text);
  box-shadow: var(--raised-shadow);
}

.review-toggle-all-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.22rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.65rem;
  cursor: pointer;
  transition: all 150ms ease;
}

.review-toggle-all-button:hover {
  border-color: var(--border-strong);
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.04);
}

.review-toggle-all-button.is-active {
  border-color: var(--accent-line);
  color: var(--accent);
  background: var(--accent-soft);
}

.results-review ul {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 14.5rem;
  margin: 0;
  padding: 0 0.25rem 0 0;
  overflow-y: auto;
  list-style: none;
  scrollbar-width: thin;
}

.results-review li.review-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: background-color 150ms ease, border-color 150ms ease;
}

.results-review li.review-item:hover {
  background: rgba(255, 255, 255, 0.035);
  border-color: var(--border-hover);
}

.results-review li.review-item.is-missed {
  border-left: 3px solid var(--error);
  background: linear-gradient(90deg, rgba(244, 63, 94, 0.07) 0%, rgba(255, 255, 255, 0.02) 42%);
  box-shadow: inset 2px 0 10px -4px var(--error-glow);
}

.results-review li.review-item.is-correct {
  border-left: 3px solid var(--correct);
}

.review-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem 0.65rem;
}

.review-flow {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.4rem 0.6rem;
}

.results-review .review-arabic {
  color: var(--text);
  font-family: var(--font-arabic);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.4;
}

.review-arrow {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.review-typed {
  padding: 0.08rem 0.4rem;
  border-radius: 0.28rem;
  background: rgba(244, 63, 94, 0.09);
  color: var(--error);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-decoration: line-through;
  text-decoration-color: rgba(244, 63, 94, 0.55);
}

.review-target-translit {
  padding: 0.08rem 0.42rem;
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 0.28rem;
  background: rgba(16, 185, 129, 0.07);
  color: var(--correct);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.review-retry-single-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 140ms ease;
}

.review-retry-single-btn:hover {
  border-color: var(--accent);
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-strong);
  transform: translateY(-1px);
}

.review-accepted {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.review-label {
  color: var(--faint);
  font-size: 0.56rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.results-review .review-accepted code {
  padding: 0.06rem 0.34rem;
  border: 1px solid rgba(16, 185, 129, 0.18);
  border-radius: 0.28rem;
  background: rgba(16, 185, 129, 0.06);
  color: var(--correct);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  text-align: left;
}

.review-meta-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
}

.review-meaning-wrap {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.review-dialect-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.06rem 0.4rem;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.review-meaning-text {
  color: var(--text-soft);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 500;
}

.review-note-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.12rem 0.42rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.62rem;
  cursor: pointer;
  transition: all 140ms ease;
}

.review-note-toggle-btn:hover {
  border-color: var(--border-strong);
  color: var(--accent);
  background: var(--panel-raised);
}

.review-note-toggle-btn.is-open {
  border-color: var(--accent-line);
  color: var(--accent);
  background: var(--accent-soft);
}

.review-note-drawer {
  margin-top: 0.2rem;
  padding: 0.38rem 0.6rem;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.25);
  border: 1px dashed rgba(16, 185, 129, 0.25);
  color: var(--text-soft);
  font-size: 0.72rem;
  line-height: 1.45;
  animation: fade-up 150ms ease both;
}

.review-empty-state {
  padding: 1.5rem 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.results-hint {
  margin: 1rem 0 0;
  color: var(--faint);
  font-size: 0.72rem;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.55rem;
  padding: 0.58rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.2;
  text-transform: lowercase;
  transition:
    background-color 150ms ease,
    border-color 150ms ease,
    color 150ms ease,
    box-shadow 160ms ease,
    transform 120ms var(--ease-out-expo);
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: scale(0.985);
}

.button--primary {
  border-color: rgba(255, 255, 255, 0.12);
  background: linear-gradient(180deg, #34D399 0%, #10B981 100%);
  color: #000000;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 4px 16px -6px rgba(16, 185, 129, 0.5);
}

.button--primary:hover {
  background: linear-gradient(180deg, #4ADE80 0%, #10B981 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32), 0 6px 20px -6px rgba(16, 185, 129, 0.55);
}

.button--primary kbd {
  border-color: rgba(0, 0, 0, 0.2);
  border-bottom-color: rgba(0, 0, 0, 0.35);
  background: rgba(0, 0, 0, 0.12);
  color: rgba(0, 0, 0, 0.72);
}

.button--ghost {
  border-color: var(--border-glass);
  background: var(--surface-gradient);
  color: var(--muted);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.button--ghost:hover {
  border-color: var(--border-hover);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.02) 100%);
  color: var(--text-soft);
}

.button--accent {
  border: 1px solid rgba(16, 185, 129, 0.42);
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.16) 0%, rgba(16, 185, 129, 0.08) 100%);
  color: var(--accent-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 0 24px -10px rgba(16, 185, 129, 0.5);
}

.button--accent:hover {
  border-color: var(--accent-strong);
  background: rgba(16, 185, 129, 0.22);
  color: #ffffff;
}

.button--accent kbd {
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-strong);
}

.button--small {
  min-height: 2.15rem;
  padding: 0.45rem 0.75rem;
  font-size: 0.76rem;
}

.text-button {
  padding: 0.2rem;
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 0.72rem;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 0.2em;
  transition:
    color 150ms ease,
    text-decoration-color 150ms ease;
}

.text-button:hover {
  color: var(--text-soft);
  text-decoration-color: currentColor;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */

.test-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: auto;
  padding: 0.8rem 0 1.6rem;
  border-top: 1px solid var(--border);
}

.shortcuts {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem 1rem;
  color: var(--faint);
  font-size: 0.7rem;
}

.shortcuts span {
  display: inline-flex;
  align-items: center;
  gap: 0.33rem;
}

.shortcuts kbd {
  font-size: 0.7rem;
}

/* --------------------------------------------------------------------------
   Typing capture
   -------------------------------------------------------------------------- */

.typing-input {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 1;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
  caret-color: transparent;
  font-size: 16px;
}

/* --------------------------------------------------------------------------
   Dialogs
   -------------------------------------------------------------------------- */

dialog {
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  animation: backdrop-in 140ms ease both;
}

.modal-dialog {
  width: min(92vw, 38rem);
  max-height: min(90svh, 48rem);
  padding: 0;
  overflow: visible;
  border: 1px solid var(--top-border);
  border-radius: var(--radius-lg);
  background: var(--top-surface);
  box-shadow: var(--top-shadow);
  backdrop-filter: blur(24px) saturate(190%);
  -webkit-backdrop-filter: blur(24px) saturate(190%);
}

.modal-dialog[open] {
  animation: modal-in 140ms ease-out both;
}

.modal-card {
  max-height: calc(90svh - 2px);
  overflow-y: auto;
  padding: clamp(1.25rem, 4vw, 1.8rem);
}

.modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.3rem;
}

.eyebrow {
  margin: 0 0 0.28rem;
  color: var(--accent);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.modal-heading h2 {
  margin: 0;
  color: var(--text);
  font-size: clamp(1.35rem, 3vw, 1.7rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.field-label {
  display: block;
  margin-bottom: 0.55rem;
  color: var(--text-soft);
  font-size: 0.82rem;
  font-weight: 500;
}

.custom-textarea {
  display: block;
  width: 100%;
  min-height: 11rem;
  padding: 0.85rem 1rem;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-arabic);
  font-size: 1.22rem;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 2;
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.custom-textarea::placeholder {
  color: var(--faint);
}

.custom-textarea:focus {
  border-color: rgba(16, 185, 129, 0.55);
  outline: none;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.08);
}

.field-help {
  margin: 0.65rem 0 0;
  color: var(--faint);
  font-size: 0.73rem;
  line-height: 1.65;
}

.form-error {
  margin: 0.75rem 0 0;
  color: var(--error);
  font-size: 0.78rem;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 1.4rem;
}

/* Sheet */

.sheet-dialog {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(100vw, 28rem);
  max-width: none;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-left: 1px solid var(--top-border);
  background: var(--top-surface);
  box-shadow: var(--top-shadow);
  backdrop-filter: blur(24px) saturate(190%);
  -webkit-backdrop-filter: blur(24px) saturate(190%);
}

.sheet-dialog[open] {
  animation: sheet-in 260ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.sheet-shell {
  display: flex;
  height: 100%;
  flex-direction: column;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.05rem 0.85rem 1.35rem;
  border-bottom: 1px solid var(--border);
}

.sheet-tabs {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.sheet-tab {
  padding: 0.45rem 0.7rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.sheet-tab:hover {
  color: var(--text-soft);
}

.sheet-tab.is-active {
  border-color: rgba(255, 255, 255, 0.08);
  background: var(--raised-surface);
  color: var(--text);
  box-shadow: var(--raised-shadow);
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.3rem 1.35rem 3rem;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}

.sheet-intro {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.7;
}

.legend-block {
  margin-bottom: 1.65rem;
}

.legend-block h3 {
  margin: 0 0 0.45rem;
  color: var(--text-soft);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.mapping-table {
  border-top: 1px solid var(--border);
}

.mapping-row {
  display: grid;
  grid-template-columns: minmax(6.5rem, 0.85fr) minmax(0, 1.15fr);
  align-items: center;
  gap: 0.7rem;
  min-height: 2.45rem;
  padding: 0.38rem 0;
  border-bottom: 1px solid var(--border);
}

.mapping-arabic {
  color: var(--text-soft);
  font-family: var(--font-arabic);
  font-size: 1.16rem;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.8;
}

.mapping-keys {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.28rem;
}

.mapping-keys kbd {
  color: var(--muted);
  font-size: 0.72rem;
}

.key-separator {
  color: var(--faint);
  font-size: 0.68rem;
}

.mapping-note {
  color: var(--faint);
  font-family: var(--font-ui);
  font-size: 0.7rem;
  text-align: right;
}

.tip-card {
  margin-top: 1.2rem;
  padding: 0.95rem 1rem;
  border: 1px solid var(--border-glass);
  border-left: 2px solid var(--accent-line);
  border-radius: var(--radius-sm);
  background: var(--surface-gradient);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.tip-card strong {
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 500;
}

.tip-card p {
  margin: 0.42rem 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.7;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.settings-heading {
  margin: 0.9rem 0 0.45rem;
  color: var(--text-soft);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.settings-heading:first-child {
  margin-top: 0;
}

.settings-hint-panel .field-help {
  margin-top: 0.35rem;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.2rem;
  padding: 0.68rem 0;
  border-bottom: 1px solid var(--border);
}

.setting-row label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--text-soft);
  font-size: 0.82rem;
  font-weight: 500;
}

.setting-row label span {
  color: var(--accent);
  font-family: var(--font-arabic);
  font-size: 1.05rem;
}

.setting-row select {
  min-width: 5rem;
  padding: 0.42rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 0.76rem;
}

.setting-row select:hover {
  border-color: var(--border-strong);
}

.settings-form .field-help {
  margin-top: 1rem;
}

.settings-form .button {
  align-self: flex-start;
  margin-top: 1.1rem;
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

.toast {
  position: fixed;
  bottom: 1.4rem;
  left: 50%;
  z-index: 1000;
  max-width: min(90vw, 25rem);
  padding: 0.62rem 0.95rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(24, 24, 27, 0.96) 0%, rgba(12, 12, 14, 0.96) 100%);
  color: var(--text-soft);
  font-size: 0.76rem;
  line-height: 1.4;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 16px 40px rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 0.65rem);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --------------------------------------------------------------------------
   Animations
   -------------------------------------------------------------------------- */

@keyframes caret-pulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.18;
  }
}

@keyframes caret-blink {
  0%,
  48% {
    opacity: 1;
  }

  49%,
  100% {
    opacity: 0;
  }
}

@keyframes word-nudge {
  0%,
  100% {
    transform: translateX(0);
  }

  30% {
    transform: translateX(3px);
  }

  65% {
    transform: translateX(-3px);
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes backdrop-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.98) translateY(-4px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes word-focus {
  from {
    opacity: 0.6;
    filter: blur(2px);
  }

  to {
    opacity: 1;
    filter: blur(0);
  }
}

@keyframes subtitle-refresh {
  from {
    opacity: 0.35;
  }

  to {
    opacity: 1;
  }
}

@keyframes error-flash {
  from {
    color: rgba(255, 255, 255, 0.82);
    text-shadow: 0 0 0 rgba(244, 63, 94, 0);
  }

  to {
    color: #F43F5E;
    text-shadow: 0 0 10px rgba(244, 63, 94, 0.45);
  }
}

@keyframes sheet-in {
  from {
    opacity: 0.6;
    transform: translateX(1.5rem);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

/* --------------------------------------------------------------------------
   Desktop Default States for Mobile Elements
   -------------------------------------------------------------------------- */

.mobile-menu-btn {
  display: none !important;
}

.mobile-drawer-dialog {
  display: none;
}

.label-short {
  display: none;
}

.label-full {
  display: inline;
}

/* ==========================================================================
   Mobile Architecture (viewport <= 768px)
   Native iOS HIG & Mobile Web App Experience
   ========================================================================== */

@media (max-width: 768px) {
  /* ------------------------------------------------------------------------
     Rule 2: Perfect Viewport & Stage Framing (100dvh, flex, space-between)
     ------------------------------------------------------------------------ */
  :root {
    --arabic-sample-size: clamp(2rem, 9vw, 3.2rem);
  }

  html, body {
    overscroll-behavior: none;
    height: 100%;
    min-height: 100dvh;
    width: 100%;
    position: fixed;
    inset: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .app-shell {
    height: 100dvh;
    height: var(--vvh, 100dvh);
    max-height: 100dvh;
    max-height: var(--vvh, 100dvh);
    min-height: unset;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: max(12px, env(safe-area-inset-top, 12px)) max(16px, env(safe-area-inset-right, 16px)) max(12px, env(safe-area-inset-bottom, 12px)) max(16px, env(safe-area-inset-left, 16px));
    box-sizing: border-box;
    width: 100%;
  }

  .main-content {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    margin: 0;
    padding: 0;
    justify-content: space-between;
    overflow: hidden;
  }

  /* ------------------------------------------------------------------------
     Rule 1: Single-Row Ultra-Clean Header
     ------------------------------------------------------------------------ */
  .site-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 44px;
    margin: 0;
    padding: 0 0 4px;
    border: none;
    flex-shrink: 0;
  }

  /* Left: Compact Brand logo (ناطق) */
  .brand {
    display: flex;
    align-items: center;
    gap: 0;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
  }

  .brand-arabic {
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1;
    color: var(--text);
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.12);
  }

  .brand-text {
    display: none !important;
  }

  /* Right: Exactly two buttons only: #dialectPill and #mobileMenuBtn */
  .header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    min-width: 0;
  }

  /* 1. #dialectPill: Compact badge showing dialect */
  .dialect-selector {
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .dialect-pill {
    min-height: 38px;
    height: 38px;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    gap: 0.35rem;
    background: var(--surface-gradient);
    border: 1px solid var(--border-glass);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  }

  .dialect-pill-icon svg {
    width: 13px;
    height: 13px;
  }

  .dialect-pill-name {
    font-size: 0.78rem;
    font-weight: 500;
    max-width: 6.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .dialect-pill-shortcut {
    display: none !important;
  }

  /* 2. #mobileMenuBtn: Sleek native-like gear / settings button */
  .mobile-menu-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    border-radius: 999px;
    background: var(--surface-gradient);
    border: 1px solid var(--border-glass);
    color: var(--text);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 120ms ease, background-color 150ms ease;
  }

  .mobile-menu-btn:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.12);
  }

  /* Hide redundant desktop header controls on mobile (they are in the mobile drawer) */
  .font-selector,
  .font-pill,
  #fontPill,
  #legendButton,
  #settingsButton {
    display: none !important;
  }

  /* Hide the redundant 2nd and 3rd navigation rows from the main mobile screen */
  .control-bar {
    display: none !important;
  }

  /* ------------------------------------------------------------------------
     Rule 2 (cont): Discreet Hairline Stats Bar (WPM, ACC, TIME)
     ------------------------------------------------------------------------ */
  .stats-bar {
    display: flex;
    position: relative;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 1.8rem;
    width: 100%;
    margin: 0;
    padding: 3px 0 7px;
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 0;
    box-shadow: none;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
  }

  .stat-cell {
    display: inline-flex;
    flex-direction: row;
    align-items: baseline;
    gap: 4px;
    min-width: 0;
  }

  .stat-value {
    font-size: 0.95rem;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text);
    line-height: 1;
  }

  .stat-label {
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--faint);
    line-height: 1;
  }

  .label-short {
    display: inline;
  }

  .label-full {
    display: none;
  }

  .stat-cell--streak {
    display: none !important;
  }

  /* 1.5px hairline progress fill along the bottom of the stats bar */
  .stat-progress {
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    width: 100%;
    margin: 0;
    padding: 0;
    border-top: none;
  }

  .progress-meta {
    display: none !important;
  }

  .progress-track {
    height: 1.5px;
    background: transparent;
    border-radius: 0;
    overflow: hidden;
  }

  .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #10B981 0%, #34D399 100%);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.7);
  }

  /* ------------------------------------------------------------------------
     Rule 2 (cont): Center #testStage Vertically in Prime Visual Zone
     ------------------------------------------------------------------------ */
  .test-stage {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 6px 12px;
    border: none;
    background: transparent;
    box-shadow: none;
    width: 100%;
    box-sizing: border-box;
    position: relative;
  }

  .prompt {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    padding: 0;
  }

  .prompt-head {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2px;
    padding: 0 4px;
  }

  .prompt-counter {
    font-size: 0.7rem;
    color: var(--muted);
    font-family: var(--font-mono);
  }

  .prompt-mode {
    font-size: 0.6rem;
    color: var(--faint);
    text-transform: uppercase;
    letter-spacing: 0.1em;
  }

  .prompt-tools {
    display: flex;
    align-items: center;
    gap: 0.35rem;
  }

  .hint-button {
    min-height: 30px;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    touch-action: manipulation;
  }

  .hint-button kbd {
    display: none;
  }

  /* ------------------------------------------------------------------------
     Rule 3: Stage Polish (Arabic Word Scaling, Translation Chip, Up-Next Queue)
     ------------------------------------------------------------------------ */
  /* Dynamic font scaling so even multi-word phrases never wrap awkwardly or clip */
  .prompt-arabic,
  #displayWord,
  .display-word {
    width: 100%;
    max-width: 100%;
    font-size: var(--arabic-sample-size, clamp(2rem, 9vw, 3.2rem));
    line-height: 1.65 !important;
    text-align: center;
    margin: 6px auto 4px;
    padding: 0.14em 0;
    overflow: visible;
    overflow-wrap: break-word;
    word-break: normal;
    text-wrap: balance;
    letter-spacing: 0;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    text-shadow: 0 0 32px rgba(245, 245, 247, 0.08);
    transition: font-size 140ms cubic-bezier(0.16, 1, 0.3, 1), color 180ms ease;
  }

  /* Input line & caret container */
  .prompt-input-wrap {
    width: 100%;
    max-width: 320px;
    min-height: 2.85rem;
    margin: 4px auto 0;
    padding: 0.35rem 0.85rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid var(--border);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
    cursor: text;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    transition: border-color 160ms ease, background-color 160ms ease;
  }

  .prompt-input-wrap:focus-within,
  .test-stage:not(.is-paused) .prompt-input-wrap {
    border-color: var(--accent-line);
    background: rgba(16, 185, 129, 0.035);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.12), inset 0 1px 2px rgba(0, 0, 0, 0.2);
  }

  .prompt-latin {
    font-size: clamp(1.2rem, 5vw, 1.45rem);
    letter-spacing: 0.08em;
    line-height: 1.4;
  }

  .prompt-latin[lang="ar"] {
    font-size: clamp(1.4rem, 6.5vw, 1.85rem);
    line-height: 1.6;
  }

  /* Translation chip: directly below the input line with compact padding */
  .word-feedback {
    min-height: 26px;
    height: auto;
    margin: 6px auto 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .word-feedback-content {
    max-width: 90vw;
    min-height: 24px;
    padding: 3px 12px;
    gap: 0.35rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .word-feedback-translation {
    font-size: 0.74rem;
    font-weight: 500;
  }

  .word-feedback-notes {
    font-size: 0.66rem;
  }

  /* Up-Next Queue: 2-3 faintly visible upcoming words with clean edge fade */
  .queue-wrap {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    max-width: 280px;
    margin: 8px auto 0;
    padding: 6px 0 0;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    overflow: hidden;
  }

  .queue-label {
    flex-shrink: 0;
    font-size: 0.55rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--faint);
    text-transform: uppercase;
  }

  .words {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    direction: rtl;
    max-width: 220px;
    overflow: hidden;
    mask-image: linear-gradient(90deg, transparent 0%, black 15%, black 85%, transparent 100%);
    -webkit-mask-image: linear-gradient(90deg, transparent 0%, black 15%, black 85%, transparent 100%);
  }

  .queue-item {
    display: none;
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 1.05rem;
    line-height: 1.5;
  }

  .queue-item:nth-child(1),
  .queue-item:nth-child(2),
  .queue-item:nth-child(3) {
    display: inline-block;
  }

  .queue-item:nth-child(1) {
    opacity: 0.55;
  }

  .queue-item:nth-child(2) {
    opacity: 0.38;
  }

  .queue-item:nth-child(3) {
    opacity: 0.22;
  }

  .queue-more {
    display: none !important;
  }

  /* ------------------------------------------------------------------------
     Rule 4: Keyboard & Touch Focus (16px input, eliminate desktop prompts)
     ------------------------------------------------------------------------ */
  .typing-input,
  #typingInput,
  #inputField,
  #mobileInput {
    font-size: 16px !important;
    position: fixed;
    top: 30%;
    left: 50%;
    bottom: auto;
    right: auto;
    transform: translate(-50%, -50%);
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    z-index: -1;
  }

  /* Completely remove any desktop focus prompts, shortcut bars, and instruction lines */
  .focus-badge,
  #focusBadge,
  .instruction-line,
  .prompt-help,
  .test-footer,
  .shortcuts,
  .shortcuts-hint {
    display: none !important;
  }

  /* Keyboard-open state: maintain tight rhythm without viewport jump */
  body.keyboard-open .site-header {
    padding-bottom: 2px;
  }

  body.keyboard-open .test-stage {
    padding: 2px 8px;
  }

  body.keyboard-open .prompt-arabic,
  body.keyboard-open #displayWord,
  body.keyboard-open .display-word {
    margin: 2px auto 2px;
    font-size: var(--arabic-sample-size, clamp(1.8rem, 8vw, 2.5rem));
  }

  body.keyboard-open .word-feedback {
    margin-top: 4px;
  }

  body.keyboard-open .queue-wrap {
    margin-top: 4px;
    padding-top: 4px;
  }

  /* ------------------------------------------------------------------------
     Native Bottom Sheet Drawer (Settings & Practice Options)
     ------------------------------------------------------------------------ */
  .mobile-drawer-dialog {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    max-width: 100%;
    max-height: 85dvh;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 24px 24px 0 0;
    background: rgba(18, 18, 22, 0.96);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.75);
    z-index: 1000;
    overflow: hidden;
  }

  .mobile-drawer-dialog[open] {
    display: flex;
    flex-direction: column;
    animation: drawer-slide-up 280ms cubic-bezier(0.16, 1, 0.3, 1) both;
  }

  .mobile-drawer-dialog::backdrop {
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: drawer-fade-in 220ms ease both;
  }

  .mobile-drawer-sheet {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-height: 85dvh;
    padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
    box-sizing: border-box;
  }

  .mobile-drawer-handle {
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.25);
    margin: 8px auto 4px;
    flex-shrink: 0;
  }

  .mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1.2rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
  }

  .mobile-drawer-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
  }

  .mobile-drawer-close {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: var(--muted);
    touch-action: manipulation;
  }

  .mobile-drawer-close:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.16);
  }

  .mobile-drawer-body {
    padding: 1rem 1.2rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
  }

  .drawer-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .drawer-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }

  .drawer-section-label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--faint);
  }

  .drawer-section-value {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--accent);
    letter-spacing: 0.03em;
  }

  /* Drawer Font Size Slider */
  .drawer-slider-wrap {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.25rem 0.2rem 0;
    width: 100%;
  }

  .drawer-slider-bound {
    font-family: var(--font-arabic);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--muted);
    line-height: 1;
    user-select: none;
  }

  .drawer-slider-bound--large {
    font-size: 1.45rem;
    color: var(--text-soft);
  }

  .drawer-size-slider {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    touch-action: pan-x;
    cursor: pointer;
  }

  .drawer-size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #FFFFFF;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 10px rgba(16, 185, 129, 0.4);
    cursor: pointer;
    transition: transform 120ms ease;
  }

  .drawer-size-slider::-webkit-slider-thumb:active {
    transform: scale(1.15);
  }

  .drawer-size-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #FFFFFF;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 10px rgba(16, 185, 129, 0.4);
    cursor: pointer;
    transition: transform 120ms ease;
  }

  /* Drawer Font Options Grid */
  .drawer-font-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    width: 100%;
  }

  .drawer-font-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.65rem 0.4rem;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--muted);
    touch-action: manipulation;
    transition: all 160ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .drawer-font-btn:active {
    transform: scale(0.96);
  }

  .drawer-font-btn.is-active {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.45);
    color: var(--text);
    box-shadow: 0 0 14px rgba(16, 185, 129, 0.15);
  }

  .drawer-font-sample {
    font-size: 1.35rem;
    line-height: 1.3;
    color: var(--text);
  }

  .drawer-font-btn.is-active .drawer-font-sample {
    color: var(--accent);
  }

  .drawer-font-meta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
  }

  .drawer-font-name {
    font-size: 0.76rem;
    font-weight: 600;
  }

  .drawer-font-desc {
    font-size: 0.58rem;
    color: var(--faint);
  }

  /* Drawer Segmented Tracks */
  .drawer-segmented-track {
    display: flex;
    flex-wrap: wrap;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 12px;
    padding: 3px;
    gap: 3px;
    width: 100%;
    box-sizing: border-box;
  }

  .drawer-pill {
    flex: 1 1 auto;
    min-height: 36px;
    padding: 0.35rem 0.65rem;
    border-radius: 9px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 500;
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: all 150ms ease;
  }

  .drawer-pill:active {
    transform: scale(0.96);
  }

  .drawer-pill.is-active {
    background: var(--raised-surface);
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  }

  .drawer-pill.script-tab--arabic {
    font-size: 0.88rem;
  }

  /* Drawer Footer Quick Actions */
  .drawer-footer-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.4rem;
    padding-top: 0.8rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }

  .drawer-link-btn {
    flex: 1;
    min-height: 40px;
    padding: 0.4rem 0.75rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    touch-action: manipulation;
  }

  .drawer-link-btn:active {
    transform: scale(0.96);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
  }

  .drawer-link-btn--restart {
    color: var(--accent);
  }

  /* ------------------------------------------------------------------------
     Native Mobile Bottom Sheet for Legend & Settings
     ------------------------------------------------------------------------ */
  .sheet-dialog {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    max-width: 100%;
    height: min(88dvh, 46rem);
    max-height: 88dvh;
    border-radius: 22px 22px 0 0;
    border: 0;
    border-top: 1px solid var(--top-border);
    background: rgba(14, 14, 16, 0.94);
    box-shadow: var(--top-shadow);
    margin: 0;
  }

  .sheet-dialog[open] {
    animation: mobile-sheet-up 280ms cubic-bezier(0.16, 1, 0.3, 1) both;
  }

  .sheet-shell::before {
    content: "";
    display: block;
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
    margin: 8px auto 2px;
    flex-shrink: 0;
  }

  .sheet-header {
    padding: 0.65rem 1rem 0.75rem;
  }

  .sheet-body {
    padding: 1rem 1rem calc(2.5rem + env(safe-area-inset-bottom, 0px));
  }

  /* Native Results Dialog on Mobile */
  .results-dialog {
    width: calc(100vw - 1.25rem);
    max-width: 26rem;
    border-radius: 22px;
    border: 1px solid var(--top-border);
    background: rgba(14, 14, 16, 0.94);
    box-shadow: var(--top-shadow);
  }

  .results {
    padding: 1.4rem 1.15rem 1.5rem;
  }

  .results-hero {
    margin-bottom: 1rem;
  }

  .results-wpm {
    font-size: clamp(3.4rem, 18vw, 4.8rem);
    font-weight: 700;
    color: var(--accent);
  }

  .results-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.2rem;
  }

  .results-grid > div {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem 0.6rem;
    text-align: center;
  }

  .results-actions {
    flex-direction: column;
    gap: 0.6rem;
    width: 100%;
  }

  .results-actions .button {
    width: 100%;
    min-height: 48px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
  }

  .results-actions .button kbd {
    display: none;
  }

  /* Custom Text Modal on Mobile */
  .modal-dialog {
    width: calc(100vw - 1.25rem);
    max-width: 28rem;
    border-radius: 20px;
  }

  .custom-textarea {
    min-height: 8.5rem;
    font-size: 1.15rem;
  }

  .modal-actions {
    flex-direction: column-reverse;
    width: 100%;
    gap: 0.5rem;
  }

  .modal-actions .button {
    width: 100%;
    min-height: 44px;
    border-radius: 10px;
  }
}

@keyframes drawer-slide-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes drawer-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* --------------------------------------------------------------------------
   Dialect Selector Pill & Modals
   -------------------------------------------------------------------------- */

.dialect-selector {
  display: flex;
  align-items: center;
}

.dialect-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.15rem;
  padding: 0.34rem 0.62rem;
  border: 1px solid var(--specular-border);
  border-radius: 999px;
  background: var(--mid-surface);
  box-shadow: var(--specular-rim);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition:
    color 150ms ease,
    background-color 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease,
    transform 120ms var(--ease-out-expo);
}

.dialect-pill:hover {
  color: var(--text);
  border-color: var(--border-hover);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.02) 100%);
  box-shadow: var(--specular-rim-hover);
  transform: translateY(-1px);
}

.dialect-pill:active {
  transform: scale(0.985);
}

.dialect-pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.dialect-pill-icon {
  display: grid;
  place-items: center;
  color: var(--accent);
  filter: drop-shadow(0 0 6px rgba(16, 185, 129, 0.45));
  opacity: 0.95;
}

.dialect-pill-name {
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialect-pill-shortcut {
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #8E8E93;
  font-family: ui-monospace, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
}

/* Dialect Search Dialog */
.dialect-search-dialog {
  width: min(92vw, 32rem);
}

.dialect-search-card {
  padding: 1.5rem;
}

.dialect-search-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.9rem;
  margin-bottom: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.dialect-search-bar:focus-within {
  border-color: rgba(16, 185, 129, 0.55);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.08);
}

.dialect-search-icon {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.dialect-search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

.dialect-search-input::placeholder {
  color: var(--faint);
}

.dialect-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 18rem;
  overflow-y: auto;
  padding-right: 0.2rem;
  scrollbar-width: thin;
}

.dialect-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem 0.95rem;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  background: var(--surface-gradient);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition:
    background-color 150ms ease,
    border-color 150ms ease,
    box-shadow 160ms ease,
    transform 120ms var(--ease-out-expo);
}

.dialect-item:hover,
.dialect-item.is-selected {
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.09) 0%, rgba(16, 185, 129, 0.02) 100%);
  border-color: var(--accent-line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 26px -20px rgba(16, 185, 129, 0.55);
  transform: translateY(-1px);
}

.dialect-item.is-active {
  border-color: rgba(16, 185, 129, 0.45);
}

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

.dialect-item-name {
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.dialect-active-badge {
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.dialect-item-desc {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.dialect-item-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.dialect-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.85rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.dialect-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--faint);
  font-size: 0.72rem;
}

.dialect-hint kbd {
  font-size: 0.7rem;
}

/* First-Visit Onboarding Modal */
.onboarding-dialog {
  width: min(92vw, 36rem);
}

.onboarding-card {
  padding: clamp(1.4rem, 4vw, 2.2rem);
}

.onboarding-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.onboarding-arabic {
  display: block;
  font-family: var(--font-arabic);
  font-size: 2.2rem;
  color: var(--accent);
  margin-bottom: 0.35rem;
  line-height: 1.2;
}

.onboarding-header h2 {
  margin: 0 0 0.45rem;
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.onboarding-subtitle {
  margin: 0 auto;
  max-width: 28rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
}

.onboarding-subtitle kbd {
  font-size: 0.7rem;
}

.onboarding-dialects {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1.6rem;
}

.onboarding-dialect-option {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 0.95rem 1.15rem;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  background: var(--surface-gradient);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: all 150ms ease;
}

.onboarding-dialect-option:hover {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.02) 100%);
  border-color: var(--border-hover);
}

.onboarding-dialect-option.is-selected {
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.1) 0%, rgba(16, 185, 129, 0.025) 100%);
  border-color: var(--accent-line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 30px -20px rgba(16, 185, 129, 0.55);
}

.onboarding-dialect-option input[type="radio"] {
  accent-color: var(--accent);
  margin-top: 0.25rem;
  cursor: pointer;
}

.onboarding-dialect-content {
  flex: 1;
}

.onboarding-dialect-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.onboarding-dialect-name {
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
}

.dialect-default-badge {
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.onboarding-dialect-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.onboarding-actions {
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 768px) {
  .dialect-pill-shortcut {
    display: none;
  }

  .dialect-pill-name {
    max-width: 8rem;
  }

  .dialect-modal-footer {
    display: none;
  }
}

/* Arabic Typeface Switcher */
.font-dialog {
  width: min(92vw, 34rem);
}

.font-card {
  padding: clamp(1.3rem, 3.6vw, 1.8rem);
}

.font-intro {
  margin: -0.35rem 0 1.2rem;
  color: var(--muted);
  font-size: 0.79rem;
  line-height: 1.65;
}

.font-options {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.font-option {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.9rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  background: var(--surface-gradient);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    box-shadow 180ms ease,
    transform 120ms var(--ease-out-expo);
}

.font-option:hover {
  border-color: var(--border-hover);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.02) 100%);
  transform: translateY(-1px);
}

.font-option:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.font-option:active {
  transform: scale(0.99);
}

.font-option.is-selected {
  border-color: var(--accent-line);
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.1) 0%, rgba(16, 185, 129, 0.025) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 0 0 1px rgba(16, 185, 129, 0.12),
    0 12px 30px -20px rgba(16, 185, 129, 0.55);
}

.font-option input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.font-preview {
  display: grid;
  width: 4.5rem;
  height: 3.25rem;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 0.6rem;
  background: #000000;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 1.85rem;
  font-weight: 600;
  line-height: 1;
  text-shadow: 0 0 24px rgba(245, 245, 247, 0.08);
}

.font-preview--modern {
  font-family: var(--font-arabic-modern);
}

.font-preview--classical {
  font-family: var(--font-arabic-classical);
  font-weight: 700;
  font-size: 2.05rem;
}

.font-preview--display {
  font-family: var(--font-arabic-display);
}

.font-option-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.16rem;
}

.font-option-name {
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.font-option-desc {
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.45;
}

.font-option-check {
  display: grid;
  width: 1.15rem;
  height: 1.15rem;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  color: transparent;
  transition:
    color 150ms ease,
    border-color 150ms ease,
    background-color 150ms ease,
    box-shadow 150ms ease;
}

.font-option-check svg {
  width: 0.68rem;
  height: 0.68rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.font-option.is-selected .font-option-check {
  border-color: rgba(16, 185, 129, 0.55);
  background: var(--accent);
  color: #000000;
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.4);
}

.font-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: 1.1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.font-footer-note {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--faint);
  font-size: 0.69rem;
}

.font-footer-dot {
  width: 0.36rem;
  height: 0.36rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
}

@media (max-width: 640px) {
  .dialect-pill-name {
    max-width: 5.5rem;
  }

  .font-preview {
    width: 3.7rem;
    height: 2.9rem;
    font-size: 1.6rem;
  }

  .font-preview--classical {
    font-size: 1.8rem;
  }

  .font-option {
    gap: 0.7rem;
    padding: 0.72rem 0.78rem;
  }

  .font-option-desc {
    font-size: 0.69rem;
  }
}

@media (max-width: 420px) {
  .brand-text {
    display: none;
  }

  .header-actions {
    gap: 0.3rem;
  }

  .dialect-pill-name {
    max-width: 4.6rem;
  }
}

@keyframes mobile-sheet-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .caret {
    animation: none;
  }
}
