:root {
    --bg-gradient: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --primary-color: #00d2ff;
    --primary-glow: rgba(0, 210, 255, 0.6);
    --text-main: #ffffff;
    --text-muted: #a0a0a0;
    --card-selected-bg: rgba(0, 210, 255, 0.15);
    --card-selected-border: #00d2ff;

    --font-main: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

.app-container {
    width: 100%;
    max-width: 800px;
    min-height: 600px;
    padding: 2rem;
    position: relative;
    /* Optional: Main container glass framing */
    /* background: rgba(0,0,0,0.2);
    border-radius: 20px;
    backdrop-filter: blur(10px); */
}

/* Typography */
h1 {
    font-size: 3rem;
    font-weight: 800;
    background: linear-gradient(to right, #fff, #00d2ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    -webkit-background-clip: text;
    background-clip: text;
    text-align: center;
}

h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    text-align: center;
}

p {
    text-align: center;
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

.sub-instruction {
    font-size: 0.9rem;
    margin-top: -1.5rem;
    margin-bottom: 2rem;
    opacity: 0.8;
}

/* Phases & Transitions */
.phase {
    opacity: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.phase.hidden {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
}

.phase.active {
    position: relative;
    transform: scale(1);
}

/* Phase 1: Number Grid */
.number-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    gap: 1rem;
    width: 100%;
    margin-bottom: 2rem;
}

.grid-item {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: 600;
    backdrop-filter: blur(5px);
    transition: transform 0.2s, background 0.2s;
}

.grid-item:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.code-item {
    display: flex;
    flex-direction: column;
    /* Stack vertically */
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    gap: 5px;
    padding: 15px;
    /* Add padding for expansion feel */
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.code-item .symbol {
    font-size: 2rem;
    line-height: 1;
}

.code-item .number {
    font-weight: 800;
    color: var(--primary-color);
    font-size: 1.5rem;

    /* Animation initial state */
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transform: translateY(-10px);
    transition: all 0.5s ease-out;
}

/* Class to trigger animation */
.code-item.reveal .number {
    max-height: 50px;
    /* target height */
    opacity: 1;
    transform: translateY(0);
    margin-top: 5px;
}

/* Phase 2: Cards / Rows */
.cards-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    margin-bottom: 2rem;
}

.magic-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
}

.magic-card:hover {
    background: rgba(255, 255, 255, 0.08);
}

.magic-card.selected {
    background: var(--card-selected-bg);
    border-color: var(--card-selected-border);
    box-shadow: 0 0 20px var(--primary-glow);
}

.magic-card-content {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    justify-content: center;
}

.card-num {
    font-size: 1.1rem;
    opacity: 0.7;
}

.magic-card.selected .card-num {
    opacity: 1;
    color: #fff;
    text-shadow: 0 0 5px var(--primary-color);
}

/* Phase 3: Reveal */
.reveal-content {
    text-align: center;
}

.result-number {
    font-size: 8rem;
    font-weight: 800;
    color: var(--primary-color);
    text-shadow: 0 0 30px var(--primary-glow);
    margin: 2rem 0;
    opacity: 0;
    transform: scale(0.5);
    animation:
        popIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards,
        pulseGlow 2s ease-in-out infinite alternate;
    animation-delay: 0.3s, 1.1s;
}

.end-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 2rem;
}

/* Buttons */
.btn-primary,
.btn-secondary {
    padding: 1rem 3rem;
    border-radius: 30px;
    border: none;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: var(--font-main);
}

.btn-primary {
    background: var(--primary-color);
    color: #000;
    box-shadow: 0 0 15px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 0 25px var(--primary-glow);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-secondary {
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-secondary:hover {
    background: rgba(0, 210, 255, 0.1);
}

/* Settings UI */
.settings-container {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 100;
}

.btn-icon {
    background: transparent;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    transition: transform 0.3s;
    padding: 0.5rem;
    border-radius: 50%;
}

.btn-icon:hover {
    transform: rotate(90deg);
    background: rgba(255, 255, 255, 0.1);
}

.settings-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: rgba(15, 12, 41, 0.95);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    padding: 1rem;
    border-radius: 12px;
    width: 200px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    transform-origin: top right;
    transition: all 0.3s ease;
}

.settings-menu.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9);
}

.settings-menu p {
    margin: 0 0 0.5rem 0;
    font-size: 0.9rem;
    text-align: left;
    color: var(--text-muted);
}

.difficulty-options {
    display: flex;
    gap: 0.5rem;
    justify-content: space-between;
}

.btn-diff {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-main);
    font-weight: 600;
}

.btn-diff:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-diff.active {
    background: var(--primary-color);
    color: #000;
    border-color: var(--primary-color);
    box-shadow: 0 0 10px var(--primary-glow);
}

/* Vacuum Animation */
.vacuum-suck {
    animation: vacuumSuckAnim 1.2s cubic-bezier(0.55, 0.055, 0.675, 0.19) forwards;
    pointer-events: none;
    position: relative;
    /* Ensure transforms work well */
    z-index: 10;
}

@keyframes vacuumSuckAnim {
    0% {
        transform: translate(0, 0) scale(1) rotate(0deg);
        opacity: 1;
    }

    100% {
        /* Move to center (calculated coordinates) */
        transform: translate(var(--tx), var(--ty)) scale(0) rotate(720deg);
        opacity: 0;
    }
}

/* Utility Animations */
@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.5);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pulseGlow {
    0% {
        text-shadow: 0 0 30px var(--primary-glow);
    }

    100% {
        text-shadow: 0 0 60px var(--primary-glow), 0 0 20px #fff;
    }
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    .app-container {
        padding: 1rem;
        min-height: auto;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    .grid-item {
        padding: 0.5rem;
        font-size: 1.5rem;
    }

    .code-item {
        padding: 5px;
    }

    .code-item .symbol {
        font-size: 1.5rem;
    }

    .magic-card {
        padding: 1rem;
    }

    .btn-primary,
    .btn-secondary {
        padding: 0.8rem 2rem;
        font-size: 1rem;
    }

    .settings-container {
        top: 0.5rem;
        right: 0.5rem;
    }

    .btn-icon {
        font-size: 1.5rem;
    }

    .result-number {
        font-size: 5rem;
    }
}