/* Kuldvillak — mängu loomise vaade (create.php)
   Pinnad/tekstid/äärised globaalsete teemamuutujate kaudu (--bg-*, --text-*, --border-*),
   rakenduse aktsent --kv-* tokenitega (DISAIN.md: tokenid kolmes kohas). */

/* ---------- Rakenduse tokenid ---------- */
:root {
    --kv-accent: #2643c9;
    --kv-accent-hover: #1e37a8;
    --kv-accent-text: #ffffff;
    --kv-accent-soft: rgba(38, 67, 201, 0.09);
    --kv-dur-fast: 150ms;
    --kv-ease: cubic-bezier(0.4, 0, 0.2, 1);
}
[data-theme="dark"] {
    --kv-accent: #93a5f2;
    --kv-accent-hover: #a7b6f5;
    --kv-accent-text: #161d3d;
    --kv-accent-soft: rgba(147, 165, 242, 0.14);
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --kv-accent: #93a5f2;
        --kv-accent-hover: #a7b6f5;
        --kv-accent-text: #161d3d;
        --kv-accent-soft: rgba(147, 165, 242, 0.14);
    }
}

/* ---------- Primaarne CTA (üks aktsent vaate kohta) ---------- */
.kv-btn-primary {
    background-color: var(--kv-accent);
    border-color: transparent;
    color: var(--kv-accent-text);
    font-weight: 600;
    border-radius: 8px;
    transition: background-color var(--kv-dur-fast) var(--kv-ease);
}
.kv-btn-primary:hover,
.kv-btn-primary:focus {
    background-color: var(--kv-accent-hover);
    border-color: transparent;
    color: var(--kv-accent-text);
}

/* ---------- Fookus (klaviatuur) ---------- */
#action-buttons-top .button:focus-visible,
.kv-btn-primary:focus-visible,
.media-dropdown .dropdown-item:focus-visible,
.answer-media-dropdown .dropdown-item:focus-visible,
.move-media-btn:focus-visible,
.preview-close-btn:focus-visible,
.preview-round-btn:focus-visible,
.preview-question-card:focus-visible {
    outline: 3px solid var(--kv-accent);
    outline-offset: 2px;
}

/* ---------- Redaktori tabel ---------- */
#jeopardy-table,
#double-table {
    border-collapse: collapse;
}

#jeopardy-table th,
#double-table th {
    padding: 0;
    border: 2px solid var(--border-color);
    background-color: var(--bg-secondary);
}

#jeopardy-table td,
#double-table td {
    padding: 0;
    vertical-align: top;
    border: 2px solid var(--border-color);
}

/* Esimene tulp (punktid) */
#jeopardy-table td:first-child,
#double-table td:first-child {
    background-color: var(--bg-secondary);
    padding: 8px;
}

#jeopardy-table th .input,
#double-table th .input {
    width: 100%;
    font-size: 0.875rem;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
}

#jeopardy-table td .textarea,
#double-table td .textarea {
    width: 100%;
    font-size: 0.875rem;
    resize: none;
    min-height: 38px;
    overflow: hidden;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 6px 8px;
    line-height: 1.4;
}

#jeopardy-table td .input,
#double-table td .input {
    width: 100%;
    font-size: 0.875rem;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

#jeopardy-table td .textarea:focus,
#double-table td .textarea:focus,
#jeopardy-table td .input:focus,
#double-table td .input:focus {
    box-shadow: inset 0 0 0 2px var(--kv-accent);
    outline: none;
}

/* Hõbevillaku checkbox kompaktsemaks */
#jeopardy-table td .checkbox,
#double-table td .checkbox {
    font-size: 0.75rem;
    display: block;
    padding: 4px;
}

.textarea {
    resize: none;
    min-height: 38px;
}

/* ---------- Hover-peidetavad juhtelemendid AINULT hover-võimekatel seadmetel.
   Puuteseadmel (hover puudub) on Meedia-nupp ja Hõbe-checkbox alati nähtavad. ---------- */
@media (hover: hover) {
    #jeopardy-table td .checkbox,
    #double-table td .checkbox {
        opacity: 0;
        transition: opacity var(--kv-dur-fast) var(--kv-ease);
    }
    #jeopardy-table td:hover .checkbox,
    #double-table td:hover .checkbox,
    #jeopardy-table td .checkbox:focus-within,
    #double-table td .checkbox:focus-within,
    #jeopardy-table td .checkbox:has(input:checked),
    #double-table td .checkbox:has(input:checked) {
        opacity: 1;
    }

    .question-extras-row .media-dropdown-container,
    .answer-media-field .media-dropdown-container {
        opacity: 0;
        transition: opacity var(--kv-dur-fast) var(--kv-ease);
    }
    .question-section:hover .media-dropdown-container,
    .question-extras-row .media-dropdown-container:focus-within,
    .answer-section:hover .answer-media-field .media-dropdown-container,
    .answer-media-field .media-dropdown-container:focus-within,
    .media-field:has(.media-preview-item) .media-dropdown-container,
    .answer-media-field:has(.media-preview-item) .media-dropdown-container {
        opacity: 1;
    }
}

/* ---------- Küsimuse/vastuse sektsioonid ---------- */
.question-extras-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.question-extras-row .media-field {
    flex: 1;
    margin: 0;
}

.question-extras-row .daily-double-label {
    white-space: nowrap;
    align-items: center;
}

.answer-section {
    margin-top: 4px;
}

.answer-row {
    display: flex;
    align-items: flex-start;
}

.answer-row .textarea {
    flex: 1;
    min-height: 32px;
    resize: none;
    overflow: hidden;
}

.answer-media-preview {
    margin-top: 4px;
    margin-bottom: 4px;
}

/* ---------- Meedia dropdown ---------- */
.media-field {
    margin-top: 6px;
}

.media-dropdown .dropdown-content,
.answer-media-dropdown .dropdown-content {
    padding: 8px 0;
    min-width: 160px;
    background-color: var(--bg-card);
}

.media-dropdown .dropdown-item,
.answer-media-dropdown .dropdown-item {
    padding: 8px 16px;
    font-size: 0.875rem;
    cursor: pointer;
    color: var(--text-primary);
}

.media-dropdown .dropdown-item:hover,
.answer-media-dropdown .dropdown-item:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.media-dropdown .dropdown-divider,
.answer-media-dropdown .dropdown-divider {
    background-color: var(--border-color);
}

.media-dropdown label.dropdown-item,
.answer-media-dropdown label.dropdown-item {
    display: block;
}

/* ---------- Meedia eelvaade lahtris ---------- */
.media-preview {
    margin-bottom: 8px;
}

.media-preview-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 6px;
}

.media-preview-item img {
    object-fit: cover;
}

/* Kustutamise rist puuteala miinimum (WCAG 2.2: ≥24px) */
.media-preview-item .delete {
    min-width: 24px;
    min-height: 24px;
}

.move-media-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    padding: 4px 6px;
    min-width: 28px;
    min-height: 28px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: background-color var(--kv-dur-fast) var(--kv-ease),
                color var(--kv-dur-fast) var(--kv-ease);
}
.move-media-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ---------- Meedia liigutamise režiim ---------- */
.media-move-source {
    outline: 3px solid var(--kv-accent);
    outline-offset: 2px;
    border-radius: 6px;
}

td.media-move-target {
    background: rgba(72, 199, 116, 0.1);
    cursor: pointer;
    transition: background var(--kv-dur-fast) var(--kv-ease);
}
td.media-move-target:hover {
    background: rgba(72, 199, 116, 0.25);
}
td.media-move-target textarea,
td.media-move-target input[type="text"] {
    background: transparent !important;
    pointer-events: none;
}

.media-move-choice-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    box-shadow: var(--shadow-hover);
}

/* ---------- Hõbevillaku tähis lahtris ---------- */
td:has(.daily-double-jeopardy:checked),
td:has(.daily-double-double:checked) {
    position: relative;
}
td:has(.daily-double-jeopardy:checked)::before,
td:has(.daily-double-double:checked)::before {
    content: '★';
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 0.875rem;
    color: #c0c0c0; /* hõbe — temaatiline */
    text-shadow: 0 0 2px rgba(0,0,0,0.3);
    z-index: 1;
    pointer-events: none;
    line-height: 1;
}

.media-input-group .buttons,
.media-input-group .button {
    margin-bottom: 0;
}

.media-input-group .button input[type="file"] {
    display: none;
}

/* Brauseri mängudele ei saa faile üles laadida — näita ainult URL/YouTube valikuid */
body.browser-owned-game label.media-option,
body.browser-owned-game label.dropdown-item.media-option {
    display: none !important;
}

/* ---------- Mängu eelvaate modaal.
   Mängulaud on teadlikult alati tume (Kuldvillaku bränd) — värvid fikseeritud,
   ei sõltu teemast. ---------- */
#preview-modal .modal-card {
    width: 95%;
    max-width: 1400px;
    height: 90vh;
    height: 90svh;
    position: relative;
}

#preview-modal .modal-card-head {
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    border-bottom: 2px solid #ffd700;
}

#preview-modal .modal-card-title {
    color: #fff;
}

#preview-modal .modal-card-body {
    background: linear-gradient(135deg, #0a0a1a 0%, #1a1a2e 50%, #0a0a1a 100%);
    padding: 20px;
}

.preview-game-board {
    background: transparent;
    padding: 16px;
    border-radius: 8px;
    min-height: 400px;
}

.preview-category-header {
    background: linear-gradient(180deg, #060CE9 0%, #040099 100%);
    color: #fff;
    padding: 16px 10px;
    text-align: center;
    font-weight: 700;
    font-size: 0.875rem;
    border-radius: 4px;
    text-transform: uppercase;
    border: 2px solid #000;
}

.preview-question-card {
    background: linear-gradient(180deg, #060CE9 0%, #040099 100%);
    color: #ffd700;
    padding: 20px 10px;
    text-align: center;
    font-weight: 700;
    font-size: 1.5rem;
    font-variant-numeric: tabular-nums;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid #000;
    transition: background var(--kv-dur-fast) var(--kv-ease),
                transform var(--kv-dur-fast) var(--kv-ease),
                box-shadow var(--kv-dur-fast) var(--kv-ease);
}

@media (hover: hover) {
    .preview-question-card:hover {
        background: linear-gradient(180deg, #0b12f5 0%, #060CE9 100%);
        transform: scale(1.02);
        box-shadow: 0 0 15px rgba(255,204,0,0.4);
    }
}

.preview-question-card.daily-double {
    box-shadow: 0 0 10px #ffd700;
}

.preview-question-card.empty {
    background: linear-gradient(180deg, #1a1a2e 0%, #0a0a1a 100%);
    opacity: 0.3;
    cursor: default;
    border-color: #333;
}

.preview-question-card.empty:hover {
    transform: none;
    background: linear-gradient(180deg, #1a1a2e 0%, #0a0a1a 100%);
    box-shadow: none;
}

/* Eelvaate tühi olek */
.preview-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 300px;
    color: #e4e4e7;
    text-align: center;
    padding: 24px;
}
.preview-empty .icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: rgba(255, 204, 0, 0.12);
    color: #ffd700;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.preview-empty-hint {
    font-size: 0.875rem;
    color: rgba(228, 228, 231, 0.7);
    max-width: 360px;
}

.preview-final-container {
    color: #fff;
}

.preview-final-container .box {
    background: linear-gradient(180deg, #060CE9 0%, #040099 100%);
    color: #fff;
    border: 2px solid #ffd700;
}

.preview-final-container .box .title {
    color: #fff !important;
}

.preview-final-container .box .has-text-success {
    color: #ffd700 !important;
}

/* Eelvaate sulgemise nupp */
.preview-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    font-size: 18px;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--kv-dur-fast) var(--kv-ease),
                box-shadow var(--kv-dur-fast) var(--kv-ease);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.preview-close-btn:hover {
    background: #fff;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* ---------- Küsimuse eelvaate modaal ---------- */
#preview-question-modal .modal-card-head {
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    border-bottom: 2px solid #ffd700;
}

#preview-question-modal .modal-card-title {
    color: #ffd700;
}

#preview-question-modal .modal-card-head .delete {
    background: rgba(255,255,255,0.3);
    min-width: 24px;
    min-height: 24px;
}

#preview-question-modal .modal-card-head .delete::before,
#preview-question-modal .modal-card-head .delete::after {
    background-color: #fff;
}

#preview-question-modal .modal-card-head .delete:hover {
    background: rgba(255,255,255,0.5);
}

#preview-question-modal .modal-card-body {
    background: linear-gradient(180deg, #060CE9 0%, #040099 100%);
    color: #fff;
    text-align: center;
    padding: 40px;
}

#preview-question-modal .modal-card-foot {
    background: #1a1a2e;
    border-top: none;
    justify-content: center;
}

#preview-question-text {
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    white-space: pre-line;
}

#preview-answer-text {
    color: #ffd700 !important;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    white-space: pre-line;
}

/* ---------- Liikumise vähendamine: liikumine kaob, tagasiside jääb ---------- */
@media (prefers-reduced-motion: reduce) {
    .kv-btn-primary,
    .preview-question-card,
    .preview-close-btn,
    .move-media-btn,
    td.media-move-target,
    .media-dropdown-container,
    #jeopardy-table td .checkbox,
    #double-table td .checkbox {
        transition: none;
    }
    .preview-question-card:hover,
    .preview-close-btn:hover {
        transform: none;
    }
}

/* ---------- Mobiil (kontrollitud ~360 px) ---------- */
@media screen and (max-width: 768px) {
    /* ≥16px font väldib iOS-i automaatset suumi fookusel */
    #jeopardy-table td .textarea,
    #double-table td .textarea,
    #jeopardy-table th .input,
    #double-table th .input {
        font-size: 16px;
    }

    /* Lahtrid püsivad kasutatava laiusega — tabel kerib horisontaalselt */
    #jeopardy-table th:not(:first-child),
    #double-table th:not(:first-child),
    #jeopardy-table td:not(:first-child),
    #double-table td:not(:first-child) {
        min-width: 200px;
    }

    /* Tegevusnupud murduvad reale */
    #action-buttons-top {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 8px;
    }
    #action-buttons-top .control {
        margin-right: 0;
    }

    #preview-modal .modal-card {
        width: 100%;
        height: 100vh;
        height: 100svh;
    }
    #preview-modal .modal-card-body,
    #preview-question-modal .modal-card-body {
        padding: 12px;
    }
}
