:root { --bg:#faf8f3; --fg:#222; --muted:#777; --accent:#2f6b4f; --card:#fff; --line:#e3ddd0; --f:#9b3d6b; }
@media (prefers-color-scheme: dark) { :root { --bg:#171a18; --fg:#e8e6e1; --muted:#9a9a9a; --accent:#7fc4a0; --card:#212522; --line:#333a35; --f:#e08ab4; } }
* { box-sizing: border-box; }
body { margin:0; background:var(--bg); color:var(--fg); font:16px/1.6 system-ui, "Segoe UI", Tahoma, sans-serif; }
main { max-width: 900px; margin: 0 auto; padding: 16px; }
h1 { color: var(--accent); margin: .2em 0; }
input, select, button { font: inherit; padding: .5em .7em; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg); }
button { cursor: pointer; background: var(--accent); color: #fff; border: 0; }
button.secondary { background: var(--card); color: var(--fg); border: 1px solid var(--line); }
button.danger { background: #b23b3b; }
input[type=search] { width: 100%; }
.muted { color: var(--muted); }
.notice { background: #b23b3b; color: #fff; padding: .6em 1em; border-radius: 8px; }
.results { list-style: none; padding: 0; }
.results li { padding: .5em; border-bottom: 1px solid var(--line); cursor: pointer; }
.results li:hover { background: var(--card); }
.tree, .tree ul { list-style: none; padding-inline-start: 1.2em; margin: 0; border-inline-start: 1px dashed var(--line); }
.tree { border: 0; padding: 0; }
.tree summary { cursor: pointer; }
.tree .leaf { padding-inline-start: 1.1em; }
.female { color: var(--f); }
.hit { background: #ffe58a; color: #222; border-radius: 4px; padding: 0 .2em; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin: 12px 0; display: grid; gap: 10px; }
.card label { display: grid; gap: 4px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
footer { margin-top: 2em; text-align: center; }

textarea { font: inherit; padding: .5em .7em; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg); }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: .6em 0; border-top: 1px solid var(--line); }
.plain p { white-space: pre-wrap; margin: .3em 0; }
.plain button { font-size: 13px; padding: .3em .8em; }

/* ===== صفحة الشجرة ===== */
.tree-page { --pink:#ff3d8b; --wood:#a8703e; --wood-d:#6e4826; --gold:#b8854a; --panel:#2a2118; color:#efe6d6;
  background:#1f1812; -webkit-font-smoothing:antialiased; text-rendering:optimizeLegibility; font-family:"IBM Plex Sans Arabic", system-ui, Tahoma, sans-serif; }
.tree-page button, .tree-page .btn { font-family:inherit; }

.top { padding:12px 16px; display:grid; gap:10px; }
.top h1 { margin:0; font-size:26px; font-weight:700; color:var(--gold); }
.tools { display:flex; flex-wrap:wrap; gap:8px; }
.top { position:relative; }
.bar { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.menu-btn { display:none; }
.tools button, .find > button, .btn { background:var(--panel); color:#c9a77a; border:1px solid var(--wood-d); border-radius:99px;
  padding:6px 14px; font-size:14px; font-weight:700; text-decoration:none; display:inline-block; }
.tools button:hover, .find > button:hover, .btn:hover { background:#3a2d20; }
.find { display:flex; gap:8px; align-items:center; }
.find .field { position:relative; flex:1; }
.find input { width:100%; background:var(--panel); color:#fff; border:1px solid var(--wood-d); border-radius:12px; padding:12px 14px; }
.find > button { border-radius:12px; padding:12px 14px; }
#pos { color:#cfc6b4; font-size:13px; min-width:4em; }
.results { position:absolute; inset-inline:0; top:100%; z-index:5; margin:4px 0 0; max-height:50vh; overflow:auto; background:#2a2118; border-radius:12px; }
.results:empty { display:none; }
.tree-page .results li { border-color:#ffffff1a; font-size:14px; }
.tree-page .results li:hover { background:#3a3127; }
.tree-page .notice { margin:0 16px 10px; }

.screen { height:100dvh; min-height:480px; display:flex; flex-direction:column; }
.stage { position:relative; flex:1; border-block:1px solid #4a3826;
  background:radial-gradient(ellipse at 50% 40%, #415534 0%, #27311f 50%, #1a1611 100%); }
.view { position:absolute; inset:0; overflow:auto; display:flex; cursor:grab; scrollbar-color:var(--wood-d) transparent; }
.view.drag { cursor:grabbing; user-select:none; }
.tree { position:relative; margin:auto auto 0; padding:40px 60px 30px; width:max-content; }
.n { display:flex; flex-direction:column; align-items:center; }
.kids { display:flex; align-items:flex-end; position:relative; padding-bottom:26px; }
.kids::after, .kids > .n::after { content:""; position:absolute; bottom:0; left:50%; width:10px; height:26px; margin-left:-5px; background:var(--wood); }
.kids > .n { position:relative; padding:0 6px 26px; }
.kids > .n::before { content:""; position:absolute; bottom:0; left:-1px; right:-1px; height:10px; background:var(--wood); }
.kids > .n:first-child::before { inset-inline-start:calc(50% - 5px); }
.kids > .n:last-child::before { inset-inline-end:calc(50% - 5px); }
.kids > .n:only-child::before { display:none; }

.nd { font:inherit; border:0; cursor:pointer; display:flex; flex-direction:column; gap:1px; min-width:124px;
  padding:8px 16px 9px; border-radius:18px 18px 18px 6px; background:var(--c); color:#1d2140; white-space:nowrap;
  box-shadow:0 4px 0 rgba(0,0,0,.28), inset 0 -2px 0 rgba(0,0,0,.12); position:relative; z-index:1; }
.nd:hover { box-shadow:0 4px 0 rgba(0,0,0,.28), inset 0 0 0 2px rgba(255,255,255,.45); }
.nd small { font-size:13px; font-weight:500; color:#3a3f5c; text-align:start; line-height:1.2; }
.nd .nm { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.nd b { font-size:18px; font-weight:600; line-height:1.35; }
.nd i { font-style:normal; font-size:13px; font-weight:600; color:#fff; background:#00000059; padding:1px 9px; border-radius:99px; }
.nd.trunk { background:#9a663a; color:#fff; text-shadow:none; border:2px solid var(--wood-d); border-radius:999px; min-width:84px; padding:8px 20px; align-items:center; }
.nd.trunk .nm { justify-content:center; }
.nd.trunk.root { background:#6e4826; border-color:#4a2f18; }
.stem { width:10px; height:22px; background:var(--wood); }
.tribe { position:relative; background:#5a3a1f; color:#fff; font-weight:700; font-size:20px; padding:10px 28px; border-radius:999px;
  border:2px solid #3e2814; box-shadow:0 4px 0 rgba(0,0,0,.3); }
.tribe::after { content:""; position:absolute; left:-60px; right:-60px; bottom:-28px; height:30px; z-index:-1;
  background:radial-gradient(ellipse at center, #c9a77a33, transparent 70%); }
.nd.f { background:color-mix(in srgb, var(--c) 55%, #fff); }
.nd.me b::before { content:"★ "; color:#b8860b; }
.path-svg { position:absolute; inset:0; width:100%; height:100%; overflow:visible; pointer-events:none; }
.path-svg path { fill:none; stroke:var(--pink); stroke-width:10; stroke-linejoin:round; stroke-linecap:round; }
.nd.path, .nd.path:hover { box-shadow:0 0 0 3px var(--pink), 0 4px 0 rgba(0,0,0,.28); }
.nd.sel, .nd.sel:hover { box-shadow:0 0 0 4px var(--pink), 0 0 0 9px #ff3d8b44, 0 4px 0 rgba(0,0,0,.28); }
.nd.hit { animation:pulse 1s 2; }
@keyframes pulse { 50% { transform:scale(1.08); } }

.pop { position:absolute; z-index:4; width:270px; max-height:calc(100% - 16px); overflow:auto; display:grid; gap:8px;
  background:#2a2118; border:1px solid #8a5a2e; border-radius:14px; padding:14px; box-shadow:0 10px 30px #0008; }
.pop[hidden] { display:none; }
.pop .x { position:absolute; top:10px; left:10px; width:28px; height:28px; padding:0; border-radius:50%; background:#00000055; color:#efe6d6; font-size:13px; }
.pop small { color:#cfc6b4; font-size:13px; }
.pop h3 { margin:-4px 0 0; color:var(--gold); font-size:20px; }
.pop .lin { margin:0; font-size:14px; line-height:1.8; color:#e6dccb; }
.pop .note { margin:0; color:#f0c24b; font-size:14px; }
.pop hr { width:100%; border:0; border-top:1px solid #5a4430; margin:2px 0; }
.pop h4 { margin:0; font-size:14px; color:var(--gold); }
.chips { display:flex; flex-wrap:wrap; gap:6px; }
.chip { background:transparent; color:#efe6d6; border:1px solid #8a7a66; border-radius:99px; padding:4px 12px; font-size:14px; }
.chip:hover { background:#3a2d20; } .chip.f { color:#f3b6cf; border-color:#a0708a; }
.pop .two { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
.pop .two button { background:transparent; color:#d8c3a0; border:1px solid #6e4826; border-radius:10px; padding:10px 6px; font-size:14px; }
.pop .two button:disabled { opacity:.45; cursor:default; }
.pop .me-btn { background:transparent; color:#8fd18f; border:1px solid #3f8f4a; border-radius:10px; font-size:14px; }
.pop .me-btn.on { background:#2f5a35; color:#fff; }
.pop .add { background:#8a5a2e; color:#fff; border-radius:10px; font-weight:700; font-size:15px; }
.pop .fix { background:transparent; color:#c9a77a; border:1px dashed #6e4826; border-radius:10px; font-size:14px; }

.lcard { background:linear-gradient(#f7efe0, #eadcc2); color:#3a2a18; border-radius:14px; padding:18px; text-align:center; border:2px solid #b8854a; }
#dlg-body .lcard h3 { margin:2px 0; font-size:28px; color:#6e4826; }
.lcard small { color:#7a6040; }
.lcard .muted { color:#7a6040; }
.chain { list-style:none; margin:10px 0 0; padding:0; display:grid; gap:2px; }
.chain li { font-size:16px; } .chain span { color:#9a7a55; font-size:13px; margin-inline-end:6px; }
#dlg-body select { background:var(--panel); color:#fff; border:1px solid var(--wood-d); border-radius:10px; padding:10px 12px; font:inherit; }
@media print {
  body > :not(dialog) { display:none !important; }
  dialog { position:static; border:0; max-height:none; width:100%; background:#fff; color:#000; }
  .dlg-head, #dlg-body .row { display:none; }
}

.zoom { position:absolute; left:16px; bottom:16px; display:grid; gap:10px; z-index:2; }
.zoom button { width:40px; height:40px; padding:0; border-radius:50%; background:#1a1611cc; border:2px solid #ffffff44; font-size:20px; line-height:1; }
.zoom button.spin { animation:spin .5s; }
@keyframes spin { to { transform:rotate(-360deg); } }
.suggest { position:absolute; right:16px; bottom:16px; z-index:2; background:#f0c24b; color:#2a2110; font-weight:700; padding:10px 18px;
  border-radius:16px; box-shadow:0 4px 0 rgba(0,0,0,.3); }

.welcome { text-align:center; color:#cfc6b4; font-size:14px; border-top:1px solid #4a3826; padding-top:8px; }
.welcome p { margin:2px 0; }
.welcome .half.copy { display:none; }
.welcome h2 { color:var(--gold); font-size:18px; margin:6px 0 2px; }
.foot { text-align:center; padding:12px 16px 20px; }
.foot a { color:#8f8573; font-size:13px; }

dialog { width:min(560px, calc(100% - 32px)); max-height:85dvh; padding:0; border:1px solid var(--wood-d); border-radius:16px;
  background:#231b14; color:#efe6d6; font-family:inherit; }
dialog::backdrop { background:#0009; }
.dlg-head { position:sticky; top:0; display:flex; justify-content:space-between; align-items:center; padding:12px 16px; background:#231b14; border-bottom:1px solid #3a2d20; z-index:3; }
.dlg-head h2 { margin:0; font-size:18px; color:var(--gold); }
.dlg-head button { background:none; color:#cfc6b4; font-size:18px; padding:4px 8px; }
#dlg-body { padding:14px 16px 18px; display:grid; gap:10px; }
#dlg-body input, #dlg-body textarea { width:100%; background:var(--panel); color:#fff; border:1px solid var(--wood-d); border-radius:10px; font:inherit; padding:10px 12px; }
#dlg-body button, #dlg-body .btn { justify-self:start; background:#8a5a2e; color:#fff; border:0; border-radius:10px; padding:9px 16px; font-weight:600; }
#dlg-body button:hover { background:#9d6836; }
#dlg-body p { margin:0; }
#dlg-body .big { font-size:17px; font-weight:700; }
.rel { color:#f0c24b; }
.picker { position:relative; }
.chosen { color:#c9a77a; font-size:14px; }
.list { list-style:none; margin:0; padding:0; }
.list li { display:flex; gap:10px; align-items:center; padding:10px 6px; border-bottom:1px solid #3a2d20; cursor:pointer; }
.list li:hover { background:#2f251b; }
.list .muted { margin-inline-start:auto; }
.dot { width:14px; height:14px; border-radius:50%; }
.tiles { display:grid; grid-template-columns:repeat(2, 1fr); gap:8px; }
.tile { background:var(--panel); border:1px solid #5a4430; border-radius:14px; padding:14px 10px; text-align:center; display:grid; gap:4px; }
.tile b { font-size:26px; color:#c9894a; }
.sbox { border:1px solid #5a4430; border-radius:14px; padding:12px 14px; display:grid; gap:8px; }
#dlg-body .sbox h3 { margin:0 0 2px; font-size:15px; color:#c9894a; }
.sname { display:grid; gap:8px; }
.srow { display:grid; grid-template-columns:6em 1fr 2.5em; align-items:center; gap:10px; font-size:14px; }
.srow .sk { font-weight:600; }
.sbox:last-child .srow { grid-template-columns:11em 1fr 2.5em; }
.srow b { text-align:end; font-size:13px; }
.srow small { grid-column:1 / -1; color:#a8703e; font-size:12px; margin-top:-6px; }
.srow.link { cursor:pointer; padding:4px 6px; margin:0 -6px; border-radius:8px; }
.srow.link:hover { background:#2f251b; }
.track { height:10px; background:#1a1410; border-radius:99px; overflow:hidden; display:flex; }
.track span { display:block; height:100%; border-radius:99px; }
.tile span { font-size:13px; color:#cfc6b4; }
#dlg-body h3 { margin:8px 0 0; font-size:15px; color:var(--gold); }
.qr { background:#fff; border-radius:12px; padding:8px; width:min(260px, 100%); justify-self:center; }
.qr svg { display:block; width:100%; height:auto; }
.ltr { direction:ltr; text-align:center; word-break:break-all; font-size:13px; }
.news { border-bottom:1px solid #3a2d20; padding-bottom:10px; }
.news h3 { margin:0 !important; }
.news p { white-space:pre-wrap; margin-top:6px !important; }

@media (max-width:600px) {
  .top h1 { font-size:21px; }
  .top { padding:10px 12px; gap:8px; }
  .menu-btn { display:grid; place-items:center; width:42px; height:42px; font-size:24px; line-height:1; color:#c9a77a;
    background:var(--panel); border:1px solid var(--wood-d); border-radius:12px; cursor:pointer; }
  .top.open .menu-btn { background:#3a2d20; color:var(--gold); }
  .tools { display:none; position:absolute; z-index:30; top:60px; inset-inline:12px; flex-direction:column; gap:2px; padding:6px;
    background:#2a2118; border:1px solid var(--wood-d); border-radius:14px; box-shadow:0 12px 30px #0009; }
  .top.open .tools { display:flex; }
  .tools button { border:0; border-radius:10px; background:none; text-align:start; font-size:16px; padding:12px 14px; color:#e9dcc6; }
  .tools button + button { border-top:1px solid #3a2d20; border-radius:0; }
  .find input, .find > button { padding:9px 10px; }
  #pos { display:none; }
  /* شريط متحرك بسطر واحد: يدخل من اليسار ويمشي يمين عشان القارئ يشوف أول الجملة أول. */
  .welcome { overflow:hidden; padding-block:6px 0; direction:ltr; }
  .welcome .ticker-track { display:flex; width:max-content; direction:ltr; animation:ticker var(--dur, 40s) linear infinite; }
  .welcome .ticker-track:active { animation-play-state:paused; }
  .welcome .half, .welcome .half.copy { display:flex; flex-direction:row; align-items:baseline; gap:28px; padding-inline:14px; white-space:nowrap; direction:rtl; }
  .welcome .half > * { margin:0 !important; }
  .welcome h2 { order:1; } .welcome .credits { order:2; } .welcome #status, .welcome .status { order:3; }
  .welcome { font-size:12px; padding-top:6px; } .welcome h2 { font-size:15px; margin:3px 0 1px; }
    .suggest { padding:8px 12px; font-size:13px; }
  .pop { position:fixed; inset:auto 0 0 0; width:auto; max-height:62dvh; border-radius:16px 16px 0 0; }
}
@keyframes ticker { from { transform:translateX(-50%); } to { transform:translateX(0); } }
@media (max-width:600px) and (prefers-reduced-motion:reduce) {
  .welcome .ticker-track { animation:none; width:auto; display:block; }
  .welcome .half { flex-direction:column; white-space:normal; align-items:center; gap:2px; }
  .welcome .half.copy { display:none; }
}
