:root {
  --bg-top: #eef6ff;
  --bg-bottom: #d7e8ff;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-border: rgba(18, 57, 99, 0.12);
  --ink: #15304d;
  --muted: #55708d;
  --accent: #0f766e;
  --accent-strong: #0d9488;
  --shadow: 0 24px 60px rgba(19, 48, 77, 0.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Gill Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255,255,255,0.85), transparent 30%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

.page {
  width: min(1280px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 2rem;
}

/* ── Hero ─────────────────────────────────────────────────── */

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.hero-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255,255,255,0.9);
  border: 1px solid rgba(21,48,77,0.12);
}
.hero-link:hover { background: white; }

.hero-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; justify-content: flex-end; }

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 0.95;
}

.intro {
  max-width: 68ch;
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 1rem;
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

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

.controls {
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  max-height: calc(100vh - 180px);
}

.controls h2 { margin: 0; font-size: 1.2rem; }

.control-group > label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 700;
  font-size: 0.92rem;
}

/* ── Segmented controls ────────────────────────────────────── */

.seg-control {
  display: grid;
  background: rgba(21,48,77,0.07);
  border-radius: 14px;
  padding: 3px;
  gap: 0;
}

.seg-control.cols-2 { grid-template-columns: 1fr 1fr; }
.seg-control.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.seg-btn-wide { grid-column: 1 / -1; }

.seg-btn {
  padding: 0.45rem 0.3rem;
  border: 0;
  border-radius: 11px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: center;
  line-height: 1.25;
}

.seg-btn.active {
  background: white;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(21,48,77,0.12);
}

/* ── Radio buttons ─────────────────────────────────────────── */

.radio-group {
  display: flex;
  gap: 0.85rem;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}

.radio-label input[type="radio"] {
  accent-color: var(--accent-strong);
}

/* ── Slider rows ───────────────────────────────────────────── */

input[type="range"] {
  width: 100%;
  accent-color: var(--accent-strong);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.slider-val {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  min-width: 2.8rem;
  text-align: right;
}

.slider-unit {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── Particle / fragment config groups ─────────────────────── */

.particle-group {
  background: rgba(21,48,77,0.04);
  border-radius: 14px;
  padding: 0.7rem 0.75rem;
}

.particle-label {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  display: block;
}

.param-row {
  display: grid;
  grid-template-columns: 36px 1fr auto auto;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.param-row input[type="range"] { width: 100%; }

/* ── Vector toggles ────────────────────────────────────────── */

.vector-toggles {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.vec-btn {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.42rem 0.65rem;
  border: 1.5px solid rgba(21,48,77,0.14);
  border-radius: 10px;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--muted);
  background: rgba(255,255,255,0.5);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.vec-btn.active { background: rgba(255,255,255,0.92); color: var(--ink); }
.vec-btn:not(.active) { opacity: 0.45; }

.vec-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Explanation card ──────────────────────────────────────── */

.explain-card {
  padding: 0.75rem 0.9rem;
  border-radius: 14px;
  background: rgba(239,247,255,0.9);
  border-left: 3px solid var(--accent-strong);
  font-size: 0.85rem;
  line-height: 1.55;
  color: #334155;
}

.explain-card.hidden { display: none; }

/* ── Action buttons ────────────────────────────────────────── */

.action-btn {
  padding: 0.65rem 1.1rem;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(15,118,110,0.25);
  transition: opacity 0.15s;
}

.action-btn.secondary {
  background: linear-gradient(135deg, #475569, #64748b);
  box-shadow: 0 6px 18px rgba(71,85,105,0.2);
}

/* ── Canvas panel ──────────────────────────────────────────── */

.visual-panel { padding: 0.85rem; }

.canvas-wrap {
  overflow: hidden;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.82), rgba(225,238,255,0.94));
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 12 / 7;
}

/* ── Warning banner ────────────────────────────────────────── */

.warn-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 12px;
  background: rgba(251,191,36,0.18);
  border-left: 3px solid #f59e0b;
  font-size: 0.82rem;
  line-height: 1.45;
  color: #78350f;
}

.warn-banner span { flex: 1; }

.warn-close {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(120,53,15,0.25);
  border-radius: 50%;
  background: rgba(120,53,15,0.08);
  font-size: 0.75rem;
  font-weight: 700;
  color: #78350f;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}
.warn-close:hover { background: rgba(120,53,15,0.18); }

/* ── Triangle editor modal ─────────────────────────────────── */

.tri-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
}
.tri-modal[hidden] { display: none; }

.tri-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10,20,40,0.45);
  backdrop-filter: blur(4px);
}

.tri-modal-panel {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 500px;
  background: white;
  border-radius: 24px;
  box-shadow: 0 32px 80px rgba(10,20,40,0.28);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tri-modal-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
  border-bottom: 1px solid var(--panel-border);
}

.tri-hd-actions { display: flex; gap: 0.4rem; align-items: center; }

.tri-reset-btn {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: rgba(21,48,77,0.05);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.tri-reset-btn:hover { background: rgba(21,48,77,0.1); color: var(--ink); }

.tri-close-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  background: rgba(21,48,77,0.05);
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
}
.tri-close-btn:hover { background: rgba(21,48,77,0.1); color: var(--ink); }

#coll-tri-canvas,
#coll-tri2-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
}

.tri-hint {
  margin: 0;
  padding: 0.7rem 1.25rem 1rem;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.5;
}

/* Locked controls in triangle mode */
.tri-locked {
  opacity: 0.4;
  pointer-events: none;
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 960px) {
  .hero { align-items: flex-start; flex-direction: column; }
  .hero-actions { justify-content: flex-start; }
  .layout { grid-template-columns: 1fr; }
  .controls { max-height: none; }
}
