:root {
  /* Light theme variables */
  --bg: #ffffff;
  --glass: rgba(255,255,255,0.52);
  --surface: rgba(255,255,255,0.65);
  --surface-2: rgba(255,255,255,0.85);
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --primary: #3b82f6;
  --border: 1px solid rgba(0,0,0,0.08);
  --shadow: 0 8px 24px rgba(0,0,0,0.06);
  --chip-bg: #f3f4f6;
  --chip-fg: #111827;
  --chip-border: 1px solid rgba(0,0,0,0.08);
  --mark-bg: #dbeafe;
  --mark-fg: #1e3a8a;
}

html[data-theme="dark"] {
  /* Dark theme variables */
  --bg: #0d1117;
  --glass: rgba(17,24,39,0.48);
  --surface: rgba(22,27,34,0.55);
  --surface-2: #161b22;
  --card: #1c2330;
  --text: #e6edf3;
  --muted: #9ea7b3;
  --primary: #3b82f6;
  --border: 1px solid rgba(255,255,255,0.10);
  --shadow: 0 12px 28px rgba(0,0,0,0.55);
  --chip-bg: #1f2735;
  --chip-fg: #e6edf3;
  --chip-border: 1px solid rgba(255,255,255,0.12);
  --mark-bg: #334155;
  --mark-fg: #ffffff;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Roboto, Arial;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  position: relative;
  z-index: 0;
  transition: background 0.25s ease, color 0.25s ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(120% 120% at 0% 0%, rgba(96,165,250,0.22) 0, transparent 55%),
    radial-gradient(120% 120% at 100% 100%, rgba(37,99,235,0.16) 0, transparent 55%);
}

html[data-theme="dark"] body::before {
  background:
    radial-gradient(120% 120% at 0% 0%, rgba(96,165,250,0.18) 0, transparent 55%),
    radial-gradient(120% 120% at 100% 100%, rgba(30,41,59,0.9) 0, transparent 65%);
}

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

::placeholder {
  color: var(--muted);
  opacity: 0.9;
  font-family: inherit;
}

.container {
  max-width: 1200px;
  margin-inline: auto;
  padding: 0 16px;
}

main.container {
  padding-top: 16px;
  padding-bottom: 24px;
}

/* Glass header */
.glassbar {
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
  backdrop-filter: blur(12px);
  background: var(--surface);
  border-bottom: var(--border);
}

.bar-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 20px;
}

.brandlink {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  order: 1;
}

.brand-img {
  height: 34px;
  width: auto;
  object-fit: contain;
}

.nav-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.left-actions {
  display: flex;
  gap: 10px;
  order: 2;
  margin-right: auto;
}

.action-btn {
  padding: 8px 16px;
  min-width: 110px;
  text-align: center;
  border-radius: 10px;
  font-size: 14px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  text-decoration: none !important;
}

.pill {
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  padding: 8px 12px;
  border-radius: 999px;
  border: var(--border);
  background: var(--chip-bg);
  color: var(--chip-fg);
  text-decoration: none !important;
}

.pill:hover {
  opacity: 0.9;
  text-decoration: none;
}

.btn {
  cursor: pointer;
  border: var(--border);
  padding: 8px 12px;
  border-radius: 10px;
  background: transparent;
}

.btn.ghost {
  background: transparent;
  border: var(--border);
  color: var(--text);
}

.btn.ghost:hover {
  background: rgba(255,255,255,0.06);
}

.btn.small {
  padding: 6px 10px;
}

/* Theme Toggle Specific Styles */
#themeToggle {
  position: relative;
  width: 40px;
  height: 40px;
  min-width: auto;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
}

#themeIcon {
  position: absolute;
  top: 55%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 20px;
}

/* Hero */
.hero {
  margin: 22px 0 8px;
  text-align: center;
}

.hero h1 {
  margin: 0;
  font-weight: 900;
  font-size: clamp(1.5rem, 3.2vw, 2.2rem);
}

.hero h1 span {
  color: var(--primary);
}

.hero .sub {
  margin: 0.4rem auto 0;
  max-width: 760px;
  color: var(--muted);
}

/* Search */
.search-area {
  margin-top: 12px;
}

.searchbox {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--surface-2);
  border: var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.search-icn {
  text-align: center;
  opacity: 0.9;
}

#searchInput {
  background: transparent;
  border: none;
  outline: none;
  padding: 10px 6px;
  font-size: 1.02rem;
  color: var(--text);
  direction: rtl;
}

#clearBtn {
  visibility: hidden;
}

#clearBtn.show {
  visibility: visible;
}

/* Chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 2px;
}

.chip {
  padding: 6px 10px;
  border-radius: 12px;
  border: var(--chip-border);
  background: var(--chip-bg);
  color: var(--chip-fg);
  cursor: pointer;
  font-size: 0.9rem;
}

.chip.active {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

/* Filters row */
.filters-row {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.selectbox {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 220px;
  position: relative;
}

.selectbox label {
  font-size: 0.85rem;
  color: var(--muted);
}

.selectbox select {
  border-radius: 999px;
  padding: 10px 40px 10px 16px;
  background: linear-gradient(135deg, color-mix(in hsl, var(--surface-2), transparent 5%), color-mix(in hsl, var(--surface), transparent 20%));
  border: var(--border);
  color: var(--text);
  outline: none;
  font-size: 0.9rem;
  appearance: none;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(15,23,42,0.10);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, transform 0.08s ease;
}

.selectbox select:hover {
  box-shadow: 0 14px 30px rgba(15,23,42,0.16);
  transform: translateY(-1px);
}

.selectbox select:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px color-mix(in hsl, var(--primary), transparent 40%), 0 16px 40px rgba(15,23,42,0.24);
}

html[data-theme="dark"] .selectbox select {
  background: linear-gradient(135deg, color-mix(in hsl, var(--surface-2), transparent 10%), color-mix(in hsl, var(--surface), transparent 30%));
}

.selectbox::after {
  content: "▾";
  position: absolute;
  inset-inline-end: 16px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 0.8rem;
  opacity: 0.7;
}

/* Meta */
.meta-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 6px;
  gap: 12px;
}

.meta-left {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.meta-right {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
}

.muted {
  color: var(--muted);
  font-size: 0.95rem;
}

/* Cards */
.results-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 14px;
}

.card {
  background: var(--card);
  border: var(--border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.14s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-3px);
}

.card-header {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  flex: 0 0 48px;
  overflow: hidden;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  border: var(--border);
}

.logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.logo .fallback {
  font-weight: 900;
  font-size: 1.05rem;
  opacity: 0.8;
}

.title-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
  justify-content: space-between;
}

.card-title {
  font-weight: 800;
  margin: 0;
  font-size: 1.02rem;
}

.card-title-link {
  color: inherit;
  text-decoration: none;
}

.card-title-link:hover {
  text-decoration: underline;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  font-size: 0.74rem;
  padding: 4px 8px;
  border-radius: 999px;
  border: var(--border);
  color: var(--muted);
  background: transparent;
}

.card-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
  min-height: 42px;
}

.card-actions {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.link {
  text-decoration: none;
  color: #fff;
  background: var(--primary);
  padding: 8px 10px;
  border-radius: 10px;
  font-weight: 800;
}

.ghostlink {
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
}

.no-results {
  margin: 24px 0;
  padding: 16px;
  border-radius: 14px;
  text-align: center;
  border: var(--border);
  background: var(--surface-2);
}

.hidden {
  display: none;
}

mark {
  background: var(--mark-bg);
  color: var(--mark-fg);
  padding: 0 0.2em;
  border-radius: 4px;
}

/* Footer */
.footer {
  padding: 24px 0;
  margin-top: 40px;
  border-top: var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  text-align: center;
}

.footer-links {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.footer a {
  color: inherit;
  text-decoration: none;
  opacity: 0.85;
  transition: opacity 0.2s;
}

.footer a:hover {
  opacity: 1;
}

.footer-copy {
  opacity: 0.7;
}

html[data-theme="dark"] .footer {
  border-color: rgba(255,255,255,0.12);
}

html[data-theme="dark"] .footer-copy {
  opacity: 0.8;
}

/* General links */
a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: none;
  opacity: 0.9;
}

/* SVG icons in dark mode */
html[data-theme="dark"] svg {
  fill: #ffffff;
  color: #ffffff;
}

html[data-theme="dark"] img[src$=".svg"] {
  filter: brightness(0) invert(1);
}

/* Media queries */
@media (max-width: 720px) {
  .brand-img {
    height: 26px;
  }

  .pill {
    font-size: 0.74rem;
    padding: 3px 8px;
  }

  #themeToggle {
    width: 32px;
    height: 32px;
  }

  #themeIcon {
    font-size: 16px;
  }
}