/* ==========================================================================
   Interactive visualisations and calculators
   ========================================================================== */

.viz {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: radial-gradient(120% 100% at 50% 40%, #0d0d0f 0%, var(--space-bg) 72%);
  color: var(--space-text);
  border: 1px solid color-mix(in srgb, #fff 7%, var(--border));
  box-shadow: var(--shadow);
}
.viz__stage { position: relative; aspect-ratio: 16 / 9; min-height: 340px; max-height: 78vh; width: 100%; }
.viz__stage--tall { aspect-ratio: 4 / 3; }
.viz__stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.viz__stage canvas:active { cursor: grabbing; }
@media (max-width: 640px) { .viz__stage { aspect-ratio: 4 / 5; } }

.viz__overlay {
  position: absolute;
  left: 1rem; top: 1rem;
  max-width: min(22rem, calc(100% - 2rem));
  padding: .75rem .9rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, .66);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, .08);
  font-size: .84rem;
  line-height: 1.5;
  color: #d9d7d0;
  pointer-events: none;
}
.viz__overlay strong { color: #fff; font-weight: 650; }
.viz__overlay .viz__big { display: block; font-family: var(--font-display); font-size: 1.3rem; color: #fff; font-variant-numeric: tabular-nums; }

.viz__legend { position: absolute; right: 1rem; top: 1rem; display: flex; flex-direction: column; gap: .3rem; font-size: .78rem; color: #c9c7c0; pointer-events: none; text-align: right; }
.viz__legend span { display: inline-flex; align-items: center; justify-content: flex-end; gap: .45rem; }
.viz__legend i { width: .6rem; height: .6rem; border-radius: 50%; display: inline-block; }
@media (max-width: 640px) { .viz__legend { top: auto; bottom: .75rem; right: .75rem; } }

.viz__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem 1rem;
  padding: .85rem 1rem;
  background: rgba(255, 255, 255, .03);
  border-top: 1px solid rgba(255, 255, 255, .08);
}
.viz__controls .seg {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .08);
  flex-wrap: wrap;
}
.viz__controls .seg button, .viz__btn {
  border: 0;
  min-height: 36px;
  padding: .35rem .8rem;
  border-radius: 9px;
  background: transparent;
  color: #cfcdc6;
  font-size: .86rem;
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
.viz__controls .seg button:hover, .viz__btn:hover { color: #fff; background: rgba(255,255,255,.06); }
.viz__controls .seg button[aria-pressed="true"] { background: #ffffff; color: #000; }
.viz__btn { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); }
.viz__btn .icon { width: 1rem; height: 1rem; }
.viz__controls label { display: inline-flex; align-items: center; gap: .55rem; font-size: .84rem; color: #cfcdc6; }
.viz__controls .grow { flex: 1 1 220px; }
.viz__controls .grow input { flex: 1; }
.viz__controls input[type="range"] { accent-color: #ffffff; min-width: 120px; }
.viz__controls input[type="checkbox"] { accent-color: #ffffff; width: 1rem; height: 1rem; }
.viz__caption { padding: .9rem 1.1rem 1.1rem; font-size: .88rem; line-height: 1.6; color: #b9b6ae; border-top: 1px solid rgba(255,255,255,.06); }
.viz__caption strong { color: #eae8e2; }

/* ---------- Light "lab" panels for calculators ---------- */
.lab {
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.lab__head { padding: 1.1rem 1.3rem .2rem; }
.lab__head h3 { font-size: 1.15rem; }
.lab__head p { margin-top: .35rem; color: var(--text-2); font-size: .93rem; line-height: 1.55; }
.lab__body { padding: 1rem 1.3rem 1.3rem; }
.lab__body > * + * { margin-top: 1rem; }
.lab__row { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: center; }
.lab label { font-size: .88rem; color: var(--text-2); display: inline-flex; align-items: center; gap: .5rem; }
.lab input[type="text"], .lab input[type="number"], .lab select {
  min-height: 44px;
  padding: .45rem .8rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  min-width: 0;
}
.lab input[type="text"]:focus, .lab input[type="number"]:focus, .lab select:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.lab input.ar-input { font-family: var(--font-arabic); font-size: 1.35rem; direction: rtl; width: 100%; }
.lab input[type="range"] { accent-color: var(--accent); width: 100%; }
.lab__out {
  padding: .9rem 1rem;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.lab__big { font-family: var(--font-display); font-size: clamp(1.6rem, 1.3rem + 1vw, 2.2rem); font-weight: 600; line-height: 1.15; }
.lab__sub { color: var(--muted); font-size: .88rem; margin-top: .25rem; }
.lab__chips { display: flex; flex-wrap: wrap; gap: .35rem; direction: rtl; }
.lab__chip { display: inline-flex; flex-direction: column; align-items: center; min-width: 2.5rem; padding: .3rem .4rem; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); }
.lab__chip b { font-family: var(--font-arabic); font-size: 1.3rem; line-height: 1.4; font-weight: 500; }
.lab__chip small { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; direction: ltr; }
.lab__presets { display: flex; flex-wrap: wrap; gap: .4rem; }
.lab__presets button { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: .3rem .75rem; font-size: .84rem; color: var(--text-2); }
.lab__presets button:hover { color: var(--text); border-color: var(--border-strong); }
.lab__presets button [lang="ar"] { font-size: 1.05rem; line-height: 1.2; }

/* Bars (inheritance, ratios) */
.bars { display: flex; height: 44px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.bars > span { display: grid; place-items: center; font-size: .78rem; font-weight: 650; white-space: nowrap; overflow: hidden; transition: flex-basis 500ms var(--ease); min-width: 0; }
.bars__legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .84rem; color: var(--text-2); }
.bars__legend i { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }

/* Basmala letter strip */
.letter-strip { display: flex; flex-wrap: wrap; gap: .3rem; direction: rtl; justify-content: flex-start; }
.letter-strip span { display: inline-flex; flex-direction: column; align-items: center; width: 2.6rem; padding: .35rem 0; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.letter-strip b { font-family: var(--font-arabic); font-weight: 500; font-size: 1.35rem; line-height: 1.5; }
.letter-strip small { font-size: .7rem; color: var(--muted); direction: ltr; }
.letter-strip span.gap { width: .6rem; border: 0; background: none; }

/* Isostasy diagram */
.iso svg { width: 100%; height: auto; }
.iso text { font-family: var(--font-sans); font-size: 13px; fill: var(--text-2); }
.iso .iso-mantle { fill: var(--surface-3); }
.iso .iso-crust { fill: var(--surface); stroke: var(--text-2); }
.iso .iso-sea { fill: var(--surface-2); }
.iso .iso-dim { stroke: var(--text-2); stroke-width: 1.2; fill: none; }
.iso .iso-label { font-weight: 650; fill: var(--text); }

/* Embryology stages */
.stages { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); counter-reset: stage; }
.stage { padding: 1.1rem 1.15rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); position: relative; }
.stage::before { counter-increment: stage; content: counter(stage); position: absolute; right: 1rem; top: .9rem; font-family: var(--font-display); font-size: 1.5rem; color: var(--border-strong); }
.stage__ar { font-family: var(--font-quran); font-size: 1.6rem; line-height: 1.6; color: var(--text); }
.stage__tr { font-style: italic; color: var(--accent); font-weight: 600; }
.stage__when { display: inline-block; margin-top: .45rem; font-size: .76rem; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.stage p { margin-top: .45rem; color: var(--text-2); font-size: .92rem; line-height: 1.55; }

/* Prime chips */
.nums { display: flex; flex-wrap: wrap; gap: .4rem; }
.nums span { min-width: 3rem; text-align: center; padding: .35rem .55rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-variant-numeric: tabular-nums; font-weight: 600; font-size: .92rem; }
.nums span.is-prime { border-color: color-mix(in srgb, var(--accent) 60%, transparent); background: var(--accent-soft); color: var(--accent-ink); }
.nums span small { display: block; font-size: .68rem; font-weight: 500; color: var(--muted); }

/* Range sliders get their label above them */
.lab label:has(input[type="range"]) { display: flex; flex-direction: column; align-items: stretch; gap: .35rem; width: 100%; }

/* Calculator fields never exceed the panel width */
.lab label { flex-wrap: wrap; max-width: 100%; }
.lab select, .lab input[type="text"], .lab input[type="number"] { max-width: 100%; }
