/* ==========================================================================
   Name Spinner Tool - Modern Glass-morphism Design
   Spinning wheel that picks random names
   Following Zhween branding & name-picker pattern
   ========================================================================== */

/* Override page wrapper background & forced heights */
.tool-page-wrapper:has(.ns-container) {
    background: #ffffff !important;
    min-height: 0 !important;
}

.tool-page-wrapper:has(.ns-container) .tool-content-area {
    background: #ffffff !important;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0 !important;
    overflow: visible !important;
}

.ns-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    --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;
}

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

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

/* Top overlay - controls */
.ns-top-overlay {
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    z-index: 100;
    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%);
    flex-shrink: 0;
}

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

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

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

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

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

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

.ns-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;
}

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

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

/* Button styles */
.ns-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;
}

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

#nsClearButton: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;
}

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

.ns-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;
}

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

.ns-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);
}

/* Spin button */
.ns-btn-spin {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #e55a2b 100%);
    color: white;
    border-color: var(--secondary-light);
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    box-shadow: 0 4px 15px rgba(255, 107, 53, 0.3);
    margin-top: 0;
}

.ns-btn-spin:hover:not(:disabled) {
    background: linear-gradient(135deg, #e55a2b 0%, #cc4a1e 100%);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(255, 107, 53, 0.5);
    color: white;
}

.ns-btn-spin:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ns-btn-spin:active:not(:disabled) {
    transform: translateY(-1px);
}

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

.ns-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;
}

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

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

/* Result display */
.ns-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;
}

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

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

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

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

.ns-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: ns-winner-glow 0.5s ease-in-out infinite alternate;
}

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

@keyframes ns-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); }
}

/* ============================================================
   Spinner Area
   ============================================================ */
.ns-spinner-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    position: relative;
    z-index: 10;
}

.ns-wheel-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Pointer */
.ns-pointer {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3));
}

/* Canvas */
#nsWheelCanvas {
    width: 340px;
    height: 340px;
    border-radius: 50%;
    box-shadow:
        0 0 0 8px #15aebf,
        0 0 0 12px rgba(21, 174, 191, 0.3),
        0 8px 30px rgba(0, 0, 0, 0.25);
    transition: filter 0.3s ease;
}

#nsWheelCanvas.ns-wheel-spinning {
    filter: drop-shadow(0 0 20px rgba(21, 174, 191, 0.4));
}

/* ============================================================
   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 .ns-container,
.tool-page-wrapper:-webkit-full-screen .ns-container,
.tool-page-wrapper:-moz-full-screen .ns-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.tool-page-wrapper:fullscreen .ns-game-container,
.tool-page-wrapper:-webkit-full-screen .ns-game-container,
.tool-page-wrapper:-moz-full-screen .ns-game-container {
    max-width: 900px;
    margin: 0 auto;
    height: 100%;
    justify-content: center;
    align-items: center;
}

.tool-page-wrapper:fullscreen .ns-top-overlay,
.tool-page-wrapper:-webkit-full-screen .ns-top-overlay,
.tool-page-wrapper:-moz-full-screen .ns-top-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
}

.tool-page-wrapper:fullscreen .ns-spinner-area,
.tool-page-wrapper:-webkit-full-screen .ns-spinner-area,
.tool-page-wrapper:-moz-full-screen .ns-spinner-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.tool-page-wrapper:fullscreen #nsWheelCanvas,
.tool-page-wrapper:-webkit-full-screen #nsWheelCanvas,
.tool-page-wrapper:-moz-full-screen #nsWheelCanvas {
    width: 600px;
    height: 600px;
}

.tool-page-wrapper:fullscreen .ns-btn-spin,
.tool-page-wrapper:-webkit-full-screen .ns-btn-spin,
.tool-page-wrapper:-moz-full-screen .ns-btn-spin {
    font-size: 1rem;
    padding: 0.65rem 1.75rem;
}

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

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

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

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

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

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

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

/* ============================================================
   Responsive - Mobile
   ============================================================ */
@media (max-width: 600px) {
    .ns-game-container {
        min-height: 0;
        overflow-y: auto;
    }

    .ns-top-overlay {
        padding: 0.35rem 0.5rem;
        gap: 0.25rem;
    }

    .ns-top-row {
        gap: 0.3rem;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        width: 100%;
    }

    .ns-result-row {
        gap: 0.3rem;
        flex-direction: row;
        justify-content: center;
        flex-wrap: wrap;
        margin-bottom: 0.1rem;
    }

    .ns-result {
        font-size: 0.7rem;
        padding: 0.2rem 0.5rem;
    }

    .ns-controls {
        display: flex;
        flex-wrap: nowrap;
        justify-content: center;
        align-items: center;
        gap: 0.25rem;
        width: auto;
    }

    .ns-btn {
        padding: 0.35rem 0.6rem !important;
        font-size: 0.8rem !important;
        gap: 0.25rem !important;
        min-height: 34px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        white-space: nowrap !important;
        overflow: visible !important;
    }

    /* Override base_tool.html hiding all .tool-btn spans on mobile */
    .ns-btn span {
        display: inline !important;
        font-size: 0.9rem !important;
        line-height: 1 !important;
    }

    /* Hide text labels on mobile, keep only icons */
    .ns-btn-file span:last-child {
        display: none !important;
    }

    .ns-btn-file {
        flex: 0 0 auto;
    }

    .ns-input-group {
        display: flex;
        gap: 0.2rem;
        align-items: center;
        flex: 0 1 auto;
        min-width: 80px;
        max-width: 130px;
    }

    .ns-name-input {
        flex: 1;
        min-width: 60px;
        font-size: 0.75rem;
        padding: 0.35rem 0.5rem;
    }

    .ns-btn-add {
        flex: 0 0 auto;
        padding: 0.3rem !important;
        min-width: 34px !important;
        min-height: 34px !important;
        width: 34px !important;
        height: 34px !important;
    }

    #nsClearButton {
        flex: 0 0 auto;
        padding: 0.3rem !important;
        min-width: 34px !important;
        min-height: 34px !important;
        width: 34px !important;
        height: 34px !important;
    }

    .ns-stat-card { padding: 0.15rem 0.35rem; }
    .ns-stat-value { font-size: 0.7rem; }
    .ns-stat-label { font-size: 0.5rem; }

    #nsWheelCanvas {
        width: 200px;
        height: 200px;
    }

    .ns-btn-spin {
        font-size: 0.85rem !important;
        padding: 0.5rem 1.5rem !important;
        width: auto !important;
        min-width: 100px !important;
        min-height: 36px !important;
    }

    .ns-btn-spin span {
        display: inline !important;
        visibility: visible !important;
    }

    .ns-spinner-area {
        flex: 0 1 auto;
        justify-content: flex-start;
        padding: 0.5rem;
        gap: 1.25rem;
    }

    .ns-pointer svg {
        width: 26px;
        height: 32px;
    }
}

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

    .ns-btn {
        padding: 0.3rem 0.4rem !important;
        font-size: 0.75rem !important;
        min-height: 30px !important;
    }

    .ns-btn span {
        display: inline !important;
        font-size: 0.85rem !important;
    }

    .ns-input-group {
        min-width: 70px;
        max-width: 110px;
    }

    .ns-name-input {
        min-width: 50px;
        font-size: 0.65rem;
    }

    .ns-btn-add,
    #nsClearButton {
        width: 30px !important;
        height: 30px !important;
        min-width: 30px !important;
        min-height: 30px !important;
        padding: 0.25rem !important;
    }

    .ns-result {
        font-size: 0.65rem;
    }

    #nsWheelCanvas {
        width: 170px;
        height: 170px;
    }

    .ns-btn-spin {
        font-size: 0.8rem !important;
        padding: 0.45rem 1.25rem !important;
        width: auto !important;
        min-width: 90px !important;
        min-height: 34px !important;
    }

    .ns-pointer svg {
        width: 22px;
        height: 28px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ns-result-spinning { animation: none; }
    .ns-result-winner { animation: none; }
}
