@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Variable.woff2") format("woff2-variations"),
       url("/static/fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ------------------------------------------------------------------ tokens */
:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1d1c1a;
  --muted: #6d6a63;
  --border: #e5e2da;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-soft: #e3f1ef;
  --on-accent: #ffffff;
  --record: #dc3d43;
  --record-soft: #fbe7e7;
  --success: #1a7f4b;
  --success-soft: #e3f3ea;
  --danger: #c0352f;
  --danger-soft: #fbe9e7;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px -12px rgb(0 0 0 / 0.12);
  --radius: 18px;
  --radius-sm: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131312;
    --surface: #1c1c1a;
    --surface-2: #252522;
    --text: #ecebe7;
    --muted: #9d9a92;
    --border: #2e2d2a;
    --accent: #2db3a3;
    --accent-hover: #4cc6b7;
    --accent-soft: #15302d;
    --on-accent: #0b1f1d;
    --record: #f0595e;
    --record-soft: #3a1d1e;
    --success: #4cc387;
    --success-soft: #16301f;
    --danger: #f0716a;
    --danger-soft: #3a1e1c;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px -12px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

/* Telegram Mini App follows Telegram's theme, not the OS one (see telegram.js). */
:root[data-theme="dark"] {
  --bg: #131312;
  --surface: #1c1c1a;
  --surface-2: #252522;
  --text: #ecebe7;
  --muted: #9d9a92;
  --border: #2e2d2a;
  --accent: #2db3a3;
  --accent-hover: #4cc6b7;
  --accent-soft: #15302d;
  --on-accent: #0b1f1d;
  --record: #f0595e;
  --record-soft: #3a1d1e;
  --success: #4cc387;
  --success-soft: #16301f;
  --danger: #f0716a;
  --danger-soft: #3a1e1c;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px -12px rgb(0 0 0 / 0.5);
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

button, input { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.container {
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
  padding-inline: 16px;
}

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

/* ----------------------------------------------------------------- header */
.site-header { padding-block: 20px 8px; }

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
}

.nav { display: flex; gap: 4px; }
.nav a {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.95rem;
}
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }

main { flex: 1; padding-block: 16px 40px; }
.has-dock main { padding-bottom: 140px; }

.page-intro { margin: 8px 0 20px; }
.page-intro + * { margin-top: 0; }
.page-intro h1 {
  margin: 0;
  font-size: clamp(1.4rem, 3.6vw, 1.75rem);
  font-weight: 800;
  line-height: 1.4;
  letter-spacing: -0.01em;
}
.page-intro p { margin: 6px 0 0; color: var(--muted); }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
@media (max-width: 520px) { .card { padding: 18px; } }

/* vertical rhythm between top-level blocks (cards, notes, forms) */
main > * + * { margin-top: 16px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

/* The text to read. Latin words inside are handled by the bidi algorithm. */
.prompt-text {
  font-size: clamp(1.2rem, 2.8vw, 1.45rem);
  line-height: 2.15;
  font-weight: 450;
  text-align: start;
  overflow-wrap: anywhere;
}
.prompt-text p { margin: 0; }
.prompt-text p + p { margin-top: 0.9em; }
.prompt-text.is-loading { color: var(--muted); }

/* --------------------------------------------------------- segmented ctrl */
.segmented {
  display: flex;
  padding: 4px;
  gap: 2px;
  background: var(--surface-2);
  border-radius: 999px;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.segmented button:disabled { cursor: not-allowed; opacity: 0.6; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.98rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  text-decoration: none;
  white-space: nowrap;
  flex: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }

.btn-quiet { background: transparent; color: var(--muted); min-height: 36px; padding: 4px 12px; }
.btn-quiet:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }

.btn-success { background: var(--success-soft); color: var(--success); }
.btn-success:hover:not(:disabled) { border-color: var(--success); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover:not(:disabled) { border-color: var(--danger); }

.btn-block { width: 100%; }

/* ------------------------------------------------------ recorder dock bar */
.dock {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 10;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.dock .container {
  display: flex;
  align-items: center;
  gap: 14px;
}
.dock-info { flex: 1; min-width: 0; }
.dock-title { font-weight: 600; }
.dock-sub { color: var(--muted); font-size: 0.88rem; }

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  direction: ltr;
  unicode-bidi: isolate;
}

.record-btn {
  flex: none;
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  background: var(--record);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--record) 70%, transparent);
  transition: transform 0.12s, box-shadow 0.2s;
}
.record-btn:hover { transform: scale(1.04); }
.record-btn:active { transform: scale(0.97); }
.record-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.record-btn .icon-stop { display: none; }
.record-btn.is-recording .icon-mic { display: none; }
.record-btn.is-recording .icon-stop { display: block; }
.record-btn.is-recording { animation: pulse 1.6s ease-out infinite; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--record) 45%, transparent); }
  100% { box-shadow: 0 0 0 16px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .record-btn.is-recording { animation: none; }
}

.meter {
  flex: none;
  width: 120px;
  height: 36px;
  display: block;
}
@media (max-width: 420px) { .meter { width: 72px; } }

/* -------------------------------------------------------------- review/form */
.review { display: grid; gap: 16px; }
.review audio { width: 100%; height: 44px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row > .grow { flex: 1; }

.section-title {
  margin: 0 0 4px;
  font-size: 1.05rem;
  font-weight: 700;
}
.section-sub { margin: 0 0 16px; color: var(--muted); font-size: 0.92rem; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 0.92rem; }
.field .hint { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[dir="ltr"] { text-align: left; }
.input:user-invalid { border-color: var(--danger); }

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  margin-bottom: 10px;
  font-size: 0.94rem;
  line-height: 1.7;
}
.check:hover { background: var(--surface-2); }
.check input {
  flex: none;
  width: 20px; height: 20px;
  margin: 3px 0 0;
  accent-color: var(--accent);
}
.check .req { color: var(--record); font-weight: 700; }

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s;
}

/* ------------------------------------------------------------------ notes */
.note {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.94rem;
}
.note-error { background: var(--danger-soft); color: var(--danger); }
.note-success { background: var(--success-soft); color: var(--success); }
.note-muted { background: var(--surface-2); color: var(--muted); }

details.tips {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.93rem;
}
details.tips summary { cursor: pointer; font-weight: 600; color: var(--text); width: fit-content; }
details.tips ul { margin: 8px 0 0; padding-inline-start: 20px; }
details.tips li + li { margin-top: 4px; }

.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}
.empty .big { font-size: 2.2rem; line-height: 1; margin-bottom: 8px; }

/* ----------------------------------------------------------------- toast */
.toast {
  position: fixed;
  top: 16px;
  inset-inline: 16px;
  margin-inline: auto;
  max-width: 420px;
  z-index: 50;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-weight: 500;
  text-align: center;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

/* ------------------------------------------------------------------ stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.stat .value { font-size: 1.5rem; font-weight: 800; line-height: 1.3; }
.stat .label { color: var(--muted); font-size: 0.86rem; }

/* ------------------------------------------------------------------ prose */
.prose h2 { font-size: 1.15rem; margin: 28px 0 8px; }
.prose h2:first-child { margin-top: 0; }
.prose p, .prose li { color: var(--text); }
.prose ul { padding-inline-start: 22px; }
.prose .ltr { display: inline-block; direction: ltr; overflow-wrap: anywhere; font-size: 0.92em; }

.site-footer {
  padding-block: 24px;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
}

kbd {
  font: inherit;
  font-size: 0.8em;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface);
}

[hidden] { display: none !important; }
