/*
 * Styles for ChemViz interactive visualizations.
 * Reuses the site palette from style.css (--navy, --blue, --ink, --muted, --line, --bg).
 */

/* ---------------------------------------------------------------- *
 * Shared widget shell
 * ---------------------------------------------------------------- */

.chem-widget {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  margin: 28px 0;
  box-shadow: 0 4px 18px rgba(11, 31, 51, .07);
}

/* Placeholder before JS runs (and the <noscript> fallback) shouldn't look broken. */
.chem-widget:not([data-chem-widget-initialized]) { color: var(--muted); font-size: 15px; }

.chem-widget__header { margin-bottom: 16px; }
.chem-widget__header h4 {
  margin: 0 0 4px;
  font-size: 19px;
  color: var(--navy);
}
.chem-widget__header p {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.chem-widget__visual {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: center;
}

.chem-widget__controls { margin-top: 20px; }

.chem-widget__control { margin-bottom: 14px; }
.chem-widget__control:last-child { margin-bottom: 0; }

.chem-titration__slider-label,
.chem-widget__control label {
  display: block;
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--navy);
}

.chem-widget__control-value {
  font-weight: 400;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chem-widget__slider {
  display: block;
  width: 100%;
  margin: 0;
  /* Comfortable touch target around the native track. */
  height: 32px;
  accent-color: var(--blue);
  cursor: pointer;
}
/* The titration widget stacks presets right under its single slider. */
.chem-titration .chem-widget__slider { margin-bottom: 14px; }

/* Match the site-wide focus treatment in style.css. */
.chem-widget__slider:focus-visible,
.chem-widget__btn:focus-visible {
  outline: 3px solid var(--blue-2);
  outline-offset: 2px;
}

.chem-widget__status {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.chem-widget__stat {
  flex: 1 1 130px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
}
.chem-widget__stat-key {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.chem-widget__stat-value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
  /* Keep the readout from reflowing as digits change while dragging. */
  font-variant-numeric: tabular-nums;
}

.chem-widget__explanation {
  margin: 14px 0 0;
  padding: 12px 14px;
  background: var(--bg);
  border-left: 3px solid var(--blue);
  border-radius: 0 8px 8px 0;
  font-size: 14.5px;
  /* Reserve height so committing a new explanation doesn't jump the layout. */
  min-height: 3.6em;
}

.chem-widget__btn {
  font: inherit;
  font-size: 14px;
  line-height: 1.2;
  background: var(--blue);
  color: #fff;
  border: 1px solid var(--blue);
  border-radius: 7px;
  padding: 9px 14px;
  min-height: 40px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.chem-widget__btn:hover { background: var(--blue-2); border-color: var(--blue-2); }

.chem-widget__btn--ghost {
  background: #fff;
  color: var(--blue);
}
.chem-widget__btn--ghost:hover { background: var(--bg); color: var(--blue-2); }

/* Shared SVG chart furniture. */
.chem-titration__grid,
.chem-reaction__grid { stroke: var(--line); stroke-width: 1; }
.chem-titration__axis,
.chem-reaction__axis { stroke: var(--muted); stroke-width: 1.5; }
.chem-titration__tick,
.chem-reaction__tick { fill: var(--muted); font-size: 1em; }
.chem-titration__axis-label,
.chem-reaction__axis-label { fill: var(--ink); font-size: 1em; font-weight: 600; }

/* ---------------------------------------------------------------- *
 * Titration widget
 * ---------------------------------------------------------------- */

.chem-titration__beaker-pane {
  flex: 0 1 150px;
  text-align: center;
}

.chem-titration__curve-pane {
  flex: 1 1 320px;
  min-width: 0; /* let the SVG shrink instead of forcing the row wider */
}

.chem-titration__beaker {
  width: 100%;
  max-width: 130px;
  height: auto;
}

.chem-titration__swatch-label {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.chem-titration__glass {
  fill: none;
  stroke: var(--muted);
  stroke-width: 2.5;
  stroke-linejoin: round;
}
.chem-titration__titrant { fill: #cfe0f0; }
.chem-titration__drop { fill: #9dc0dd; }

.chem-titration__curve {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  font-family: inherit;
}

.chem-titration__curve-line {
  fill: none;
  stroke: var(--blue);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chem-titration__equiv-line {
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}
.chem-titration__equiv-dot {
  fill: #fff;
  stroke: var(--navy);
  stroke-width: 2;
}
.chem-titration__equiv-label {
  fill: var(--navy);
  font-size: 1em;
  font-weight: 600;
}

.chem-titration__crosshair {
  stroke: var(--navy);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: .55;
}
.chem-titration__current-dot {
  stroke: var(--navy);
  stroke-width: 2.5;
}

.chem-titration__presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chem-titration__actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

/* ---------------------------------------------------------------- *
 * Reaction-energy widget
 * ---------------------------------------------------------------- */

.chem-reaction__diagram-pane {
  flex: 1 1 100%;
  min-width: 0;
}

.chem-reaction__diagram {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  font-family: inherit;
}

/* Reactant / product reference levels. */
.chem-reaction__level {
  stroke: var(--line);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}

.chem-reaction__curve {
  fill: none;
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chem-reaction__curve--active { stroke: var(--blue); }
/* Uncatalysed path: dashed as well as paler, so it reads without relying on colour. */
.chem-reaction__curve--plain {
  stroke: var(--muted);
  stroke-width: 2;
  stroke-dasharray: 6 5;
  opacity: .8;
}

.chem-reaction__arrow {
  stroke: var(--navy);
  stroke-width: 1.5;
}
.chem-reaction__arrow-head { fill: var(--navy); }
.chem-reaction__arrow--dh { stroke: var(--blue); }
.chem-reaction__arrow--dh-head { fill: var(--blue); }

.chem-reaction__measure {
  fill: var(--navy);
  font-size: 1em;
  font-weight: 700;
}
.chem-reaction__species {
  fill: var(--ink);
  font-size: 1em;
  font-weight: 600;
}

.chem-reaction__legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.chem-reaction__legend[hidden] { display: none; }
.chem-reaction__legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chem-reaction__key {
  display: inline-block;
  width: 26px;
  height: 0;
  border-top-width: 3px;
  border-top-style: solid;
}
.chem-reaction__key--active { border-top-color: var(--blue); }
.chem-reaction__key--plain {
  border-top-color: var(--muted);
  border-top-style: dashed;
}

.chem-reaction__actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

/* ---------------------------------------------------------------- *
 * Equilibrium widget
 * ---------------------------------------------------------------- */

.chem-equilibrium__stage {
  border-radius: 10px;
  overflow: hidden;
}

.chem-equilibrium__canvas {
  display: block;
  width: 100%;
  height: 260px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

.chem-equilibrium__legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.chem-equilibrium__legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
/* Size differs as well as colour, matching the particles themselves. */
.chem-equilibrium__key {
  display: inline-block;
  border-radius: 50%;
}
.chem-equilibrium__key--a {
  width: 16px; height: 16px;
  background: #dbe6f2;
  border: 1.5px solid #7d94ab;
}
.chem-equilibrium__key--b {
  width: 10px; height: 10px;
  background: #a8552a;
  border: 1.5px solid #7c3d1d;
}

.chem-equilibrium__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

/* ---------------------------------------------------------------- *
 * Gas-law widget
 * ---------------------------------------------------------------- */

.chem-gas__stage {
  display: flex;
  justify-content: center;
}

/* Tall and narrow: the piston needs vertical travel to be legible. */
.chem-gas__canvas {
  display: block;
  width: 100%;
  max-width: 300px;
  height: 300px;
  border-radius: 10px;
  background: var(--bg);
}

.chem-gas__actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

/* ---------------------------------------------------------------- *
 * Dilution widget
 * ---------------------------------------------------------------- */

.chem-dilution__diagram-pane {
  flex: 1 1 100%;
  min-width: 0;
}

.chem-dilution__diagram {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  font-family: inherit;
}

.chem-dilution__glass {
  fill: none;
  stroke: var(--muted);
  stroke-width: 2.5;
  stroke-linejoin: round;
}
.chem-dilution__liquid { fill: #d6e8f5; }
.chem-dilution__solute { fill: var(--blue); }

.chem-dilution__arrow { stroke: var(--muted); stroke-width: 2; }
.chem-dilution__arrow-head { fill: var(--muted); }

.chem-dilution__caption {
  fill: var(--navy);
  font-size: 1.15em;
  font-weight: 700;
}
.chem-dilution__sub { fill: var(--muted); font-size: 1em; }
.chem-dilution__note { fill: var(--ink); font-size: 1em; font-weight: 600; }

.chem-dilution__actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

/* ---------------------------------------------------------------- *
 * Narrow screens
 * ---------------------------------------------------------------- */

@media (max-width: 560px) {
  .chem-widget { padding: 16px; }
  .chem-widget__visual { gap: 14px; }
  .chem-titration__beaker-pane { flex: 1 1 100%; }
  .chem-titration__beaker { max-width: 96px; }
  .chem-titration__curve-pane { flex: 1 1 100%; }
  .chem-widget__stat { flex: 1 1 100%; }
  .chem-titration__presets .chem-widget__btn { flex: 1 1 auto; }
  .chem-equilibrium__canvas { height: 200px; }
  .chem-equilibrium__buttons .chem-widget__btn { flex: 1 1 auto; }
  .chem-gas__canvas { height: 260px; max-width: 220px; }
}
