/* ==========================================================================
   Word-Embedding article — page-scoped styles
   ==========================================================================
   Scoped to the interactive training simulator in §4.6. All rules are
   prefixed with .ed-* to avoid colliding with the site-wide style.css.
   ========================================================================== */

.ed-wrap {
  border: 1px solid #dddddd;
  border-radius: 20px;
  padding: 20px;
  margin: 24px 0 32px 0;
  background: #fafbff;
  box-shadow: rgba(149, 157, 165, 0.18) 0px 8px 24px;
}

.ed-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px 24px;
  margin-bottom: 16px;
  align-items: end;
}

.ed-controls label {
  display: block;
  font-size: var(--fs-s, 13px);
  color: #1d1f28;
  margin-bottom: 4px;
  font-weight: 500;
}

.ed-controls input[type="range"] {
  width: 100%;
  accent-color: #6471E9;
}

.ed-controls select {
  width: 100%;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #dddddd;
  background: #ffffff;
  font-size: var(--fs-s, 13px);
  color: #1d1f28;
}

.ed-controls .ed-val {
  color: #6471E9;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

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

.ed-btn {
  flex: 1 0 auto;
  min-width: 64px;
  padding: 6px 14px;
  border: 1px solid #dddddd;
  background: #ffffff;
  border-radius: 8px;
  font-size: var(--fs-s, 13px);
  color: #1d1f28;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.ed-btn:hover { border-color: #6471E9; color: #6471E9; }
.ed-btn-playing { background: #6471E9; color: #ffffff; border-color: #6471E9; }
.ed-btn-playing:hover { color: #ffffff; }

.ed-viz {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
}

@media (max-width: 767px) {
  .ed-viz { grid-template-columns: 1fr; }
}

.ed-scatter-wrap,
.ed-metrics-wrap {
  background: #fafbff;
  border: 1px solid #dddddd;
  border-radius: 12px;
  padding: 8px;
}

.ed-scatter-wrap canvas { width: 100%; height: 420px; display: block; }
.ed-metrics-wrap canvas { width: 100%; height: 240px; display: block; }

.ed-readout {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 16px;
  margin-top: 12px;
  font-size: var(--fs-s, 13px);
}

.ed-readout .ed-k { color: rgba(29, 31, 40, 0.7); }

.ed-readout .ed-v {
  color: #1d1f28;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Side-by-side image pair inside a <figure>.
   Two columns on desktop, single column on mobile (767px breakpoint matches
   the rest of the page). Use via:
     <figure>
       <div class="fig-pair"> <img ...> <img ...> </div>
       <figcaption>…</figcaption>
     </figure>
*/
.fig-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}

.fig-pair img { width: 100%; height: auto; display: block; }

@media (max-width: 767px) {
  .fig-pair { grid-template-columns: 1fr; }
}


/* ==========================================================================
   Cosine-comparison table used in §4.9 (and reusable elsewhere).
   Apple-ish: rounded corners, soft shadow, subtle row separators,
   tabular-nums numerics, colored delta column for at-a-glance reading.
   ========================================================================== */
table.cosine-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 24px 0;
  border: 1px solid #dddddd;
  border-radius: 14px;
  overflow: hidden;
  background: #fafbff;
  box-shadow: rgba(149, 157, 165, 0.12) 0px 4px 16px;
  font-size: var(--fs-s, 14px);
  color: #1d1f28;
}

table.cosine-table thead th {
  background: #eef0f8;
  color: #1d1f28;
  font-weight: 600;
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid #dddddd;
  letter-spacing: 0.01em;
}

table.cosine-table tbody td {
  padding: 10px 16px;
  border-bottom: 1px solid #ececf3;
  vertical-align: middle;
}

table.cosine-table tbody tr:last-child td { border-bottom: none; }

/* Section header row inside the table (e.g. "similar pairs"). */
table.cosine-table tbody tr.section-row td {
  background: #f4f5fb;
  color: #766C82;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 10px 16px;
  border-top: 1px solid #dddddd;
  border-bottom: 1px solid #dddddd;
}

table.cosine-table .pair {
  font-weight: 500;
}

table.cosine-table .pair-a,
table.cosine-table .pair-b {
  font-weight: 600;
}

table.cosine-table .pair-sep {
  color: rgba(29, 31, 40, 0.4);
  margin: 0 2px;
}

table.cosine-table th.num,
table.cosine-table td.num {
  text-align: right;
  font-family: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

table.cosine-table .delta {
  font-weight: 600;
}

/* Visual signal columns: green for "this is the direction we want",
   red for the opposite, soft grey for ~flat. The mapping from sign to
   color depends on whether the pair is in a similar or unrelated row, so
   the section author picks .delta-good / .delta-bad / .delta-flat
   explicitly in the markup. */
table.cosine-table .delta-good { color: #2E9D5F; }
table.cosine-table .delta-bad  { color: #C2533F; }
table.cosine-table .delta-flat { color: rgba(29, 31, 40, 0.5); }

table.cosine-table .note {
  color: rgba(29, 31, 40, 0.6);
  font-size: 13px;
  font-style: italic;
}

@media (max-width: 600px) {
  table.cosine-table thead th,
  table.cosine-table tbody td { padding: 8px 10px; }
  table.cosine-table .note { display: none; }
}


/* ==========================================================================
   3D embedding viewer (§5.2). Three.js renders into the canvas; the
   tooltip and legend are HTML overlays positioned absolutely inside the
   container so they stay aligned with the canvas regardless of layout.
   ========================================================================== */
.ed3d-wrap {
  position: relative;
  width: 100%;
  height: 540px;
  border: 1px solid #dddddd;
  border-radius: 16px;
  background: #fafbff;
  box-shadow: rgba(149, 157, 165, 0.16) 0px 6px 18px;
  overflow: hidden;
  margin: 24px 0;
  cursor: grab;
}
.ed3d-wrap:active { cursor: grabbing; }

.ed3d-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Hover tooltip. Positioned by JS in container-relative coordinates. */
.ed3d-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(29, 31, 40, 0.92);
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  z-index: 5;
  box-shadow: rgba(0, 0, 0, 0.18) 0px 2px 8px;
}

/* Category legend, top-right of the viewer. */
.ed3d-legend {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(250, 251, 255, 0.94);
  border: 1px solid #dddddd;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  color: #1d1f28;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  z-index: 4;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.ed3d-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ed3d-legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(29, 31, 40, 0.15);
}

.ed3d-legend-label {
  font-variant-numeric: tabular-nums;
}

/* The static PNG fallback inside the same figure. Hidden by JS once
   the viewer initialises; visible by default if the JS or Three.js
   fails to load. */
.ed3d-fallback {
  display: block;
  width: 100%;
  height: auto;
}

@media (max-width: 600px) {
  .ed3d-wrap   { height: 380px; }
  .ed3d-legend { font-size: 11px; padding: 6px 8px; top: 8px; right: 8px; }
}
