:root {
  --bg: #f8fafc;
  --fg: #0f172a;
  --muted: #475569;
  --border: #cbd5e1;
  --noun: #16a34a;
  --verb: #2563eb;
  --particle: #7c3aed;

  /* language colors */
  --en: #3b82f6;      /* blue for English */
  --ar-dark: #ffffff; /* Arabic on dark tooltip */
}

/* Keep box-sizing global */
* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 system-ui, "Segoe UI", Roboto, Arial, "Noto Naskh Arabic", "Amiri", sans-serif;
}

/* Page header + legend */
header {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}
h1 { font-size: 18px; margin: 0; }

.legend {
  display: flex;
  gap: 16px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}
.legend .dot { display:inline-block; width:10px; height:10px; border-radius:50%; margin-inline-end:6px; vertical-align:middle; }
.legend .noun { background:var(--noun); }
.legend .verb { background:var(--verb); }
.legend .particle { background:var(--particle); }

/* Diagram viewport container (if you add one) */
#diagram-container {
  position: relative;
  height: calc(100vh - 58px);
  overflow: auto;
  background: conic-gradient(from 90deg at 1px 1px, #0000 90deg, #eef2f7 0) 0 0 / 24px 24px;
}

/* SVG: allow touch panning & avoid selection */
svg#canvas {
  touch-action: pan-x pan-y;
  -webkit-user-select: none;
  user-select: none;
}

/* SVG connectors */
path.link {
  stroke-width: 2;
  fill: none;
  stroke-linejoin: round;
  stroke-linecap: round;
  mix-blend-mode: multiply;
}
path.link.dimmed { opacity: 0.18; }
path.link.strong { stroke-width: 3; opacity: 0.95; }

/* Node polish */
rect { stroke: rgba(255, 255, 255, 0.9); stroke-width: 2; }
text {
  font-family: system-ui, "Segoe UI", Roboto, Arial, "Noto Naskh Arabic", "Amiri", sans-serif;
  font-weight: 700;
  fill: #fff;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.25);
  stroke-width: 1;
}
rect.active-glow { filter: drop-shadow(0 1px 2px rgba(0,0,0,.20)); }

/* ─────────────────────────────────────────────────────────
   Tooltip (dark bubble) — bilingual colors
   ───────────────────────────────────────────────────────── */
#tooltip {
  position: fixed;
  z-index: 9999;
  max-width: none;
  padding: 10px 12px;
  font-size: 25px;
  line-height: 1.9;
  background: rgba(15, 23, 42, 0.95);
  color: var(--ar-dark);
  border: 1px solid rgba(100,116,139,0.35);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  pointer-events: none;
  white-space: normal;
  -webkit-user-select: none;
  user-select: none;
}
#tooltip .hover-line { display:block; }
#tooltip .hover-line + .hover-line { margin-top: 4px; }

/* Language color helpers */
.lang-en { color: var(--en); }
.lang-ar { color: inherit; }       /* default = inherit */

/* Enforce inside tooltip */
#tooltip .lang-en { color: var(--en); }
#tooltip .lang-ar { color: var(--ar-dark); }

/* ─── Examples Panel ─── */
aside#examples-panel {
  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  left: auto !important;
  box-sizing: border-box !important;

  width: min(900px, 65vw) !important;
  max-width: 95vw !important;
  min-width: 320px !important;
  height: auto !important;
  max-height: 95vh !important;

  background: #fff;
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow: visible;
  box-shadow: -8px 0 24px rgba(15,23,42,.08);
  z-index: 2147483647 !important;
  display: flex !important;
  flex-direction: column !important;

  --examples-font-size: 13px;
}
aside#examples-panel.hidden { display: none !important; }

aside#examples-panel > header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight:700;
  margin-bottom:8px;
  color: var(--fg);
}
#examples-close { margin-inline-start: auto; background:none; border:none; font-size:20px; cursor:pointer; }
#examples-tag.pill { background:#f1f5f9; padding:2px 6px; border-radius:999px; font-size:12px; margin-left:6px; }

.zoom-controls { display:inline-flex; gap:6px; align-items:center; }
.zoom-controls button {
  font: inherit;
  padding: 2px 8px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
}
.zoom-controls button:hover { opacity: 0.9; }

#examples-content {
  flex: 1;
  font-size: var(--examples-font-size);
  line-height: 1.5;
  width: 100%;
  max-width: none;
  background: #fff;
  color: var(--fg);
  max-height: none;
  overflow-y: auto;
  overflow-x: auto;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
  padding: 8px 10px;
}

/* Language colors inside examples */
#examples-content .lang-ar { color: var(--fg); }
#examples-content .lang-en { color: var(--en); }

/* Markdown headings inside examples */
#examples-content h1,
#examples-content h2,
#examples-content h3,
#examples-content h4 {
  color: var(--fg);
  margin: 0 0 8px;
  line-height: 1.2;
}

/* Markdown → HTML table rules */
#examples-content table {
  width: 100% !important;
  max-width: 100%;
  min-width: 0;
  table-layout: auto;
  font-size: inherit;
  border-collapse: collapse;
  word-break: normal;
  white-space: normal;
  background: transparent;
}
#examples-content thead th { font-weight: 700; white-space: nowrap; }
#examples-content th, #examples-content td {
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  text-align: center;
  vertical-align: top;
  word-break: normal;
  overflow-wrap: anywhere;
}

/* Arabic columns RTL */
#examples-content table td:nth-child(1),
#examples-content table td:nth-child(2),
#examples-content table td:nth-child(4),
#examples-content table td:nth-child(6),
#examples-content table th:nth-child(1),
#examples-content table th:nth-child(2),
#examples-content table th:nth-child(4),
#examples-content table th:nth-child(6) {
  direction: rtl;
  text-align: right;
}

/* English columns LTR */
#examples-content table td:nth-child(3),
#examples-content table td:nth-child(5),
#examples-content table td:nth-child(7),
#examples-content table th:nth-child(3),
#examples-content table th:nth-child(5),
#examples-content table th:nth-child(7) {
  direction: ltr;
  text-align: left;
  color: var(--en);
}

/* Highlight class used by keyword highlighter */
.hl { color:#16a34a !important; font-weight:700; }
#examples-content table td .hl,
#examples-content table th .hl { color:#16a34a !important; }

#examples-content .empty { color:#666; font-style:italic; }

/* Fullscreen behavior (if you toggle it) */
aside#examples-panel.fullscreen {
  position: fixed !important;
  top: 0 !important; left: 0 !important; right: 0 !important;
  width: 100vw !important; height: 100vh !important;
  max-width: none !important; max-height: none !important;
  padding: 24px !important;
  background: #fff;
  z-index: 2147483647 !important;
  overflow: auto !important;
  box-shadow: none !important;
}
aside#examples-panel.fullscreen #examples-content { max-height: calc(100vh - 88px); }

/* small responsive font tweaks */
@media (max-width: 900px) {
  aside#examples-panel { --examples-font-size: 12px; padding: 14px; }
}
@media (max-width: 520px) {
  aside#examples-panel { --examples-font-size: 11px; padding: 12px; }
  aside#examples-panel.fullscreen { padding: 12px !important; }
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) { #tooltip { transition: none; } }

/* utility spacer */
.spacer { flex: 1; }

/* ───────────── Extra-polish for mobile ───────────── */

/* Safe-area helper */
@supports (padding: max(0px)) {
  .safe-pad {
    padding-left:  max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom:max(8px, env(safe-area-inset-bottom));
    padding-top:   max(8px, env(safe-area-inset-top));
  }
}

/* Hover zoom buttons (mobile) */
#hover-zoom-controls {
  position: fixed;
  right: 12px;
  bottom: 12px;
  display: none;
  gap: 8px;
  z-index: 9999;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) 0;
}
#hover-zoom-controls button {
  min-width: 44px;
  min-height: 44px;
  font-size: 16px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}

/* Landscape: hide big header to free space */
@media (orientation: landscape) {
  header { display: none; }
  #hover-zoom-controls {
    right: calc(12px + env(safe-area-inset-right));
    bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

/* Hint toast */
#mobile-hint {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom));
  background: rgba(0,0,0,.75);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 9999;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
}
#mobile-hint.hidden { display: none; }
