/* ==========================================================================
   Name Picker Tool - Modern Glass-morphism Design
   Following virtual-bouncy-balls pattern
   ========================================================================== */

/* Override page wrapper background for Name Picker */
.tool-page-wrapper:has(.np-container) {
    min-height: 0 !important;
    background: #ffffff !important;
}

.tool-content-area:has(.np-container) {
    min-height: 0 !important;
}

.tool-page-wrapper:has(.np-container) .tool-content-area {
    background: #ffffff !important;
}

.np-container {
    --primary-color: #15aebf;
    --primary-light: #4ecdc4;
    --primary-dark: #0e9bb2;
    --secondary-color: #ff6b35;
    --secondary-light: #ff8c5a;
    --accent-color: #ffd93d;
    --success-color: #00b894;
    --danger-color: #e17055;
    --warning-color: #fdcb6e;
    --white: #ffffff;
    --gray-100: #f1f3f4;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #adb5bd;
    --gray-600: #6c757d;
    --gray-700: #495057;
    --gray-800: #343a40;
    --text-primary: #2d3748;
    --text-secondary: #4a5568;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.25rem;
    --radius-full: 9999px;
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --bg-gradient: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    background: #ffffff;
}

.np-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 80vh;
    max-width: 1000px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem;
    gap: 0;
    background: #ffffff;
    align-items: center;
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
}

.np-game-container {
    position: relative;
    width: 100%;
    height: 100%;
    flex: 1;
    background: #ffffff;
    overflow: hidden;
    min-height: 400px;
    border-radius: var(--radius-xl);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

/* Watermark */
.np-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    opacity: 0.08;
    pointer-events: none;
    z-index: 1;
}

/* Top overlay - controls only */
.np-top-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    z-index: 100;
    pointer-events: none;
    background: linear-gradient(135deg, rgba(21, 174, 191, 0.95) 0%, rgba(78, 205, 196, 0.9) 30%, rgba(255, 217, 61, 0.85) 70%, rgba(255, 255, 255, 0.8) 100%);
}

.np-top-overlay > * {
    pointer-events: auto;
}

.np-top-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.np-result-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.25rem;
}

/* Controls */
.np-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.375rem;
    align-items: center;
}

.np-file-input-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
}

.np-file-input-wrapper input[type=file] {
    position: absolute;
    left: -9999px;
    opacity: 0;
    width: 0.1px;
    height: 0.1px;
    pointer-events: none;
}

.np-input-group {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.np-name-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-full);
    font-size: 0.8125rem;
    width: 140px;
    background: var(--white);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.np-name-input::placeholder {
    color: var(--gray-500);
}

.np-name-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(21, 174, 191, 0.2);
}

/* Button styles */
.np-btn {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.8125rem;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
}

.np-btn-secondary {
    background: var(--white);
    color: var(--text-secondary);
    border: 1px solid var(--gray-300);
}

.np-btn-secondary:hover {
    background: var(--gray-100);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
}

/* Clear button - purple gradient */
#npClearButton {
    background: linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%);
    color: white;
    border: 1px solid #a569bd;
}

#npClearButton:hover {
    background: linear-gradient(135deg, #8e44ad 0%, #7d3c98 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(155, 89, 182, 0.4);
    color: white;
}

.np-btn-file {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5252 100%);
    color: white;
    border-color: #ff8a75;
}

.np-btn-file:hover {
    background: linear-gradient(135deg, #ff5252 0%, #d43d3d 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
    color: white;
}

.np-btn-add {
    background: linear-gradient(135deg, #ffffff 0%, #f1f3f4 100%);
    color: var(--text-secondary);
    border: 1px solid var(--gray-300);
}

.np-btn-add:hover {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
}

.np-btn-pick {
    background: var(--bg-gradient);
    color: white;
    border-color: var(--primary-light);
    padding: 0.5rem 1rem;
}

.np-btn-pick:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(21, 174, 191, 0.4);
    color: white;
}

.np-btn-pick:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Stats */
.np-stats {
    display: flex;
    gap: 0.375rem;
    flex-shrink: 0;
}

.np-stat-card {
    background: rgba(0, 0, 0, 0.2);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.np-stat-value {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--white);
}

.np-stat-label {
    font-size: 0.5625rem;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Result display */
.np-result {
    padding: 0.375rem 0.875rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-lg);
    font-size: 0.8125rem;
    font-weight: 600;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--white);
    text-align: center;
}

.np-result-success {
    background: rgba(0, 184, 148, 0.4);
    border-color: var(--success-color);
    color: #7dffcc;
}

.np-result-error {
    background: rgba(225, 112, 85, 0.4);
    border-color: var(--danger-color);
    color: #ffb8a8;
}

.np-result-info {
    background: rgba(78, 205, 196, 0.3);
    border-color: var(--primary-light);
    color: #a8f0ec;
}

.np-result-picking {
    background: rgba(253, 203, 110, 0.4);
    border-color: var(--warning-color);
    color: #fff3cd;
    animation: np-pulse 1s ease-in-out infinite;
}

.np-result-winner {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.5) 0%, rgba(255, 165, 0, 0.5) 100%);
    border-color: #ffd700;
    color: #fff;
    font-size: 1rem;
    animation: np-winner-glow 0.5s ease-in-out infinite alternate;
}

@keyframes np-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.02); }
}

@keyframes np-winner-glow {
    0% { box-shadow: 0 0 10px rgba(255, 215, 0, 0.5); }
    100% { box-shadow: 0 0 20px rgba(255, 215, 0, 0.8), 0 0 30px rgba(255, 165, 0, 0.4); }
}

/* Crane system */
.np-crane-container {
    position: absolute;
    top: 95px;
    width: 100%;
    height: calc(100% - 95px);
    z-index: 20;
    pointer-events: none;
}

.np-crane {
    pointer-events: auto;
}

.np-crane-track {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 8px;
    background: linear-gradient(180deg, #555 0%, #333 50%, #555 100%);
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255,255,255,0.1);
}

.np-crane {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 70px;
    height: 80px;
    transition: left 1s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.np-crane-head {
    width: 70px;
    height: 18px;
    background: linear-gradient(180deg, #15aebf 0%, #0e9bb2 100%);
    border-radius: 9px;
    position: relative;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.np-crane-cable {
    width: 6px;
    height: 80px;
    background: linear-gradient(90deg, #222 0%, #555 50%, #222 100%);
    margin: 0 auto;
    transition: height 0.8s cubic-bezier(0.25, 0.1, 0.25, 1);
    position: relative;
    max-height: 90vh;
    border-radius: 3px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.np-crane-hook {
    width: 50px;
    height: 12px;
    background: linear-gradient(180deg, #888 0%, #666 100%);
    border-radius: 12px 12px 0 0;
    margin: 0 auto;
    position: relative;
    top: -6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.np-picked-ball {
    position: absolute;
    bottom: -70px;
    left: 50%;
    transform: translateX(-50%);
    width: 70px;
    height: 70px;
    border-radius: 50%;
    font-size: 10px;
    font-weight: bold;
    color: var(--white);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.2;
    word-wrap: break-word;
    z-index: 25;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    padding: 5px;
    animation: np-picked-glow 0.5s ease-in-out infinite alternate;
}

@keyframes np-picked-glow {
    0% { box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4), 0 0 20px rgba(255, 255, 255, 0.2); }
    100% { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5), 0 0 40px rgba(255, 255, 255, 0.4); }
}

/* Balls container */
.np-balls-container {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    top: 95px;
    overflow: hidden;
}

/* Ball styles */
.np-ball {
    position: absolute;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    color: var(--white);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    text-align: center;
    line-height: 1.2;
    word-wrap: break-word;
    overflow: hidden;
    z-index: 10;
    padding: 5px;
    will-change: transform;
}

.np-ball:hover {
    filter: brightness(1.1);
}

/* Ball animations - use opacity only to avoid transform conflicts */
@keyframes np-ball-create {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

.np-ball-created {
    animation: np-ball-create 0.3s ease-out;
}

@keyframes np-ball-remove {
    0% { opacity: 1; }
    100% { opacity: 0; transform: scale(0); }
}

.np-ball-removing {
    animation: np-ball-remove 0.4s ease-in forwards;
}

@keyframes np-ball-pick {
    0% { opacity: 1; }
    30% { transform: scale(1.15); filter: brightness(1.2); opacity: 1; }
    100% { transform: scale(0.3); opacity: 0; }
}

.np-ball-picked {
    animation: np-ball-pick 0.6s ease-out forwards;
    z-index: 30;
}

/* Fullscreen adjustments */
.tool-page-wrapper:fullscreen,
.tool-page-wrapper:-webkit-full-screen,
.tool-page-wrapper:-moz-full-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff !important;
    width: 100vw;
    height: 100vh;
}

.tool-page-wrapper:fullscreen .tool-content-area,
.tool-page-wrapper:-webkit-full-screen .tool-content-area,
.tool-page-wrapper:-moz-full-screen .tool-content-area {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff !important;
    width: 100%;
    height: 100%;
    flex: 1;
}

.tool-page-wrapper:fullscreen .np-container,
.tool-page-wrapper:-webkit-full-screen .np-container,
.tool-page-wrapper:-moz-full-screen .np-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.tool-page-wrapper:fullscreen .np-wrapper,
.tool-page-wrapper:-webkit-full-screen .np-wrapper,
.tool-page-wrapper:-moz-full-screen .np-wrapper {
    max-width: 1200px;
    max-height: 85vh;
    min-height: 70vh;
    margin: auto;
}

.tool-page-wrapper:fullscreen .np-crane,
.tool-page-wrapper:-webkit-full-screen .np-crane,
.tool-page-wrapper:-moz-full-screen .np-crane {
    width: 85px;
}

.tool-page-wrapper:fullscreen .np-crane-head,
.tool-page-wrapper:-webkit-full-screen .np-crane-head,
.tool-page-wrapper:-moz-full-screen .np-crane-head {
    width: 85px;
    height: 20px;
    border-radius: 10px;
}

.tool-page-wrapper:fullscreen .np-crane-cable,
.tool-page-wrapper:-webkit-full-screen .np-crane-cable,
.tool-page-wrapper:-moz-full-screen .np-crane-cable {
    max-height: none;
    width: 7px;
}

.tool-page-wrapper:fullscreen .np-crane-hook,
.tool-page-wrapper:-webkit-full-screen .np-crane-hook,
.tool-page-wrapper:-moz-full-screen .np-crane-hook {
    width: 65px;
    height: 14px;
}

.tool-page-wrapper:fullscreen .np-ball,
.tool-page-wrapper:-webkit-full-screen .np-ball,
.tool-page-wrapper:-moz-full-screen .np-ball {
    width: 90px;
    height: 90px;
    font-size: 12px;
    padding: 6px;
}

.tool-page-wrapper:fullscreen .np-picked-ball,
.tool-page-wrapper:-webkit-full-screen .np-picked-ball,
.tool-page-wrapper:-moz-full-screen .np-picked-ball {
    width: 90px;
    height: 90px;
    font-size: 12px;
    bottom: -95px;
}

/* RTL support */
[dir="rtl"] .np-wrapper {
    direction: rtl;
}

/* RTL UI adjustments */
[dir="rtl"] .np-name-input {
    text-align: right;
}

[dir="rtl"] .np-name-input::placeholder {
    text-align: right;
}

[dir="rtl"] .np-btn {
    flex-direction: row-reverse;
}

[dir="rtl"] .np-input-group {
    flex-direction: row-reverse;
}

[dir="rtl"] .np-result-row {
    flex-direction: row-reverse;
}

[dir="rtl"] .np-stat-card {
    flex-direction: row-reverse;
}

/* Force LTR for physics-based elements - balls use absolute pixel positioning */
[dir="rtl"] .np-game-container,
[dir="rtl"] .np-balls-container,
[dir="rtl"] .np-crane-container,
[dir="rtl"] .np-crane,
[dir="rtl"] .np-ball,
[dir="rtl"] .np-picked-ball {
    direction: ltr;
}

/* Ensure balls container doesn't inherit RTL offset */
[dir="rtl"] .np-balls-container {
    left: 0;
    right: 0;
    transform: none;
}

/* Ensure crane positioning works correctly in RTL */
[dir="rtl"] .np-crane {
    /* Crane uses left percentage + translateX, preserve transform */
    transform: translateX(-50%);
}

[dir="rtl"] .np-crane-container {
    left: 0;
    right: 0;
}

/* Responsive - Mobile */
@media (max-width: 600px) {
    .np-wrapper {
        padding: 1rem;
    }

    .np-top-overlay {
        padding: 0.5rem;
        gap: 0.4rem;
    }

    .np-top-row {
        gap: 0.4rem;
        flex-direction: column;
        align-items: center;
        width: 100%;
    }

    .np-result-row {
        gap: 0.4rem;
        flex-direction: row;
        justify-content: center;
        flex-wrap: wrap;
    }

    .np-result {
        font-size: 0.75rem;
        padding: 0.3rem 0.6rem;
    }

    /* Controls - flexbox row wrap layout for mobile */
    .np-controls {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        gap: 0.35rem;
        width: 100%;
        max-width: 340px;
    }

    /* All buttons - ensure icon and text visible */
    .np-btn {
        padding: 0.4rem 0.6rem !important;
        font-size: 0.75rem !important;
        gap: 0.3rem !important;
        min-height: 34px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        white-space: nowrap !important;
    }

    /* Force show all spans inside buttons */
    .np-btn span,
    .np-btn-file span,
    .np-btn-add span,
    .np-btn-pick span,
    #npClearButton span {
        display: inline !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* File/Upload button */
    .np-btn-file {
        flex: 0 0 auto;
    }

    /* Input group */
    .np-input-group {
        display: flex;
        gap: 0.2rem;
        align-items: center;
        flex: 1 1 auto;
        min-width: 100px;
        max-width: 160px;
    }

    .np-name-input {
        flex: 1;
        min-width: 70px;
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
    }

    /* Add button - small square, icon only */
    .np-btn-add {
        flex: 0 0 auto;
        padding: 0.35rem !important;
        min-width: 32px !important;
        min-height: 32px !important;
        width: 32px !important;
        height: 32px !important;
    }

    /* Clear button - small square like Add button */
    #npClearButton {
        flex: 0 0 auto;
        padding: 0.35rem !important;
        min-width: 32px !important;
        min-height: 32px !important;
        width: 32px !important;
        height: 32px !important;
    }

    /* Pick button - full width on its own row */
    .np-btn-pick {
        flex: 1 0 100%;
        min-width: 100%;
    }

    .np-stat-card { padding: 0.2rem 0.4rem; }
    .np-stat-value { font-size: 0.75rem; }
    .np-stat-label { font-size: 0.55rem; }

    .np-ball { width: 60px; height: 60px; font-size: 9px; }
    .np-picked-ball { width: 65px; height: 65px; font-size: 10px; bottom: -70px; }
    .np-crane { width: 60px; }
    .np-crane-head { width: 60px; height: 14px; }
    .np-crane-hook { width: 45px; height: 10px; }
    .np-crane-container { top: 95px; }
    .np-balls-container { top: 95px; }
}

/* Extra small screens */
@media (max-width: 400px) {
    .np-controls {
        max-width: 300px;
        gap: 0.3rem;
    }

    .np-btn {
        padding: 0.35rem 0.5rem !important;
        font-size: 0.7rem !important;
        min-height: 30px !important;
    }

    .np-input-group {
        min-width: 110px;
        max-width: 180px;
    }

    .np-name-input {
        min-width: 80px;
        font-size: 0.7rem;
    }

    .np-btn-add,
    #npClearButton {
        width: 30px !important;
        height: 30px !important;
        min-width: 30px !important;
        min-height: 30px !important;
        padding: 0.3rem !important;
    }

    .np-result {
        font-size: 0.7rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .np-ball-created,
    .np-ball-removing,
    .np-ball-picked { animation: none; }
    .np-result-picking { animation: none; }
    .np-result-winner { animation: none; }
    .np-picked-ball { animation: none; }
}
