* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    /* Font options - uncomment to try different fonts:
       font-family: 'Lato', sans-serif;          (Default - Clean and professional)
       font-family: 'Inter', sans-serif;         (Modern and highly readable)
       font-family: 'Poppins', sans-serif;       (Geometric and friendly)
       font-family: 'Source Sans Pro', sans-serif; (Adobe's clean design)
       font-family: 'Nunito', sans-serif;        (Rounded and approachable)
    */
    font-family: 'Nunito', 'Lato', sans-serif;
    background: linear-gradient(to bottom, #0a0015 0%, #1a0a2e 50%, #2d1b4e 100%);
    height: 100vh;
    height: 100dvh; /* 동적 viewport height - 사파리 대응 */
    min-height: -webkit-fill-available; /* iOS Safari 대응 */
    color: white;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
}

body.constellation-page {
    overflow: hidden;
}

/* Menu Bar */
.menu-bar {
    background: transparent;
    padding: 0.8rem 0;
}

.menu-list {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2.5rem;
    list-style: none;
}

.menu-item a {
    color: rgba(224, 212, 255, 0.7);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 400;
    padding: 0.4rem 0.8rem;
    border-radius: 5px;
    transition: all 0.3s ease;
}

.menu-item a:hover {
    background: rgba(147, 112, 219, 0.2);
    color: #fff;
    transform: translateY(-2px);
}

.menu-item a.active {
    color: #fff;
    background: rgba(147, 112, 219, 0.3);
}

/* Star Counter */
.star-counter-container {
    position: fixed;
    top: 70px;
    left: 2rem;
    z-index: 10;
}

.star-counter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.counter-label {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 300;
}

.counter-value {
    font-size: 0.75rem;
    font-weight: 300;
    color: rgba(255, 255, 255, 0.7);
}

/* Canvas Container */
.canvas-container {
    width: 100%;
    height: calc(100vh - 140px);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: crosshair;
    position: relative;
}

#constellation-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Overlay Illustration */
.overlay-illustration {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    display: none;
}

.overlay-illustration.visible {
    display: block;
    opacity: 0.85;
}

/* Controls */
.controls {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 1rem;
}

.btn {
    padding: 0.6rem 1.5rem;
    font-size: 0.85rem;
    font-weight: 400;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
    color: white;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* Candidates Section */
.candidates-section {
    position: fixed;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    width: 140px;
    max-height: calc(100vh - 80px); /* Prevent overflow on small screens */
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 15;
    overflow-y: auto; /* Enable vertical scrolling when needed */
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(147, 112, 219, 0.3) transparent;
}

.candidates-section::-webkit-scrollbar {
    width: 4px;
}

.candidates-section::-webkit-scrollbar-track {
    background: transparent;
}

.candidates-section::-webkit-scrollbar-thumb {
    background: rgba(147, 112, 219, 0.3);
    border-radius: 2px;
}

.candidates-section::-webkit-scrollbar-thumb:hover {
    background: rgba(147, 112, 219, 0.5);
}

.candidates-section.visible {
    opacity: 1;
    pointer-events: auto;
}

.candidates-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.8rem;
    padding-right: 0.3rem; /* Space for scrollbar */
}

.candidate-item {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0.5rem;
    position: relative;
    overflow: hidden;
}

.candidate-item:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.02);
}

.candidate-item.active {
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.05);
}

.candidate-preview {
    position: relative;
    width: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.candidate-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
}

.candidate-illustration {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 80%;
    max-height: 80%;
    object-fit: contain;
    opacity: 0.8;
}

.candidate-name {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.9);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    font-weight: 300;
}

/* Mobile Menu Styles */
@media (max-width: 768px) {
    .menu-bar {
        padding: 0.5rem 0 !important;
    }

    .menu-list {
        gap: 0.5rem !important;
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .menu-list::-webkit-scrollbar {
        display: none;
    }

    .menu-item a {
        font-size: 0.75rem !important;
        padding: 0.3rem 0.5rem !important;
    }

    /* Candidates Section Mobile - Horizontal layout at bottom */
    .candidates-section {
        position: fixed;
        right: auto;
        left: 0;
        top: auto;
        bottom: 75px; /* Above the controls - reduced spacing */
        transform: none;
        width: 100%;
        padding: 0 0.6rem;
    }

    .candidates-grid {
        display: flex;
        justify-content: center;
        gap: 0.4rem;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 0.3rem 0;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .candidates-grid::-webkit-scrollbar {
        display: none;
    }

    .candidate-item {
        /* Flexible width - fits 4 items on screen when possible */
        flex: 1 1 0;
        min-width: 70px;  /* Minimum size for very small screens */
        max-width: 110px; /* Maximum size to keep items compact */
        scroll-snap-align: start;
    }

    /* For very small screens (< 340px), allow scrolling with fixed width */
    @media (max-width: 340px) {
        .candidate-item {
            flex: 0 0 85px; /* Fixed width on tiny screens */
            min-width: 85px;
        }
    }

    .candidate-name {
        font-size: 0.8rem; /* Match button text size */
    }

    /* Adjust star counter position for mobile */
    .star-counter-container {
        top: 55px;
        left: 0.8rem;
    }

    /* Adjust canvas height to avoid overlap with bottom candidates */
    .canvas-container {
        height: calc(100vh - 210px); /* Reduced spacing for less cramped feel */
    }

    /* Controls stay at the bottom */
    .controls {
        bottom: 1rem;
        gap: 0.6rem;
    }

    .btn {
        padding: 0.5rem 1.2rem;
        font-size: 0.8rem;
    }
}

/* Mobile Landscape - Keep vertical layout on left side */
@media (max-width: 768px) and (orientation: landscape) {
    .candidates-section {
        /* Use left side vertical layout for landscape */
        position: fixed;
        left: 0.6rem;
        right: auto;
        top: 50%;
        bottom: auto;
        transform: translateY(-50%);
        width: 100px;
        max-height: calc(100vh - 20px); /* Minimal top/bottom margin for scrollable area */
        padding: 0;
    }

    .candidates-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.6rem; /* Keep spacing between items */
        overflow-x: visible;
        overflow-y: visible;
        padding: 0 0.3rem 0 0;
    }

    .candidate-item {
        flex: none;
        min-width: auto;
        max-width: none;
        width: 100%;
        aspect-ratio: 1;
    }

    .candidate-name {
        font-size: 0.7rem;
    }

    /* Adjust canvas to avoid overlap with left candidates */
    .canvas-container {
        margin-left: 115px;
        height: calc(100vh - 120px);
    }

    /* Move star counter to top right in landscape */
    .star-counter-container {
        top: 55px;
        left: auto;
        right: 0.8rem;
    }

    .controls {
        bottom: 0.8rem;
        gap: 0.5rem;
    }
}

/* Loading Animation Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 3px solid rgba(147, 112, 219, 0.2);
    border-top-color: rgba(147, 112, 219, 0.9);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    font-weight: 300;
    text-align: center;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Custom Alert Modal - Glassmorphism Design */
.custom-alert-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.custom-alert-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.custom-alert-box {
    background: rgba(26, 10, 46, 0.8);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 2rem 1.5rem 1.5rem;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(147, 112, 219, 0.3),
                inset 0 1px 1px rgba(255, 255, 255, 0.1);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.custom-alert-overlay.active .custom-alert-box {
    transform: scale(1);
}

.custom-alert-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(147, 112, 219, 0.2);
    font-size: 1.5rem;
}

.custom-alert-icon.info {
    background: rgba(100, 180, 255, 0.2);
}

.custom-alert-icon.warning {
    background: rgba(255, 180, 100, 0.2);
}

.custom-alert-icon.error {
    background: rgba(255, 100, 100, 0.2);
}

.custom-alert-message {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.95rem;
    font-weight: 300;
    text-align: center;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.custom-alert-button {
    width: 100%;
    padding: 0.7rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 400;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(147, 112, 219, 0.15);
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.custom-alert-button:hover {
    background: rgba(147, 112, 219, 0.3);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.custom-alert-button:active {
    transform: translateY(0);
}

/* Intro Splash Screen */
.splash-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, #1b1464 0%, #0a0a2e 50%, #000000 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.6s ease;
}

.splash-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.splash-logo-container {
    display: flex;
    align-items: center;
    gap: 20px;
}

.splash-star-logo {
    width: 80px;
    height: 80px;
    animation: splashStarShoot 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards,
               splashIntensePulse 2s ease-in-out 1.2s infinite;
    filter: drop-shadow(0 0 30px rgba(255, 215, 0, 1));
}

@keyframes splashStarShoot {
    0% {
        opacity: 1;
        transform: translateX(800px) translateY(-100px) scale(0.3) rotate(-360deg);
        filter: drop-shadow(0 0 50px rgba(255, 215, 0, 1));
    }
    50% {
        opacity: 1;
        transform: translateX(200px) translateY(-20px) scale(0.8) rotate(-180deg);
        filter: drop-shadow(0 0 40px rgba(255, 215, 0, 1));
    }
    80% {
        opacity: 1;
        transform: translateX(-20px) scale(1.1) rotate(-30deg);
        filter: drop-shadow(0 0 35px rgba(255, 215, 0, 0.9));
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1) rotate(0deg);
        filter: drop-shadow(0 0 30px rgba(255, 215, 0, 1));
    }
}

@keyframes splashIntensePulse {
    0%, 100% {
        filter: drop-shadow(0 0 30px rgba(255, 215, 0, 1));
    }
    50% {
        filter: drop-shadow(0 0 50px rgba(255, 255, 100, 1));
    }
}

.splash-text-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.splash-main-text {
    font-size: 48px;
    font-weight: 600;
    color: #ffffff;
    letter-spacing: 1px;
    animation: splashTextIlluminate 1s ease-out 1s forwards;
    opacity: 0;
}

.splash-main-text span {
    font-weight: 700;
    background: linear-gradient(45deg, #FFD700, #FFA500);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.splash-dot-com {
    font-size: 28px;
    font-weight: 300;
    color: #FFD700;
    margin-left: 260px;
    margin-top: -15px;
    animation: splashDotComShine 0.8s ease-out 1.8s forwards;
    opacity: 0;
}

@keyframes splashTextIlluminate {
    0% {
        opacity: 0;
        transform: scale(0.9);
        text-shadow: 0 0 0px rgba(255, 255, 255, 0);
    }
    50% {
        opacity: 0.5;
        transform: scale(0.95);
        text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
    }
    100% {
        opacity: 1;
        transform: scale(1);
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    }
}

@keyframes splashDotComShine {
    0% {
        opacity: 0;
        text-shadow: 0 0 0px rgba(255, 215, 0, 0);
    }
    100% {
        opacity: 1;
        text-shadow: 0 0 15px rgba(255, 215, 0, 0.8);
    }
}
