* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    color: #fff;
    margin: 0;
    padding: 10px;
    min-height: 100vh;
    overflow-x: auto;
}

.game-container {
    max-width: 1400px;
    margin: 0 auto;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 0 30px rgba(255, 255, 0, 0.3);
    border: 2px solid #ffff00;
}

.game-content {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
    min-height: 70vh;
    width: 100%;
    flex-direction: column;
}

.game-area {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-width: 0;
}

.stats-panel {
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #333;
    border-radius: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.stats-panel h1 {
    width: 100%;
    text-align: center;
    margin-bottom: 10px;
    order: -1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 80px;
}

.score-item .label {
    font-size: 0.8em;
    color: #ccc;
    margin-bottom: 2px;
}

.score-item span:last-child {
    font-size: 1.1em;
    font-weight: bold;
    color: #ffff00;
    text-shadow: 0 0 5px #ffff00;
}

.game-buttons {
    margin-top: 15px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    order: 1;
}

/* Скрываем портретные кнопки в базовом режиме */
.portrait-buttons {
    display: none;
}

.info-btn {
    background: linear-gradient(45deg, #ffff00, #ffa500);
    border: none;
    color: #000;
    padding: 12px 16px;
    font-size: 1.2em;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 255, 0, 0.3);
    margin: 5px;
    min-width: 50px;
}

.info-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 255, 0, 0.5);
}

.info-btn:active {
    transform: translateY(0);
}

/* Оверлеи */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: 10px;
}

.overlay-content {
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid #ffff00;
    border-radius: 15px;
    padding: 20px;
    max-width: 90%;
    max-height: 90%;
    overflow-y: auto;
    box-shadow: 0 0 30px rgba(255, 255, 0, 0.5);
}

.overlay-content h3 {
    color: #ffff00;
    text-align: center;
    margin-bottom: 15px;
    font-size: 1.3em;
    text-shadow: 0 0 10px #ffff00;
}

.close-btn {
    background: linear-gradient(45deg, #ff4444, #cc0000);
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    margin-top: 15px;
    width: 100%;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background: linear-gradient(45deg, #ff6666, #ff0000);
    transform: scale(1.02);
}

.close-btn:active {
    transform: scale(0.98);
}

h1 {
    font-size: 3em;
    color: #ffff00;
    text-shadow: 0 0 20px #ffff00;
    margin-bottom: 20px;
    font-weight: bold;
}

#gameCanvas {
    border: 3px solid #0099ff;
    border-radius: 10px;
    background-color: #000;
    box-shadow: 0 0 20px rgba(0, 153, 255, 0.5);
    display: block;
    margin: 0 auto;
    transition: all 0.3s ease;
}

.controls {
    margin-top: 20px;
}

.instructions {
    margin-bottom: 15px;
    font-size: 1em;
    color: #ccc;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid #333;
    border-radius: 10px;
    padding: 15px;
    text-align: left;
}

.instructions h3 {
    color: #00ff00;
    text-align: center;
    margin-bottom: 12px;
    font-size: 1.2em;
    text-shadow: 0 0 5px #00ff00;
}

.control-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.95em;
}

.key-symbol {
    background: linear-gradient(45deg, #333, #555);
    color: #fff;
    padding: 4px 8px;
    border-radius: 5px;
    font-weight: bold;
    min-width: 80px;
    text-align: center;
    margin-right: 12px;
    border: 1px solid #666;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    font-family: monospace;
}

.control-tips {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #444;
}

.control-tips p {
    margin: 6px 0;
    font-size: 0.85em;
    color: #aaa;
}

.control-tips strong {
    color: #ffff00;
}

.legend {
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #333;
    border-radius: 10px;
    padding: 15px;
    margin: 15px 0;
    text-align: left;
}

.legend h3 {
    color: #ffff00;
    text-align: center;
    margin-bottom: 10px;
    font-size: 1.2em;
    text-shadow: 0 0 5px #ffff00;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.9em;
}

.legend-symbol {
    width: 30px;
    text-align: center;
    margin-right: 10px;
    font-weight: bold;
}

.pacman-symbol {
    color: #ffff00;
    font-size: 1.2em;
    text-shadow: 0 0 5px #ffff00;
}

.ghost-symbol {
    font-size: 1em;
}

.ghost-symbol.red {
    color: #ff0000;
    text-shadow: 0 0 3px #ff0000;
}

.ghost-symbol.pink {
    color: #ffb8ff;
    text-shadow: 0 0 3px #ffb8ff;
}

.ghost-symbol.cyan {
    color: #00ffff;
    text-shadow: 0 0 3px #00ffff;
}

.ghost-symbol.orange {
    color: #ffb852;
    text-shadow: 0 0 3px #ffb852;
}

.dot-symbol {
    color: #ffff00;
    font-size: 1.2em;
}

.power-dot-symbol {
    color: #ffff00;
    font-size: 1.4em;
    text-shadow: 0 0 8px #ffff00;
    animation: pulse 1s infinite;
}

.wall-symbol {
    color: #0099ff;
    text-shadow: 0 0 3px #0099ff;
}

.start-btn, .pause-btn, .restart-btn, .sound-btn {
    background: linear-gradient(45deg, #ffff00, #ffa500);
    border: none;
    color: #000;
    padding: 12px 24px;
    font-size: 1.1em;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 255, 0, 0.3);
    margin: 5px;
}

.sound-btn {
    padding: 12px 16px;
    font-size: 1.2em;
    min-width: 50px;
}

.sound-btn.muted {
    background: linear-gradient(45deg, #666, #999);
    color: #fff;
}

.start-btn:hover, .pause-btn:hover, .restart-btn:hover, .sound-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 255, 0, 0.5);
}

.start-btn:active, .pause-btn:active, .restart-btn:active, .sound-btn:active {
    transform: translateY(0);
}

/* Сенсорное управление */


.game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    padding: 40px;
    border-radius: 15px;
    border: 3px solid #ff0000;
    box-shadow: 0 0 30px rgba(255, 0, 0, 0.5);
    z-index: 1000;
}

.game-over h2 {
    color: #ff0000;
    font-size: 2.5em;
    margin-bottom: 20px;
    text-shadow: 0 0 15px #ff0000;
}

.game-over p {
    font-size: 1.3em;
    margin-bottom: 20px;
    color: #fff;
}

.victory-screen {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, rgba(0, 50, 0, 0.95), rgba(0, 100, 0, 0.95));
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    border: 3px solid #00ff00;
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.5);
    z-index: 1000;
    min-width: 350px;
}

.victory-screen h2 {
    color: #00ff00;
    text-shadow: 0 0 20px #00ff00;
    margin-bottom: 20px;
    font-size: 2em;
    animation: glow-green 2s infinite;
}

@keyframes glow-green {
    0%, 100% { text-shadow: 0 0 10px #00ff00; }
    50% { text-shadow: 0 0 20px #00ff00, 0 0 30px #00ff00; }
}

.victory-screen p {
    margin: 10px 0;
    font-size: 1.1em;
    color: #fff;
}

.next-level-btn {
    background: linear-gradient(45deg, #00aa00, #00ff00);
    color: #000;
    border: none;
    padding: 12px 25px;
    font-size: 1.1em;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    margin: 10px 5px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 255, 0, 0.3);
}

.next-level-btn:hover {
    background: linear-gradient(45deg, #00ff00, #66ff66);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 255, 0, 0.4);
}

/* Стили для ссылки на сайт */
.website-link {
    text-align: center;
    margin-top: 15px;
    padding: 8px;
}

.website-link a {
    color: #ffff00;
    text-decoration: none;
    font-size: 0.9em;
    font-weight: bold;
    padding: 6px 12px;
    border: 1px solid #ffff00;
    border-radius: 5px;
    background: rgba(255, 255, 0, 0.1);
    transition: all 0.3s ease;
    display: inline-block;
}

.website-link a:hover {
    background: rgba(255, 255, 0, 0.2);
    color: #ffffff;
    border-color: #ffffff;
    transform: scale(1.02);
}

.website-link a:active {
    transform: scale(0.98);
}

/* Адаптивность */
@media (max-width: 1200px) {
    .game-content {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }
    
    .controls-sidebar {
        width: 100%;
        max-width: 600px;
        flex-direction: row;
        gap: 20px;
    }
    
    .instructions, .legend {
        flex: 1;
    }
    
    .game-area {
        width: 100%;
    }
}

@media (max-width: 800px) {
    body {
        padding: 10px;
    }
    
    .game-container {
        padding: 15px;
    }
    
    .game-content {
        flex-direction: column;
        gap: 15px;
    }
    
    .controls-sidebar {
        flex-direction: column;
        gap: 15px;
    }
    
    #gameCanvas {
        width: 100%;
        max-width: 380px;
    }
    

    
    h1 {
        font-size: 2em;
    }
    
    .instructions {
        padding: 10px;
        margin-bottom: 10px;
    }
    
    .instructions h3 {
        font-size: 1.1em;
    }
    
    .control-item {
        font-size: 0.85em;
        margin-bottom: 6px;
    }
    
    .key-symbol {
        min-width: 70px;
        padding: 3px 6px;
        margin-right: 8px;
        font-size: 0.9em;
    }
    
    .control-tips p {
        font-size: 0.8em;
    }
    
    .legend {
        padding: 10px;
        margin: 10px 0;
    }
    
    .legend h3 {
        font-size: 1.1em;
    }
    
    .legend-item {
        font-size: 0.8em;
        margin-bottom: 6px;
    }
    
    .legend-symbol {
        width: 25px;
        margin-right: 8px;
    }
}

@media (max-width: 600px) {
    .controls-sidebar {
        width: 100%;
    }
    
    .game-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .start-btn, .pause-btn, .restart-btn {
        width: 200px;
    }
}

/* Ландшафтная ориентация на мобильных */
@media (max-height: 600px) and (orientation: landscape) {
    body {
        padding: 5px;
    }
    
    .game-container {
        padding: 10px;
    }
    
    .game-content {
        height: calc(100vh - 30px) !important; /* 5px*2 (body) + 10px*2 (container) + 4px (borders) */
    }
    
    .game-header {
        margin-bottom: 10px;
    }
    
    h1 {
        font-size: 1.8em;
        margin-bottom: 10px;
    }
    
    .game-content {
        flex-direction: row;
        gap: 15px;
    }
    
    .controls-sidebar {
        width: 250px;
        gap: 10px;
    }
    
    #gameCanvas {
        max-height: 400px;
        width: auto;
    }
    
    .instructions, .legend {
        padding: 8px;
    }
    
    .instructions h3, .legend h3 {
        font-size: 1em;
        margin-bottom: 8px;
    }
    
    .control-item, .legend-item {
        font-size: 0.75em;
        margin-bottom: 4px;
    }
    
    .control-tips p {
        font-size: 0.7em;
        margin: 3px 0;
    }
    
    .victory-screen {
        min-width: 300px;
        padding: 30px 20px;
    }
    
    .victory-screen h2 {
        font-size: 1.6em;
    }
    
    .victory-screen p {
        font-size: 1em;
    }
    
    .next-level-btn, .victory-screen .restart-btn {
        padding: 10px 20px;
        font-size: 1em;
        margin: 8px 3px;
    }
    
    /* Адаптация сенсорного управления для маленьких экранов */
    .touch-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    .touch-center {
        width: 50px;
        height: 50px;
    }
    
    .touch-middle {
        grid-template-columns: 50px 50px 50px;
    }
    
    .touch-dpad {
        grid-template-rows: 50px 50px 50px;
        padding: 8px;
    }
}

/* Очень маленькие ландшафтные экраны */
@media (max-height: 530px) and (orientation: landscape) and (min-width: 768px) {
    .stats-panel {
        width: 180px; /* Уменьшаем ширину панели */
        padding: 10px; /* Уменьшаем внутренние отступы */
    }
    
    .stats-panel h1 {
        font-size: 1.4em; /* Уменьшаем размер заголовка */
        margin-bottom: 8px;
        line-height: 1.2;
    }
    
    .score-item {
        margin-bottom: 5px; /* Уменьшаем отступы между элементами */
        font-size: 0.85em; /* Уменьшаем размер шрифта */
    }
    
    .score-item .label {
        font-size: 0.8em;
    }
    
    .score-item span:last-child {
        font-size: 0.9em;
        font-weight: bold;
    }
    
    .landscape-buttons {
        gap: 4px; /* Уменьшаем промежутки между кнопками */
        margin-top: 10px;
    }
    
    .landscape-buttons button {
        padding: 6px 8px; /* Уменьшаем размер кнопок */
        font-size: 0.75em;
        min-height: 28px;
    }
    
    .game-content {
        gap: 15px; /* Уменьшаем зазор между игрой и панелью */
    }
}

/* Экстремально маленькие ландшафтные экраны */
@media (max-height: 450px) and (orientation: landscape) and (min-width: 768px) {
    .stats-panel {
        width: 160px; /* Еще больше уменьшаем ширину панели */
        padding: 8px;
    }
    
    .stats-panel h1 {
        font-size: 1.2em; /* Еще больше уменьшаем заголовок */
        margin-bottom: 5px;
    }
    
    .score-item {
        margin-bottom: 3px;
        font-size: 0.75em;
    }
    
    .score-item .label {
        font-size: 0.7em;
    }
    
    .score-item span:last-child {
        font-size: 0.8em;
    }
    
    .landscape-buttons {
        gap: 3px;
        margin-top: 8px;
    }
    
    .landscape-buttons button {
        padding: 4px 6px;
        font-size: 0.7em;
        min-height: 24px;
    }
    
    .game-content {
        gap: 10px;
    }
    
    /* Уменьшаем ссылку на экстремально маленьких экранах */
    .website-link {
        margin-top: 5px;
        padding: 2px;
    }
    
    .website-link a {
        font-size: 0.65em;
        padding: 2px 4px;
    }
}

/* Анимации */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.pulse {
    animation: pulse 1s infinite;
}

@keyframes glow {
    0%, 100% { text-shadow: 0 0 10px #ffff00; }
    50% { text-shadow: 0 0 20px #ffff00, 0 0 30px #ffff00; }
}

h1 {
    animation: glow 2s infinite;
}

/* Для очень маленьких экранов */
@media (max-width: 400px) {
    .game-container {
        padding: 5px;
        margin: 5px;
    }
    
    h1 {
        font-size: 1.5em;
    }
    
    .game-buttons {
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .start-btn, .pause-btn, .restart-btn, .sound-btn {
        padding: 8px 12px;
        font-size: 0.9em;
    }
}

/* Медиа-запросы для адаптивности */

/* Ландшафтный режим (широкие экраны) */
@media (min-width: 768px) and (orientation: landscape) {
    body {
        padding: 0; /* Убираем отступы body в ландшафтном режиме */
    }
    
    .game-content {
        flex-direction: row;
        align-items: flex-start;
        gap: 20px;
        height: calc(100vh - 40px - 4px); /* container padding + borders */
        padding: 0;
        margin: 0;
    }
    
    .game-area {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 100%;
        overflow: hidden;
        min-width: 0; /* Позволяет элементу сжиматься */
    }
    
    .stats-panel {
        flex-direction: column;
        width: 220px;
        margin-top: 0;
        margin-left: 0;
        gap: 10px;
        flex-shrink: 0;
        height: 100%;
        overflow-y: auto;
        box-sizing: border-box;
        padding: 20px;
    }
    
    .stats-panel h1 {
        width: 100%;
        text-align: center;
        margin-bottom: 15px;
        font-size: 2em;
        order: -1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .score-item {
        flex-direction: row;
        justify-content: space-between;
        width: 100%;
    }
    
    #gameCanvas {
        max-width: none;
        max-height: none;
    }
    
    .game-container {
        max-width: none;
        width: 100vw;
        height: 100vh;
        margin: 0;
        padding: 20px;
        border-radius: 0;
        box-sizing: border-box;
        overflow: hidden;
    }
    
    /* Показываем только ландшафтные кнопки */
    .landscape-buttons {
        display: flex;
        flex-direction: column;
        gap: 8px;
        width: 100%;
        margin-top: 20px;
        order: 1;
    }
    
    .portrait-buttons {
        display: none;
    }
    
    .landscape-buttons button {
        width: 100%;
        text-align: center;
    }
    
    .score-item .label {
        margin-bottom: 0;
        margin-right: 10px;
    }
    
    /* Ссылка в ландшафтном режиме */
    .landscape-link {
        display: block;
    }
    
    .portrait-link {
        display: none;
    }
}

/* Портретный режим или узкие экраны */
@media (max-width: 767px), (orientation: portrait) {
    .game-content {
        flex-direction: column;
    }
    
    .stats-panel {
        order: -1;
        margin-top: 0;
        margin-bottom: 20px;
    }
    
    .stats-panel h1 {
        width: 100%;
        text-align: center;
        margin-bottom: 10px;
        font-size: 2.5em;
        order: -1;
    }
    
    #gameCanvas {
        width: 100%;
        max-width: calc(100vw - 60px); /* Максимальная ширина с учетом отступов */
        height: auto;
    }
    
    .game-container {
        margin: 10px;
        padding: 15px;
        max-width: none;
        width: calc(100% - 20px);
    }
    
    /* Скрываем ландшафтные кнопки и показываем портретные */
    .landscape-buttons {
        display: none;
    }
    
    .portrait-buttons {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
        width: 100%;
        order: 1;
        margin-top: 15px;
    }
    
    h1 {
        font-size: 2em;
    }
    
    .info-btn {
        font-size: 1em;
        padding: 10px 12px;
    }
    
    /* Ссылка в портретном режиме */
    .portrait-link {
        display: block;
        order: 2;
    }
    
    .landscape-link {
        display: none;
    }
}

/* Очень маленькие экраны */
@media (max-width: 480px) {
    .game-container {
        padding: 10px;
        margin: 5px;
    }
    
    h1 {
        font-size: 1.8em;
    }
    
    .stats-panel {
        gap: 10px;
        padding: 10px;
    }
    
    .score-item {
        min-width: 60px;
    }
    
    .score-item .label {
        font-size: 0.7em;
    }
    
    .score-item span:last-child {
        font-size: 1em;
    }
    
    .overlay-content {
        padding: 15px;
        margin: 10px;
    }
    
    .game-buttons {
        gap: 5px;
    }
    
    button {
        padding: 8px 12px;
        font-size: 0.9em;
    }
    
    .info-btn {
        font-size: 0.9em;
        padding: 8px 10px;
    }
}

/* Очень маленькие ландшафтные экраны */
@media (max-height: 530px) and (orientation: landscape) and (min-width: 768px) {
    .stats-panel {
        width: 180px; /* Уменьшаем ширину панели */
        padding: 10px; /* Уменьшаем внутренние отступы */
    }
    
    .stats-panel h1 {
        font-size: 1.4em; /* Уменьшаем размер заголовка */
        margin-bottom: 8px;
        line-height: 1.2;
    }
    
    .score-item {
        margin-bottom: 5px; /* Уменьшаем отступы между элементами */
        font-size: 0.85em; /* Уменьшаем размер шрифта */
    }
    
    .score-item .label {
        font-size: 0.8em;
    }
    
    .score-item span:last-child {
        font-size: 0.9em;
        font-weight: bold;
    }
    
    .landscape-buttons {
        gap: 4px; /* Уменьшаем промежутки между кнопками */
        margin-top: 10px;
    }
    
    .landscape-buttons button {
        padding: 6px 8px; /* Уменьшаем размер кнопок */
        font-size: 0.75em;
        min-height: 28px;
    }
    
    .game-content {
        gap: 15px; /* Уменьшаем зазор между игрой и панелью */
    }
}

/* Экстремально маленькие ландшафтные экраны */
@media (max-height: 450px) and (orientation: landscape) and (min-width: 768px) {
    .stats-panel {
        width: 160px; /* Еще больше уменьшаем ширину панели */
        padding: 8px;
    }
    
    .stats-panel h1 {
        font-size: 1.2em; /* Еще больше уменьшаем заголовок */
        margin-bottom: 5px;
    }
    
    .score-item {
        margin-bottom: 3px;
        font-size: 0.75em;
    }
    
    .score-item .label {
        font-size: 0.7em;
    }
    
    .score-item span:last-child {
        font-size: 0.8em;
    }
    
    .landscape-buttons {
        gap: 3px;
        margin-top: 8px;
    }
    
    .landscape-buttons button {
        padding: 4px 6px;
        font-size: 0.7em;
        min-height: 24px;
    }
    
    .game-content {
        gap: 10px;
    }
}
