* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-color: #ffffff;
    --card-bg: #ffffff;
    --text-color: #333333;
    --secondary-text: #6c757d;
    --border-color: #dee2e6;
    --primary-color: #0056b3;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --header-bg: #f8f9fa;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --card-bg: #2d2d2d;
    --text-color: #ffffff;
    --secondary-text: #adb5bd;
    --border-color: #495057;
    --primary-color: #4dabf7;
    --success-color: #51cf66;
    --danger-color: #ff6b6b;
    --warning-color: #ffd43b;
    --header-bg: #343a40;
}

html {
    overscroll-behavior: none;
    overflow: hidden;
}

body {
    font-family: 'Comic Sans MS', cursive, Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 0.3s ease;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    touch-action: pan-y;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 8px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.screen {
    display: none;
}

.screen.active {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.header {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 8px 10px;
    margin-bottom: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--border-color);
}

.btn {
    background: var(--primary-color);
    border: none;
    padding: 12px 20px;
    border-radius: 12px;
    color: white;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    margin-bottom: 8px;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
    touch-action: manipulation;
}

.btn:active {
    transform: scale(0.95);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--secondary-text);
}

.btn-success {
    background: var(--success-color);
}

.btn-small {
    padding: 8px 15px;
    font-size: 0.9rem;
}

.game-visual-area {
    background: var(--card-bg);
    border-radius: 15px;
    padding: 10px 8px;
    margin-bottom: 8px;
    border: 2px solid var(--border-color);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.instruction-text {
    text-align: center;
    font-size: 0.95rem;
    font-weight: bold;
    color: var(--text-color);
    margin-bottom: 6px;
    line-height: 1.2;
}

.formula-display {
    background: var(--header-bg);
    border-radius: 10px;
    padding: 6px;
    text-align: center;
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 8px;
    border: 2px solid var(--primary-color);
}

.objects-pool {
    background: var(--header-bg);
    border-radius: 12px;
    padding: 8px;
    margin-bottom: 8px;
    min-height: 60px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    align-items: center;
    border: 2px dashed var(--border-color);
}

.draggable-object {
    font-size: 1.2rem;
    padding: 2px;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    transition: opacity 0.2s, transform 0.2s;
}

.draggable-object.dragging {
    opacity: 0.4;
}

.draggable-object.placed {
    opacity: 0.3;
    pointer-events: none;
}

.drag-ghost {
    position: fixed;
    font-size: 1.8rem;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.9;
    filter: drop-shadow(0 6px 12px rgba(0,0,0,0.4));
    transform: translate(-50%, -50%);
}

.containers-area {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}

.container-person {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.3s ease;
    min-height: 45px;
}

.container-person.drag-over {
    border-color: var(--primary-color);
    background: rgba(77, 171, 247, 0.2);
    transform: scale(1.02);
}

.container-person.highlight {
    border-color: var(--warning-color);
    background: rgba(255, 193, 7, 0.1);
}

.container-person.full {
    border-color: var(--success-color);
    background: rgba(40, 167, 69, 0.1);
}

.person-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
}

.person-items {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    min-height: 30px;
    align-items: center;
}

.person-items .item {
    font-size: 1rem;
    animation: dropIn 0.3s ease;
}

@keyframes dropIn {
    from {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    to {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

.remainder-zone {
    background: rgba(255, 193, 7, 0.15);
    border: 2px dashed var(--warning-color);
    border-radius: 10px;
    padding: 8px;
    text-align: center;
    margin-top: 8px;
    min-height: 45px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.remainder-label {
    font-weight: bold;
    color: var(--warning-color);
    font-size: 0.85rem;
}

.remainder-items {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
}

.remainder-items .item {
    font-size: 1rem;
}

.answer-section {
    margin-top: 8px;
}

.answer-question {
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--text-color);
    margin-bottom: 8px;
    text-align: center;
}

.answer-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.answer-btn {
    background: var(--header-bg);
    border: 2px solid var(--border-color);
    padding: 10px 4px;
    border-radius: 8px;
    color: var(--text-color);
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.answer-btn:active {
    transform: scale(0.95);
}

.answer-btn.correct {
    background: var(--success-color);
    color: white;
    border-color: var(--success-color);
    animation: correctPulse 0.6s ease;
}

.answer-btn.incorrect {
    background: var(--danger-color);
    color: white;
    border-color: var(--danger-color);
    animation: shake 0.5s ease;
}

@keyframes correctPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

.game-header {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 8px 10px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--border-color);
}

.lives-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.quit-btn {
    background: var(--danger-color);
    border: none;
    border-radius: 12px;
    padding: 6px 10px;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    gap: 3px;
    transition: all 0.2s ease;
}

.quit-btn:active {
    transform: scale(0.95);
}

.learning-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--card-bg);
    border-radius: 20px;
    padding: 25px;
    text-align: center;
    max-width: 85%;
    width: 320px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    z-index: 3000;
    border: 3px solid var(--success-color);
    animation: popupAppear 0.3s ease;
    display: none;
}

.learning-popup.show {
    display: block;
}

@keyframes popupAppear {
    from {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
    }
    to {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

.learning-popup-icon {
    font-size: 4rem;
    margin-bottom: 15px;
    animation: bounce 0.6s ease;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.learning-popup-title {
    font-size: 1.6rem;
    font-weight: bold;
    color: var(--success-color);
    margin-bottom: 15px;
}

.learning-popup-formula {
    background: var(--header-bg);
    border-radius: 15px;
    padding: 15px;
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
    line-height: 1.6;
}

.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2999;
    display: none;
}

.popup-overlay.show {
    display: block;
}

.lives {
    display: flex;
    gap: 3px;
}

.heart {
    font-size: 1.1rem;
    color: var(--danger-color);
}

.heart.lost {
    color: var(--border-color);
    opacity: 0.4;
}

.level-info {
    text-align: center;
}

.level-number {
    font-size: 0.95rem;
    font-weight: bold;
    color: var(--text-color);
}

.progress-text {
    font-size: 0.7rem;
    color: var(--secondary-text);
}

.timer {
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--primary-color);
}

.timer.danger {
    color: var(--danger-color);
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 25px 20px;
    text-align: center;
    max-width: 300px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-icon {
    font-size: 3.5rem;
    margin-bottom: 12px;
}

.modal-title {
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--text-color);
    margin-bottom: 8px;
}

.modal-text {
    color: var(--secondary-text);
    margin-bottom: 15px;
    line-height: 1.4;
    font-size: 0.95rem;
}

.theme-toggle {
    background: var(--header-bg);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 35px;
    height: 35px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.3s ease;
}

.help-message {
    background: rgba(77, 171, 247, 0.1);
    border: 2px solid var(--primary-color);
    border-radius: 10px;
    padding: 6px 8px;
    margin-bottom: 8px;
    text-align: center;
    color: var(--text-color);
    font-size: 0.75rem;
    line-height: 1.3;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger-color);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: bold;
    z-index: 3000;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: toastSlide 0.3s ease;
}

@keyframes toastSlide {
    from {
        transform: translateX(-50%) translateY(100px);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

.celebration {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    animation: celebrate 1s ease;
    z-index: 1000;
    pointer-events: none;
}

@keyframes celebrate {
    0% { 
        transform: translate(-50%, -50%) scale(0) rotate(0deg);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.3) rotate(180deg);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(0.8) rotate(360deg);
        opacity: 0;
    }
}

.input-group {
    margin-bottom: 15px;
}

.input-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: bold;
    color: var(--text-color);
    text-align: left;
    font-size: 0.9rem;
}

.input-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 1rem;
    background: var(--header-bg);
    color: var(--text-color);
    font-family: inherit;
}

.pin-input {
    text-align: center;
    font-size: 1.5rem;
    letter-spacing: 0.5rem;
    font-weight: bold;
}

.player-list {
    max-height: 250px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.player-item {
    background: var(--header-bg);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.player-item:active {
    transform: scale(0.98);
}

.player-item.selected {
    border-color: var(--primary-color);
    background: rgba(77, 171, 247, 0.15);
}

.player-info {
    flex: 1;
}

.player-name {
    font-weight: bold;
    font-size: 1.1rem;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.player-stats {
    font-size: 0.8rem;
    color: var(--secondary-text);
}

.sync-indicator {
    position: fixed;
    bottom: 15px;
    right: 15px;
    background: var(--success-color);
    color: white;
    padding: 8px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 2000;
    display: none;
}

.sync-indicator.show {
    display: block;
    animation: fadeInOut 2s ease;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

.loading {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.info-box {
    background: rgba(77, 171, 247, 0.1);
    border: 2px solid var(--primary-color);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 15px;
    font-size: 0.85rem;
    color: var(--text-color);
    text-align: center;
}

.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
    overflow: hidden;
}

.splash-screen.hide {
    opacity: 0;
    pointer-events: none;
}

.splash-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.progress-card {
    background: var(--header-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 12px;
    text-align: center;
}

.progress-card-header {
    font-size: 0.9rem;
    color: var(--secondary-text);
    margin-bottom: 8px;
    font-weight: bold;
}

.progress-card-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

.progress-phases {
    margin-top: 20px;
    margin-bottom: 20px;
}

.progress-phase-title {
    font-size: 0.95rem;
    font-weight: bold;
    color: var(--text-color);
    margin-bottom: 12px;
}

.progress-phase-item {
    background: var(--header-bg);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.progress-phase-item.completed {
    border-color: var(--success-color);
    background: rgba(40, 167, 69, 0.1);
}

.progress-phase-item.in-progress {
    border-color: var(--warning-color);
    background: rgba(255, 193, 7, 0.1);
}

.progress-phase-info {
    flex: 1;
}

.progress-phase-name {
    font-weight: bold;
    font-size: 0.95rem;
    margin-bottom: 3px;
}

.progress-phase-desc {
    font-size: 0.75rem;
    color: var(--secondary-text);
}

.progress-phase-status {
    font-size: 1.8rem;
}

.progress-detail {
    margin-top: 20px;
}

.progress-detail-title {
    font-size: 0.95rem;
    font-weight: bold;
    color: var(--text-color);
    margin-bottom: 12px;
}

.progress-levels-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.progress-level-item {
    background: var(--header-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 5px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: bold;
}

.progress-level-item.completed {
    background: var(--success-color);
    color: white;
    border-color: var(--success-color);
}

.progress-level-item.current {
    background: var(--warning-color);
    color: white;
    border-color: var(--warning-color);
    animation: pulse 1.5s infinite;
}