:root {
  --bg: #f6f1e7;
  --surface: #fffcf6;
  --surface-2: #f0e9db;
  --ink: #2b231a;
  --muted: #76685a;
  --line: #e2d8c6;
  --accent: #1f4d3a;
  --accent-ink: #ffffff;
  --gold: #b08a3e;
  --sire-bg: #eaf0f6;
  --sire-line: #6f8db0;
  --dam-bg: #f7ebee;
  --dam-line: #b77587;
  --ext-bg: transparent;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 4px 16px rgba(60, 40, 10, .06);
  --radius: 12px;
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Amiri", Georgia, serif;
}
:root { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #15120e;
    --surface: #1e1a15;
    --surface-2: #29241d;
    --ink: #efe6d6;
    --muted: #a8998a;
    --line: #3a3229;
    --accent: #5fa883;
    --accent-ink: #0f1a14;
    --gold: #d9b866;
    --sire-bg: #1c2633;
    --sire-line: #6f94bf;
    --dam-bg: #2f1f25;
    --dam-line: #c48597;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15120e;
  --surface: #1e1a15;
  --surface-2: #29241d;
  --ink: #efe6d6;
  --muted: #a8998a;
  --line: #3a3229;
  --accent: #5fa883;
  --accent-ink: #0f1a14;
  --gold: #d9b866;
  --sire-bg: #1c2633;
  --sire-line: #6f94bf;
  --dam-bg: #2f1f25;
  --dam-line: #c48597;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.25; margin: 0; }
.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px; }
main { flex: 1; padding-top: 24px; padding-bottom: 48px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
[dir="rtl"] .ltr { direction: ltr; unicode-bidi: isolate; }

/* Header */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-inner { display: flex; align-items: center; gap: 20px; min-height: 64px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand:hover { color: inherit; }
.mark { width: 46px; height: 46px; flex: none; display: block; border-radius: 50%; filter: drop-shadow(0 1px 2px rgba(0,0,0,.18)); }
.brand-text { display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.brand-name { font: 700 21px/1.15 var(--display); color: var(--gold); }
.brand-en { margin-top: 4px; font: 600 11px/1.3 "IBM Plex Sans Arabic", system-ui, sans-serif; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); white-space: nowrap; }
.brand-text { justify-content: center; }
.foot .by { margin: 14px 0 0; text-align: center; font-size: 11px; opacity: .55; letter-spacing: .04em; }
.foot .by a { text-decoration: none; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; align-items: center; gap: 6px; }
.nav a { padding: 6px 12px; border-radius: 999px; font-size: 14px; color: var(--muted); }
.nav a:hover, .nav a.active { color: var(--ink); background: var(--surface-2); }
.nav .lang { border: 1px solid var(--line); color: var(--ink); }
.theme-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: transparent;
  color: var(--ink); cursor: pointer; display: grid; place-items: center; padding: 0; flex: none;
}
.theme-btn:hover { background: var(--surface-2); }
.theme-btn svg { width: 17px; height: 17px; }
.theme-btn .sun { display: none; }
:root[data-theme="dark"] .theme-btn .sun { display: block; }
:root[data-theme="dark"] .theme-btn .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .sun { display: block; }
  :root:not([data-theme="light"]) .theme-btn .moon { display: none; }
}
.top-search { flex: 1; min-width: 220px; max-width: 420px; margin-inline-start: auto; }
.top-search:empty { display: none; }

/* Search box + suggestions */
.search { position: relative; }
.search input {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 9px 16px; outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.search.big input { font-size: 18px; padding: 16px 22px; background: var(--surface); box-shadow: var(--shadow); }
.suggest {
  position: absolute; inset-inline: 0; top: calc(100% + 6px); z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; list-style: none; margin: 0; padding: 4px;
}
.suggest:empty { display: none; }
.suggest li a { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-radius: 8px; }
.suggest li a.on, .suggest li a:hover { background: var(--surface-2); color: inherit; }
.suggest .s-name { font-weight: 600; }
.suggest .s-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggest .s-all { justify-content: center; color: var(--accent); font-size: 14px; }

/* Loading */
.loading { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 120px 0; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Home */
.hero { text-align: center; padding: 48px 0 32px; }
.hero h1 { font-size: clamp(32px, 5vw, 48px); }
.hero p { color: var(--muted); margin: 8px 0 28px; font-size: 16px; }
.hero .search { max-width: 640px; margin: 0 auto; text-align: start; }
.hero .examples { margin-top: 14px; font-size: 14px; color: var(--muted); }
.hero .examples a { color: var(--accent); margin-inline: 6px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 8px 0 40px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font: 700 26px/1.2 var(--display); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 36px 0 14px; flex-wrap: wrap; }
.section-head h2 { font-size: 26px; }
.section-head a { color: var(--accent); font-size: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card {
  display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); color: inherit; transform: translateY(-1px); }
.card .c-name { font-weight: 600; font-size: 16px; }
.card .c-alt { font-size: 12px; color: var(--muted); }
.card .c-row { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px; color: var(--muted); }
.card .c-row b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* Horse page */
.horse-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin: 8px 0 20px; }
.horse-head h1 { font-size: clamp(30px, 4.5vw, 44px); }
.horse-head .alt { color: var(--muted); font-size: 17px; margin-top: 2px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink); }
.chip.m { background: var(--sire-bg); }
.chip.f { background: var(--dam-bg); }
.chip.warn { background: transparent; border: 1px dashed var(--muted); color: var(--muted); }
.parents { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.parent { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; border-inline-start: 4px solid var(--line); }
.parent.m { border-inline-start-color: var(--sire-line); }
.parent.f { border-inline-start-color: var(--dam-line); }
.parent .lbl { font-size: 12px; color: var(--muted); }
.parent .val { font-weight: 600; font-size: 16px; display: block; }
.parent .sub { font-size: 12px; color: var(--muted); }
@media (max-width: 760px) { .parent { padding: 8px 14px; } .parent .sub:empty, .parent .sub { display: inline; margin-inline-start: 8px; } .parent .val { display: inline; } }
.info { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.info div { padding: 10px 16px; background: var(--surface); }
.info dt { font-size: 12px; color: var(--muted); }
.info dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.note { background: var(--surface); border: 1px dashed var(--muted); border-radius: var(--radius); padding: 14px 16px; color: var(--muted); }
.ext-info:not(:empty) { margin-top: 14px; }
.src { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.src a { text-decoration: underline; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button, .seg a {
  font: inherit; font-size: 13px; border: 0; background: transparent; color: var(--muted);
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
}
.seg button.on, .seg a.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

/* Pedigree tree */
.tree-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.seg button:disabled { opacity: .35; cursor: default; }
.seg .fs { font-weight: 600; min-width: 34px; }
.save-btn {
  font: inherit; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 6px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
}
.save-btn:hover { filter: brightness(1.08); }
.save-btn:disabled { opacity: .6; cursor: progress; }
.save-btn svg { width: 15px; height: 15px; }
.tree-scroll { overflow-x: auto; margin: 0 -4px; padding: 4px; }
.tree { display: grid; gap: 4px 8px; }
.node {
  display: flex; flex-direction: column; justify-content: center;
  padding: 4px 10px; border-radius: 8px; min-height: 30px; min-width: 0;
  border-inline-start: 3px solid; position: relative;
}
.node.m { background: var(--sire-bg); border-color: var(--sire-line); }
.node.f { background: var(--dam-bg); border-color: var(--dam-line); }
.node.unknown { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.node.unknown .nm { font-weight: 400; font-size: calc(12px * var(--ts, 1)); }
.node.blank { border: 0; background: transparent; }
.node.ext { background-image: repeating-linear-gradient(-45deg, transparent 0 6px, rgba(128, 128, 128, .07) 6px 12px); }
.node a, .node .nm { font-weight: 600; font-size: calc(14px * var(--ts, 1)); line-height: 1.3; overflow-wrap: anywhere; }
.node .yr { font-size: calc(11px * var(--ts, 1)); color: var(--muted); }
.tree.g5 .node a, .tree.g5 .node .nm { font-size: calc(12.5px * var(--ts, 1)); }
.tree.g5 .gen5 .yr { display: none; }
.node .dup {
  position: absolute; inset-inline-end: 6px; top: 50%; transform: translateY(-50%);
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  font-size: 11px; font-weight: 600; display: grid; place-items: center; color: #fff;
}
.tree-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 12px; }
.tree-legend i.ext-sw { border: 1px dashed var(--muted); background-image: repeating-linear-gradient(-45deg, transparent 0 3px, rgba(128, 128, 128, .25) 3px 6px); }
.tree-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-inline-end: 5px; }
.dups { margin-top: 12px; font-size: 13px; }
.dups a { margin-inline-end: 4px; }

/* Progeny */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface-2); border-radius: 10px; padding: 10px 14px; }
.tile b { display: block; font: 700 26px/1.2 var(--display); font-variant-numeric: tabular-nums; }
.tile span { font-size: 12px; color: var(--muted); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar select { font: inherit; font-size: 13px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
.tbl-scroll { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
.list th { text-align: start; font-weight: 500; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list tr:last-child td { border-bottom: 0; }
.list td.n { font-variant-numeric: tabular-nums; white-space: nowrap; }
.list .nm { font-weight: 600; }
.list .alt { display: block; font-size: 12px; color: var(--muted); }
.sx { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 6px; vertical-align: 1px; }
.sx.m { background: var(--sire-line); }
.sx.f { background: var(--dam-line); }
.more { display: block; margin: 14px auto 0; font: inherit; font-size: 14px; color: var(--accent); background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 8px 20px; cursor: pointer; }
.more:hover { border-color: var(--accent); }
.more[hidden] { display: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* Footer */
.foot { border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 13px; padding: 20px 0; }
.foot a { text-decoration: underline; }
.contact { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.contact-lbl { font: 700 18px/1.2 var(--display); color: var(--ink); }
.socials { display: flex; gap: 8px; flex-wrap: wrap; }
.foot a.soc {
  display: inline-flex; align-items: center; gap: 7px; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px 6px 12px; font-size: 13px; font-weight: 500;
  transition: border-color .15s, color .15s, background .15s;
}
.soc svg { width: 18px; height: 18px; flex: none; }
.foot a.soc:hover { background: var(--surface-2); }
.foot a.soc.wa:hover { color: #1da851; border-color: #1da851; }
.foot a.soc.ig:hover { color: #d62976; border-color: #d62976; }
.foot a.soc.sc:hover { color: #c9a400; border-color: #e6c200; }
.foot a.soc.em:hover { color: var(--gold); border-color: var(--gold); }
.wa-float {
  position: fixed; inset-inline-end: 18px; bottom: 18px; z-index: 40;
  width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center;
  background: #25d366; color: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
.wa-float:hover { color: #fff; transform: scale(1.07); }
.wa-float svg { width: 30px; height: 30px; }
.foot { padding-bottom: 84px; }
@media (max-width: 760px) {
  .soc span { display: none; }
  .foot a.soc { padding: 9px; }
  .soc svg { width: 20px; height: 20px; }
  .wa-float { width: 50px; height: 50px; inset-inline-end: 14px; bottom: 14px; }
}
@media print { .wa-float { display: none; } }

@media (max-width: 760px) {
  .parents { grid-template-columns: 1fr; }
  .two { grid-template-columns: 1fr; }
  .top { position: static; }
  .top-inner { gap: 8px 10px; }
  .nav { margin-inline-start: auto; gap: 2px; }
  .nav a { padding: 5px 9px; font-size: 13px; }
  .mark { width: 40px; height: 40px; }
  .brand-name { font-size: 18px; }
  .top-search { order: 3; max-width: none; flex-basis: 100%; }
  .brand-sub { display: none; }
  .hero { padding-top: 24px; }
  .list .hide-sm { display: none; }
  .info { grid-template-columns: 1fr 1fr; }
}

/* Cross search */
.cross-form { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 12px 14px; align-items: end; }
.cross-side { border-inline-start: 4px solid var(--line); padding-inline-start: 12px; min-width: 0; }
.cross-side.m { border-inline-start-color: var(--sire-line); }
.cross-side.f { border-inline-start-color: var(--dam-line); }
.cross-side .lbl { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.picked { display: flex; align-items: center; gap: 8px; min-height: 42px; flex-wrap: wrap; }
.picked .nm { font-weight: 600; font-size: 17px; }
.pick-change, .swap {
  font: inherit; font-size: 13px; color: var(--muted); background: transparent; cursor: pointer;
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px;
}
.pick-change:hover, .swap:hover:not(:disabled) { color: var(--ink); border-color: var(--accent); }
.swap { width: 40px; height: 40px; padding: 0; font-size: 18px; margin-bottom: 1px; }
.swap:disabled { opacity: .4; cursor: default; }
.cross-gens { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; margin-top: 10px; }
.cross-gens .seg { flex-wrap: wrap; border-radius: 16px; }
.cross-form { align-items: start; }
.swap { align-self: center; }
.list td.where { white-space: nowrap; font-size: 13px; }
.where .up { color: var(--sire-line); font-weight: 600; }
.where .down { color: var(--dam-line); font-weight: 600; margin-inline-start: 6px; }
.chip.link { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.chip.link:hover { color: var(--accent); border-color: var(--accent); }
@media (max-width: 760px) {
  .cross-form { grid-template-columns: 1fr; }
  .swap { justify-self: center; transform: none; }
}
.cross-side.third { grid-column: 1 / -1; border-inline-start-style: dashed; }
.chip.link.same { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }

/* Pedigree maker */
.make-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.cross-side.foal { grid-column: 1 / -1; border-inline-start-color: var(--gold); }
.make-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; }
.fld { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
.fld input, .fld select {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; outline: none; width: 100%;
}
.fld input:focus, .fld select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
@media (max-width: 760px) {
  .make-form { grid-template-columns: 1fr; }
  .make-fields { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .nav a { white-space: nowrap; padding: 5px 7px; }
}

/* Dam sire page */
.ds-h { font-size: 16px; margin: 14px 0 8px; }
.ds-top { display: flex; flex-wrap: wrap; gap: 6px; }
.ds-top .chip { display: inline-flex; align-items: center; gap: 6px; }
.ds-top .chip b { color: var(--ink); }
@media (max-width: 760px) {
  /* five links no longer fit beside the brand: the menu gets a row of its own and may wrap */
  .top-inner { flex-wrap: wrap; }
  .nav { flex-basis: 100%; order: 2; flex-wrap: wrap; justify-content: center; margin-inline-start: 0; row-gap: 4px; }
}
