:root {
    --bg-color: #0b0f19;
    --panel-bg: #151d30;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --buzz-red: #ef4444;
    --buzz-green: #22c55e;
    --text-main: #ffffff;
    --text-sub: #94a3b8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    user-select: none;
    /* Предотвратява маркиране на текст при бързо кликане */
}

body {
    background-color: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* Фиксиран 16:9 контейнер, който скалира спрямо прозореца */
#app-viewport {
    width: 100vw;
    height: 56.25vw;
    /* 16:9 съотношение */
    max-height: 100vh;
    max-width: 177.78vh;
    /* 16:9 съотношение */
    background-color: var(--bg-color);
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
}

/* Навигация (Скрита по подразбиране, вижда се само при задържане най-горе) */
#navigation {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: rgba(15, 23, 42, 0.95);
    padding: 10px;
    display: flex;
    justify-content: center;
    gap: 15px;
    transform: translateY(-90%);
    transition: transform 0.3s ease;
}

#navigation:hover {
    transform: translateY(0);
}

#navigation button {
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    background: #1e293b;
    color: #fff;
    border: 1px solid #334155;
    border-radius: 6px;
}

/* Екрани */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    padding: 2vh 4vw;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* ИГРОВ ЕКРАН (16:9 Структура) */
#game-screen {
    justify-content: space-between;
    align-items: center;
}

.brand-header {
    font-size: 4vh;
    font-weight: 900;
    letter-spacing: 2px;
    color: #fff;
    text-transform: uppercase;
    text-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
    margin-top: 1vh;
}

/* Основна зона: Таймер + Бузер | Въпрос + Отговори */
.game-layout {
    display: flex;
    width: 100%;
    height: 70%;
    gap: 3vw;
    align-items: center;
}

/* Лява колона: Кръгъл таймер и визуален бузер */
.left-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    background: var(--panel-bg);
    border-radius: 20px;
    border: 1px solid #1e293b;
    padding: 2vh;
}

/* Кръгъл таймер */
#timer-container {
    position: relative;
    width: 18vh;
    height: 18vh;
    margin-bottom: 2vh;
}

.timer-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.timer-bg {
    fill: none;
    stroke: #1e293b;
    stroke-width: 8;
}

.timer-stroke {
    fill: none;
    stroke: var(--accent-color);
    stroke-width: 8;
    stroke-dasharray: 264;
    stroke-dashoffset: 0;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s linear, stroke 0.3s ease;
}

#timer-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 6vh;
    font-weight: 800;
    color: #ffffff;
}

/* Индикатор на физическия бузер */
#buzz-indicator {
    width: 14vh;
    height: 14vh;
    border-radius: 50%;
    background: #0f172a;
    border: 0.5vh solid #334155;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.buzzer-cap {
    width: 10vh;
    height: 10vh;
    border-radius: 50%;
    background: var(--buzz-red);
    color: white;
    font-weight: 900;
    font-size: 2.2vh;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 -0.5vh 0 rgba(0, 0, 0, 0.3);
}

#buzz-indicator.ready {
    border-color: #f59e0b;
    box-shadow: 0 0 30px rgba(245, 158, 11, 0.3);
}

#buzz-indicator.ready .buzzer-cap {
    animation: pulse 1.2s infinite;
}

#buzz-indicator.pressed {
    transform: scale(0.92);
    border-color: var(--buzz-green);
    box-shadow: 0 0 40px rgba(34, 197, 94, 0.6);
}

#buzz-indicator.pressed .buzzer-cap {
    background: var(--buzz-green);
}

#buzz-indicator.disabled .buzzer-cap {
    background: #475569;
    color: #94a3b8;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

/* Дясна колона: Въпрос и Бутони за отговор */
.right-panel {
    flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
}

#question-box {
    background: var(--panel-bg);
    padding: 3vh 2vw;
    border-radius: 16px;
    border: 1px solid #1e293b;
    min-height: 18vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

#question-text {
    font-size: 3vh;
    font-weight: 600;
    line-height: 1.3;
    color: #fff;
    text-align: center;
}

/* Опции за отговор */
#options-container {
    display: flex;
    flex-direction: column;
    gap: 1.5vh;
}

.opt-btn {
    width: 100%;
    padding: 2vh 2vw;
    font-size: 2.4vh;
    font-weight: 600;
    border-radius: 12px;
    text-align: left;
    transition: all 0.2s ease;
}

.opt-btn:disabled {
    background: var(--panel-bg);
    color: #475569;
    border: 2px solid #1e293b;
    cursor: not-allowed;
}

.opt-btn:not(:disabled) {
    background: var(--accent-color);
    color: #ffffff;
    border: 2px solid #60a5fa;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.opt-btn:not(:disabled):hover {
    background: var(--accent-hover);
    transform: translateX(5px);
}

/* Долен панел за статус и бутон за следващ въпрос */
.bottom-bar {
    height: 10%;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1vw;
}

#status-msg {
    font-size: 2.5vh;
    font-weight: 600;
    color: var(--text-sub);
}

#next-btn {
    background: var(--buzz-green);
    color: white;
    border: none;
    padding: 1.5vh 3vw;
    font-size: 2.2vh;
    font-weight: 700;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.4);
}

/* РЕДАКТОР ЕКРАН */
#editor-screen {
    overflow-y: auto;
    color: #fff;
}

#editor-screen h2 {
    font-size: 3vh;
    margin-bottom: 2vh;
}

#question-form input,
#question-form select {
    display: block;
    width: 100%;
    padding: 1.2vh;
    margin: 1vh 0;
    background: #1e293b;
    border: 1px solid #334155;
    color: white;
    border-radius: 6px;
    font-size: 1.8vh;
}

#question-form button {
    width: 100%;
    padding: 1.5vh;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 2vh;
    cursor: pointer;
}

#questions-list {
    max-height: 25vh;
    overflow-y: auto;
    margin: 2vh 0;
    text-align: left;
}

.q-item {
    background: #1e293b;
    padding: 1vh 1vw;
    margin-bottom: 1vh;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.q-item button {
    background: var(--buzz-red);
    color: white;
    border: none;
    padding: 0.5vh 1vw;
    border-radius: 4px;
    cursor: pointer;
}

.json-actions {
    display: flex;
    gap: 1vw;
}

.json-actions button {
    flex: 1;
    padding: 1.5vh;
    background: #0d9488;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.8vh;
}

.hidden {
    display: none !important;
}

/* Модален прозорец за тъчскрийн избор на играч */
#player-selector-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.modal-content {
    background: var(--panel-bg);
    padding: 4vh 3vw;
    border-radius: 20px;
    border: 2px solid var(--accent-color);
    text-align: center;
}

.modal-content h3 {
    font-size: 3vh;
    margin-bottom: 3vh;
    color: #fff;
}

.player-btns {
    display: flex;
    gap: 2vw;
}

.p-btn {
    padding: 2.5vh 3vw;
    font-size: 2.5vh;
    font-weight: 800;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    transition: transform 0.1s;
}

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

.p-btn.p1 {
    background: #3b82f6;
    color: white;
}

/* Ляв играч */
.p-btn.p2 {
    background: #ec4899;
    color: white;
}

/* Десен играч */

/* Показване кой играч отговаря в момента на екрана */
.active-player-badge {
    display: inline-block;
    padding: 0.5vh 1.5vw;
    border-radius: 20px;
    font-size: 2vh;
    font-weight: bold;
    margin-bottom: 1vh;
}

.badge-p1 {
    background: #3b82f6;
    color: white;
}

.badge-p2 {
    background: #ec4899;
    color: white;
}

/* Панел за резултат горе */
.score-board {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0 2vw;
    margin-top: 1vh;
}

.score-box {
    background: var(--panel-bg);
    border: 2px solid #1e293b;
    border-radius: 12px;
    padding: 1vh 2vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 12vw;
}

.score-box span {
    font-size: 1.8vh;
    font-weight: 700;
    color: var(--text-sub);
}

.score-box strong {
    font-size: 4vh;
    font-weight: 900;
    color: #fff;
}

.p1-score {
    border-color: #3b82f6;
}

.p1-score strong {
    color: #60a5fa;
}

.p2-score {
    border-color: #ec4899;
}

.p2-score strong {
    color: #f472b6;
}

/* Побединен Екран (Match Winner) */
#winner-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(11, 15, 25, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.3s ease-in-out;
}

.winner-content {
    background: var(--panel-bg);
    border: 3px solid #22c55e;
    border-radius: 24px;
    padding: 5vh 5vw;
    text-align: center;
    box-shadow: 0 0 50px rgba(34, 197, 94, 0.4);
}

.trophy-icon {
    font-size: 10vh;
    margin-bottom: 2vh;
}

#winner-title {
    font-size: 5vh;
    font-weight: 900;
    color: #fff;
    margin-bottom: 1vh;
}

#winner-score-text {
    font-size: 3vh;
    color: var(--text-sub);
    margin-bottom: 4vh;
}

#restart-game-btn {
    background: #22c55e;
    color: white;
    border: none;
    padding: 2vh 4vw;
    font-size: 2.8vh;
    font-weight: 800;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.5);
    transition: transform 0.2s;
}

#restart-game-btn:hover {
    transform: scale(1.05);
}