/* =====================================================================
   Lab experiment shell — shared styling
   ---------------------------------------------------------------------
   The first three experiments each carried their own copy of this file,
   drifted from each other, and accounted for ~83 of the ~1100 lines in
   every new experiment. Extracted so an experiment only styles what is
   genuinely its own.

   Experiments may still add a <style> block for a bespoke widget. What
   belongs here is anything a second experiment would otherwise retype.
   ===================================================================== */

/* Self-hosted. jsdelivr is unreliable from Iran, which is where the
   readers are, and a lab that loads its font from a blocked CDN falls
   back to a face that renders Persian numerals wrong. */
@font-face {
  font-family: 'Vazirmatn';
  src: url('/wp-content/mu-plugins/fonts/vazirmatn/Vazirmatn-400.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/wp-content/mu-plugins/fonts/vazirmatn/Vazirmatn-600.woff2') format('woff2');
  font-weight: 600; font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/wp-content/mu-plugins/fonts/vazirmatn/Vazirmatn-700.woff2') format('woff2');
  font-weight: 700; font-display: swap;
}

:root {
  --bg: #0f1419;
  --panel: #1a2028;
  --panel-2: #232b36;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --good: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --border: #30363d;
  --mono: 'JetBrains Mono', 'Consolas', monospace;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.7; padding: 20px; }
html[lang="fa"] body { font-family: Vazirmatn, Tahoma, sans-serif; }
h1, h2, h3 { color: var(--accent); margin-top: 1.5em; }
h1 { text-align: center; border-bottom: 2px solid var(--border); padding-bottom: 12px; }
.container { max-width: 1100px; margin: 0 auto; }
.grid { display: grid; grid-template-columns: 1fr 350px; gap: 20px; margin: 20px 0; }
@media (max-width: 800px) { .grid { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
canvas { background: var(--panel-2); border-radius: 6px; display: block; width: 100%; height: auto; }

button { background: var(--accent); color: #0d1117; border: none; padding: 10px 18px; border-radius: 6px; font-family: inherit; font-size: 15px; font-weight: 600; cursor: pointer; margin: 4px; transition: transform 0.1s, opacity 0.2s; }
button:hover:not(:disabled) { transform: translateY(-1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--err); color: white; }
button.good { background: var(--good); color: #0d1117; }
/* A row of mutually exclusive choices — masses, angles, materials. */
button.choice-btn { min-width: 68px; unicode-bidi: plaintext; }
button.choice-btn.active { background: var(--warn); color: #0d1117; box-shadow: 0 0 0 2px var(--warn) inset, 0 0 10px rgba(210, 153, 34, 0.4); }

.control-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.control-row label { min-width: 100px; color: var(--muted); }
input[type=range] { flex: 1; }
input[type=number] { background: #0d1117; color: var(--text); border: 1px solid var(--border); padding: 6px 10px; font-family: var(--mono); font-size: 14px; border-radius: 4px; width: 100px; text-align: center; }

.timer-display { font-family: var(--mono); font-size: 42px; text-align: center; background: #0d1117; padding: 12px; border-radius: 6px; color: var(--good); margin: 12px 0; font-variant-numeric: tabular-nums; }
.phase-display { font-size: 16px; text-align: center; color: var(--warn); margin: 8px 0; min-height: 24px; }
/* One instrument readout: the number the student is reading off. */
.reading { background: #0d1117; padding: 12px; border-radius: 6px; text-align: center; font-family: var(--mono); margin: 12px 0; }
.reading .value { color: var(--warn); font-size: 26px; font-weight: 700; unicode-bidi: plaintext; }
.reading .label { color: var(--muted); font-size: 13px; }

table { width: 100%; border-collapse: collapse; margin: 12px 0; font-variant-numeric: tabular-nums; }
/* Cells mix Persian words with Latin units, so on the RTL page a value like
   "46 mm" gets reordered into "mm 46". `plaintext` lets each cell take its
   direction from its own first strong character, which gets both kinds right. */
th, td { padding: 8px 10px; text-align: center; border-bottom: 1px solid var(--border); unicode-bidi: plaintext; }
th { background: var(--panel-2); color: var(--accent); }
tr:hover td { background: var(--panel-2); }
.empty-row td { color: var(--muted); font-style: italic; }

.stats { background: var(--panel-2); padding: 12px; border-radius: 6px; margin: 12px 0; font-family: var(--mono); }
.stats .row { display: flex; justify-content: space-between; padding: 4px 0; gap: 12px; }
.stats .label { color: var(--muted); }
.stats .value { color: var(--text); font-weight: 600; unicode-bidi: plaintext; }
.highlight { color: var(--warn); font-size: 18px; }

.info-box { background: rgba(88, 166, 255, 0.1); border-inline-start: 3px solid var(--accent); padding: 12px 16px; border-radius: 4px; margin: 12px 0; }
.formula { background: #0d1117; padding: 12px; border-radius: 6px; text-align: center; font-size: 20px; font-family: 'Cambria Math', 'Times New Roman', serif; margin: 12px 0; color: var(--warn); }
.final-result { padding: 20px; background: linear-gradient(135deg, rgba(63, 185, 80, 0.15), rgba(88, 166, 255, 0.15)); border: 1px solid var(--good); border-radius: 8px; text-align: center; font-size: 22px; margin: 16px 0; }
.reveal-box { background: rgba(210, 153, 34, 0.1); border: 1px dashed var(--warn); padding: 16px; border-radius: 6px; margin: 16px 0; }
.reveal-box.hidden { display: none; }

details { margin: 10px 0; }
summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 6px 0; }
code { background: var(--panel-2); padding: 2px 6px; border-radius: 3px; font-family: var(--mono); color: var(--warn); }

.status-indicator { display: inline-block; padding: 4px 10px; border-radius: 12px; font-size: 13px; font-weight: 600; }
.status-idle { background: var(--panel-2); color: var(--muted); }
.status-running { background: rgba(63, 185, 80, 0.2); color: var(--good); animation: pulse 1s infinite; }
.status-active { background: rgba(210, 153, 34, 0.2); color: var(--warn); }
.status-settled { background: rgba(63, 185, 80, 0.2); color: var(--good); }
.status-done { background: rgba(248, 81, 73, 0.2); color: var(--err); }
@keyframes pulse { 50% { opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) {
  .status-running { animation: none; }
  button { transition: none; }
}

.video-wrap { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; border-radius: 8px; background: #000; margin: 16px 0; cursor: pointer; }
.video-wrap iframe, .video-wrap .video-poster { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; }
.video-poster { background-size: cover; background-position: center; display: flex; align-items: center; justify-content: center; background-color: #111; }
.video-poster::before { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 40%, rgba(0,0,0,0.6)); }
.video-play-btn { position: relative; width: 84px; height: 84px; border-radius: 50%; background: rgba(255, 0, 0, 0.85); display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 24px rgba(0,0,0,0.5); transition: transform 0.15s, background 0.15s; }
.video-wrap:hover .video-play-btn { transform: scale(1.1); background: rgb(255, 0, 0); }
.video-play-btn::after { content: ''; border-style: solid; border-width: 14px 0 14px 22px; border-color: transparent transparent transparent white; margin-inline-end: -4px; }
.video-title-overlay { position: absolute; bottom: 12px; left: 16px; right: 16px; color: white; font-size: 14px; text-shadow: 0 1px 4px rgba(0,0,0,0.8); text-align: start; z-index: 1; }
.video-caption { color: var(--muted); font-size: 14px; text-align: center; margin-top: 8px; }
.video-fallback { text-align: center; color: var(--muted); font-size: 13px; margin-top: 6px; }
.video-fallback a { color: var(--accent); }

.py-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.py-status { font-size: 13px; color: var(--muted); font-family: var(--mono); }
.py-status.ready { color: var(--good); }
.py-status.loading { color: var(--warn); }
.py-status.error { color: var(--err); }
.py-editor { width: 100%; min-height: 320px; background: #0d1117; color: #e6edf3; border: 1px solid var(--border); border-radius: 6px; padding: 14px; font-family: var(--mono); font-size: 13.5px; line-height: 1.65; direction: ltr; text-align: left; resize: vertical; tab-size: 4; -moz-tab-size: 4; }
.py-editor:focus { outline: 1px solid var(--accent); outline-offset: -1px; }
.py-output { background: #0d1117; border: 1px solid var(--border); border-radius: 6px; padding: 14px; margin-top: 12px; min-height: 40px; direction: ltr; text-align: left; }
.py-output.empty { color: var(--muted); font-style: italic; font-size: 13px; text-align: center; padding: 20px; }
.py-stdout { color: var(--good); font-family: var(--mono); font-size: 13px; white-space: pre-wrap; margin: 0; word-break: break-word; }
.py-stderr { color: var(--err); font-family: var(--mono); font-size: 13px; white-space: pre-wrap; margin: 8px 0 0; border-top: 1px dashed rgba(248, 81, 73, 0.4); padding-top: 8px; }
.py-plot { max-width: 100%; display: block; margin: 12px auto; border-radius: 6px; background: #232b36; }
.py-help { background: rgba(210, 153, 34, 0.08); border-inline-start: 3px solid var(--warn); padding: 10px 14px; border-radius: 4px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.py-help code { font-size: 12px; }

/* ── language toggle ─────────────────────────────────────────────── */
/* Fixed in the top-right of the iframe so it never scrolls away.
   Uses `right` not `inset-inline-end` so it stays top-right in both
   RTL and LTR without flipping. */
.lab-lang-toggle {
  position: fixed;
  top: 10px;
  right: 12px;
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  z-index: 9999;
  margin: 0;
  line-height: 1.5;
  letter-spacing: 0.5px;
  font-family: system-ui, sans-serif;
}
button.lab-lang-toggle:hover:not(:disabled) {
  background: rgba(88, 166, 255, 0.15);
  border-color: var(--accent);
  transform: none;
}
