/* Shared Top Bar - Consistent across all toys */
.toy-top-bar {
  position: sticky;
  top: 0;
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: rgba(12, 12, 16, 0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 100;
  gap: 10px;
}

.toy-top-bar .back-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  color: #909898;
  text-decoration: none;
  font-family: 'Space Mono', 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.toy-top-bar .back-button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  color: #c8d8c8;
}

.toy-top-bar .back-button::before {
  content: '\2190';
  font-size: 0.85rem;
  line-height: 1;
}

.toy-top-bar .bar-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.toy-top-bar .toy-name {
  color: var(--toy-accent, #c8d8c8);
  font-family: 'Space Grotesk', 'IBM Plex Mono', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 2px;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toy-top-bar .bar-spacer {
  flex: 1;
}

.toy-top-bar .bar-about {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  color: #909898;
  text-decoration: none;
  font-family: 'Space Mono', 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.toy-top-bar .bar-about:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  color: #c8d8c8;
}

.toy-top-bar .bar-about svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toy-top-bar .bar-share {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  color: #909898;
  font-family: 'Space Mono', 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.toy-top-bar .bar-share:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  color: #c8d8c8;
}

.toy-top-bar .bar-share.copied {
  color: #00ffcc;
  border-color: rgba(0, 255, 204, 0.3);
  background: rgba(0, 255, 204, 0.06);
}

.toy-top-bar .bar-share svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Top bar icon accents per toy */
.bar-icon--binary {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: #00ffcc;
  letter-spacing: 2px;
  text-shadow: 0 0 6px rgba(0, 255, 204, 0.4);
  animation: binary-flicker 4s ease-in-out infinite;
}

.bar-icon--arp {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: #ff3333;
  letter-spacing: 3px;
  text-shadow: 0 0 8px rgba(255, 51, 51, 0.5);
  animation: arp-pulse 2s ease-in-out infinite;
}

.bar-icon--drum {
  display: inline-grid !important;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
}

.bar-icon--drum span {
  width: 8px;
  height: 8px;
  background: #ff9933;
  border-radius: 1px;
  animation: drum-tap 1.6s ease-in-out infinite;
}

.bar-icon--drum span:nth-child(2) { animation-delay: 0.2s; }
.bar-icon--drum span:nth-child(3) { animation-delay: 0.4s; }
.bar-icon--drum span:nth-child(4) { animation-delay: 0.6s; }

.bar-icon--metronome {
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  color: #00ffcc;
  font-weight: 700;
  animation: metro-tick 1s ease-in-out infinite;
  transform-origin: center top;
}

.bar-icon--circle {
  font-family: 'VT323', monospace;
  font-size: 20px;
  color: #00ffcc;
  text-shadow: 0 0 8px rgba(0, 255, 204, 0.4);
  animation: note-breathe 3s ease-in-out infinite;
}

.bar-icon--bath {
  width: 24px;
  height: 12px;
  border: 2px solid #00ffcc;
  border-radius: 50% 50% 0 0;
  border-bottom: none;
  opacity: 0.7;
  animation: wave 2s ease-in-out infinite;
}

.bar-icon--spiro {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background:
    conic-gradient(from 0deg, #ff3333, #ff9933, #eab308, #22c55e, #00ffcc, #3b82f6, #cc66ff, #ff66aa, #ff3333);
  -webkit-mask:
    radial-gradient(farthest-side, transparent calc(100% - 2px), #fff calc(100% - 2px));
  mask:
    radial-gradient(farthest-side, transparent calc(100% - 2px), #fff calc(100% - 2px));
  animation: spin 4s linear infinite;
}

.bar-icon--gravity {
  flex-direction: column;
  gap: 3px;
}

.bar-icon--gravity .g-ball {
  width: 6px;
  height: 6px;
  background: #fff;
  border-radius: 50%;
  animation: bounce 1s ease-in-out infinite;
}

.bar-icon--gravity .g-bar {
  width: 20px;
  height: 3px;
  background: linear-gradient(90deg, #ff3333, #ff9933);
  border-radius: 1px;
  transform: rotate(-15deg);
}

.bar-icon--cellular {
  display: inline-grid !important;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}

.bar-icon--cellular span {
  width: 5px;
  height: 5px;
  border-radius: 1px;
}

.bar-icon--cellular span.alive {
  background: #22c55e;
}

.bar-icon--cellular span.dead {
  background: rgba(34, 197, 94, 0.15);
}

.bar-icon--matrix {
  display: inline-grid !important;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
}

.bar-icon--matrix span {
  width: 4px;
  height: 4px;
  border-radius: 1px;
}

.bar-icon--matrix span.on {
  background: #00ffcc;
}

.bar-icon--matrix span.off {
  background: rgba(0, 255, 204, 0.15);
}

.bar-icon--pendulum {
  flex-direction: column;
  align-items: center;
  gap: 0;
  transform-origin: center top;
  animation: pendulum-bar-swing 1.5s ease-in-out infinite;
}

.bar-icon--pendulum .pw-string {
  width: 1px;
  height: 10px;
  background: rgba(245, 158, 11, 0.5);
}

.bar-icon--pendulum .pw-bob {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f59e0b;
}

@keyframes pendulum-bar-swing {
  0%, 100% { transform: rotate(-15deg); }
  50% { transform: rotate(15deg); }
}

.bar-icon--sound-wave-drawing {
  width: 24px;
  height: 14px;
  position: relative;
  overflow: hidden;
}

.bar-icon--sound-wave-drawing .swd-wave {
  display: block;
  width: 100%;
  height: 100%;
  background: #06b6d4;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 14'%3E%3Cpath d='M0 7 Q6 0 12 7 Q18 14 24 7 Q30 0 36 7 Q42 14 48 7' fill='none' stroke='white' stroke-width='3'/%3E%3C/svg%3E");
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 14'%3E%3Cpath d='M0 7 Q6 0 12 7 Q18 14 24 7 Q30 0 36 7 Q42 14 48 7' fill='none' stroke='white' stroke-width='3'/%3E%3C/svg%3E");
  -webkit-mask-size: cover;
  mask-size: cover;
  clip-path: inset(0 100% 0 0);
  animation: swd-draw 3s ease-in-out infinite;
}

@keyframes swd-draw {
  0% { clip-path: inset(0 100% 0 0); opacity: 0.5; }
  40% { clip-path: inset(0 0% 0 0); opacity: 1; }
  60% { clip-path: inset(0 0% 0 0); opacity: 1; }
  100% { clip-path: inset(0 0% 0 0); opacity: 0.5; }
}

/* Shared keyframes for bar icons */
@keyframes binary-flicker {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.6; }
  75% { opacity: 1; }
}

@keyframes arp-pulse {
  0%, 100% { text-shadow: 0 0 8px rgba(255, 51, 51, 0.5); }
  50% { text-shadow: 0 0 14px rgba(255, 51, 51, 0.8), 0 0 4px rgba(255, 51, 51, 0.3); }
}

@keyframes drum-tap {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

@keyframes metro-tick {
  0%, 100% { transform: rotate(-6deg); }
  50% { transform: rotate(6deg); }
}

@keyframes note-breathe {
  0%, 100% { transform: scale(1); text-shadow: 0 0 8px rgba(0, 255, 204, 0.4); }
  50% { transform: scale(1.1); text-shadow: 0 0 14px rgba(0, 255, 204, 0.6); }
}

@keyframes wave {
  0%, 100% { transform: translateY(1px) scaleY(1); opacity: 0.7; }
  50% { transform: translateY(-1px) scaleY(0.8); opacity: 1; }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(-3px); }
  50% { transform: translateY(1px); }
}

/* Visualization Controls (rendered into #viz-slot in the top bar) */
#viz-slot {
  display: contents;
}

.viz-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.viz-button {
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  color: #909898;
  font-family: 'Space Mono', 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.viz-button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  color: #c8d8c8;
}

.viz-button.active {
  border-color: var(--toy-accent, #cc66ff);
  color: var(--toy-accent, #cc66ff);
  background: rgba(255, 255, 255, 0.08);
}

/* Visualization Canvas */
.viz-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.viz-canvas.fullscreen {
  z-index: 50;
  background: rgba(12, 12, 16, 0.95);
}

/* Hide main content in viz-only mode */
body.viz-only .binary-container,
body.viz-only .stranger-container > *:not(.viz-canvas),
body.viz-only .editor-container {
  opacity: 0.1;
  pointer-events: none;
}

body.viz-only .viz-canvas {
  background: rgba(12, 12, 16, 0.95);
}

/* Responsive */
@media (max-width: 768px) {
  .toy-top-bar {
    height: 40px;
    padding: 0 10px;
    gap: 6px;
  }

  .toy-top-bar .back-button {
    padding: 4px 8px;
    font-size: 0.65rem;
  }

  .toy-top-bar .toy-name {
    font-size: 0.65rem;
    letter-spacing: 1px;
  }

  .toy-top-bar .bar-icon {
    display: none;
  }

  .toy-top-bar .bar-about span,
  .toy-top-bar .bar-share span {
    display: none;
  }

  .viz-button {
    padding: 4px 8px;
    font-size: 0.6rem;
  }
}
