:root {
  color-scheme: dark;
  --bg: #0B0F19;
  --panel: rgb(15 23 42 / 0.82);
  --panel-solid: #0f172a;
  --line: rgb(148 163 184 / 0.22);
  --text: #e5e7eb;
  --muted: #a3b0c2;
  --emerald: #10B981;
  --cyan: #06B6D4;
  --amber: #F59E0B;
  --violet: #8B5CF6;
  --g-mutawatir: #10B981;
  --g-sahih: #22C55E;
  --g-hasan: #3B82F6;
  --g-dhaif: #F43F5E;
  --font-ar: "Amiri", "Scheherazade New", "Noto Naskh Arabic", "Geeza Pro", "Traditional Arabic", serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(1px 1px at 12% 18%, #ffffff55, transparent 60%),
    radial-gradient(1px 1px at 78% 12%, #ffffff44, transparent 60%),
    radial-gradient(1.5px 1.5px at 34% 72%, #ffffff40, transparent 60%),
    radial-gradient(1px 1px at 90% 66%, #ffffff55, transparent 60%),
    radial-gradient(1px 1px at 56% 40%, #ffffff33, transparent 60%),
    radial-gradient(1px 1px at 8% 88%, #ffffff44, transparent 60%),
    radial-gradient(ellipse at 50% 55%, #131b30 0%, var(--bg) 70%),
    linear-gradient(rgb(148 163 184 / 0.04) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, rgb(148 163 184 / 0.04) 1px, transparent 1px) 0 0 / 48px 48px,
    var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.5;
}

[hidden] { display: none !important; }

:focus-visible { outline: 3px solid #fbbf24; outline-offset: 3px; }

.skip-link {
  position: absolute; inset-block-start: 0; inset-inline-start: 0;
  padding: .5rem .75rem; background: #fbbf24; color: #111;
  translate: 0 -120%;
}
.skip-link:focus { translate: 0 0; }

/* ---------- Anchor bar ---------- */
.anchor {
  flex: none;
  padding: .75rem clamp(.75rem, 3vw, 1.5rem) .5rem;
  background: linear-gradient(180deg, rgb(11 15 25 / .95), rgb(11 15 25 / .75));
  border-block-end: 1px solid var(--line);
  max-height: 46dvh;
  overflow-y: auto;
}
.anchor-top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.badge-ref {
  display: inline-block; padding: .15rem .7rem; border-radius: 999px;
  background: rgb(6 182 212 / .15); border: 1px solid var(--cyan); color: #67e8f9;
  font-weight: 600; font-size: .9rem;
}
.expiry { display: flex; align-items: baseline; gap: .5rem; font-size: .85rem; color: var(--muted); }
.expiry time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); }
.expiry[data-warn="true"] time { color: #fb7185; }
.demo-note {
  margin: .5rem 0 0; padding: .4rem .7rem; font-size: .85rem;
  background: rgb(245 158 11 / .12); border: 1px solid rgb(245 158 11 / .5); border-radius: .5rem; color: #fcd34d;
}
.verse-ar {
  margin: .6rem 0 .25rem; font-family: var(--font-ar);
  font-size: clamp(1.4rem, 1rem + 1.2vw, 2rem); line-height: 1.8; text-align: center;
  text-wrap: balance;
}
.verse-ms { margin: 0 auto; max-width: 70ch; text-align: center; color: #cbd5e1; font-size: .95rem; text-wrap: pretty; }
.core-summary { margin: .5rem auto 0; max-width: 70ch; font-size: .88rem; color: var(--muted); }
.core-summary summary { cursor: pointer; color: #cbd5e1; }
.core-summary p { margin: .4rem 0 0; }
.pins { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; margin-block: .6rem .25rem; }
.pin {
  display: inline-flex; align-items: center; gap: .5rem; max-width: 100%;
  padding: .3rem .8rem; border-radius: 999px; cursor: pointer;
  background: rgb(15 23 42 / .9); color: var(--text); border: 1px solid var(--line); font: inherit; font-size: .85rem;
}
.pin b { color: #67e8f9; }
.pin .pin-ar { font-family: var(--font-ar); font-size: 1.15rem; line-height: 1.4; }
.pin[aria-pressed="true"] { border-color: var(--cyan); background: rgb(6 182 212 / .18); box-shadow: 0 0 0 1px var(--cyan) inset; }
.pin:hover { border-color: #67e8f9; }

/* ---------- Toolbar ---------- */
.toolbar {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.25rem;
  padding: .5rem clamp(.75rem, 3vw, 1.5rem); border-block-end: 1px solid var(--line);
  background: rgb(11 15 25 / .7);
}
.filters { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip, .icon-btn {
  min-block-size: 36px; padding: .25rem .85rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: rgb(15 23 42 / .9); color: var(--text); font: inherit; font-size: .85rem;
}
.icon-btn { min-inline-size: 36px; padding-inline: .5rem; font-size: 1.2rem; line-height: 1; }
.chip:hover, .icon-btn:hover { border-color: #94a3b8; }
.chip[aria-pressed="true"] { background: #e5e7eb; color: #0B0F19; border-color: #e5e7eb; font-weight: 600; }
.chip-quran[aria-pressed="true"] { background: var(--emerald); border-color: var(--emerald); }
.chip-hadith[aria-pressed="true"] { background: var(--amber); border-color: var(--amber); }
.chip-athar[aria-pressed="true"] { background: var(--violet); border-color: var(--violet); color: #fff; }

.switch-row { display: inline-flex; align-items: center; gap: .6rem; font-size: .88rem; cursor: pointer; position: relative; }
.switch-row input {
  position: absolute; inline-size: 44px; block-size: 24px; margin: 0; opacity: 0; cursor: pointer;
}
.switch-track {
  flex: none; inline-size: 44px; block-size: 24px; border-radius: 999px; background: #334155;
  border: 1px solid #64748b; position: relative; transition: background .2s;
}
.switch-track::after {
  content: ""; position: absolute; inset-block-start: 2px; inset-inline-start: 2px;
  inline-size: 18px; block-size: 18px; border-radius: 50%; background: #e5e7eb; transition: translate .2s;
}
.switch-row input:checked + .switch-track { background: var(--g-dhaif); border-color: var(--g-dhaif); }
.switch-row input:checked + .switch-track::after { translate: 20px 0; }
.switch-row input:focus-visible + .switch-track { outline: 3px solid #fbbf24; outline-offset: 3px; }

.view-controls { display: flex; gap: .4rem; margin-inline-start: auto; }

/* ---------- Graph ---------- */
.graph-region { position: relative; flex: 1 1 auto; min-block-size: 0; }
#graph { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; display: block; touch-action: none; cursor: grab; }
#graph:active { cursor: grabbing; }

.ring { fill: none; stroke-width: 1.2; stroke-dasharray: 3 7; opacity: .55; }
.ring-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; fill: currentColor; opacity: .7; }

.sun-core { fill: url(#sun-grad); stroke: #fcd34d; stroke-width: 1.5; filter: url(#glow); }
.sun-ref { font-size: 20px; font-weight: 700; fill: #fff; text-anchor: middle; }
.sun-name { font-size: 11px; fill: #fde68a; text-anchor: middle; }

.pin-port { cursor: pointer; }
.pin-port circle { fill: #0f172a; stroke: #67e8f9; stroke-width: 2; }
.pin-port text { font-size: 12px; font-weight: 700; fill: #67e8f9; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.pin-port[aria-pressed="true"] circle { fill: #0e7490; stroke: #fff; }

.node { cursor: pointer; transition: opacity .35s, visibility 0s; }
.node .body { fill: #0f172a; stroke: var(--c); stroke-width: 2.5; }
.node.dhaif .body { stroke-dasharray: 5 4; }
.node .node-id { font-size: 14px; font-weight: 700; fill: var(--c); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.node .grade-dot { fill: var(--gc); stroke: var(--bg); stroke-width: 2; }
.node .node-title {
  font-size: 13px; fill: #e2e8f0; text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round;
}
.node:hover .body, .node:focus-visible .body, .node.is-selected .body { stroke-width: 4; filter: url(#glow); }
.node:focus-visible { outline: none; }
.node:focus-visible .body { stroke: #fbbf24; }

.edge { fill: none; stroke-width: 1.8; opacity: .75; transition: opacity .35s, visibility 0s; }
.edge-label { transition: opacity .35s, visibility 0s; pointer-events: none; }
.edge-label rect { fill: #0f172a; stroke: var(--c); stroke-width: 1; }
.edge-label text { font-size: 11px; fill: #e5e7eb; text-anchor: middle; dominant-baseline: central; }
.particle { fill: #fff; transition: opacity .35s; pointer-events: none; }

.is-hidden { opacity: 0 !important; visibility: hidden; pointer-events: none; transition: opacity .35s, visibility 0s .35s; }
.is-dim { opacity: .1; }
.edge.is-hl { opacity: 1; stroke-width: 2.6; }

.legend {
  position: absolute; inset-block-end: .75rem; inset-inline-start: .75rem; margin: 0; padding: .4rem .7rem;
  display: flex; flex-wrap: wrap; gap: .25rem 1rem; list-style: none; font-size: .78rem; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line); border-radius: .5rem; max-inline-size: calc(100% - 1.5rem);
}
.dot { display: inline-block; inline-size: .7rem; block-size: .7rem; border-radius: 50%; background: var(--c); margin-inline-end: .4rem; }
.dot-dhaif { background: none; border: 2px dashed var(--g-dhaif); }

.loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); }

.state {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: .5rem;
  padding: 2rem; text-align: center; background: rgb(11 15 25 / .92); z-index: 5;
}
.state h1 { margin: 0; font-size: 1.4rem; }
.state p { margin: 0; max-inline-size: 60ch; color: #cbd5e1; }
.prompt-box { padding: .6rem .9rem; border-radius: .5rem; border: 1px dashed var(--line); font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }

/* ---------- Drawer ---------- */
.drawer {
  margin: 0; margin-inline-start: auto; padding: 0; border: 0; border-inline-start: 1px solid var(--line);
  inset-block: 0; inline-size: min(32rem, 100vw); max-inline-size: 100vw; block-size: 100dvh; max-block-size: none;
  background: var(--panel-solid); color: var(--text);
  box-shadow: -20px 0 60px rgb(0 0 0 / .5);
  translate: 100% 0;
  transition: translate .3s ease, overlay .3s allow-discrete, display .3s allow-discrete;
}
.drawer[open] { translate: 0 0; }
@starting-style { .drawer[open] { translate: 100% 0; } }
.drawer::backdrop {
  background: rgb(2 6 23 / 0);
  transition: background .3s, overlay .3s allow-discrete, display .3s allow-discrete;
}
.drawer[open]::backdrop { background: rgb(2 6 23 / .55); }
@starting-style { .drawer[open]::backdrop { background: rgb(2 6 23 / 0); } }

.drawer-inner { block-size: 100%; overflow-y: auto; padding: 1rem 1.25rem 2rem; overscroll-behavior: contain; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.badges { display: flex; flex-wrap: wrap; gap: .4rem; }
.badge {
  display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .65rem; border-radius: 999px;
  font-size: .78rem; font-weight: 700; border: 1px solid var(--bc); color: var(--bc); background: color-mix(in srgb, var(--bc) 14%, transparent);
}
.drawer h2 { margin: .75rem 0 .5rem; font-size: 1.25rem; line-height: 1.35; text-wrap: balance; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: 0 0 1rem; font-size: .88rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

[role="tablist"] { display: flex; gap: .25rem; overflow-x: auto; border-block-end: 1px solid var(--line); scrollbar-width: thin; }
[role="tab"] {
  position: relative; flex: none; padding: .55rem .9rem; border: 0; background: none; color: var(--muted);
  font: inherit; font-size: .88rem; cursor: pointer; white-space: nowrap;
}
[role="tab"][aria-selected="true"] { color: #fff; font-weight: 600; }
[role="tab"][aria-selected="true"]::after {
  content: ""; position: absolute; inset: auto 0 -1px; border-block-end: 3px solid var(--cyan);
}
[role="tabpanel"] { padding-block: 1rem; }
[role="tabpanel"] h3 { margin: 1rem 0 .35rem; font-size: .95rem; color: #cbd5e1; }
[role="tabpanel"] h3:first-child { margin-block-start: 0; }
[role="tabpanel"] p { margin: 0 0 .75rem; text-wrap: pretty; }
.note { padding: .6rem .8rem; border-radius: .5rem; background: rgb(148 163 184 / .08); border: 1px solid var(--line); font-size: .9rem; }
.note.dhaif { background: rgb(244 63 94 / .1); border-color: rgb(244 63 94 / .5); }
.links { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.links li { padding: .55rem .7rem; border: 1px solid var(--line); border-radius: .5rem; font-size: .88rem; }
.links .rel { display: inline-block; margin-inline-end: .4rem; padding: .05rem .5rem; border-radius: 999px; background: #1e293b; font-size: .75rem; font-weight: 600; color: #fcd34d; }
.arabic {
  font-family: var(--font-ar); font-size: 1.6rem; line-height: 2.1; text-align: right; direction: rtl;
  padding: .75rem 1rem; background: rgb(255 255 255 / .04); border-inline-end: 3px solid var(--cyan); border-radius: .4rem;
  margin: 0 0 1rem; white-space: pre-wrap;
}
.empty { color: var(--muted); font-style: italic; }

.pivot { margin-block-start: 1rem; padding-block-start: 1rem; border-block-start: 1px solid var(--line); }
.copy { position: relative; display: inline-block; }
.btn-primary {
  min-block-size: 40px; padding: .5rem 1rem; border-radius: .5rem; border: 0; cursor: pointer;
  background: var(--cyan); color: #04202a; font: inherit; font-weight: 700;
}
.btn-primary:hover { background: #22d3ee; }
.tip {
  position: absolute; inset-block-start: calc(100% + .35rem); inset-inline-start: 0; padding: .2rem .6rem;
  border-radius: .4rem; background: #e5e7eb; color: #0B0F19; font-size: .8rem; font-weight: 600; white-space: nowrap;
  opacity: 0; transition: opacity .15s; pointer-events: none;
}
.tip:not(:empty) { opacity: 1; }
.pivot-preview { margin: 1.8rem 0 0; font-size: .85rem; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }

@media (max-width: 640px) {
  .view-controls { margin-inline-start: 0; }
  .legend { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer::backdrop, .node, .edge, .edge-label, .switch-track::after { transition: none; }
  .drawer { translate: 0 0; }
}

.dot-quran { --c: var(--emerald); }
.dot-hadith { --c: var(--amber); }
.dot-athar { --c: var(--violet); }
