/* Virtual Science Lab - themed to match the My Study Mantra site: soft light page, white cards,
   violet accent, Plus Jakarta Sans headings and DM Sans body. The experiment stage stays a deep
   indigo "lab desk" so the SVG apparatus (glass, brass, glowing lamps) keeps its contrast. */
@font-face { font-family: 'DM Sans'; font-style: normal; font-display: swap; font-weight: 100 1000; src: url(/fonts/dm-sans-latin-ext-wght-normal.woff2) format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'DM Sans'; font-style: normal; font-display: swap; font-weight: 100 1000; src: url(/fonts/dm-sans-latin-wght-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Plus Jakarta Sans'; font-style: normal; font-display: swap; font-weight: 200 800; src: url(/fonts/plus-jakarta-sans-latin-ext-wght-normal.woff2) format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Plus Jakarta Sans'; font-style: normal; font-display: swap; font-weight: 200 800; src: url(/fonts/plus-jakarta-sans-latin-wght-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --bg: #f7f8fb;
  --card: #ffffff;
  --ink: #252b3d;
  --ink-dim: #6f7589;
  --ink-faint: #8b90a0;
  --title: #2b2470;
  --line: #edf0f4;
  --line-strong: #e3e6ee;
  --brand: #6758d8;
  --brand-hover: #5a4bd0;
  --brand-soft: #eeeaff;
  --brand-softer: #f7f5ff;
  --brand-line: #d9d4f7;
  --ok: #1f8a52;
  --ok-soft: #eaf8f0;
  --bad: #c2410c;
  --shadow: 0 2px 8px #31394d18;
  --shadow-lg: 0 6px 16px #34435a18;
  --font-head: 'Plus Jakarta Sans', 'DM Sans', system-ui, sans-serif;
  /* kept for the experiment scripts, which reference --accent-2 for headings inside cards */
  --accent: var(--brand);
  --accent-2: var(--brand);
  --glass-line: var(--line);
  --radius: 16px;
  --topbar-h: 66px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  color: var(--ink);
  font: 15px/1.5 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  min-width: 320px;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------------- top bar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20; min-height: var(--topbar-h);
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; padding: 10px 24px;
  background: rgba(255, 255, 255, .94); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); box-shadow: 0 2px 10px #31394d0d;
}
.brand { display: flex; align-items: center; gap: 11px; margin-right: 6px; font-family: var(--font-head); font-weight: 800; font-size: 19px; letter-spacing: -.7px; color: #202438; line-height: 1; white-space: nowrap; }
.brand small { display: block; margin-top: 6px; font: 800 8px/1 'DM Sans', sans-serif; letter-spacing: 2.3px; text-transform: uppercase; color: #afb3c2; }
.brand-mark {
  flex: none; width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: var(--brand); color: #fff; box-shadow: 0 7px 14px #7566e82b;
}
.brand-mark svg { width: 20px; height: 20px; }
.back-home {
  color: var(--brand); text-decoration: none; font-size: 13.5px; font-weight: 700; padding: 8px 13px; border-radius: 999px;
  border: 1px solid var(--brand-line); background: var(--brand-softer); white-space: nowrap;
}
.back-home:hover { background: var(--brand-soft); border-color: var(--brand); }
.back-home[hidden] { display: none; }
.seg { display: inline-flex; border-radius: 13px; padding: 4px; gap: 2px; background: #f0edff; }
.seg-btn {
  appearance: none; border: 0; cursor: pointer; padding: 8px 15px; border-radius: 10px; color: var(--ink-dim);
  background: transparent; font: inherit; font-size: 14px; font-weight: 600; white-space: nowrap; transition: background .15s, color .15s, box-shadow .15s;
}
.seg-btn:hover { color: var(--brand); }
.seg-btn.on { color: #fff; background: var(--brand); box-shadow: 0 6px 14px #6758d82a; }
.select-wrap select {
  font: inherit; font-weight: 600; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 12px;
  padding: 10px 14px; min-width: 280px; max-width: 46vw; box-shadow: var(--shadow); cursor: pointer;
}
.select-wrap select:hover { border-color: var(--brand-line); }

/* ---------------- layout ---------------- */
.layout {
  display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 22px;
  max-width: 1680px; margin: 0 auto; padding: 22px 24px 48px; align-items: start;
}
.panel, .workspace { min-width: 0; }
.panel { position: sticky; top: calc(var(--topbar-h) + 14px); max-height: calc(100vh - var(--topbar-h) - 28px); overflow: auto; display: flex; flex-direction: column; gap: 12px; scrollbar-width: thin; scrollbar-color: var(--brand-line) transparent; padding: 2px; }
#panel-sections { display: flex; flex-direction: column; gap: 12px; }
.sec, .obs-card, .study-card, .controls {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.sec { padding: 0 18px; }
.sec summary { cursor: pointer; padding: 14px 0; font-family: var(--font-head); font-weight: 800; letter-spacing: .8px; text-transform: uppercase; font-size: 12px; color: var(--brand); }
.sec summary:hover { color: var(--brand-hover); }
.sec p, .sec ul, .sec ol { margin: 0 0 16px; color: var(--ink); }
.sec ul, .sec ol { padding-left: 20px; }
.sec li { margin-bottom: 5px; }
.obs-card { padding: 16px 18px 18px; }
.obs-card h2 { margin: 0 0 10px; font-family: var(--font-head); font-size: 12px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase; color: var(--brand); }
.obs-title { font-weight: 700; margin-bottom: 6px; color: var(--title); }
table.obs { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
table.obs th { text-align: right; font-weight: 700; font-size: 12.5px; color: var(--ink-dim); border-bottom: 1px solid var(--line-strong); padding: 5px 6px; }
table.obs td { text-align: right; padding: 5px 6px; border-bottom: 1px dashed var(--line); }
table.obs th:first-child, table.obs td:first-child { text-align: left; }
table.obs td.empty { text-align: center; color: var(--ink-faint); padding: 14px; font-style: italic; }
table.obs .x { background: none; border: 0; color: #d9534f; cursor: pointer; font-size: 17px; line-height: 1; padding: 0 4px; border-radius: 6px; }
table.obs .x:hover { background: #fff0f1; }
.obs-line { font-size: 13.5px; color: var(--ink); margin-top: 3px; }
.obs-mean { margin-top: 10px; padding: 9px 12px; border-radius: 10px; background: var(--brand-softer); border: 1px solid var(--brand-soft); color: var(--title); font-weight: 700; font-variant-numeric: tabular-nums; }
.result { margin-top: 14px; padding: 14px 16px; border-radius: 14px; background: linear-gradient(135deg, #f7f5ff, #eeeaff); border: 1px solid var(--brand-line); }
.res-line.big { font-family: var(--font-head); font-size: 22px; font-weight: 800; letter-spacing: -.3px; color: var(--brand); margin: 2px 0; }
.res-hints { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--brand-line); }
.res-hints-title { font-size: 12px; font-weight: 800; letter-spacing: .7px; text-transform: uppercase; color: var(--brand); margin-bottom: 4px; }
.res-hints ul { margin: 0; padding-left: 18px; }
.res-hints-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.hint-btn { padding: 8px 14px; font-size: 13px; }
.hint-btn.ghost { background: transparent; box-shadow: none; border-color: var(--brand-line); color: var(--brand); }
.hint-btn.ghost:hover { background: #fff; border-color: var(--brand); }
.hint-btn:disabled { opacity: .55; cursor: default; filter: none; transform: none; }
.res-hints li { margin-bottom: 6px; font-size: 13.5px; line-height: 1.45; }
.res-verdict { margin-top: 4px; color: var(--ink-dim); }

/* ---------------- stage: the indigo lab desk ---------------- */
.stage {
  position: relative; border-radius: 22px; overflow: hidden; aspect-ratio: 1200 / 690;
  background:
    radial-gradient(ellipse at 50% -10%, #4a4296 0%, rgba(74, 66, 150, 0) 58%),
    radial-gradient(rgba(255, 255, 255, .07) 1px, transparent 1.3px) 0 0 / 26px 26px,
    linear-gradient(180deg, #2c2759 0%, #1e1a40 100%);
  border: 1px solid #3a3470;
  box-shadow: 0 18px 40px #2b247033, inset 0 1px 0 rgba(255, 255, 255, .08);
}
.stage-svg { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; touch-action: pan-y; }
.stage-svg .item.dragging { filter: drop-shadow(0 12px 10px rgba(0, 0, 0, .5)); }
.flame { transform-box: fill-box; transform-origin: 50% 100%; animation: flicker 1.7s ease-in-out infinite alternate; }
@keyframes flicker { 0% { transform: scale(1, 1); } 50% { transform: scale(.94, 1.05) skewX(1.5deg); } 100% { transform: scale(1.04, .97) skewX(-1.5deg); } }
.reset-btn:focus-visible { outline: none; }
.reset-btn:focus-visible circle:first-child { stroke: #cfc9f5; stroke-width: 3; }

.exp-title {
  margin: 24px 2px 14px; font-family: var(--font-head); font-weight: 800; font-size: clamp(22px, 2.6vw, 32px); line-height: 1.2; letter-spacing: -.6px;
  color: var(--title);
}

/* ---------------- controls ---------------- */
.controls { display: flex; flex-direction: column; gap: 14px; padding: 16px 18px; }
.control-row { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; }
.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 700; font-size: 14px; color: #3d4356;
  padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: #fff; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s, border-color .15s, background .15s, color .15s;
}
.btn:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-softer); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn.primary { color: #fff; background: var(--brand); border-color: var(--brand); box-shadow: 0 10px 22px #6758d82a; }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }
.btn.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-hover); }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-weight: 600; color: #3d4356; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 44px; height: 26px; border-radius: 13px; background: #d5d8e2; position: relative; transition: background .15s; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(32, 36, 56, .3); transition: transform .15s; }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track .knob { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--brand); outline-offset: 2px; }
.field { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-dim); font-size: 14px; font-weight: 500; }
.field input[type=range] { width: 150px; accent-color: var(--brand); }
.field output { min-width: 4.2em; color: var(--title); font-weight: 700; font-variant-numeric: tabular-nums; }
.setup-guide { padding: 14px 16px; border-radius: 14px; background: var(--brand-softer); border: 1px solid var(--brand-soft); }
.setup-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.setup-title { font-family: var(--font-head); font-size: 12px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase; color: var(--brand); }
.setup-count { font-size: 12.5px; color: var(--ink-dim); font-weight: 600; }
.setup-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.setup-steps li { display: flex; gap: 10px; align-items: flex-start; opacity: .7; }
.setup-steps li.current { opacity: 1; }
.setup-steps .tick { flex: 0 0 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; background: #fff; border: 1px solid var(--brand-line); color: var(--ink-dim); }
.setup-steps li.done .tick { background: var(--ok); border-color: var(--ok); color: #fff; }
.setup-steps li.current .tick { background: var(--brand); color: #fff; border-color: var(--brand); }
.setup-steps .step-label { font-size: 14px; font-weight: 700; color: var(--title); }
.setup-steps li.done .step-label { text-decoration: line-through; text-decoration-color: #afb3c2; color: var(--ink-dim); }
.setup-steps .step-hint { margin-top: 2px; font-size: 13.5px; line-height: 1.45; color: var(--ink); }
.field.quiz select, .count-input, .quiz-text, .conclusion {
  font: inherit; font-size: 13.5px; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 10px; padding: 7px 10px;
}
.field.quiz select:focus, .count-input:focus, .quiz-text:focus, .conclusion:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px #7665e719; }
.count-input { width: 80px; }
.quiz-text, .conclusion { width: 100%; padding: 9px 11px; }
.counts { color: var(--title); font-weight: 800; font-variant-numeric: tabular-nums; }
.status { min-height: 3em; color: var(--ink); font-size: 14.5px; }

.graphs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.graph-card { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); aspect-ratio: 420 / 300; background: #fff; }
.graph-svg { display: block; width: 100%; height: 100%; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 24px); opacity: 0; pointer-events: none; z-index: 40;
  max-width: min(640px, 92vw); padding: 12px 18px; border-radius: 14px; color: #fff; text-align: center; font-weight: 500;
  background: #252b3d; box-shadow: 0 14px 34px rgba(32, 36, 56, .35); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- responsive ---------------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  .workspace { order: -1; }
  .topbar { position: static; }
}
@media (max-width: 720px) {
  .topbar { padding: 10px 14px; gap: 8px 10px; }
  .select-wrap select { min-width: 0; width: 100%; max-width: none; }
  .select-wrap { flex: 1 1 100%; }
  .seg { max-width: 100%; overflow-x: auto; }
  .seg-btn { padding: 8px 12px; }
  .graphs { grid-template-columns: 1fr; }
  .layout { padding: 14px; gap: 16px; }
  .stage { border-radius: 16px; }
  .controls { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) { .flame { animation: none; } .btn, .seg-btn, .switch .track, .switch .knob { transition: none; } }

/* ---------------- subject picker, tooltips, overlays, study cards ---------------- */
.subject-picker .seg-btn { padding: 8px 14px; }
.lab-tooltip { position: fixed; z-index: 60; max-width: 260px; padding: 9px 12px; border-radius: 12px; font-size: 13px; line-height: 1.4; color: #fff; background: #252b3d; box-shadow: 0 10px 26px rgba(32, 36, 56, .35); pointer-events: none; opacity: 0; transition: opacity .12s; display: flex; flex-direction: column; gap: 2px; }
.lab-tooltip.show { opacity: 1; }
.lab-tooltip strong { color: #cfc9f5; }
.lab-overlay { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; background: rgba(30, 26, 64, .55); backdrop-filter: blur(3px); }
.lab-overlay[hidden] { display: none; }
.overlay-card { width: min(440px, 92%); max-height: 92%; overflow: auto; padding: 18px 20px; border-radius: 18px; background: #fff; color: var(--ink); border: 1px solid var(--line); box-shadow: 0 20px 44px rgba(32, 36, 56, .4); }
.overlay-card h3, .study-card h3 { margin: 0 0 4px; font-family: var(--font-head); font-size: 15px; font-weight: 800; letter-spacing: -.2px; color: var(--title); }
.lower-svg { width: 100%; background: #f7f5ff; border-radius: 10px; margin: 8px 0; }
.lower-range { width: 100%; accent-color: var(--brand); }
.card-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; flex-wrap: wrap; }
.card-sub { font-size: 12.5px; color: var(--ink-dim); margin-bottom: 8px; }
.card-note { font-size: 13.5px; margin: 6px 0; color: var(--ink); }
.study-card { padding: 16px 18px; min-width: 0; }
.study-card.wide { grid-column: 1 / -1; }
.label-svg { width: 100%; background: #f7f5ff; border-radius: 10px; touch-action: none; }
.sketch-canvas { width: 100%; background: #fff; border: 1px solid var(--line-strong); border-radius: 10px; touch-action: none; cursor: crosshair; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line-strong); cursor: pointer; }
.quiz-q { font-weight: 700; margin: 12px 0 4px; color: var(--title); }
.quiz-opt { display: block; margin: 3px 0; font-size: 14px; cursor: pointer; }
.quiz-opt input { accent-color: var(--brand); }
.quiz-why { font-size: 13px; color: var(--ink-dim); margin: 2px 0 6px; }
.check-line { font-size: 13.5px; margin: 4px 0; }
.check-line.ok { color: var(--ok); }
.check-line.bad { color: var(--bad); }
.bar-row { display: grid; grid-template-columns: 130px 1fr 130px; gap: 8px; align-items: center; margin: 5px 0; font-size: 13px; }
.bar-track { height: 12px; border-radius: 6px; background: var(--brand-soft); overflow: hidden; }
.bar-fill { display: block; height: 100%; background: linear-gradient(90deg, #7566e8, #a79cf5); }
.view-canvas { z-index: 2; }
