/*
 * Arc Compass visual system: styles for lib/discovery-viz.js.
 *
 * Covers three renderers: the compass rose (.arc-viz-compass), the bearing
 * history line chart (.arc-viz-history), and the atlas constellation
 * (.arc-viz-atlas). Mobile-first: base rules already target a narrow phone;
 * min-width blocks only add room on larger screens, and one max-width block
 * tightens further for the smallest supported phones (320px).
 *
 * Tokens reuse styles/discovery.css's --compass-* custom properties (same
 * dark-by-default / html[data-theme="light"] override mechanism as the rest
 * of the Arc Compass surface) with literal fallbacks, so this file still
 * renders correctly and on-theme if it is ever the only stylesheet present.
 * New colors this file needs but discovery.css does not define (the loop
 * accent) are declared here, at the values already used inline elsewhere in
 * discovery.css, so nothing looks invented.
 *
 * Marks: 2px lines, >=8px markers, a surface-color ring on every marker, a
 * hairline recessive grid, never dashed. Confidence is never a percentage;
 * it is size, opacity, a soft halo, and plain words. Only opacity/transform
 * are animated, and the prefers-reduced-motion block at the bottom is the
 * single source of truth for turning all of it off.
 */

.arc-viz-root {
  --arc-viz-bg: var(--compass-bg, #0d0e10);
  --arc-viz-surface: var(--compass-surface, #17181b);
  --arc-viz-surface-raised: var(--compass-surface-raised, #202126);
  --arc-viz-ink: var(--compass-text, #f4f0e8);
  --arc-viz-muted: var(--compass-muted, #9d9b96);
  --arc-viz-faint: var(--compass-faint, #706f6b);
  --arc-viz-border: var(--compass-border, rgba(255, 255, 255, 0.1));
  --arc-viz-accent: var(--compass-accent, #e66f51);
  --arc-viz-accent-soft: var(--compass-accent-soft, rgba(230, 111, 81, 0.14));
  --arc-viz-loop: #9b8bf4;
  --arc-viz-shadow: var(--compass-shadow, 0 22px 70px rgba(0, 0, 0, 0.32));

  position: relative;
  color: var(--arc-viz-ink);
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

html[data-theme="light"] .arc-viz-root {
  --arc-viz-bg: var(--compass-bg, #f4f0e8);
  --arc-viz-surface: var(--compass-surface, rgba(255, 255, 255, 0.72));
  --arc-viz-surface-raised: var(--compass-surface-raised, #fffdf8);
  --arc-viz-ink: var(--compass-text, #24231f);
  --arc-viz-muted: var(--compass-muted, #6f6b63);
  --arc-viz-faint: var(--compass-faint, #98928a);
  --arc-viz-border: var(--compass-border, rgba(49, 45, 39, 0.13));
  --arc-viz-accent-soft: var(--compass-accent-soft, rgba(202, 80, 50, 0.11));
  --arc-viz-shadow: var(--compass-shadow, 0 22px 70px rgba(87, 72, 55, 0.12));
}

/* ---------------------------------------------------------------------- */
/* Shared: empty states                                                    */
/* ---------------------------------------------------------------------- */

.arc-viz-empty {
  margin: 0;
  padding: 20px 18px;
  border: 1px solid var(--arc-viz-border);
  border-radius: 17px;
  background: var(--arc-viz-surface);
  color: var(--arc-viz-muted);
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
}

/* ---------------------------------------------------------------------- */
/* Compass map                                                             */
/* ---------------------------------------------------------------------- */

.arc-viz-compass-figure {
  width: 100%;
  max-width: min(92vw, 380px);
  margin: 0 auto;
}

.arc-viz-compass-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  animation: arc-viz-enter 420ms ease both;
}

.arc-viz-ring {
  fill: none;
  stroke: var(--arc-viz-border);
  stroke-width: 1;
  opacity: 0.55;
}

.arc-viz-ring-mid {
  stroke-width: 1.25;
  opacity: 0.95;
}

.arc-viz-spoke {
  stroke: var(--arc-viz-border);
  stroke-width: 1;
  opacity: 0.8;
}

.arc-viz-compass-polygon {
  fill: color-mix(in srgb, var(--arc-viz-accent) 12%, transparent);
  stroke: color-mix(in srgb, var(--arc-viz-accent) 55%, var(--arc-viz-ink) 6%);
  stroke-width: 1.75;
  stroke-linejoin: round;
}

.arc-viz-marker-halo {
  fill: var(--arc-viz-marker-color, var(--arc-viz-accent));
  stroke: none;
  transform-box: fill-box;
  transform-origin: center;
}

.arc-viz-marker-dot {
  fill: var(--arc-viz-marker-color, var(--arc-viz-accent));
  stroke: var(--arc-viz-bg);
  stroke-width: 2;
}

/* Low-confidence bearings stay visibly present: a soft, slow breathing
   halo, not a missing spoke. Transform-only, so it is free to run and free
   to stop under reduced motion. */
.arc-viz-marker-group.is-forming .arc-viz-marker-halo {
  animation: arc-viz-breathe 3600ms ease-in-out infinite;
}

.arc-viz-spoke-label {
  fill: var(--arc-viz-muted);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.arc-viz-compass-legend {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.arc-viz-legend-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--arc-viz-border);
  border-radius: 14px;
  background: var(--arc-viz-surface);
}

.arc-viz-legend-swatch {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--arc-viz-marker-color, var(--arc-viz-accent));
  box-shadow: 0 0 0 2px var(--arc-viz-bg), 0 0 0 3px var(--arc-viz-border);
}

.arc-viz-legend-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.arc-viz-legend-name {
  font-size: 13px;
  font-weight: 650;
  color: var(--arc-viz-ink);
}

.arc-viz-legend-poles {
  font-size: 11px;
  color: var(--arc-viz-faint);
}

.arc-viz-legend-reading {
  margin-top: 1px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--arc-viz-muted);
}

.arc-viz-legend-reading.is-forming {
  opacity: 0.85;
}

@media (min-width: 640px) {
  .arc-viz-compass-legend {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---------------------------------------------------------------------- */
/* Bearing history                                                         */
/* ---------------------------------------------------------------------- */

.arc-viz-history {
  max-width: min(94vw, 480px);
  margin: 0 auto;
}

.arc-viz-history-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  animation: arc-viz-enter 420ms ease both;
}

.arc-viz-history-pole {
  fill: var(--arc-viz-muted);
  font-size: 10px;
  font-weight: 650;
}

.arc-viz-history-midline {
  stroke: var(--arc-viz-border);
  stroke-width: 1;
}

.arc-viz-history-guide {
  stroke: var(--arc-viz-border);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}

.arc-viz-history-band {
  fill: var(--arc-viz-marker-color, var(--arc-viz-accent));
  fill-opacity: 0.1;
  stroke: none;
}

.arc-viz-history-line {
  fill: none;
  stroke: var(--arc-viz-marker-color, var(--arc-viz-accent));
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.arc-viz-history-dot {
  fill: var(--arc-viz-marker-color, var(--arc-viz-accent));
  stroke: var(--arc-viz-bg);
  stroke-width: 2;
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 140ms ease;
}

.arc-viz-history-dot.is-single {
  stroke-width: 2.5;
}

.arc-viz-history-halo {
  fill: var(--arc-viz-marker-color, var(--arc-viz-accent));
  transform-box: fill-box;
  transform-origin: center;
  animation: arc-viz-breathe 3200ms ease-in-out infinite;
}

.arc-viz-history-caption {
  fill: var(--arc-viz-faint);
  font-size: 8.5px;
  font-weight: 600;
}

.arc-viz-history-axis-label {
  fill: var(--arc-viz-faint);
  font-size: 8px;
}

.arc-viz-history-point {
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.arc-viz-history-hit {
  fill: transparent;
  pointer-events: all;
}

.arc-viz-history-point:hover .arc-viz-history-dot,
.arc-viz-history-point:focus-visible .arc-viz-history-dot {
  transform: scale(1.3);
}

.arc-viz-history-point:focus-visible {
  outline: 2px solid var(--arc-viz-accent);
  outline-offset: 3px;
  border-radius: 50%;
}

.arc-viz-history-tooltip {
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.arc-viz-history-tooltip.is-visible {
  opacity: 1;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.28));
}

.arc-viz-history-tooltip-bg {
  fill: var(--arc-viz-surface-raised);
  stroke: var(--arc-viz-border);
  stroke-width: 1;
}

.arc-viz-history-tooltip-value {
  fill: var(--arc-viz-ink);
  font-size: 11px;
  font-weight: 650;
}

.arc-viz-history-tooltip-meta {
  fill: var(--arc-viz-muted);
  font-size: 9.5px;
}

/* ---------------------------------------------------------------------- */
/* Atlas constellation                                                     */
/* ---------------------------------------------------------------------- */

.arc-viz-atlas {
  max-width: min(94vw, 480px);
  margin: 0 auto;
}

.arc-viz-atlas-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  animation: arc-viz-enter 480ms ease both;
}

.arc-viz-node {
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.arc-viz-node-hit {
  fill: transparent;
  pointer-events: all;
}

.arc-viz-node-dot {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 160ms ease;
}

.arc-viz-node:hover .arc-viz-node-dot,
.arc-viz-node:focus-visible .arc-viz-node-dot {
  transform: scale(1.16);
}

.arc-viz-node:focus-visible {
  outline: 2px solid var(--arc-viz-accent);
  outline-offset: 3px;
  border-radius: 50%;
}

.arc-viz-node-thread .arc-viz-node-dot {
  fill: var(--arc-viz-accent);
  stroke: var(--arc-viz-bg);
  stroke-width: 2;
}

.arc-viz-node-thread .arc-viz-node-halo {
  fill: var(--arc-viz-accent);
  opacity: 0.16;
}

.arc-viz-node-loop .arc-viz-node-dot {
  fill: var(--arc-viz-loop);
  fill-opacity: 0.9;
  stroke: var(--arc-viz-bg);
  stroke-width: 1.5;
}

.arc-viz-node-fact .arc-viz-node-dot {
  fill: var(--arc-viz-faint);
  fill-opacity: 0.75;
}

.arc-viz-node-label {
  fill: var(--arc-viz-muted);
  font-size: 8.5px;
  font-weight: 600;
}

.arc-viz-node-label-small {
  fill: var(--arc-viz-faint);
  font-size: 8px;
  font-weight: 500;
}

.arc-viz-atlas-legend {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.arc-viz-legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border: 1px solid var(--arc-viz-border);
  border-radius: 999px;
  color: var(--arc-viz-muted);
  background: var(--arc-viz-surface);
  font-size: 11.5px;
  line-height: 1.2;
}

.arc-viz-legend-chip .arc-viz-legend-swatch {
  width: 8px;
  height: 8px;
  margin-top: 0;
  box-shadow: none;
}

.arc-viz-legend-chip-thread .arc-viz-legend-swatch { background: var(--arc-viz-accent); }
.arc-viz-legend-chip-loop .arc-viz-legend-swatch { background: var(--arc-viz-loop); }
.arc-viz-legend-chip-fact .arc-viz-legend-swatch { background: var(--arc-viz-faint); }

/* ---------------------------------------------------------------------- */
/* Motion                                                                   */
/* ---------------------------------------------------------------------- */

@keyframes arc-viz-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.22); }
}

@keyframes arc-viz-enter {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

/* ---------------------------------------------------------------------- */
/* Safe typography at 320px                                                */
/* ---------------------------------------------------------------------- */

@media (max-width: 360px) {
  .arc-viz-legend-row { padding: 9px 10px; gap: 8px; }
  .arc-viz-legend-name { font-size: 12.5px; }
  .arc-viz-legend-poles { font-size: 10.5px; }
  .arc-viz-legend-reading { font-size: 11.5px; }
  .arc-viz-legend-chip { padding: 6px 9px; font-size: 10.5px; }
  .arc-viz-empty { padding: 16px; font-size: 12.5px; }
}

/* ---------------------------------------------------------------------- */
/* Motion accessibility: the single source of truth for turning off every */
/* animation and transition declared above.                                */
/* ---------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .arc-viz-root,
  .arc-viz-root * {
    animation: none !important;
    transition: none !important;
  }
}
