/* Carbon Nanotube Studio Component */

.cp-carbon-nanotube-studio {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--bg);
  overflow: hidden;

  /* Toggle button - matches Menu text style from header, mirrors hamburger position */
  & .sidebar-toggle {
    position: fixed;
    top: var(--xs);
    left: max(1.5rem, calc((100vw - var(--wide)) / 2 + 1.5rem));
    z-index: 1001;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 40px;
    padding: 0;
    background: none;
    border: none;
    color: var(--text);
    font-family: var(--ubuntu);
    font-size: 1.3rem;
    font-weight: var(--bold);
    cursor: pointer;
    transition: opacity var(--fast);
  }


  & .toggle-arrow {
    font-size: 1.3rem;
    line-height: 1;
  }

  & .toggle-label {
    display: none;
  }

  @media (min-width: 450px) {
    & .toggle-label {
      display: inline;
    }
  }

  @media (min-width: 768px) {
    & .sidebar-toggle {
      height: 50px;
    }
  }

  @media (min-width: 1100px) {
    & .sidebar-toggle {
      height: 60px;
    }
  }

  /* Sidebar controls - always off-canvas, slides in from left */
  & .controls {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    max-width: 480px;
    height: 100vh;
    height: 100dvh;
    z-index: 1100;
    background: var(--bg);
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    transform: translateX(-100%);
    transition: transform var(--normal), visibility var(--normal);
    visibility: hidden;
    overflow-y: auto;
    padding: var(--sm);
    font-family: var(--ubuntu);
    color: var(--text-2);
    font-size: var(--small);
    display: flex;
    flex-direction: column;
  }

  & .controls.open {
    transform: translateX(0);
    visibility: visible;
  }


  /* Studio branding header — matches fullscreen page header height */
  & .studio-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
    margin: calc(-1 * var(--sm)) calc(-1 * var(--sm)) 0;
    padding: var(--xs) var(--sm);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  @media (min-width: 768px) {
    & .studio-header {
      min-height: 66px;
    }
  }

  @media (min-width: 1100px) {
    & .studio-header {
      min-height: 76px;
    }
  }

  & .studio-title {
    font-size: var(--body);
    font-weight: var(--bold);
    color: var(--text);
    letter-spacing: 1px;
  }

  & .controls-close {
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 2rem;
    font-family: var(--ubuntu);
    cursor: pointer;
    padding: 0;
    line-height: 1;
  }

  /* Collapsible sections using native details/summary */
  & details {
    margin-top: var(--sm);
    margin-bottom: var(--xs);
    border-bottom: 1px solid var(--border);
    padding-bottom: var(--xs);
  }

  & summary {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--xs);
    font-size: var(--small);
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    list-style: none;
    user-select: none;
  }

  & summary::-webkit-details-marker {
    display: none;
  }

  & summary::after {
    content: "\25BE";
    font-size: var(--small);
    color: var(--text-3);
    transition: transform var(--fast);
    transform: rotate(0deg);
  }

  & details:not([open]) > summary::after {
    transform: rotate(90deg);
  }

  & details:not([open]) > summary {
    margin-bottom: 0;
  }

  /* Slider row */
  & .slider-row {
    margin-bottom: var(--xs);
  }

  & .slider-label {
    display: flex;
    justify-content: space-between;
    font-size: var(--small);
    color: var(--text-2);
    margin-bottom: 2px;
  }

  & .slider-value {
    color: var(--text);
    font-family: var(--mono);
  }

  & input[type="range"] {
    width: 100%;
    cursor: pointer;
    border: none;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--white-10);
  }

  & input[type="range"]:hover {
    outline: none;
    border: none;
  }

  & input[type="range"]:focus {
    outline: none;
    border: none;
  }

  & input[type="range"]:focus::-webkit-slider-thumb {
    background: var(--text);
  }

  & input[type="range"]:focus::-moz-range-thumb {
    background: var(--text);
  }

  & input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    background: transparent;
    border: none;
  }

  & input[type="range"]::-moz-range-track {
    height: 4px;
    background: var(--white-10);
    border: none;
    border-radius: 2px;
  }

  & input[type="range"]::-moz-range-progress {
    height: 4px;
    background: var(--accent);
    border-radius: 2px;
  }

  & input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    margin-top: -5px;
  }

  & input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
  }

  /* Chirality type display */
  & .chirality-type {
    font-size: var(--small);
    color: var(--text-3);
    margin-top: 2px;
  }

  /* Shape handle groups */
  & .handle-group {
    margin-bottom: 6px;
  }

  & .handle-label {
    font-size: var(--small);
    color: var(--text-3);
    letter-spacing: 1px;
    margin-bottom: 2px;
  }

  & .handle-sliders {
    display: flex;
    gap: var(--sm);
  }

  & .handle-sliders > div {
    flex: 1;
  }

  & .shape-hint {
    font-size: var(--small);
    color: var(--text-3);
    margin-top: 2px;
  }

  /* Reset button */
  & .reset-shape {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-3);
    font-size: var(--small);
    padding: 2px 8px;
    cursor: pointer;
    border-radius: 3px;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-family: var(--ubuntu);
    transition: border-color var(--fast), color var(--fast);
  }

  & .reset-shape:hover {
    border-color: var(--text-3);
    color: var(--text-2);
  }

  & .shape-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 6px;
  }

  /* Color preset buttons */
  & .preset-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: var(--xs);
    margin-bottom: var(--xs);
  }

  & .preset-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-3);
    padding: var(--xs);
    font-size: var(--small);
    cursor: pointer;
    border-radius: 3px;
    display: flex;
    align-items: center;
    gap: var(--xs);
    font-family: var(--ubuntu);
    transition: border-color var(--fast), color var(--fast);
  }

  & .preset-btn:hover {
    border-color: var(--text-3);
    color: var(--text-2);
  }

  & .preset-btn.active {
    border: 2px solid var(--swatch);
    color: var(--text);
  }

  & .preset-swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--swatch);
    flex-shrink: 0;
  }

  /* Lighting hint */
  & .lighting-hint {
    font-size: var(--small);
    color: var(--text-3);
    margin-top: 2px;
  }

  /* Auto-rotate checkbox */
  & .auto-rotate-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--small);
    color: var(--text-2);
    cursor: pointer;
  }

  & .auto-rotate-label input[type="checkbox"] {
    accent-color: var(--accent);
  }

  & .camera-hint {
    font-size: var(--small);
    color: var(--text-3);
    margin-top: 6px;
  }

  /* Action buttons at sidebar bottom */
  & .action-buttons {
    margin-top: auto;
    padding-top: var(--sm);
    display: flex;
    flex-direction: column;
    gap: var(--xs);
  }

  & .action-buttons .button {
    width: 100%;
    text-align: center;
  }

  & .transparent-bg-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--small);
    color: var(--text-2);
    cursor: pointer;
  }

  & .transparent-bg-label input[type="checkbox"] {
    accent-color: var(--accent);
  }

  /* Three.js canvas wrapper - fills entire container */
  & .canvas-wrapper {
    position: absolute;
    inset: 0;
    cursor: grab;
    transition: background var(--normal);
  }

  & .canvas-wrapper.grabbing {
    cursor: grabbing;
  }

  & .canvas-wrapper canvas {
    display: block;
    width: 100%;
    height: 100%;
  }

  /* Toast notification */
  & .studio-notification {
    position: absolute;
    bottom: var(--lg);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg);
    border: 1px solid var(--accent);
    color: var(--text);
    padding: var(--xs) var(--sm);
    font-size: var(--small);
    font-family: var(--ubuntu);
    border-radius: 3px;
    pointer-events: none;
    opacity: 1;
    transition: opacity var(--normal);
    z-index: 10;
  }

  /* WebGL fallback */
  & .webgl-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-3);
    font-size: var(--body);
    padding: var(--lg);
    text-align: center;
  }
}

/* Notification fade animation - must be at root level */
@keyframes cp-carbon-nanotube-studio-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}
