/* Mobile-First Responsive Design */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-color: #475569;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app-container {
    max-width: 100%;
    min-height: 100vh;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 1rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.title {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-controls {
    display: flex;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:active {
    transform: scale(0.95);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: var(--bg-tertiary);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-icon {
    padding: 0.5rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.5rem;
}

.icon {
    font-size: 1.25rem;
}

/* Screens */
.screen {
    display: none;
    flex: 1;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

/* Main Menu */
.menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    padding: 1.5rem;
    flex: 1;
    justify-content: center;
}

.menu-title {
    font-size: 2rem;
    margin-bottom: 1rem;
    text-align: center;
}

.game-modes {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 20rem;
}

.mode-btn {
    padding: 1.5rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 1rem;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    box-shadow: var(--shadow);
}

.mode-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.mode-btn:active {
    transform: translateY(0);
}

.mode-icon {
    font-size: 2rem;
}

.mode-text {
    font-size: 1rem;
}

.menu-stats {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 20rem;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 0.75rem;
    font-size: 0.875rem;
}

.stat-label {
    color: var(--text-secondary);
}

.stat-value {
    font-weight: 700;
    color: var(--primary-color);
}

/* Level Selection */
.level-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.level-container .btn {
    flex-shrink: 0;
    margin-top: auto;
}

.screen-title {
    font-size: 1.75rem;
    text-align: center;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(4rem, 1fr));
    gap: 0.75rem;
    padding: 0.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    max-height: calc(100vh - 12rem);
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--bg-secondary);
}

.level-grid::-webkit-scrollbar {
    width: 0.5rem;
}

.level-grid::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 0.5rem;
}

.level-grid::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 0.5rem;
}

.level-grid::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

.level-btn {
    aspect-ratio: 1;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 0.75rem;
    color: var(--text-primary);
    font-size: 1.125rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
}

.level-btn:hover:not(:disabled) {
    border-color: var(--primary-color);
    transform: scale(1.05);
}

.level-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.level-btn.completed {
    background: linear-gradient(135deg, var(--success-color), #059669);
    border-color: var(--success-color);
}

.level-btn.current {
    border-color: var(--primary-color);
    border-width: 3px;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}

/* Game Area */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 1rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.game-info {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    flex: 1;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.875rem;
}

.info-label {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.info-value {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1rem;
}

.game-area {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    align-items: flex-start;
    padding: 1rem;
    overflow-y: auto;
    min-height: 0;
    position: relative;
    z-index: 1;
    width: 100%;
    box-sizing: border-box;
}

.tube {
    width: 4rem;
    min-width: 4rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 0.5rem 0.5rem 0 0;
    border-bottom: none;
    padding: 0.25rem;
    display: flex;
    flex-direction: column-reverse;
    gap: 0.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    box-shadow: var(--shadow);
    min-height: calc(4 * (100% / 4 + 0.25rem));
}

.tube:hover {
    border-color: var(--primary-color);
}

.tube.selected {
    border-color: var(--primary-color);
    border-width: 3px;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
    background: rgba(99, 102, 241, 0.1);
}

.tube.completed {
    border-color: var(--success-color);
    background: rgba(16, 185, 129, 0.1);
}

.tube.empty {
    border-style: dashed;
    border-width: 2px;
    background: var(--bg-tertiary);
    position: relative;
}

.tube.empty:hover {
    border-color: var(--primary-color);
    border-style: solid;
    background: rgba(99, 102, 241, 0.15);
}

.tube.valid-target {
    border-color: var(--success-color);
    border-style: solid;
    background: rgba(16, 185, 129, 0.15);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3);
}

.tube.valid-target.empty::before {
    background: rgba(16, 185, 129, 0.3);
    border-color: var(--success-color);
    animation: pulse 1s ease-in-out infinite;
}

.tube.has-space:not(.empty) {
    border-style: solid;
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.3;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 0.6;
        transform: translate(-50%, -50%) scale(1.1);
    }
}

.tube::after {
    content: '';
    position: absolute;
    bottom: -0.125rem;
    left: 0;
    right: 0;
    height: 0.25rem;
    background: var(--bg-primary);
    border-radius: 0 0 0.5rem 0.5rem;
    z-index: 1;
}

.tube.has-space:not(.empty)::before {
    content: attr(data-empty-slots);
    position: absolute;
    top: -0.5rem;
    right: -0.5rem;
    width: 1.25rem;
    height: 1.25rem;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.625rem;
    font-weight: 700;
    box-shadow: var(--shadow);
    z-index: 10;
}

.tube.empty::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 1.5rem;
    height: 1.5rem;
    background: rgba(99, 102, 241, 0.2);
    border-radius: 50%;
    border: 2px dashed var(--primary-color);
    animation: pulse 2s ease-in-out infinite;
    z-index: 2;
}

.empty-slot {
    width: 100%;
    aspect-ratio: 1;
    border: 1px dashed rgba(99, 102, 241, 0.3);
    border-radius: 50%;
    opacity: 0.3;
    transition: all 0.2s ease;
    pointer-events: none;
}

.tube:hover .empty-slot {
    border-color: var(--primary-color);
    opacity: 0.5;
    background: rgba(99, 102, 241, 0.1);
}

.ball {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.ball.moving {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    transform: scale(1.1);
}

.game-controls {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.game-controls .btn {
    flex: 1;
    min-width: 8rem;
    max-width: 12rem;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 1rem;
    width: 100%;
    max-width: 25rem;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.3s ease;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--bg-secondary);
}

.modal-content::-webkit-scrollbar {
    width: 0.5rem;
}

.modal-content::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 0.5rem;
}

.modal-content::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 0.5rem;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-2rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.5rem;
}

.modal-body {
    padding: 1.5rem;
}

.setting-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-color);
}

.setting-group:last-child {
    border-bottom: none;
}

.setting-group label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.setting-input {
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.toggle {
    width: 3rem;
    height: 1.5rem;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 1rem;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle:checked {
    background: var(--primary-color);
}

.toggle::before {
    content: '';
    position: absolute;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: white;
    top: 0.125rem;
    left: 0.125rem;
    transition: transform 0.3s;
}

.toggle:checked::before {
    transform: translateX(1.5rem);
}

.game-result {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.result-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.celebration-item {
    min-width: 0;
}

@media (max-width: 640px) {
    .result-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .celebration-item {
        padding: 0.75rem;
    }
    
    .result-icon {
        font-size: 1.5rem;
    }
    
    .result-value {
        font-size: 1rem;
    }
}

.result-item {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 0.5rem;
    font-size: 0.875rem;
}

/* Celebration Modal */
.celebration-modal {
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 90vh;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--bg-secondary);
}

.celebration-modal::-webkit-scrollbar {
    width: 0.5rem;
}

.celebration-modal::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 0.5rem;
}

.celebration-modal::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 0.5rem;
}

.celebration-modal::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

.celebration-container {
    position: relative;
    z-index: 10;
    min-height: min-content;
}

.celebration-particles {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

@keyframes confetti {
    0% {
        transform: translateY(-100px) translateX(0) rotate(0deg);
        opacity: 1;
    }
    50% {
        opacity: 1;
    }
    100% {
        transform: translateY(600px) translateX(calc(var(--random-x, 0) * 100px)) rotate(720deg);
        opacity: 0;
    }
}

.celebration-icon {
    font-size: 4rem;
    text-align: center;
    animation: celebration-bounce 1s ease-in-out infinite;
    margin-bottom: 1rem;
}

@keyframes celebration-bounce {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    50% {
        transform: translateY(-20px) scale(1.1);
    }
}

.celebration-title {
    font-size: 2rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color), var(--success-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: title-glow 2s ease-in-out infinite;
    text-align: center;
}

@keyframes title-glow {
    0%, 100% {
        filter: drop-shadow(0 0 5px rgba(99, 102, 241, 0.5));
    }
    50% {
        filter: drop-shadow(0 0 20px rgba(99, 102, 241, 0.8));
    }
}

.celebration-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
    border-radius: 0.75rem;
    border: 2px solid var(--primary-color);
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
    animation: slideIn 0.5s ease-out;
    animation-fill-mode: both;
}

.result-row:nth-child(1) .celebration-item:nth-child(1) {
    animation-delay: 0.1s;
}

.result-row:nth-child(1) .celebration-item:nth-child(2) {
    animation-delay: 0.2s;
}

.result-row:nth-child(2) .celebration-item:nth-child(1) {
    animation-delay: 0.3s;
}

.result-row:nth-child(2) .celebration-item:nth-child(2) {
    animation-delay: 0.4s;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.result-icon {
    font-size: 2rem;
    animation: icon-spin 2s ease-in-out infinite;
}

@keyframes icon-spin {
    0%, 100% {
        transform: rotate(0deg) scale(1);
    }
    50% {
        transform: rotate(10deg) scale(1.1);
    }
}

.result-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
}

.result-label {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.result-value {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1.25rem;
    animation: value-pulse 1.5s ease-in-out infinite;
}

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

.celebration-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    animation: button-glow 2s ease-in-out infinite;
}

@keyframes button-glow {
    0%, 100% {
        box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    }
    50% {
        box-shadow: 0 4px 25px rgba(99, 102, 241, 0.6);
    }
}

.result-actions,
.pause-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.result-actions .btn,
.pause-actions .btn {
    width: 100%;
}

/* Responsive Design - Tablet */
@media (min-width: 768px) {
    .app-container {
        padding: 1rem;
        max-width: 48rem;
        margin: 0 auto;
    }

    .title {
        font-size: 2rem;
    }

    .menu-title {
        font-size: 2.5rem;
    }

    .game-modes {
        flex-direction: row;
        max-width: 100%;
    }

    .mode-btn {
        flex: 1;
    }

    .level-grid {
        grid-template-columns: repeat(auto-fill, minmax(5rem, 1fr));
        gap: 1rem;
    }

    .tube {
        width: 5rem;
        min-width: 5rem;
    }

    .game-info {
        flex-wrap: nowrap;
    }

    .menu-stats {
        flex-direction: row;
        max-width: 100%;
    }

    .stat-item {
        flex: 1;
    }
}

/* Responsive Design - Desktop */
@media (min-width: 1024px) {
    .app-container {
        max-width: 64rem;
        padding: 2rem;
    }

    .level-grid {
        grid-template-columns: repeat(auto-fill, minmax(6rem, 1fr));
    }

    .tube {
        width: 5.5rem;
        min-width: 5.5rem;
    }

    .result-actions,
    .pause-actions {
        flex-direction: row;
    }

    .result-actions .btn,
    .pause-actions .btn {
        flex: 1;
    }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

/* Animations */
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-0.5rem); }
}

.bounce {
    animation: bounce 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 0.5rem;
    height: 0.5rem;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 0.5rem;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 0.5rem;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}
