/* EduQuant Kit — lab interface */

.lab-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: calc(100vh - var(--header-h));
}

/* ---------- Sidebar ---------- */
.lab-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
}
.lab-sidebar .sidebar-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.lab-list { list-style: none; margin: 0; padding: 6px 8px; overflow: auto; flex: 1; }
.lab-list li { margin-bottom: 2px; }
.lab-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}
.lab-item:hover { background: var(--bg); }
.lab-item.active { background: #EAF2FB; }
.lab-item.locked { color: var(--text-secondary); }
.lab-item .status { font-size: 14px; text-align: center; }
.lab-item .status.complete { color: var(--success); }
.lab-item .status.locked { color: #94A3B8; }
.lab-item .status.available { color: var(--primary-light); }
.lab-item .title { font-weight: 500; font-size: 13px; line-height: 1.3; }
.lab-item .meta { display: flex; gap: 6px; align-items: center; margin-top: 2px; font-size: 11.5px; color: var(--text-secondary); }
.lab-item .points { font-size: 11.5px; font-weight: 600; color: var(--text-secondary); }
.lab-level-group { padding: 10px 10px 4px; font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 12.5px; }
.sidebar-foot .progress { margin-top: 6px; }

/* ---------- Content ---------- */
.lab-content { padding: 24px 28px 60px; max-width: 1100px; width: 100%; }
.lab-header { margin-bottom: 20px; }
.lab-header .badges { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.lab-header h1 { font-size: 1.6rem; margin-bottom: 4px; }
.lab-header .subtitle { color: var(--text-secondary); font-size: 15px; }
.lab-header .meta-row { display: flex; gap: 18px; margin-top: 10px; color: var(--text-secondary); font-size: 13px; flex-wrap: wrap; }
.lab-header .meta-row span { display: inline-flex; align-items: center; gap: 5px; }
.lab-section { margin-bottom: 18px; }

.collapsible > .collapsible-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 6px 0;
}
.collapsible > .collapsible-head .collapsible-toggle {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}
.collapsible > .collapsible-head .ti-chevron { margin-left: auto; transition: transform .15s; color: var(--text-secondary); }
.collapsible.open > .collapsible-head .ti-chevron { transform: rotate(180deg); }
.collapsible > .collapsible-body { display: none; padding: 0 16px 16px; }
.collapsible.open > .collapsible-body { display: block; }
.collapsible.card { padding: 0; }

.theory-body p { line-height: 1.65; }
.theory-body pre { background: var(--bg); color: var(--text); border: 1px solid var(--border); }

.steps-list { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.step {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--surface);
}
.step > .step-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
  font-weight: 500;
}
.step > .step-head .num {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.step > .step-head .ti-chevron { margin-left: auto; color: var(--text-secondary); transition: transform .15s; }
.step.open > .step-head .ti-chevron { transform: rotate(180deg); }
.step > .step-body { display: none; padding: 0 12px 12px 46px; line-height: 1.6; color: var(--text); }
.step.open > .step-body { display: block; }
.step > .step-head .preview { color: var(--text-secondary); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step.open > .step-head .preview { display: none; }

/* ---------- Split layout (lab.html only — demo.html reuses .lab-layout/.lab-content, so everything is scoped) ----------
 * lab list | steps panel (resizable, collapsible) | divider | circuit panel. Each panel scrolls on its own, so the
 * steps and the circuit are on screen together. Phones stack the two panels. */
body.lab-page .lab-layout {
  grid-template-columns: 200px minmax(0, 1fr);
  height: calc(100vh - var(--header-h));
  min-height: 0;
}
/* 200px list: the points move under the level/difficulty row so titles get the full width */
body.lab-page .lab-item { grid-template-columns: 22px minmax(0, 1fr); column-gap: 6px; row-gap: 0; padding: 8px; align-items: start; }
body.lab-page .lab-item .status { grid-row: 1 / span 2; margin-top: 1px; }
body.lab-page .lab-item .points { grid-column: 2; margin-top: 2px; }
body.lab-page .lab-item .title { overflow-wrap: break-word; }
body.lab-page .lab-item .meta { flex-wrap: wrap; row-gap: 2px; }
body.lab-page .lab-page-container {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
  padding: 0;
  max-width: none;
  min-width: 0;
}
.lab-mobile-switch { display: none; }

.lab-steps-panel {
  width: var(--steps-w, 380px);
  min-width: 280px;
  max-width: 500px;
  height: 100%;
  overflow-y: auto;
  border-right: 2px solid #EEF4FB;
  background: #FFFFFF;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.steps-panel-bar {
  position: sticky; top: 0; z-index: 4;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  background: #FFFFFF;
  border-bottom: 1px solid var(--border);
}
.steps-strip-label { display: none; }
.steps-panel-body { flex: 1; padding: 14px 16px 0; }
.lab-steps-panel .lab-section { margin-bottom: 14px; }
.lab-steps-panel .collapsible > .collapsible-head { padding-right: 8px; }
.lab-steps-panel .collapsible > .collapsible-head .collapsible-toggle { padding: 10px 12px; font-size: 14px; }
.lab-steps-panel .collapsible > .collapsible-body { padding: 0 12px 12px; }
.lab-steps-panel .card:not(.collapsible) { padding: 12px 14px; }
.lab-steps-panel .card p { margin: 0 0 6px; font-size: 13.5px; line-height: 1.55; }
.lab-steps-panel .card p:last-child { margin-bottom: 0; }

/* compact lab header: badges and meta on tight lines */
.lab-header.compact { margin-bottom: 12px; }
.lab-header.compact .badges { gap: 6px; margin-bottom: 6px; }
.lab-header.compact .badge { font-size: 11px; padding: 2px 7px; }
.lab-header.compact h1 { font-size: 1.2rem; line-height: 1.3; }
.lab-header.compact .subtitle { font-size: 13px; }
.lab-header.compact .meta-row { gap: 12px; margin-top: 6px; font-size: 12px; }

.panel-divider {
  width: 4px;
  background: #EEF4FB;
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.2s;
  touch-action: none;
}
.panel-divider:hover,
.panel-divider:focus-visible,
.lab-page-container.resizing .panel-divider { background: #22D3EE; outline: none; }
.lab-page-container.resizing { cursor: col-resize; user-select: none; }

.lab-circuit-panel {
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  background: #F8FAFC;
  display: flex;
  flex-direction: column;
  padding: 0 18px 40px;
}
.lab-circuit-panel > * { flex-shrink: 0; }
.circuit-controls {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  margin: 0 -18px 14px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.circuit-controls .ctl-group { display: flex; align-items: center; gap: 8px; }
.circuit-controls .ctl-label { color: var(--text-secondary); font-weight: 600; }
.circuit-controls .spacer { flex: 1; }
.circuit-controls .stats { display: flex; gap: 14px; font-weight: 500; color: var(--text-secondary); }
.circuit-controls .stats b { color: var(--text); }
.lab-circuit-panel .gate-grid,
.lab-circuit-panel .gate-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.lab-circuit-card .designer-embed { min-height: 260px; }
.lab-circuit-card .canvas-panel { padding-top: 4px; }

.run-sim-btn {
  width: 100%;
  justify-content: center;
  margin-top: 12px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  background: #0E7490;
  border-color: #0E7490;
  color: #fff;
}
.run-sim-btn:hover:not(:disabled) { background: #155E75; border-color: #155E75; }

/* collapsed steps panel: a 48px strip with the toggle and the progress count */
.lab-page-container.steps-collapsed .lab-steps-panel { width: 48px; min-width: 48px; overflow: hidden; }
.lab-page-container.steps-collapsed .steps-panel-body,
.lab-page-container.steps-collapsed .panel-divider { display: none; }
.lab-page-container.steps-collapsed .steps-panel-bar { flex-direction: column; padding: 10px 4px; border-bottom: 0; gap: 14px; }
.lab-page-container.steps-collapsed .steps-collapse-btn { writing-mode: vertical-rl; padding: 10px 4px; }
.lab-page-container.steps-collapsed .steps-strip-label {
  display: flex; align-items: center; gap: 8px;
  writing-mode: vertical-rl;
  font-size: 12.5px; font-weight: 600; color: var(--text-secondary); cursor: pointer;
}
.steps-strip-count { color: #059669; }

/* ---------- Steps accordion (lab_guide.js) ---------- */
.lab-guide-header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.lab-guide-title { font-size: 15px; margin: 0; }
.lab-guide-subtitle { color: var(--text-secondary); font-size: 12.5px; }
.lab-guide-header .btn { margin-left: auto; }
.lab-guide-steps { list-style: none; margin: 0; padding: 0; }
.step-item { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 6px; background: var(--surface); }
.step-item.active { border-color: #93C5FD; background: #EFF6FF; box-shadow: inset 3px 0 0 #2563EB; }
.step-item > .step-head {
  width: 100%;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 9px 10px;
  border: 0; background: transparent;
  font: inherit; text-align: left; color: var(--text);
  cursor: pointer;
}
.step-badge {
  background: #1B4F8A; color: white; border-radius: 50%;
  flex: 0 0 24px; width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.step-badge .ok { display: none; }
.step-item.active .step-badge { background: #2563EB; }
.step-item.done .step-badge { background: #059669; }
.step-item.done .step-badge .n { display: none; }
.step-item.done .step-badge .ok { display: inline; }
.step-action { flex: 1; min-width: 0; line-height: 1.45; font-weight: 500; font-size: 13.5px; overflow-wrap: anywhere; }
.step-item.done:not(.active) .step-action { color: var(--text-secondary); }
.step-item > .step-body { display: none; padding: 0 10px 10px 44px; }
.step-item.open > .step-body { display: block; }
.step-expected { color: #059669; font-style: italic; font-size: 0.9em; line-height: 1.45; }
.step-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.lab-guide-empty { margin: 0; padding: 4px 0 12px; color: var(--text-secondary); }
.lab-progress {
  position: sticky; bottom: 0; z-index: 3;
  margin-top: 8px;
  padding: 10px 0 12px;
  background: #FFFFFF;
  border-top: 1px solid var(--border);
  font-size: 13px; font-weight: 600;
}
.lab-progress .progress { margin-top: 6px; }
.step > .step-head .preview { flex: 1; min-width: 0; }   /* long previews ellipsize instead of widening the page */

/* step → palette gate hint: glow for three seconds with a tip beside the gate */
.gate-btn.gate-hint { animation: gate-hint-glow 3s ease-out forwards; }
@keyframes gate-hint-glow {
  0%, 75% { box-shadow: 0 0 8px #22D3EE, 0 0 0 2px #22D3EE; }
  100% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0); }
}
.gate-hint-tip {
  position: fixed; z-index: 200;
  transform: translateY(-50%);
  padding: 5px 9px;
  background: #0F2D4F; color: #fff;
  border-radius: 6px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  animation: gate-hint-tip 3s ease-out forwards;
}
.gate-hint-tip.below { transform: none; }
@keyframes gate-hint-tip { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .gate-btn.gate-hint { animation: none; box-shadow: 0 0 8px #22D3EE, 0 0 0 2px #22D3EE; }
  .gate-hint-tip { animation: none; }
}

/* tablets: narrower steps panel (the palette also starts folded, labs.js) */
@media (min-width: 769px) and (max-width: 1024px) {
  .lab-steps-panel { width: var(--steps-w, 280px); }
  .lab-circuit-panel { padding: 0 12px 32px; }
  .circuit-controls { margin: 0 -12px 12px; padding: 8px 12px; }
}

/* phones: stack the panels; the switch jumps between them */
@media (max-width: 768px) {
  body.lab-page .lab-layout { height: auto; }
  body.lab-page .lab-page-container {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  .lab-mobile-switch {
    display: flex; gap: 8px;
    position: sticky; top: var(--header-h); z-index: 20;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  .lab-mobile-switch .btn { flex: 1; justify-content: center; }
  .lab-mobile-switch .btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
  .lab-steps-panel,
  .lab-page-container.steps-collapsed .lab-steps-panel {
    width: 100%;
    min-width: 0;
    max-width: none;
    height: auto;
    max-height: 400px;
    border-right: none;
    border-bottom: 2px solid #EEF4FB;
  }
  .steps-panel-bar, .panel-divider { display: none; }
  .lab-page-container.steps-collapsed .steps-panel-body { display: block; }
  .steps-panel-body { padding: 12px 12px 0; }
  .lab-circuit-panel {
    width: 100%;
    height: auto;
    overflow: visible;
    padding: 0 12px 40px;
  }
  .circuit-controls { position: static; margin: 0 -12px 12px; padding: 8px 12px; }
  .lab-circuit-card .designer-embed { grid-template-columns: minmax(0, 1fr); }   /* 1fr grew to the palette's min-content */
  .lab-circuit-card .palette-row { flex-wrap: wrap; }
}

/* ---------- Closed-beta content protection (content-protection.js; beta tester sessions only) ---------- */
body.beta-protected .lab-theory,
body.beta-protected .lab-steps {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;   /* the long-press copy bubble on iOS */
}
@media print {
  /* Ctrl+P is blocked, File > Print is not: keep the protected text off the paper either way */
  body.beta-protected .lab-theory,
  body.beta-protected .lab-steps { display: none; }
}

.designer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}
.designer-actions .spacer { flex: 1; }
.verify-result { margin-top: 12px; }
.lab-results { margin-top: 14px; }
.lab-results .chart-box { height: 220px; }

.ibm-note { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ibm-note .btn { margin-left: auto; }

/* ---------- Quiz ---------- */
.quiz-question { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.quiz-question:last-of-type { border-bottom: 0; }
.quiz-question .q { font-weight: 600; margin-bottom: 8px; }
.quiz-option {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  line-height: 1.4;
}
.quiz-option:hover { background: var(--bg); }
.quiz-option input { margin-top: 3px; }
.quiz-option.correct { border-color: var(--success); background: #ECFDF5; }
.quiz-option.wrong { border-color: var(--danger); background: #FEF2F2; }
.quiz-explanation { font-size: 13px; color: var(--text-secondary); margin-top: 6px; padding-left: 4px; }
.quiz-score { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 12px; }
.quiz-score .score { font-size: 1.6rem; font-weight: 700; color: var(--primary); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .lab-layout { grid-template-columns: 1fr; }
  .lab-sidebar { position: static; height: auto; max-height: 360px; border-right: 0; border-bottom: 1px solid var(--border); }
  .lab-content { padding: 16px 14px 40px; }
}
@media (max-width: 900px) {
  /* lab page: the lab list stacks above the split panels, as before */
  body.lab-page .lab-layout { grid-template-columns: 1fr; height: auto; }
}
