/* ============================================================
   متغیرهای سراسری
   ============================================================ */
:root {
  --color-bg: #eef1f7;
  --color-surface: #ffffff;
  --color-text: #1b2233;
  --color-muted: #b6bfcd;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-secondary: #334155;
  --color-secondary-hover: #1e293b;

  --radius-md: 12px;
  --shadow-soft: 0 12px 32px rgba(15, 23, 42, 0.12);
  --shadow-btn: 0 8px 18px rgba(15, 23, 42, 0.22);

  --font-fa: "Vazirmatn", "Segoe UI", Tahoma, Arial, sans-serif;

  --sheet-width: 210mm;   /* A4 */
  --sheet-height: 297mm;  /* A4 */
}

/* ============================================================
   پایه
   ============================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-fa);
  background-color: var(--color-bg);
  color: var(--color-text);
}

/* ============================================================
   چیدمان صفحه  (page)
   ============================================================ */
.page {
  padding: 28px 16px 56px;
  overflow-x: auto; /* در موبایل امکان اسکرول افقی */
}

.page__inner {
  width: var(--sheet-width);
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ============================================================
   نوار ابزار  (toolbar)
   ============================================================ */
.toolbar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.toolbar--top {
  justify-content: flex-end;
}

.toolbar--bottom {
  justify-content: center;
}

/* ============================================================
   دکمه‌ها  (btn)
   ============================================================ */
.btn {
  appearance: none;
  border: 0;
  border-radius: var(--radius-md);
  padding: 12px 28px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 0.2s ease, box-shadow 0.2s ease,
    transform 0.12s ease, opacity 0.2s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.35);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  background-color: var(--color-primary);
  color: #ffffff;
  box-shadow: var(--shadow-btn);
}

.btn--primary:hover:not(:disabled) {
  background-color: var(--color-primary-hover);
}

.btn--secondary {
  background-color: var(--color-secondary);
  color: #ffffff;
  box-shadow: var(--shadow-btn);
}

.btn--secondary:hover:not(:disabled) {
  background-color: var(--color-secondary-hover);
}

/* ============================================================
   برگه A4  (sheet)
   ============================================================ */
.sheet {
  width: var(--sheet-width);
  height: var(--sheet-height);
  padding: 18mm 16mm;
  background-color: var(--color-surface);
  border-radius: 4px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* حالت مخصوص خروجی گرفتن: حذف سایه و گردی گوشه‌ها */
.sheet--exporting {
  box-shadow: none !important;
  border-radius: 0 !important;
}

/* ============================================================
   لیست تمرین‌ها  (sheet__list)
   ============================================================ */
.sheet__list {
  flex: 1 1 auto;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between; /* پر کردن کامل ارتفاع صفحه */
  font-size: 15pt;
  line-height: 1.4;
}

/* ============================================================
   هر سطر تمرین  (problem)
   ============================================================ */
.problem {
  display: flex;
  direction: ltr;
  align-items: baseline; /* نقطه‌چین دقیقاً روی خط کرسی عدد می‌نشیند */
  width: 100%;
}

.problem__number {
  direction: ltr;           /* عدد از چپ به راست خوانده شود */
  unicode-bidi: isolate;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--color-text);
}

.problem__line {
  flex: 1 1 auto;
  min-width: 40px;
  margin-inline-start: 10px;
  border-bottom: 2px dotted var(--color-muted);
  align-self: baseline;
}

/* ============================================================
   چاپ مستقیم مرورگر (اختیاری)
   ============================================================ */
/* ============================================================
   چاپ
   ============================================================ */
/* ============================================================
   چاپ — فقط یک صفحه A4
   ============================================================ */
@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  /* خنثی‌سازی کامل html و body */
  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;      /* ← حذف min-height:100vh که باعث صفحهٔ دوم می‌شد */
    overflow: hidden !important;   /* ← جلوگیری از سرریز هر پیکسل اضافه */
    background: #ffffff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .toolbar {
    display: none !important;
  }

  .page {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    background: #ffffff !important;
    overflow: hidden !important;
  }

  .page__inner {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
  }

  /* برگه: یک میلی‌متر کمتر از A4 تا سرریز پیکسلی رخ ندهد */
  .sheet {
    width: 210mm !important;
    height: 296mm !important;      /* ← ۲۹۶ به‌جای ۲۹۷ */
    max-height: 296mm !important;
    padding: 14mm 16mm !important; /* ← کمی کم‌تر تا محتوا هم راحت جا شود */
    margin: 0 auto !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #ffffff !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    page-break-after: avoid !important;
    break-after: avoid !important;
  }

  .sheet__list {
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .problem {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .problem__number { color: #1b2233 !important; }
  .problem__line   { border-bottom-color: #b6bfcd !important; }
}