@media (max-width: 1180px) {
  .watch-grid { grid-template-columns: 290px minmax(0, 1fr); }
  .home-main .course-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .watch-grid { display: flex; flex-direction: column; direction: rtl; gap: 14px; align-items: stretch; }
  .watch-center { order: 1; } .lessons-panel { order: 2; }
  .home-main .course-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  .detail-head { grid-template-columns: minmax(0, 1fr); grid-template-areas: "intro" "box" "body"; gap: 14px; }
  .detail-cover { aspect-ratio: 16 / 7; }
  .buy-box { position: static; }
  .cart-grid { grid-template-columns: 1fr; }
  .cart-summary { position: static; }
  .hero { padding: 16px; }
  .hero h1 { font-size: 1.25rem; }

  .lessons-panel { position: static; max-height: none; margin-bottom: 14px; }
  .lessons-scroll { max-height: 420px; }
  .mobile-only { display: block; }
  .exam-head { top: var(--header-h); }
  .q-card { padding: 14px; }
  .course-grid, .home-main .course-grid { gap: 12px; }
  .buy-box { padding: 14px; }
}

/* گوشی: حاشیه‌ی کناری ۱۶، چیزی از عرض صفحه بیرون نمی‌زند، و مرورگر هنگام فوکوس روی فیلد زوم نمی‌کند.
   (iOS روی هر فیلد با نوشته‌ی کوچک‌تر از ۱۶ پیکسل صفحه را بزرگ می‌کند و دیگر برنمی‌گرداند؛ برای همین فقط فیلدها ۱۶ می‌مانند.) */
@media (max-width: 900px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="hidden"]),
  select, select.input, textarea, textarea.textarea, .cw-form textarea { font-size: 16px; }
  img, video, iframe, canvas, table { max-width: 100%; }
  .prose, .cw-msg, .comment p, .lesson-row, .cc-title, .mc-title { overflow-wrap: anywhere; }
  .table-wrap, .receipt-scroll, .cert-stage, .stories { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
}

@media (max-width: 520px) {
  /* the receipt's table becomes one block per line, so no column is ever hidden off to the side */
  .receipt-scroll { overflow: visible; }
  .receipt-table { min-width: 0; }
  .receipt-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .receipt-table, .receipt-table tbody, .receipt-table tr, .receipt-table th, .receipt-table td { display: block; }
  .receipt-table tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .receipt-table th, .receipt-table td { border: 0; padding: 3px 0; }
  .receipt-table td { display: flex; justify-content: space-between; gap: 12px; }
  .receipt-table td::before { content: attr(data-label); color: var(--muted); }
  .cart-row { flex-wrap: wrap; padding: 12px; }
  .cart-thumb { width: 72px; }
  .cart-price { order: 3; flex-direction: row; align-items: baseline; gap: 8px; min-width: 0; margin-inline-start: 84px; flex: 1 1 calc(100% - 84px); text-align: start; }
  .stories { gap: 14px; }
  .course-grid, .home-main .course-grid { grid-template-columns: 1fr; }
  /* the card is one row on a phone: a small tile and the text beside it, so the first screen shows three or four courses and not one */
  .course-card { flex-direction: row; height: auto; }
  .cc-cover { aspect-ratio: auto; width: 96px; min-height: 96px; flex: none; }
  .cc-cover img { position: absolute; inset: 0; }
  .cc-cover .ph { font-size: 1.8rem; }
  .cc-cover .play, .cc-cover .cc-tool, .cc-cover .cc-price { display: none; }
  .cc-price-inline, .cc-tool-inline { display: inline-flex; }
  .cc-tool-inline { background: var(--brand-50); color: var(--brand-700); padding: 1px 8px; border-radius: 8px; font-weight: 600; }
  .cc-body { padding: 10px 12px; gap: 4px; min-width: 0; }
  .cc-meta { gap: 4px 10px; }
  .detail-cover { aspect-ratio: 3 / 1; font-size: 2.2rem; }
  /* search on one line with its button as an icon; the tool and the price tabs share the line under it */
  .filters-search { flex-basis: 100%; }
  .filters-search-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .filters-search .btn { min-width: var(--touch); padding-inline: 12px; }
  .filters select.input { flex: 1 1 150px; min-width: 0; }
  .filters .pill-tabs { flex: 1 1 auto; }
  .filters .pill-tabs a { flex: 1; justify-content: center; }
  .hero-actions { width: 100%; }
  .hero-actions .btn { width: 100%; justify-content: center; }
  /* two fields side by side get cut off on a phone (a name, a long option): one per line */
  .row:has(> .field + .field) { flex-direction: column; align-items: stretch; --gap: 0px !important; }
  .row:has(> .field + .field) > .field { width: 100%; flex: none; }
  .auth-card { padding: 20px 16px; }
  .site-header .inner { gap: 8px; }
  .brand span { font-size: 1rem; }
  .user-chip .who { display: none; }
  .user-chip { padding: 4px; }
  .bars { gap: 4px; }
}

@media print {
  body { background: #fff; padding: 0; }
  .site-header, .bottom-nav, .site-footer, .no-print, .messages { display: none !important; }
  main { padding: 0; }
  .cert-stage { padding: 0; }
  .cert-svg { box-shadow: none; border-radius: 0; max-width: none; width: 100%; height: auto; }
  @page { size: A4 landscape; margin: 0; }
}
