:root {
  --bg: #f6f6f3;
  --card: #ffffff;
  --fg: #1b1b1b;
  --muted: #666666;
  --line: #e1e1dc;
  --accent: #2f5bea;
  --danger: #b91c1c;
  --ok: #15803d;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --card: #1c1c1c;
    --fg: #eeeeee;
    --muted: #a0a0a0;
    --line: #2e2e2e;
    --accent: #7aa2ff;
    --danger: #f87171;
    --ok: #4ade80;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  line-height: 1.6;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; }
h1 { font-size: 1.5rem; }

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

.muted { color: var(--muted); font-size: 0.9rem; margin: 0; }
.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; }
.ok { color: var(--ok); }

button, input { font: inherit; }

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* تسجيل الدخول */
#login-view { padding-top: 48px; }
.panel {
  max-width: 380px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

label { display: block; margin: 10px 0 0; font-size: 0.95rem; }

label input,
.search input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}

.primary,
.secondary {
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  border: 1px solid var(--accent);
}

.primary { background: var(--accent); color: #ffffff; width: 100%; margin-top: 10px; }
.secondary { background: transparent; color: var(--fg); border-color: var(--line); }
.secondary[aria-pressed="true"] { background: var(--accent); color: #ffffff; border-color: var(--accent); }

/* الشريط العلوي والبحث */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.topbar h1 { flex: 1 0 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; flex: 1 1 auto; }

.search { margin-bottom: 4px; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }

.tab {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.tab span { opacity: 0.85; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 6px; }

.tag {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  border-radius: 999px;
  padding: 3px 10px;
  cursor: pointer;
  font-size: 0.85rem;
}

.tag[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.tag-label { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.tag-label span[lang="en"] { opacity: 0.8; }

/* البطاقات */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.site {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.thumb {
  display: block;
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--line);
  overflow: hidden;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.letter {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 2.6rem;
  font-weight: 700;
  color: #ffffff;
}

.tile-a { background: #4f46e5; }
.tile-b { background: #0f766e; }
.tile-c { background: #b45309; }
.tile-d { background: #be185d; }
.tile-e { background: #1d4ed8; }
.tile-f { background: #475569; }

.badge {
  position: absolute;
  top: 8px;
  inset-inline-start: 8px;
  background: rgba(0, 0, 0, 0.72);
  color: #ffffff;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.8rem;
}

.body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px 14px;
}

.body h2 { font-size: 1.05rem; }
.body h2 a { color: var(--fg); text-decoration: none; }
.body h2 a:hover { text-decoration: underline; }

.host { color: var(--muted); font-size: 0.85rem; margin: 0; }
.desc-ar { margin: 2px 0 0; }
.desc-en { color: var(--muted); font-size: 0.92rem; margin: 0; }

.tags { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }

.star {
  position: absolute;
  top: 8px;
  inset-inline-end: 8px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 0;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  font-size: 1.1rem;
  cursor: pointer;
}

.star[aria-pressed="true"] { color: #facc15; }

/* نافذة تغيير كلمة السر */
dialog {
  width: calc(100% - 32px);
  max-width: 380px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--fg);
  padding: 20px;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.panel-form h2 { font-size: 1.1rem; margin-bottom: 4px; }
.panel-form .actions { justify-content: flex-end; margin-top: 12px; }
