/* نمير يشرح · الملفات — colours and type from brand-identity.md */
:root {
  --paper: #F7F5EF; --ink: #14181F; --teal: #0F6E6B; --tint: #D9ECEA; --mint: #7FD1C9; --coral: #E0654F;
  --bg: var(--paper); --text: var(--ink); --muted: #6B717B; --card: #fff; --line: rgba(20,24,31,.09);
  --grid: rgba(20,24,31,.045); --accent: var(--teal); --accent-bg: var(--tint); --shadow: 0 1px 2px rgba(20,24,31,.05), 0 8px 24px -12px rgba(20,24,31,.18);
  --radius: 22px;
  --sans: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --ruqaa: 'Aref Ruqaa', 'IBM Plex Sans Arabic', serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #101419; --text: #EEF0EC; --muted: #9AA0A8; --card: #1A2028; --line: rgba(255,255,255,.08);
  --grid: rgba(255,255,255,.035); --accent: var(--mint); --accent-bg: rgba(127,209,201,.13);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -14px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans); color: var(--text); background-color: var(--bg); line-height: 1.6;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 34px 34px; min-height: 100vh; -webkit-font-smoothing: antialiased;
}
body.locked { overflow: hidden; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 3px; border-radius: 10px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 20px 40px; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0 18px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand img { width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--ink); background: var(--tint); }
[data-theme="dark"] .brand img { border-color: var(--mint); }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-family: var(--ruqaa); font-weight: 700; font-size: 27px; color: var(--accent); }
.brand-tag { font-size: 13px; color: var(--muted); font-weight: 500; }
.icon-btn {
  width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); flex: none;
}
.icon-btn:hover { color: var(--accent); }
.i-sun { display: none; }
[data-theme="dark"] .i-sun { display: block; }
[data-theme="dark"] .i-moon { display: none; }

/* Search */
.search { position: relative; }
.search svg { position: absolute; inset-inline-start: 20px; top: 50%; translate: 0 -50%; color: var(--muted); }
.search input {
  width: 100%; height: 60px; border-radius: 99px; border: 1.5px solid var(--line); background: var(--card);
  padding-inline: 54px 22px; font: 500 17px var(--sans); color: var(--text); box-shadow: var(--shadow);
  transition: border-color .15s;
}
.search input::placeholder { color: var(--muted); opacity: .8; }
.search input:focus { outline: none; border-color: var(--accent); }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.hint { font-size: 13.5px; color: var(--muted); margin: 8px 18px 22px; }

/* Hero */
.hero {
  position: relative; overflow: hidden; border-radius: 28px; color: var(--paper);
  background:
    radial-gradient(120% 140% at 0% 100%, rgba(127,209,201,.35), transparent 55%),
    linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px) 0 0/34px 34px,
    linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px) 0 0/34px 34px,
    var(--teal);
  display: flex; align-items: flex-end; justify-content: space-between; min-height: 250px;
}
.hero-copy { padding: 34px 36px 32px; position: relative; z-index: 1; max-width: 640px; }
.pill {
  display: inline-block; font-size: 13.5px; font-weight: 600; padding: 3px 14px 5px; border-radius: 99px;
  border: 1px solid rgba(247,245,239,.45); background: rgba(247,245,239,.1);
}
.hero h1 { font-size: clamp(30px, 4.6vw, 46px); line-height: 1.3; font-weight: 700; margin: 16px 0 10px; letter-spacing: -.2px; }
.hero h1 em { white-space: nowrap; font-style: normal; font-family: var(--ruqaa); color: var(--mint); font-size: 1.08em; }
.stats { font-size: 15px; opacity: .85; font-weight: 500; }
.hero-mascot { height: 260px; width: auto; align-self: flex-end; margin-inline-end: 44px; margin-bottom: -6px; filter: drop-shadow(0 10px 18px rgba(0,0,0,.25)); }

/* Toolbar */
.bar { display: flex; align-items: center; justify-content: space-between; margin: 34px 4px 16px; }
.bar h2 { font-size: 19px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.count { font: 600 13px var(--sans); color: var(--accent); background: var(--accent-bg); border-radius: 99px; padding: 1px 11px 3px; }
.views { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); }
.views button { width: 36px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 10px; background: none; color: var(--muted); }
.views button svg { width: 18px; height: 18px; }
.views button[aria-pressed="true"] { background: var(--accent-bg); color: var(--accent); }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.card {
  display: flex; flex-direction: column; text-decoration: none; background: var(--card); border-radius: var(--radius);
  border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; position: relative;
  transition: transform .18s cubic-bezier(.2,.8,.3,1.2), box-shadow .18s;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 2px 4px rgba(20,24,31,.06), 0 18px 36px -16px rgba(20,24,31,.3); }
.thumb { margin: 10px 10px 0; border-radius: 15px; overflow: hidden; aspect-ratio: 720/343; background: var(--paper); border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 50%; }
.thumb.none { display: grid; place-items: center; font-family: var(--ruqaa); color: var(--teal); font-size: 28px; }
.body { padding: 14px 18px 16px; display: flex; flex-direction: column; flex: 1; }
.new { align-self: flex-start; font-size: 12px; font-weight: 700; color: var(--paper); background: var(--coral); border-radius: 99px; padding: 1px 10px 3px; margin-bottom: 8px; }
.card h3 { font-size: 17px; line-height: 1.45; font-weight: 700; }
.card h3 em { font-style: normal; font-family: var(--ruqaa); color: var(--accent); font-size: 1.1em; }
.card .en { direction: ltr; text-align: right; font-size: 12.5px; color: var(--muted); font-weight: 500; margin-top: 2px; }
.card p.desc { font-size: 14px; color: var(--muted); margin-top: 6px; line-height: 1.6; }
.meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 14px; font-size: 13px; color: var(--muted); }
.kw {
  display: inline-flex; align-items: center; gap: 6px; direction: ltr; font: 600 12.5px var(--mono); letter-spacing: .5px;
  color: var(--accent); background: var(--accent-bg); border-radius: 99px; padding: 3px 11px;
}
.kw svg { width: 14px; height: 14px; }
.card.match { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg), var(--shadow); }
.match-tag { align-self: flex-start; margin-bottom: 8px; font-size: 12px; font-weight: 700; color: var(--paper); background: var(--teal); padding: 1px 10px 3px; border-radius: 99px; }
body.searching .hero { display: none; }
body.searching .bar { margin-top: 18px; }

/* List view */
.grid.list { grid-template-columns: 1fr; gap: 12px; }
.grid.list .card { flex-direction: row; align-items: stretch; }
.grid.list .thumb { width: 200px; flex: none; margin: 10px; margin-inline-end: 0; aspect-ratio: auto; align-self: center; }

.empty { text-align: center; color: var(--muted); padding: 50px 20px; font-size: 15.5px; }

.foot { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 56px; font-size: 13.5px; color: var(--muted); }
.foot a { text-decoration: none; font-weight: 600; }
.ruqaa { font-family: var(--ruqaa); color: var(--accent); font-size: 19px; }

/* Reader */
.viewer { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; flex-direction: column; animation: up .22s ease-out; }
.viewer[hidden] { display: none; }
@keyframes up { from { opacity: 0; transform: translateY(14px); } }
.v-bar {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.v-head { flex: 1; min-width: 0; text-align: center; display: flex; flex-direction: column; line-height: 1.35; }
.v-head strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-head span { font-size: 12.5px; color: var(--muted); }
.v-actions { display: flex; gap: 8px; align-items: center; }
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 42px; padding: 0 16px 2px; border-radius: 99px;
  background: var(--teal); color: var(--paper); text-decoration: none; font-weight: 600; font-size: 14.5px; white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); }
.btn svg { width: 18px; height: 18px; }
.v-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; }
.v-pages { --w: 820px; margin: 0 auto; padding: 24px 16px 110px; width: min(100%, calc(var(--w) + 32px)); display: flex; flex-direction: column; gap: 18px; }
.v-pages img { width: 100%; height: auto; aspect-ratio: 210/297; border-radius: 10px; box-shadow: var(--shadow); background: var(--paper); border: 1px solid var(--line); }
.v-end {
  text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 12px; box-shadow: var(--shadow);
}
.v-end p { color: var(--muted); font-size: 14.5px; }
.v-end .ruqaa { font-size: 26px; }
.zoom {
  position: fixed; bottom: max(18px, env(safe-area-inset-bottom)); left: 50%; translate: -50% 0; z-index: 51;
  display: flex; align-items: center; gap: 4px; padding: 5px; border-radius: 99px; background: var(--ink); color: var(--paper);
  box-shadow: 0 10px 30px -10px rgba(0,0,0,.5);
}
.zoom button { width: 36px; height: 36px; border-radius: 50%; border: 0; background: none; font-size: 20px; line-height: 1; }
.zoom button:hover { background: rgba(255,255,255,.12); }
.zoom span { min-width: 58px; text-align: center; font-size: 13.5px; font-weight: 600; background: rgba(255,255,255,.1); border-radius: 99px; padding: 4px 0 6px; }
[data-theme="dark"] .zoom { background: #2A323C; }

.toast {
  position: fixed; bottom: 84px; left: 50%; translate: -50% 20px; opacity: 0; pointer-events: none; z-index: 60;
  background: var(--ink); color: var(--paper); padding: 9px 18px 11px; border-radius: 99px; font-size: 14px; font-weight: 500;
  transition: opacity .2s, translate .2s;
}
[data-theme="dark"] .toast { background: #2A323C; }
.toast.show { opacity: 1; translate: -50% 0; }

@media (max-width: 640px) {
  .wrap { padding: 14px 14px 32px; }
  .brand-name { font-size: 24px; }
  .search input { height: 54px; font-size: 16px; }
  .hero { min-height: 0; }
  .hero-copy { padding: 26px 22px 24px; max-width: 74%; }
  .hero-mascot { height: 170px; margin: 0; position: absolute; inset-inline-end: 8px; bottom: -4px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .body { padding: 10px 12px 12px; }
  .card h3 { font-size: 14.5px; }
  .card .en, .card p.desc { display: none; }
  .meta { flex-wrap: wrap; padding-top: 10px; font-size: 12px; }
  .kw { font-size: 11px; padding: 2px 9px; }
  .grid.list .card p.desc { display: block; font-size: 13px; }
  .btn span { display: none; }
  .btn { width: 42px; padding: 0; justify-content: center; }
  .v-pages { padding: 14px 8px 100px; gap: 12px; }
}

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