:root{
  --bg: #0b1220;
  --panel: rgba(255,255,255,0.06);
  --panel2: rgba(255,255,255,0.09);
  --text: #e5e7eb;
  --muted: #a3a3a3;
  --border: rgba(148,163,184,0.25);
  --accent: #7dd3fc;
  --accent2: #a78bfa;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --shadow: 0 18px 50px rgba(0,0,0,0.35);
  --radius: 18px;
  --max: 1120px;
  --code: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  color-scheme: dark;
}
:root[data-theme="light"]{
  --bg: #f8fafc;
  --panel: rgba(15,23,42,0.04);
  --panel2: rgba(15,23,42,0.06);
  --text: #0f172a;
  --muted: #475569;
  --border: rgba(15,23,42,0.14);
  --accent: #0284c7;
  --accent2: #7c3aed;
  --shadow: 0 18px 50px rgba(2,8,23,0.18);
  color-scheme: light;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Apple Color Emoji","Segoe UI Emoji";
  background: radial-gradient(900px 600px at 30% 10%, rgba(125,211,252,0.16), transparent 55%),
              radial-gradient(900px 600px at 70% 20%, rgba(167,139,250,0.14), transparent 55%),
              var(--bg);
  color: var(--text);
  line-height: 1.65;
}

a{ color: var(--accent); text-decoration:none; }
a:hover{ text-decoration:underline; }

.container{ width: min(var(--max), calc(100% - 40px)); margin: 0 auto; }
.small{ font-size: 0.95rem; color: var(--muted); }

.nav{
  position: sticky; top: 0; z-index: 30;
  backdrop-filter: blur(10px);
  background: linear-gradient(to bottom, rgba(0,0,0,0.45), rgba(0,0,0,0.12));
  border-bottom: 1px solid var(--border);
}
:root[data-theme="light"] .nav{
  background: linear-gradient(to bottom, rgba(248,250,252,0.88), rgba(248,250,252,0.55));
}
.nav-inner{
  display:flex; align-items:center; justify-content:space-between;
  padding: 14px 0;
  gap: 14px;
}
.brand{
  display:flex; align-items:center; gap: 10px;
  font-weight: 800; letter-spacing: 0.2px;
}
.brand img{ width: 34px; height: 34px; border-radius: 12px; border:1px solid var(--border); background: var(--panel); }
.brand span{ display:inline-block; }
.nav-links{ display:flex; gap: 10px; flex-wrap: wrap; align-items:center; }
.nav-links a{
  padding: 8px 10px;
  border-radius: 12px;
  color: var(--text);
  opacity: 0.9;
}
.nav-links a.active, .nav-links a:hover{
  background: var(--panel);
  opacity: 1;
}
.nav-actions{ display:flex; gap: 10px; align-items:center; }
.btn{
  appearance:none; border: 1px solid var(--border); background: var(--panel);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 12px;
  cursor:pointer;
  box-shadow: none;
}
.btn:hover{ background: var(--panel2); }
.btn:active{ transform: translateY(1px); }
.icon-btn{ display:flex; align-items:center; gap: 8px; }
.kbd{
  font-family: var(--code);
  font-size: 12px;
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 10px;
  color: var(--muted);
  background: rgba(0,0,0,0.12);
}
:root[data-theme="light"] .kbd{ background: rgba(15,23,42,0.06); }

.burger{ display:none; }
@media (max-width: 880px){
  .burger{ display:inline-flex; }
  .nav-links{ display:none; position:absolute; left:0; right:0; top:64px; padding: 10px 20px 16px; background: var(--bg); border-bottom:1px solid var(--border); }
  .nav-links.open{ display:flex; flex-direction: column; align-items:flex-start; }
  .nav-links a{ width:100%; }
}

.hero{
  padding: 40px 0 26px;
}
.hero-grid{
  display:grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 18px;
  align-items: stretch;
}
@media (max-width: 920px){
  .hero-grid{ grid-template-columns: 1fr; }
}
.card{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px;
  box-shadow: var(--shadow);
}
.card.soft{ box-shadow: none; }
.h1{
  font-size: clamp(2rem, 4vw, 2.6rem);
  line-height: 1.1;
  margin: 0 0 10px;
  letter-spacing: -0.4px;
}
.h2{
  font-size: 1.45rem;
  margin: 28px 0 10px;
}
.h3{
  font-size: 1.2rem;
  margin: 22px 0 8px;
}
.pseudo{ opacity: 0.95; }
.lead{
  font-size: 1.05rem;
  color: var(--muted);
  margin: 0 0 12px;
}
.pills{ display:flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.pill{
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.14);
  padding: 8px 10px;
  border-radius: 999px;
  color: var(--text);
  font-size: 0.92rem;
}
:root[data-theme="light"] .pill{ background: rgba(15,23,42,0.05); }

.grid3{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
@media (max-width: 920px){
  .grid3{ grid-template-columns: 1fr; }
}

.section{ padding: 18px 0 42px; }

.footer{
  padding: 30px 0 46px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  margin-top: 40px;
}
.footer a{ color: var(--muted); }

.badge{
  display:inline-flex; align-items:center; gap: 8px;
  padding: 6px 10px; border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.9rem;
}
.dot{ width: 8px; height: 8px; border-radius: 999px; background: var(--accent); }

hr.sep{
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

.reader{
  padding: 18px 0 40px;
}
.reader-layout{
  display:grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  align-items:start;
}
@media (max-width: 980px){
  .reader-layout{ grid-template-columns: 1fr; }
}
.sidebar{
  position: sticky;
  top: 86px;
  max-height: calc(100vh - 110px);
  overflow:auto;
  padding: 14px;
}
.toc{
  display:flex;
  flex-direction: column;
  gap: 6px;
}
.toc a{
  color: var(--text);
  opacity: 0.86;
  border-radius: 12px;
  padding: 7px 10px;
  border: 1px solid transparent;
}
.toc a:hover{ background: var(--panel); opacity: 1; }
.toc a.active{ background: var(--panel2); border-color: var(--border); opacity: 1; }
.toc a.l1{ font-weight: 750; }
.toc a.l2{ padding-left: 18px; }
.toc a.l3{ padding-left: 30px; opacity: 0.78; }
.toc a.l4{ padding-left: 42px; opacity: 0.74; font-size: 0.95rem; }

.reader-main{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px;
  box-shadow: var(--shadow);
}

.reader-toolbar{
  display:flex; flex-wrap: wrap; align-items:center; justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.reader-toolbar .tools{ display:flex; gap: 10px; flex-wrap: wrap; align-items:center; }
.reader-toolbar input[type="search"]{
  width: min(360px, 70vw);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  outline: none;
  background: rgba(0,0,0,0.12);
  color: var(--text);
}
:root[data-theme="light"] .reader-toolbar input[type="search"]{ background: rgba(15,23,42,0.05); }

#content h1,#content h2,#content h3,#content h4{
  scroll-margin-top: 92px;
  position: relative;
}
#content p{ margin: 10px 0; }
#content h1{ margin-top: 30px; }
#content h2{ margin-top: 26px; }
#content h3{ margin-top: 22px; }
#content h4{ margin-top: 18px; font-size: 1.05rem; opacity: 0.92; }

.anchor-tools{
  position:absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  display:flex; gap: 6px;
  opacity: 0;
  transition: opacity .15s ease;
}
#content h1:hover .anchor-tools,
#content h2:hover .anchor-tools,
#content h3:hover .anchor-tools,
#content h4:hover .anchor-tools{ opacity: 1; }
.toolchip{
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 12px;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.9rem;
}
.toolchip:hover{ background: var(--panel2); }

.cite a{
  color: var(--muted);
  text-decoration:none;
}
.cite a:hover{ text-decoration: underline; }

.arabic{
  font-family: "Noto Naskh Arabic", "Amiri", "Scheherazade New", serif;
  font-size: 1.05em;
  letter-spacing: 0;
}
.url{ font-family: var(--code); font-size: 0.95rem; overflow-wrap: anywhere; color: var(--muted); }
.ref-item{
  display:grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  padding: 12px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.10);
  margin: 10px 0;
}
:root[data-theme="light"] .ref-item{ background: rgba(15,23,42,0.03); }
.ref-num{ font-family: var(--code); color: var(--muted); padding-top: 2px; }
.ref-body{ color: var(--text); }

.table{
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow:hidden;
}
.table th, .table td{
  border-bottom: 1px solid var(--border);
  padding: 12px 12px;
  vertical-align: top;
}
.table th{
  text-align:left;
  font-size: 0.95rem;
  color: var(--muted);
  background: rgba(0,0,0,0.12);
}
:root[data-theme="light"] .table th{ background: rgba(15,23,42,0.04); }
.table tr:last-child td{ border-bottom: none; }
.table .strength{
  font-weight: 700;
  display:inline-flex;
  align-items:center;
  gap: 8px;
}
.str-dot{ width: 9px; height: 9px; border-radius: 999px; background: var(--warn); }

.matrix-row{
  cursor: pointer;
}
.matrix-details{
  display:none;
  padding: 12px 0 0;
}
.matrix-row.open + .matrix-details{ display:block; }
.matrix-details .cols{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 980px){
  .matrix-details .cols{ grid-template-columns: 1fr; }
}
.matrix-details .col{
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  background: rgba(0,0,0,0.10);
}
:root[data-theme="light"] .matrix-details .col{ background: rgba(15,23,42,0.03); }
.col h4{ margin: 0 0 8px; font-size: 1rem; color: var(--muted); }

.modal{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display:none;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 18px;
}
.modal.open{ display:flex; }
.modal-card{
  width: min(880px, 100%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 14px;
}
.modal-head{ display:flex; align-items:center; justify-content: space-between; gap: 10px; padding: 8px 8px 12px; border-bottom: 1px solid var(--border); }
.modal-head h3{ margin:0; font-size: 1.05rem; }
.modal-body{ padding: 12px 8px 4px; }
textarea.note{
  width: 100%;
  min-height: 260px;
  resize: vertical;
  padding: 12px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.12);
  color: var(--text);
  outline: none;
  font-family: inherit;
}
:root[data-theme="light"] textarea.note{ background: rgba(15,23,42,0.05); }
.modal-foot{ padding: 12px 8px 8px; display:flex; justify-content: flex-end; gap: 10px; }

.toast{
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 999px;
  padding: 10px 14px;
  display:none;
  z-index: 80;
}
:root[data-theme="light"] .toast{ background: rgba(15,23,42,0.85); }

@media (prefers-reduced-motion: reduce){
  *{ scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

@media print{
  .nav, .sidebar, .reader-toolbar, .footer{ display:none !important; }
  body{ background: #fff !important; color: #000 !important; }
  .reader-main{ box-shadow:none !important; border: none !important; background: #fff !important; }
  a{ color:#000 !important; text-decoration: underline; }
}
