/**
 * CQM Quantum Simulator - Responsive Styles v2.0
 * Mobile-First, Fully Responsive Design
 * Supports: Mobile (320px+), Tablet (768px+), Desktop (1024px+), Large (1440px+)
 */

/* ============================================
   CSS Variables & Design Tokens
   ============================================ */
:root {
    /* Colors */
    --cqm-primary: #0652DD;
    --cqm-secondary: #4a148c;
    --cqm-accent: #00d4ff;
    --cqm-success: #4CAF50;
    --cqm-warning: #FF9800;
    --cqm-error: #f44336;
    --cqm-dark: #0d111c;
    --cqm-darker: #070a10;

    /* Shadows */
    --cqm-glow: 0 0 20px rgba(6, 82, 221, 0.5);
    --cqm-glow-accent: 0 0 20px rgba(0, 212, 255, 0.5);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
    --font-mono: 'Monaco', 'Menlo', 'Courier New', monospace;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;
    --transition-slow: 500ms ease;

    /* Z-index layers */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-modal: 1000;
    --z-tooltip: 1100;
    --z-notification: 1200;

    /* Layout */
    --header-height: 64px;
    --footer-height: auto;
    --sidebar-width: 280px;
    --sidebar-width-collapsed: 60px;
}

/* ============================================
   Base Reset & Global Styles
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e40af 100%);
    color: white;
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* ============================================
   Utility Classes
   ============================================ */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   App Container - Responsive Layout
   ============================================ */
#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
    min-height: 0;
    overflow: hidden;
}

/* ============================================
   Header - Responsive
   ============================================ */
.quantum-header {
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 2px solid var(--cqm-accent);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
}

.header-content {
    max-width: 1600px;
    margin: 0 auto;
    padding: var(--space-sm) var(--space-md);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-sm);
}

/* Mobile Header */
@media (max-width: 767px) {
    .header-content {
        padding: var(--space-sm);
    }

    .header-logo {
        flex: 0 0 auto;
        text-decoration: none;
        color: inherit;
    }

    a.header-logo:hover {
        opacity: 0.9;
    }

    .header-logo h1 {
        font-size: 1.25rem !important;
    }

    .header-logo h2 {
        font-size: 0.875rem !important;
    }

    .header-logo p {
        display: none;
    }

    .header-controls {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: var(--space-sm);
        padding-top: var(--space-sm);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .header-controls.show {
        display: flex;
    }

    .mobile-menu-btn {
        display: flex !important;
    }

    .view-mode-selector {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .header-actions {
        width: 100%;
        justify-content: center;
    }
}

/* Tablet Header */
@media (min-width: 768px) and (max-width: 1023px) {
    .header-content {
        padding: var(--space-md);
    }

    .header-logo h1 {
        font-size: 1.5rem;
    }

    .header-controls {
        flex-wrap: wrap;
        justify-content: flex-end;
    }
}

/* Desktop Header */
@media (min-width: 1024px) {
    .header-content {
        padding: var(--space-md) var(--space-lg);
        flex-wrap: nowrap;
    }
}

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(0, 212, 255, 0.1);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: var(--radius-md);
    color: var(--cqm-accent);
    cursor: pointer;
    transition: var(--transition-fast);
}

.mobile-menu-btn:hover {
    background: rgba(0, 212, 255, 0.2);
}

.mobile-menu-btn svg {
    width: 24px;
    height: 24px;
}

/* ============================================
   Main Simulator Layout - Responsive Grid
   ============================================ */
.simulator-container {
    display: grid;
    gap: var(--space-md);
    padding: var(--space-md);
    flex: 1;
    min-height: 0;
}

/* Mobile Layout - Single Column */
@media (max-width: 767px) {
    .simulator-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr auto;
        grid-template-areas:
            "controls"
            "gates"
            "circuit"
            "results";
        padding: var(--space-sm);
        gap: var(--space-sm);
    }

    .gate-palette-panel {
        grid-area: gates;
        max-height: 200px;
        overflow-y: auto;
    }

    .circuit-panel {
        grid-area: circuit;
        min-height: 300px;
    }

    .results-panel {
        grid-area: results;
    }

    .control-panel {
        grid-area: controls;
    }
}

/* Tablet Layout - Two Columns */
@media (min-width: 768px) and (max-width: 1023px) {
    .simulator-container {
        grid-template-columns: 250px 1fr;
        grid-template-rows: 1fr auto;
        grid-template-areas:
            "gates circuit"
            "gates results";
        padding: var(--space-md);
    }

    .gate-palette-panel {
        grid-area: gates;
    }

    .circuit-panel {
        grid-area: circuit;
        min-height: 400px;
    }

    .results-panel {
        grid-area: results;
    }
}

/* Desktop Layout - Three Columns */
@media (min-width: 1024px) {
    .simulator-container {
        grid-template-columns: var(--sidebar-width) 1fr var(--sidebar-width);
        grid-template-rows: 1fr;
        grid-template-areas: "gates circuit results";
        height: calc(100vh - var(--header-height) - 100px);
        padding: var(--space-sm);
        gap: var(--space-sm);
    }

    .gate-palette-panel {
        grid-area: gates;
    }

    .circuit-panel {
        grid-area: circuit;
    }

    .results-panel {
        grid-area: results;
    }
}

/* Large Desktop */
@media (min-width: 1440px) {
    .simulator-container {
        grid-template-columns: var(--sidebar-width) 1fr var(--sidebar-width);
        max-width: none;
        margin: 0;
        padding: var(--space-sm);
    }
}

/* ============================================
   Panel Base Styles
   ============================================ */
.panel {
    background: rgba(13, 17, 28, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(6, 82, 221, 0.3);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-header {
    background: linear-gradient(135deg, rgba(6, 82, 221, 0.15), rgba(74, 20, 140, 0.15));
    padding: var(--space-md);
    border-bottom: 1px solid rgba(6, 82, 221, 0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.panel-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--cqm-accent);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.panel-content {
    padding: var(--space-md);
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ============================================
   Gate Palette - Responsive
   ============================================ */
.gate-palette {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.gate-categories {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    padding: var(--space-sm);
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(6, 82, 221, 0.2);
}

.category-tab {
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    background: transparent;
    border: 1px solid transparent;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.category-tab:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.category-tab.active {
    background: rgba(0, 212, 255, 0.2);
    border-color: rgba(0, 212, 255, 0.5);
    color: var(--cqm-accent);
}

.gate-grid {
    display: grid;
    gap: var(--space-sm);
    padding: var(--space-sm);
}

/* Mobile Gate Grid */
@media (max-width: 767px) {
    .gate-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .gate-item {
        padding: var(--space-sm);
    }

    .gate-name {
        display: none;
    }
}

/* Tablet Gate Grid */
@media (min-width: 768px) and (max-width: 1023px) {
    .gate-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Desktop Gate Grid */
@media (min-width: 1024px) {
    .gate-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Gate Item */
.gate-item {
    background: rgba(6, 82, 221, 0.1);
    border: 2px solid rgba(6, 82, 221, 0.3);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-sm);
    text-align: center;
    cursor: grab;
    transition: var(--transition-normal);
    user-select: none;
    touch-action: none;
}

.gate-item:hover {
    background: rgba(6, 82, 221, 0.2);
    border-color: var(--cqm-primary);
    transform: translateY(-2px);
    box-shadow: 0 0 15px rgba(6, 82, 221, 0.4);
}

.gate-item:active {
    cursor: grabbing;
    transform: scale(0.95);
}

.gate-item.selected {
    border-color: var(--cqm-accent);
    box-shadow: var(--cqm-glow-accent);
}

.gate-icon {
    font-size: 1.5rem;
    margin-bottom: var(--space-xs);
    display: block;
    font-weight: bold;
}

.gate-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
}

.gate-description {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.6);
    margin-top: var(--space-xs);
    line-height: 1.3;
}

/* ============================================
   Circuit View - Responsive
   ============================================ */
.circuit-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.circuit-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(6, 82, 221, 0.2);
}

.circuit-canvas {
    flex: 1;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
}

/* Circuit Grid */
.circuit-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-md);
    min-width: fit-content;
}

.qubit-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.qubit-label {
    width: 50px;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--cqm-accent);
    flex-shrink: 0;
}

.qubit-wire {
    display: flex;
    gap: var(--space-xs);
    position: relative;
}

.qubit-wire::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 2px;
    background: rgba(0, 212, 255, 0.3);
    z-index: 0;
}

.circuit-cell {
    width: 48px;
    height: 48px;
    border: 2px dashed rgba(6, 82, 221, 0.3);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.circuit-cell:hover {
    border-color: var(--cqm-accent);
    background: rgba(0, 212, 255, 0.1);
}

.circuit-cell.has-gate {
    border-style: solid;
}

/* Mobile Circuit */
@media (max-width: 767px) {
    .circuit-cell {
        width: 40px;
        height: 40px;
    }

    .qubit-label {
        width: 40px;
        font-size: 0.75rem;
    }
}

/* ============================================
   Results Panel - Responsive
   ============================================ */
.results-panel {
    display: flex;
    flex-direction: column;
}

.results-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* SDK Buttons Grid */
.sdk-grid {
    display: grid;
    gap: var(--space-sm);
}

@media (max-width: 767px) {
    .sdk-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .sdk-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.sdk-btn {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.3);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.sdk-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}

.sdk-btn.active {
    background: rgba(76, 175, 80, 0.2);
    border-color: var(--cqm-success);
    color: var(--cqm-success);
}

/* Results Display */
.quantum-results {
    padding: var(--space-md);
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.result-state {
    font-family: var(--font-mono);
    color: var(--cqm-accent);
}

.result-bar-container {
    flex: 1;
    margin: 0 var(--space-md);
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.result-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--cqm-accent), var(--cqm-secondary));
    border-radius: var(--radius-full);
    transition: var(--transition-normal);
}

.result-value {
    font-weight: 600;
    min-width: 50px;
    text-align: right;
}

/* ============================================
   Buttons - Responsive
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition-fast);
    border: none;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--cqm-success);
    color: white;
}

.btn-primary:hover {
    background: #45a049;
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* AI Design Button - Cyan/Turquoise */
.btn-ai-design {
    background: linear-gradient(135deg, #00ccff, #00d4ff) !important;
    border: 1px solid rgba(0, 204, 255, 0.5) !important;
    color: white !important;
    box-shadow: 0 0 10px rgba(0, 204, 255, 0.3);
}

.btn-ai-design:hover {
    background: linear-gradient(135deg, #00d4ff, #00e5ff) !important;
    box-shadow: 0 0 15px rgba(0, 204, 255, 0.5);
    transform: translateY(-1px);
}

.btn-accent {
    background: linear-gradient(135deg, var(--cqm-primary), var(--cqm-accent));
    color: white;
}

.btn-accent:hover {
    box-shadow: var(--cqm-glow);
}

.btn-danger {
    background: rgba(244, 67, 54, 0.2);
    border: 1px solid rgba(244, 67, 54, 0.5);
    color: var(--cqm-error);
}

.btn-danger:hover {
    background: rgba(244, 67, 54, 0.3);
}

/* Button Sizes */
.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
}

.btn-lg {
    padding: var(--space-md) var(--space-lg);
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* Mobile Button Adjustments */
@media (max-width: 767px) {
    .btn {
        padding: var(--space-sm);
        font-size: 0.8rem;
    }

    .btn-lg {
        padding: var(--space-md);
    }
}

/* ============================================
   Footer - Main Site Style
   ============================================ */
.cqm-footer {
    background: rgba(7, 10, 16, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0, 212, 255, 0.2);
    margin-top: auto;
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-xl) var(--space-md);
}

.footer-grid {
    display: grid;
    gap: var(--space-xl);
}

/* Mobile Footer */
@media (max-width: 767px) {
    .footer-grid {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .footer-section {
        padding-bottom: var(--space-lg);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .footer-section:last-child {
        border-bottom: none;
    }
}

/* Tablet Footer */
@media (min-width: 768px) and (max-width: 1023px) {
    .footer-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Desktop Footer */
@media (min-width: 1024px) {
    .footer-grid {
        grid-template-columns: 2fr repeat(3, 1fr);
    }
}

.footer-section h4 {
    color: var(--cqm-accent);
    font-size: 0.875rem;
    font-weight: 700;
    margin-bottom: var(--space-md);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.footer-section ul {
    list-style: none;
}

.footer-section li {
    margin-bottom: var(--space-sm);
}

.footer-section a {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.875rem;
    transition: var(--transition-fast);
}

.footer-section a:hover {
    color: var(--cqm-accent);
}

.footer-company {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
    line-height: 1.8;
}

.footer-company strong {
    color: rgba(255, 255, 255, 0.8);
}

.footer-bottom {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: var(--space-lg);
    margin-top: var(--space-lg);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-md);
}

.footer-copyright {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
}

.footer-social {
    display: flex;
    gap: var(--space-md);
}

.footer-social a {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
    color: rgba(255, 255, 255, 0.7);
    transition: var(--transition-fast);
}

.footer-social a:hover {
    background: var(--cqm-accent);
    color: white;
}

/* ============================================
   Modal System - Responsive
   ============================================ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: var(--z-modal);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: var(--space-md);
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-normal);
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: linear-gradient(135deg, var(--cqm-dark), var(--cqm-darker));
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: var(--radius-xl);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateY(20px) scale(0.95);
    transition: var(--transition-normal);
}

.modal-overlay.show .modal-content {
    transform: translateY(0) scale(1);
}

/* Mobile Modal */
@media (max-width: 767px) {
    .modal-content {
        max-height: 95vh;
        border-radius: var(--radius-lg);
        margin: var(--space-sm);
    }
}

.modal-header {
    padding: var(--space-lg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--cqm-accent);
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: var(--radius-full);
    color: white;
    cursor: pointer;
    transition: var(--transition-fast);
}

.modal-close:hover {
    background: rgba(244, 67, 54, 0.3);
}

.modal-body {
    padding: var(--space-lg);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
}

.modal-footer {
    padding: var(--space-lg);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-md);
    flex-shrink: 0;
}

/* ============================================
   Tutorial System
   ============================================ */
.tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: var(--z-modal);
    pointer-events: none;
}

.tutorial-highlight {
    position: absolute;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7);
    border: 3px solid var(--cqm-accent);
    border-radius: var(--radius-md);
    animation: pulse-border 2s infinite;
    pointer-events: auto;
}

@keyframes pulse-border {
    0%, 100% { border-color: var(--cqm-accent); }
    50% { border-color: var(--cqm-primary); }
}

.tutorial-tooltip {
    position: absolute;
    background: linear-gradient(135deg, var(--cqm-primary), var(--cqm-secondary));
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    max-width: 320px;
    z-index: calc(var(--z-modal) + 1);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
}

@media (max-width: 767px) {
    .tutorial-tooltip {
        max-width: calc(100vw - 32px);
        left: var(--space-md) !important;
        right: var(--space-md) !important;
    }
}

.tutorial-tooltip::before {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border: 10px solid transparent;
}

.tutorial-tooltip.top::before {
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    border-top-color: var(--cqm-secondary);
}

.tutorial-tooltip.bottom::before {
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    border-bottom-color: var(--cqm-primary);
}

.tutorial-step {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: var(--space-sm);
}

.tutorial-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: white;
    margin-bottom: var(--space-sm);
}

.tutorial-text {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.6;
    margin-bottom: var(--space-md);
}

.tutorial-actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
}

.tutorial-progress {
    display: flex;
    gap: var(--space-xs);
    justify-content: center;
    margin-top: var(--space-md);
}

.tutorial-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.3);
    transition: var(--transition-fast);
}

.tutorial-dot.active {
    background: white;
    transform: scale(1.2);
}

.tutorial-dot.completed {
    background: var(--cqm-success);
}

/* ============================================
   Help Modal Specific
   ============================================ */
.help-modal .modal-content {
    max-width: 800px;
}

.help-tabs {
    display: flex;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.help-tab {
    padding: var(--space-md) var(--space-lg);
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition-fast);
    border-bottom: 2px solid transparent;
}

.help-tab:hover {
    color: white;
}

.help-tab.active {
    color: var(--cqm-accent);
    border-bottom-color: var(--cqm-accent);
}

.help-content {
    padding: var(--space-lg);
}

.help-section {
    margin-bottom: var(--space-xl);
}

.help-section h3 {
    color: var(--cqm-accent);
    font-size: 1.1rem;
    margin-bottom: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.help-section p {
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.7;
    margin-bottom: var(--space-md);
}

.help-shortcut {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.help-shortcut kbd {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    padding: var(--space-xs) var(--space-sm);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--cqm-accent);
}

.gate-reference {
    display: grid;
    gap: var(--space-md);
}

@media (min-width: 768px) {
    .gate-reference {
        grid-template-columns: repeat(2, 1fr);
    }
}

.gate-ref-item {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    display: flex;
    gap: var(--space-md);
}

.gate-ref-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.gate-ref-info h4 {
    color: white;
    font-size: 0.9rem;
    margin-bottom: var(--space-xs);
}

.gate-ref-info p {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.8rem;
    margin: 0;
}

/* ============================================
   Notification System
   ============================================ */
.notification {
    position: fixed;
    top: var(--space-lg);
    right: var(--space-lg);
    padding: var(--space-md) var(--space-lg);
    background: linear-gradient(135deg, var(--cqm-primary), var(--cqm-accent));
    color: white;
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(6, 82, 221, 0.4);
    z-index: var(--z-notification);
    transform: translateX(calc(100% + var(--space-lg)));
    opacity: 0;
    transition: var(--transition-normal);
    max-width: calc(100vw - 32px);
}

.notification.show {
    transform: translateX(0);
    opacity: 1;
}

.notification.success {
    background: linear-gradient(135deg, var(--cqm-success), #2e7d32);
}

.notification.error {
    background: linear-gradient(135deg, var(--cqm-error), #c62828);
}

.notification.warning {
    background: linear-gradient(135deg, var(--cqm-warning), #f57c00);
}

/* Mobile Notification */
@media (max-width: 767px) {
    .notification {
        left: var(--space-md);
        right: var(--space-md);
        top: var(--space-md);
    }
}

/* ============================================
   Dropdown Menus - Responsive
   ============================================ */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: var(--space-sm);
    background: rgba(13, 17, 28, 0.98);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: var(--radius-lg);
    min-width: 200px;
    z-index: var(--z-dropdown);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: var(--transition-fast);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Mobile Dropdown */
@media (max-width: 767px) {
    .dropdown-menu {
        position: fixed;
        left: var(--space-md);
        right: var(--space-md);
        top: auto;
        bottom: var(--space-md);
        width: auto;
    }
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: var(--transition-fast);
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-size: 0.875rem;
}

.dropdown-item:hover {
    background: rgba(0, 212, 255, 0.1);
    color: var(--cqm-accent);
}

.dropdown-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: var(--space-sm) 0;
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

@keyframes floating {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

.animate-fadeIn { animation: fadeIn var(--transition-normal) forwards; }
.animate-slideUp { animation: slideUp var(--transition-normal) forwards; }
.animate-pulse { animation: pulse 2s ease-in-out infinite; }
.animate-spin { animation: spin 1s linear infinite; }
.animate-floating { animation: floating 3s ease-in-out infinite; }

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

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

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

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

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--cqm-accent) rgba(255, 255, 255, 0.05);
}

/* ============================================
   Touch Optimizations
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    .btn, .gate-item, .sdk-btn, .category-tab, .dropdown-item {
        min-height: 44px;
    }

    .gate-item:hover {
        transform: none;
    }

    .btn:hover {
        transform: none;
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .quantum-header,
    .cqm-footer,
    .btn,
    .modal-overlay,
    .notification {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .panel {
        border: 1px solid #ccc;
        background: white;
    }
}

/* ============================================
   Accessibility
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus Styles */
:focus-visible {
    outline: 2px solid var(--cqm-accent);
    outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --cqm-accent: #00ffff;
        --cqm-primary: #0066ff;
    }

    .panel {
        border-width: 2px;
    }
}

/* Dark Mode Preference (already dark, but ensure) */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e40af 100%);
    }
}

/* ============================================
   Sidebar Toggle Styles
   ============================================ */

/* Sidebar Container - Add position relative for toggle button */
.gate-palette-panel,
.results-panel {
    position: relative;
    overflow: visible !important; /* Override .panel overflow:hidden for toggle button visibility */
    transition: width 0.3s ease, min-width 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
}

/* Inner content scrollable when sidebar is not collapsed */
.gate-palette-panel > div,
.results-panel > div {
    overflow-y: auto;
    max-height: 100%;
}

/* Collapsed sidebar state */
.sidebar-collapsed {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    opacity: 0;
}

/* Sidebar Toggle Button Base Style */
.sidebar-toggle-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 60px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 100;
    /* backdrop-filter: blur(5px); */
    /* -webkit-backdrop-filter: blur(5px); */
}

/* Left Sidebar Toggle - positioned at right edge, purple color */
.left-sidebar-toggle {
    right: -24px;
    border-radius: 0 6px 6px 0;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: 1px solid rgba(139, 92, 246, 0.5);
    border-left: none;
    color: white;
    z-index: 1000;
}

.left-sidebar-toggle:hover {
    background: linear-gradient(135deg, #8b5cf6, #a78bfa);
    border-color: rgba(167, 139, 250, 0.8);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.5);
}

/* Right Sidebar Toggle - positioned at left edge, cyan color */
.right-sidebar-toggle {
    left: -24px;
    border-radius: 6px 0 0 6px;
    background: linear-gradient(135deg, #06b6d4, #0891b2);
    border: 1px solid rgba(8, 145, 178, 0.5);
    border-right: none;
    color: white;
    z-index: 1000;
}

.right-sidebar-toggle:hover {
    background: linear-gradient(135deg, #0891b2, #0e7490);
    border-color: rgba(14, 116, 144, 0.8);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.5);
}

/* Collapsed state toggle buttons - shown when sidebar is collapsed */
.sidebar-toggle-collapsed {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 60px;
    z-index: 1000;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.3s ease;
}

.left-sidebar-toggle.sidebar-toggle-collapsed {
    left: 0;
    border-radius: 0 6px 6px 0;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: 1px solid rgba(139, 92, 246, 0.5);
    border-left: none;
    z-index: 10000;
}

.left-sidebar-toggle.sidebar-toggle-collapsed:hover {
    background: linear-gradient(135deg, #8b5cf6, #a78bfa);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.5);
}

.right-sidebar-toggle.sidebar-toggle-collapsed {
    right: 0;
    border-radius: 6px 0 0 6px;
    background: linear-gradient(135deg, #06b6d4, #0891b2);
    border: 1px solid rgba(8, 145, 178, 0.5);
    border-right: none;
}

.right-sidebar-toggle.sidebar-toggle-collapsed:hover {
    background: linear-gradient(135deg, #0891b2, #0e7490);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.5);
}

/* Grid adjustment when sidebars are collapsed */
@media (min-width: 1024px) {
    .simulator-container {
        transition: grid-template-columns 0.3s ease;
    }

    .simulator-container.left-collapsed {
        grid-template-columns: 0 1fr var(--sidebar-width);
    }

    .simulator-container.right-collapsed {
        grid-template-columns: var(--sidebar-width) 1fr 0;
    }

    .simulator-container.both-collapsed {
        grid-template-columns: 0 1fr 0;
    }
}

/* Responsive adjustments for toggle buttons */
@media (max-width: 1023px) {
    .sidebar-toggle-btn {
        display: none;
    }
}

/* ============================================
   Hybrid Mode Layout - Dynamic 3D + Classic Scrollable
   ============================================ */

/* Hybrid layout container */
.hybrid-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    gap: 8px;
}

/*
 * 3D View: 초기에는 flex-1로 50:50 유지
 * JavaScript가 큐비트 > 8일 때 .hybrid-3d-fixed 클래스를 추가하여 고정 높이 적용
 */
.hybrid-3d-view {
    flex: 1 1 50%;
    min-height: 200px;
    overflow: hidden;
}

/* 3D View 고정 상태 - JavaScript에서 동적으로 적용 */
.hybrid-3d-view.hybrid-3d-fixed {
    flex: 0 0 auto !important;
    /* height는 JavaScript에서 인라인 스타일로 설정 */
}

/* Ensure 3D view inner container fills the space */
.hybrid-3d-view > div {
    height: 100% !important;
}

/*
 * Classic View: 초기에는 flex-1로 50:50 유지
 * 3D가 고정되면 나머지 공간을 차지하며 스크롤 가능
 */
.hybrid-classic-view {
    flex: 1 1 50%;
    min-height: 200px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Classic view inner container should also flex */
.hybrid-classic-view > div {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Classic view scrollable canvas */
.classic-view-scrollable {
    flex: 1;
    overflow-y: auto !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    max-height: none !important;
}

/* Mobile adjustments for hybrid mode */
@media (max-width: 767px) {
    .hybrid-3d-view {
        min-height: 180px;
    }

    .hybrid-classic-view {
        min-height: 150px;
    }
}

/* Tablet adjustments for hybrid mode */
@media (min-width: 768px) and (max-width: 1023px) {
    .hybrid-3d-view {
        min-height: 220px;
    }
}

/* ============================================
   3D View Container Fix - Ensure proper sizing
   ============================================ */

/* 3D View container must have explicit dimensions for Three.js */
#threejs-container {
    width: 100% !important;
    height: 100% !important;
    min-height: 200px !important;
    display: block !important;
}

/* 3D View wrapper needs explicit height for flex-1 to work */
#threejs-container canvas {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
}

/* Ensure parent container of #threejs-container has proper height */
.circuit-panel .relative.flex-1,
.hybrid-3d-view .relative.flex-1 {
    flex: 1 1 auto !important;
    min-height: 200px !important;
    height: 100% !important;
}

/* 3D View panel in all modes */
.circuit-panel > div.h-full,
.hybrid-3d-view > div.h-full {
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
}

/* Fix for standalone 3D mode */
.circuit-panel > div > div.h-full {
    height: 100% !important;
}

/* Ensure 3D view takes full available space */
.circuit-panel [class*="border-purple-500"] {
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
}

.circuit-panel [class*="border-purple-500"] > .relative.flex-1 {
    flex: 1 1 auto !important;
    min-height: 200px !important;
}

/* ===== RTL (Right-to-Left) 언어 지원 ===== */
/* 아랍어, 히브리어, 페르시아어, 우르두어 등 */

[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

/* 사이드바 RTL */
[dir="rtl"] .quantum-sidebar,
[dir="rtl"] .cqm-sidebar {
    left: auto;
    right: 0;
    border-left: 1px solid rgba(168, 85, 247, 0.3);
    border-right: none;
}

/* 메인 컨텐츠 RTL */
[dir="rtl"] .quantum-main,
[dir="rtl"] .cqm-main {
    margin-left: 0;
    margin-right: 260px;
}

/* 사이드바 접힘 시 */
[dir="rtl"] .sidebar-collapsed .quantum-main,
[dir="rtl"] .sidebar-collapsed .cqm-main {
    margin-right: 60px;
}

/* 버튼 아이콘 반전 */
[dir="rtl"] .btn-icon-left {
    margin-left: 0.5rem;
    margin-right: 0;
}

[dir="rtl"] .btn-icon-right {
    margin-right: 0.5rem;
    margin-left: 0;
}

/* 게이트 팔레트 RTL */
[dir="rtl"] .gate-palette {
    text-align: right;
}

/* 드롭다운 메뉴 RTL */
[dir="rtl"] .dropdown-menu {
    left: auto;
    right: 0;
    text-align: right;
}

/* 툴팁 RTL */
[dir="rtl"] .tooltip {
    text-align: right;
}

/* 회로 컨트롤 RTL */
[dir="rtl"] .circuit-controls {
    flex-direction: row-reverse;
}

/* 푸터 RTL */
[dir="rtl"] .cqm-footer {
    text-align: right;
}

[dir="rtl"] .cqm-footer-section {
    text-align: right;
}

/* 헤더 RTL */
[dir="rtl"] .cqm-header {
    flex-direction: row-reverse;
}

[dir="rtl"] .cqm-header-nav {
    flex-direction: row-reverse;
}

/* 모달 RTL */
[dir="rtl"] .modal-content,
[dir="rtl"] .wia-modal-content {
    text-align: right;
}

[dir="rtl"] .modal-close,
[dir="rtl"] .wia-modal-close {
    left: 1rem;
    right: auto;
}

/* 입력 필드 RTL */
[dir="rtl"] input,
[dir="rtl"] textarea,
[dir="rtl"] select {
    text-align: right;
}

/* 체크박스/라디오 라벨 RTL */
[dir="rtl"] .checkbox-label,
[dir="rtl"] .radio-label {
    padding-left: 0;
    padding-right: 1.5rem;
}

/* 슬라이더 RTL */
[dir="rtl"] .slider-container {
    flex-direction: row-reverse;
}

/* 탭 RTL */
[dir="rtl"] .tab-list {
    flex-direction: row-reverse;
}

/* 카드 RTL */
[dir="rtl"] .card-header,
[dir="rtl"] .panel-header {
    flex-direction: row-reverse;
}

/* 리스트 RTL */
[dir="rtl"] ul,
[dir="rtl"] ol {
    padding-left: 0;
    padding-right: 1.5rem;
}

/* Flexbox 반전 */
[dir="rtl"] .flex-row {
    flex-direction: row-reverse;
}

/* 3D View 헤더 RTL */
[dir="rtl"] .view-header {
    flex-direction: row-reverse;
}

/* 코드 생성 패널 RTL */
[dir="rtl"] .code-panel {
    text-align: left; /* 코드는 LTR 유지 */
    direction: ltr;
}

[dir="rtl"] .code-panel pre,
[dir="rtl"] .code-panel code {
    direction: ltr;
    text-align: left;
}

/* ===== 라이트 모드 텍스트 가시성 수정 ===== */

/* 게이트 섹션 */
body.light-mode [data-i18n="gates_title"],
body.light-mode .gates-section h3 {
    color: #1e3a5f !important;
}

body.light-mode [data-i18n="gates_drag_hint"],
body.light-mode .gates-section .text-gray-400 {
    color: #4b5563 !important;
}

/* Classic View / 3D View 제목 */
body.light-mode [data-i18n="view_classic_title"] {

    color: #7c3aed !important;
}

body.light-mode .text-purple-400 {
    color: #7c3aed !important;
}

body.light-mode [data-i18n="view_3d_title"],
body.light-mode .view-header h3 {
    color: #1e3a5f !important;
}

/* SDK 내보내기 */
body.light-mode [data-i18n="sdk_export_title"],
body.light-mode [data-i18n="sdk_export_name"],
body.light-mode [data-i18n="sdk_export_platforms"] {
    color: #1e3a5f !important;
}

/* 양자 상태 결과 */
body.light-mode [data-i18n="results_quantum_state"],
body.light-mode .text-green-300 {
    color: #059669 !important;
}

body.light-mode [data-i18n="results_initial_state"],
body.light-mode .text-gray-500 {
    color: #4b5563 !important;
}

/* 예제 회로 */
body.light-mode [data-i18n="demo_title"] {
    color: #1e3a5f !important;
}

body.light-mode [data-i18n="demo_click_hint"] {
    color: #4b5563 !important;
}

/* 푸터 */
body.light-mode .cqm-footer,
body.light-mode .cqm-footer-section {
    background: #f8fafc !important;
}

body.light-mode .cqm-footer-logo,
body.light-mode .cqm-footer-company h3,
body.light-mode .cqm-footer-company strong {
    color: #1e3a5f !important;
}

body.light-mode .cqm-footer-section h4 {
    color: #1e3a5f !important;
    font-weight: 700 !important;
}

body.light-mode .cqm-footer-section a,
body.light-mode .cqm-footer-section li {
    color: #374151 !important;
}

body.light-mode .cqm-footer-section a:hover {
    color: #7c3aed !important;
}

body.light-mode .text-purple-400 {
    color: #7c3aed !important;
}

body.light-mode .cqm-footer-family h4 {
    color: #1e3a5f !important;
}

body.light-mode .cqm-footer-copyright {
    color: #6b7280 !important;
}
