/* ── Design tokens ──────────────────────────────────────────────────────────── */

:root {
  color-scheme: dark;

  /* Colors – dark only */
  --color-bg: #0c0c0c;
  --color-text: #e2e2e2;
  --color-accent: #22d3ee;
  --color-muted: #888888;
  --color-subtle: #666666;
  --color-faint: #3a3a3a;
  --color-dim: #777777;
  --color-dot: #999999;
  --color-error: #fb7185;

  /* Typography */
  --font-mono: ui-monospace, "Courier New", monospace;
  --fs-heading: 0.8rem;
  --fs-label: 0.6rem;
  --fs-input: 0.8rem;
  --fs-button: 0.6rem;
  --fs-status: 0.6rem;
  --fs-tooltip: 0.8rem;

  /* Spacing */
  --sp-body-px: 12px;
  --sp-body-py: 14px;
  --sp-gap: 8px;
  --sp-gap-sm: 3px;
  --sp-section: 10px;
  --sp-section-sm: 6px;

  /* SVG stroke widths */
  --sw-fine: 0.002;
  --sw-thin: 0.0025;
  --sw-medium: 0.003;
  --sw-bold: 0.004;

  /* SVG dash pattern */
  --dash-pattern: 0.012 0.012;

  /* Canvas */
  --canvas-max: 1200px;

  /* Transitions */
  --ease-fast: 0.1s;
  --ease-normal: 0.15s;

  /* Z-index layers (HTML overlays) */
  --z-tooltip: 50;
  --z-hud: 100;
  --z-splash: 1000;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */

body {
  font-family: var(--font-mono);
  background: var(--color-bg);
  color: var(--color-text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

.centered {
  position: relative;
  width: 100%;
  height: 100%;
}

h1 {
  font-size: var(--fs-heading);
  font-weight: 400;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--color-text);
}

#canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: none; /* prevent browser pan/zoom on touch drag */
}

#canvas-wrap.cursor-hidden {
  cursor: none;
}

svg {
  width: 100%;
  height: 100%;
  display: block;
  shape-rendering: geometricPrecision;
}

/* ── Controls ──────────────────────────────────────────────────────────────── */

.controls {
  display: flex;
  gap: var(--sp-gap);
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: var(--sp-section);
}

button {
  background: transparent;
  border: 1px solid var(--color-accent);
  border-radius: 0;
  color: var(--color-accent);
  cursor: pointer;
  font-size: var(--fs-button);
  font-family: inherit;
  font-weight: 400;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 5px 14px;
  transition:
    background var(--ease-normal),
    color var(--ease-normal);
}

button:hover {
  background: var(--color-accent);
  color: var(--color-bg);
}

button:disabled {
  border-color: var(--color-faint);
  color: var(--color-faint);
  cursor: not-allowed;
}

button:disabled:hover {
  background: transparent;
  color: var(--color-faint);
}

/* ── Tooltip ───────────────────────────────────────────────────────────────── */

#tooltip {
  position: absolute;
  background: var(--color-bg);
  border: 1px solid var(--color-accent);
  padding: 2px 4px;
  font-size: var(--fs-tooltip);
  font-family: var(--font-mono);
  pointer-events: none;
  max-width: 260px;
  opacity: 0;
  transition: opacity var(--ease-fast);
  z-index: var(--z-tooltip);
}

#tooltip.visible {
  opacity: 1;
}

#tooltip .tw {
  font-weight: 400;
  color: var(--color-accent);
  background: transparent;
  border-bottom: none;
  padding: 0;
  letter-spacing: 0.04em;
}

/* ── SVG: Triangle ─────────────────────────────────────────────────────────── */

.tri-edge {
  stroke: var(--color-faint);
  stroke-width: var(--sw-thin);
  fill: none;
}

.tri-vertex-dot {
  fill: var(--color-muted);
}

.tri-vertex-label {
  fill: var(--color-text);
  font-weight: 400;
}

.vertex-label-bg,
.distance-label-bg {
  fill: var(--color-bg);
  stroke: none;
}

/* ── SVG: Word dots ────────────────────────────────────────────────────────── */

.word-dot {
  fill: var(--color-dot);
  fill-opacity: 0.1;
}

.word-dot.visited {
  fill: var(--color-muted);
  fill-opacity: 1 !important;
}

/* ── SVG: Hover elements ───────────────────────────────────────────────────── */

.active-node {
  fill: var(--color-accent);
}

.hover-cursor-dot {
  fill: none;
  stroke: var(--color-accent);
  stroke-width: var(--sw-thin);
}

.link-line {
  stroke: var(--color-accent);
  stroke-width: var(--sw-thin);
  stroke-opacity: 0.6;
}

.link-label {
  fill: var(--color-muted);
}

.cursor-link-line {
  stroke: var(--color-accent);
  stroke-width: var(--sw-thin);
  stroke-opacity: 0.5;
  stroke-dasharray: var(--dash-pattern);
}

/* ── SVG: Rulers ───────────────────────────────────────────────────────────── */

.ruler-tick {
  stroke: var(--color-faint);
  stroke-width: var(--sw-fine);
}

.ruler-marker {
  stroke: var(--color-accent);
  stroke-width: var(--sw-bold);
  stroke-opacity: 0.85;
}

.ruler-marker-match {
  stroke: var(--color-subtle);
  stroke-width: var(--sw-medium);
  stroke-opacity: 0.7;
}

/* ── SVG: Exploration path ─────────────────────────────────────────────────── */

.path-line {
  stroke: var(--color-subtle);
  stroke-width: var(--sw-medium);
  stroke-opacity: 0.7;
}

.path-line-preview {
  stroke: var(--color-subtle);
  stroke-width: var(--sw-medium);
  stroke-opacity: 0.7;
  stroke-dasharray: var(--dash-pattern);
}

.last-visited-line {
  stroke: var(--color-subtle);
  stroke-width: var(--sw-medium);
  stroke-opacity: 0.8;
  stroke-dasharray: var(--dash-pattern);
}

.last-visited-label {
  fill: var(--color-subtle);
}

/* ── HUD toggles ───────────────────────────────────────────────────────────── */

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-hud);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: var(--sp-body-py) var(--sp-body-px);
  pointer-events: none;
}

.hud > * {
  pointer-events: auto;
}

.hud h1 {
  grid-column: 2;
  text-align: center;
  white-space: nowrap;
}

.hud > :first-child {
  justify-self: start;
}

.hud > :last-child {
  justify-self: end;
}

.hud-toggle {
  font-size: var(--fs-label);
  letter-spacing: 0.1em;
  text-transform: lowercase;
  padding: 3px 10px;
  border: 1px solid var(--color-faint);
  color: var(--color-dim);
  background: var(--color-bg);
  cursor: pointer;
  transition: color var(--ease-normal);
}

.hud-toggle:hover {
  color: var(--color-muted);
  background: var(--color-bg);
}

.hud-toggle[aria-pressed="true"] {
  color: var(--color-muted);
}

/* ── Splash / loading screen ───────────────────────────────────────────────── */

.splash {
  position: fixed;
  inset: 0;
  z-index: var(--z-splash);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}

.splash.hidden {
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
}

#splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.loading-msg {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  color: var(--color-dim);
}

.loading-msg.hidden {
  display: none;
}

.splash-start {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 400;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--color-accent);
  background: transparent;
  border: 1px solid var(--color-accent);
  padding: 10px 32px;
  cursor: pointer;
  transition:
    background var(--ease-normal),
    color var(--ease-normal);
}

.splash-start:hover:not(:disabled) {
  background: var(--color-accent);
  color: var(--color-bg);
}

/* ── Utility ───────────────────────────────────────────────────────────────── */

.blink-hide {
  opacity: 0 !important;
}
