/* Общие настройки в стиле старых консолей */
body {
    margin: 0;
    padding: 0;
    background-color: #0b0214;
    color: #00ff66;
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    overflow: hidden;
    height: 100vh;
    box-sizing: border-box;
}

/* Эффект ЭЛТ-телевизора поверх всего экрана */
.crt-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), 
                linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 4px, 6px 100%;
    z-index: 5;
    pointer-events: none;
    opacity: 0.6;
}

/* Главный контейнер */
.arcade-container {
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px; /* Сжали расстояние между блоками */
    height: 100vh;
    min-height: 0;
}

/* Аркадная панель управления (СДЕЛАЛИ УЗКОЙ: внутренние отступы 6px вместо 15px) */
.arcade-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #130324;
    border: 4px solid #ff00ff;
    padding: 6px 20px; /* Панель стала тонкой полосой */
    box-shadow: inset 0 0 15px rgba(255, 0, 255, 0.3);
    z-index: 10;
}

.control-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 12px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

label {
    color: #ff00ff;
    text-shadow: 0 0 5px #ff00ff;
    white-space: nowrap;
    font-size: 10px;
}

.retro-select {
    background: #000;
    color: #00ff66;
    border: 2px solid #00ff66;
    font-family: 'Press Start 2P', monospace;
    padding: 5px 10px; /* Компактные отступы внутри селекта */
    outline: none;
    cursor: pointer;
    font-size: 11px;
    width: 500px;
    max-width: 500px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.retro-select:focus {
    border-color: #fff;
    box-shadow: 0 0 10px #00ff66;
}

#playerCountSelect,
#playerNumberSelect {
    width: 170px;
}

#challengeSelect {
    width: 250px;
}

.retro-btn {
    background: #00ff66;
    color: #000;
    border: none;
    font-family: 'Press Start 2P', monospace;
    font-size: 11px; /* Сделали шрифт кнопок капельку меньше */
    font-weight: bold;
    padding: 6px 15px; /* Уменьшили высоту кнопок */
    cursor: pointer;
    box-shadow: 0 0 10px #00ff66;
    transition: all 0.1s ease;
}

.retro-btn:hover {
    background: #fff;
    box-shadow: 0 0 20px #fff;
}

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

/* ==========================================
   СЕТКА ДЛЯ МУЛЬТИПЛЕЕРА (Твоя оригинальная)
========================================== */
.grid-layout {
    display: grid;
    gap: 20px;
    width: 100%;
    z-index: 6;
}

.grid-1-players { grid-template-columns: 1fr; }
.grid-2-players { grid-template-columns: 1fr 1fr; }
.grid-3-players { grid-template-columns: 1fr 1fr; }
.grid-4-players { grid-template-columns: 1fr 1fr; }

.player-slot {
    background: #000;
    border: 4px solid #ffcc00;
    box-shadow: 0 0 15px rgba(255, 204, 0, 0.4);
    position: relative;
    aspect-ratio: 4 / 3;
    display: flex;
    flex-direction: column;
    z-index: 7;
}

.player-slot.active-user-slot {
    border-color: #00ffcc;
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.6);
}

.player-slot.stream-slot {
    border-color: #ff0055;
    box-shadow: 0 0 15px rgba(255, 0, 85, 0.4);
}

.player-label {
    position: absolute;
    top: -12px; left: 15px;
    background: #ffcc00;
    color: #000;
    padding: 2px 8px;
    font-size: 10px;
    z-index: 12;
    text-transform: uppercase;
    font-weight: bold;
}

.player-slot.active-user-slot .player-label {
    background: #00ffcc;
}

.player-slot.stream-slot .player-label {
    background: #ff0055;
    color: #fff;
}

.slot-content {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    image-rendering: pixelated;
    background: #000;
    z-index: 4;
}

video.slot-content {
    object-fit: contain;
}

/* Экран обратного отсчета */
.countdown-screen {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
}

#countdown-number {
    font-size: 100px;
    color: #ffcc00;
    text-shadow: 0 0 30px #ffcc00;
    font-family: 'Press Start 2P', monospace;
    animation: pulseCount 0.5s infinite alternate;
}

@keyframes pulseCount {
    0% { transform: scale(0.9); }
    100% { transform: scale(1.1); }
}

/* Кнопка челленджа особого цвета */
.retro-btn.challenge-trigger {
    background: #ffcc00;
    color: #000;
    box-shadow: 0 0 10px #ffcc00;
}
.retro-btn.challenge-trigger:hover {
    background: #fff;
    box-shadow: 0 0 25px #ffcc00;
}

/* Таблица лидеров соревнования */
.leaderboard-box {
    display: flex;
    flex-direction: column;
    align-items: flex-start !important;
    border-color: #ffcc00 !important;
    box-shadow: inset 0 0 15px rgba(255, 204, 0, 0.2) !important;
    gap: 10px !important;
}

.leaderboard-title {
    color: #ffcc00;
    font-size: 11px;
    margin-bottom: 5px;
}

.player-score-row {
    font-size: 10px;
    margin: 4px 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
}

/* ==========================================
   GRIDSTACK — РЕДАКТОР LAYOUT
   ========================================== */
/* Контейнер грида + бумажная grid-layout внутри */
#main-arena.gridstack-active {
    background: #0a020f;
    padding: 6px;
    box-sizing: border-box;
    flex: 1;
    min-height: 0;
    /* GridStack сам управляет layout */
}

/* Переопределяем GridStack под ретро-стиль */
.grid-stack {
    background: #0a020f;
    width: 100%;
    height: 100%;
}

.grid-stack-item-content {
    background: transparent !important;
    border: none !important;
    overflow: hidden;
}

/* Кнопка удаления на виджете в режиме редактирования */
.widget-delete-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: #ff0055;
    color: #fff;
    border: 2px solid #fff;
    border-radius: 50%;
    font-size: 14px;
    line-height: 20px;
    text-align: center;
    cursor: pointer;
    z-index: 100;
    display: none;
    font-family: 'Press Start 2P', monospace;
    box-shadow: 0 0 10px rgba(255, 0, 85, 0.8);
}

.grid-stack-item.ui-draggable .widget-delete-btn,
.grid-stack-item.ui-resizable .widget-delete-btn {
    display: block;
}

/* Ручка перетаскивания */
.widget-handle {
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 6px;
    background: rgba(255, 0, 255, 0.6);
    border-radius: 3px;
    cursor: grab;
    z-index: 50;
    display: none;
    box-shadow: 0 0 8px #ff00ff;
}

.grid-stack-item.ui-draggable .widget-handle {
    display: block;
}

/* Маркер изменения размера (уголок) */
.widget-resize-handle {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-right: 3px solid rgba(0, 255, 102, 0.6);
    border-bottom: 3px solid rgba(0, 255, 102, 0.6);
    cursor: nw-resize;
    z-index: 50;
    display: none;
}

.grid-stack-item.ui-resizable .widget-resize-handle {
    display: block;
}

/* Панель виджетов */
.widget-panel {
    border-color: #ff00ff !important;
    margin-top: 4px;
}

.widget-panel .control-row {
    flex-wrap: wrap;
    gap: 8px;
}

/* Анимация появления виджета */
@keyframes widgetAppear {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.grid-stack-item-content > div {
    animation: widgetAppear 0.2s ease-out;
}

/* Placeholder для пустых слотов при drag */
.grid-stack-placeholder {
    background: rgba(255, 0, 255, 0.15) !important;
    border: 2px dashed #ff00ff !important;
    border-radius: 8px !important;
}

/* ==========================================
   СТИЛИ РЕДАКТОРА (vanilla JS)
   ========================================== */
#main-arena.editing {
    background: #0a020f;
    padding: 6px;
    box-sizing: border-box;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.editor-widget {
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0,0,0,0.5);
    transition: box-shadow 0.15s;
}

.editor-widget .widget-inner {
    border-radius: 0;
}

.editor-widget:hover {
    box-shadow: 0 0 0 2px #ff00ff, 0 4px 20px rgba(255,0,255,0.3);
}

/* Placeholder при добавлении нового виджета */
@keyframes widgetPopIn {
    0% { transform: scale(0.85); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.editor-widget {
    animation: widgetPopIn 0.2s ease-out;
}

/* Кнопки редактора */
.editor-toolbar {
    margin-top: 6px;
    border-top: 1px solid rgba(255,0,255,0.3);
    padding-top: 8px;
}

/* Критические исправления для окон (оригинал) */
#main-arena:not(.editing) {
    background: #0a020f;
    padding: 10px;
    box-sizing: border-box;
    flex: 1;
    min-height: 0;
}

.player-frame {
    background: #000;
    border: 4px solid #ffcc00;
    box-shadow: 0 0 20px rgba(255, 204, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-width: 100%;
    max-height: 100%;
    min-height: 0;
}

.player-frame .player-header {
    background: #130324;
    color: #ffcc00;
    padding: 8px 12px;
    font-size: 12px;
    border-bottom: 3px solid #ff00ff;
    flex-shrink: 0;
}

.player-frame iframe {
    width: 100%;
    height: calc(100% - 40px);
    border: none;
    flex-shrink: 1;
    min-height: 0;
}

.player-frame.ratio-16-9 {
    aspect-ratio: 16 / 9;
}

/* ==========================================
   РЕТРО-ЧЕКБОКСЫ ДЛЯ ФИЛЬТРА ПЛАТФОРМ
========================================== */
.retro-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: #00ff66;
    font-size: 11px;
    user-select: none;
}

.retro-checkbox input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 2px solid #00ff66;
    background: #000;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}

.retro-checkbox input[type="checkbox"]:checked {
    background: #00ff66;
    box-shadow: 0 0 8px #00ff66;
}

.retro-checkbox input[type="checkbox"]:checked::after {
    content: "✔";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #000;
    font-size: 12px;
    font-weight: bold;
}

.retro-checkbox input[type="checkbox"]:focus {
    outline: none;
    box-shadow: 0 0 8px #00ff66;
}

.retro-checkbox span {
    color: #00ff66;
    text-shadow: 0 0 5px #00ff66;
}

/* ==========================================
   НОВЫЙ DASHBOARD (замена editor.js)
   ========================================== */

/* Контейнер контента виджета */
.dashboard-widget-content {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* Кнопка удаления виджета (редактирование) */
.gs-del {
    position: absolute !important;
    top: -8px !important;
    right: -8px !important;
    width: 22px !important;
    height: 22px !important;
    background: #ff0055 !important;
    color: #fff !important;
    border: 2px solid #fff !important;
    border-radius: 50% !important;
    font-size: 12px !important;
    line-height: 18px !important;
    text-align: center !important;
    cursor: pointer !important;
    z-index: 999 !important;
    display: none !important;
    font-family: sans-serif !important;
    box-shadow: 0 0 10px rgba(255,0,85,0.8) !important;
}

/* Кнопка настроек виджета (редактирование) */
.gs-settings {
    position: absolute !important;
    top: -8px !important;
    left: -8px !important;
    width: 22px !important;
    height: 22px !important;
    background: #00ff66 !important;
    color: #000 !important;
    border: 2px solid #fff !important;
    border-radius: 50% !important;
    font-size: 11px !important;
    line-height: 18px !important;
    text-align: center !important;
    cursor: pointer !important;
    z-index: 999 !important;
    display: none !important;
    font-family: sans-serif !important;
    box-shadow: 0 0 10px rgba(0,255,102,0.8) !important;
}

.editing .gs-del,
.editing .gs-settings {
    display: block !important;
}

/* Оверлей для iframe в режиме редактирования (чтобы не перехватывали drag) */
.edit-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    background: rgba(0,0,0,0.1);
    cursor: move;
}

/* GridStack styles */
.grid-stack {
    background: var(--dashboard-bg, #0a020f) !important;
}
.grid-stack-item {
    background: transparent;
    border-radius: 6px;
    overflow: visible;
}
.grid-stack-item-content {
    background: transparent !important;
    border: none;
}
.dashboard-widget-content > div {
    width: 100%;
    height: 100%;
    min-height: 0;
    box-sizing: border-box;
}
.grid-stack-placeholder {
    background: rgba(255,0,255,0.15) !important;
    border: 2px dashed #ff00ff !important;
    border-radius: 8px !important;
}

/* Floating Action Buttons (правый верхний угол) */
.fab-btn {
    width: 34px;
    height: 34px;
    border: 2px solid #fff;
    border-radius: 50%;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 8px rgba(255,0,255,0.6);
    transition: all 0.15s;
    font-family: 'Press Start 2P', monospace;
    line-height: 1;
    padding: 0;
    z-index: 99991;
}
.fab-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 16px rgba(255,0,255,1);
    border-color: #ff00ff;
}

/* Theme customizer panel */
.theme-customizer-panel input[type="range"] {
    accent-color: #ff00ff;
}

/* Settings modal */
.widget-settings-modal input:focus,
.widget-settings-modal select:focus {
    outline: none;
    border-color: #fff !important;
    box-shadow: 0 0 10px #ff00ff !important;
}

/* ==========================================
   ЭКСТРЕМАЛЬНОЕ СЖАТИЕ ВИДЖЕТОВ (minW/minH=1)
   ========================================== */

/* Предотвращаем выпадение контента за границы при сильном сжатии */
.grid-stack-item-content > div,
.grid-stack-item-content > div > div,
.dashboard-widget-content > div,
.dashboard-widget-content {
    min-width: 0 !important;
    min-height: 0 !important;
}

/* Виджеты с select — обрезаем текст опций, если не влезает */
.dashboard-widget-content select {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    text-overflow: ellipsis;
}

/* Лобби: кнопки и текст не ломают сетку при сильном сжатии */
#lobby-widget-body button {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#lobby-room-list > div {
    overflow: hidden;
}

#lobby-room-list > div > div {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

#lobby-status {
    overflow: hidden;
}

/* Виджеты-кнопки (steal_save, customizer, lobby_page) — текст не вылезает */
.grid-stack-item-content button {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Ranking: строки не разрывают layout */
.dashboard-widget-content > div > div {
    word-break: break-word;
    overflow: hidden;
}

/* Виджет чата — сообщения не ломают layout */
.chat-messages div {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Game loader — drop zone адаптируется под размер */
#game-loader-input + div + div {
    min-height: 30px !important;
    padding: 4px !important;
    font-size: 6px !important;
}
