/* ==========================================================================
   C2CAD-Bench — 3D Visualizer
   ========================================================================== */

#main-canvas {
  position: fixed;
  inset: 0;
  z-index: 500;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
}

.viz-page {
  position: relative;
  min-height: 100vh;
  background: var(--bg);
}

.viz-hero {
  position: relative;
  overflow: hidden;
  padding: calc(var(--nav-h) + 46px) 0 30px;
}

.viz-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  display: none;
}

.viz-hero .container {
  position: relative;
  z-index: 1;
}

.viz-title {
  font-size: clamp(1.9rem, 3.6vw, 2.7rem);
  letter-spacing: -0.035em;
}

.viz-lead {
  max-width: 720px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 1rem;
}

.viz-toolbar {
  position: sticky;
  top: var(--nav-h);
  z-index: 900;
  padding: 14px 0;
  border-block: 1px solid var(--border);
  background: var(--bg-glass);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  backdrop-filter: blur(16px) saturate(160%);
}

.viz-toolbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.viz-control {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.viz-control > label {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  white-space: nowrap;
}

.viz-select {
  min-width: 220px;
  max-width: 280px;
  height: 40px;
  padding: 0 38px 0 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background-color: var(--bg-elev);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7690' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.viz-select:hover,
.viz-select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.viz-spacer {
  flex: 1;
}

.overall-badge {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--accent-ring);
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.overall-badge.is-visible {
  display: inline-flex;
}

.viz-phase-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg-soft);
}

.viz-phase-tab {
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.viz-phase-tab:hover {
  color: var(--ink);
  background: var(--bg-elev);
}

.viz-phase-tab.is-active {
  border-color: var(--border);
  background: var(--bg-elev);
  color: var(--accent);
  box-shadow: var(--shadow-xs);
}

.viz-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 12px 0 0;
  color: var(--muted);
  font-size: 11.5px;
}

.legend-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

/* --------------------------------------------------------------------------
   Content
   -------------------------------------------------------------------------- */

.viz-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 46px;
  padding: 34px 0 76px;
}

.viz-empty {
  display: grid;
  place-items: center;
  gap: 14px;
  padding: 90px 24px;
  color: var(--muted);
  text-align: center;
}

.viz-empty h3 {
  color: var(--ink);
}

.family-block {
  display: flex;
  flex-direction: column;
  scroll-margin-top: 90px;
  animation: fade-up 0.45s ease-out both;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.family-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.family-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.family-name {
  font-family: var(--font-display);
  font-size: 1.16rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.fam-phase-pill {
  padding: 3px 9px;
  border: 1px solid var(--accent-ring);
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
}

.fam-count {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.level-switcher {
  display: flex;
  gap: 5px;
  margin-left: auto;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-soft);
}

.lvl-btn {
  min-width: 42px;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.lvl-btn:hover {
  color: var(--ink);
  background: var(--bg-elev);
}

.lvl-btn.is-active {
  border-color: var(--border);
  background: var(--bg-elev);
  color: var(--accent);
  box-shadow: var(--shadow-xs);
}

/* --------------------------------------------------------------------------
   Viewports
   -------------------------------------------------------------------------- */

.vp-row {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.vp-row.is-active {
  display: grid;
}

.viewport-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}

.card-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 700;
}

.card-title .icon {
  color: var(--good);
}

.card-title.is-ai .icon {
  color: var(--accent);
}

.card-meta {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  white-space: nowrap;
}

.score-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}

.score-badge {
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--bg-elev);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
}

.score-badge.global-badge {
  outline: 1px solid currentColor;
}

.vp-toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}

.vp-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.vp-btn .icon {
  width: 11px;
  height: 11px;
}

.vp-btn:hover {
  border-color: var(--border-strong);
  color: var(--ink);
}

.vp-btn.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.vp-zoom {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  color: var(--muted-2);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.vp-zoom input[type="range"] {
  width: 68px;
  height: 4px;
  border-radius: 999px;
  background: var(--bg-deep);
  accent-color: var(--accent);
  cursor: pointer;
}

.viewport {
  position: relative;
  height: 460px;
  width: 100%;
  background: var(--bg-soft);
  cursor: grab;
  touch-action: none;
}

.viewport:active {
  cursor: grabbing;
}

.viewport.is-empty {
  cursor: default;
}

.viewport.is-empty::after {
  content: "No geometry returned";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted-2);
  font-size: 12px;
}

.prompt-container {
  border-top: 1px solid var(--border);
}

.prompt-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 9px 14px;
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-align: left;
  text-transform: uppercase;
  transition: color var(--transition);
}

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

.prompt-content {
  display: none;
  max-height: 260px;
  overflow-y: auto;
  padding: 18px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.75;
  white-space: pre-wrap;
}

.prompt-content.is-open {
  display: block;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 1080px) {
  .vp-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .viz-legend {
    display: none;
  }

  .viz-toolbar-inner {
    gap: 10px;
  }

  .viz-control {
    width: 100%;
  }

  .viz-select {
    flex: 1;
    min-width: 0;
    max-width: none;
  }

  .viz-phase-tabs {
    width: 100%;
    justify-content: space-between;
  }

  .viz-phase-tab {
    flex: 1;
    text-align: center;
  }

  .viewport {
    height: 360px;
  }

  .level-switcher {
    margin-left: 0;
  }
}
