/* ==========================================================================
   Arma Links: stylesheet
   Fonts are local-only (no external CDN), so the page works on Iran's
   domestic network. Vazirmatn is used when installed, else system fonts.
   ========================================================================== */

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efeee8;
  --border: #e3e1d9;
  --border-strong: #cfccc1;
  --text: #1b1c20;
  --muted: #5f6168;
  --faint: #8a8c93;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe8;
  --focus: #2b7fff;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 4px 16px rgba(20, 20, 30, .05);
  --shadow-hover: 0 2px 4px rgba(20, 20, 30, .06), 0 12px 28px rgba(20, 20, 30, .10);
  --hl: #fff1a8;

  --radius: 14px;
  --radius-sm: 10px;
  --wrap: 1240px;
  --gutter: 16px;
  --font: "Vazirmatn", "Vazir", "Segoe UI", Tahoma, system-ui, -apple-system, "Noto Sans Arabic", sans-serif;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14151a;
    --surface: #1c1d24;
    --surface-2: #24262e;
    --border: #2d2f38;
    --border-strong: #3c3f4a;
    --text: #ecebe6;
    --muted: #a6a8b0;
    --faint: #7c7f88;
    --accent: #5cc8a8;
    --accent-ink: #0d1f1a;
    --accent-soft: #1d3530;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-hover: 0 8px 28px rgba(0, 0, 0, .45);
    --hl: #5a4c10;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #14151a;
  --surface: #1c1d24;
  --surface-2: #24262e;
  --border: #2d2f38;
  --border-strong: #3c3f4a;
  --text: #ecebe6;
  --muted: #a6a8b0;
  --faint: #7c7f88;
  --accent: #5cc8a8;
  --accent-ink: #0d1f1a;
  --accent-soft: #1d3530;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-hover: 0 8px 28px rgba(0, 0, 0, .45);
  --hl: #5a4c10;
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 150px; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}

a { color: inherit; }
[hidden] { display: none !important; }
svg { display: block; }
button { font: inherit; color: inherit; }

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

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

.skip-link {
  position: absolute;
  inset-inline-start: 1rem;
  top: -100px;
  z-index: 100;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
}
.skip-link:focus { top: 1rem; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Shared stroke-icon style */
.icon-btn svg, .search svg, .to-top svg, .cat__icon svg, .card__action svg, .card__go svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Masthead ---------- */
.masthead { padding-top: 14px; }

.masthead__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  text-decoration: none;
  font-weight: 700;
}
.brand__mark { width: 34px; height: 34px; }
.brand__mark rect { fill: var(--accent); }
.brand__mark path {
  fill: none;
  stroke: var(--accent-ink);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--border-strong); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .i-sun { display: none; }
:root[data-theme="dark"] .icon-btn .i-sun { display: block; }
:root[data-theme="dark"] .icon-btn .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-btn .i-sun { display: block; }
  :root:not([data-theme="light"]) .icon-btn .i-moon { display: none; }
}

.hero { padding-block: 40px 22px; }
.hero h1 {
  margin: 0 0 .6rem;
  max-width: 22ch;
  font-size: clamp(1.6rem, 4.2vw, 2.6rem);
  line-height: 1.35;
  font-weight: 800;
  letter-spacing: -.01em;
  text-wrap: balance;
}
.hero__lead {
  margin: 0;
  max-width: 62ch;
  color: var(--muted);
  font-size: 1.02rem;
}
.hero__stats {
  margin: 1rem 0 0;
  color: var(--faint);
  font-size: .9rem;
}
.hero__stats b { color: var(--text); font-weight: 700; }

/* ---------- Sticky toolbar ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-block: 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.toolbar.is-stuck { border-bottom-color: var(--border); }

.search { position: relative; }
.search input {
  width: 100%;
  height: 50px;
  padding: 0 46px 0 46px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  box-shadow: var(--shadow);
  -webkit-appearance: none;
  appearance: none;
}
.search input::placeholder { color: var(--faint); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input::-webkit-search-cancel-button { display: none; }

.search__icon {
  position: absolute;
  inset-inline-start: 15px;
  top: 50%;
  width: 20px; height: 20px;
  transform: translateY(-50%);
  color: var(--faint);
  pointer-events: none;
}
.search__hint, .search__clear {
  position: absolute;
  inset-inline-end: 12px;
  top: 50%;
  transform: translateY(-50%);
}
.search__hint {
  padding: 0 .45rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--faint);
  font: .8rem/1.6 ui-monospace, monospace;
}
.search__clear {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  cursor: pointer;
}
.search__clear[hidden] { display: none; }
.search__clear svg { width: 16px; height: 16px; }
.search__clear:not([hidden]) ~ .search__hint,
.search:focus-within .search__hint { display: none; }

.chips {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(to left, #000 92%, transparent);
  -webkit-mask-image: linear-gradient(to left, #000 92%, transparent);
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  height: 34px;
  padding: 0 .8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: .86rem;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.is-active { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip__n { font-size: .75rem; opacity: .65; }
.chip[aria-disabled="true"] { opacity: .4; pointer-events: none; }

/* ---------- Directory ---------- */
main { padding-bottom: 48px; }
main:focus { outline: none; }

.result-line {
  min-height: 1.75em;
  margin: 14px 0 0;
  color: var(--faint);
  font-size: .88rem;
}

.cat { margin-top: 34px; }
.cat--fav,
.cat--fav[hidden] + #categories > .cat:first-child { margin-top: 8px; }
.cat__head {
  display: flex;
  align-items: center;
  gap: .7rem;
  margin-bottom: 14px;
}
.cat__icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px; height: 38px;
  border-radius: 11px;
  background: hsl(var(--h) 55% 50% / .13);
  color: hsl(var(--h) 55% 38%);
}
:root[data-theme="dark"] .cat__icon { color: hsl(var(--h) 60% 70%); background: hsl(var(--h) 50% 50% / .18); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cat__icon { color: hsl(var(--h) 60% 70%); background: hsl(var(--h) 50% 50% / .18); }
}
.cat__icon svg { width: 20px; height: 20px; }
.cat__title { margin: 0; font-size: 1.2rem; font-weight: 800; }
.cat__count {
  margin-inline-start: auto;
  color: var(--faint);
  font-size: .85rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* ---------- Favorites section ---------- */
.cat--fav {
  padding: 16px;
  border: 1px solid hsl(42 80% 50% / .35);
  border-radius: calc(var(--radius) + 6px);
  background: hsl(42 90% 55% / .07);
}
.cat--fav .cat__icon svg { fill: currentColor; }
.cat__note {
  margin: .7rem 0 0;
  color: var(--faint);
  font-size: .78rem;
}

/* ---------- Card ---------- */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 14px 14px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-hover);
}
.card:focus-within { border-color: var(--accent); }

.card__top {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-width: 0;
}
.card__avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: hsl(var(--h) 55% 50% / .14);
  color: hsl(var(--h) 55% 34%);
  font-weight: 800;
  font-size: 1.02rem;
}
:root[data-theme="dark"] .card__avatar { color: hsl(var(--h) 65% 72%); background: hsl(var(--h) 50% 50% / .2); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .card__avatar { color: hsl(var(--h) 65% 72%); background: hsl(var(--h) 50% 50% / .2); }
}
.card__avatar { position: relative; overflow: hidden; }
.card__avatar img {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 22px;
  height: 22px;
  object-fit: contain;
  opacity: 0;
  transition: opacity .2s;
}
.card__avatar.has-icon { background: #fbfbf9; box-shadow: inset 0 0 0 1px var(--border); }
.card__avatar.has-icon img { opacity: 1; }
.card__avatar.has-icon .card__letter { visibility: hidden; }

.card__titles { min-width: 0; flex: 1; }
.card__name {
  display: block;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.45;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Whole card is clickable via the name link */
.card__name::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.card__name--btn { width: 100%; padding: 0; border: 0; background: none; text-align: inherit; cursor: pointer; }
.card__name:focus-visible { outline: none; }
.card__name:focus-visible::after { outline: 2px solid var(--focus); outline-offset: 2px; }

.card__host {
  display: block;
  direction: ltr;
  text-align: right;
  color: var(--faint);
  font-size: .78rem;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card__desc {
  margin: .55rem 0 0;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.75;
}

.card__actions {
  display: flex;
  align-self: flex-start;
  gap: 2px;
  margin-top: -4px;
  margin-inline-end: -6px;
}

.card__action {
  position: relative; /* above the stretched link */
  z-index: 1;
  display: grid;
  place-items: center;
  flex: none;
  width: 32px; height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, background .15s;
}
.card:hover .card__action, .card__action:focus-visible { opacity: 1; }
.card__action:hover { background: var(--surface-2); color: var(--text); }
.card__action svg { width: 17px; height: 17px; }
@media (hover: none) { .card__action { opacity: 1; } }

.card__fav[aria-pressed="true"] { opacity: 1; color: #e0a100; }
.card__fav[aria-pressed="true"] svg { fill: currentColor; }
.card__fav:hover { color: #e0a100; }
.card.is-fav { border-color: hsl(42 80% 50% / .45); }

.card__badge {
  display: inline-block;
  margin-top: .5rem;
  padding: 0 .5rem;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .74rem;
  align-self: flex-start;
}

mark {
  background: var(--hl);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

/* ---------- Empty state ---------- */
.empty {
  margin-top: 40px;
  padding: 40px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
}
.empty strong { display: block; color: var(--text); font-size: 1.1rem; margin-bottom: .3rem; }
.btn {
  display: inline-block;
  margin-top: 1rem;
  padding: .55rem 1.2rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  cursor: pointer;
}

.notice {
  margin-top: 24px;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--border);
  padding-block: 28px 40px;
  color: var(--muted);
  font-size: .88rem;
}
.footer p { margin: 0 0 .4rem; }
.footer a { color: var(--accent); font-weight: 700; text-decoration: none; }
.footer a:hover { text-decoration: underline; }
.footer__meta { color: var(--faint); }

/* ---------- Floating bits ---------- */
.to-top {
  position: fixed;
  inset-inline-start: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 30;
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-hover);
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.to-top.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.to-top svg { width: 20px; height: 20px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 40;
  padding: .55rem 1.1rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: .9rem;
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  body { font-size: 14.5px; }
  .hero { padding-block: 26px 16px; }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .cat { margin-top: 28px; }
  .search__hint { display: none; }
  html { scroll-padding-top: 130px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
