/* Gradient descent explainer. Site-wide tokens (--bg, --fg, --muted, --line,
   --soft, --surface, --grid) come from /assets/css/index.css; the series and
   landscape colors below are stepped separately for light and dark. */

.gd {
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --ink: var(--fg);
  --ink2: #52514e;
  --axis: #c3c2b7;
  --bad: #d03b3b;
  --bad-wash: rgba(208, 59, 59, 0.07);
  --heat-lo: #ffffff;
  --heat-mid: #dfe3e9;
  --heat-hi: #8a94a3;
  --contour: rgba(40, 48, 60, 0.16);
  --halo: rgba(255, 255, 255, 0.9);
  --dot: #3d3d3a;
  max-width: 900px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .gd {
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --ink2: #c3c2b7;
    --axis: #4a4e55;
    --bad: #e66767;
    --bad-wash: rgba(230, 103, 103, 0.1);
    --heat-lo: #1b1d21;
    --heat-mid: #23262c;
    --heat-hi: #474e5b;
    --contour: rgba(220, 226, 235, 0.16);
    --halo: rgba(21, 23, 26, 0.85);
    --dot: #d6d6d2;
  }
}

:root[data-theme='dark'] .gd {
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --ink2: #c3c2b7;
  --axis: #4a4e55;
  --bad: #e66767;
  --bad-wash: rgba(230, 103, 103, 0.1);
  --heat-lo: #1b1d21;
  --heat-mid: #23262c;
  --heat-hi: #474e5b;
  --contour: rgba(220, 226, 235, 0.16);
  --halo: rgba(21, 23, 26, 0.85);
  --dot: #d6d6d2;
}

.gd h2 {
  font-family: 'Merriweather', serif;
  font-weight: 700;
  font-size: 1.15rem;
  margin: 52px 0 8px;
}

.gd h3 {
  font-size: 0.95rem;
  font-weight: 500;
  margin: 28px 0 6px;
}

.gd .intro,
.gd .hint,
.gd .try li {
  line-height: 1.6;
  font-weight: 300;
}

.gd .hint {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0 0 12px;
}

.gd a:not(.back) {
  color: var(--s1);
}

.gd select,
.gd input,
.gd button {
  font: inherit;
}

.gd .katex {
  font-size: 1.05em;
}

.k-tan {
  color: var(--s2);
  font-weight: 500;
}

.k-raw {
  color: var(--s2);
  font-weight: 500;
}

.k-std {
  color: var(--s1);
  font-weight: 500;
}

/* Hero ---------------------------------------------------------------------*/

.hero-eq {
  margin: 20px 0 8px;
  overflow-x: auto;
  overflow-y: hidden;
  font-size: 1.15rem;
}

.explain3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 8px;
}

.explain3 > div,
.opt-explain > div {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.55;
  font-weight: 300;
  color: var(--muted);
}

.explain3 b,
.opt-explain b {
  color: var(--ink);
  font-weight: 500;
}

/* Card + controls ----------------------------------------------------------*/

.card {
  margin: 4px 0 18px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px 22px;
  align-items: end;
}

.field,
.slider {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--muted);
}

.field select {
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.slider > span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.slider output {
  font-family: 'Roboto Mono', monospace;
  color: var(--ink);
}

.slider input[type='range'] {
  width: 100%;
  accent-color: var(--ink);
}

.slider.wide {
  margin-top: 12px;
}

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

.btn {
  padding: 6px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.btn:hover {
  border-color: var(--muted);
}

.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.fn-tex {
  margin: 12px 0 0;
  color: var(--ink);
}

.opt-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px 18px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.check {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  margin-top: 10px;
  font-size: 0.88rem;
  color: var(--muted);
}

.check input,
.toggles-legend input {
  accent-color: var(--ink);
}

/* Legends ------------------------------------------------------------------*/

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 6px 0;
  font-size: 0.88rem;
  color: var(--ink);
}

.legend label,
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend .sub {
  color: var(--muted);
}

.sw {
  display: inline-block;
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  vertical-align: -1px;
  margin-right: 6px;
}

.legend .sw {
  margin-right: 0;
}

.sw.s1 { background: var(--s1); }
.sw.s2 { background: var(--s2); }
.sw.s3 { background: var(--s3); }
.sw.s4 { background: var(--s4); }

.opt-explain {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 14px;
}

/* Charts -------------------------------------------------------------------*/

.chart {
  width: 100%;
  position: relative;
}

.chart svg {
  display: block;
  overflow: visible;
  font-family: 'Roboto', sans-serif;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.chart.map svg {
  margin: 0 auto;
}

.grid-line {
  stroke: var(--grid);
  shape-rendering: crispEdges;
}

.axis-line {
  stroke: var(--axis);
  shape-rendering: crispEdges;
}

.tick {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.axis-title {
  fill: var(--ink2);
  font-size: 11px;
  font-weight: 500;
}

.plot-border {
  fill: none;
  stroke: var(--line);
}

.curve {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linejoin: round;
}

.curve.soft {
  stroke: var(--muted);
  stroke-width: 1.5;
  opacity: 0.7;
}

.series {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.halo {
  fill: none;
  stroke: var(--halo);
  stroke-width: 5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.trail {
  fill: none;
  stroke: var(--s1);
  stroke-width: 1.5;
  opacity: 0.55;
}

.ball {
  fill: var(--s1);
  stroke: var(--surface);
  stroke-width: 2;
}

.ghost {
  fill: var(--s1);
  opacity: 0.35;
}

.tangent {
  stroke: var(--s2);
  stroke-width: 2;
  stroke-linecap: round;
}

.tangent-label {
  fill: var(--ink2);
  font-size: 11.5px;
}

.step-arrow {
  stroke: var(--ink);
  stroke-width: 1.5;
  fill: none;
}

.step-head {
  fill: var(--ink);
}

.step-label {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 500;
}

.drop {
  stroke: var(--muted);
  stroke-dasharray: 2 3;
}

.hover-line {
  stroke: var(--muted);
  stroke-dasharray: 3 3;
  shape-rendering: crispEdges;
}

.hover-dot {
  stroke: var(--surface);
  stroke-width: 2;
}

.hit {
  fill: transparent;
  cursor: crosshair;
}

.end-label {
  fill: var(--ink2);
  font-size: 11.5px;
}

.diverge-zone {
  fill: var(--bad-wash);
}

.diverge-label {
  fill: var(--bad);
  font-size: 11px;
  font-weight: 500;
}

.unit-line {
  stroke: var(--bad);
  stroke-dasharray: 4 3;
  opacity: 0.7;
}

.region-line {
  stroke: var(--line);
  stroke-dasharray: 2 3;
}

.region-label {
  fill: var(--muted);
  font-size: 11px;
}

.contour {
  fill: none;
  stroke: var(--contour);
  stroke-width: 1;
}

.field-arrow {
  stroke: var(--ink2);
  stroke-width: 1.2;
  stroke-linecap: round;
}

.field-head {
  fill: var(--ink2);
}

.cursor-arrow {
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linecap: round;
}

.cursor-head {
  fill: var(--ink);
}

.start-mark {
  fill: var(--surface);
  stroke: var(--ink);
  stroke-width: 2;
}

.min-mark {
  stroke: var(--ink2);
  stroke-width: 1.6;
  stroke-linecap: round;
}

.min-label {
  fill: var(--ink2);
  font-size: 10.5px;
}

.data-dot {
  fill: var(--dot);
  opacity: 0.6;
}

.data-dot:hover {
  opacity: 1;
}

.empty {
  fill: var(--muted);
  font-size: 13px;
}

/* Small multiples -----------------------------------------------------------*/

.sm-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.sm-grid figure {
  margin: 0;
  min-width: 0;
}

.sm-grid figcaption,
.map-pair figcaption {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--ink);
  margin-bottom: 4px;
}

.sm-grid figcaption .sub,
.map-pair figcaption .sub {
  color: var(--muted);
  font-weight: 300;
}

.sm-grid .verdict {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

.factor-grid {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 20px;
  align-items: start;
}

.map-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 16px;
}

.map-pair figure {
  margin: 0;
  min-width: 0;
}

.map-pair figcaption {
  flex-wrap: wrap;
}

/* Readouts ------------------------------------------------------------------*/

.readout {
  margin: 12px 0;
  padding: 12px 16px;
  background: var(--soft);
  border-radius: 8px;
  line-height: 1.6;
}

.readout p {
  margin: 0;
}

.readout p + p {
  margin-top: 4px;
}

.readout .eq {
  overflow-x: auto;
  overflow-y: hidden;
}

.readout .note {
  color: var(--muted);
  font-weight: 300;
}

.readout .bad {
  color: var(--bad);
  font-weight: 500;
}

.table-wrap {
  margin-top: 16px;
  overflow-x: auto;
}

.stats {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.stats th,
.stats td {
  padding: 6px 10px;
  text-align: right;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

.stats th:first-child,
.stats td:first-child {
  text-align: left;
}

.stats thead th {
  color: var(--muted);
  font-weight: 500;
}

.stats td {
  font-family: 'Roboto Mono', monospace;
  font-variant-numeric: tabular-nums;
}

.stats td:first-child {
  font-family: 'Roboto', sans-serif;
}

.stats .bad {
  color: var(--bad);
}

.tip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  padding: 7px 10px;
  background: rgba(30, 30, 30, 0.94);
  color: #fff;
  font-family: 'Roboto', sans-serif;
  font-size: 0.8rem;
  line-height: 1.5;
  border-radius: 6px;
  max-width: 280px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.tip .row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tip .sw {
  width: 9px;
  height: 9px;
  margin: 0;
  border-radius: 50%;
}

.tip b {
  font-weight: 500;
}

.tip .mono {
  font-family: 'Roboto Mono', monospace;
}

.try {
  padding-left: 20px;
}

.try li {
  margin-bottom: 10px;
}

@media (max-width: 760px) {
  .sm-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .explain3,
  .opt-explain,
  .factor-grid,
  .map-pair {
    grid-template-columns: 1fr;
  }
}
