/* Gate Grid Container - Scrollable */
.gate-grid-container {
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}

.gate-grid-container::-webkit-scrollbar {
    width: 6px;
}

.gate-grid-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.gate-grid-container::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.3);
    border-radius: 3px;
}

.gate-grid-container::-webkit-scrollbar-thumb:hover {
    background: rgba(212, 175, 55, 0.5);
}

/* Gate Categories */
.gate-category {
    margin-bottom: 16px;
}

.gate-category:last-child {
    margin-bottom: 0;
}

.gate-category-label {
    font-size: 0.7em;
    font-weight: 600;
    color: rgba(212, 175, 55, 0.6);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(212, 175, 55, 0.15);
}

.gate-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 0;
    overflow: visible;
}

/* State Grid Container - Scrollable (matching gate grid style) */
.state-grid-container {
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}

.state-grid-container::-webkit-scrollbar {
    width: 6px;
}

.state-grid-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.state-grid-container::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.3);
    border-radius: 3px;
}

.state-grid-container::-webkit-scrollbar-thumb:hover {
    background: rgba(212, 175, 55, 0.5);
}

/* State Categories (matching gate categories) */
.state-category {
    margin-bottom: 16px;
}

.state-category:last-child {
    margin-bottom: 0;
}

.state-category-label {
    font-size: 0.7em;
    font-weight: 600;
    color: rgba(212, 175, 55, 0.6);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(212, 175, 55, 0.15);
}

.viz-settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.gate-info {
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 14px 16px;
    font-size: 0.9em;
    color: rgba(244, 228, 176, 0.9);
    text-align: center;
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.35s ease;
    font-style: normal;
    line-height: 1.6;
    letter-spacing: 0.3px;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.35);
}

.gate-info.active {
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.22), rgba(212, 175, 55, 0.08));
    border-color: rgba(212, 175, 55, 0.7);
    color: var(--gold-light);
    box-shadow: 0 0 18px rgba(212, 175, 55, 0.35);
    animation: gateInfoPulse 0.4s ease-out;
}

.gate-sequence {
    margin-top: 14px;
    padding: 12px;
    border-radius: 12px;
    border: 1px dashed rgba(212, 175, 55, 0.35);
    background: rgba(0, 0, 0, 0.18);
    min-height: 64px;
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    position: relative;
}

.gate-sequence.empty::before {
    content: 'Drag gates here to build a circuit';
    color: rgba(212, 175, 55, 0.45);
    font-style: italic;
    font-size: 0.9em;
}

.gate-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: rgba(212, 175, 55, 0.15);
    border: 1px solid rgba(212, 175, 55, 0.35);
    border-radius: 999px;
    color: var(--gold-light);
    font-family: var(--font-main);
    font-size: 0.85em;
    cursor: grab;
    user-select: none;
    position: relative;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1),
        box-shadow 0.25s cubic-bezier(0.2, 0.8, 0.2, 1),
        opacity 0.25s ease;
}

.gate-chip:not(:last-child)::after {
    content: '→';
    position: absolute;
    right: -16px;
    color: rgba(212, 175, 55, 0.55);
    font-size: 0.85em;
    pointer-events: none;
}

.gate-chip.dragging {
    opacity: 0.35;
    transform: scale(1.08) rotate(-1.5deg);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
    cursor: grabbing;
}

.gate-chip-placeholder {
    width: 40px;
    height: 32px;
    border: 1px dashed rgba(212, 175, 55, 0.4);
    border-radius: 999px;
    background: rgba(212, 175, 55, 0.05);
    animation: placeholderPulse 1.5s ease-in-out infinite;
}

@keyframes placeholderPulse {

    0%,
    100% {
        opacity: 0.4;
        transform: scale(0.95);
    }

    50% {
        opacity: 0.8;
        transform: scale(1.05);
    }
}

/* Touch drag-and-drop feedback on mobile */
.gate-sequence.touch-drag-active {
    border-color: rgba(212, 175, 55, 0.45) !important;
    background: rgba(212, 175, 55, 0.04) !important;
    transition: all 0.2s ease;
}

.gate-sequence.touch-drag-hover {
    border-color: rgba(212, 175, 55, 0.7) !important;
    background: rgba(212, 175, 55, 0.08) !important;
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.12), inset 0 0 20px rgba(212, 175, 55, 0.04);
}

.gate-chip.active {
    border-color: var(--gold);
    box-shadow: 0 0 18px rgba(212, 175, 55, 0.55);
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.35), rgba(212, 175, 55, 0.15));
}

.gate-chip small {
    font-family: var(--font-main);
    font-size: 0.75em;
    opacity: 0.7;
}

.gate-chip-remove {
    border: none;
    background: rgba(0, 0, 0, 0.35);
    color: var(--gold-light);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.8em;
    line-height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.gate-chip-tooltip {
    position: absolute;
    width: 110px;
    padding: 10px;
    border-radius: 12px;
    border: 1px solid rgba(212, 175, 55, 0.45);
    background: rgba(10, 10, 10, 0.98);
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 25px rgba(212, 175, 55, 0.12);
    z-index: 4000;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}

.gate-chip-tooltip::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
}

.gate-chip-tooltip[data-placement="top"]::after {
    bottom: -7px;
    left: 50%;
    transform: translateX(-50%);
    border-top: 7px solid rgba(212, 175, 55, 0.45);
}

.gate-chip-tooltip[data-placement="bottom"]::after {
    top: -7px;
    left: 50%;
    transform: translateX(-50%);
    border-bottom: 7px solid rgba(212, 175, 55, 0.45);
}

.gate-chip-tooltip.active {
    display: flex;
    animation: popoverFadeIn 0.15s ease-out;
}

.gate-chip-tooltip-canvas {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    border: 1px solid rgba(212, 175, 55, 0.35);
    background: radial-gradient(circle at 30% 30%, rgba(212, 175, 55, 0.25), rgba(0, 0, 0, 0.4));
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.4);
}

/* Gate Button Preview Tooltip */
.gate-preview-tooltip {
    position: fixed;
    width: 180px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(212, 175, 55, 0.45);
    background: rgba(10, 10, 10, 0.98);
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 25px rgba(212, 175, 55, 0.12);
    z-index: 5000;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.gate-preview-tooltip::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
}

.gate-preview-tooltip[data-placement="top"]::after {
    bottom: -7px;
    left: 50%;
    transform: translateX(-50%);
    border-top: 7px solid rgba(212, 175, 55, 0.45);
}

.gate-preview-tooltip[data-placement="bottom"]::after {
    top: -7px;
    left: 50%;
    transform: translateX(-50%);
    border-bottom: 7px solid rgba(212, 175, 55, 0.45);
}

.gate-preview-tooltip.active {
    display: flex;
    animation: popoverFadeIn 0.15s ease-out;
}

.gate-preview-tooltip-arrow {
    position: absolute;
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
}

.gate-preview-tooltip[data-placement="top"]>.gate-preview-tooltip-arrow {
    bottom: -7px;
    left: 50%;
    transform: translateX(-50%);
    border-top: 7px solid rgba(212, 175, 55, 0.45);
}

.gate-preview-tooltip[data-placement="bottom"]>.gate-preview-tooltip-arrow {
    top: -7px;
    left: 50%;
    transform: translateX(-50%);
    border-bottom: 7px solid rgba(212, 175, 55, 0.45);
}

.gate-preview-tooltip-header {
    font-family: var(--font-display);
    font-size: 13px;
    color: rgba(244, 228, 176, 0.95);
    text-align: center;
    letter-spacing: 0.5px;
}

.gate-preview-tooltip-matrix {
    font-family: var(--font-main);
    font-size: 14px;
    color: rgba(244, 228, 176, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.gate-preview-tooltip-matrix .matrix-bracket {
    font-size: 32px;
    font-weight: 100;
    color: rgba(212, 175, 55, 0.7);
    line-height: 1;
}

.gate-preview-tooltip-matrix .matrix-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 10px;
    text-align: center;
}

.gate-preview-tooltip-matrix .matrix-cell {
    min-width: 28px;
}

.gate-preview-tooltip-canvas {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 1px solid rgba(212, 175, 55, 0.35);
    background: radial-gradient(circle at 30% 30%, rgba(212, 175, 55, 0.25), rgba(0, 0, 0, 0.4));
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.4);
}

.gate-preview-tooltip-label {
    font-family: var(--font-main);
    font-size: 11px;
    color: rgba(244, 228, 176, 0.6);
    text-align: center;
}

/* Measurement Gate Buttons - distinct teal accent */
.quantum-btn.gate-measurement {
    border-color: rgba(52, 152, 219, 0.4);
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.12), rgba(52, 152, 219, 0.04));
}

.quantum-btn.gate-measurement:hover {
    border-color: rgba(52, 152, 219, 0.7);
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.25), rgba(52, 152, 219, 0.1));
    box-shadow: 0 0 16px rgba(52, 152, 219, 0.25);
}

.quantum-btn.gate-measurement .btn-symbol {
    background: linear-gradient(135deg, rgba(127, 200, 248, 0.95), rgba(52, 152, 219, 0.9));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.quantum-btn.gate-measurement .btn-symbol sub {
    font-size: 0.7em;
    -webkit-text-fill-color: inherit;
}

/* Measurement Gate Chips in sequence */
.gate-chip.gate-chip-measurement {
    border-color: rgba(52, 152, 219, 0.45);
    background: rgba(52, 152, 219, 0.15);
}

.gate-chip.gate-chip-measurement.active {
    border-color: rgba(52, 152, 219, 0.8);
    box-shadow: 0 0 18px rgba(52, 152, 219, 0.45);
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.35), rgba(52, 152, 219, 0.15));
}

/* ── Parametric Gate Tooltip ── */
.param-gate-tooltip {
    display: none;
    position: fixed;
    z-index: 6000;
    width: 240px;
    padding: 14px 16px 16px;
    border-radius: 16px;
    border: 1px solid rgba(212, 175, 55, 0.5);
    background: rgba(12, 12, 16, 0.97);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow:
        0 24px 64px rgba(0, 0, 0, 0.7),
        0 0 30px rgba(212, 175, 55, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    flex-direction: column;
    align-items: center;
    gap: 12px;
    pointer-events: auto;
}

.param-gate-tooltip.active {
    display: flex;
    animation: paramTooltipIn 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes paramTooltipIn {
    from {
        opacity: 0;
        transform: scale(0.92) translateY(6px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.param-gate-tooltip-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
    color: var(--gold-light);
    letter-spacing: 0.5px;
}

.param-gate-tooltip-close {
    background: none;
    border: none;
    color: rgba(244, 228, 176, 0.5);
    font-size: 18px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    transition: color 0.15s ease;
}

.param-gate-tooltip-close:hover {
    color: var(--gold-light);
}

.param-gate-tooltip-canvas {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 1px solid rgba(212, 175, 55, 0.3);
    background: radial-gradient(circle at 30% 30%, rgba(212, 175, 55, 0.2), rgba(0, 0, 0, 0.5));
    box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.5);
}

.param-gate-tooltip-controls {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.param-slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.param-slider-label {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 600;
    color: rgba(212, 175, 55, 0.8);
    min-width: 14px;
    text-align: center;
    flex-shrink: 0;
}

.param-slider {
    flex: 1;
    min-width: 0;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(212, 175, 55, 0.2);
    border-radius: 2px;
    outline: none;
}

.param-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--gold);
    cursor: pointer;
    box-shadow: 0 0 6px rgba(212, 175, 55, 0.4);
}

.param-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--gold);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 6px rgba(212, 175, 55, 0.4);
}

.param-slider-value {
    font-family: var(--font-main);
    font-size: 11px;
    color: rgba(244, 228, 176, 0.7);
    min-width: 42px;
    text-align: right;
    flex-shrink: 0;
}

.param-gate-apply {
    width: 100%;
    padding: 8px 16px;
    font-size: 0.85em;
    font-weight: 600;
    letter-spacing: 0.5px;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.2), rgba(212, 175, 55, 0.08));
    border: 1px solid rgba(212, 175, 55, 0.5);
    color: var(--gold-light);
    cursor: pointer;
    transition: all 0.2s ease;
}

.param-gate-apply:hover {
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.35), rgba(212, 175, 55, 0.15));
    border-color: rgba(212, 175, 55, 0.8);
    box-shadow: 0 0 18px rgba(212, 175, 55, 0.3);
}

.param-gate-apply:active {
    transform: scale(0.97);
}