/* ===== Tutorial Overlay Styles ===== */
/* First-time user tutorial with spotlight highlighting */

/* ----- Main Overlay Container ----- */
.tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: var(--z-tutorial);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.tutorial-overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* ----- SVG Backdrop with Spotlight Cutout ----- */
.tutorial-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
}

/* Smooth spotlight transitions */
.tutorial-backdrop #tutorial-spotlight-rect {
    transition: x 0.3s ease, y 0.3s ease, width 0.3s ease, height 0.3s ease;
}

/* ----- Tooltip Box ----- */
.tutorial-tooltip {
    position: fixed;
    background: var(--bg-elevated);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-default);
    border-radius: 10px;
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 var(--border-subtle);
    padding: 20px;
    max-width: 400px;
    min-width: 280px;
    pointer-events: auto;
    z-index: 1;
    font-family: sans-serif;
}

/* Modal-style tooltip (centered, larger) */
.tutorial-tooltip--modal {
    max-width: 450px;
}

/* Spotlight-style tooltip (positioned near target) */
.tutorial-tooltip--spotlight {
    max-width: 350px;
}

/* ----- Close Button ----- */
.tutorial-close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: var(--font-size-h3);
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.tutorial-close-btn:hover {
    background-color: var(--interactive-hover);
    color: var(--text-primary);
}

/* ----- Content Area ----- */
.tutorial-content {
    margin-bottom: 16px;
    padding-right: 20px;
}

.tutorial-title {
    margin: 0 0 8px 0;
    color: var(--text-primary);
    font-size: var(--font-size-body-md);
    font-weight: 600;
}

.tutorial-text {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--font-size-body-sm);
    line-height: 1.5;
}

/* Keyboard key styling within tutorial text */
.tutorial-text kbd {
    display: inline-block;
    padding: 2px 6px;
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: 4px;
    font-family: system-ui, -apple-system, sans-serif;
    font-size: var(--font-size-ui-sm);
    font-weight: 500;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
}

/* ----- Footer with Progress and Buttons ----- */
.tutorial-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
}

.tutorial-progress {
    color: var(--text-muted);
    font-size: var(--font-size-ui-sm);
}

.tutorial-buttons {
    display: flex;
    gap: 8px;
}

/* ----- Button Styles ----- */
.tutorial-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: var(--font-size-body-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.tutorial-btn--next,
.tutorial-btn--finish {
    background: var(--accent-main);
    border: none;
    color: var(--shade-white);
}

.tutorial-btn--next:hover,
.tutorial-btn--finish:hover {
    filter: brightness(1.1);
}

.tutorial-btn--back {
    background: transparent;
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
}

.tutorial-btn--back:hover {
    background: var(--interactive-hover);
    color: var(--text-primary);
}

.tutorial-btn--skip {
    background: transparent;
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
}

.tutorial-btn--skip:hover {
    background: var(--interactive-hover);
    color: var(--text-primary);
}

.tutorial-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ----- Highlight Pulse Animation ----- */
@keyframes tutorial-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(71, 144, 255, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(71, 144, 255, 0);
    }
}

.tutorial-highlight-target {
    animation: tutorial-pulse 2s ease-in-out infinite;
}

/* ----- Port Highlight Ring ----- */
/* Rendered inside the overlay so it appears above the dark backdrop */
@keyframes tutorial-port-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 #4790ff, 0 0 12px 4px rgba(71, 144, 255, 0.5);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(71, 144, 255, 0), 0 0 16px 4px rgba(71, 144, 255, 0.2);
    }
}

.tutorial-port-highlight {
    position: fixed;
    border-radius: 50%;
    border: 3px solid #4790ff;
    background: rgba(71, 144, 255, 0.3);
    box-sizing: border-box;
    animation: tutorial-port-pulse 1.5s ease-in-out infinite;
    pointer-events: none;
    z-index: 100;
}

/* ----- Drawer Item Highlight ----- */
/* Pulsing highlight on a specific node button in the library drawer */
@keyframes tutorial-drawer-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(71, 144, 255, 0.5), inset 0 0 8px rgba(71, 144, 255, 0.15);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(71, 144, 255, 0), inset 0 0 12px rgba(71, 144, 255, 0.25);
    }
}

.tutorial-drawer-highlight {
    animation: tutorial-drawer-pulse 1.5s ease-in-out infinite;
    background-color: rgba(71, 144, 255, 0.15) !important;
    border: 1px solid rgba(71, 144, 255, 0.5) !important;
    border-radius: 6px;
    position: relative;
}

/* Dim non-highlighted drawer buttons during the tutorial */
body.tutorial-active .drawer-node-btn:not(.tutorial-drawer-highlight) {
    opacity: 0.35;
    pointer-events: none;
}

/* Field Highlight Glow */
@keyframes tutorial-field-glow {
    0%, 100% {
        box-shadow: 0 0 6px 1px rgba(71, 144, 255, 0.4), inset 0 0 4px rgba(71, 144, 255, 0.1);
    }
    50% {
        box-shadow: 0 0 14px 3px rgba(71, 144, 255, 0.6), inset 0 0 8px rgba(71, 144, 255, 0.15);
    }
}

.tutorial-field-highlight {
    animation: tutorial-field-glow 1.5s ease-in-out infinite;
    border-color: rgba(71, 144, 255, 0.6) !important;
    border-radius: 6px;
}

/* ----- Drag Hint Animation ----- */
/* Animated cursor + trail showing drag gesture — animation is JS-driven */
.tutorial-drag-hint {
    position: fixed;
    pointer-events: none;
    z-index: 99;
    overflow: visible;
}


/* ----- Tooltip Arrow Indicators ----- */
.tutorial-tooltip::before {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    transform: rotate(45deg);
    z-index: -1;
    display: none;
}

.tutorial-tooltip--arrow-top::before,
.tutorial-tooltip--arrow-bottom::before,
.tutorial-tooltip--arrow-left::before,
.tutorial-tooltip--arrow-right::before {
    display: block;
}

/* Arrow positions */
.tutorial-tooltip--arrow-top::before {
    top: -7px;
    left: var(--arrow-left, 50%);
    margin-left: -6px;
    border-right: none;
    border-bottom: none;
}

.tutorial-tooltip--arrow-bottom::before {
    bottom: -7px;
    left: var(--arrow-left, 50%);
    margin-left: -6px;
    border-left: none;
    border-top: none;
}

.tutorial-tooltip--arrow-left::before {
    left: -7px;
    top: var(--arrow-top, 50%);
    margin-top: -6px;
    border-right: none;
    border-top: none;
}

.tutorial-tooltip--arrow-right::before {
    right: -7px;
    top: var(--arrow-top, 50%);
    margin-top: -6px;
    border-left: none;
    border-bottom: none;
}

/* Arrow visibility is now opt-in via direction classes above */

/* ----- Responsive Adjustments ----- */
@media (max-width: 600px) {
    .tutorial-tooltip {
        max-width: calc(100vw - 40px);
        min-width: 240px;
    }

    .tutorial-footer {
        flex-direction: column;
        gap: 12px;
    }

    .tutorial-buttons {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ----- Keep content viewers above tutorial layers ----- */
/* Content viewer overlays must sit above the tutorial spotlight and tooltip */
.tutorial-active #text-editor-overlay,
.tutorial-active #text-viewer-overlay {
    z-index: calc(var(--z-tutorial) + 10) !important;
}

/* Disable node delete buttons during the tutorial */
.tutorial-active .delete-icon {
    pointer-events: none !important;
    opacity: 0.25 !important;
    cursor: not-allowed !important;
}

/* Disable all play/run buttons during the tutorial until the run step */
.tutorial-active #run-graph-btn,
.tutorial-active .play-icon {
    pointer-events: none !important;
    opacity: 0.25 !important;
    cursor: not-allowed !important;
}

/* Re-enable when the run step is active */
.tutorial-active.tutorial-run-step #run-graph-btn,
.tutorial-active.tutorial-run-step .play-icon {
    pointer-events: auto !important;
    opacity: 1 !important;
    cursor: pointer !important;
}

/* Circular pulsing highlight on a node's play icon (rendered in overlay) */
.tutorial-play-circle-highlight {
    position: fixed;
    border-radius: 50%;
    border: 3px solid #4790ff;
    background: rgba(71, 144, 255, 0.15);
    box-sizing: border-box;
    animation: tutorial-port-pulse 1.5s ease-in-out infinite;
    pointer-events: none;
    z-index: 100;
}

/* Raise the toolbar above the tutorial overlay during the run step so the
   Run Graph button is visible and clickable above the dark backdrop. */
.tutorial-active.tutorial-run-step .toolbar-wrapper {
    z-index: calc(var(--z-tutorial) + 1);
}

/* Circular pulsing highlight on the toolbar Run Graph button.
   Rendered on document.body so it escapes the overlay stacking context
   and sits above the toolbar-wrapper (z-tutorial + 1). */
.tutorial-run-btn-circle-highlight {
    position: fixed;
    border-radius: 50%;
    border: 3px solid #4790ff;
    background: rgba(71, 144, 255, 0.15);
    box-sizing: border-box;
    animation: tutorial-port-pulse 1.5s ease-in-out infinite;
    pointer-events: none;
    z-index: calc(var(--z-tutorial) + 2);
}
