:root {
  --bg: #04060d;
  --panel: rgba(12, 18, 34, 0.62);
  --border: rgba(120, 180, 255, 0.14);
  --text: #e8f0ff;
  --muted: #8aa0c4;
  --live: #22e6a6;
  --silent: #ffb020;
  --loop: #ff5da2;
  --down: #ff4d5e;
  --font: "Segoe UI", "Tahoma", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

#viz {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

/* ───────── الشريط العلوي ───────── */

.top {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 26px;
  background: linear-gradient(180deg, rgba(4, 6, 13, 0.85), transparent);
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.brand h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.url {
  margin: 3px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  direction: ltr;
  text-align: right;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 14px currentColor;
  flex: none;
  transition: background 0.4s, box-shadow 0.4s;
}

.dot.live   { background: var(--live);   box-shadow: 0 0 18px var(--live); animation: pulse 2s infinite; }
.dot.silent { background: var(--silent); box-shadow: 0 0 18px var(--silent); }
.dot.loop   { background: var(--loop);   box-shadow: 0 0 18px var(--loop); }
.dot.down   { background: var(--down);   box-shadow: 0 0 18px var(--down); animation: pulse 1s infinite; }

@keyframes pulse { 50% { opacity: 0.35; } }

.top-actions { display: flex; gap: 10px; flex: none; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 9px 15px;
  border-radius: 11px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  backdrop-filter: blur(14px);
  transition: border-color 0.2s, transform 0.15s, background 0.2s;
}

.btn:hover { border-color: rgba(120, 180, 255, 0.45); transform: translateY(-1px); }
.btn.on { border-color: var(--live); color: var(--live); }

/* ───────── القراءة المركزية ───────── */

.center-readout {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
}

.status-pill {
  padding: 7px 20px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(6, 10, 20, 0.5);
  font-size: 13px;
  letter-spacing: 0.4px;
  backdrop-filter: blur(8px);
  margin-bottom: 14px;
}

.db {
  font-size: 58px;
  font-weight: 200;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 40px rgba(80, 200, 255, 0.35);
}

.db-label { margin-top: 8px; font-size: 12px; color: var(--muted); letter-spacing: 1px; }

/* ───────── الإحصائيات ───────── */

.stats {
  position: fixed;
  bottom: 22px;
  right: 26px;
  left: 26px;
  z-index: 3;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 120px;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--panel);
  backdrop-filter: blur(16px);
}

.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-size: 16px; font-variant-numeric: tabular-nums; }

/* ───────── درج سجل الأحداث (منزلق — لا يغطي الموجة) ───────── */

.btn-label { margin: 0 2px; }

#eventsToggle { display: inline-flex; align-items: center; gap: 7px; }
#eventsToggle.has-new { border-color: var(--live); color: var(--live); }

.badge {
  font-size: 11px;
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(120, 180, 255, 0.16);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#eventsToggle.has-new .badge { background: rgba(34, 230, 166, 0.2); color: var(--live); }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 8;
  background: rgba(4, 6, 13, 0.5);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  width: min(360px, 88vw);
  display: flex;
  flex-direction: column;
  background: rgba(8, 13, 26, 0.92);
  border-inline-start: 1px solid var(--border);
  backdrop-filter: blur(24px);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.5);
  transform: translateX(105%);
  transition: transform 0.36s cubic-bezier(0.22, 1, 0.36, 1);
}

.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.drawer-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

.icon-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 9px;
  font-size: 14px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.icon-btn:hover { color: var(--text); border-color: rgba(120, 180, 255, 0.45); }

.drawer ul { margin: 0; padding: 10px; list-style: none; overflow-y: auto; flex: 1; }

.drawer li {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 11px 12px;
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.55;
  border: 1px solid transparent;
  animation: slide-in 0.3s ease;
}

@keyframes slide-in { from { opacity: 0; transform: translateX(14px); } }

.drawer li + li { margin-top: 3px; }
.drawer li:hover { background: rgba(255, 255, 255, 0.04); border-color: var(--border); }
.drawer li .ico { font-size: 16px; flex: none; }
.drawer li .txt { flex: 1; min-width: 0; }
.drawer li .time { color: var(--muted); font-size: 11px; }
.drawer li .meta { color: var(--muted); font-size: 11px; margin-top: 3px; }
.drawer .empty { color: var(--muted); text-align: center; padding: 30px 18px; font-size: 12.5px; }

.drawer-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}

.drawer-foot a { color: var(--muted); text-decoration: none; }
.drawer-foot a:hover { color: var(--live); }

.drawer ul::-webkit-scrollbar { width: 6px; }
.drawer ul::-webkit-scrollbar-thumb { background: rgba(120, 180, 255, 0.25); border-radius: 3px; }

/* ───────── إشعار عابر عند وقوع حدث ───────── */

.toast-stack {
  position: fixed;
  top: 84px;
  right: 26px;
  z-index: 7;
  display: flex;
  flex-direction: column;
  gap: 9px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--live);
  background: rgba(10, 16, 30, 0.9);
  backdrop-filter: blur(20px);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  font-size: 13px;
  cursor: pointer;
  pointer-events: auto;
  max-width: 330px;
  animation: toast-in 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.toast.out { animation: toast-out 0.35s ease forwards; }
.toast .ico { font-size: 19px; flex: none; }
.toast .t-title { font-weight: 600; }
.toast .t-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

@keyframes toast-in  { from { opacity: 0; transform: translateX(26px) scale(0.96); } }
@keyframes toast-out { to   { opacity: 0; transform: translateX(26px) scale(0.96); } }

@media (max-width: 820px) {
  .db { font-size: 42px; }
  .btn-label { display: none; }
  .toast-stack { top: 76px; right: 12px; left: 12px; }
  .toast { max-width: none; }
  .url { max-width: 40vw; }
  .stats { gap: 8px; }
  .stat { min-width: 96px; padding: 9px 12px; }
  body { overflow-y: auto; }
}

/* ───────── طبقة تفعيل الصوت (عند منع التشغيل التلقائي) ───────── */

.unlock {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 13, 0.55);
  backdrop-filter: blur(3px);
  cursor: pointer;
  animation: fade-in 0.35s ease;
}

.unlock.show { display: flex; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.unlock-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 30px 40px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(10, 16, 30, 0.75);
  text-align: center;
}

.unlock-play {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 28px;
  color: #04121a;
  background: linear-gradient(135deg, var(--live), #12b0e0);
  box-shadow: 0 0 44px rgba(34, 230, 166, 0.45);
  animation: breathe 2.2s ease-in-out infinite;
}

@keyframes breathe {
  50% { transform: scale(1.07); box-shadow: 0 0 62px rgba(34, 230, 166, 0.65); }
}

.unlock-title { margin: 6px 0 0; font-size: 15px; }
.unlock-sub { margin: 0; font-size: 11.5px; color: var(--muted); }
