:root {
  --bg: #eef0f4;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --ink: #1c2430;
  --ink-soft: #5a6573;
  --ink-faint: #8a93a0;
  --line: #e3e6ea;
  --accent: #3a4660;
  --accent-soft: #eef0f6;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(20, 30, 45, 0.06);
  --shadow-md: 0 6px 20px -10px rgba(20, 30, 45, 0.28);
  --shadow-lg: 0 18px 44px -22px rgba(20, 30, 45, 0.40);

  /* dataset colors — mirror Global.colors in bundle.js */
  --c-toric: rgb(72, 72, 110);
  --c-cicy: rgb(220, 38, 38);
  --c-weighted: rgb(51, 51, 204);
  --c-smoothing: rgb(22, 163, 74);
  --c-quot: rgb(217, 119, 6);
  --c-tip: rgb(204, 26, 204);
  --c-flag: rgb(14, 165, 165);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

/* Always reserve the scrollbar's space so the centred layout doesn't jump
   sideways when marking a point makes the page tall enough to scroll.
   scrollbar-gutter is the modern way; overflow-y: scroll is the fallback. */
html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 540px at 88% -12%, rgba(58, 70, 96, 0.10), transparent 62%),
    radial-gradient(900px 480px at -8% 8%, rgba(58, 70, 96, 0.06), transparent 60%),
    var(--bg);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] { display: none !important; }

/* centred page container — gutter matches the canvas columnWidth (56) so the
   plot lines up with the controls and is framed by whitespace on wide screens */
.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 28px 28px;
}

/* ===================== top bar ===================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px 0 16px;
  margin-bottom: 6px;
}

.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }

h1 {
  font-family: 'Fraunces', 'Book Antiqua', Georgia, serif;
  font-weight: 600;
  font-size: clamp(1.45rem, 2.4vw, 1.95rem);
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0;
  line-height: 1.1;
}

.tagline { margin: 0; font-size: 0.84rem; color: var(--ink-soft); }

/* segmented control */
.view-toggle {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-sm) inset;
}

.seg {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.seg .seg-k {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(58, 70, 96, 0.10);
  color: var(--accent);
}

.seg:hover { color: var(--ink); }

.seg.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.seg.is-active .seg-k { background: var(--accent); color: #fff; }

/* ===================== views ===================== */
.stage { position: relative; }
.view { animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- dataset toggle chips ---------- */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  padding: 0;
}

.chip {
  --c: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1;
  appearance: none;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, background 0.15s ease,
    box-shadow 0.15s ease, color 0.15s ease, transform 0.05s ease;
}

.chip[data-c="toric"]     { --c: var(--c-toric); }
.chip[data-c="cicy"]      { --c: var(--c-cicy); }
.chip[data-c="weighted"]  { --c: var(--c-weighted); }
.chip[data-c="smoothing"] { --c: var(--c-smoothing); }
.chip[data-c="quot"]      { --c: var(--c-quot); }
.chip[data-c="tip"]       { --c: var(--c-tip); }
.chip[data-c="flag"]      { --c: var(--c-flag); }

.chip input[type="checkbox"] {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0; pointer-events: none; margin: 0;
}

.chip .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--c);
  opacity: 0.35;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.chip:hover {
  border-color: color-mix(in srgb, var(--c) 45%, var(--line));
  background: color-mix(in srgb, var(--c) 6%, var(--surface));
}

.chip:has(input:checked),
.chip.is-active {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 12%, var(--surface));
  box-shadow: var(--shadow-sm), 0 0 0 1px color-mix(in srgb, var(--c) 25%, transparent);
  color: var(--ink);
}
.chip:has(input:checked) .dot,
.chip.is-active .dot { opacity: 1; transform: scale(1.05); }
.chip:active { transform: translateY(0.5px); }
.chip:has(input:focus-visible) {
  outline: 2px solid color-mix(in srgb, var(--c) 60%, transparent);
  outline-offset: 2px;
}

/* ---------- class / family description (active blurb) ---------- */
#class-description,
#family-description {
  line-height: 1.6;
  margin: 0 0 16px;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 0.86rem;
  color: var(--ink-soft);
}
#class-description-p,
#family-description-p { margin: 0; }
#class-description strong { color: var(--ink); }
#class-description a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

/* ---------- 2D plot ---------- */
.plot-stage { position: relative; }
#myDiv { text-align: center; }

#canvas {
  display: block;
  /* match the renderer's fill colour (Global.backgroundColor) to avoid a white flash */
  background-color: rgb(220, 230, 255);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-sm), var(--shadow-md);
}
@media (max-width: 600px) {
  #canvas { height: calc(100vh - 400px); }
}

#offscreenCanvas { display: none; }

/* hover read-out overlay (MathJax label + live numbers) */
.hover-readout {
  position: absolute;
  left: 22px;
  bottom: 22px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 6px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(28, 36, 48, 0.10);
  box-shadow: var(--shadow-sm), var(--shadow-md);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.hover-readout.is-visible { opacity: 1; transform: none; }
.hr-label { color: var(--ink-soft); font-size: 0.95rem; line-height: 1; }
.hr-label mjx-container { margin: 0 !important; }
.hr-val {
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', 'JetBrains Mono', Menlo, monospace;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--accent);
}

/* ---------- detail panel (future: variety behind a marker) ---------- */
.info-panel {
  position: absolute;
  top: 18px;
  right: max(18px, 4%);
  width: min(280px, 32vw);
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.72);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  backdrop-filter: blur(10px) saturate(1.2);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
}
.info-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.info-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.info-close {
  appearance: none; border: 0; background: transparent;
  font-size: 1.1rem; line-height: 1; color: var(--ink-faint);
  cursor: pointer; padding: 0 2px;
}
.info-empty {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--ink-soft);
}
.info-constr {
  margin: 0 0 8px;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--ink-soft);
}
.info-fam { font-weight: 600; }
.info-ref { margin: 0; font-size: 0.82rem; }
.info-ref a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
@media (max-width: 720px) {
  .info-panel { position: static; width: auto; margin: 10px 4px 0; }
}

/* ---------- 3D view ---------- */
.intro-card {
  margin: 0 0 16px;
  padding: 13px 18px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.intro-card p { color: var(--ink-soft); }
.intro-card p { margin: 0; font-size: 0.88rem; line-height: 1.55; color: var(--ink-soft); }
.intro-card strong { color: var(--ink); }
.intro-meta { margin-top: 4px !important; font-size: 0.8rem !important; color: var(--ink-faint) !important; }
.intro-card a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.js-mail { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }

.plot3d {
  height: calc(100vh - 360px);
  min-height: 380px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  /* match the 2D canvas fill colour */
  background: rgb(220, 230, 255);
  box-shadow: var(--shadow-sm), var(--shadow-md);
  overflow: hidden;
}
.plot3d-status {
  margin: 10px 4px 0;
  font-size: 0.82rem;
  color: var(--ink-faint);
  text-align: center;
}

/* ---------- bottom description (marked points) ---------- */
#myDiv > #description { display: none; }
body > #description,
#marks-3d {
  text-align: left;
  overflow-y: auto;
  margin: 12px 6px 0;
  font-size: 0.84rem;
  color: var(--ink-soft);
}
#description-p,
#marks-3d-p {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* marked-point tags */
.mark-hint {
  flex-basis: 100%;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--ink-faint);
  margin-bottom: 2px;
}
.mark-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  background: color-mix(in srgb, var(--accent) 9%, var(--surface));
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', 'JetBrains Mono', Menlo, monospace;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1;
}
.mark-tag.is-empty {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--ink-faint);
}
