:root {
  /* رَسْم على رموز دلاتو (وثيقة ١٢٠ §٣): أسماء رَسْم الداخلية تبقى، وقيمها كلّها من delato.style.css — لا قيمة لونية حرفية */
  --bg: var(--dl-bg);
  --panel: var(--dl-panel);
  --panel-2: var(--dl-panel-2);
  --line: var(--dl-line);
  --text: var(--dl-ink);
  --muted: var(--dl-dim);
  --accent: var(--dl-accent);
  --amber: var(--dl-warn);
  --danger: var(--dl-err);
  --ok: var(--dl-ok);
  --shadow: var(--dl-shadow-2);
  --bar: var(--dl-panel);                                   /* الأشرطة (كان أغمق قليلاً من اللوحة) */
  --deep: var(--dl-bg);                                     /* القيعان والمسرح */
  --veil: color-mix(in srgb, var(--dl-bg) 60%, transparent);  /* ستارة خلف الحوارات والإطار */
  font-family: var(--dl-font);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); user-select: none; }
input, textarea { user-select: text; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }

/* ١٥٨ (MOUNT §١٠): الشريط الموحَّد (.dl-nav--glass، ارتفاعه --dl-nav-h) أوّل <body>، والمحرّر يأخذ الباقي
   فلا يُدفع الخطّ الزمنيّ ولا التذييل تحت حافّة النافذة */
body { overflow: hidden; }
:root[data-dl-locale="en"] .dl-nav { direction: ltr; }
#app {
  height: calc(100dvh - var(--dl-nav-h));
  display: grid;
  grid-template-columns: 300px 1fr 76px;
  grid-template-rows: auto 1fr auto 40px;
  direction: rtl;
}

header, footer, #timeline { grid-column: 1 / -1; }
#side { grid-column: 1; grid-row: 2; }
#stage { grid-column: 2; grid-row: 2; }
#tools { grid-column: 3; grid-row: 2; }
#timeline { grid-row: 3; }
footer { grid-row: 4; }

header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  background: var(--bar);
  border-bottom: 1px solid var(--line);
  min-width: 0;
  flex-wrap: wrap;
  height: auto;
  padding: 6px 8px;
  row-gap: 6px;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-left: 4px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.brand b { font-size: 16px; font-weight: 700; letter-spacing: 0; }
.brand span { color: var(--muted); font-size: 12px; }
.sep { width: 1px; height: 22px; background: var(--line); }
.grow { flex: 1; }

.hbtn, .tool, .mini, .swatch, select, .vcb {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.hbtn, .mini {
  height: 32px;
  padding: 0 8px;
  background: var(--panel-2);
  flex: 0 0 auto;
}
.hbtn:hover, .mini:hover, .tool:hover { border-color: var(--dl-line-2); }
.hbtn.on, .tool.on, .mini.on {
  background: var(--dl-accent-soft);
  border-color: var(--accent);
  color: var(--dl-ink);
}
select {
  height: 32px;
  padding: 0 8px;
  background: var(--panel-2);
}

#tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--bar);
  border-right: 1px solid var(--line);
  overflow: auto;
}
.tool {
  width: 58px;
  height: 46px;
  display: grid;
  place-items: center;
  padding: 0;
  position: relative;
}
.tool svg { width: 22px; height: 22px; }
.tool .k {
  position: absolute;
  left: 4px;
  bottom: 2px;
  font-size: 9px;
  color: var(--muted);
  font-family: var(--dl-mono);
}
.tool-gap { height: 8px; }

#side {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;            /* لا يخرج شيء من اللوحة إلى الخطّ الزمني (١٥٧) */
}
.side-head, .prop-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}
.crumb {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 10px 0;
  color: var(--muted);
  font-size: 12px;
}
.crumb button {
  background: transparent;
  border: 0;
  color: var(--accent);
  padding: 0;
}
#tree {
  overflow: auto;
  padding: 6px;
  min-height: 96px;
  flex: 1 1 0;                 /* الشجرة تأخذ ما يبقى، ولا تنزل تحت ٩٦ */
}
.row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 4px;
  align-items: center;
  padding: 4px 6px;
  border-radius: 7px;
  margin-bottom: 2px;
}
.row:hover { background: var(--dl-panel-2); }
.row.on { background: var(--dl-accent-soft); }
.row .nm { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 10px; }
.iconbtn {
  width: 22px;
  height: 22px;
  border: 0;
  background: transparent;
  border-radius: 5px;
  color: var(--muted);
}
.iconbtn:hover { background: var(--dl-line); color: var(--text); }
.iconbtn.off { opacity: 0.35; }

#props { border-top: 1px solid var(--line); padding: 8px 10px 12px; flex: 0 1 auto; min-height: 0; overflow-y: auto; }   /* بطوله ما اتّسع، ثمّ يُمرَّر داخل حدّه */
.field { display: grid; grid-template-columns: 52px 1fr; gap: 6px; align-items: center; margin-bottom: 6px; }
.field label { color: var(--muted); font-size: 12px; }
.xyz { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.xyz input, .field input[type="text"], .field input[type="number"] {
  width: 100%;
  background: var(--deep);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  min-width: 0;
}
.xyz input, .field input[type="number"] {
  direction: ltr;
  text-align: center;
}
.swatches { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.swatch { width: 18px; height: 18px; border-radius: 50%; padding: 0; }
.swatch.on { outline: 2px solid var(--text); outline-offset: 1px; }

#stage { position: relative; min-width: 0; min-height: 0; }
#board {
  position: absolute;
  inset: 0;
  display: grid;
  direction: ltr;
  gap: 2px;
  background: var(--deep);
}
#board.lay-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
#board.lay-1 .pane:not(.persp) { display: none; }
#board.lay-1 .pane-lab, #board.lay-1 .pane.active { outline: none; }
#board.lay-1 .pane-lab { display: none; }
#board.lay-2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
#board.lay-2 .pane.top, #board.lay-2 .pane.side { display: none; }
#board.lay-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.pane { position: relative; min-width: 0; min-height: 0; }
.pane.active { outline: 1px solid var(--accent); outline-offset: -1px; z-index: 1; }
.pane-canvas, #view { width: 100%; height: 100%; display: block; touch-action: none; }
.pane-lab {
  position: absolute;
  top: 6px;
  left: 8px;
  z-index: 2;
  font-size: 11px;
  color: var(--text);
  background: color-mix(in srgb, var(--dl-bg) 62%, transparent);
  border-radius: 4px;
  padding: 2px 6px;
  pointer-events: none;
}
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.tag {
  position: absolute;
  transform: translate(-50%, -140%);
  background: color-mix(in srgb, var(--dl-bg) 88%, transparent);
  color: var(--amber);
  border: 1px solid color-mix(in srgb, var(--amber) 45%, transparent);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 12px;
  white-space: nowrap;
  font-family: var(--dl-mono);
}
#marquee {
  position: fixed;
  pointer-events: none;
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  z-index: 4;
}
#marquee.cross {
  border-style: dashed;
  border-color: var(--amber);
  background: color-mix(in srgb, var(--amber) 12%, transparent);
}
#empty {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, calc(100% - 24px));
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
  pointer-events: none;
}
#axes {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: 86px;
  height: 86px;
  pointer-events: none;
}
#snapname {
  position: absolute;
  pointer-events: none;
  color: var(--text);
  font-size: 11px;
  text-shadow: 0 1px 2px var(--deep);
}

footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--bar);
  border-top: 1px solid var(--line);
  font-size: 12px;
}
#hint { color: var(--muted); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#readout { color: var(--amber); font-family: var(--dl-mono); }
.vcb {
  width: 140px;
  height: 28px;
  padding: 0 8px;
  background: var(--deep);
  direction: ltr;
  text-align: center;
}

#toasts {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 20;
  pointer-events: none;
}
.toast {
  background: var(--deep);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
  font-size: 13px;
}

dialog {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  width: min(560px, calc(100vw - 32px));
  padding: 16px 18px;
}
dialog::backdrop { background: var(--veil); }
dialog h3 { margin: 0 0 8px; }
dialog table { width: 100%; border-collapse: collapse; font-size: 13px; }
dialog td { padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
kbd {
  font-family: var(--dl-mono);
  background: var(--deep);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 11px;
}
.mfoot { display: flex; justify-content: flex-start; margin-top: 12px; }

@media (max-width: 1100px) {
  .brand span { display: none; }
}
#app.side-off { grid-template-columns: 1fr 76px; }
#app.side-off #side { display: none; }
#app.side-off #stage { grid-column: 1; }
#app.side-off #tools { grid-column: 2; }

@media (max-width: 680px) {
  #app { grid-template-columns: 1fr 64px; grid-template-rows: 52px 1fr auto 180px 40px; }
  #side { grid-column: 1 / -1; grid-row: 4; }
  #tools { grid-column: 2; grid-row: 2; }
  #stage { grid-column: 1; grid-row: 2; }
  #timeline { grid-row: 3; }
  footer { grid-row: 5; }
  #app.side-off { grid-template-columns: 1fr 64px; grid-template-rows: 52px 1fr auto 40px; }
  #app.side-off #timeline { grid-row: 3; }
  #app.side-off footer { grid-row: 4; }
}

#timeline {
  direction: ltr;
  background: var(--deep);
  border-top: 1px solid var(--line);
  min-height: 96px;
  display: flex;
  flex-direction: column;
}
.tl-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 0;
}
.tlbtn {
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 6px;
  font-size: 12px;
}
.tlbtn.on { border-color: var(--accent); color: var(--accent); }
#tl-time, #gate .tc {
  font-family: var(--dl-mono);
  color: var(--amber);
  font-size: 12px;
  min-width: 72px;
}
.tl-dur { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 4px; }
.tl-dur input {
  width: 52px;
  height: 26px;
  background: var(--deep);
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
}
.tl-title { margin-left: auto; color: var(--muted); font-size: 12px; }
#tl-track {
  position: relative;
  margin: 6px 8px 8px;
  height: 52px;
  background: var(--deep);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
#tl-ruler {
  position: absolute;
  inset: 0 0 auto 0;
  height: 16px;
  border-bottom: 1px solid var(--line);
}
.tick {
  position: absolute;
  top: 0;
  height: 16px;
  border-left: 1px solid var(--dl-line-2);
  color: var(--muted);
  font-size: 10px;
  padding-left: 3px;
  font-family: var(--dl-mono);
}
#tl-keys { position: absolute; left: 0; right: 0; top: 16px; bottom: 0; }
.diamond {
  position: absolute;
  top: 50%;
  width: 11px;
  height: 11px;
  margin: -6px 0 0 -6px;
  background: var(--amber);
  transform: rotate(45deg);
  cursor: ew-resize;
}
.diamond.on { background: var(--accent); }
#tl-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px solid var(--danger);
  pointer-events: none;
}
#tl-playhead::before {
  content: "";
  position: absolute;
  top: 0;
  left: -5px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid var(--danger);
}
#gate {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}
#gate.on { display: block; }
#gate .frame {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  width: min(92%, calc(70vh * 16 / 9));
  aspect-ratio: 16 / 9;
  max-height: 78%;
  border: 1px solid var(--accent);
  box-shadow: 0 0 0 9999px var(--veil);
}
#gate .tc {
  position: absolute;
  top: 10px;
  left: 12px;
  text-shadow: 0 1px 2px var(--deep);
}

/* ---------- جسر دلاتو (١٢٠ — الموجة ٨): أقسام تُطوى في لوحة الخصائص، كلّها برموز ---------- */
.dlsec { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 6px; }
.dlsec > summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.dlsec .field select { width: 100%; height: 28px; }
.dltext {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-bottom: 6px;
  background: var(--deep);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  padding: 4px 6px;
  resize: vertical;
}
.dltext:focus, .dlsec input:focus { outline: 1px solid var(--accent); }
.dlnote { color: var(--muted); font-size: 11px; margin: 4px 0; }
.dlref { display: flex; align-items: center; gap: 6px; }
.dlref img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.dlrow { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
#dl-gen { width: min(760px, calc(100vw - 32px)); }
#dl-gen select { max-width: 100%; }
#dl-gen input[type="password"] { height: 32px; background: var(--deep); border: 1px solid var(--line); border-radius: 8px; color: var(--text); padding: 0 8px; }
.dlwarn { color: var(--amber); font-size: 12px; margin: 4px 0; }
.gprompt {
  background: var(--deep);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  user-select: text;
}
.gjob { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; margin: 6px 0; background: var(--panel-2); }
.gjob video { width: 100%; margin-top: 6px; border-radius: 6px; background: var(--deep); }
.gjob a { color: var(--accent); font-size: 12px; }
.gstage { color: var(--accent); font-size: 12px; }

/* ---------- الأيقونات (١٥٧): من icons.js وحده؛ الزرّ المربّع أيقونة بلا كتابة ---------- */
.hbtn, .mini, .tlbtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.hbtn .dl-svg { width: 18px; height: 18px; }
.mini .dl-svg, .tlbtn .dl-svg, .iconbtn .dl-svg { width: 16px; height: 16px; }
.hbtn.ico, .mini.ico { width: 32px; padding: 0; }
.tlbtn.ico { width: 26px; padding: 0; }
.dl-ico { display: inline-flex; }
.iconbtn { display: inline-grid; place-items: center; }

/* ---------- المكتبة والاستيراد (١٥٧) ---------- */
#dl-lib, #dl-imp { width: min(820px, calc(100vw - 32px)); }
.dlsearch { flex: 1 1 auto; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px;
  background: var(--deep); border: 1px solid var(--line); border-radius: 8px; color: var(--muted); }
.dlsearch:focus-within { border-color: var(--accent); }
.dlsearch input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 14px; }
.libgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; max-height: min(60vh, 520px); overflow-y: auto; margin: 8px 0; }
.libcard { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; color: var(--text); }
.libcard:hover, .libcard:focus-visible { border-color: var(--accent); outline: 0; }
.libcard img { width: 100%; aspect-ratio: 4 / 3; border-radius: 6px; display: block; }
.libname { font-size: 12px; }
.libname.en { color: var(--muted); font-size: 11px; direction: ltr; }
.dlnote.ltr { direction: ltr; text-align: end; }
