:root {
    --bg-color: #000000;
    --text-color: #ffffff;
    --accent-glow: rgba(255, 255, 255, 0.15);
    --font-family: 'Outfit', sans-serif;
    
    --color-1: #00f2ff; /* Cyan */
    --color-2: #ff00ff; /* Magenta */
    --color-3: #39ff14; /* Lime */
    --color-4: #ffce00; /* Amber */
    --color-5: #bc13fe; /* Purple */
    --color-6: #ff3131; /* Crimson */
    --color-7: #ffffff; /* White */
    --color-8: #ff7b00; /* Orange */
}

body.theme-neon {
    --bg-color: #000000;
}

body.theme-retro {
    --bg-color: #3d1d2b; /* warmer retro deep plum red (higher contrast) */
    --color-1: #ff5e5e; 
    --color-2: #ffd93d; 
    --color-3: #6bc1ff; 
    --color-4: #4dff88; 
    --color-5: #ff884d; 
    --color-6: #ff4dff; 
    --color-7: #ffffff;
    --color-8: #9dff2e;
}

body.theme-cyber {
    --bg-color: #050505;
    --color-1: #ff0055;
    --color-2: #00ff99;
    --color-3: #0066ff;
    --color-4: #ffff00;
    --color-5: #aa00ff;
    --color-6: #00ffff;
    --color-7: #ffffff;
    --color-8: #ff6600;
    --accent-glow: rgba(255, 0, 85, 0.3);
}

body.theme-mono {
    --bg-color: #000000;
    --color-1: #ffffff;
    --color-2: #ffffff;
    --color-3: #ffffff;
    --color-4: #ffffff;
    --color-5: #ffffff;
    --color-6: #ffffff;
    --color-7: #ffffff;
    --color-8: #ffffff;
}

body.theme-cyber .grid-cell {
    background: linear-gradient(180deg, transparent 95%, rgba(0, 242, 255, 0.05) 95%),
                linear-gradient(90deg, transparent 95%, rgba(0, 242, 255, 0.05) 95%);
    background-size: 20px 20px;
}

body.theme-cyber #status-text {
    text-shadow: 2px 0 var(--color-1), -2px 0 var(--color-2);
    animation: cyber-glitch 2s infinite linear alternate-reverse;
}

@keyframes cyber-glitch {
    from { transform: skew(0.5deg); }
    to { transform: skew(-0.5deg); }
}

body.theme-mono .finger-indicator {
    border-radius: 4px;
    border: 2px solid white;
    box-shadow: inset 0 0 0 4px black, inset 0 0 0 6px white;
}

body.theme-mono .grid-cell {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: black;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body, html {
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    overflow: hidden;
    touch-action: none;
}

#app {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    height: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

#touch-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#ui-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
    z-index: 10;
}

#top-bar {
    position: absolute;
    top: 20px;
    left: 0;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0 20px;
    z-index: 100;
    width: 100%;
    pointer-events: none;
}

#mode-nav {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 12px;
    align-items: center;
}

#mode-toggle {
    display: flex;
    background: rgba(255, 255, 255, 0.03);
    padding: 3px;
    border-radius: 12px;
    pointer-events: auto;
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(15px);
}

.mode-btn {
    padding: 8px 14px;
    border-radius: 9px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1rem;
    color: rgba(255, 255, 255, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.mode-btn.active {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.05);
}

#sub-menu {
    display: flex;
    gap: 8px;
    pointer-events: auto;
    opacity: 0.8;
}

.sub-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: white;
    padding: 6px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    min-width: 40px;
    height: 32px;
}

.sub-btn.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-1);
    border-color: var(--color-1);
    box-shadow: 0 0 10px var(--accent-glow);
    animation: sub-pulse 1s infinite alternate;
}

@keyframes sub-pulse {
    from { transform: scale(1); opacity: 0.8; }
    to { transform: scale(1.05); opacity: 1; }
}

.sub-btn .symbol {
    font-size: 1.1rem;
    line-height: 1;
}

#history-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    pointer-events: auto;
}

#history-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* Rank Text */
.rank-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 0 10px rgba(0,0,0,0.5);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10;
    pointer-events: none;
}

.finger-indicator.show-rank .rank-text {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.2);
}

#status-text {
    font-weight: 300;
    letter-spacing: 0.2rem;
    text-transform: uppercase;
    font-size: 1.2rem;
    opacity: 0.6;
    transition: opacity 0.5s ease;
}

#volume-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.icon-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.3));
}

#volume-slider {
    width: 60px;
    height: 4px;
    appearance: none;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
}

#volume-slider::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: #00f2ff;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px #00f2ff;
}

#lang-toggle, #theme-toggle {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 8px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#lang-select, #theme-select {
    background: transparent;
    color: white;
    border: none;
    font-family: var(--font-family);
    font-weight: 700;
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
}

#lang-select option, #theme-select option {
    background: #111;
    color: white;
}

#settings-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: all 0.3s ease;
    z-index: 100;
}

#settings-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

#settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
    pointer-events: auto;
}

#settings-modal.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
}

#settings-content {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 20px;
    width: 90%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
}

.settings-header h2 {
    font-size: 1.2rem;
    text-transform: uppercase;
    letter-spacing: 0.1rem;
    font-weight: 700;
}

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-row label {
    font-size: 1rem;
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 0.1rem;
}

#grid-container {
    position: absolute;
    top: 80px;
    left: 0;
    width: 100%;
    height: calc(100% - 80px);
    display: grid;
    gap: 2px;
    padding: 2px;
    z-index: 1;
    background: rgba(255, 255, 255, 0.02);
}

.grid-cell {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.grid-cell::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20%;
    height: 20%;
    background: currentColor;
    border-radius: 50%;
    opacity: 0.1;
    filter: blur(20px);
}

.grid-cell.indicator-0 { color: var(--color-1); }
.grid-cell.indicator-1 { color: var(--color-2); }
.grid-cell.indicator-2 { color: var(--color-3); }
.grid-cell.indicator-3 { color: var(--color-4); }
.grid-cell.indicator-4 { color: var(--color-5); }
.grid-cell.indicator-5 { color: var(--color-6); }
.grid-cell.indicator-6 { color: var(--color-7); }
.grid-cell.indicator-7 { color: var(--color-8); }

.grid-cell.occupied {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.grid-cell.unavailable {
    background: rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 0, 0, 0.2);
    opacity: 0.3;
}

/* History overlay */
#history-overlay {
    position: absolute;
    top: 50px;
    right: 0;
    background: rgba(255, 255, 255, 0.08);
    padding: 12px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    z-index: 200;
}

#history-list {
    display: flex;
    gap: 8px;
    transition: opacity 0.3s ease;
}

#clear-history {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.3);
    font-family: var(--font-family);
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1rem;
    padding: 2px 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    opacity: 0;
    pointer-events: none;
}

#clear-history.visible {
    opacity: 1;
    pointer-events: auto;
}

#clear-history:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

.history-item {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 10px currentColor;
}

#countdown-timer {
    font-size: 4rem;
    font-weight: 700;
    margin-top: 1rem;
    transition: all 0.3s ease;
}

.hidden {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
}

/* Desktop Controls */
#desktop-controls {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    transition: all 0.5s ease;
    pointer-events: auto;
}

.control-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1rem;
    padding: 8px 16px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    backdrop-filter: blur(5px);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 4px 15px rgba(255, 255, 255, 0.1);
}

#start-btn {
    border-color: var(--color-3);
    color: var(--color-3);
    box-shadow: 0 0 15px rgba(57, 255, 20, 0.1);
}

#start-btn:hover {
    background: rgba(57, 255, 20, 0.1);
    border-color: var(--color-3);
    box-shadow: 0 0 30px rgba(57, 255, 20, 0.3);
}

#reset-board-btn {
    border-color: var(--color-6);
    color: var(--color-6);
    box-shadow: 0 0 15px rgba(255, 49, 49, 0.1);
}

#reset-board-btn:hover {
    background: rgba(255, 49, 49, 0.1);
    border-color: var(--color-6);
    box-shadow: 0 0 30px rgba(255, 49, 49, 0.3);
}

/* Mouse Hover on Indicators */
@media (pointer: fine) {
    .finger-indicator {
        cursor: pointer;
    }
    
    .finger-indicator:hover {
        transform: translate(-50%, -50%) scale(1.1);
        filter: brightness(1.3);
    }

    .finger-indicator:hover::after {
        content: '×';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        font-size: 3rem;
        color: white;
        text-shadow: 0 0 10px rgba(0,0,0,0.5);
    }
}

/* Touch Indicator Styles */
.finger-indicator {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    border: 4px solid white;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3), inset 0 0 15px rgba(255, 255, 255, 0.2);
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
    z-index: 5;
}

.shape-svg {
    position: absolute;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: block;
}

.shape-svg polygon, .shape-svg circle, .shape-svg rect, .shape-svg line {
    transition: all 0.3s ease;
    filter: drop-shadow(0 0 5px currentColor);
}

.timer-circle {
    fill: none;
    stroke: currentColor;
    stroke-width: 4;
    stroke-dashoffset: 358;
    transition: stroke-dashoffset linear; /* Speed handled in JS */
    opacity: 0.3;
}

.finger-indicator.counting .timer-circle {
    stroke-dashoffset: 0;
    opacity: 0.8;
}

/* Cyber Theme Extras */
body.theme-cyber .finger-indicator {
    border-radius: 4px;
    border-width: 2px;
}
body.theme-cyber .grid-cell {
    background: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255, 0, 85, 0.05) 10px, rgba(255, 0, 85, 0.05) 11px);
}

/* Mono Theme Extras */
body.theme-mono .finger-indicator {
    border-radius: 0;
    box-shadow: none;
}
body.theme-mono #top-bar, body.theme-mono #history-overlay {
    backdrop-filter: none;
    background: black;
    border-color: white;
}

.finger-indicator.active {
    transform: translate(-50%, -50%) scale(1);
}

.finger-indicator.lost {
    animation: lost-burst 0.5s forwards cubic-bezier(0.1, 0.8, 0.3, 1);
}

@keyframes lost-burst {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    30% { transform: translate(-50%, -50%) scale(1.3); opacity: 0.8; filter: brightness(2); }
    100% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; filter: blur(10px); }
}

.finger-indicator.winner {
    animation: winner-pulse 0.4s infinite alternate cubic-bezier(0.45, 0, 0.55, 1);
    z-index: 100;
}

@keyframes winner-pulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        box-shadow: 0 0 30px currentColor, inset 0 0 20px currentColor;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.4);
        border-width: 12px;
        box-shadow: 0 0 60px currentColor, inset 0 0 40px currentColor;
    }
}

/* Color variations */
.indicator-0 { border-color: var(--color-1); color: var(--color-1); }
.indicator-1 { border-color: var(--color-2); color: var(--color-2); }
.indicator-2 { border-color: var(--color-3); color: var(--color-3); }
.indicator-3 { border-color: var(--color-4); color: var(--color-4); }
.indicator-4 { border-color: var(--color-5); color: var(--color-5); }
.indicator-5 { border-color: var(--color-6); color: var(--color-6); }
.indicator-6 { border-color: var(--color-7); color: var(--color-7); }
.indicator-7 { border-color: var(--color-8); color: var(--color-8); }

/* Theme-specific Elimination Effects */
.finger-indicator.exploding {
    animation: explode 0.5s forwards cubic-bezier(0.1, 0.8, 0.3, 1);
}

@keyframes explode {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(2.5); opacity: 0.8; filter: brightness(3); }
    100% { transform: translate(-50%, -50%) scale(3); opacity: 0; }
}

body.theme-retro .finger-indicator.exploding {
    animation: burn 0.6s forwards ease-out;
}

@keyframes burn {
    0% { transform: translate(-50%, -50%) scale(1); filter: sepia(0) brightness(1); }
    100% { transform: translate(-50%, -50%) scale(0.5); filter: sepia(1) brightness(0); opacity: 0; }
}

body.theme-cyber .finger-indicator.exploding {
    animation: glitch-shatter 0.4s forwards steps(4);
}

@keyframes glitch-shatter {
    0% { transform: translate(-50%, -50%) skew(0); clip-path: inset(0); }
    50% { transform: translate(-50%, -50%) skew(20deg); clip-path: inset(20% 0 50% 0); }
    100% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
}
