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

        body {
            font-family: 'Courier New', monospace;
            background: #1a1a1a;
            color: #fff;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 12px 20px 20px;
        }

        h1 {
            margin-bottom: 8px;
            color: #ffa500;
            text-shadow: 2px 2px 4px #000;
            font-size: 28px;
        }

        /* Игра и панель управления. На узком экране — друг под другом,
           на широком — панель справа от игры, чтобы не прокручивать вниз. */
        #layout {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 15px;
            width: 100%;
        }

        #gameCanvas {
            display: block;
            border: 3px solid #444;
            background: #000;
            image-rendering: pixelated;
            image-rendering: crisp-edges;
            /* холст ужимается под высоту окна, сохраняя пропорции 4:3 */
            width: auto;
            height: auto;
            max-width: 100%;
            max-height: calc(100vh - 80px);
            aspect-ratio: 4 / 3;
        }

        #sidebar {
            display: flex;
            flex-direction: column;
            gap: 15px;
            width: 100%;
            max-width: 806px;
        }

        #sidebar > div {
            margin-top: 0;
        }

        #ui {
            margin-top: 15px;
            padding: 15px;
            background: #2a2a2a;
            border: 2px solid #444;
            border-radius: 8px;
            text-align: center;
        }

        .stat {
            display: inline-block;
            margin: 0 15px;
            padding: 8px 15px;
            background: #1a1a1a;
            border-radius: 5px;
            border: 1px solid #555;
        }

        .stat-label {
            color: #aaa;
            font-size: 12px;
        }

        .stat-value {
            color: #ffa500;
            font-size: 18px;
            font-weight: bold;
        }

        .stat-value.full {
            color: #dc143c;
        }

        .stat-sub {
            color: #aaa;
            font-size: 11px;
            margin-top: 2px;
        }

        .backpack-bar {
            width: 90px;
            height: 6px;
            margin-top: 4px;
            background: #333;
            border-radius: 3px;
            overflow: hidden;
        }

        .backpack-fill {
            height: 100%;
            width: 0;
            background: #ffa500;
            transition: width 0.15s;
        }

        .backpack-fill.full {
            background: #dc143c;
        }

        .health-fill {
            background: #4caf50;
        }

        /* Радио */
        #leftPanel {
            display: flex;
            flex-direction: column;
            gap: 15px;
            width: 100%;
            max-width: 806px;
        }

        #leftPanel > div {
            margin-top: 0;
        }

        /* телевизор скрыт, пока его не открыли клавишей V */
        #videoPanel {
            display: none;
        }

        #videoPanel.open {
            display: block;
            padding: 12px 15px;
            background: #2a2a2a;
            border: 2px solid #444;
            border-radius: 8px;
            text-align: center;
        }

        /* корпус телевизора: дерево, кинескоп со скруглёнными углами, две ручки */
        .tv {
            position: relative;
            margin: 6px 0 8px;
            padding: 8px 8px 22px;
            background: linear-gradient(#6b3e1e, #4a2a14);
            border-radius: 10px;
            border: 2px solid #3a2410;
        }

        .tv-screen {
            position: relative;
            width: 100%;
            aspect-ratio: 16 / 9;
            background: #0b0b0b;
            border-radius: 14px / 10px;
            overflow: hidden;
            box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.9);
        }

        .video-player {
            position: absolute;
            inset: 0;
            width: 100%;
            height: 100%;
            border: 0;
            background: #000;
        }

        .tv-off {
            position: absolute;
            left: 8px;
            right: 8px;
            top: 8px;
            aspect-ratio: 16 / 9;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #555;
            font-size: 22px;
            pointer-events: none;
        }

        .tv-knobs {
            position: absolute;
            right: 10px;
            bottom: 5px;
            display: flex;
            gap: 6px;
        }

        .tv-knobs span {
            width: 11px;
            height: 11px;
            border-radius: 50%;
            background: #c8a165;
            border: 1px solid #3a2410;
        }

        .video-title {
            color: #ffa500;
            font-weight: bold;
            font-size: 14px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        #videoList {
            list-style: none;
            margin-bottom: 8px;
            max-height: 180px;
            overflow-y: auto;
        }

        #videoList li {
            display: flex;
            gap: 4px;
            margin-bottom: 4px;
        }

        #videoList li.current .radio-pick {
            border-color: #ffa500;
            color: #ffa500;
        }

        #videoList li.radio-empty {
            color: #888;
            font-size: 12px;
        }

        /* панель радио скрыта, пока её не открыли клавишей M */
        #radioPanel {
            display: none;
        }

        #radioPanel.open {
            display: block;
        }

        .radio-head {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .radio-x {
            background: none;
            border: none;
            color: #aaa;
            font-size: 16px;
            cursor: pointer;
            padding: 2px 6px;
        }

        .radio-manage {
            margin-top: 10px;
            text-align: left;
            font-size: 13px;
        }

        .radio-manage summary {
            cursor: pointer;
            color: #ffa500;
            margin-bottom: 6px;
        }

        #radioList {
            list-style: none;
            margin-bottom: 8px;
            max-height: 180px;
            overflow-y: auto;
        }

        #radioList li {
            display: flex;
            gap: 4px;
            margin-bottom: 4px;
        }

        #radioList li.radio-empty {
            color: #888;
            font-size: 12px;
        }

        .radio-pick {
            flex: 1;
            text-align: left;
            background: #1a1a1a;
            color: #ddd;
            border: 1px solid #444;
            border-radius: 4px;
            padding: 4px 8px;
            font: 13px 'Courier New', monospace;
            cursor: pointer;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        #radioList li.current .radio-pick {
            border-color: #ffa500;
            color: #ffa500;
        }

        .radio-del {
            background: #1a1a1a;
            color: #ff6b6b;
            border: 1px solid #444;
            border-radius: 4px;
            padding: 0 8px;
            cursor: pointer;
        }

        .radio-manage input[type="text"],
        .radio-manage input[type="url"] {
            width: 100%;
            margin-bottom: 6px;
            padding: 6px 8px;
            background: #1a1a1a;
            color: #fff;
            border: 1px solid #555;
            border-radius: 4px;
            font: 13px 'Courier New', monospace;
        }

        .radio-note.error {
            color: #ff6b6b;
        }

        #radioPanel.open {
            padding: 12px 15px;
            background: #2a2a2a;
            border: 2px solid #444;
            border-radius: 8px;
            text-align: center;
        }

        #radioStation {
            color: #ffa500;
            font-size: 16px;
            font-weight: bold;
            margin: 2px 0;
        }

        #radioStatus {
            font-size: 12px;
            color: #888;
            margin-bottom: 8px;
        }

        #radioStatus.live { color: #7CFC00; }
        #radioStatus.error { color: #ff6b6b; }

        .radio-buttons {
            display: flex;
            gap: 6px;
            justify-content: center;
            margin-bottom: 8px;
        }

        .radio-buttons .btn {
            padding: 6px 12px;
        }

        .radio-volume {
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 12px;
            color: #aaa;
        }

        .radio-volume input {
            flex: 1;
            min-width: 0;
            accent-color: #ffa500;
        }

        .radio-note {
            font-size: 10px;
            color: #777;
            margin-top: 6px;
        }

        #savePanel {
            margin-top: 15px;
            padding: 15px;
            background: #2a2a2a;
            border: 2px solid #444;
            border-radius: 8px;
            display: flex;
            gap: 10px;
            justify-content: center;
            align-items: center;
            flex-wrap: wrap;
        }

        .btn {
            padding: 10px 20px;
            background: #ffa500;
            color: #000;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-weight: bold;
            font-family: 'Courier New', monospace;
            transition: all 0.2s;
        }

        .btn:hover {
            background: #ff8c00;
            transform: translateY(-2px);
        }

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

        .btn-secondary {
            background: #555;
            color: #fff;
        }

        .btn-secondary:hover {
            background: #666;
        }

        .btn-danger {
            background: #dc143c;
            color: #fff;
        }

        .btn-danger:hover {
            background: #b01030;
        }

        #controls {
            margin-top: 15px;
            padding: 15px;
            background: #2a2a2a;
            border: 2px solid #444;
            border-radius: 8px;
            text-align: center;
        }

        #controls p {
            margin: 5px 0;
            color: #bbb;
        }

        .key {
            display: inline-block;
            padding: 3px 8px;
            background: #444;
            border: 1px solid #666;
            border-radius: 3px;
            color: #ffa500;
            font-weight: bold;
        }

        #legend {
            margin-top: 15px;
            padding: 15px;
            background: #2a2a2a;
            border: 2px solid #444;
            border-radius: 8px;
            display: flex;
            justify-content: center;
            gap: 20px;
            flex-wrap: wrap;
        }

        .legend-item {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .legend-color {
            width: 20px;
            height: 20px;
            border: 1px solid #666;
        }

        /* Модальное окно */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.8);
            z-index: 1000;
            align-items: center;
            justify-content: center;
        }

        .modal.active {
            display: flex;
        }

        .modal-content {
            background: #2a2a2a;
            border: 3px solid #444;
            border-radius: 10px;
            padding: 30px;
            max-width: 600px;
            width: 90%;
            max-height: 80vh;
            overflow-y: auto;
        }

        .modal-title {
            color: #ffa500;
            font-size: 24px;
            margin-bottom: 20px;
            text-align: center;
        }

        .save-slot {
            background: #1a1a1a;
            border: 2px solid #555;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 10px;
            cursor: pointer;
            transition: all 0.2s;
        }

        .save-slot:hover {
            border-color: #ffa500;
            transform: translateX(5px);
        }

        .save-slot-empty {
            opacity: 0.5;
            font-style: italic;
        }

        .save-slot-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 8px;
        }

        .save-slot-title {
            color: #ffa500;
            font-size: 16px;
            font-weight: bold;
        }

        .save-slot-info {
            color: #aaa;
            font-size: 12px;
        }

        .save-slot-actions {
            display: flex;
            gap: 5px;
            margin-top: 10px;
        }

        .btn-small {
            padding: 5px 10px;
            font-size: 12px;
        }

        /* настройки */
        .setting {
            margin-bottom: 18px;
            text-align: left;
        }

        .setting-label {
            color: #ffa500;
            margin-bottom: 8px;
        }

        .setting-options {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 6px;
            margin-bottom: 8px;
        }

        .setting-options .btn {
            margin: 0;
            padding: 8px 6px;
            font-size: 12px;
        }

        .setting-options .btn.chosen {
            background: #ffa500;
            color: #000;
        }

        .setting-check {
            display: flex;
            gap: 10px;
            align-items: flex-start;
            cursor: pointer;
            line-height: 1.4;
        }

        .setting-check input {
            margin-top: 3px;
            accent-color: #ffa500;
        }

        .setting-note {
            color: #888;
            font-size: 12px;
            margin-top: 6px;
        }

        .notification {
            position: fixed;
            top: 20px;
            right: 20px;
            max-width: 420px;
            transition: top 0.2s;
            background: #2a2a2a;
            border: 2px solid #ffa500;
            border-radius: 8px;
            padding: 15px 20px;
            z-index: 2000;
            animation: slideIn 0.3s ease-out;
        }

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

        .modal-buttons {
            display: flex;
            gap: 10px;
            justify-content: center;
            margin-top: 20px;
        }

        input[type="text"] {
            width: 100%;
            padding: 10px;
            background: #1a1a1a;
            border: 2px solid #555;
            border-radius: 5px;
            color: #fff;
            font-family: 'Courier New', monospace;
            font-size: 14px;
            margin-bottom: 15px;
        }

        input[type="text"]:focus {
            outline: none;
            border-color: #ffa500;
        }

        input[type="file"] {
            display: none;
        }

        /* Лавка: список кирок */
        .shop-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 15px;
            background: #1a1a1a;
            border: 2px solid #555;
            border-radius: 8px;
            padding: 12px 15px;
            margin-bottom: 10px;
        }

        .shop-item.owned {
            border-color: #ffa500;
        }

        .shop-item.below {
            opacity: 0.45;
        }

        .shop-item-name {
            color: #ffa500;
            font-weight: bold;
            font-size: 16px;
        }

        .shop-item-info {
            color: #aaa;
            font-size: 12px;
            margin-top: 4px;
        }

        /* список товаров прокручивается, чтобы «Закрыть» всегда было видно */
        #shopList {
            max-height: calc(80vh - 240px);
            overflow-y: auto;
            padding-right: 4px;
        }

        /* на широком экране лавка шире и в две колонки */
        @media (min-width: 1000px) {
            #shopModal .modal-content {
                max-width: 920px;
            }
            #shopList {
                display: grid;
                grid-template-columns: 1fr 1fr;
                column-gap: 10px;
                align-content: start;
            }
            #shopList .shop-section {
                grid-column: 1 / -1;
            }
            #shopList .shop-item {
                margin-bottom: 0;
                margin-top: 10px;
            }
        }

        .shop-section {
            color: #aaa;
            font-size: 12px;
            text-transform: uppercase;
            letter-spacing: 1px;
            margin: 12px 0 6px;
        }

        .shop-money {
            text-align: center;
            color: #ccc;
            margin-bottom: 15px;
        }

        .btn:disabled {
            background: #444;
            color: #888;
            cursor: default;
            transform: none;
        }
        /* Широкий экран: идёт последним, чтобы перекрывать правила выше */
        /* узкий экран: сначала игра, потом сохранения и радио, потом статистика */
        #gameCanvas { order: 0; }
        #leftPanel { order: 1; }
        #sidebar { order: 2; }

        @media (min-width: 1100px) {
            #layout {
                flex-direction: row;
                justify-content: center;
                align-items: flex-start;
            }

            /* широкий экран: слева сохранения и радио, в центре игра, справа статистика */
            #leftPanel { order: 0; width: 200px; flex-shrink: 0; max-height: calc(100vh - 80px); overflow-y: auto; }
            /* настройка «поменять панели местами» */
            body.swap-panels #leftPanel { order: 2; }
            body.swap-panels #sidebar { order: 0; }
            #gameCanvas { order: 1; }
            #sidebar { order: 2; }

            #leftPanel #savePanel {
                display: flex;
                flex-direction: column;
                gap: 8px;
                padding: 10px;
            }

            #leftPanel #savePanel .btn {
                margin: 0;
                width: 100%;
            }

            /* на большом мониторе холст растягивается на всю высоту окна,
               но оставляет место под панель справа */
            #gameCanvas {
                height: min(calc(100vh - 80px), calc((100vw - 620px) * 0.75), 1200px);
                width: auto;
                max-width: none;
                max-height: none;
            }

            #sidebar {
                width: 320px;
                flex-shrink: 0;
                max-height: calc(100vh - 80px);
                overflow-y: auto;
            }

            #ui {
                display: grid;
                grid-template-columns: 1fr 1fr;
                gap: 8px;
                padding: 10px;
            }

            #ui .stat {
                margin: 0;
            }

            /* рюкзак — на всю ширину: под ним список содержимого */
            #ui .stat.wide {
                grid-column: 1 / -1;
            }

            #savePanel {
                display: grid;
                grid-template-columns: 1fr 1fr;
                padding: 10px;
            }

            #savePanel .btn {
                padding: 10px 8px;
            }

            #savePanel .btn-danger {
                grid-column: 1 / -1;
            }

            #legend {
                display: grid;
                grid-template-columns: 1fr 1fr 1fr;
                gap: 8px;
                font-size: 13px;
            }

            #controls {
                font-size: 13px;
                text-align: left;
            }

            .backpack-bar {
                width: 100%;
            }
        }

        /* ===== Сенсорное управление (телефоны, планшеты) =====
           Включается само на устройствах без мыши; на компьютере его не видно. */
        #touchControls,
        #menuClose {
            display: none;
        }

        body.touch {
            padding: 0;
            overflow: hidden;
            touch-action: none;
            -webkit-user-select: none;
            user-select: none;
            -webkit-touch-callout: none;
        }

        /* на телефоне уведомления у́же и ниже сводки, чтобы не закрывать её */
        body.touch .notification {
            right: 8px;
            max-width: 70vw;
            padding: 8px 12px;
            font-size: 13px;
        }

        /* в полях ввода (станция радио, имя сохранения) текст должен выделяться и
           печататься — иначе на iPhone в них нельзя ничего ввести */
        body.touch input,
        body.touch textarea {
            -webkit-user-select: text;
            user-select: text;
            touch-action: manipulation;
            font-size: 16px;   /* меньше 16px — iPhone приближает страницу при вводе */
        }

        body.touch h1 {
            display: none;
        }

        body.touch #layout {
            gap: 0;
        }

        body.touch #gameCanvas {
            border: none;
            aspect-ratio: auto;
            max-width: 100vw;
            max-height: 100vh;
        }

        @media (orientation: landscape) {
            body.touch #gameCanvas { height: 100vh; width: auto; }
        }

        @media (orientation: portrait) {
            body.touch #gameCanvas { width: 100vw; height: auto; }
        }

        /* панель со статистикой и сохранениями — по кнопке «☰», поверх игры */
        body.touch #sidebar {
            display: none;
        }

        body.touch.menu-open #sidebar {
            display: flex;
            position: fixed;
            inset: 0;
            z-index: 900;
            width: 100%;
            max-width: none;
            max-height: none;
            overflow-y: auto;
            padding: 12px;
            background: rgba(20, 20, 20, 0.97);
        }

        /* телефон: панель слева не видна; сохранения — в меню ☰ (переносятся туда при
           включении сенсорного режима), радио — плавающая панель поверх игры */
        body.touch .radio-open-btn {
            display: none;
        }

        body.touch #leftPanel {
            width: 0;
            height: 0;
        }

        body.touch #videoPanel.open {
            position: fixed;
            top: calc(44px + env(safe-area-inset-top, 0px));
            left: 8px;
            width: min(360px, calc(100vw - 16px));
            max-height: calc(100vh - 260px);
            overflow-y: auto;
            z-index: 860;
        }

        body.touch #radioPanel.open {
            position: fixed;
            top: calc(44px + env(safe-area-inset-top, 0px));
            left: 8px;
            width: min(340px, calc(100vw - 16px));
            max-height: calc(100vh - 260px);
            overflow-y: auto;
            z-index: 850;
        }

        body.touch.menu-open #menuClose {
            display: block;
            align-self: center;
        }

        body.touch #touchControls {
            display: block;
        }

        /* размер кнопки подстраивается под ширину экрана, чтобы две панели не наезжали */
        body.touch {
            --tb: clamp(42px, calc((100vw - 56px) / 6.4), 64px);
        }

        .touch-pad {
            position: fixed;
            bottom: calc(10px + env(safe-area-inset-bottom, 0px));
            z-index: 800;
            display: grid;
            gap: 8px;
        }

        #touchLeft {
            left: calc(10px + env(safe-area-inset-left, 0px));
            grid-template-columns: repeat(3, var(--tb));
            grid-template-rows: repeat(3, var(--tb));
        }

        #touchRight {
            right: calc(10px + env(safe-area-inset-right, 0px));
            grid-template-columns: repeat(3, var(--tb));
            grid-template-rows: repeat(3, var(--tb));
        }

        .tbtn {
            border: 2px solid rgba(255, 165, 0, 0.6);
            border-radius: 12px;
            background: rgba(30, 30, 30, 0.55);
            color: #ffd27f;
            font: bold clamp(10px, calc(var(--tb) * 0.22), 14px) 'Courier New', monospace;
            touch-action: none;
            -webkit-tap-highlight-color: transparent;
            display: flex;
            align-items: center;
            justify-content: center;
            text-align: center;
            line-height: 1.1;
            padding: 0;
        }

        .tbtn.big {
            font-size: 26px;
        }

        .tbtn.down,
        .tbtn.on {
            background: rgba(255, 165, 0, 0.55);
            color: #000;
        }

        #tUp    { grid-column: 2; grid-row: 1; }
        #tLeft  { grid-column: 1; grid-row: 2; }
        #tRight { grid-column: 3; grid-row: 2; }
        #tDown  { grid-column: 2; grid-row: 3; }
        #tDig   { grid-column: 2 / 4; grid-row: 2 / 4; font-size: 30px; border-radius: 50%; }

        /* вертикальный экран: игра сверху, кнопки снизу */
        @media (orientation: portrait) {
            body.touch #gameCanvas {
                margin-top: env(safe-area-inset-top, 0px);
            }
        }
    
