/* ==========================================================================
   Simulation shell: header, stage, control panel, help dialog
   ========================================================================== */
html, body.sim-body { height: 100%; }
body.sim-body { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }

.sim-header {
  display: flex; align-items: center; gap: 14px;
  min-height: 60px; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  flex: none; z-index: 5;
}
.sim-back {
  display: inline-flex; align-items: center; gap: 4px;
  height: 38px; padding: 0 12px 0 8px; border-radius: 10px;
  text-decoration: none; font-weight: 600; font-size: 14px; color: var(--ink-2);
  border: 1px solid var(--line);
}
[dir="rtl"] .sim-back { padding: 0 8px 0 12px; }
.sim-back:hover { background: var(--surface-2); color: var(--ink); }
.sim-heading { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.sim-heading .subject-icon { background: var(--subject-soft); color: var(--subject); }
.sim-heading-text { min-width: 0; }
.sim-heading h1 { margin: 0; font-size: 17px; line-height: 1.2; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sim-crumbs { display: flex; align-items: center; gap: 6px; margin: 2px 0 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.sim-crumbs .badge { font-size: 11px; line-height: 16px; padding: 0 6px; }
.sim-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.sim-main { flex: 1; min-height: 0; display: flex; gap: 0; }
.sim-stage {
  position: relative; flex: 1; min-width: 0; min-height: 0; overflow: hidden;
  background: #fff; touch-action: none; user-select: none; -webkit-user-select: none;
}
.sim-stage > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.sim-main[data-mode="3d"] .sim-stage { background: radial-gradient(ellipse at 50% 35%, #1d2547 0%, #0b1022 70%); }
.sim-embed { padding: 0; }
.sim-frame { flex: 1; width: 100%; height: 100%; border: 0; background: #fff; }

.sim-panel {
  width: 330px; flex: none; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-inline-start: 1px solid var(--line);
  padding: 14px 14px 24px;
  display: flex; flex-direction: column; gap: 12px;
}
.sim-panel:empty { display: none; }

/* ---------- panel building blocks (created by sim-core.js) ---------- */
.ctl-group { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface); }
.ctl-group > h2 {
  margin: 0 0 10px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.ctl-group > h2::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--subject); }
.ctl-group > .ctl + .ctl { margin-top: 12px; }

.ctl-slider label, .ctl-select label, .ctl-seg > span {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  font-size: 13.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px;
}
.ctl-slider output { font-family: var(--mono); font-size: 13px; color: var(--ink); background: var(--surface-2); padding: 1px 7px; border-radius: 6px; white-space: nowrap; }
.ctl-slider input[type="range"] { width: 100%; accent-color: var(--subject); height: 24px; margin: 0; cursor: pointer; }
.ctl-select select {
  width: 100%; height: 36px; padding: 0 10px; border-radius: 9px;
  border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer;
}
.ctl-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; color: var(--ink-2); font-weight: 500; }
.ctl-toggle input { appearance: none; width: 36px; height: 21px; border-radius: 999px; background: var(--line-strong); position: relative; cursor: pointer; flex: none; transition: background .15s; margin: 0; }
.ctl-toggle input::after { content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.ctl-toggle input:checked { background: var(--subject); }
.ctl-toggle input:checked::after { transform: translateX(15px); }
[dir="rtl"] .ctl-toggle input:checked::after { transform: translateX(-15px); }
.ctl-toggle .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }

.ctl-seg .seg { display: flex; padding: 3px; background: var(--surface-2); border-radius: 10px; gap: 3px; flex-wrap: wrap; }
.ctl-seg .seg button {
  flex: 1 1 auto; min-height: 32px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent;
  font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.ctl-seg .seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(20,26,46,.15); }

.ctl-row { display: flex; gap: 8px; flex-wrap: wrap; }
.ctl-row .btn { flex: 1 1 auto; }

.ctl-readouts { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; font-size: 13.5px; }
.ctl-readout { display: contents; }
.ctl-readout span { color: var(--ink-2); }
.ctl-readout output { font-family: var(--mono); font-weight: 600; text-align: end; color: var(--ink); white-space: nowrap; }
.ctl-readout.big output { font-size: 18px; }

.ctl-note { margin: 0; font-size: 13px; color: var(--ink-2); line-height: 1.5; }
.ctl-note.ok { color: var(--ok); font-weight: 600; }
.ctl-note.bad { color: var(--bad); font-weight: 600; }
.ctl-formula { font-family: "Cambria Math", "STIX Two Math", Georgia, serif; font-size: 18px; text-align: center; padding: 8px; background: var(--surface-2); border-radius: 9px; direction: ltr; }

.ctl-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--ink-2); }
.ctl-legend span { display: inline-flex; align-items: center; gap: 6px; }
.ctl-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* overlays on the stage */
.stage-overlay { position: absolute; inset: 0; pointer-events: none; }
.stage-overlay > * { pointer-events: auto; }
.stage-hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  padding: 6px 12px; border-radius: 999px; font-size: 12.5px;
  background: rgba(10, 14, 30, .62); color: #fff; pointer-events: none;
  white-space: nowrap; max-width: calc(100% - 24px); overflow: hidden; text-overflow: ellipsis;
  transition: opacity .6s;
}
.stage-card {
  position: absolute; top: 12px; inset-inline-start: 12px;
  padding: 10px 12px; border-radius: 12px; background: rgba(255,255,255,.92);
  box-shadow: var(--shadow); font-size: 13px; max-width: min(320px, 60%);
}
.sim-main[data-mode="3d"] .stage-card { background: rgba(14, 19, 40, .78); color: #e8ebf7; box-shadow: none; border: 1px solid rgba(255,255,255,.12); }
.label-3d {
  position: absolute; top: 0; left: 0; transform: translate(-50%, -50%);
  padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: rgba(10, 14, 30, .72); color: #fff; pointer-events: none; will-change: transform;
  unicode-bidi: plaintext;
}

/* help dialog */
.help-dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  border: 0; border-radius: 18px; padding: 0; box-shadow: var(--shadow-lg); color: var(--ink);
}
.help-dialog::backdrop { background: rgba(10, 14, 30, .45); }
.help-dialog form { padding: 20px 22px 18px; }
.help-dialog header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.help-dialog h2 { margin: 0; font-size: 20px; }
.help-dialog h3 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--subject); }
.help-dialog p { margin: 0 0 8px; color: var(--ink-2); }
.help-dialog ul { margin: 0; padding-inline-start: 20px; color: var(--ink-2); }
.help-dialog li { margin-bottom: 4px; }
.help-dialog footer { display: flex; justify-content: flex-end; margin-top: 16px; }

@media (max-width: 600px) {
  .stage-hint { white-space: normal; text-align: center; width: max-content; border-radius: 12px; }
}
@media (max-width: 860px) {
  body.sim-body { overflow: auto; height: auto; min-height: 100%; }
  .sim-main { flex-direction: column; }
  .sim-stage { flex: none; height: 62vh; min-height: 320px; }
  .sim-embed { min-height: calc(100vh - 60px); }
  .sim-panel { width: auto; border-inline-start: 0; border-top: 1px solid var(--line); overflow: visible; }
  .sim-back span { display: none; }
  .sim-back { padding: 0 8px; }
}
@media (max-width: 520px) {
  .sim-header { padding: 8px 10px; gap: 8px; flex-wrap: wrap; }
  .sim-heading .subject-icon { display: none; }
  .sim-actions .lang-picker svg { display: none; }
  .sim-actions [data-fullscreen] { display: none; }
}

/* numbers + units stay in LTR order inside RTL (Arabic) panels */
[dir="rtl"] .ctl-slider output, [dir="rtl"] .ctl-readout output, [dir="rtl"] .ctl-formula { direction: ltr; unicode-bidi: isolate; }
