@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;600&family=JetBrains+Mono:wght@400;700&display=swap');

:root {
    --bg-primary: #0a0e14;
    --bg-secondary: #1a1f29;
    --bg-tertiary: #252b38;
    --accent-green: #00ff88;
    --accent-amber: #ffb744;
    --accent-cyan: #00d4ff;
    --accent-orange: #ff8833;
    --text-primary: #e6e8eb;
    --text-secondary: #8a92a6;
    --border: #2d3543;
    --grid-line: rgba(0, 255, 136, 0.1);
    --shadow: rgba(0, 255, 136, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'IBM Plex Mono', monospace;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100%;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
}

.container {
    display: grid;
    grid-template-columns: 1fr 280px;
    grid-template-rows: 60px 1fr 200px;
    height: 100%;
    width: 100%;
    gap: 0;
    position: relative;
}

/* Header */
header {
    grid-column: 1 / -1;
    grid-row: 1;
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--accent-green);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    box-shadow: 0 2px 20px var(--shadow);
}

h1 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--accent-green);
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.header-actions button {
    height: 36px;
    padding: 0 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 4px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.header-actions button:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-cyan);
    color: var(--text-primary);
    transform: none;
    box-shadow: none;
}

.header-actions button.primary {
    background: var(--accent-green);
    color: var(--bg-primary);
    border-color: var(--accent-green);
    font-weight: 600;
}

.header-actions button.primary:hover {
    background: #00dd77;
    border-color: #00dd77;
    color: var(--bg-primary);
}

.header-actions button.icon-only {
    width: 36px;
    padding: 0;
    justify-content: center;
}

#eraserBtn.active {
    background: var(--accent-red);
    border-color: var(--accent-red);
    color: white;
}

#dustbin:hover {
    background: rgba(255, 68, 68, 0.1);
    border-color: #ff4444;
    color: #ff4444;
}

#dustbin.drag-over {
    background: rgba(255, 68, 68, 0.2);
    border-color: #ff4444;
    color: #ff4444;
    box-shadow: 0 0 20px rgba(255, 68, 68, 0.4);
    transform: scale(1.1);
}

.canvas.eraser-mode {
    cursor: crosshair;
}

.canvas.eraser-mode .grid-cell:hover {
    background: rgba(255, 68, 68, 0.1);
}

button {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 4px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

button:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-green);
    box-shadow: 0 0 10px var(--shadow);
    transform: translateY(-1px);
}

button.primary {
    background: var(--accent-green);
    color: var(--bg-primary);
    border-color: var(--accent-green);
    font-weight: 600;
}

button.primary:hover {
    background: #00dd77;
    box-shadow: 0 0 20px var(--shadow);
}

/* Sidebar - Gate Palette */
.gate-palette {
    grid-column: 1;
    grid-row: 3;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: row;
    gap: 0;
    height: 200px;
}

.palette-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-width: 0;
    padding: 0 12px;
}

.palette-column:first-child {
    padding-left: 0;
    border-right: 1px solid var(--border);
}

.palette-column:last-child {
    padding-right: 0;
}

.palette-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Measure + Group sit side by side */
.palette-section-row {
    display: flex;
    gap: 14px;
}

.palette-section-row .palette-section {
    flex: 1;
}

.palette-heading {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-amber);
    font-weight: 700;
    margin: 0 0 4px 0;
    white-space: nowrap;
    margin: 0;
}

.gate-grid {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.gate-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 0;
    text-align: center;
    cursor: grab;
    transition: all 0.2s;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-cyan);
    white-space: nowrap;
    width: 46px;
    box-sizing: border-box;
}

.gate-item * {
    pointer-events: none;
}

.gate-item:hover {
    background: var(--bg-primary);
    border-color: var(--accent-green);
    box-shadow: 0 0 15px var(--shadow);
    transform: translateY(-2px);
}

.gate-item:active {
    cursor: grabbing;
}

/* Canvas Area */
.canvas-area {
    grid-column: 1;
    grid-row: 2;
    background: var(--bg-primary);
    overflow: auto;
    position: relative;
    cursor: grab; /* Indicate panning is available */
}

.status-message {
    position: fixed;
    bottom: calc(48px + 12px); /* tab bar height + gap */
    right: 12px;
    background: rgba(0, 212, 255, 0.95);
    color: var(--bg-primary);
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    display: none;
    max-width: calc(100vw - 24px);
    line-height: 1.4;
    transition: bottom 0.3s ease;
}

.status-message.visible {
    display: block;
    animation: fadeIn 0.2s ease-in;
}

/* Automatically position above panel when open - no JS needed */
.mobile-panel.open ~ .status-message {
    bottom: calc(200px + 48px + 12px); /* panel max-height + tab bar + gap */
}

/* V5: Static mobile tab system */
.mobile-tab-content {
    display: none;
    height: 100%;
    overflow-y: auto;
}

.mobile-tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Properties sub-tabs */
.prop-subtabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.prop-subtab {
    flex: 1;
    padding: 8px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 10px;
    text-transform: uppercase;
    border-bottom: 2px solid transparent;
    font-family: 'IBM Plex Mono', monospace;
}

.prop-subtab.active {
    color: var(--accent-cyan);
    border-bottom-color: var(--accent-cyan);
}

.prop-pane {
    display: none;
    flex: 1;
    overflow-y: auto;
}

.prop-pane.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.canvas {
    display: inline-block; /* Allows width: fit-content to work properly */
    width: fit-content;
    min-width: 100%;
    min-height: 100%;
    padding: 40px;
    position: relative;
}

.qubit-row {
    display: flex;
    align-items: center;
    margin-bottom: 40px;
    position: relative;
    height: 60px;
}

.qubit-label {
    width: 80px;
    min-width: 80px;
    font-size: 18px;
    color: var(--accent-green);
    font-weight: 600;
    flex-shrink: 0;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: all 0.2s;
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    position: relative;
}

.wire-type-pill {
    position: absolute;
    top: 50%;
    left: 58px;
    transform: translateY(-50%);
    font-size: 8px;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 20px;
    cursor: pointer;
    user-select: none;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    transition: all 0.15s;
    white-space: nowrap;
    z-index: 20;
}

.wire-type-pill:hover {
    filter: brightness(1.2);
    transform: translateY(-50%) scale(1.15);
}

.wire-type-pill.type-q { background: rgba(0, 212, 255, 0.2); color: var(--accent-cyan); border: 1px solid var(--accent-cyan); }
.wire-type-pill.type-c { background: rgba(68, 255, 136, 0.2); color: var(--accent-green); border: 1px solid var(--accent-green); }
.wire-type-pill.type-b { background: rgba(255, 183, 68, 0.2); color: var(--accent-amber); border: 1px solid var(--accent-amber); }
.wire-type-pill.type-n { background: rgba(100, 100, 100, 0.2); color: var(--text-secondary); border: 1px solid var(--text-secondary); }

.qubit-label-brace {
    position: absolute;
    right: -15px;
    width: 20px;
    border: none;
    pointer-events: none;
    z-index: 4;
}

.qubit-label-brace::before,
.qubit-label-brace::after {
    content: '';
    position: absolute;
    left: 0;
    width: 6px;
    height: 50%;
    border: 2px solid var(--accent-green);
    border-right: none;
    box-sizing: border-box;
}

.qubit-label-brace::before {
    top: 0;
    border-bottom: none;
    border-top-left-radius: 8px;
}

.qubit-label-brace::after {
    bottom: 0;
    border-top: none;
    border-bottom-left-radius: 8px;
}

.qubit-label:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-green);
}

.qubit-label.selected {
    border-color: var(--accent-orange);
    background: var(--bg-tertiary);
    color: var(--accent-orange);
}

.qubit-label mjx-container {
    margin: 0 !important;
}

/* rstick — right-side label */
.rstick-label {
    width: 80px;
    min-width: 80px;
    font-size: 18px;
    color: var(--accent-green);
    font-weight: 600;
    flex-shrink: 0;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: all 0.2s;
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    position: relative;
}

.rstick-label:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-green);
}

.rstick-label.selected {
    border-color: var(--accent-orange);
    background: var(--bg-tertiary);
    color: var(--accent-orange);
}

.rstick-label mjx-container {
    margin: 0 !important;
}

/* } brace on the LEFT of the rstick label */
.rstick-label-brace {
    position: absolute;
    left: -15px;
    width: 20px;
    border: none;
    pointer-events: none;
    z-index: 4;
}

.rstick-label-brace::before,
.rstick-label-brace::after {
    content: '';
    position: absolute;
    right: 0;
    width: 6px;
    height: 50%;
    border: 2px solid var(--accent-green);
    border-left: none;
    box-sizing: border-box;
}

.rstick-label-brace::before {
    top: 0;
    border-bottom: none;
    border-top-right-radius: 8px;
}

.rstick-label-brace::after {
    bottom: 0;
    border-top: none;
    border-bottom-right-radius: 8px;
}

.rstick-label.selected .rstick-label-brace::before,
.rstick-label.selected .rstick-label-brace::after {
    border-color: var(--accent-orange);
}

.wire-container {
    flex: 1;
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
}

.wire {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 0;
    pointer-events: none;
}

.wire-line {
    height: 2px;
    background: var(--accent-green);
    box-shadow: 0 0 5px var(--shadow);
}

/* Wire type styling */
.wire.type-q .wire-line:first-child {
    transform: translateY(0);
}

.wire.type-c {
    height: 10px;
    gap: 6px;
}

.wire.type-b {
    height: 14px;
    gap: 3px;
}

.wire.type-n .wire-line {
    display: none;
}

.grid-cells {
    display: flex;
    position: relative;
    z-index: 1;
    height: 100%;
}

.grid-cell {
    width: 120px;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px dashed rgba(0, 255, 136, 0.05);
}

.grid-cell.available-target {
    background: rgba(0, 212, 255, 0.1);
    cursor: crosshair;
}

.grid-cell.available-target:hover {
    background: rgba(0, 212, 255, 0.2);
    outline: 2px solid var(--accent-cyan);
    outline-offset: -2px;
}

.grid-cell.gate-group-target {
    cursor: crosshair;
    background: rgba(255, 183, 68, 0.1);
}

.grid-cell.gate-group-target:hover {
    background: rgba(255, 183, 68, 0.2);
    outline: 2px solid var(--accent-amber);
    outline-offset: -2px;
}

.grid-cell.drop-target {
    background: rgba(0, 255, 136, 0.1);
    outline: 2px solid var(--accent-green);
    outline-offset: -2px;
}

.column-insert-indicator {
    position: absolute;
    width: 4px;
    background: var(--accent-amber);
    box-shadow: 0 0 10px var(--accent-amber);
    pointer-events: none;
    z-index: 20;
    opacity: 0;
    transition: opacity 0.15s;
}

.column-insert-indicator.active {
    opacity: 1;
}

.slice-line {
    position: absolute;
    width: 2px;
    background: repeating-linear-gradient(
        to bottom,
        #ff4444 0px,
        #ff4444 4px,
        transparent 4px,
        transparent 8px
    );
    pointer-events: none;
    z-index: 15;
    top: 0;
    bottom: 0;
}

.gate-on-canvas {
    background: var(--bg-tertiary);
    border: 2px solid var(--accent-cyan);
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-cyan);
    cursor: move;
    user-select: none;
    min-width: 60px;
    max-width: 110px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 255, 136, 0.3);
    transition: all 0.15s;
    position: relative;
    z-index: 10;
}

.gate-on-canvas:hover {
    border-color: var(--accent-green);
    box-shadow: 0 6px 25px var(--shadow);
    transform: scale(1.05);
}

.gate-on-canvas.dragging {
    opacity: 0.4;
}

.gate-on-canvas.selected {
    border-color: var(--accent-orange);
    color: var(--accent-orange);
    box-shadow: 0 0 25px rgba(255, 136, 51, 0.5);
}

.gate-on-canvas.special {
    /* Remove special coloring - all gates are cyan now */
}

.gate-on-canvas.multi-qubit-gate {
    padding: 16px 12px;
    font-size: 18px;
    font-weight: 700;
}

.gate-on-canvas.cnot-target,
.gate-on-canvas.swap-target {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    width: 50px;
    height: 50px;
    min-width: 50px;
    max-width: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gate-on-canvas.cnot-target svg,
.gate-on-canvas.swap-target svg {
    color: var(--accent-cyan);
}

.gate-on-canvas.cnot-target.selected svg,
.gate-on-canvas.swap-target.selected svg {
    color: var(--accent-orange);
}

.gate-on-canvas.ctrl-dot {
    background: transparent;
    border: 2px solid var(--bg-primary);
    box-shadow: 0 0 10px var(--shadow);
    padding: 0;
    min-width: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-cyan);
    cursor: move;
    position: relative;
}

.gate-on-canvas.ctrl-dot::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid var(--accent-cyan);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.2s;
}

.gate-on-canvas.ctrl-dot:hover::after {
    opacity: 0.5;
}

.gate-on-canvas.ctrl-dot.selected::after {
    opacity: 1;
    border-color: var(--accent-amber);
}

.gate-on-canvas.ctrl-dot-open {
    background: transparent;
    border: 2.5px solid var(--accent-cyan);
    box-shadow: none;
    padding: 0;
    min-width: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    cursor: move;
    position: relative;
}

.gate-on-canvas.ctrl-dot-open::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid var(--accent-cyan);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.2s;
}

.gate-on-canvas.ctrl-dot-open:hover::after {
    opacity: 0.5;
}

.gate-on-canvas.ctrl-dot-open.selected {
    border-color: var(--accent-amber);
}

.gate-on-canvas.ctrl-dot-open.selected::after {
    opacity: 1;
    border-color: var(--accent-amber);
}

.gate-on-canvas.measurement {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    padding: 8px 12px;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Modal overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* Modal content container */
.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Modal message text */
.modal-message {
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
}

/* Modal button container */
.modal-buttons {
    display: flex;
    gap: 8px;
}

/* Modal button */
.modal-button {
    flex: 1;
    padding: 10px;
}

.gate-on-canvas.measurement.selected {
    border-color: var(--accent-orange);
    color: var(--accent-orange);
}

.control-line-preview {
    position: absolute;
    width: 2px;
    background: var(--accent-cyan);
    opacity: 0.5;
    pointer-events: none;
    z-index: 15;
}

.control-dot-preview {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-cyan);
    opacity: 0.5;
    pointer-events: none;
    z-index: 16;
    transform: translate(-50%, -50%);
}

.gate-group-box {
    position: absolute;
    border: 2px dashed var(--accent-amber);
    border-radius: 8px;
    pointer-events: none;
    z-index: 2;
    background: rgba(255, 183, 68, 0.05);
}

.gate-group-label {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: var(--accent-amber);
    font-weight: 600;
    white-space: nowrap;
    background: var(--bg-primary);
    padding: 2px 8px;
    border-radius: 4px;
}

.control-line {
    position: absolute;
    width: 2px;
    background: var(--accent-cyan);
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    box-shadow: 0 0 5px var(--shadow);
    z-index: 5;
}

.control-dot {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-cyan);
    border: 2px solid var(--bg-primary);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px var(--shadow);
    z-index: 10;
}

.control-dot-open {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--bg-primary);
    border: 2px solid var(--accent-cyan);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px var(--shadow);
    z-index: 10;
}

/* Output Panel */
.output-panel {
    grid-column: 2;
    grid-row: 2 / 4;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

.tab-nav {
    display: flex;
    flex-direction: column;
    width: 44px;
    min-width: 44px;
    background: var(--bg-primary);
    border-left: 1px solid var(--border);
    align-items: center;
    padding: 8px 0;
    gap: 4px;
}

.tab-button {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    position: relative;
}

.tab-button svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.tab-button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.tab-button.active {
    color: var(--accent-green);
    background: var(--bg-secondary);
}

.tab-button::after {
    content: attr(data-tooltip);
    position: absolute;
    right: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 100;
    font-family: 'IBM Plex Mono', monospace;
}

.tab-button:hover::after {
    opacity: 1;
}


.tab-content {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    min-width: 0;
}

.tab-content.active {
    display: flex;
}

.property-section {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.property-section h3 {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-amber);
    margin-bottom: 12px;
    font-weight: 600;
}

.property-field {
    margin-bottom: 12px;
}

.property-field label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.property-field input[type="text"],
.property-field input[type="number"] {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 12px;
    color: var(--text-primary);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
}

.property-field input:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 10px var(--shadow);
}

.no-selection {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.6;
}

.output-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.output-header h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent-amber);
    margin-bottom: 12px;
    font-weight: 600;
}

.output-actions {
    display: flex;
    gap: 8px;
}

.output-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

textarea {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    line-height: 1.6;
    color: var(--accent-green);
    resize: vertical;
    min-height: 300px;
    flex: 1;
}

textarea:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 10px var(--shadow);
}


.qubit-controls {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.qubit-controls label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

input[type="number"] {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 12px;
    color: var(--text-primary);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 10px var(--shadow);
}

select {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 8px;
    color: var(--text-primary);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    margin-bottom: 8px;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--accent-green);
    box-shadow: 0 0 10px var(--shadow);
}

.wire-type-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.wire-type-item label {
    font-size: 11px;
    color: var(--accent-green);
    margin: 0;
    min-width: 30px;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border);
}

/* ── Mobile layout (<600px) ─────────────────────────────────────── */
/* Mobile-first layout (always active) */

    .container {
        grid-template-columns: 1fr;
        grid-template-rows: 52px 1fr;
    }

    header {
        padding: 0 10px;
        grid-column: 1;
        grid-row: 1;
    }

    h1 { font-size: 15px; }

    /* Shrink header buttons to icon-only on very small screens */
    @media (max-width: 640px) {
        .header-actions { gap: 4px; }
        .header-actions button { height: 32px; }
        .header-actions button:not(.icon-only) {
            width: 32px;
            padding: 0;
            justify-content: center;
        }
        /* Hide text nodes in buttons (Reset, Export PNG, Generate Code) */
        .header-actions button:not(.icon-only) svg { display: block; }
        #resetBtnText, #generateBtnText { display: none; }
    }

    /* Canvas fills remaining space above the fixed tab bar */
    .canvas-area {
        grid-column: 1;
        grid-row: 2;
        margin-bottom: 48px; /* room for fixed tab bar */
        padding-bottom: 0;
        transition: padding-bottom 0.25s ease;
    }
    
    /* Add padding when mobile panel is open so scrollbar is visible */
    .canvas-area.panel-open {
        padding-bottom: min(55vh, 200px); /* Match mobile panel max-height */
    }

    /* Ensure canvas content doesn't shrink below usable width */
    .qubit-row {
        min-width: max-content;
    }

    /* Hide desktop panels permanently */
    .output-panel { display: none !important; }
    .gate-palette  { display: none !important; }

    /* Show mobile UI always */
    .mobile-tab-bar { display: flex !important; }
    .mobile-panel   { display: block !important; }

    /* Mobile panel: only as tall as needed, max ~200px */
    .mobile-panel {
        height: auto;
        max-height: 200px;
    }

/* Mobile tab bar — fixed to bottom */
.mobile-tab-bar {
    display: none; /* Will be shown via !important in mobile styles above */
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 48px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    z-index: 200;
}

.mobile-tab-bar button {
    flex: 1;
    height: 48px;
    background: transparent;
    border: none;
    border-radius: 0;
    color: var(--text-secondary);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    transition: color 0.2s, background 0.2s;
    padding: 0;
}

.mobile-tab-bar button.active {
    color: var(--accent-cyan);
    border-top: 2px solid var(--accent-cyan);
    background: rgba(0,212,255,0.07);
}

/* CSS-based tab highlighting using data attributes */
.mobile-tab-bar[data-active="gates"] #mobileTabGates,
.mobile-tab-bar[data-active="properties"] #mobileTabProperties,
.mobile-tab-bar[data-active="code"] #mobileTabCode {
    color: var(--accent-cyan);
    border-top: 2px solid var(--accent-cyan);
    background: rgba(0,212,255,0.07);
}

/* Mobile sliding panel — fixed above tab bar, hidden on desktop */
.mobile-panel {
    display: none;
    position: fixed;
    bottom: 48px; left: 0; right: 0;
    height: auto;
    max-height: 55vh;
    background: var(--bg-secondary);
    border-top: 2px solid var(--border);
    z-index: 199;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.25s ease;
}

.mobile-panel.open {
    transform: translateY(0);
}

/* ── Touch / tablet support ─────────────────────────────────────────────── */

/* Prevent iOS callout / text selection during touch-drag */
.gate-item,
.gate-on-canvas {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;   /* let JS handle touch on these elements */
}

/* Canvas area: allow vertical scroll but let JS intercept horizontal */
#canvas {
    touch-action: pan-y;
}

/* Ghost element styling (created dynamically) */
#touch-drag-ghost {
    cursor: grabbing !important;
}
