/* =====================================================
   COMPONENTS.CSS — Reusable UI Components
   ===================================================== */

/* ─── Callout Boxes ─── */
.callout {
  display: flex;
  gap: 0.9rem;
  padding: 1rem 1.2rem;
  border-radius: var(--radius);
  margin: 1.6rem 0;
  border: 1px solid transparent;
  font-size: 0.94rem;
  line-height: 1.65;
}

.callout-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  margin-top: 0.05rem;
  line-height: 1.65;
}

.callout-body { flex: 1; min-width: 0; }
.callout-body p:last-child { margin-bottom: 0; }
.callout-body strong { display: block; margin-bottom: 0.25rem; font-size: 0.92rem; }

/* Key concept (blue) */
.callout-key {
  background: var(--blue-pale);
  border-color: var(--blue-light);
}
.callout-key .callout-icon { color: var(--blue); }
.callout-key .callout-body strong { color: var(--blue); }

/* Info / explainer (teal) */
.callout-info {
  background: var(--teal-pale);
  border-color: var(--teal-light);
}
.callout-info .callout-icon { color: var(--teal); }
.callout-info .callout-body strong { color: var(--teal); }

/* Warning / limitation (amber) */
.callout-warn {
  background: var(--amber-pale);
  border-color: var(--amber-light);
}
.callout-warn .callout-icon { color: var(--amber); }
.callout-warn .callout-body strong { color: var(--amber); }

/* Danger / important (red) */
.callout-danger {
  background: var(--red-pale);
  border-color: var(--red-light);
}
.callout-danger .callout-icon { color: var(--red); }
.callout-danger .callout-body strong { color: var(--red); }

/* Success / example (green) */
.callout-success {
  background: var(--green-pale);
  border-color: var(--green-light);
}
.callout-success .callout-icon { color: var(--green); }
.callout-success .callout-body strong { color: var(--green); }

/* Deep dive / advanced (purple) */
.callout-deep {
  background: var(--purple-pale);
  border-color: var(--purple-light);
}
.callout-deep .callout-icon { color: var(--purple); }
.callout-deep .callout-body strong { color: var(--purple); }

/* Analogy (amber, softer) */
.callout-analogy {
  background: #fffbeb;
  border-color: #fde68a;
  border-left: 4px solid var(--amber);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.callout-analogy .callout-icon { color: var(--amber); }
.callout-analogy .callout-body strong { color: var(--amber); }

/* ─── Term Tooltips ─── */
.term {
  cursor: help;
  border-bottom: 1px dashed var(--blue-mid);
  color: var(--blue);
  position: relative;
  display: inline;
  text-decoration: none;
}

.term::after {
  content: attr(data-def);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 280px;
  background: var(--text-primary);
  color: #fefcf8;
  font-family: 'Source Serif 4', serif;
  font-size: 0.82rem;
  line-height: 1.55;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  white-space: normal;
  text-align: left;
}

.term::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--text-primary);
  z-index: 501;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.term:hover::after,
.term:hover::before,
.term.tip-open::after,
.term.tip-open::before {
  opacity: 1;
}

/* ─── Cards ─── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.6rem;
  box-shadow: var(--shadow-sm);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1.4rem 0;
}

.card h4 {
  font-family: 'Playfair Display', serif;
  font-size: 1.05rem;
  margin-top: 0;
  margin-bottom: 0.45rem;
  color: var(--text-primary);
}

.card p { font-size: 0.92rem; color: var(--text-secondary); margin-bottom: 0; }

.card-accent-blue  { border-left: 3px solid var(--blue); }
.card-accent-teal  { border-left: 3px solid var(--teal); }
.card-accent-amber { border-left: 3px solid var(--amber); }
.card-accent-green { border-left: 3px solid var(--green); }
.card-accent-red   { border-left: 3px solid var(--red); }
.card-accent-purple{ border-left: 3px solid var(--purple); }

/* ─── Stat Cards (index hero) ─── */
.stat-cards {
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  margin-top: 2.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.2rem 1.5rem;
  box-shadow: var(--shadow-sm);
  min-width: 130px;
  flex: 1;
}

.stat-value {
  font-family: 'Playfair Display', serif;
  font-size: 1.9rem;
  font-weight: 900;
  color: var(--blue);
  line-height: 1;
  margin-bottom: 0.3rem;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* ─── Timeline ─── */
.timeline {
  margin: 1.8rem 0;
  position: relative;
  padding-left: 1.8rem;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: linear-gradient(to bottom, var(--blue-mid), var(--teal));
  border-radius: 2px;
}

.timeline-item {
  position: relative;
  margin-bottom: 1.5rem;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -1.8rem;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--blue-mid);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 2px var(--blue-mid);
}

.timeline-item.milestone::before {
  background: var(--teal);
  box-shadow: 0 0 0 2px var(--teal);
  width: 12px;
  height: 12px;
  left: calc(-1.8rem - 1px);
  top: 5px;
}

.timeline-year {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 0.2rem;
}

.timeline-item h4 {
  margin-top: 0;
  margin-bottom: 0.3rem;
  font-size: 1rem;
}

.timeline-item p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0;
}

/* ─── Step-by-step guide ─── */
.steps {
  margin: 1.6rem 0;
  counter-reset: steps;
}

.step {
  display: flex;
  gap: 1.2rem;
  margin-bottom: 1.6rem;
  counter-increment: steps;
}

.step-num {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  background: var(--blue);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 0.1rem;
}

.step-body { flex: 1; }
.step-body h4 { margin-top: 0; margin-bottom: 0.3rem; font-size: 1rem; }
.step-body p { font-size: 0.93rem; color: var(--text-secondary); margin-bottom: 0.5rem; }

/* ─── Comparison Table ─── */
.comparison-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4rem 0;
  font-size: 0.9rem;
}

.comparison-table th {
  background: var(--blue-pale);
  color: var(--blue);
  font-family: 'Source Serif 4', serif;
  font-weight: 600;
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 2px solid var(--blue-light);
}

.comparison-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.comparison-table tr:last-child td { border-bottom: none; }
.comparison-table tr:hover td { background: var(--bg-secondary); }

.check { color: var(--green); font-size: 1.1em; }
.cross { color: var(--red); font-size: 1.1em; }
.partial { color: var(--amber); font-size: 1.1em; }

/* ─── pLDDT Color Guide ─── */
.plddt-guide {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 0.8rem;
  margin: 1.4rem 0;
}

.plddt-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.plddt-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
}

.plddt-text { min-width: 0; }
.plddt-range {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
  margin-bottom: 2px;
}
.plddt-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.2;
}

/* ─── Protein structure diagram ─── */
.structure-levels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin: 1.4rem 0;
}

.structure-level {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  padding: 1rem;
  text-align: center;
}

.structure-level .sl-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.5rem;
}

.structure-level .sl-visual {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  line-height: 1;
}

.structure-level .sl-name {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

.structure-level .sl-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}

/* ─── Accordion (FAQ/deep dives) ─── */
.accordion {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 1.2rem 0;
}

.accordion-item {
  border-bottom: 1px solid var(--border);
}

.accordion-item:last-child { border-bottom: none; }

.accordion-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
  background: var(--bg-card);
  border: none;
  cursor: pointer;
  text-align: left;
  font-family: 'Source Serif 4', serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  transition: background 0.15s;
}

.accordion-trigger:hover { background: var(--bg-secondary); }

.accordion-trigger .acc-arrow {
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.accordion-item.open .acc-arrow { transform: rotate(180deg); }

.accordion-body {
  display: none;
  padding: 1rem 1.2rem 1.2rem;
  background: var(--bg-secondary);
  font-size: 0.92rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.accordion-item.open .accordion-body { display: block; }
.accordion-body p:last-child { margin-bottom: 0; }

/* ─── Tool Cards ─── */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.4rem 0;
}

.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, transform 0.15s;
}

.tool-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.tool-card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.tool-badge {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  text-transform: uppercase;
}

.badge-free   { background: var(--green-light); color: var(--green); }
.badge-web    { background: var(--blue-light); color: var(--blue); }
.badge-python { background: var(--amber-light); color: var(--amber); }
.badge-open   { background: var(--teal-light); color: var(--teal); }
.badge-paid   { background: #fce7f3; color: #9d174d; }

.tool-card h4 {
  font-size: 0.95rem;
  margin: 0;
  line-height: 1.2;
  color: var(--text-primary);
}

.tool-card p {
  font-size: 0.84rem;
  color: var(--text-secondary);
  margin-bottom: 0.6rem;
  line-height: 1.5;
}

.tool-card a {
  font-size: 0.8rem;
  font-family: 'JetBrains Mono', monospace;
}

/* ─── Interactive Diagram: MSA Grid ─── */
.msa-demo {
  overflow-x: auto;
  margin: 1.4rem 0;
}

.msa-table {
  border-collapse: collapse;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
}

.msa-table td, .msa-table th {
  width: 28px;
  height: 28px;
  text-align: center;
  padding: 0;
  border: 1px solid rgba(255,255,255,0.3);
}

.msa-table .row-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: right;
  padding-right: 0.6rem;
  width: auto;
  white-space: nowrap;
  border: none;
  background: none;
}

.msa-table .col-num {
  font-size: 0.65rem;
  color: var(--text-muted);
  border: none;
  background: none;
}

/* Amino acid coloring */
.aa-hydrophobic { background: #fbbf24; color: #451a03; }
.aa-polar       { background: #34d399; color: #022c22; }
.aa-charged-pos { background: #60a5fa; color: #1e3a5f; }
.aa-charged-neg { background: #f87171; color: #450a0a; }
.aa-special     { background: #a78bfa; color: #2e1065; }
.aa-conserved   { background: #1d4ed8; color: white; font-weight: 700; }
.aa-gap         { background: #e7e5e4; color: #a8a29e; }

/* ─── PAE Heatmap ─── */
.pae-wrapper {
  position: relative;
  display: inline-block;
  margin: 1.2rem 0;
}

.pae-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  text-align: center;
}

/* ─── Inline Diagram: Protein Chain ─── */
.chain-diagram {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.4rem;
  margin: 1.2rem 0;
  overflow-x: auto;
  line-height: 1.9;
  white-space: pre;
}

/* ─── Quiz / Check your understanding ─── */
.quiz-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.6rem;
  margin: 2rem 0;
}

.quiz-box h4 {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: 'JetBrains Mono', monospace;
  margin-bottom: 0.6rem;
  margin-top: 0;
}

.quiz-q {
  font-family: 'Playfair Display', serif;
  font-size: 1.05rem;
  margin-bottom: 1rem;
}

.quiz-reveal-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  font-family: 'Source Serif 4', serif;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}

.quiz-reveal-btn:hover { background: var(--blue-pale); color: var(--blue); }

.quiz-answer {
  display: none;
  margin-top: 1rem;
  padding: 0.9rem 1.1rem;
  background: var(--green-pale);
  border: 1px solid var(--green-light);
  border-radius: var(--radius);
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.quiz-answer.shown { display: block; }

/* ─── Key Point summary boxes ─── */
.key-points {
  background: var(--blue-pale);
  border: 1px solid var(--blue-light);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.6rem;
  margin: 2rem 0;
}

.key-points h4 {
  color: var(--blue);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.8rem;
  margin-top: 0;
}

.key-points ul {
  margin-bottom: 0;
  padding-left: 1.4rem;
}

.key-points li {
  color: var(--text-secondary);
  font-size: 0.93rem;
  margin-bottom: 0.45rem;
}

.key-points li:last-child { margin-bottom: 0; }

/* ─── Mistake list ─── */
.mistake-list {
  list-style: none;
  padding: 0;
  margin: 1.2rem 0;
}

.mistake-list li {
  display: flex;
  gap: 0.8rem;
  padding: 0.85rem 1rem;
  margin-bottom: 0.7rem;
  border: 1px solid var(--red-light);
  border-radius: var(--radius);
  background: var(--red-pale);
  font-size: 0.92rem;
  align-items: flex-start;
  line-height: 1.55;
}

.mistake-list li::before {
  content: '✗';
  color: var(--red);
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 0.05rem;
}

.mistake-list li strong {
  color: var(--red);
}

/* ─── Wide figure ─── */
.figure {
  margin: 2rem 0;
}

.figure-caption {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.6rem;
  font-style: italic;
}

/* ─── Inline math / formula ─── */
.math {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88em;
  background: var(--bg-code);
  padding: 0.2em 0.5em;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

/* ─── Process flow ─── */
.process-flow {
  display: flex;
  align-items: flex-start;
  gap: 0;
  flex-wrap: wrap;
  margin: 1.5rem 0;
}

.process-step {
  flex: 1;
  min-width: 120px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  text-align: center;
  position: relative;
}

.process-step + .process-step::before {
  content: '→';
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.1rem;
}

.process-step .ps-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-faint);
  margin-bottom: 0.3rem;
}

.process-step .ps-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.process-step .ps-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* ─── Hover-reveal answer ─── */
.spoiler {
  background: var(--text-primary);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.4em;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s, color 0.2s;
  display: inline;
}

.spoiler:hover, .spoiler.revealed {
  background: var(--green-pale);
  color: var(--text-primary);
}

/* ─── Responsive ─── */
@media (max-width: 600px) {
  .plddt-guide { grid-template-columns: 1fr 1fr; }
  .structure-levels { grid-template-columns: 1fr 1fr; }
  .process-flow { flex-direction: column; }
  .process-step + .process-step::before { content: '↓'; left: 50%; top: -14px; transform: translateX(-50%); }
  .tool-grid { grid-template-columns: 1fr; }
  .stat-cards { flex-direction: column; }
  .term::after { width: 220px; }
}
