:root {
  --bg: #faf7f0;
  --card: #ffffff;
  --ink: #1d2a25;
  --muted: #5d6b65;
  --line: #e6dfcf;
  --green: #0f4c3a;
  --green-2: #176b52;
  --gold: #c99a2e;
  --gold-soft: #f6ecd3;
  --boy: #2a6f97;
  --girl: #b5487a;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1714;
    --card: #17221e;
    --ink: #eef2ef;
    --muted: #9fb0a8;
    --line: #26342e;
    --green: #2f9e78;
    --green-2: #3bb98d;
    --gold: #e0b44f;
    --gold-soft: #2a2717;
    --boy: #7ab8de;
    --girl: #e48ab3;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { font-family: Lora, Georgia, serif; line-height: 1.2; }
button { font: inherit; cursor: pointer; }

/* Hero */
.hero {
  color: #fff;
  background:
    radial-gradient(circle at 20% 20%, rgba(233, 196, 106, .18), transparent 40%),
    linear-gradient(135deg, #0b3a2c, #0f4c3a 55%, #176b52);
  position: relative;
  overflow: hidden;
  padding: 48px 0 56px;
  text-align: center;
}
.hero::before {
  content: "";
  position: absolute; inset: 0;
  opacity: .08;
  background-image:
    repeating-linear-gradient(45deg, #fff 0 1px, transparent 1px 22px),
    repeating-linear-gradient(-45deg, #fff 0 1px, transparent 1px 22px);
}
.hero .wrap { position: relative; }
.bismillah { font-size: 1.6rem; color: #e9c46a; margin: 0 0 8px; font-family: "Amiri", "Traditional Arabic", serif; }
.hero h1 { font-size: clamp(2.2rem, 6vw, 3.4rem); margin: 0 0 10px; }
.lead { font-size: 1.1rem; margin: 0 auto 22px; max-width: 620px; opacity: .92; }
.hadith {
  margin: 0 auto; max-width: 640px;
  padding: 14px 18px;
  border: 1px solid rgba(233, 196, 106, .45);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, .15);
  font-style: italic;
}
.hadith cite { display: block; margin-top: 6px; font-style: normal; color: #e9c46a; font-size: .9rem; }

/* Controls */
.controls {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin: -28px 0 22px;
  position: relative;
  box-shadow: 0 10px 30px rgba(15, 76, 58, .08);
}
.search { position: relative; }
.search svg {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2;
}
.search input {
  width: 100%;
  padding: 14px 14px 14px 44px;
  font: inherit; font-size: 1.05rem;
  color: var(--ink); background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 12px;
  outline: none;
}
.search input:focus { border-color: var(--green-2); }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.seg, .chip, .letters button, .ghost, .primary {
  border: 1px solid var(--line);
  background: transparent; color: var(--ink);
  border-radius: 999px;
  padding: 7px 14px;
  transition: background .15s, color .15s, border-color .15s;
}
.seg { font-weight: 600; }
.seg:hover, .chip:hover, .letters button:hover, .ghost:hover { border-color: var(--green-2); }
.seg.active, .chip.active, .letters button.active { background: var(--green); border-color: var(--green); color: #fff; }
.chip { font-size: .92rem; }
.letters { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 14px; }
.letters button { padding: 4px 0; width: 36px; font-size: .9rem; border-radius: 8px; }
.toolbar {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
  margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line);
  color: var(--muted); font-size: .95rem;
}
.tools { display: flex; align-items: center; gap: 10px; }
.script { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.primary { background: var(--green); color: #fff; border-color: var(--green); font-weight: 600; }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.card {
  position: relative;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  color: var(--ink);
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(15, 76, 58, .1); border-color: var(--gold); }
.card .nm { font-family: Lora, Georgia, serif; font-size: 1.4rem; font-weight: 700; margin: 0 28px 2px 0; }
.card .mn { color: var(--muted); font-size: .95rem; margin: 0; }
.card .g { font-size: .78rem; font-weight: 600; letter-spacing: .02em; }
.g.o { color: var(--boy); }
.g.q { color: var(--girl); }
.card .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.tag { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--gold-soft); color: var(--ink); }
.fav {
  position: absolute; top: 10px; right: 10px;
  border: 0; background: none; font-size: 1.25rem; line-height: 1;
  color: var(--line); padding: 4px;
}
.fav.on { color: #d64545; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.more { display: block; margin: 20px auto 0; }

/* Advice */
.advice { margin: 56px 0 30px; }
.advice h2 { font-size: 1.7rem; text-align: center; margin-bottom: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.cards article { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: var(--radius); padding: 16px; }
.cards h3 { margin: 0 0 6px; font-size: 1.1rem; color: var(--green-2); }
.cards p { margin: 0; color: var(--muted); }
.note { text-align: center; color: var(--muted); font-size: .9rem; margin-top: 18px; }

.advice h2.sub { margin-top: 44px; }
.note a { color: var(--green-2); }
.avoid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; margin-top: 14px; }
.avoid div { background: var(--card); border: 1px solid var(--line); border-left: 4px solid #c0504d; border-radius: 12px; padding: 12px 14px; }
.avoid b { display: block; font-family: Lora, Georgia, serif; font-size: 1.05rem; margin-bottom: 2px; }
.avoid span { color: var(--muted); font-size: .93rem; }
.tag.t { background: var(--green); color: #fff; }

/* Dialog */
dialog {
  width: min(520px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px 24px 22px;
  background: var(--card); color: var(--ink);
}
dialog::backdrop { background: rgba(10, 30, 22, .55); backdrop-filter: blur(2px); }
dialog h2 { font-size: 2.3rem; margin: 2px 0 0; color: var(--green-2); }
dialog h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 4px; font-family: Inter, sans-serif; }
dialog p { margin: 0; }
.close { position: absolute; top: 10px; right: 14px; border: 0; background: none; font-size: 1.8rem; color: var(--muted); }
.dGender { font-size: .85rem; font-weight: 600; }
.dCyr { color: var(--muted); }
.dTags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.preview { margin-top: 20px; padding: 14px; background: var(--bg); border-radius: 12px; }
.preview label { font-size: .9rem; color: var(--muted); }
.preview input {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px;
}
.dFull { font-family: Lora, Georgia, serif; font-size: 1.25rem; margin-top: 10px !important; min-height: 1.5em; }
.dActions { display: flex; gap: 10px; margin-top: 18px; }

.foot { border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; text-align: center; padding: 20px 0; }

@media (max-width: 560px) {
  .hero { padding: 34px 0 48px; }
  .controls { padding: 14px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 12px; }
  .card .nm { font-size: 1.15rem; }
  .card .mn { font-size: .86rem; }
  .letters button { width: 32px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; margin-left: -14px; margin-right: -14px; padding: 0 14px 4px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { white-space: nowrap; flex: none; }
}
@media (max-width: 360px) { .grid { grid-template-columns: 1fr; } }
