/* Chuck the Lathe Chuck - Assistant Mascot Animations & Styles */

/* Container */
.chuck-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chuck-container.active {
    pointer-events: auto;
}

.chuck-container.hidden {
    transform: translateY(200px) scale(0);
    opacity: 0;
}

/* Chuck character */
.chuck-character {
    width: 80px;
    height: 104px;
    cursor: pointer;
    pointer-events: auto;
    transition: transform 0.3s ease;
    position: relative;
}

.chuck-character:hover {
    transform: scale(1.1);
}

.chuck-character svg {
    width: 100%;
    height: 100%;
}

/* Mini Chuck (bottom-right fab button) */
.chuck-mini {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6b6b6b, #555);
    border: 3px solid #cd7f32;
    cursor: pointer;
    z-index: 9998;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    overflow: hidden;
}

.chuck-mini:hover {
    transform: scale(1.15);
    box-shadow: 0 6px 20px rgba(205, 127, 50, 0.4);
}

.chuck-mini svg {
    width: 44px;
    height: 44px;
    margin-top: -4px;
}

.chuck-mini .chuck-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: #ff4444;
    border-radius: 50%;
    border: 2px solid #1a1a1a;
    display: none;
}

.chuck-mini.has-tip .chuck-badge {
    display: block;
    animation: chuck-pulse 2s infinite;
}

/* Speech Bubble */
.chuck-speech {
    position: absolute;
    bottom: 110px;
    right: 0;
    background: #1a1a1a;
    border: 2px solid #cd7f32;
    border-radius: 12px;
    padding: 12px 16px;
    min-width: 220px;
    max-width: 320px;
    color: #e0e0e0;
    font-size: 0.9rem;
    line-height: 1.4;
    box-shadow: 0 8px 25px rgba(0,0,0,0.5);
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: auto;
}

.chuck-speech.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.chuck-speech::after {
    content: '';
    position: absolute;
    bottom: -10px;
    right: 30px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #cd7f32;
}

.chuck-speech::before {
    content: '';
    position: absolute;
    bottom: -7px;
    right: 32px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #1a1a1a;
    z-index: 1;
}

.chuck-speech .chuck-name {
    font-weight: 700;
    color: #cd7f32;
    font-size: 0.8rem;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.chuck-speech .chuck-text {
    min-height: 20px;
}

.chuck-speech .chuck-text .cursor {
    display: inline-block;
    width: 2px;
    height: 14px;
    background: #cd7f32;
    margin-left: 2px;
    animation: chuck-cursor-blink 0.7s infinite;
}

.chuck-speech .chuck-dismiss {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 2px;
}

.chuck-speech .chuck-dismiss:hover {
    color: #ff4444;
}

/* ===== ANIMATIONS ===== */

@keyframes chuck-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@keyframes chuck-wave {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-20deg); }
    75% { transform: rotate(20deg); }
}

@keyframes chuck-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
}

@keyframes chuck-slide-in-right {
    from { transform: translateX(200px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes chuck-slide-in-left {
    from { transform: translateX(-200px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes chuck-cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

@keyframes chuck-celebrate {
    0% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-15px) rotate(-5deg); }
    50% { transform: translateY(0) rotate(5deg); }
    75% { transform: translateY(-10px) rotate(-3deg); }
    100% { transform: translateY(0) rotate(0deg); }
}

@keyframes chuck-think {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

@keyframes chuck-point-right {
    0% { transform: rotate(0deg) translateX(0); }
    100% { transform: rotate(-30deg) translateX(15px); }
}

@keyframes chuck-run {
    0% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-4px) rotate(3deg); }
    50% { transform: translateY(0) rotate(0deg); }
    75% { transform: translateY(-4px) rotate(-3deg); }
    100% { transform: translateY(0) rotate(0deg); }
}

/* Mood states */
.chuck-character.idle {
    animation: chuck-bounce 3s ease-in-out infinite;
}

.chuck-character.waving .chuck-right-arm {
    animation: chuck-wave 0.8s ease-in-out 3;
    transform-origin: top center;
}

.chuck-character.celebrating {
    animation: chuck-celebrate 0.6s ease-in-out 3;
}

.chuck-character.thinking {
    animation: chuck-think 2s ease-in-out infinite;
}

.chuck-character.pointing .chuck-right-arm {
    animation: chuck-point-right 0.5s ease forwards;
    transform-origin: top center;
}

.chuck-character.running {
    animation: chuck-run 0.3s ease-in-out infinite;
}

/* Eyes follow direction */
.chuck-character.look-right .chuck-left-pupil,
.chuck-character.look-right .chuck-right-pupil {
    transform: translateX(4px);
    transition: transform 0.3s ease;
}

.chuck-character.look-left .chuck-left-pupil,
.chuck-character.look-left .chuck-right-pupil {
    transform: translateX(-4px);
    transition: transform 0.3s ease;
}

.chuck-character.look-up .chuck-left-pupil,
.chuck-character.look-up .chuck-right-pupil {
    transform: translateY(-4px);
    transition: transform 0.3s ease;
}

/* Slide animation */
.chuck-container.slide-in-right {
    animation: chuck-slide-in-right 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.chuck-container.slide-in-left {
    animation: chuck-slide-in-left 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ===== CHAT INPUT ===== */

.chuck-chat {
    margin-top: 10px;
    border-top: 1px solid rgba(205, 127, 50, 0.25);
    padding-top: 8px;
}

.chuck-chat-input {
    width: 100%;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(205, 127, 50, 0.35);
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s;
    box-sizing: border-box;
}

.chuck-chat-input::placeholder {
    color: rgba(205, 127, 50, 0.45);
    font-style: italic;
}

.chuck-chat-input:focus {
    border-color: #cd7f32;
    box-shadow: 0 0 8px rgba(205, 127, 50, 0.3);
}

/* ===== WALKING / ROAMING STATE ===== */

.chuck-container.chuck-walking {
    transition: left 0.5s cubic-bezier(0.34, 1.56, 0.64, 1),
                top 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chuck-container.chuck-walking .chuck-character {
    animation: chuck-run 0.3s ease-in-out infinite;
}

/* When roaming, allow Chuck to float freely */
.chuck-container[style*="left"] {
    bottom: auto !important;
    right: auto !important;
}

/* ===== SPEECH BUBBLE REPOSITIONING (when roaming) ===== */

/* Speech bubble on the left side of Chuck (when he's on the right side of screen) */
.chuck-speech.chuck-speech-left {
    right: auto;
    left: 0;
    transform-origin: bottom left;
}

.chuck-speech.chuck-speech-left.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.chuck-speech.chuck-speech-left::after {
    right: auto;
    left: 30px;
}

.chuck-speech.chuck-speech-left::before {
    right: auto;
    left: 32px;
}

/* Speech bubble on the right side of Chuck (when he's on the left side of screen) */
.chuck-speech.chuck-speech-right {
    right: 0;
    left: auto;
    transform-origin: bottom right;
}

.chuck-speech.chuck-speech-right::after {
    right: 30px;
    left: auto;
}

.chuck-speech.chuck-speech-right::before {
    right: 32px;
    left: auto;
}

/* ===== HIGHLIGHT RING (pulsing ring around target elements) ===== */

.chuck-highlight-ring {
    position: fixed;
    border: 3px solid #cd7f32;
    border-radius: 8px;
    pointer-events: none;
    z-index: 9997;
    box-shadow: 0 0 12px rgba(205, 127, 50, 0.5),
                0 0 24px rgba(205, 127, 50, 0.2),
                inset 0 0 12px rgba(205, 127, 50, 0.1);
    animation: chuck-highlight-pulse 1.5s ease-in-out infinite;
}

@keyframes chuck-highlight-pulse {
    0%, 100% {
        box-shadow: 0 0 12px rgba(205, 127, 50, 0.5),
                    0 0 24px rgba(205, 127, 50, 0.2),
                    inset 0 0 12px rgba(205, 127, 50, 0.1);
        border-color: #cd7f32;
    }
    50% {
        box-shadow: 0 0 20px rgba(205, 127, 50, 0.7),
                    0 0 40px rgba(205, 127, 50, 0.35),
                    inset 0 0 20px rgba(205, 127, 50, 0.2);
        border-color: #e09540;
    }
}

/* ===== PAC-MAN SIZE MODE ===== */

.chuck-character.chuck-pacman {
    width: 160px;
    height: 208px;
}

/* Adjust speech bubble for Pac-Man size Chuck */
.chuck-container.chuck-size-pacman .chuck-speech {
    bottom: 215px;
    min-width: 280px;
    max-width: 420px;
    font-size: 1rem;
}

/* ===== DRAG STYLES ===== */

.chuck-container.chuck-draggable .chuck-character {
    cursor: grab;
}

.chuck-container.chuck-draggable .chuck-character:active {
    cursor: grabbing;
}

.chuck-container.chuck-dragging {
    transition: none !important;
}

/* Onboarding-specific: larger Chuck */
.chuck-onboarding .chuck-character {
    width: 120px;
    height: 156px;
}

.chuck-onboarding .chuck-speech {
    bottom: 165px;
    min-width: 280px;
    max-width: 400px;
    font-size: 1rem;
}

/* ===== TOOLTIP (tile hover guide) ===== */

.chuck-tooltip {
    position: fixed;
    z-index: 10000;
    background: #1a1a2e;
    border: 1px solid #cd7f32;
    border-radius: 8px;
    padding: 8px 12px;
    max-width: 300px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.chuck-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.chuck-tooltip-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    background: #cd7f32;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
}

.chuck-tooltip-text {
    color: #e0e0e0;
    font-size: 0.82rem;
    line-height: 1.4;
}

/* ===== WALKTHROUGH OVERLAY (first-visit tile guide) ===== */

.chuck-walkthrough-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    z-index: 10001;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    transition: background 0.3s ease;
}

.chuck-walkthrough-overlay.active {
    background: rgba(0, 0, 0, 0.7);
}

.chuck-walkthrough-card {
    background: #1a1a2e;
    border: 2px solid #cd7f32;
    border-radius: 16px;
    padding: 2rem;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6),
                0 0 40px rgba(205, 127, 50, 0.15);
    transform: scale(0.9) translateY(20px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chuck-walkthrough-overlay.active .chuck-walkthrough-card {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.chuck-walkthrough-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #cd7f32;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.chuck-walkthrough-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.chuck-walkthrough-icon {
    width: 40px;
    height: 40px;
    background: #cd7f32;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.chuck-walkthrough-header h3 {
    margin: 0;
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
}

.chuck-walkthrough-message {
    color: #c0c0c0;
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.chuck-walkthrough-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.chuck-walkthrough-skip {
    background: transparent;
    border: 1px solid rgba(205, 127, 50, 0.3);
    color: #999;
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    transition: all 0.15s;
}

.chuck-walkthrough-skip:hover {
    border-color: #cd7f32;
    color: #cd7f32;
}

.chuck-walkthrough-go {
    background: #cd7f32;
    border: none;
    color: #1a1a2e;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    font-family: inherit;
    transition: all 0.15s;
}

.chuck-walkthrough-go:hover {
    background: #e09540;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(205, 127, 50, 0.4);
}

/* ===== ESCALATION BUTTONS ===== */

.chuck-escalation-btn {
    padding: 6px 14px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.15s;
}

.chuck-escalation-ai {
    background: #cd7f32;
    color: #1a1a2e;
}

.chuck-escalation-ai:hover {
    background: #e09540;
}

.chuck-escalation-dismiss {
    background: rgba(255, 255, 255, 0.1);
    color: #999;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.chuck-escalation-dismiss:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ccc;
}

/* ===== MOBILE ADJUSTMENTS ===== */

@media (max-width: 600px) {
    .chuck-speech {
        min-width: 180px;
        max-width: 260px;
        font-size: 0.82rem;
    }

    .chuck-chat-input {
        font-size: 16px; /* prevent iOS zoom */
    }

    .chuck-highlight-ring {
        border-width: 2px;
    }
}

/* 2026-10-15: a faded (hidden) speech bubble must not catch taps — it made an invisible dead zone on phones. */
.chuck-speech:not(.visible) { pointer-events: none !important; }

/* 2026-10-16 walk: an unasked greeting / page tip sat on the page's own controls (phone: "Who's on shift?" Save, new
   machines in the layout builder; desktop: Chuck's figure on "Run AI Suggestions"). A bubble nobody asked for is
   passive: clicks and taps go straight through it to the page — only its own × and its question box take them —
   and it leaves after a few seconds. .mz-helper-passive is set by the helper guard at the end of
   js/spindle-pete-assistant.js; asking Chuck (pressing his button, typing to him) makes him interactive again. */
.chuck-container.mz-helper-passive,
.chuck-container.mz-helper-passive * {
    pointer-events: none !important;
}
.chuck-container.mz-helper-passive .chuck-dismiss,
.chuck-container.mz-helper-passive .chuck-chat,
.chuck-container.mz-helper-passive .chuck-chat * {
    pointer-events: auto !important;
}
/* Phones: a smaller Chuck (was 160 x 208 px), a bubble that fits the screen, and a bigger ×. */
@media (max-width: 600px) {
    .chuck-character.chuck-pacman {
        width: 80px;
        height: 104px;
    }
    .chuck-container.chuck-size-pacman .chuck-speech {
        bottom: 112px;
        min-width: 0;
        width: min(300px, calc(100vw - 40px));
        max-width: none;
        font-size: 0.85rem;
    }
    .chuck-speech .chuck-dismiss {
        top: 2px;
        right: 2px;
        min-width: 32px;
        min-height: 32px;
        font-size: 1.3rem;
    }
}

/* 2026-10-18 walk judge: an answer from the shop's assistant (js/chuck-assistant.js show(), class .chuck-answer) keeps
   its paragraphs, scrolls inside the bubble instead of running off the top of the screen, and lists the manual pages it
   came from under the text (#chuckSources: one row per manual, each page opening the manual there). The text box gives up
   height on short screens so the whole bubble stays on screen. */
.chuck-speech .chuck-text.chuck-answer {
    white-space: pre-line;
    max-height: clamp(120px, calc(100vh - 480px), 340px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 4px;
}
.chuck-speech .chuck-sources {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid rgba(205, 127, 50, 0.35);
    font-size: 0.75rem;
    line-height: 1.35;
    max-height: clamp(48px, 14vh, 110px);
    overflow-y: auto;
}
.chuck-speech .chuck-sources[hidden] {
    display: none;
}
.chuck-speech .chuck-sources-head {
    color: #cd7f32;
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 3px;
}
.chuck-speech .chuck-sources-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.chuck-speech .chuck-source-link {
    color: #f0b37e;
    text-decoration: none;
    border-bottom: 1px dotted rgba(205, 127, 50, 0.6);
}
.chuck-speech a.chuck-source-link:hover,
.chuck-speech a.chuck-source-link:focus-visible {
    color: #ffd2a8;
    border-bottom-color: #cd7f32;
}
.chuck-speech .chuck-source-doc {
    color: #c8c8c8;
}
