* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comic Sans MS', cursive, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

h1 {
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    font-size: 2.5em;
}

.subtitle {
    color: #ffeb3b;
    font-size: 1.2em;
    margin-top: 5px;
}

.game-area {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    background: rgba(255,255,255,0.95);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

/* Стили для волшебника */
.wizard-container {
    position: relative;
    min-height: 0px;
    margin-bottom: 20px;
    display: flex;
    align-items: flex-end;
}

.wizard-svg {
    width: 140px;
    height: 140px;
    margin-bottom: -10px;
    margin-left: 20px;
}

.speech-bubble {
    position: absolute;
    left: 180px;
    top: 20px;
    background: #fff;
    padding: 15px;
    border-radius: 20px;
    max-width: 300px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    border: 3px solid #4CAF50;
    z-index: 10;
}

.speech-bubble::after {
    content: '';
    position: absolute;
    left: -20px;
    top: 30px;
    border: 10px solid transparent;
    border-right-color: #fff;
}

/* Стили для кнопок на левой стороне */
.left-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    justify-content: flex-start;
    align-items: center;
}

.control-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(145deg, #2196F3 0%, #1976D2 100%);
    color: white;
    font-size: 0.85em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.3);
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.control-btn:hover {
    background: linear-gradient(145deg, #1976D2 0%, #1565C0 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
}

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

/* Особые стили для кнопки "?" */
#hintBtn {
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 1.1em;
    font-weight: bold;
    border-radius: 50%;
}

/* Выпадающий список */
.mode-select {
    width: 100%;
    padding: 12px 15px;
    font-size: 1.1em;
    border: 2px solid #4CAF50;
    border-radius: 10px;
    background: linear-gradient(145deg, #ffffff 0%, #f5f5f5 100%);
    color: #333;
    cursor: pointer;
    transition: all 0.3s ease;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234CAF50' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 15px center;
    background-size: 16px;
}

.mode-select:hover {
    border-color: #388E3C;
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.2);
}

.mode-select:focus {
    outline: none;
    border-color: #4CAF50;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.3);
}

/* Игровое поле */
.grid-container {
    display: grid;
    grid-template-columns: repeat(10, 30px);
    grid-template-rows: repeat(10, 30px);
    gap: 2px;
    background-color: #e0e0e0;
    padding: 15px;
    border-radius: 10px;
    margin: 15px 0;
    border: 3px solid #bdbdbd;
}

.grid-cell {
    background-color: #f5f5f5;
    border: 1px solid #ccc;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.grid-cell.hover {
    background-color: #e3f2fd;
    border-color: #2196F3;
}

.grid-cell.occupied {
    border: 2px solid #333;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.3);
}

.grid-cell.error {
    background-color: #ff5252 !important;
    border-color: #d32f2f !important;
}

/* Стили для preview кирпичей */
.grid-cell.preview {
    border: 2px dashed #666;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
}

.grid-cell.preview-valid {
    border-color: #4CAF50;
    box-shadow: inset 0 0 10px rgba(76, 175, 80, 0.3);
}

.grid-cell.preview-invalid {
    border-color: #ff5252;
    box-shadow: inset 0 0 10px rgba(255, 82, 82, 0.3);
    background-color: #ffebee !important;
}

/* Стили для салюта */
.firework {
    position: absolute;
    pointer-events: none;
    z-index: 1000;
}

.star {
    position: absolute;
    width: 0;
    height: 0;
    border-right: 10px solid transparent;
    border-bottom: 7px solid;
    border-left: 10px solid transparent;
    transform: rotate(35deg);
    animation: star-fall 1.5s ease-out forwards;
}

.star:before {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-right: 3px solid transparent;
    border-bottom: 8px solid;
    border-left: 3px solid transparent;
    transform: rotate(-35deg);
    top: -4.5px;
    left: -6.5px;
}

.star:after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-right: 10px solid transparent;
    border-bottom: 7px solid;
    border-left: 10px solid transparent;
    transform: rotate(-70deg);
    top: 0.3px;
    left: -10.5px;
}

@keyframes star-fall {
    0% {
        transform: translateY(0) rotate(35deg) scale(0);
        opacity: 1;
    }
    50% {
        transform: translateY(-100px) rotate(35deg) scale(1);
        opacity: 0.8;
    }
    100% {
        transform: translateY(-200px) rotate(35deg) scale(0);
        opacity: 0;
    }
}

@keyframes star-explode {
    0% {
        transform: translate(0, 0) scale(0);
        opacity: 1;
    }
    50% {
        transform: translate(var(--tx), var(--ty)) scale(1);
        opacity: 0.8;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

.celebrate .grid-container {
    position: relative;
}

.celebrate .grid-cell {
    animation: cell-pulse 0.5s ease-in-out;
}

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

/* Стили для кирпичиков */
.bricks-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.brick {
    border-radius: 4px;
    cursor: grab;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9em;
    color: white;
    text-shadow: 1px 1px 1px rgba(0,0,0,0.5);
    font-weight: bold;
}

.brick:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}

.brick.dragging {
    opacity: 0.8;
    transform: rotate(5deg);
    z-index: 1000;
}

/* Вертикальные кирпичики для сложения/вычитания */
.brick.vertical {
    writing-mode: vertical-lr;
    text-orientation: mixed;
    transform: rotate(180deg);
}

.brick.size-1.vertical { 
    width: 28px; 
    height: 30px; 
}
.brick.size-2.vertical { 
    width: 28px; 
    height: 60px; 
}
.brick.size-3.vertical { 
    width: 28px; 
    height: 90px; 
}
.brick.size-4.vertical { 
    width: 28px; 
    height: 120px; 
}

/* Горизонтальные кирпичики для умножения */
.brick.size-1.horizontal { width: 30px; height: 28px; }
.brick.size-2.horizontal { width: 60px; height: 28px; }
.brick.size-3.horizontal { width: 90px; height: 28px; }
.brick.size-4.horizontal { width: 120px; height: 28px; }

/* Информация о текущей постройке */
.current-structure {
    background: #f3e5f5;
    padding: 15px;
    border-radius: 10px;
    border: 2px solid #9c27b0;
    margin-top: 15px;
}

.current-structure h3 {
    margin: 0 0 10px 0;
    color: #7b1fa2;
}

#structureInfo {
    font-size: 1.1em;
    min-height: 24px;
}

/* Панель управления */
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.inventory {
    background: #fff3e0;
    padding: 15px;
    border-radius: 15px;
    border: 2px solid #ff9800;
}

/* Элементы управления */
.game-controls {
    background: #e8f5e9;
    padding: 15px;
    border-radius: 15px;
    border: 2px solid #4CAF50;
}

.task-display {
    background: #e3f2fd;
    padding: 15px;
    border-radius: 10px;
    border: 2px solid #2196F3;
    font-size: 1.1em;
    text-align: center;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
}

.answer-input {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

#answer {
    padding: 10px;
    border: 2px solid #2196F3;
    border-radius: 8px;
    font-size: 1.1em;
    width: 100px;
}

/* Кнопка проверки */
.check-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(145deg, #4CAF50 0%, #45a049 100%);
    color: white;
    font-size: 0.9em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
    min-height: 36px;
}

.check-btn:hover {
    background: linear-gradient(145deg, #45a049 0%, #3d8b40 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

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

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    background: #bbdefb;
    padding: 15px;
    border-radius: 10px;
    font-size: 1.1em;
    font-weight: bold;
    text-align: center;
}

.streak {
    color: #d32f2f;
}

/* Стиль для ссылки учреждения */
.institution-link {
    color: #ffeb3b;
    text-decoration: none;
    transition: all 0.3s ease;
}

.institution-link:hover {
    color: #fff;
    text-decoration: underline;
    text-shadow: 0 0 10px rgba(255, 235, 59, 0.5);
}

/* Анимации */
@keyframes celebrate {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.celebrate {
    animation: celebrate 0.5s ease-in-out;
}

.placed-brick {
    animation: placeBrick 0.3s ease-out;
}

@keyframes placeBrick {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Адаптивность */
@media (max-width: 768px) {
    .game-area {
        grid-template-columns: 1fr;
    }
    
    .wizard-svg {
        width: 100px;
        height: 100px;
        margin-left: 10px;
    }
    
    .speech-bubble {
        left: 130px;
        max-width: 200px;
        font-size: 0.9em;
    }
    
    .left-controls {
        gap: 6px;
        margin-bottom: 12px;
    }
    
    .control-btn {
        padding: 5px 10px;
        font-size: 0.8em;
        min-height: 28px;
    }
    
    #hintBtn {
        width: 28px;
        height: 28px;
        font-size: 1em;
    }
    
    .check-btn {
        padding: 6px 12px;
        font-size: 0.85em;
        min-height: 32px;
    }
    
    .grid-container {
        grid-template-columns: repeat(10, 25px);
        grid-template-rows: repeat(10, 25px);
    }
    
    .brick.size-1.vertical { width: 23px; height: 25px; }
    .brick.size-2.vertical { width: 23px; height: 50px; }
    .brick.size-3.vertical { width: 23px; height: 75px; }
    .brick.size-4.vertical { width: 23px; height: 100px; }
    
    .brick.size-1.horizontal { width: 25px; height: 23px; }
    .brick.size-2.horizontal { width: 50px; height: 23px; }
    .brick.size-3.horizontal { width: 75px; height: 23px; }
    .brick.size-4.horizontal { width: 100px; height: 23px; }
    
    .brick {
        height: 23px;
        font-size: 0.8em;
    }
    
    .mode-select {
        font-size: 1em;
        padding: 10px 12px;
    }
}

@media (max-width: 480px) {
    .wizard-svg {
        width: 80px;
        height: 80px;
    }
    
    .speech-bubble {
        left: 110px;
        max-width: 180px;
        font-size: 0.85em;
        padding: 10px;
    }
    
    h1 {
        font-size: 2em;
    }
    
    .subtitle {
        font-size: 1em;
    }
    
    .left-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .control-btn {
        padding: 4px 8px;
        font-size: 0.75em;
        min-height: 26px;
    }
    
    #hintBtn {
        width: 26px;
        height: 26px;
        font-size: 0.9em;
    }
    
    .check-btn {
        padding: 5px 10px;
        font-size: 0.8em;
        min-height: 30px;
    }
    
    .answer-input {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    
    #answer {
        width: 100%;
    }
    
    .stats {
        grid-template-columns: 1fr;
        gap: 8px;
        font-size: 1em;
    }
}