/* ============================================================================
   Chemical Equation Balancer
   Prefix: ceb-   Accent: #1d4e6f (deep petrol) + copper #a3562a

   Layout intent: the equation input and the balanced result own the fold.
   Desktop puts input on the left, the result in the centre and the atom
   verification on the right; the working sits underneath. On a phone the
   order becomes input → result → verification → steps.
   ============================================================================ */

.ceb-page {
  --ceb-accent: #1d4e6f;
  --ceb-accent-deep: #143a53;
  --ceb-accent-soft: rgba(29, 78, 111, .08);
  --ceb-accent-line: rgba(29, 78, 111, .22);
  --ceb-copper: #a3562a;
  --ceb-copper-soft: rgba(163, 86, 42, .1);

  --ceb-bg: #eef1f3;
  --ceb-grad:
    radial-gradient(900px 460px at 6% -10%, rgba(29, 78, 111, .09), transparent 58%),
    radial-gradient(760px 400px at 100% 0%, rgba(163, 86, 42, .05), transparent 54%);

  --ceb-surface: #ffffff;
  --ceb-raised: #ffffff;
  --ceb-soft: #f4f7f8;
  --ceb-text: #141c22;
  --ceb-text-2: #56636c;
  --ceb-text-3: #83909a;
  --ceb-border: #dde4e8;
  --ceb-border-strong: #c2cdd4;

  --ceb-ok: #0f7b4f;
  --ceb-ok-soft: rgba(15, 123, 79, .09);
  --ceb-danger: #b42318;
  --ceb-danger-soft: rgba(180, 35, 24, .08);

  --ceb-r-lg: 18px;
  --ceb-r-md: 12px;
  --ceb-r-sm: 8px;
  --ceb-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --ceb-shadow: 0 1px 2px rgba(20, 28, 34, .05), 0 10px 28px rgba(20, 28, 34, .07);

  background: var(--ceb-bg) !important;
  background-image: var(--ceb-grad) !important;
  background-attachment: fixed !important;
  color: var(--ceb-text);
}

[data-theme="dark"] .ceb-page {
  --ceb-accent: #5cc8f5;
  --ceb-accent-deep: #91ddfa;
  --ceb-accent-soft: rgba(92, 200, 245, .12);
  --ceb-accent-line: rgba(92, 200, 245, .28);
  --ceb-copper: #e8a34a;
  --ceb-copper-soft: rgba(232, 163, 74, .12);

  --ceb-bg: #0d1418;
  --ceb-grad:
    radial-gradient(900px 460px at 6% -10%, rgba(92, 200, 245, .09), transparent 58%),
    radial-gradient(760px 400px at 100% 0%, rgba(232, 163, 74, .05), transparent 54%);

  --ceb-surface: #15202699;
  --ceb-surface: #152026;
  --ceb-raised: #1b272e;
  --ceb-soft: #19242a;
  --ceb-text: #e7f0f4;
  --ceb-text-2: #a3b3bc;
  --ceb-text-3: #82929c;
  --ceb-border: #2a3940;
  --ceb-border-strong: #3d4f58;

  --ceb-ok: #6ee7b7;
  --ceb-ok-soft: rgba(110, 231, 183, .1);
  --ceb-danger: #fca5a5;
  --ceb-danger-soft: rgba(252, 165, 165, .1);
  --ceb-shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 14px 34px rgba(0, 0, 0, .5);
}

.ceb-page .breadcrumb,
.ceb-page .breadcrumb a { color: var(--ceb-text-2); }

/* ------------------------------------------------------------------ hero */
.ceb-hero {
  position: relative; overflow: hidden;
  border: 1px solid var(--ceb-border); border-radius: var(--ceb-r-lg);
  background: linear-gradient(180deg, var(--ceb-surface), var(--ceb-soft));
  box-shadow: var(--ceb-shadow);
  padding: 1.15rem 1.25rem 1.25rem; margin-bottom: 1rem;
}
.ceb-hero::before {
  content: ""; position: absolute; inset: 0 auto auto 0; width: 100%; height: 3px;
  background: linear-gradient(90deg, var(--ceb-accent), var(--ceb-copper));
}
.ceb-eyebrow {
  display: inline-flex; align-items: center; gap: .45rem; margin: 0;
  font-size: .74rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ceb-accent); background: var(--ceb-accent-soft);
  border: 1px solid var(--ceb-accent-line); border-radius: 999px; padding: .3rem .75rem;
}
.ceb-hero h1 {
  font-size: clamp(1.6rem, 1rem + 2.2vw, 2.5rem); line-height: 1.12;
  margin: .7rem 0 .45rem; letter-spacing: -.02em; font-weight: 900;
  color: var(--ceb-text); text-wrap: balance;
}
.ceb-hero h1 em { font-style: normal; color: var(--ceb-accent); }
.ceb-hero-sub { color: var(--ceb-text-2); font-size: 1.02rem; max-width: 68ch; margin: 0; line-height: 1.6; }
.ceb-trust { display: flex; flex-wrap: wrap; gap: .4rem; margin: .9rem 0 0; padding: 0; list-style: none; }
.ceb-trust li {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .78rem; font-weight: 700; color: var(--ceb-text-2);
  background: var(--ceb-surface); border: 1px solid var(--ceb-border);
  border-radius: 999px; padding: .32rem .7rem;
}
.ceb-trust li::before { content: "\2713"; color: var(--ceb-accent); font-weight: 900; }

/* ------------------------------------------------------------ workspace */
.ceb-bench {
  display: grid; gap: 1rem; align-items: start;
  grid-template-columns: minmax(0, 360px) minmax(0, 1fr) minmax(0, 300px);
  margin-bottom: 1rem;
}
.ceb-card {
  background: var(--ceb-surface); border: 1px solid var(--ceb-border);
  border-radius: var(--ceb-r-md); box-shadow: var(--ceb-shadow); overflow: hidden;
}
.ceb-card-head {
  display: flex; align-items: center; gap: .5rem;
  padding: .65rem .85rem; border-bottom: 1px solid var(--ceb-border); background: var(--ceb-soft);
}
.ceb-card-head h2 {
  margin: 0; font-size: .78rem; font-weight: 800; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ceb-text-2);
}
.ceb-spacer { flex: 1 1 auto; }
.ceb-card-body { padding: .95rem; }

/* ---------------------------------------------------------------- input */
.ceb-field > label {
  display: block; margin-bottom: .35rem;
  font-size: .74rem; font-weight: 800; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ceb-text-2);
}
.ceb-page #cebInput {
  width: 100%; box-sizing: border-box;
  font-family: var(--ceb-mono); font-size: 1.05rem; font-weight: 600;
  min-height: 62px; padding: .7rem .8rem; resize: vertical; line-height: 1.5;
  color: var(--ceb-text); background: var(--ceb-raised);
  border: 1px solid var(--ceb-border-strong); border-radius: var(--ceb-r-sm);
}
.ceb-page #cebInput:focus-visible { outline: 3px solid var(--ceb-accent); outline-offset: 1px; }
.ceb-page #cebInput[aria-invalid="true"] { border-color: var(--ceb-danger); }
.ceb-hint { margin: .35rem 0 0; font-size: .74rem; color: var(--ceb-text-3); line-height: 1.5; }

.ceb-btnrow { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .8rem; }
.ceb-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 40px; padding: .45rem .85rem; cursor: pointer;
  font: inherit; font-size: .84rem; font-weight: 750; line-height: 1;
  color: var(--ceb-text); background: var(--ceb-surface);
  border: 1px solid var(--ceb-border-strong); border-radius: var(--ceb-r-sm);
  transition: border-color .14s ease, background .14s ease, transform .14s ease;
}
.ceb-btn:hover { border-color: var(--ceb-accent); background: var(--ceb-accent-soft); }
.ceb-btn:active { transform: translateY(1px); }
.ceb-btn:focus-visible { outline: 3px solid var(--ceb-accent); outline-offset: 2px; }
.ceb-btn-primary {
  background: var(--ceb-accent); color: #fff; border-color: transparent;
  box-shadow: 0 6px 18px rgba(29, 78, 111, .24);
}
.ceb-btn-primary:hover { background: var(--ceb-accent-deep); border-color: transparent; }
[data-theme="dark"] .ceb-btn-primary { color: #07171f; }
.ceb-btn-sm { min-height: 32px; padding: .28rem .6rem; font-size: .77rem; }

.ceb-examples { display: flex; flex-wrap: wrap; gap: .32rem; }
.ceb-examples .ceb-btn-sm { font-family: var(--ceb-mono); }

/* ---------------------------------------------------------- result card */
.ceb-status {
  display: flex; align-items: center; gap: .45rem;
  font-size: .82rem; font-weight: 800;
  padding: .5rem .7rem; border-radius: var(--ceb-r-sm); margin-bottom: .75rem;
}
/* status is carried by an icon and wording as well as colour */
.ceb-status.is-ok { background: var(--ceb-ok-soft); color: var(--ceb-ok); border: 1px solid var(--ceb-ok); }
.ceb-status.is-error { background: var(--ceb-danger-soft); color: var(--ceb-danger); border: 1px solid var(--ceb-danger); }
.ceb-status[hidden] { display: none; }

.ceb-equation {
  font-family: var(--ceb-mono);
  font-size: clamp(1.15rem, .8rem + 1.6vw, 1.8rem); font-weight: 800;
  line-height: 1.5; color: var(--ceb-accent);
  padding: 1rem; border-radius: var(--ceb-r-md);
  background: linear-gradient(135deg, var(--ceb-accent-soft), var(--ceb-copper-soft));
  border: 1px solid var(--ceb-accent-line);
  overflow-x: auto; word-break: normal;
}
.ceb-equation.is-empty { color: var(--ceb-text-3); font-weight: 600; font-size: 1rem; }

.ceb-meta { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .7rem; }
.ceb-chip {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .76rem; font-weight: 700; color: var(--ceb-text-2);
  background: var(--ceb-soft); border: 1px solid var(--ceb-border);
  border-radius: 999px; padding: .28rem .65rem;
}
.ceb-chip b { color: var(--ceb-text); }

/* ---------------------------------------------------------- atom tables */
.ceb-tablewrap { overflow-x: auto; border: 1px solid var(--ceb-border); border-radius: var(--ceb-r-sm); }
.ceb-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.ceb-table th, .ceb-table td { padding: .42rem .45rem; text-align: right; border-bottom: 1px solid var(--ceb-border); }
/* the verification card is the narrowest column, so keep its marks compact */
.ceb-verify .ceb-table { font-size: .8rem; }
.ceb-verify .ceb-table td.ceb-mark { white-space: nowrap; }
.ceb-table th:first-child, .ceb-table td:first-child { text-align: left; }
.ceb-table thead th {
  background: var(--ceb-soft); font-size: .68rem; font-weight: 900;
  text-transform: uppercase; letter-spacing: .05em; color: var(--ceb-text-2); white-space: nowrap;
}
.ceb-table td { font-family: var(--ceb-mono); color: var(--ceb-text-2); }
.ceb-table tbody th { font-weight: 800; color: var(--ceb-text); font-family: var(--ceb-mono); }
.ceb-table tr:last-child td, .ceb-table tr:last-child th { border-bottom: 0; }
/* a mismatched row is marked with text as well as colour */
.ceb-table tr.is-bad td, .ceb-table tr.is-bad th { background: var(--ceb-danger-soft); color: var(--ceb-danger); }
.ceb-table tr.is-good td.ceb-mark { color: var(--ceb-ok); font-weight: 800; }
.ceb-table tr.is-bad td.ceb-mark { color: var(--ceb-danger); font-weight: 800; }

.ceb-subhead {
  margin: .9rem 0 .4rem; font-size: .7rem; font-weight: 900;
  letter-spacing: .06em; text-transform: uppercase; color: var(--ceb-text-3);
}
.ceb-subhead:first-child { margin-top: 0; }

/* ---------------------------------------------------------------- steps */
.ceb-steps { display: grid; gap: .5rem; margin: 0; padding: 0; list-style: none; counter-reset: cebstep; }
.ceb-steps li {
  counter-increment: cebstep; position: relative;
  border: 1px solid var(--ceb-border); border-radius: var(--ceb-r-sm);
  background: var(--ceb-soft); padding: .65rem .8rem .65rem 2.4rem;
  font-size: .87rem; color: var(--ceb-text-2); line-height: 1.55;
}
.ceb-steps li::before {
  content: counter(cebstep); position: absolute; left: .7rem; top: .68rem;
  width: 19px; height: 19px; border-radius: 5px; display: grid; place-items: center;
  font-size: .68rem; font-weight: 900;
  background: var(--ceb-accent-soft); color: var(--ceb-accent); border: 1px solid var(--ceb-accent-line);
}
.ceb-steps b { display: block; color: var(--ceb-text); margin-bottom: .15rem; }
.ceb-mathline { font-family: var(--ceb-mono); font-size: .86rem; color: var(--ceb-text); }

.ceb-math { display: grid; gap: .4rem; }
.ceb-math .ceb-mathline {
  padding: .45rem .6rem; border-radius: var(--ceb-r-sm);
  background: var(--ceb-soft); border: 1px solid var(--ceb-border);
  overflow-x: auto;
}
.ceb-math dt { font-size: .72rem; font-weight: 800; text-transform: uppercase; color: var(--ceb-text-3); }

/* -------------------------------------------------------------- history */
.ceb-history { display: grid; gap: .3rem; margin: 0; padding: 0; list-style: none; }
.ceb-history li { display: flex; align-items: center; gap: .4rem; }
.ceb-history button.ceb-recall {
  flex: 1 1 auto; text-align: left; min-height: 34px; padding: .3rem .55rem;
  font-family: var(--ceb-mono); font-size: .8rem; font-weight: 600;
  color: var(--ceb-text); background: var(--ceb-soft);
  border: 1px solid var(--ceb-border); border-radius: var(--ceb-r-sm); cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ceb-history button.ceb-recall:hover { border-color: var(--ceb-accent); }
.ceb-history button.ceb-del {
  flex: 0 0 auto; width: 30px; height: 30px; cursor: pointer;
  color: var(--ceb-text-3); background: transparent;
  border: 1px solid var(--ceb-border); border-radius: var(--ceb-r-sm);
  font: inherit; font-size: .9rem; line-height: 1;
}
.ceb-history button.ceb-del:hover { color: var(--ceb-danger); border-color: var(--ceb-danger); }
.ceb-history button:focus-visible { outline: 3px solid var(--ceb-accent); outline-offset: 2px; }

/* ----------------------------------------------------------------- misc */
.ceb-note {
  border: 1px solid var(--ceb-border); border-left: 3px solid var(--ceb-copper);
  border-radius: var(--ceb-r-sm); background: var(--ceb-soft);
  padding: .7rem .9rem; font-size: .84rem; color: var(--ceb-text-2); line-height: 1.6;
}
.ceb-sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.ceb-block { margin-top: 1.5rem; }
.ceb-block > h2 {
  margin: 0 0 .7rem; font-size: clamp(1.15rem, 2.3vw, 1.4rem);
  font-weight: 900; letter-spacing: -.015em; color: var(--ceb-text);
}
.ceb-formula { font-family: var(--ceb-mono); }

/* ----------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .ceb-bench { grid-template-columns: minmax(0, 340px) minmax(0, 1fr); }
  .ceb-bench > .ceb-verify { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  /* phone order: input, result, verification, steps */
  .ceb-bench { grid-template-columns: minmax(0, 1fr); }
  .ceb-bench > .ceb-verify { grid-column: auto; }
  .ceb-hero { padding: 1rem .9rem 1.05rem; }
  .ceb-btnrow .ceb-btn { flex: 1 1 calc(50% - .3rem); }
}
@media (prefers-reduced-motion: reduce) {
  .ceb-btn { transition: none; }
}
@media print {
  .ceb-btnrow, .ceb-examples, .site-header, .site-footer, .ceb-historywrap { display: none !important; }
  .ceb-page { background: #fff !important; }
  .ceb-card { box-shadow: none; break-inside: avoid; }
}
