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

body {
    font-family: Arial, sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    height: 100vh;
    overflow: hidden;
    user-select: none;
    --mc-h: 0px;
}

#game-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 55px);
    padding: 20px;
}

/* Вопрос */
#question-area {
    text-align: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    margin-bottom: 20px;
}

#question-text {
    font-size: 36px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

/* Регулярные раунды */
#regular-game-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Верх: имена команд + текущие очки */
#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    margin-bottom: 20px;
}

.team-name {
    font-size: 30px;
    min-width: 250px;
    text-align: center;
}

.team-name.active {
    font-weight: bold;
    text-decoration: underline;
    color: #ffcc00;
}

/* LCD дисплей */
.lcd-display {
    background: #000;
    color: #0f0;
    font-family: 'Courier New', monospace;
    font-size: 48px;
    padding: 10px 20px;
    border: 2px solid #333;
    text-align: center;
    min-width: 150px;
    box-shadow: inset 0 0 10px rgba(0, 255, 0, 0.3);
    border-radius: 5px;
}

/* Низ: команды + ответы */
#bottom-area {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    flex: 1;
}

.team-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: 10px;
    min-width: 200px;
}

.round-icon {
    max-width: 150px;
    max-height: 100px;
}

.bad-marks {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.x-mark {
    width: 60px;
    height: 60px;
}

/* Ответы */
#answers-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    min-height: 0;
}

.answer-slot {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
}

.answer-flip {
    perspective: 1000px;
    width: 100%;
    height: 100%;
    min-height: 52px;
}

.answer-flip-inner {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 52px;
    transition: transform 0.7s cubic-bezier(0.4, 0.2, 0.2, 1);
    transform-style: preserve-3d;
}

.answer-flip-inner.is-flipped {
    transform: rotateY(180deg);
}

.answer-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    overflow: hidden;
}

.answer-face-front {
    background: #152238;
}

.answer-face-back {
    transform: rotateY(180deg);
    background: repeating-linear-gradient(
        90deg,
        #f0c020 0px,
        #f0c020 14px,
        #e8a810 14px,
        #e8a810 28px
    );
}

.answer-slot-num {
    position: absolute;
    font-size: clamp(26px, 4.5vw, 42px);
    font-weight: 900;
    color: #1a1a1a;
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.35);
    z-index: 2;
    pointer-events: none;
}

.answer-bg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 5px;
}

.answer-face-back .answer-text {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    max-width: 70%;
    font-size: clamp(13px, 2vw, 22px);
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.85);
    font-weight: bold;
    text-align: center;
    white-space: normal;
    line-height: 1.15;
}

.answer-face-back .answer-points {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: clamp(20px, 3.2vw, 34px);
    font-weight: bold;
    color: #fff700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.6);
}

.answer-text.revealed {
    animation: revealAnswerFlip 0.45s ease-out;
}

@keyframes revealAnswerFlip {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.92);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* Супер игра */
#super-game-grid {
    display: flex;
    gap: 40px;
    justify-content: center;
    flex: 1;
    padding: 20px;
}

.player-column {
    flex: 1;
    max-width: 550px;
    display: flex;
    flex-direction: column;
    background: rgba(42, 82, 152, 0.6);
    padding: 20px;
    border-radius: 10px;
}

.player-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}

.row-num {
    font-size: 20px;
    font-weight: bold;
    min-width: 30px;
}

.answer-input {
    flex: 1;
    padding: 10px;
    font-size: 24px;
    border: none;
    border-radius: 5px;
}

.points-input {
    width: 80px;
    padding: 10px;
    font-size: 24px;
    border: none;
    border-radius: 5px;
}

.sum-row {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid rgba(255, 255, 255, 0.3);
    display: flex;
    gap: 10px;
    align-items: center;
}

.sum-row span {
    font-size: 20px;
    font-weight: bold;
    min-width: 80px;
}

.sum-display {
    flex: 1;
    padding: 10px;
    font-size: 24px;
    font-weight: bold;
    text-align: center;
    background: #000;
    color: #0f0;
    border: 2px solid #333;
    border-radius: 5px;
}

#super-game-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 20px;
}

#super-game-controls button {
    padding: 15px 30px;
    font-size: 18px;
    font-weight: bold;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    transition: all 0.3s;
}

#super-game-controls button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

/* Таймер */
#timer-widget {
    position: fixed;
    top: 10px;
    right: 12px;
    left: auto;
    bottom: auto;
    transform: none;

    display: none;
    align-items: center;
    gap: 10px;

    background: rgba(0, 0, 0, 0.82);
    border: 2px solid rgba(255, 204, 0, 0.85);
    border-radius: 12px;
    padding: 8px 14px;

    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
    z-index: 6000;
}

.timer-icon {
    width: 36px;
    height: 36px;
}

#timer-seconds {
    font-size: 22px;
    font-weight: bold;
    color: #ffcc00;
    text-shadow: 0 0 8px rgba(255, 204, 0, 0.6);
    min-width: 4.5ch;
}

/* Help overlay */
#help-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

#help-content {
    background: rgba(255, 255, 255, 0.1);
    padding: 40px 50px;
    border-radius: 20px;
    max-width: 1100px;
    max-height: 85vh;
    overflow-y: auto;
}

#help-content h3 {
    grid-column: 1 / -1;  /* Заголовки на всю ширину */
    margin: 15px 0 10px 0;
    font-size: 22px;
    color: #ffcc00;
    border-bottom: 1px solid rgba(255, 204, 0, 0.3);
    padding-bottom: 5px;
}

#help-content .help-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;  /* 2 колонки */
    gap: 12px 30px;
    margin-bottom: 20px;
}

#help-content .help-item {
    display: flex;
    align-items: baseline;
    font-size: 18px;
    line-height: 1.6;
}

#help-content .help-key {
    background: rgba(255, 255, 255, 0.15);
    padding: 3px 10px;
    border-radius: 4px;
    margin-right: 10px;
    font-family: monospace;
    font-weight: bold;
    min-width: 60px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

#help-content .help-desc {
    flex: 1;
    color: rgba(255, 255, 255, 0.9);
}

#help-content .help-status {
    grid-column: 1 / -1;  /* Статус на всю ширину */
    margin-top: 10px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 17px;
    line-height: 1.7;
}

/* Settings modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    overflow-y: auto;
}

.modal-content {
    background: rgba(30, 60, 114, 0.95);
    padding: 40px;
    border-radius: 20px;
    max-width: 900px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 14px;
    transition: all 0.3s;
}

.tab-btn.active {
    background: rgba(255, 255, 255, 0.4);
    font-weight: bold;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.tab-content label {
    display: block;
    margin: 15px 0;
    font-size: 16px;
}

.tab-content input[type="text"],
.tab-content input[type="number"] {
    width: 100%;
    padding: 10px;
    margin-top: 5px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
}

.tab-content input[type="checkbox"] {
    margin-right: 10px;
}

.answers-grid {
    display: grid;
    gap: 10px;
}

.answer-editor-row {
    display: grid;
    grid-template-columns: 1fr 100px;
    gap: 10px;
}

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

.modal-buttons button {
    padding: 15px 40px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s;
}

#settings-save {
    background: #51cf66;
    color: white;
}

#settings-cancel {
    background: #ff6b6b;
    color: white;
}

/* Панель управления для организатора */
#control-panel {
    position: fixed;
    bottom: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10000;
    opacity: 0.3;
    transition: opacity 0.3s;
}

#control-panel:hover {
    opacity: 1;
}

.control-btn {
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid #666;
    border-radius: 4px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.control-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    border-color: #ffcc00;
}

.control-btn:active {
    background: #ffcc00;
    color: black;
}

/* Контекстные подсказки внизу */
#hints-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 55px;
    background: rgba(0, 0, 0, 0.85);
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 12px;
}

body.ufa-tv-mode #hints-panel {
    display: none !important;
}

/* Встроено в страницу novoufa: вопрос показывается снаружи (уведомление) */
body.ufa-embed-mode #question-area,
body.ufa-embed-mode #ufa-host-banner {
    display: none !important;
}

body.ufa-tv-mode #mobile-controls {
    bottom: 8px;
}

/* Один клик — старт игры */
.ufa-start-overlay {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(5, 12, 28, 0.88);
    backdrop-filter: blur(4px);
}

.ufa-start-overlay[hidden] {
    display: none !important;
}

.ufa-start-card {
    text-align: center;
    padding: 28px 36px;
    border-radius: 16px;
    background: linear-gradient(165deg, rgba(40, 70, 130, 0.95), rgba(15, 25, 55, 0.98));
    border: 1px solid rgba(255, 204, 0, 0.35);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.ufa-start-brand {
    font-size: clamp(26px, 5vw, 40px);
    font-weight: 800;
    color: #ffe066;
    margin-bottom: 18px;
    letter-spacing: 0.04em;
}

.ufa-btn-ready {
    font-size: 18px;
    font-weight: 700;
    padding: 12px 36px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    background: linear-gradient(180deg, #ffd43b, #f08c00);
    color: #1a1303;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.ufa-btn-ready:disabled {
    opacity: 0.5;
    cursor: wait;
}

/* Реплика ведущего на табло */
.ufa-host-banner {
    max-width: 96%;
    margin: 0 auto 8px;
    padding: 8px 14px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 204, 0, 0.45);
    color: #fff8e0;
    font-size: clamp(13px, 1.6vw, 17px);
    line-height: 1.35;
    text-align: center;
}

.ufa-host-banner-label {
    color: #ffd43b;
    font-weight: 700;
    margin-right: 6px;
}

#ufa-board-footer {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    padding: 6px 0 2px;
}

.ufa-btn-start-board {
    font-size: clamp(16px, 2.2vw, 22px);
    font-weight: 800;
    padding: 10px 42px;
    border-radius: 999px;
    border: 2px solid rgba(255, 212, 59, 0.9);
    cursor: pointer;
    background: linear-gradient(180deg, #ffe066, #f59f00);
    color: #1a1303;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
    letter-spacing: 0.06em;
}

.ufa-btn-start-board:disabled {
    opacity: 0.45;
    cursor: wait;
}

.ufa-btn-start-board[hidden] {
    display: none !important;
}

/* Заставка раунда (1, 2, 3…) */
.ufa-round-overlay {
    position: fixed;
    inset: 0;
    z-index: 12500;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(5, 12, 28, 0.9);
    backdrop-filter: blur(5px);
}

.ufa-round-overlay[hidden] {
    display: none !important;
}

.ufa-round-card {
    text-align: center;
    padding: 24px 32px;
    max-width: min(92vw, 480px);
    border-radius: 16px;
    background: linear-gradient(165deg, rgba(40, 70, 130, 0.96), rgba(15, 25, 55, 0.98));
    border: 1px solid rgba(255, 204, 0, 0.4);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}

.ufa-round-intro-brand {
    font-size: 14px;
    color: #94a3b8;
    margin-bottom: 10px;
}

.ufa-round-intro-img {
    max-width: 120px;
    max-height: 80px;
    object-fit: contain;
    margin: 0 auto 12px;
    display: block;
}

.ufa-round-intro-title {
    font-size: clamp(22px, 4vw, 34px);
    font-weight: 800;
    color: #ffe066;
    margin-bottom: 8px;
}

.ufa-round-intro-sub {
    font-size: 15px;
    color: #e2e8f0;
    margin-bottom: 18px;
    line-height: 1.35;
}

/* Debug label to confirm updated HTML loaded */
#mc-debug {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 30000;
    font-family: monospace;
    font-size: 12px;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(0,0,0,0.55);
    border: 1px solid rgba(255,255,255,0.18);
    color: rgba(255,255,255,0.9);
    pointer-events: none;
}

/* Mobile touch controls */
#mobile-controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 55px;
    z-index: 20000;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(6px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: none;
    pointer-events: auto;
    touch-action: manipulation;
}

#mobile-controls .mc-header {
    justify-content: flex-end;
}

.mc-btn.mc-ghost {
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(0, 0, 0, 0.18);
    font-weight: 700;
}

body.mc-collapsed #mobile-controls .mc-row:not(.mc-header) {
    display: none;
}

body.mc-collapsed #mobile-controls {
    padding: 6px 10px;
}

#mobile-controls .mc-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

#mobile-controls .mc-row:last-child {
    margin-bottom: 0;
}

.mc-btn {
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(0, 0, 0, 0.35);
    color: white;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: bold;
    min-width: 44px;
    cursor: pointer;
    touch-action: manipulation;
}

.mc-btn:active {
    transform: scale(0.98);
}

.mc-btn.mc-primary {
    border-color: rgba(255, 204, 0, 0.45);
    background: rgba(255, 204, 0, 0.18);
}

.mc-btn.mc-danger {
    border-color: rgba(255, 107, 107, 0.55);
    background: rgba(255, 107, 107, 0.18);
}

#hints-content {
    text-align: center;
    padding: 0 20px;
}

#hints-content kbd {
    background: rgba(255, 255, 255, 0.15);
    padding: 3px 8px;
    border-radius: 3px;
    margin: 0 2px;
    font-family: monospace;
    font-size: 11px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.tab-btn.disabled {
    background: rgba(255, 100, 100, 0.3);
    border: 1px solid rgba(255, 100, 100, 0.5);
}

.tab-btn.disabled:hover {
    background: rgba(255, 100, 100, 0.4);
}

.round-toggle {
    display: block;
    margin-bottom: 20px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
    font-weight: bold;
}

/* ============================================================================
   Mobile fit (phones)
   ============================================================================ */

@media (max-width: 520px) {
    #game-container {
        padding: 10px;
        height: calc(100vh - var(--mc-h, 52px));
    }

    #question-area {
        padding: 10px;
        margin-bottom: 10px;
    }

    #question-text {
        font-size: 18px;
        line-height: 1.15;
    }

    #top-bar {
        padding: 10px;
        margin-bottom: 10px;
        gap: 8px;
    }

    .team-name {
        font-size: 16px;
        min-width: 0;
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .lcd-display {
        font-size: 26px;
        padding: 6px 10px;
        min-width: 90px;
    }

    #bottom-area {
        gap: 10px;
    }

    .team-column {
        min-width: 110px;
        padding: 10px;
        gap: 10px;
    }

    .round-icon {
        max-width: 90px;
        max-height: 70px;
    }

    .x-mark {
        width: 34px;
        height: 34px;
    }

    #answers-column {
        padding: 10px;
        gap: 6px;
    }

    .answer-text {
        font-size: 14px;
        white-space: normal;
        text-align: center;
        padding: 0 44px;
    }

    .answer-points {
        right: 10px;
        font-size: 20px;
    }

    #control-panel {
        bottom: 6px;
        right: 6px;
        gap: 6px;
        opacity: 0.75;
    }

    .control-btn {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    #hints-panel {
        height: 46px;
        font-size: 11px;
    }

    #mobile-controls {
        display: block;
        bottom: 46px;
    }

    body {
        --mc-h: 120px;
    }

    body.mc-collapsed {
        --mc-h: 40px;
    }

    #mobile-controls .mc-row {
        margin-bottom: 6px;
    }
}

@media (max-width: 380px) {
    #question-text {
        font-size: 16px;
    }

    .lcd-display {
        font-size: 22px;
        min-width: 80px;
    }

    .team-column {
        min-width: 98px;
        padding: 8px;
    }

    .answer-text {
        font-size: 13px;
        padding: 0 38px;
    }

    .answer-points {
        font-size: 18px;
    }
}