:root {
  /* الثيم الافتراضي: البيتكويني الناري */
  --bg: #070508;
  --bg-glow: radial-gradient(circle at 50% 0%, rgba(255, 42, 0, 0.16) 0%, rgba(247, 147, 26, 0.06) 35%, #070508 75%);
  --surface: rgba(18, 12, 16, 0.84);
  --surface-2: rgba(28, 18, 22, 0.85);
  --fg: #fff7ed;
  --mut: #a89992;
  --bd: rgba(247, 147, 26, 0.25);
  --bd-hot: rgba(255, 42, 0, 0.55);
  --ac: #f7931a;        /* برتقالي بيتكوين */
  --ac-hover: #ffaa2b;
  --fire: #ff2a00;      /* أحمر ناري */
  --gold: #ffd000;      /* ذهبي متوهج */
  --ac-soft: rgba(247, 147, 26, 0.15);
  --warn: #f59e0b;
  --bad: #ff1e42;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.65), 0 0 28px rgba(247, 147, 26, 0.08);
  --radius: 16px;
}

/* وضع نهاري دافئ متناسق عند الضغط على زر تبديل الثيم */
[data-theme="light"] {
  --bg: #fdf8f4;
  --bg-glow: radial-gradient(circle at 50% 0%, rgba(247, 147, 26, 0.14) 0%, #fdf8f4 65%);
  --surface: rgba(255, 255, 255, 0.92);
  --surface-2: #fff4eb;
  --fg: #1c120c;
  --mut: #786458;
  --bd: rgba(247, 147, 26, 0.3);
  --bd-hot: rgba(234, 88, 12, 0.6);
  --ac: #ea580c;
  --ac-hover: #c2410c;
  --fire: #dc2626;
  --gold: #d97706;
  --ac-soft: rgba(234, 88, 12, 0.12);
  --shadow: 0 8px 28px rgba(124, 45, 18, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }

body {
  background: var(--bg-glow);
  background-color: var(--bg);
  background-attachment: fixed;
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  line-height: 1.55;
  padding: 18px;
  position: relative;
  overflow-x: hidden;
  transition: background 0.25s, color 0.25s;
}

/* شبكة الخلفية الثابتة */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(247, 147, 26, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 42, 0, 0.055) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at center, black 40%, transparent 90%);
  pointer-events: none;
  z-index: 0;
}

.container {
  max-width: 1240px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

/* الشريط العلوي */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  padding: 16px 20px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.topbar::before {
  content: "";
  position: absolute;
  top: 0;
  left: 15%;
  right: 15%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), var(--fire), transparent);
  box-shadow: 0 0 12px var(--ac);
}
.brand h1 {
  font-size: 20px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(90deg, var(--fg), var(--gold), var(--ac));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand p { margin: 3px 0 0; font-size: 12.5px; color: var(--mut); }

.badge {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(247, 147, 26, 0.16);
  color: var(--gold);
  border: 1px solid rgba(247, 147, 26, 0.4);
  text-shadow: 0 0 8px rgba(247, 147, 26, 0.45);
}
.badge.warn {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warn);
  border-color: rgba(245, 158, 11, 0.4);
}
.badge.bad {
  background: rgba(255, 30, 66, 0.15);
  color: var(--bad);
  border-color: rgba(255, 30, 66, 0.45);
}

.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* بطاقات الإحصائيات */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
@media (max-width: 800px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-box {
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bd);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, transform 0.2s;
}
.stat-box:hover {
  border-color: var(--bd-hot);
  transform: translateY(-2px);
}
.stat-box .lbl { font-size: 12px; color: var(--mut); display: block; margin-bottom: 4px; }
.stat-box .val { font-size: 22px; font-weight: 800; }
.stat-box .val.ac {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(255, 42, 0, 0.45);
}

/* الشبكة والبطاقات */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  position: relative;
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(247, 147, 26, 0.14);
}
.sub { font-size: 12px; color: var(--mut); font-weight: 400; }

/* الحقول */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--mut); margin-bottom: 5px; font-weight: 600; }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  background: var(--surface-2);
  color: var(--fg);
  border: 1px solid var(--bd);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(247, 147, 26, 0.18), 0 0 14px rgba(255, 42, 0, 0.2);
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  direction: ltr;
  unicode-bidi: isolate;
  word-break: break-all;
}

/* الأزرار النارية */
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 700;
  font-family: inherit;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button.primary {
  background: linear-gradient(135deg, var(--ac), var(--fire));
  color: #fff;
  box-shadow: 0 0 18px rgba(255, 42, 0, 0.35);
}
button.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 28px rgba(255, 208, 0, 0.5), 0 0 42px rgba(255, 42, 0, 0.45);
}
button.secondary {
  background: var(--surface-2);
  color: var(--fg);
  border-color: var(--bd);
}
button.secondary:hover {
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 14px rgba(247, 147, 26, 0.2);
}
button.danger {
  background: linear-gradient(135deg, #e11d48, #991b1b);
  color: #fff;
  box-shadow: 0 0 16px rgba(225, 29, 72, 0.35);
}
button.danger:hover {
  box-shadow: 0 0 26px rgba(255, 30, 66, 0.6);
}
button.sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* شريط التقدم الناري */
.prog-wrap {
  width: 100%;
  height: 11px;
  background: var(--surface-2);
  border: 1px solid var(--bd);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0;
}
.prog-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--fire), var(--ac), var(--gold));
  box-shadow: 0 0 14px var(--fire);
  transition: width 0.25s ease;
}

/* الجداول */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  padding: 11px 12px;
  border-bottom: 1px solid rgba(247, 147, 26, 0.12);
  text-align: start;
  white-space: nowrap;
}
th {
  font-size: 12px;
  color: var(--gold);
  font-weight: 700;
  background: rgba(247, 147, 26, 0.06);
}
tbody tr:hover { background: rgba(247, 147, 26, 0.05); }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mut);
  margin-inline-end: 6px;
}
.dot.on {
  background: var(--gold);
  box-shadow: 0 0 10px var(--fire), 0 0 6px var(--gold);
}

/* لوحة القطع الـ 10 */
.chunks-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
@media (max-width: 1024px) { .chunks-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px)  { .chunks-grid { grid-template-columns: 1fr; } }

.chunk-card {
  background: var(--surface-2);
  border: 1px solid var(--bd);
  border-radius: 12px;
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.2s ease;
}
.chunk-card:hover:not(.locked) {
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(247, 147, 26, 0.22);
  transform: translateY(-2px);
}
.chunk-card.locked {
  opacity: 0.36;
  filter: grayscale(0.65);
  pointer-events: none;
  border-style: dashed;
}
.chunk-card.mine {
  border-color: var(--gold);
  background: rgba(247, 147, 26, 0.1);
  box-shadow: 0 0 20px rgba(255, 42, 0, 0.25);
}
.chunk-meta { font-size: 12px; color: var(--mut); display: flex; flex-direction: column; gap: 3px; }

/* التنبيهات */
.alert {
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}
.alert.err {
  background: rgba(255, 30, 66, 0.14);
  color: #ff6b81;
  border: 1px solid rgba(255, 30, 66, 0.4);
}
.alert.ok {
  background: rgba(247, 147, 26, 0.14);
  color: var(--gold);
  border: 1px solid rgba(247, 147, 26, 0.45);
}
.hidden { display: none !important; }