/* ========================================================================
   Unified Shape Viewer — Geometric Library
   ======================================================================== */

.viewer-page {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 60px);
  background: #0a0a0a;
  color: #e0e0e0;
}

/* ---- Top bar: breadcrumb + title ---- */
.viewer-topbar {
  padding: 0.5rem 1.5rem 0.65rem;
  background: #111;
  border-bottom: 1px solid #222;
  flex-shrink: 0;
}
.breadcrumb { font-size: 0.78rem; color: #777; }
.breadcrumb a { color: #9aa; text-decoration: none; }
.breadcrumb a:hover { color: #fff; }
.breadcrumb .sep { margin: 0 0.4rem; color: #444; }
.crumb-shape { color: #e0e0e0; font-weight: 600; }

.shape-title-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-top: 0.3rem;
  flex-wrap: wrap;
}
.shape-title-row h1.shape-name {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
}
.shape-title-row .shape-dim {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #666;
}

/* ---- Signal badge ---- */
.signal-badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.signal-badge[data-signal="TRAP"]       { background: #4a1a1a; color: #ff6b6b; border: 1px solid #6b2020; }
.signal-badge[data-signal="CHANNEL"]    { background: #1a3a1a; color: #6bff6b; border: 1px solid #206b20; }
.signal-badge[data-signal="DISTRIBUTE"] { background: #1a1a4a; color: #6b6bff; border: 1px solid #20206b; }
.signal-badge[data-signal="FRUSTRATE"]  { background: #4a3a1a; color: #ffbb6b; border: 1px solid #6b4a20; }
.signal-badge[data-signal="CONVERT"]    { background: #3a1a4a; color: #bb6bff; border: 1px solid #4a206b; }
.signal-badge[data-signal="OSCILLATE"]  { background: #1a4a4a; color: #6bffff; border: 1px solid #206b6b; }
.signal-badge[data-signal="POLARIZE"]   { background: #4a4a1a; color: #ffff6b; border: 1px solid #6b6b20; }
.signal-badge[data-signal="LAYER"]      { background: #2a2a2a; color: #cccccc; border: 1px solid #444; }
.signal-badge[data-signal="TWIST"]      { background: #3a1a3a; color: #ff6bff; border: 1px solid #6b206b; }
.signal-badge[data-signal="FOCUS"]      { background: #2a3a1a; color: #bbff6b; border: 1px solid #3a5b20; }

/* ---- Main split layout ---- */
.viewer-main {
  display: flex;
  flex: 1;
  min-height: 0;
  height: calc(100vh - 260px);
}
.panel-3d, .panel-sweep {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.panel-3d { background: #0a0a0a; border-right: 1px solid #222; }
.panel-sweep { background: #0d0d0d; }

.panel-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #555;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid #1a1a1a;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}
.panel-hint {
  text-transform: none;
  letter-spacing: 0;
  color: #3a3a3a;
  font-size: 0.62rem;
}

.canvas-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #0a0a0a;
}
.canvas-wrap canvas {
  position: relative;
  z-index: 1;   /* credits panel sits above so it can capture scroll */
}

/* ---- Slow "found in" credits, rendered BEHIND the 3D shape ---- */
.found-credits {
  position: absolute;
  top: 0;
  right: 0;
  width: 27%;
  min-width: 185px;
  max-width: 250px;
  height: 100%;
  pointer-events: auto;          /* scroll/interact with the text */
  overflow-y: auto;              /* scrollbar appears when content overflows */
  overflow-x: hidden;
  mask-image: linear-gradient(to bottom,
              transparent 0%, black 14%, black 86%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom,
              transparent 0%, black 14%, black 86%, transparent 100%);
  z-index: 3;                    /* above the 3D canvas so scroll hits this */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}
.found-credits::-webkit-scrollbar {
  width: 6px;
}
.found-credits::-webkit-scrollbar-track {
  background: transparent;
}
.found-credits::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.22);
  border-radius: 3px;
}
.found-credits::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
}
/* Pause the auto-crawl once the user starts scrolling or hovering the panel */
.found-credits:hover .found-credits-inner,
.found-credits.is-interacting .found-credits-inner {
  animation-play-state: paused;
}
.found-credits-inner {
  position: relative;            /* in flow so parent can scroll its height */
  padding: 0 0.85rem;
  color: #f5f5f5;
  font-family: 'Times New Roman', Times, serif;
  font-size: 0.88rem;
  line-height: 1.5;
  text-align: center;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.85), 0 0 2px rgba(0, 0, 0, 0.9);
  /* Start position (below panel) and end position (centered) are driven
     by CSS vars written from viewer.js after measuring content + panel.  */
  transform: translateY(var(--found-start, 100%));
  animation: found-scroll var(--found-duration, 42s) linear 1 forwards;
  will-change: transform;
}
.found-credits-inner .fc-heading {
  display: block;
  font-size: 0.78rem;
  font-style: italic;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #c0c0c0;
  margin: 1.4rem 0 0.35rem;
  font-family: 'Times New Roman', Times, serif;
}
.found-credits-inner .fc-entry {
  display: block;
  margin: 0 0 0.85rem;
  font-family: 'Times New Roman', Times, serif;
}
.found-credits-inner .fc-spacer {
  display: block;
  height: 2.5rem;
}
.found-credits-inner .fc-title {
  display: block;
  font-size: 1.25rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  margin-bottom: 1rem;
  color: #fff;
  font-family: 'Times New Roman', Times, serif;
}

@keyframes found-scroll {
  from { transform: translateY(var(--found-start, 100%)); }
  to   { transform: translateY(var(--found-end,   0px));  }
}
.canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}
.canvas-wrap canvas:active { cursor: grabbing; }

.toggle-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: #111;
  border-top: 1px solid #222;
}
.toggle-btn {
  background: #1a1a1a;
  border: 1px solid #333;
  color: #aaa;
  padding: 0.3rem 0.7rem;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.75rem;
  transition: all 0.15s;
}
.toggle-btn:hover { border-color: #555; color: #fff; }
.toggle-btn.active {
  background: #1e3a5f;
  border-color: #3a7bd5;
  color: #fff;
}

/* ---- Sweep panel: image + slider ---- */
.sweep-image-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 1rem;
  min-height: 0;
}
.sweep-image-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border: 1px solid #222;
  border-radius: 4px;
  background: #0a0a0a;
}
.sweep-image-label {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  color: #888;
  background: rgba(10, 10, 10, 0.8);
  padding: 0.2rem 0.6rem;
  border-radius: 3px;
  letter-spacing: 0.04em;
}

.sweep-placeholder {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0a0a0a;
  z-index: 3;
}
.placeholder-icon {
  width: 48px;
  height: 48px;
  border: 2px dashed #333;
  border-radius: 8px;
  margin-bottom: 0.75rem;
}
.placeholder-text {
  font-size: 0.8rem;
  color: #666;
  text-align: center;
  line-height: 1.5;
  max-width: 320px;
  padding: 0 1rem;
}

.sweep-image-wrap.dim-transition img {
  outline: 2px solid;
  outline-offset: -2px;
  animation: dimFlash 0.6s ease-out;
}
.sweep-image-wrap.dim-transition[data-dim="3D"] img { outline-color: #ffbb6b; }
.sweep-image-wrap.dim-transition[data-dim="4D"] img { outline-color: #6b8bff; }
@keyframes dimFlash {
  0%   { outline-width: 4px; outline-offset: -4px; }
  100% { outline-width: 2px; outline-offset: -2px; }
}

/* ---- f|t slider ---- */
.ft-slider-container {
  padding: 0.5rem 1.5rem 0.6rem;
  background: #111;
  border-top: 1px solid #222;
}
.ft-axis-labels {
  display: flex;
  justify-content: space-between;
  padding: 0 0.25rem;
  margin-bottom: 0.15rem;
}
.ft-label {
  font-size: 0.9rem;
  font-weight: 700;
  font-style: italic;
}
.ft-label-f { color: #ffbb6b; }
.ft-label-t { color: #6b8bff; }

.ft-triangle-track {
  position: relative;
  height: 60px;
  margin: 0.25rem 0;
}
.ft-triangle-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
.ft-dim-labels {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 100%;
  pointer-events: none;
}
.ft-dim {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  opacity: 0.5;
}
.ft-dim[data-dim="3D"] { color: #ffbb6b; }
.ft-dim[data-dim="4D"] { color: #6b8bff; }

.ft-range-input {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 100%;
  height: 40px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  outline: none;
  margin: 0;
  z-index: 2;
  cursor: pointer;
}
.ft-range-input:disabled { cursor: not-allowed; opacity: 0.35; }
.ft-range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 4px;
  height: 60px;
  background: rgba(255, 255, 255, 0.9);
  cursor: ew-resize;
  border: none;
  border-radius: 1px;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}
.ft-range-input::-moz-range-thumb {
  width: 4px;
  height: 60px;
  background: rgba(255, 255, 255, 0.9);
  cursor: ew-resize;
  border: none;
  border-radius: 1px;
}
.ft-range-input::-moz-range-track { background: transparent; border: none; }

.ft-divider-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 3;
  overflow: visible;
}
.ft-edge-sq  { filter: drop-shadow(0 0 3px rgba(58, 123, 213, 0.4)); }
.ft-center-sq { filter: drop-shadow(0 0 5px rgba(58, 123, 213, 0.6)); }

/* ---- Controls row ---- */
.ft-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}
.ft-play-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #444;
  background: #1a1a1a;
  color: #ccc;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ft-play-btn:hover:not(:disabled) { background: #2a2a2a; border-color: #666; }
.ft-play-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.ft-play-btn.playing { border-color: #3a7bd5; background: #1a2a3a; }

.ft-step-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 110px;
}
.ft-current-dim {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #888;
}
.ft-current-dim[data-dim="3D"] { color: #ffbb6b; }
.ft-current-dim[data-dim="4D"] { color: #6b8bff; }
.ft-step-num {
  font-size: 0.62rem;
  color: #555;
  font-variant-numeric: tabular-nums;
}

.view-tabs {
  display: flex;
  gap: 0.3rem;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
  padding: 2px;
  background: #151515;
}
.view-tab {
  background: transparent;
  border: none;
  color: #777;
  padding: 0.2rem 0.55rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  border-radius: 2px;
}
.view-tab:hover { color: #ccc; }
.view-tab.active { background: #1e3a5f; color: #fff; }

.sweep-stats {
  display: flex;
  gap: 0.85rem;
  font-size: 0.62rem;
  color: #555;
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

/* ---- Bottom: fingerprint + nav ---- */
.viewer-bottom {
  display: flex;
  gap: 1.25rem;
  padding: 0.65rem 1.5rem;
  background: #111;
  border-top: 1px solid #222;
  align-items: flex-start;
  flex-shrink: 0;
}
.fp-panel { flex: 1; }
.fp-panel h3 {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #555;
  margin: 0 0 0.4rem;
}
.fp-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.3rem;
}
.fp-cell {
  display: flex;
  flex-direction: column;
  background: #1a1a1a;
  padding: 0.3rem 0.4rem;
  border-radius: 3px;
  border: 1px solid #222;
  min-width: 0;
}
.fp-label {
  font-size: 0.54rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #555;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fp-val {
  font-size: 0.84rem;
  font-weight: 600;
  color: #e0e0e0;
  font-variant-numeric: tabular-nums;
}
.distortion-note {
  margin-top: 0.5rem;
  font-size: 0.72rem;
  color: #888;
  line-height: 1.5;
}
.distortion-note strong { color: #e0e0e0; }

.nav-panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
  min-width: 170px;
}
.nav-panel .nav-btn {
  background: #1a1a1a;
  border: 1px solid #333;
  color: #aaa;
  padding: 0.4rem 0.75rem;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.8rem;
}
.nav-panel .nav-btn:hover:not(:disabled) { border-color: #555; color: #fff; }
.nav-panel .nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.nav-pos {
  text-align: center;
  font-size: 0.72rem;
  color: #666;
  font-variant-numeric: tabular-nums;
}

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  .viewer-main {
    flex-direction: column;
    height: auto;
  }
  .panel-3d {
    border-right: none;
    border-bottom: 1px solid #222;
    min-height: 340px;
  }
  .panel-sweep { min-height: 380px; }
  .fp-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 640px) {
  .fp-grid { grid-template-columns: repeat(2, 1fr); }
  .viewer-bottom { flex-direction: column; }
  .nav-panel { flex-direction: row; }
}
