:root {
  --bg: #08122a;
  --bg-2: #0e1d40;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-solid: #12234a;
  --border: rgba(214, 173, 72, 0.22);
  --border-soft: rgba(255, 255, 255, 0.08);
  --gold: #d6ad48;
  --gold-2: #f6dc8c;
  --gold-3: #9c7420;
  --text: #eef1f8;
  --muted: #93a0bf;
  --line: rgba(214, 173, 72, 0.45);
  --danger: #e5484d;
  --ok: #30a46c;
  --radius: 12px;
  --font: 'Cairo', system-ui, sans-serif;
  --display: 'Reem Kufi', 'Cairo', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(214, 173, 72, 0.16), transparent 60%),
    radial-gradient(ellipse 60% 60% at 0% 100%, rgba(47, 128, 237, 0.12), transparent 60%),
    radial-gradient(ellipse 60% 60% at 100% 100%, rgba(47, 128, 237, 0.10), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 70%);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.6;
}
body::before { /* نقش رموز الورق */
  content: '';
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='%23fff' font-family='serif' font-size='22'%3E%3Ctext x='10' y='30'%3E%E2%99%A0%3C/text%3E%3Ctext x='70' y='30'%3E%E2%99%A5%3C/text%3E%3Ctext x='40' y='80'%3E%E2%99%A6%3C/text%3E%3Ctext x='95' y='95'%3E%E2%99%A3%3C/text%3E%3C/g%3E%3C/svg%3E");
}
body > * { position: relative; z-index: 1; }

a { color: var(--gold-2); }
img { max-width: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* ---------- الترويسة ---------- */
.site-header { text-align: center; padding: 28px 16px 8px; }
.brand-row { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.brand-logo { width: 64px; height: 64px; border-radius: 14px; object-fit: cover; border: 1px solid var(--border); }
.site-title {
  font-family: var(--display); font-weight: 700; margin: 0;
  font-size: clamp(2rem, 5vw, 3.2rem); line-height: 1.2;
  background: linear-gradient(180deg, #fff 30%, var(--gold-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.site-sub { font-family: var(--display); color: var(--gold); font-size: clamp(1.1rem, 2.6vw, 1.5rem); margin: 4px 0 0; }
.t-pill {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 12px;
  padding: 4px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: rgba(214, 173, 72, 0.08); color: var(--gold-2); font-size: 0.95rem;
}
.t-pill.archived { border-color: var(--border-soft); color: var(--muted); background: var(--panel); }

.topnav { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.topnav a, .topnav button {
  font: inherit; color: var(--muted); background: transparent; border: 1px solid transparent;
  padding: 6px 14px; border-radius: 999px; text-decoration: none; cursor: pointer;
}
.topnav a:hover, .topnav button:hover { color: var(--text); border-color: var(--border-soft); }
.topnav .active { color: var(--gold-2); border-color: var(--border); background: rgba(214, 173, 72, 0.08); }

/* ---------- جدول الإقصاء ---------- */
.bracket-scroll { overflow-x: auto; padding: 8px 0 24px; -webkit-overflow-scrolling: touch; }
.bracket {
  direction: ltr; display: flex; align-items: stretch; justify-content: center;
  min-width: max-content; margin: 0 auto; padding: 0 16px;
}
.side { display: flex; }
.col { display: flex; flex-direction: column; width: 196px; }
.col-head {
  height: 44px; display: flex; align-items: center; justify-content: center;
  font-family: var(--display); color: var(--gold); font-size: 1rem; direction: rtl;
}
.col-body { flex: 1; display: flex; flex-direction: column; }
.pair { flex: 1; display: flex; flex-direction: column; position: relative; }
.mw { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; padding: 6px 14px; min-height: 92px; }

/* خطوط الربط — الجهة اليسرى تتجه لليمين */
.side.left .mw::after, .side.right .mw::after { content: ''; position: absolute; top: 50%; width: 14px; border-top: 2px solid var(--line); }
.side.left .mw::after { right: 0; }
.side.right .mw::after { left: 0; }
.side .col:not(.outer) .mw::before { content: ''; position: absolute; top: 50%; width: 14px; border-top: 2px solid var(--line); }
.side.left .col:not(.outer) .mw::before { left: 0; }
.side.right .col:not(.outer) .mw::before { right: 0; }
.side.left .pair::after, .side.right .pair::after { content: ''; position: absolute; top: 25%; bottom: 25%; }
.side.left .pair::after { right: 0; border-right: 2px solid var(--line); }
.side.right .pair::after { left: 0; border-left: 2px solid var(--line); }

.center { display: flex; flex-direction: column; width: 300px; }
.center .col-body { display: grid; grid-template-rows: 1fr auto 1fr; }
.center .top { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 14px; }
.center .bottom { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 16px; direction: rtl; text-align: center; }
.final-wrap { position: relative; display: flex; justify-content: center; padding: 0 20px; }
.final-wrap.linked::before, .final-wrap.linked::after { content: ''; position: absolute; top: 50%; width: 20px; border-top: 2px solid var(--line); }
.final-wrap.linked::before { left: 0; }
.final-wrap.linked::after { right: 0; }
.final-title { font-family: var(--display); font-size: 2rem; color: var(--gold-2); margin: 0; line-height: 1.2; }
.trophy { width: 120px; height: auto; filter: drop-shadow(0 10px 30px rgba(214, 173, 72, 0.35)); }

/* بطاقة المباراة */
.match {
  width: 100%; border-radius: 10px; overflow: hidden; direction: rtl;
  background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.03));
  border: 1px solid var(--border-soft);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.match.final { border-color: var(--border); box-shadow: 0 0 0 1px rgba(214,173,72,.15), 0 10px 40px rgba(214, 173, 72, 0.18); }
.match.final .team-row { height: 46px; font-size: 1.05rem; }
.match.clickable { cursor: pointer; }
.match.clickable:hover, .match.clickable:focus-visible { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(214,173,72,.18); transform: translateY(-1px); outline: none; }
.match.ready.clickable { border-color: rgba(214, 173, 72, 0.5); }
.team-row {
  display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px;
  font-size: 0.92rem; font-weight: 600;
}
.team-row + .team-row { border-top: 1px solid var(--border-soft); }
.team-row .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team-row .sc { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 1.5em; text-align: center; color: var(--muted); }
.team-row.win { background: linear-gradient(90deg, transparent, rgba(214, 173, 72, 0.18)); }
.team-row.win .nm, .team-row.win .sc { color: var(--gold-2); }
.team-row.lose { opacity: 0.42; }
.team-row.tbd .nm { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.team-row[data-team] { cursor: pointer; }

.av {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 0.8rem; font-weight: 800; color: #0b1430; overflow: hidden;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.12);
}
.av img { width: 100%; height: 100%; object-fit: cover; }
.av.tbd { background: rgba(255, 255, 255, 0.08); box-shadow: inset 0 0 0 1px var(--border-soft); }
.av.lg { width: 84px; height: 84px; font-size: 2rem; box-shadow: 0 0 0 3px var(--gold), 0 0 40px rgba(214,173,72,.4); }
.av.md { width: 44px; height: 44px; font-size: 1.2rem; }

.champion { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.champion .label { font-family: var(--display); color: var(--gold); font-size: 1.1rem; }
.champion .nm { font-family: var(--display); font-size: 1.6rem; color: #fff; }
.vs-hint { color: var(--muted); font-size: 0.9rem; }

/* عرض الجوال: قائمة حسب الأدوار */
.rounds-list { display: none; padding: 0 16px; max-width: 900px; margin: 0 auto; }
@media (max-width: 760px) {
  .bracket-scroll.auto { display: none; }
  .rounds-list.auto { display: block; }
}
.rounds-list .round { margin: 18px 0; }
.rounds-list h3 { font-family: var(--display); color: var(--gold); margin: 0 0 8px; font-size: 1.15rem; }
.rounds-list .grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.mobile-hero { text-align: center; margin: 8px 0 4px; }
.mobile-hero .trophy { width: 90px; }

/* ---------- الفرق ---------- */
.section-title { font-family: var(--display); font-size: 1.5rem; color: var(--gold-2); margin: 36px 0 14px; text-align: center; }
.teams-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.team-card {
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.team-card.out { opacity: 0.55; }
.team-card.champ { border-color: var(--gold); box-shadow: 0 0 30px rgba(214,173,72,.15); }
.team-card .hd { display: flex; align-items: center; gap: 10px; }
.team-card .hd .nm { font-family: var(--display); font-size: 1.15rem; flex: 1; }
.team-card ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.team-card li { background: rgba(255,255,255,0.06); padding: 2px 10px; border-radius: 999px; font-size: 0.88rem; }
.badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border-soft); color: var(--muted); white-space: nowrap; }
.badge.gold { border-color: var(--gold); color: var(--gold-2); }

/* الأرشيف */
.archive-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.archive-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--border-soft); color: inherit; text-decoration: none;
}
.archive-item:hover { border-color: var(--border); }
.archive-item .meta { flex: 1; min-width: 0; }
.archive-item .meta b { display: block; }

.empty {
  text-align: center; padding: 60px 16px; color: var(--muted);
  border: 1px dashed var(--border-soft); border-radius: var(--radius); margin: 30px auto; max-width: 560px;
}
.empty .big { font-size: 3rem; display: block; margin-bottom: 6px; }

footer.site-foot { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 40px 16px 24px; }

/* ---------- عناصر النماذج ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: 16px; padding: 20px;
  backdrop-filter: blur(6px);
}
.panel + .panel { margin-top: 18px; }
.panel h2 { font-family: var(--display); margin: 0 0 4px; font-size: 1.35rem; color: var(--gold-2); }
.panel .desc { color: var(--muted); margin: 0 0 16px; font-size: 0.95rem; }
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; font: inherit; color: var(--text); background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-soft); border-radius: 10px; padding: 10px 12px;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(214,173,72,.18); }
textarea { min-height: 220px; resize: vertical; line-height: 1.8; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }

.btn {
  font: inherit; font-weight: 700; cursor: pointer; border-radius: 10px; padding: 10px 18px;
  border: 1px solid var(--border-soft); background: rgba(255,255,255,0.06); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: rgba(255,255,255,0.1); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #1a1406; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: #ffb4b6; border-color: rgba(229, 72, 77, 0.4); background: rgba(229, 72, 77, 0.08); }
.btn.danger:hover { background: rgba(229, 72, 77, 0.16); }
.btn.sm { padding: 6px 12px; font-size: 0.88rem; }
.btn.block { width: 100%; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 8px; }

.seg { display: inline-flex; border: 1px solid var(--border-soft); border-radius: 10px; overflow: hidden; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 16px; color: var(--muted); }
.seg input:checked + span { background: rgba(214,173,72,.15); color: var(--gold-2); }
.seg input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: -2px; }

.note { padding: 10px 14px; border-radius: 10px; font-size: 0.93rem; background: rgba(47,128,237,.1); border: 1px solid rgba(47,128,237,.3); }
.note.warn { background: rgba(242,153,74,.1); border-color: rgba(242,153,74,.35); }
.note.ok { background: rgba(48,164,108,.1); border-color: rgba(48,164,108,.35); }

/* صفحة الدخول */
.auth-box { max-width: 400px; margin: 40px auto; }

/* شريط الأدمن */
.admin-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft); background: rgba(8, 18, 42, 0.7); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.admin-bar .brand { font-family: var(--display); color: var(--gold-2); font-size: 1.2rem; text-decoration: none; }
.admin-bar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.admin-bar nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 8px; }
.admin-bar nav a.active, .admin-bar nav a:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.admin-bar .who { color: var(--muted); font-size: 0.9rem; }
.admin-main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 60px; }
.narrow { max-width: 760px; margin: 0 auto; }

.steps { display: flex; gap: 8px; justify-content: center; margin: 0 0 22px; flex-wrap: wrap; }
.steps .st { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.92rem; }
.steps .st b { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--border-soft); font-size: 0.85rem; }
.steps .st.on { color: var(--gold-2); }
.steps .st.on b { background: var(--gold); color: #1a1406; border-color: var(--gold); }
.steps .st.done b { background: rgba(48,164,108,.25); border-color: var(--ok); color: #bff0d4; }
.steps .sep { width: 28px; height: 1px; background: var(--border-soft); align-self: center; }

.count-chip { font-variant-numeric: tabular-nums; color: var(--gold-2); font-weight: 700; }

/* الحوار */
.modal-bg {
  position: fixed; inset: 0; background: rgba(3, 8, 20, 0.7); backdrop-filter: blur(4px);
  display: grid; place-items: center; z-index: 100; padding: 16px;
}
.modal {
  width: 100%; max-width: 460px; background: var(--panel-solid); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.5); max-height: 90vh; overflow: auto;
}
.modal h3 { font-family: var(--display); margin: 0 0 12px; color: var(--gold-2); font-size: 1.3rem; }
.pick { display: grid; gap: 10px; margin-bottom: 14px; }
.pick-opt {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border-soft); background: rgba(255,255,255,0.04); font: inherit; color: inherit; text-align: right;
}
.pick-opt:hover { border-color: var(--border); }
.pick-opt.sel { border-color: var(--gold); background: rgba(214,173,72,.12); }
.pick-opt .nm { flex: 1; font-weight: 700; }
.pick-opt input[type=number] { width: 80px; text-align: center; }
.pick-opt .crown { opacity: 0; color: var(--gold-2); }
.pick-opt.sel .crown { opacity: 1; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: var(--panel-solid); border: 1px solid var(--border); padding: 10px 18px; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: calc(100% - 32px);
}
.toast.err { border-color: rgba(229, 72, 77, 0.6); }

/* إعدادات الفرق */
.team-edit { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border-soft); flex-wrap: wrap; }
.team-edit:last-child { border-bottom: 0; }
.team-edit input[type=text] { flex: 1; min-width: 160px; }
.team-edit .players { width: 100%; color: var(--muted); font-size: 0.85rem; }
.logo-preview { width: 72px; height: 72px; border-radius: 14px; object-fit: cover; border: 1px solid var(--border); background: rgba(0,0,0,.2); }
.admin-list { list-style: none; margin: 0 0 16px; padding: 0; }
.admin-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border-soft); }
.admin-list li span { flex: 1; }

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

/* قائمة اللاعبين المحفوظة */
.roster-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.roster-tools input { flex: 1; min-width: 180px; }
.roster { display: flex; flex-wrap: wrap; gap: 8px; min-height: 48px; padding: 12px; border-radius: 12px; background: rgba(0,0,0,.18); border: 1px solid var(--border-soft); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 4px; border-radius: 999px;
  border: 1px solid var(--border); background: rgba(214,173,72,.1); font-size: 0.95rem;
}
.chip label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; padding-inline-start: 6px; }
.chip input { accent-color: var(--gold); width: 16px; height: 16px; margin: 0; }
.chip.off { border-color: var(--border-soft); background: rgba(255,255,255,.03); color: var(--muted); }
.chip.off .cn { text-decoration: line-through; }
.chip .x {
  border: 0; background: rgba(255,255,255,.08); color: var(--muted); width: 22px; height: 22px; border-radius: 50%;
  cursor: pointer; display: grid; place-items: center; font-size: 0.85rem; line-height: 1; padding: 0;
}
.chip .x:hover { background: rgba(229,72,77,.3); color: #fff; }
.roster-summary { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 10px 0 14px; color: var(--muted); font-size: 0.92rem; }
.linkbtn { background: none; border: 0; color: var(--gold-2); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
details.bulk summary { cursor: pointer; color: var(--muted); margin: 10px 0; }
details.bulk textarea { min-height: 120px; }
