/* ===== CSS Variables ===== */
:root {
    --bg-primary: #0a0e27;
    --bg-secondary: #1a1f3a;
    --accent-tech: #00f6ff;
    --accent-voice: #ff00ff;
    --text-primary: #ffffff;
    --text-secondary: #b8c1ec;
    --border-color: #2a3a5a;
    --glow-tech: 0 0 20px rgba(0, 246, 255, 0.5);
    --glow-voice: 0 0 20px rgba(255, 0, 255, 0.5);

    /* Z-index scale */
    --z-background: 0;
    --z-content: 1;
    --z-header: 10;
    --z-navigation-hints: 10;
    --z-modal: 1000;
}

/* ===== Reset & Base Styles ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

body {
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(
        135deg,
        var(--bg-primary) 0%,
        var(--bg-secondary) 100%
    );
    color: var(--text-primary);
    min-height: 100vh; /* Fallback for older browsers */
    min-height: 100.5vh; /* Slightly taller to enable scroll for iOS 26 address bar collapse */
    height: 100dvh; /* Dynamic viewport height - adapts to Safari's UI */
    overflow-x: hidden;
    overflow-y: auto; /* Allow minimal vertical scroll for iOS 26 address bar */
    position: relative;
    -webkit-overflow-scrolling: touch;
}

/* Hide scrollbar while keeping scroll functionality */
body,
.character-select {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

body::-webkit-scrollbar,
.character-select::-webkit-scrollbar {
    display: none;
}

/* Animated background effect */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(
            circle at 20% 50%,
            rgba(0, 246, 255, 0.1) 0%,
            transparent 50%
        ),
        radial-gradient(
            circle at 80% 50%,
            rgba(255, 0, 255, 0.1) 0%,
            transparent 50%
        );
    animation: backgroundPulse 8s ease-in-out infinite;
    pointer-events: none;
    z-index: var(--z-background);
}

@keyframes backgroundPulse {
    0%,
    100% {
        opacity: 0.3;
    }
    50% {
        opacity: 0.6;
    }
}

/* ===== Game Container ===== */
.game-container {
    position: relative;
    z-index: var(--z-content);
    min-height: 100vh; /* Fallback for older browsers */
    height: 100dvh; /* Dynamic viewport height - adapts to Safari's UI */
    height: calc(var(--vh, 1vh) * 100); /* Fallback for browsers without dvh support */
    display: flex;
    flex-direction: column;
    max-width: 1400px;
    margin: 0 auto;
    overflow-x: hidden;
    overflow-y: visible;
}

/* ===== Header ===== */
.game-header {
    flex: 0 0 auto;
    text-align: center;
    padding: 40px 15px 10px;
    animation: slideDown 0.8s ease-out;
    background: transparent;
    position: relative;
    z-index: var(--z-header);
    pointer-events: none;
}

.game-header * {
    pointer-events: auto;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.glitch {
    font-size: clamp(2rem, 8vw, 4rem);
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    position: relative;
    display: inline-block;
    background: linear-gradient(
        90deg,
        var(--accent-tech) 0%,
        var(--accent-voice) 100%
    );
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: glitchPulse 3s ease-in-out infinite;
    will-change: filter;
}

@keyframes glitchPulse {
    0%,
    100% {
        filter: brightness(1);
    }
    50% {
        filter: brightness(1.3);
    }
}

.subtitle {
    font-size: clamp(0.9rem, 3vw, 1.2rem);
    color: var(--text-secondary);
    letter-spacing: 0.3em;
    margin-top: 10px;
    font-weight: 300;
}

/* ===== Character Selection ===== */
.character-select {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 25px 15px 20px;
    margin-top: -20px;
    overflow-x: hidden;
    overflow-y: visible;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    z-index: var(--z-content);
}

.characters-wrapper {
    display: flex;
    width: 100%;
    max-width: 500px;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    touch-action: pan-x;
}

@media (max-width: 767px) {
    .characters-wrapper {
        cursor: grab;
    }

    .characters-wrapper:active {
        cursor: grabbing;
    }
}

/* ===== Character Cards ===== */
.character-card {
    min-width: 100%;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    opacity: 0.5;
    transform: scale(0.9);
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: visible;
}

.character-card.active {
    opacity: 1;
    transform: scale(1);
}

.character-frame {
    width: 200px;
    height: 200px;
    position: relative;
    margin-bottom: 30px;
    border: 3px solid var(--border-color);
    border-radius: 20px;
    background: rgba(26, 31, 58, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    isolation: isolate; /* Create stacking context for nav hints */
}

.character-card.active .character-frame {
    border-color: currentColor;
    box-shadow: 0 0 30px currentColor;
    transform: translateY(-10px);
}

.character-card[data-character="tech"] {
    color: var(--accent-tech);
}

.character-card[data-character="voice"] {
    color: var(--accent-voice);
}

.character-icon {
    width: 120px;
    height: 120px;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.character-card.active .character-icon {
    opacity: 1;
    animation: iconPulse 2s ease-in-out infinite;
    will-change: transform;
}

.character-card:not(.active) .character-icon {
    will-change: auto;
}

@keyframes iconPulse {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* ===== Character Info ===== */
.character-info {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    width: 100%;
    max-width: 400px;
}

.character-title {
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: 800;
    letter-spacing: 0.2em;
    margin-bottom: 20px;
    text-transform: uppercase;
}

.character-stats {
    margin-bottom: 30px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    background: rgba(26, 31, 58, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    transition: all 0.3s ease;
}

.character-card.active .stat {
    border-color: currentColor;
    background: rgba(26, 31, 58, 0.9);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    letter-spacing: 0.2em;
    margin-bottom: 5px;
    font-weight: 600;
}

.stat-value {
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
}

/* ===== Select Button ===== */
.select-button {
    position: relative;
    display: inline-block;
    padding: 15px 50px;
    font-size: 1.1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--text-primary);
    text-decoration: none;
    border: 2px solid currentColor;
    border-radius: 50px;
    background: transparent;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(20px);
    align-self: center;
}

.character-card.active .select-button {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.2s;
}

.character-card[data-character="tech"] .select-button:hover {
    background: var(--accent-tech);
    color: var(--bg-primary);
    box-shadow: 0 0 30px var(--accent-tech);
    transform: translateY(-3px);
}

.character-card[data-character="voice"] .select-button:hover {
    background: var(--accent-voice);
    color: var(--bg-primary);
    box-shadow: 0 0 30px var(--accent-voice);
    transform: translateY(-3px);
}

.select-button span:first-child {
    position: relative;
    z-index: 2;
}

.button-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition:
        width 0.6s,
        height 0.6s;
    z-index: 1;
}

.character-card[data-character="tech"] .button-glow {
    background: var(--accent-tech);
}

.character-card[data-character="voice"] .button-glow {
    background: var(--accent-voice);
}

.select-button:hover .button-glow {
    width: 300px;
    height: 300px;
}

/* ===== Options Link ===== */
.options-link {
    position: relative;
    margin-top: 15px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    cursor: pointer;
    transition:
        color 0.3s ease,
        background 0.3s ease;
    opacity: 0;
    transform: translateY(10px);
    padding: 8px 12px;
    border-radius: 8px;
    align-self: center;
}

.character-card.active .options-link {
    opacity: 0.6;
    transform: translateY(0);
    transition:
        opacity 0.3s ease 0.3s,
        transform 0.3s ease 0.3s,
        color 0.3s ease,
        background 0.3s ease;
}

.options-link svg {
    width: 16px;
    height: 16px;
    transition: all 0.3s ease;
}

.character-card[data-character="tech"] .options-link:hover {
    opacity: 1;
    color: var(--accent-tech);
    background: rgba(26, 31, 58, 0.6);
}

.character-card[data-character="voice"] .options-link:hover {
    opacity: 1;
    color: var(--accent-voice);
    background: rgba(26, 31, 58, 0.6);
}

.options-link:hover svg {
    transform: scale(1.1);
}

.options-link:active {
    transform: scale(0.95);
}

/* ===== Navigation Indicators ===== */
.nav-indicators {
    display: flex;
    gap: 15px;
    margin-top: 40px;
    justify-content: center;
}

.nav-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--text-secondary);
    background: transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
}

.nav-dot:hover {
    transform: scale(1.2);
}

.nav-dot.active {
    background: var(--text-primary);
    box-shadow: 0 0 10px var(--text-primary);
    border-color: var(--text-primary);
}

/* ===== Character Navigation Hints ===== */
.character-nav-hint {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: currentColor;
    opacity: 0.5;
    transition: all 0.5s ease;
    pointer-events: none;
    z-index: var(--z-navigation-hints);
    will-change: transform, opacity;
}

.character-nav-hint.left-hint {
    left: -55px;
    animation: pulseLeft 2s ease-in-out infinite;
}

.character-nav-hint.right-hint {
    right: -55px;
    animation: pulseRight 2s ease-in-out infinite;
}

.character-nav-hint svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 8px currentColor);
}

@keyframes pulseLeft {
    0%,
    100% {
        transform: translateY(-50%) translateX(0);
        opacity: 0.4;
    }
    50% {
        transform: translateY(-50%) translateX(-5px);
        opacity: 0.7;
    }
}

@keyframes pulseRight {
    0%,
    100% {
        transform: translateY(-50%) translateX(0);
        opacity: 0.4;
    }
    50% {
        transform: translateY(-50%) translateX(5px);
        opacity: 0.7;
    }
}

/* ===== Menu Overlay ===== */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 14, 39, 0.95);
    backdrop-filter: blur(10px);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.3s ease,
        visibility 0.3s ease;
}

.menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

.menu-panel {
    background: linear-gradient(
        135deg,
        rgba(26, 31, 58, 0.95) 0%,
        rgba(26, 31, 58, 0.98) 100%
    );
    border: 3px solid var(--border-color);
    border-radius: 20px;
    padding: 40px;
    min-width: 320px;
    max-width: 500px;
    width: 90%;
    box-shadow:
        0 0 50px rgba(0, 246, 255, 0.2),
        0 0 100px rgba(255, 0, 255, 0.2);
}

.menu-overlay.active .menu-panel {
    animation: menuPanelAppear 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes menuPanelAppear {
    0% {
        transform: scale(0.8) translateY(-50px);
        opacity: 0;
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.menu-title {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 0.2em;
    background: linear-gradient(
        90deg,
        var(--accent-tech) 0%,
        var(--accent-voice) 100%
    );
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
}

.menu-close {
    background: transparent;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
}

.menu-close svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.menu-close:hover {
    border-color: var(--accent-voice);
    background: rgba(255, 0, 255, 0.1);
    transform: rotate(90deg);
}

.menu-close:hover svg {
    color: var(--accent-voice);
}

.menu-nav {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 30px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 20px;
    background: rgba(26, 31, 58, 0.6);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    text-decoration: none;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.menu-item::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(
        180deg,
        var(--accent-tech),
        var(--accent-voice)
    );
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

.menu-item:hover::before {
    transform: scaleY(1);
}

.menu-item-icon {
    font-size: 1.5rem;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    font-weight: bold;
}

.menu-item-text {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.menu-item:hover {
    border-color: var(--accent-tech);
    background: rgba(0, 246, 255, 0.05);
    transform: translateX(10px);
    box-shadow: 0 0 20px rgba(0, 246, 255, 0.2);
}

.menu-item:hover .menu-item-icon {
    color: var(--accent-tech);
    transform: translateX(5px);
}

.menu-item:hover .menu-item-text {
    color: var(--accent-tech);
}

.menu-footer {
    display: flex;
    justify-content: center;
    padding-top: 20px;
    border-top: 2px solid var(--border-color);
}

.menu-back-button {
    padding: 12px 40px;
    background: transparent;
    border: 2px solid var(--text-secondary);
    border-radius: 50px;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
}

.menu-back-button:hover {
    border-color: var(--accent-voice);
    color: var(--accent-voice);
    background: rgba(255, 0, 255, 0.1);
    box-shadow: 0 0 20px rgba(255, 0, 255, 0.3);
    transform: translateY(-2px);
}

/* ===== Tablet & Desktop ===== */
@media (min-width: 768px) {
    .characters-wrapper {
        max-width: 900px;
        gap: 40px;
        justify-content: center;
    }

    .character-card {
        min-width: auto;
        flex: 1;
        max-width: 400px;
    }

    .character-frame {
        width: 250px;
        height: 250px;
    }

    .character-icon {
        width: 150px;
        height: 150px;
    }

    .character-nav-hint {
        display: none;
    }

    .nav-indicators {
        display: none;
    }

    /* Show both characters side by side on desktop */
    .character-card {
        opacity: 0.6;
        transform: scale(0.95);
    }

    .character-card:hover,
    .character-card.active {
        opacity: 1;
        transform: scale(1);
    }
}

@media (min-width: 1024px) {
    .game-container {
        padding: 40px;
    }

    .character-frame {
        width: 280px;
        height: 280px;
    }

    .character-icon {
        width: 180px;
        height: 180px;
    }
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== Touch & Pointer Support ===== */
@media (hover: none) and (pointer: coarse) {
    .character-card:active {
        transform: scale(0.98);
    }
}
