/**
 * ScratchAll Character System - CSS
 * Modular styling for character interactions (Lilly, Cat, future characters)
 * Supports: tutorials, tours, tips, promotions, rewards
 * Version: 1.0.0
 */

/* ============================================
   CSS CUSTOM PROPERTIES
   ============================================ */
:root {
    /* Character accent colors - static definitions */
    --char-lilly-primary: #8b5cf6;
    --char-lilly-secondary: #a78bfa;
    --char-lilly-glow: rgba(var(--char-accent-rgb), 0.4);
    
    --char-cat-primary: #f59e0b;
    --char-cat-secondary: #fbbf24;
    --char-cat-glow: rgba(245, 158, 11, 0.4);
    
    /* Active character accent - dynamically set via JS */
    --char-accent: var(--char-accent);
    --char-accent-secondary: var(--char-accent-secondary);
    --char-accent-glow: var(--char-accent-glow);
    --char-accent-rgb: 139, 92, 246;  /* For rgba() usage */
    
    /* Speech bubble colors */
    --bubble-bg-start: #1a1a2e;
    --bubble-bg-end: #1f1f35;
    --bubble-border: #3b3b5c;
    --bubble-accent: var(--char-accent);
    
    /* Text colors */
    --char-text-title: #ffffff;
    --char-text-body: #d1d5db;
    --char-text-highlight: #fbbf24;
    --char-text-muted: #9ca3af;
    
    /* Button colors - use accent */
    --char-btn-primary-start: var(--char-accent);
    --char-btn-primary-end: var(--char-accent);
    --char-btn-success-start: #22c55e;
    --char-btn-success-end: #16a34a;
    --char-btn-secondary-bg: rgba(255, 255, 255, 0.08);
    --char-btn-secondary-border: #3b3b5c;
    
    /* Animation timing */
    --char-transition-fast: 0.15s;
    --char-transition-normal: 0.3s;
    --char-transition-slow: 0.4s;
}

/* ============================================
   BODY STATE CLASSES
   ============================================ */
body.character-active {
    overflow: hidden;
}

body.character-tour-active {
    overflow: hidden;
}

/* ============================================
   OVERLAY SYSTEM
   ============================================ */
.character-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--char-transition-slow) ease-in-out, 
                visibility var(--char-transition-slow) ease-in-out;
}

.character-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Spotlight effect for tours */
.character-spotlight {
    position: fixed;
    pointer-events: none;
    transition: all var(--char-transition-slow) ease-in-out, 
                opacity var(--char-transition-normal) ease-in-out;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.85);
    border-radius: 8px;
    opacity: 0;
    visibility: hidden;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
}

.character-spotlight.visible {
    opacity: 1;
    visibility: visible;
}

.character-spotlight.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Fade out without moving/shrinking - used when ending tour */
.character-spotlight.fade-out-only {
    transition: opacity var(--char-transition-normal) ease-in-out !important;
    opacity: 0;
    pointer-events: none;
}

.character-spotlight.pulse {
    animation: spotlightPulse 2s ease-in-out infinite;
}

@keyframes spotlightPulse {
    0%, 100% { box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.85), 0 0 0 4px rgba(var(--char-accent-rgb), 0.4); }
    50% { box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.85), 0 0 0 8px rgba(var(--char-accent-rgb), 0.6); }
}

/* Touch blocker - invisible overlay to block page interactions during tours
   The spotlight's box-shadow allows touch events to pass through,
   so we need this separate layer to block them when not wanted */
.character-touch-blocker {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    pointer-events: none;
}

/* When active, block all touch/click events on the page */
.character-touch-blocker.active {
    pointer-events: auto !important;
}

/* When allow-clicks is set (advanceOnClick step), let events pass through */
.character-touch-blocker.active.allow-clicks {
    pointer-events: none !important;
}

/* ============================================
   CHARACTER DISPLAY - FULL BODY
   ============================================ */
.character-guide {
    position: fixed;
    pointer-events: none;
    z-index: 2007;
    opacity: 0;
    visibility: hidden;
    transform: translateY(100%);
    transition: opacity var(--char-transition-normal) ease, 
                transform var(--char-transition-slow) cubic-bezier(0.34, 1.56, 0.64, 1),
                bottom var(--char-transition-normal) ease,
                left var(--char-transition-normal) ease;
}

.character-guide.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.character-guide.fading-out {
    opacity: 0 !important;
    transform: translateY(30%) !important;
    transition: opacity var(--char-transition-fast) ease, transform var(--char-transition-fast) ease !important;
}

/* Lilly specific positioning */
.character-guide.lilly {
    left: -5px;
}

/* Cat specific positioning (future) */
.character-guide.cat {
    left: auto;
    right: -5px;
}

/* Character image container - controls visible area */
.character-image-container {
    width: 280px;
    height: 290px;
    bottom: -20px;
    overflow: hidden;
    position: relative;
    pointer-events: none;
    box-sizing: content-box;
}

.character-image {
    width: 280px;
    height: auto;
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.6));
    animation: characterIdle 4s ease-in-out infinite;
    pointer-events: none;
}

@keyframes characterIdle {
    0%, 100% { transform: translateX(-50%) translateY(0) scale(1); }
    50% { transform: translateX(-50%) translateY(4px) scale(1.01); }
}

/* ============================================
   CHARACTER DISPLAY - PROFILE/SMALL
   For tooltips, notifications, smaller interactions
   ============================================ */
.character-profile {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid var(--char-accent);
    box-shadow: 0 4px 15px var(--char-accent-glow);
    flex-shrink: 0;
}

.character-profile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
}

.character-profile.small {
    width: 40px;
    height: 40px;
    border-width: 2px;
}

.character-profile.large {
    width: 80px;
    height: 80px;
    border-width: 4px;
}

/* Cat profile variant */
.character-profile.cat {
    border-color: var(--char-cat-primary);
    box-shadow: 0 4px 15px var(--char-cat-glow);
}

/* ============================================
   SPEECH BUBBLE - FULL (for tours/tutorials)
   ============================================ */
.character-speech-bubble {
    position: fixed;
    bottom: 20px;
    left: 220px;
    right: 20px;
    max-width: 500px;
    background: linear-gradient(135deg, var(--bubble-bg-start) 0%, var(--bubble-bg-end) 100%);
    border: 2px solid var(--bubble-border);
    border-radius: 20px;
    padding: 20px 25px;
    z-index: 2006;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(20px);
    transition: opacity var(--char-transition-normal) ease, 
                transform var(--char-transition-normal) ease;
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.05) inset;
}

.character-speech-bubble.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

/* Top accent line */
.character-speech-bubble .bubble-accent {
    position: absolute;
    top: 0;
    left: 20px;
    right: 20px;
    height: 3px;
    background: linear-gradient(90deg, var(--bubble-accent), var(--char-accent-secondary), var(--bubble-accent));
    border-radius: 3px 3px 0 0;
}

/* Speech bubble arrow - pointing left to character (desktop) */
.character-speech-bubble::before {
    content: '';
    position: absolute;
    left: -25px;
    bottom: 30px;
    border: 12px solid transparent;
    border-right-color: var(--bubble-border);
}

.character-speech-bubble::after {
    content: '';
    position: absolute;
    left: -18px;
    bottom: 33px;
    border: 10px solid transparent;
    border-right-color: var(--bubble-bg-start);
}

/* Speech bubble header - contains title and skip button */
.character-speech-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

/* Speech bubble title */
.character-speech-title {
    color: var(--char-text-title);
    font-size: 1.25em;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

/* Step indicator badge */
.character-speech-title .step-indicator {
    display: none; /* Hidden by default, shown via JS */
    background: rgba(var(--char-accent-rgb), 0.2);
    color: var(--char-accent-secondary);
    font-size: 0.7em;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 600;
}

/* Skip button in header */
.character-speech-header .character-nav-skip {
    background: transparent;
    border: none;
    color: var(--char-text-muted);
    font-size: 0.8em;
    cursor: pointer;
    padding: 4px 8px;
    transition: color var(--char-transition-fast) ease;
    margin: -4px -8px 0 0; /* Tuck into corner */
}

.character-speech-header .character-nav-skip:hover {
    color: var(--char-text-title);
}

/* Speech bubble text */
.character-speech-text {
    color: var(--char-text-body);
    font-size: 1em;
    line-height: 1.6;
    margin: 0 0 18px 0;
}

.character-speech-text strong {
    color: var(--char-text-highlight);
}

.character-speech-text i {
    opacity: 0.6;
}

/* ============================================
   SPEECH BUBBLE - COMPACT (for tips/tooltips)
   ============================================ */
.character-tooltip {
    position: fixed;
    box-sizing: border-box;
    background: linear-gradient(135deg, var(--bubble-bg-start) 0%, var(--bubble-bg-end) 100%);
    border: 2px solid var(--bubble-border);
    border-radius: 16px;
    padding: 16px 20px;
    z-index: 30050;
    max-width: 320px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px) scale(0.95);
    transition: opacity var(--char-transition-normal) ease,
                visibility var(--char-transition-normal) ease,
                transform var(--char-transition-normal) ease;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.character-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Centered tooltip (no target element) */
.character-tooltip.centered {
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) scale(0.95);
}

.character-tooltip.centered.visible {
    transform: translate(-50%, -50%) scale(1);
}

.character-tooltip-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.character-tooltip-title {
    color: var(--char-text-title);
    font-size: 1.1em;
    font-weight: 600;
    margin: 0;
}

.character-tooltip-text {
    color: var(--char-text-body);
    font-size: 0.95em;
    line-height: 1.5;
    margin: 0;
}

.character-tooltip-text strong {
    color: var(--char-text-highlight);
}

/* Tooltip close button */
.character-tooltip-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    color: var(--char-text-muted);
    font-size: 1.2em;
    cursor: pointer;
    padding: 4px 8px;
    transition: color var(--char-transition-fast) ease;
}

.character-tooltip-close:hover {
    color: var(--char-text-title);
}

/* ============================================
   NAVIGATION BUTTONS
   ============================================ */

/* Nav container - holds next button, full width */
.character-nav {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
}

/* Character name badge - absolutely positioned bottom-left, doesn't affect layout */
.character-name-badge {
    position: absolute;
    bottom: 15px;
    left: 25px;
    font-size: 0.95em;
    font-weight: 700;
    color: var(--char-accent-secondary);
    opacity: 0.8;
    white-space: nowrap;
}

.character-nav-next {
    background: linear-gradient(135deg, var(--char-btn-primary-start) 0%, var(--char-btn-primary-end) 100%);
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--char-transition-normal) ease;
    box-shadow: 0 4px 15px var(--char-accent-glow);
}

.character-nav-next i {
    margin-left: 6px;
}

.character-nav-next:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(var(--char-accent-rgb), 0.5);
}

.character-nav-next:active {
    transform: translateY(0);
}

/* Finish/CTA button */
.character-nav-finish {
    background: linear-gradient(135deg, var(--char-btn-success-start) 0%, var(--char-btn-success-end) 100%);
    color: #fff;
    border: none;
    padding: 14px 24px;
    border-radius: 10px;
    font-size: 1.1em;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--char-transition-normal) ease;
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.3);
    width: 100%;
}

.character-nav-finish:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.5);
}

/* Secondary/ghost button */
.character-nav-secondary {
    background: var(--char-btn-secondary-bg);
    color: #fff;
    border: 1px solid var(--char-btn-secondary-border);
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--char-transition-fast) ease;
}

.character-nav-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: #6b6b8c;
}

/* ============================================
   WELCOME/INTRO BUTTONS
   ============================================ */
.character-welcome-buttons {
    position: fixed;
    display: none;
    flex-direction: row;
    gap: 12px;
    z-index: 2007;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity var(--char-transition-normal) ease 0.1s, 
                transform var(--char-transition-normal) ease 0.1s;
}

.character-welcome-buttons.visible {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.character-btn-tour {
    flex: 1;
    background: linear-gradient(135deg, var(--char-btn-primary-start) 0%, var(--char-btn-primary-end) 100%);
    color: #fff;
    border: none;
    padding: 14px 20px;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--char-transition-normal) ease;
    box-shadow: 0 4px 20px var(--char-accent-glow);
}

.character-btn-tour i {
    margin-right: 8px;
}

.character-btn-tour:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(var(--char-accent-rgb), 0.6);
}

.character-btn-skip {
    background: var(--char-btn-secondary-bg);
    color: var(--char-text-muted);
    border: 1px solid var(--char-btn-secondary-border);
    padding: 14px 20px;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--char-transition-fast) ease;
    white-space: nowrap;
}

.character-btn-skip:hover {
    color: #fff;
    border-color: #6b6b8c;
    background: rgba(255, 255, 255, 0.12);
}

/* ============================================
   VIDEO CONTAINER
   ============================================ */
.character-video-container {
    display: none;
    margin-bottom: 15px;
    border-radius: 10px;
    overflow: hidden;
}

.character-video-container.active {
    display: block;
}

.character-video-container video {
    width: 100%;
    border-radius: 10px;
    background: #000;
}

/* ============================================
   FINAL STEP / CTA BUTTONS
   ============================================ */
.character-final-buttons {
    display: none;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    width: 100%;
}

.character-final-buttons.active {
    display: flex;
}

.character-final-skip {
    background: transparent;
    border: none;
    color: #6b7280;
    font-size: 0.8em;
    cursor: pointer;
    padding: 4px 8px;
    transition: color var(--char-transition-fast) ease;
}

.character-final-skip:hover {
    color: var(--char-text-muted);
}

/* ============================================
   NOTIFICATION BADGE
   Slides in from top, auto-dismisses
   ============================================ */
.character-notification {
    position: fixed;
    overflow: hidden;
    top: 20px;
    right: 20px;
    left: auto;
    bottom: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, var(--bubble-bg-start) 0%, var(--bubble-bg-end) 100%);
    border: 2px solid var(--bubble-border);
    border-radius: 16px;
    padding: 12px 40px 12px 12px;
    z-index: 30000;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-100%);
    transition: all var(--char-transition-slow) cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    max-width: 350px;
}

.character-notification.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.character-notification:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.5);
}

.character-notification-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.character-notification-text {
    color: var(--char-text-body);
    font-size: 0.95em;
    font-weight: 500;
    line-height: 1.4;
}

.character-notification-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    color: var(--char-text-muted);
    font-size: 1.2em;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    transition: color var(--char-transition-fast) ease;
}

.character-notification-close:hover {
    color: var(--char-text-title);
}

.character-notification-badge {
    position: absolute;
    top: -5px;
    left: -5px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 0.7em;
    font-weight: 700;
    color: #fff;
    animation: notificationPulse 2s ease-in-out infinite;
}

.character-notification-badge.visible {
    display: flex;
}

@keyframes notificationPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }

}

/* Notification progress bar for auto-dismiss */
.character-notification-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: var(--char-accent);
    border-radius: 0 0 0 14px;
    width: 100%;
    transform-origin: left;
    transition: transform linear;
}

.character-notification.no-progress .character-notification-progress {
    display: none;
}

/* ============================================
   MOBILE RESPONSIVE - TABLET
   ============================================ */
@media (max-width: 768px) {
    .character-welcome-buttons {
        max-width: calc(100% - 30px);
        gap: 10px;
    }
    
    .character-btn-tour {
        padding: 12px 18px;
        font-size: 0.95em;
    }
    
    .character-btn-skip {
        padding: 10px 16px;
        font-size: 0.9em;
    }
    
    /* Character sizing */
    .character-image-container {
        width: 220px;
        height: 220px;
        bottom: -25px;
    }
    
    .character-image {
        width: 220px;
        top: 25px;
    }
    
    /* Speech bubble - full width at bottom */
    .character-speech-bubble {
        left: 15px;
        right: 15px;
        bottom: 15px;
        padding: 15px 18px;
        max-width: none;
    }
    
    /* Arrow points UP to character above */
    .character-speech-bubble::before {
        left: 35px;
        bottom: auto;
        top: -23px;
        border: 12px solid transparent;
        border-bottom-color: var(--char-accent-secondary);
        border-right-color: transparent;
    }
    
    .character-speech-bubble::after {
        left: 37.5px;
        bottom: auto;
        top: -18px;
        border: 10px solid transparent;
        border-bottom-color: var(--char-accent);
        border-right-color: transparent;
    }
    
    .character-speech-title {
        font-size: 1.1em;
    }
    
    .character-speech-text {
        font-size: 0.95em;
        margin-bottom: 15px;
    }

    .character-name-badge {
        bottom: 12px;
        font-size: .85em;
        font-weight: 700;
    }
    
    .character-nav-next {
        padding: 10px 20px;
        font-size: 0.95em;
    }
    
    .character-video-container video {
        max-height: 30vh;
        object-fit: contain;
    }
    
    /* Tooltip adjustments */
    .character-tooltip {
        max-width: 260px;
        font-size: 0.9em;
        padding: 12px 16px;
    }
    
    /* Notification - center on mobile */
    .character-notification {
        top: 15px;
        right: 15px;
        left: 15px;
        max-width: none;
    }
}

/* ============================================
   MOBILE RESPONSIVE - SMALL PHONES
   ============================================ */
@media (max-width: 480px) {
    .character-welcome-buttons {
        gap: 8px;
    }
    
    .character-btn-tour {
        padding: 10px 14px;
        font-size: 0.9em;
    }
    
    .character-btn-skip {
        padding: 8px 12px;
        font-size: 0.85em;
    }
    
    /* Smaller Lilly on small screens */
    .character-image-container {
        width: 180px;
        height: 180px;
        bottom: -12px;
    }
    
    .character-image {
        width: 180px;
        top: 25px;
    }
    
    .character-speech-bubble {
        left: 10px;
        right: 10px;
        padding: 12px 15px;
    }
    
    .character-speech-title {
        font-size: 1em;
        flex-wrap: wrap;
    }
    
    .character-speech-title .step-indicator {
        font-size: 0.65em;
    }
    
    .character-speech-text {
        font-size: 0.9em;
        line-height: 1.5;
    }
    
    /* Profile sizing */
    .character-profile {
        width: 50px;
        height: 50px;
    }
    
    .character-profile.large {
        width: 60px;
        height: 60px;
    }
}

/* ============================================
   SPECIAL POSITIONING CLASSES
   For elements near bottom of screen (help button, etc)
   ============================================ */
.character-speech-bubble.position-elevated {
    max-width: 380px;
    right: auto;
}

@media (max-width: 768px) {
    .character-speech-bubble.position-elevated {
        bottom: 90px;
        left: 15px;
        right: 15px;
        max-width: none;
    }
    
    .character-guide.position-elevated {
        bottom: 210px;
    }
}

@media (max-width: 480px) {
    .character-speech-bubble.position-elevated {
        bottom: 80px;
    }
    
    .character-guide.position-elevated {
        bottom: 190px;
    }
}

/* ============================================
   PROGRESS DOTS (for multi-step tours)
   ============================================ */
.character-progress {
    display: none; /* Hidden by default, shown via JS */
    justify-content: center;
    gap: 8px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.character-progress-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transition: all var(--char-transition-fast) ease;
}

.character-progress-dot.active {
    background: var(--char-accent-secondary);
    transform: scale(1.2);
}

.character-progress-dot.completed {
    background: var(--char-accent);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.char-hidden {
    display: none !important;
}

.char-no-scroll {
    overflow: hidden !important;
}