/**
 * Noisemaker Shaders Demo - Layout & Structure
 * 
 * This file contains structural CSS for the shaders demo:
 * grid layouts, sizing, spacing, positioning.
 * 
 * Downstream consumers should import this file to inherit all structural
 * styles. Override colors by providing your own color variables.
 */

body {
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

#app-container {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#canvas-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Fixed canvas mode (default) */
body.fixed-canvas-mode #canvas-container,
body:not(.full-bleed-mode) #canvas-container {
  left: calc(500px + 3rem);
  width: calc(100vw - 500px - 3rem);
  height: 100vh;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  box-sizing: border-box;
}

body.fixed-canvas-mode #canvas,
body:not(.full-bleed-mode) #canvas {
  /* Square canvas, scales to fit available space */
  width: min(calc(100vw - 540px - 4rem), calc(100vh - 4rem));
  height: min(calc(100vw - 540px - 4rem), calc(100vh - 4rem));
  border: 1px solid var(--hf-accent-2);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Full bleed mode */
body.full-bleed-mode #canvas-container {
  left: 0;
  width: 100vw;
  height: 100vh;
  padding: 0;
  justify-content: center;
  z-index: 1;
}

body.full-bleed-mode #canvas {
  width: 100vw;
  height: 100vh;
  border: none;
  box-shadow: none;
}

#canvas {
  /* Checkerboard pattern to show alpha transparency */
  background: 
    repeating-conic-gradient(
      color-mix(in srgb, var(--hf-bg-surface) 60%, var(--hf-bg-base) 40%) 0% 25%, 
      color-mix(in srgb, var(--hf-bg-elevated) 50%, var(--hf-bg-surface) 50%) 0% 50%
    ) 
    50% / 20px 20px;
}

#left-panel {
  position: fixed;
  top: 1rem;
  left: 1rem;
  bottom: 1rem;
  width: 500px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  background: transparent;
  backdrop-filter: none;
  border: none;
  z-index: 1000;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

#left-panel::-webkit-scrollbar {
  display: none; /* Chrome/Safari/Opera */
}

.shader-effect {
  overflow: visible;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

/* Raise z-index when any dropdown is open */
.shader-effect:has(effect-select.open),
.shader-effect:has(select-dropdown.dropdown-open) {
  z-index: 100;
  overflow: visible;
}

.shader-effect:has(effect-select.open) .effect-content,
.shader-effect:has(select-dropdown.dropdown-open) .effect-content {
  overflow: visible;
}

.effect-title {
  background: color-mix(
    in srgb,
    var(--hf-accent-1) var(--hf-header-opacity),
    transparent var(--hf-header-transparency)
  );
  border-bottom: 1px solid var(--hf-border);
  padding: var(--hf-space-2) var(--hf-space-3);
  font-size: var(--hf-size-sm);
  font-weight: var(--hf-weight-bold);
  color: var(--hf-text-bright);
  text-transform: var(--hf-text-transform, lowercase);
  letter-spacing: var(--hf-tracking-wide);
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--hf-space-2);
  cursor: pointer;
  transition: background var(--hf-transition);
}

.effect-title-text {
  /* Placeholder for downstream customization */
  display: inline;
}

.effect-title:hover {
  background: color-mix(
    in srgb,
    var(--hf-accent-1) calc(var(--hf-header-opacity) + 5%),
    transparent calc(var(--hf-header-transparency) - 5%)
  );
}

.effect-title::before {
  content: '▼';
  font-size: 0.65rem;
  transition: transform 0.2s ease;
  order: -1;
}

.shader-effect.collapsed .effect-title::before {
  transform: rotate(-90deg);
}

.effect-content {
  padding: 0.5rem;
  overflow: visible;
}

.shader-effect.collapsed .effect-content {
  display: none;
}

/* Skipped effect styles */
.shader-effect.skipped {
  opacity: 0.5;
}

.shader-effect.skipped .effect-title {
  background: color-mix(
    in srgb,
    var(--hf-bg-elevated) 15%,
    transparent 85%
  );
}

.shader-effect.skipped .effect-title-text {
  text-decoration: line-through;
  color: color-mix(in srgb, var(--hf-text-dim) 60%, transparent 40%);
}

/* Prevent expansion when skipped */
.shader-effect.skipped .effect-title::before {
  opacity: 0.3;
}

.shader-effect.skipped .effect-title {
  cursor: default;
}

#dsl-run-btn:hover {
  background: color-mix(in srgb, var(--hf-accent) 50%, transparent 50%);
  border-color: var(--hf-accent);
}

#dsl-run-btn:active {
  background: color-mix(in srgb, var(--hf-accent) 70%, transparent 30%);
  transform: translateY(1px);
}

#dsl-editor:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--hf-accent) 50%, transparent 50%);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--hf-accent) 20%, transparent 80%);
}

#status {
  display: none;
  min-height: 20px;
  font-size: var(--hf-size-xs);
  color: var(--hf-accent);
}

#controls {
  background: transparent;
  border: 1px solid var(--hf-border-subtle);
  border-radius: var(--hf-radius);
  padding: 0.75rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.control-group {
  display: grid;
  grid-template-columns: 80px 1fr 35px;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

/* Disabled control - dependent on another control that is inactive */
.control-group.disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* Category tag bar - shows collapsed categories as clickable tags */
.category-tag-bar {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--hf-border-subtle);
}

/* When all categories collapsed, no border or padding below tag bar */
.category-tag-bar:not(:has(~ .category-group:not(.collapsed))) {
  padding-bottom: 0;
  border-bottom: none;
}

.category-tag-bar:empty {
  display: none;
}

/* Category group - wraps controls in a category */
.category-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-column: 1 / -1;
  gap: 0.5rem;
  position: relative;
}

/* Collapsed category - hidden */
.category-group.collapsed {
  display: none;
}

/* Category label - now used as expanded header */
.category-label {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: var(--hf-size-sm);
  font-weight: var(--hf-weight-semibold);
  color: color-mix(in srgb, var(--hf-text-dim) 85%, var(--hf-accent) 15%);
  text-transform: lowercase;
  letter-spacing: 0.03em;
  border-top: 1px solid var(--hf-border-subtle);
  margin: 0.5rem -0.5rem 0;
  padding: 0.5rem 0.5rem 0;
}

/* First category label - no margin or border above when after tag bar */
.category-group:first-child .category-label,
.category-tag-bar ~ .category-group:not(.collapsed) .category-label {
  margin-top: 0;
  border-top: none;
}

/* Restore border for non-first visible categories */
.category-group:not(.collapsed) ~ .category-group:not(.collapsed) .category-label {
  border-top: 1px solid var(--hf-border-subtle);
}

/* When tag bar is hidden, pull first category up to cancel effect padding */
.category-tag-bar[style*="display"] ~ .category-group:not(.collapsed) .category-label {
  margin-top: -0.5rem;
  border-top: 1px solid var(--hf-border-subtle);
}

.category-label .category-close {
  cursor: pointer;
  font-size: var(--hf-size-xs);
  opacity: 0.5;
  transition: opacity var(--hf-transition);
}

.category-label .category-close:hover {
  opacity: 1;
}

.control-header {
  display: contents;
}

.control-label {
  font-size: var(--hf-size-sm);
  font-weight: var(--hf-weight-semibold);
  color: color-mix(in srgb, var(--hf-text-normal) 85%, var(--hf-accent) 15%);
  text-transform: lowercase;
  letter-spacing: 0.03em;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.control-value {
  font-size: var(--hf-size-xs);
  font-family: var(--hf-font-family-mono);
  color: color-mix(in srgb, var(--hf-text-dim) 90%, var(--hf-accent) 10%);
  text-align: left;
}

/* Color picker input */
.control-color {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1.5rem;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--hf-accent) 35%, transparent 65%);
  border-radius: var(--hf-radius-sm);
  background: transparent;
  cursor: pointer;
}

.control-color::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.control-color::-webkit-color-swatch {
  border: none;
  border-radius: calc(var(--hf-radius-sm) - 2px);
}

.control-color::-moz-color-swatch {
  border: none;
  border-radius: calc(var(--hf-radius-sm) - 2px);
}

.control-slider {
  width: 100%;
  height: 1.125rem;
  -webkit-appearance: none;
  appearance: none;
  background: color-mix(in srgb, var(--hf-accent) 15%, transparent 85%);
  border-radius: var(--hf-radius-sm);
  outline: none;
  cursor: pointer;
  transition: background var(--hf-transition);
}

.control-slider:hover {
  background: color-mix(in srgb, var(--hf-accent) 22%, transparent 78%);
}

.control-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 0.875rem;
  height: 0.875rem;
  border-radius: 50%;
  background: var(--hf-accent);
  cursor: pointer;
  border: 2px solid color-mix(in srgb, var(--hf-accent) 100%, var(--hf-text-bright) 0%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: all var(--hf-transition);
}

.control-slider:hover::-webkit-slider-thumb {
  background: color-mix(in srgb, var(--hf-accent) 85%, var(--hf-text-bright) 15%);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

.control-slider::-moz-range-thumb {
  width: 0.875rem;
  height: 0.875rem;
  border-radius: 50%;
  background: var(--hf-accent);
  cursor: pointer;
  border: 2px solid color-mix(in srgb, var(--hf-accent) 100%, var(--hf-text-bright) 0%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: all var(--hf-transition);
}

.control-slider:hover::-moz-range-thumb {
  background: color-mix(in srgb, var(--hf-accent) 85%, var(--hf-text-bright) 15%);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

/* Scrollbar styling for left panel */
#left-panel::-webkit-scrollbar {
  width: 0.5rem;
}

#left-panel::-webkit-scrollbar-track {
  background: color-mix(in srgb, var(--hf-accent) 5%, transparent 95%);
  border-radius: var(--hf-radius-sm);
}

#left-panel::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--hf-accent) 30%, transparent 70%);
  border-radius: var(--hf-radius-sm);
  transition: background var(--hf-transition);
}

#left-panel::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--hf-accent) 50%, transparent 50%);
}

#status,
.status {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--hf-bg-base);
  border: 1px solid var(--hf-border);
  padding: 8px 12px;
  font-size: var(--hf-size-xs);
  color: var(--hf-text-dim);
  max-width: 300px;
  z-index: 1000;
  box-shadow: var(--hf-shadow-sm);
  border-radius: var(--hf-radius-sm);
}

#status.info,
.status.info {
  color: var(--hf-text-dim);
  border-color: var(--hf-border);
}

#status.error,
.status.error {
  color: var(--hf-red);
  border-color: var(--hf-red);
  box-shadow: 0 0 8px color-mix(in srgb, var(--hf-red) 50%, transparent 50%);
}

#status.success,
.status.success {
  color: var(--hf-green);
  border-color: var(--hf-green);
  box-shadow: 0 0 8px color-mix(in srgb, var(--hf-green) 50%, transparent 50%);
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-size: var(--hf-size-sm);
  color: var(--hf-text-dim);
}

/*
 * Effect Chain Styling
 * Applies "chain" styling (connected effects) ONLY to the dynamic effects list.
 * Static effects (Pipeline, DSL, Inputs) retain their original spacing.
 */

/* Container for the chain - ensure no gaps between effects */
#effect-controls-container {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Force effects in the chain to touch and be square by default */
#effect-controls-container .shader-effect {
  margin-bottom: 0 !important; /* Override inline styles */
  border-radius: 0;
  border-bottom: none; /* Prevent double borders */
}

/* Start of a chain: First child, read node, read3d node, OR element after a terminal write/write3d node */
#effect-controls-container .shader-effect:first-child,
#effect-controls-container .shader-effect[data-effect-name="read"],
#effect-controls-container .shader-effect[data-effect-name="read3d"],
#effect-controls-container .shader-effect[data-effect-name="write"]:not([data-mid-chain="true"]) + .shader-effect,
#effect-controls-container .shader-effect[data-effect-name="write3d"]:not([data-mid-chain="true"]) + .shader-effect {
  border-top-left-radius: var(--hf-radius);
  border-top-right-radius: var(--hf-radius);
}

/* End of a chain: Write/write3d node OR Last child */
#effect-controls-container .shader-effect[data-effect-name="write"],
#effect-controls-container .shader-effect[data-effect-name="write3d"],
#effect-controls-container .shader-effect:last-child {
  border-bottom-left-radius: var(--hf-radius);
  border-bottom-right-radius: var(--hf-radius);
  border-bottom: 1px solid var(--hf-border);
}

/* Restore spacing after a chain ends (after terminal write/write3d node, not mid-chain) */
#effect-controls-container .shader-effect[data-effect-name="write"]:not([data-mid-chain="true"]),
#effect-controls-container .shader-effect[data-effect-name="write3d"]:not([data-mid-chain="true"]) {
  margin-bottom: 0.5rem !important;
}

/* Mid-chain writes: no bottom radius, connect to next effect */
#effect-controls-container .shader-effect[data-mid-chain="true"] {
  border-bottom-left-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}

/* Effect following a mid-chain write: no top radius, connect to previous */
#effect-controls-container .shader-effect[data-mid-chain="true"] + .shader-effect {
  border-top-left-radius: 0 !important;
  border-top-right-radius: 0 !important;
}

/* =========================================================================
   Media Input Section
   ========================================================================= */

.media-input-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid color-mix(in srgb, var(--hf-accent) 15%, transparent 85%);
}

.media-input-section .control-group {
  grid-column: 1 / -1;
  grid-template-columns: 80px 1fr;
}

.media-source-radios {
  display: flex;
  gap: 1rem;
}

.media-source-radios label {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: var(--hf-size-sm);
  color: var(--hf-text-normal);
  cursor: pointer;
}

.media-source-radios input[type="radio"] {
  accent-color: var(--hf-accent);
}

.media-file-input {
  width: 100%;
  font-size: var(--hf-size-sm);
  color: var(--hf-text-normal);
}

.media-file-input::file-selector-button {
  padding: 0.2rem 0.5rem;
  font-size: var(--hf-size-xs);
  font-family: var(--hf-font-family);
  font-weight: 600;
  text-transform: lowercase;
  background: color-mix(in srgb, var(--hf-accent) 15%, transparent 85%);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-radius-sm);
  color: var(--hf-text-normal);
  cursor: pointer;
  margin-right: 0.5rem;
  transition: all var(--hf-transition);
}

.media-file-input::file-selector-button:hover {
  background: color-mix(in srgb, var(--hf-accent) 25%, transparent 75%);
  border-color: color-mix(in srgb, var(--hf-accent) 40%, transparent 60%);
}

.media-camera-group .control-select {
  grid-column: 2;
}

.media-camera-buttons {
  grid-column: 2;
  display: flex;
  gap: 0.5rem;
}

.media-camera-buttons .action-btn {
  flex: 1;
}

.media-status {
  font-size: var(--hf-size-xs);
  color: var(--hf-text-dim);
  font-style: italic;
}

/* Mesh input section - sits inside the 2-column controlsDiv grid */
.mesh-input-section {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.mesh-file-input {
  width: 100%;
  font-size: var(--hf-size-sm);
  color: var(--hf-text-normal);
}

.mesh-file-input::file-selector-button {
  padding: 0.2rem 0.5rem;
  font-size: var(--hf-size-xs);
  font-family: var(--hf-font-family);
  font-weight: 600;
  text-transform: lowercase;
  background: color-mix(in srgb, var(--hf-accent) 15%, transparent 85%);
  border: 1px solid var(--hf-border);
  border-radius: var(--hf-radius-sm);
  color: var(--hf-text-normal);
  cursor: pointer;
  margin-right: 0.5rem;
  transition: all var(--hf-transition);
}

.mesh-file-input::file-selector-button:hover {
  background: color-mix(in srgb, var(--hf-accent) 25%, transparent 75%);
  border-color: color-mix(in srgb, var(--hf-accent) 40%, transparent 60%);
}

.mesh-status {
  font-size: var(--hf-size-xs);
  color: var(--hf-text-dim);
  font-style: italic;
}

/* Ecosystem info text */
.noisemaker-info {
  font-size: var(--hf-size-xs);
  color: color-mix(in srgb, var(--hf-text-dim) 60%, transparent 40%);
  line-height: 1.4;
  padding: 0.5rem 0.5rem 0.75rem;
  text-align: center;
}

.noisemaker-info a {
  color: var(--hf-accent);
  text-decoration: none;
}

.noisemaker-info a:hover {
  opacity: 0.8;
}

/* Responsive: mobile — exact noisedeck pattern */
@media (max-width: 960px) {
  body {
    overflow: hidden;
    height: 100dvh;
    width: 100vw;
  }

  #app-container {
    display: flex !important;
    flex-direction: column !important;
    height: 100vh;
    height: 100dvh;
  }

  body.fixed-canvas-mode #canvas-container,
  body:not(.full-bleed-mode) #canvas-container {
    position: relative !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: calc(100dvh * var(--mobile-canvas-fraction, 0.35)) !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
    order: -1;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  body.fixed-canvas-mode #canvas,
  body:not(.full-bleed-mode) #canvas {
    max-width: 100% !important;
    max-height: 100% !important;
    width: auto !important;
    height: auto !important;
    border: none !important;
    box-shadow: none !important;
  }

  #mobile-divider {
    height: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: row-resize;
    touch-action: none;
    user-select: none;
    flex-shrink: 0;
  }

  #mobile-divider::after {
    content: '';
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--hf-accent);
  }

  #left-panel {
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
    bottom: auto !important;
    width: 100% !important;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem;
  }

  #controls {
    grid-template-columns: 1fr;
  }

  .category-group {
    grid-template-columns: 1fr;
  }

  .media-input-section,
  .mesh-input-section {
    grid-template-columns: 1fr;
  }

  #status,
  .status {
    position: relative;
    bottom: auto;
    right: auto;
    max-width: none;
  }

  .loading {
    height: calc(100dvh * var(--mobile-canvas-fraction, 0.35));
  }
}

/* Desktop: hide mobile-only elements */
@media (min-width: 961px) {
  #mobile-divider {
    display: none;
  }
}
