/* ==========================================================================
   Chemical Equation Balancer
   Editorial dossier, equation input, balanced-equation hero, species and
   ledger tables, stoichiometry, Pro steps / limiting reagent / solution
   mode / printable worksheet.
   ========================================================================== */

/* ---- Editorial ---------------------------------------------------------- */
.ceb-ed { display: grid; grid-template-columns: 104px 1fr; gap: 1.5rem; align-items: start; }
.ceb-ed-art { display: flex; flex-direction: column; align-items: center; color: var(--cluster-dark, #114F8D); }
.ceb-ed-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.6rem; letter-spacing: 0.14em; text-transform: uppercase;
  margin-top: 0.6rem; opacity: 0.65; border: 1px solid currentColor;
  padding: 0.15rem 0.45rem; border-radius: 2px;
}
.ceb-ed-head { display: flex; align-items: baseline; gap: 0.7rem; flex-wrap: wrap; margin-bottom: 0.55rem; }
.ceb-ed-head h2 { font-weight: 600; letter-spacing: -0.01em; }
.ceb-ed-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.65rem; letter-spacing: 0.2em; text-transform: uppercase;
  padding: 0.22rem 0.6rem; background: var(--cluster-dark, #114F8D); color: var(--cluster-on-dark); border-radius: 2px;
}
.ceb-ed p { margin: 0 0 0.7rem 0; }
.ceb-ed-meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.55rem 1.4rem; padding-top: 0.8rem; font-size: 0.78rem;
  border-top: 1px dashed color-mix(in srgb, var(--cluster-dark, #114F8D) 35%, transparent);
}
.ceb-ed-meta span {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.6rem; letter-spacing: 0.14em; text-transform: uppercase;
  opacity: 0.6; display: block; margin-bottom: 0.1rem;
}
@media (max-width: 575.98px) {
  .ceb-ed { grid-template-columns: 1fr; gap: 1rem; }
  .ceb-ed-art { flex-direction: row; gap: 0.8rem; align-items: center; }
  .ceb-ed-code { margin-top: 0; }
}

/* ---- Input -------------------------------------------------------------- */
.ceb-eq-row { display: flex; gap: 0.6rem; align-items: stretch; }
.ceb-eq-wrap { flex: 1; min-width: 0; }
.ceb-eq-input { font-size: 1.05rem !important; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.ceb-go-btn {
  border: 0; border-radius: var(--evvy-radius-lg, 12px); white-space: nowrap;
  background: var(--cluster-dark, #114F8D); color: var(--cluster-on-dark);
  padding: 0 1.3rem; font-weight: 700; font-size: 0.92rem; cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}
.ceb-go-btn:hover { background: var(--cluster-hover, #0D3D6B); transform: translateY(-1px); }
@media (max-width: 575.98px) {
  .ceb-eq-row { flex-direction: column; }
  .ceb-go-btn { padding: 0.7rem 1.3rem; }
}
.ceb-samples { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.7rem; align-items: center; }
.ceb-samples-label {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--evvy-text-secondary, #6C757D);
}
.ceb-sample {
  border: 1px solid var(--evvy-border-color, #DEE2E6); background: transparent;
  border-radius: 999px; padding: 0.22rem 0.7rem; font-size: 0.76rem; cursor: pointer;
  color: var(--evvy-text-secondary, #6C757D);
}
.ceb-sample:hover { border-color: var(--cluster-dark, #114F8D); color: var(--cluster-dark, #114F8D); }
.ceb-syntax { font-size: 0.76rem; color: var(--evvy-text-secondary, #6C757D); margin-top: 0.6rem; line-height: 1.7; }
.ceb-syntax code { font-size: 0.74rem; padding: 0.05rem 0.3rem; border-radius: 4px; background: var(--cluster-surface, #EAF0F7); color: inherit; }
[data-bs-theme="dark"] .ceb-syntax code { background: var(--evvy-gray-100, #1E1E1E); }

.ceb-error {
  display: flex; gap: 0.6rem; align-items: flex-start; margin-top: 1rem;
  padding: 0.8rem 1rem; border-radius: var(--evvy-radius-lg, 12px); font-size: 0.9rem; line-height: 1.55;
  background: color-mix(in srgb, #C0392B 10%, transparent); color: #A93226;
}
.ceb-error[hidden] { display: none; }
[data-bs-theme="dark"] .ceb-error { color: #F1948A; }

/* ---- Results ------------------------------------------------------------ */
.ceb-results { display: none; }
.ceb-results.show { display: block; }
.ceb-eq-out {
  font-family: Georgia, 'Times New Roman', serif; font-size: 1.55rem !important; line-height: 1.5;
  overflow-wrap: anywhere; font-weight: 500;
}
.ceb-eq-out sub, .ceb-eq-out sup { font-size: 0.62em; }
.ceb-coef { font-weight: 800; color: var(--cluster-dark, #114F8D); margin-right: 0.12em; }
.ceb-term { white-space: nowrap; }
.ceb-state { font-size: 0.55em; color: var(--evvy-text-secondary, #6C757D); margin-left: 0.1em; }
.ceb-arrow { margin: 0 0.25em; }
.ceb-plus { margin: 0 0.1em; opacity: 0.7; }
.ceb-hero-sub { font-size: 0.84rem; line-height: 1.55; margin-top: 0.5rem; color: var(--evvy-text-secondary, #6C757D); }
.ceb-result-note { font-size: 0.74rem; line-height: 1.4; margin-top: 0.35rem; color: var(--evvy-text-secondary, #6C757D); overflow-wrap: anywhere; }
.ceb-row-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 991.98px) { .ceb-row-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 575.98px) {
  .ceb-row-4 { grid-template-columns: 1fr; }
  .ceb-eq-out { font-size: 1.2rem !important; }
}

.ceb-multi, .ceb-notes {
  border-radius: var(--evvy-radius-lg, 12px); padding: 0.8rem 1rem; margin-bottom: 1rem; font-size: 0.88rem; line-height: 1.55;
}
.ceb-multi { border: 1px solid #B9770E; background: color-mix(in srgb, #B9770E 9%, transparent); }
.ceb-notes { background: var(--cluster-surface, #EAF0F7); }
[data-bs-theme="dark"] .ceb-notes { background: var(--evvy-gray-100, #1E1E1E); }
.ceb-multi[hidden], .ceb-notes[hidden] { display: none; }
.ceb-indep { margin: 0.3rem 0 0; padding-left: 1.3rem; font-family: Georgia, serif; }

.ceb-duo { display: grid; grid-template-columns: 3fr 2fr; gap: 1rem; margin-top: 1.25rem; }
@media (max-width: 767.98px) { .ceb-duo { grid-template-columns: 1fr; } }
.ceb-panel {
  border: 1px solid var(--evvy-border-color, #DEE2E6); border-radius: var(--evvy-radius-lg, 12px);
  padding: 1.1rem 1.2rem; background: var(--bs-body-bg, #fff); margin-top: 1.25rem; min-width: 0;
}
.ceb-duo .ceb-panel { margin-top: 0; }
[data-bs-theme="dark"] .ceb-panel { background: var(--evvy-gray-100, #1E1E1E); }
.ceb-callout { border-left: 4px solid var(--cluster-dark, #114F8D); }
.ceb-panel-title {
  font-weight: 700; font-size: 0.95rem; margin-bottom: 0.8rem;
  display: flex; align-items: center; gap: 0.45rem; color: var(--cluster-dark, #114F8D);
}
.ceb-muted { font-size: 0.8rem; color: var(--evvy-text-secondary, #6C757D); line-height: 1.55; }
.ceb-ok { color: #2E7D32; }
.ceb-bad { color: #C62828 !important; }
[data-bs-theme="dark"] .ceb-ok { color: #81C784; }
[data-bs-theme="dark"] .ceb-bad { color: #FF8A80 !important; }

/* ---- Tables ------------------------------------------------------------- */
.ceb-scroll { overflow-x: auto; }
.ceb-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.ceb-table th {
  text-align: left; font-size: 0.66rem; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--evvy-text-secondary, #6C757D); font-weight: 700; white-space: nowrap;
  padding: 0.4rem 0.7rem 0.4rem 0; border-bottom: 1px solid var(--evvy-border-color, #DEE2E6);
}
.ceb-table td {
  padding: 0.5rem 0.7rem 0.5rem 0; vertical-align: middle;
  border-bottom: 1px solid color-mix(in srgb, var(--evvy-border-color, #DEE2E6) 55%, transparent);
}
.ceb-table tr:last-child td { border-bottom: 0; }
.ceb-num { text-align: right !important; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ceb-f { font-family: Georgia, 'Times New Roman', serif; font-size: 1rem; white-space: nowrap; }
.ceb-known-row td { background: color-mix(in srgb, var(--cluster-dark, #114F8D) 7%, transparent); }

/* ---- Stoichiometry ------------------------------------------------------ */
.ceb-stoich-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.ceb-yield-grid { display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 1rem; align-items: end; }
.ceb-unit { max-width: 5.5rem; flex: 0 0 auto; }
.ceb-yield-out { min-height: 2.4rem; }
.ceb-yield-pct { font-size: 1.6rem; font-weight: 800; color: var(--cluster-dark, #114F8D); line-height: 1.1; }
@media (max-width: 575.98px) {
  .ceb-stoich-grid, .ceb-yield-grid { grid-template-columns: 1fr; }
}

/* ---- Pro: steps --------------------------------------------------------- */
.ceb-step { display: grid; grid-template-columns: 1.8rem 1fr; gap: 0.7rem; padding: 0.6rem 0; font-size: 0.9rem; line-height: 1.65;
  border-bottom: 1px dashed var(--evvy-border-color, #DEE2E6); min-width: 0; }
.ceb-step > div { min-width: 0; }
.ceb-step:last-child { border-bottom: 0; }
.ceb-step-n {
  width: 1.6rem; height: 1.6rem; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 800; background: var(--cluster-dark, #114F8D); color: var(--cluster-on-dark);
}
.ceb-eqs { margin: 0.3rem 0 0; padding-left: 1.1rem; font-family: Georgia, serif; }
.ceb-eq-lab {
  display: inline-block; min-width: 3.6rem; font-family: ui-monospace, monospace; font-size: 0.75rem; font-weight: 700;
  color: var(--cluster-dark, #114F8D);
}
.ceb-matrix { border-collapse: collapse; margin: 0.5rem 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem; }
.ceb-matrix th { font-weight: 700; color: var(--evvy-text-secondary, #6C757D); padding: 0.2rem 0.55rem; text-align: center; font-family: Georgia, serif; }
.ceb-matrix tbody th { text-align: right; }
.ceb-matrix td { padding: 0.2rem 0.55rem; text-align: right; border-left: 1px solid var(--evvy-border-color, #DEE2E6); white-space: nowrap; }
.ceb-ops { font-family: ui-monospace, monospace; font-size: 0.74rem; color: var(--evvy-text-secondary, #6C757D); margin: 0.3rem 0 0.5rem; line-height: 1.8; }

/* ---- Pro: limiting / solution ------------------------------------------- */
.ceb-lim-inputs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.7rem 1rem; }
.ceb-lim-row { display: grid; grid-template-columns: 5.5rem 1fr; gap: 0.5rem; align-items: center; }
.ceb-lim-row .input-group { flex-wrap: nowrap; }
.ceb-lim-verdict {
  padding: 0.6rem 0.8rem; border-radius: 10px; margin-bottom: 0.6rem; font-size: 0.9rem;
  background: color-mix(in srgb, var(--cluster-dark, #114F8D) 7%, transparent);
}
.ceb-sol-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8rem 1rem; align-items: end; }
.ceb-sol-out { grid-column: span 1; }
.ceb-sol-big { font-size: 1.6rem; font-weight: 800; color: var(--cluster-dark, #114F8D); line-height: 1.1; }
@media (max-width: 767.98px) { .ceb-sol-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 575.98px) { .ceb-sol-grid { grid-template-columns: 1fr; } }

.ceb-outline-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  border: 1px solid var(--cluster-dark, #114F8D); background: transparent;
  color: var(--cluster-dark, #114F8D); border-radius: 999px;
  padding: 0.35rem 0.95rem; font-size: 0.82rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.ceb-outline-btn:hover { background: var(--cluster-dark, #114F8D); color: var(--cluster-on-dark); }

/* ---- Print worksheet ---------------------------------------------------- */
.ceb-print-area { display: none; }
@media print {
  /* the area is reparented to <body> before printing so every sibling can be hidden */
  body.ceb-printing > *:not(.ceb-print-area) { display: none !important; }
  body.ceb-printing .ceb-print-area { display: block !important; color: #000; }
  .ceb-sheet h1 { font-size: 16pt; margin: 0 0 8pt; }
  .ceb-sheet-i { font-size: 10pt; font-style: italic; }
  .ceb-sheet ol { font-size: 13pt; line-height: 2.4; font-family: Georgia, serif; }
  .ceb-sheet-break { break-after: page; }
  .ceb-sheet-f { font-size: 8pt; color: #555; margin-top: 12pt; }
}
