/* ============================================
   MOBILE FIRST CSS - Base styles para mobile
   ============================================ */

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Base styles - Mobile (≤600px) */
body {
    font-family: Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 10px;
    overflow-x: hidden;
}

.container {
    max-width: 100%;
    flex: 1;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    padding: 20px 20px 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    height: auto;
}

h1 {
    text-align: center;
    color: #333;
    padding: 10px;
    border: 3px solid #333;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
}

h1:hover {
    background-color: #f0f0f0;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    border-color: #667eea;
}


/* Layout principal - Mobile */
.main-layout {
    display: flex;
    gap: 12px;
    align-items: stretch;
    min-height: 0;
    width: 100%;
    max-width: 100%;
}

/* Resize handle - Mobile (oculto ou minimal) */
.resize-handle {
    width: 8px;
    background: #ddd;
    cursor: col-resize;
    flex-shrink: 0;
    border-radius: 4px;
    transition: background 0.2s;
}

.resize-handle:hover {
    background: #bbb;
}

.resize-handle.resizing {
    background: #667eea;
}

/* Left panel - Mobile */
.left-panel {
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.grid-wrapper {
    flex: 1;
    border: 2px solid #4CAF50;
    border-radius: 10px;
    padding: 6px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    max-height: 35vh;
    width: 100%;
    max-width: min(35vh, 100%);
    aspect-ratio: 1 / 1;
}

.grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 2px;
    background: #ddd;
    padding: 2px;
    border-radius: 8px;
    width: 100%;
    height: 100%;
}

.cell {
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: background 0.3s;
    background-color: #f6f3f3;
    position: relative;
    overflow: hidden;
}

.cell-qubit {
    width: 70%;
    height: 70%;
    object-fit: contain;
}

.cell.goal {
    background: #ffd700;
}

/* Action buttons - Mobile */
.action-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.action-buttons button {
    background: #667eea;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    transition: background 0.3s;
}

.action-buttons button:hover {
    background: #5568d3;
}

.controls button {
    background: #667eea;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    transition: background 0.3s;
}

.controls button:hover {
    background: #5568d3;
}

.play-button {
    background: #FFB300 !important;
    color: white;
    border: none;
    padding: 8px 14px !important;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px !important;
    font-weight: bold;
    transition: background 0.3s;
}

.play-button:hover {
    background: #f5b92d !important;
}

/* Right panel - Mobile */
.right-panel {
    /* flex: 1; */
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.hints-section {
    background: #f0f8ff;
    border: 2px solid #2196F3;
    border-radius: 8px;
    padding: 4px;
    height: 50px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    overflow: hidden;
}

.robot-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qubit-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.hint-text {
    color: #333;
    font-size: 12px;
    line-height: 1.4;
    overflow: auto;
    flex: 1;
}

.right-bottom {
    display: flex;
    gap: 12px;
    flex: 1;
    min-height: 0;
}

.blocks-column {
    flex: 0 0 10%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
}

.blocks-palette {
    flex: 1;
    background: #f5f5f5;
    padding: 16px 12px;
    border-radius: 8px;
    border: 1px solid #ddd;
    overflow-y: auto;
    transition: background 0.3s ease, border-color 0.3s ease;
    max-height: 150px;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.blocks-palette::-webkit-scrollbar {
    width: 0;
    display: none;
}

.blocks-palette.auto-scroll-active {
    background: #fffacd;
    border-color: #FFB300;
    animation: paletteGlow 0.6s ease-in-out;
}

@keyframes paletteGlow {
    0%, 100% { box-shadow: 0 0 8px rgba(255, 179, 0, 0.3); }
    50% { box-shadow: 0 0 16px rgba(255, 179, 0, 0.6); }
}

.blocks-palette h3 {
    margin-bottom: 12px;
    color: #555;
    font-size: 13px;
}

.palette-blocks {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

/* Custom scroll control para paleta - Mobile */
.palette-scroll-control {
    position: absolute;
    right: -20px;
    top: 20px;
    width: 32px;
    height: 50%;
    max-height: 400px;
    background: rgba(200, 200, 200, 0.3);
    border-radius: 16px;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: auto;
}

.blocks-palette.has-scroll ~ .palette-scroll-control {
    display: flex;
}

.palette-scroll-thumb {
    width: 26px;
    height: 26px;
    background: #4CAF50;
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    transition: transform 0.1s ease, box-shadow 0.2s ease;
    position: absolute;
    top: 0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.palette-scroll-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}

.palette-scroll-thumb:active,
.palette-scroll-thumb.dragging {
    cursor: grabbing;
    transform: scale(0.95);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* Trash zone - Mobile */
.trash-zone {
    border: 2px dashed #999;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    background: #f5f5f5;
    transition: all 0.3s ease;
    cursor: pointer;
    min-height: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.trash-zone.trash-over {
    border-color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
    transform: scale(1.02);
}

.trash-icon {
    font-size: 18px;
    display: block;
}

.trash-text {
    color: #666;
    font-size: 11px;
    font-weight: 500;
}

/* Program area - Mobile */
.program-area {
    flex: 1;
    background: #f9f9f9;
    border: 3px dashed #ccc;
    border-radius: 12px;
    padding: 16px;
    overflow-x: auto;
    position: relative;
    min-height: 200px;
}

.program-area h3 {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ccc;
    font-size: 18px;
    margin: 0;
    pointer-events: none;
}

.program-blocks {
    display: flex;
    gap: 0;
    align-items: flex-start;
    padding: 10px;
    min-height: 120px;
}

.program-area.drag-over {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
}

.program-area.drag-over h3 {
    display: none;
}

/* Blocks */
.block-wrapper {
    position: relative;
    display: inline-block;
    cursor: grab;
    transition: transform 0.2s;
}

.block-wrapper:active {
    cursor: grabbing;
}

.block-wrapper:hover {
    transform: translateY(-3px);
}

.block-svg {
    display: block;
    filter: drop-shadow(0 3px 6px rgba(0,0,0,0.2));
}

.block-icon {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 32px;
    pointer-events: none;
}

.block-icon-repeat {
    position: absolute;
    top: 45%;
    left: 70%;
    transform: translate(-50%, -50%);
    font-size: 32px;
    pointer-events: none;
}

/* Program blocks */
.program-block-wrapper {
    position: relative;
    display: inline-block;
    margin-left: -8px;
    cursor: grab;
    flex-shrink: 0;
    z-index: 1;
    touch-action: none;
}

.program-block-wrapper:active {
    cursor: grabbing;
}

.program-block-wrapper:first-child {
    margin-left: 0;
    cursor: default;
}

.program-block-wrapper:first-child:active {
    cursor: default;
}

.remove-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #f44336;
    border: 2px solid white;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    z-index: 10;
}

.remove-btn:hover {
    background: #d32f2f;
}

/* Repeat block */
.repeat-content {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.repeat-content::-webkit-scrollbar {
    display: none;
}

.repeat-container {
    position: relative;
    display: inline-block;
    margin-left: -4px;
    flex-shrink: 0;
}

.repeat-block-wrapper {
    position: relative;
    display: inline-block;
    cursor: grab;
    top: -12px;
    touch-action: none;
}

.repeat-block-wrapper:active {
    cursor: grabbing;
}

.repeat-block-icon {
    position: absolute;
    font-size: 24px;
    pointer-events: none;
    z-index: 5;
}

.repeat-dropdown {
    position: absolute;
    background: white;
    border: 2px solid rgba(0,0,0,0.2);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    z-index: 5;
}

.repeat-content {
    position: absolute;
    display: flex;
    gap: 0;
    align-items: center;
    border: 2px dashed transparent;
    border-radius: 8px;
    overflow-x: auto;
    overflow-y: hidden;
}

.repeat-content::-webkit-scrollbar {
    height: 8px;
}

.repeat-content::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
}

.repeat-content::-webkit-scrollbar-thumb {
    background: #9C27B0;
    border-radius: 4px;
}

.repeat-content.drag-over {
    border-color: #9C27B0;
    background: rgba(156, 39, 176, 0.1);
}

.repeat-content .program-block-wrapper {
    flex-shrink: 0;
}

/* Drag preview */
.drag-preview {
    animation: fadeInScale 0.2s ease;
    border: 2px dashed #4CAF50;
    border-radius: 4px;
    padding: 2px;
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 0.5; transform: scale(1); }
}

/* Drop indicator */
.drop-indicator {
    animation: dropIndicatorPulse 0.6s ease-in-out infinite;
}

@keyframes dropIndicatorPulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 8px rgba(76, 175, 80, 0.6); }
    50% { opacity: 0.6; box-shadow: 0 0 12px rgba(76, 175, 80, 0.9); }
}

/* Drag ghost (pointer/touch) */
.drag-ghost {
    filter: drop-shadow(0 3px 6px rgba(0,0,0,0.25));
    pointer-events: none;
}

.controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.success-message {
    background: #4CAF50;
    color: white;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    margin-top: 20px;
    display: none;
    animation: slideIn 0.5s;
    font-size: 18px;
    font-weight: bold;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Popups */
.popup-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s;
}

.popup-overlay.show { display: flex; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.popup {
    background: white;
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    max-width: 400px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
    animation: popIn 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.popup-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: bounce 0.6s;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

.popup h2 { color: #333; margin-bottom: 15px; font-size: 28px; }
.popup p { color: #666; margin-bottom: 25px; font-size: 16px; }

.popup-buttons { display: flex; gap: 10px; justify-content: center; }
.popup button {
    padding: 12px 30px;
    font-size: 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s;
}
.popup button:hover {
    background: #5568d3;
}

/* Selection Screen */
.selection-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1001;
    align-items: center;
    justify-content: center;
}

.selection-overlay.show { display: flex; }

.selection-container {
    background: white;
    border-radius: 20px;
    padding: 40px;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}

.selection-container h2 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
    font-size: 24px;
}

.levels-grid { display: grid; gap: 20px; margin-bottom: 30px; }
.level-section { border: 1px solid #ddd; border-radius: 10px; padding: 20px; background: #f9f9f9; }
.level-section h3 { color: #333; margin-bottom: 15px; font-size: 18px; }

.phases-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 10px; }

.phase-button {
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    color: #333;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: all 0.2s;
}

.phase-button:hover:not(:disabled) { background: #f0f0f0; border-color: #999; }
.phase-button.selected { background: #4CAF50; color: white; border-color: #4CAF50; }
.phase-button:disabled { background: #ddd; color: #999; cursor: not-allowed; border-color: #ccc; }
.phase-button.completed { background: #e8f5e9; border-color: #4CAF50; }

.selection-start-btn {
    display: block;
    margin: 30px auto 0;
    padding: 15px 40px;
    font-size: 16px;
    font-weight: bold;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.selection-start-btn:hover { background: #45a049; }

/* Progress bar */
#levelProgress {
    display: grid;
    grid-template-columns: repeat(10, 18px);
    gap: 6px;
    justify-content: center;
    margin: 8px 0 12px;
}

.phase-square {
    width: 18px;
    height: 18px;
    border: 2px solid #ddd;
    border-radius: 4px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.phase-square.completed { background: #4CAF50; border-color: #4CAF50; color: #fff; }
.phase-square.current { border-color: #ffd700; }
.phase-square .phase-label { font-size: 6px; line-height: 1; font-weight: 700; user-select: none; }

/* Execution lock */
body[data-running="1"] .program-area,
body[data-running="1"] .blocks-palette { pointer-events: none; opacity: 0.7; }
body[data-running="1"] .controls button { cursor: not-allowed; }

/* Orientation Overlay */
.orientation-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}
.orientation-overlay.show { display: flex; }
.orientation-container {
    background: white;
    border-radius: 20px;
    padding: 32px;
    text-align: center;
    max-width: 420px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}
.orientation-container h2 {
    color: #333;
    margin-bottom: 12px;
    font-size: 22px;
}
.orientation-container p {
    color: #666;
    font-size: 14px;
}

/* Popup buttons - Botão Próximo Nível/Próxima Fase - Verde */
.popup button#btnNextLevel {
    background: #4CAF50;
}
.popup button#btnNextLevel:hover {
    background: #45a049;
}

/* ============================================
   MEDIA QUERIES - MOBILE FIRST
   ============================================ */

/* Tablets/Intermediário (601px - 900px) */
@media screen and (min-width: 601px) {
    body {
        padding: 15px;
    }

    .container {
        padding: 8px 16px 20px;
    }

    h1 {
        font-size: 18px;
        padding: 12px;
    }

    .main-layout {
        min-height: 0;
    }

    .left-panel {
        min-width: auto;
        max-width: 100%;
    }

    .grid-wrapper {
        max-height: 45vh;
        max-width: min(45vh, 100%);
        padding: 8px;
        border-width: 2px;
    }

    .cell {
        font-size: 20px;
    }

    .cell-qubit {
        width: 75%;
        height: 75%;
    }

    .action-buttons button,
    .controls button {
        padding: 10px 18px;
        font-size: 14px;
    }

    .play-button {
        padding: 10px 18px !important;
        font-size: 14px !important;
    }

    .program-area {
        min-height: 200px;
    }

    .hints-section {
        height: 50px;
        padding: 4px;
    }

    .qubit-icon {
        width: 40px;
        height: 40px;
    }

    .hint-text {
        font-size: 12px;
    }

    #levelProgress {
        grid-template-columns: repeat(10, 14px);
        gap: 4px;
        margin: 6px 0 10px;
    }

    .phase-square {
        width: 14px;
        height: 14px;
    }

    .trash-zone {
        min-height: 50px;
        padding: 10px;
    }

    .trash-icon {
        font-size: 18px;
    }

    .trash-text {
        font-size: 11px;
    }

    .blocks-palette {
        padding: 16px 12px;
    }

    .blocks-palette h3 {
        font-size: 13px;
        margin-bottom: 12px;
    }

    .palette-blocks {
        gap: 12px;
    }
}

/* Desktop (≥901px) */
@media screen and (min-width: 901px) {
    body {
        padding: 20px;
    }

    .container {
        max-width: 1200px;
        max-height: 520px;
        padding: 8px 32px 32px 32px;
    }

    h1 {
        font-size: 24px;
        padding: 20px;
    }

    .main-layout {
        gap: 16px;
        min-height: 20vh;
    }

    .left-panel {
        flex: 0 0 30%;
        min-width: 120px;
        max-width: 500px;
    }

    .grid-wrapper {
        border: 3px solid #4CAF50;
        padding: 12px;
        max-height: 60vh;
        max-width: min(60vh, 500px);
    }

    .cell {
        font-size: 32px;
    }

    .cell-qubit {
        width: 80%;
        height: 80%;
    }

    .action-buttons button,
    .controls button {
        padding: 12px 25px;
        font-size: 16px;
    }

    .play-button {
        padding: 12px 25px !important;
        font-size: 16px !important;
    }

    .right-panel {
        min-width: 65%;
    }

    .hints-section {
        padding: 6px;
        height: 60px;
    }

    .qubit-icon {
        width: 48px;
        height: 48px;
    }

    .hint-text {
        font-size: 14px;
    }

    .blocks-palette {
        padding: 12px;
    }

    .blocks-palette h3 {
        margin-bottom: 10px;
        font-size: 14px;
    }

    .palette-blocks {
        gap: 8px;
    }

    .trash-zone {
        padding: 15px;
        min-height: 60px;
    }

    .trash-icon {
        font-size: 20px;
    }

    .trash-text {
        font-size: 12px;
    }

    .program-area {
        padding: 20px;
        min-height: 250px;
    }

    #levelProgress {
        grid-template-columns: repeat(10, 18px);
        gap: 6px;
        margin: 8px 0 12px;
    }

    .phase-square {
        width: 18px;
        height: 18px;
    }
}
