/* ========================================
   Petualang Kode - Styles
   ======================================== */

.cb-btn-small {
    padding: 8px 14px;
    font-size: 13px;
}

.cb-lang-toggle {
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px;
    margin-right: 10px;
}

.cb-lang-btn {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    padding: 5px 10px;
    border-radius: 999px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.cb-lang-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
}

.cb-workspace-actions--secondary {
    margin-top: 8px;
}

.cb-custom-panel {
    margin-top: 12px;
    background: rgba(0, 217, 255, 0.06);
    border: 1px solid rgba(0, 217, 255, 0.3);
    border-radius: 10px;
    padding: 12px;
}

.cb-upload-label {
    display: inline-block;
    cursor: pointer;
}

.cb-level-card--custom {
    border-style: dashed;
    border-color: var(--accent);
}


/* ---------- Layar Pilih Level ---------- */

.cb-level-select {
    width: 100%;
    padding: 40px 20px;
    display: flex;
    justify-content: center;
}

.cb-level-select-inner {
    width: 100%;
    max-width: 1000px;
    text-align: center;
}

.cb-level-grid {
    margin-top: 32px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 20px;
}

.cb-level-card {
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(131, 56, 236, 0.12) 100%);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 22px 18px;
    text-align: left;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.cb-level-card:hover:not(.cb-level-card--locked) {
    border-color: var(--accent);
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.cb-level-card--locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.cb-level-card--done {
    border-color: var(--success);
}

.cb-level-num {
    display: inline-block;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    font-weight: 800;
    font-size: 13px;
    padding: 4px 12px;
    border-radius: 999px;
    margin-bottom: 12px;
}

.cb-level-card-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.cb-level-card-sub {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 14px;
    min-height: 36px;
}

.cb-level-card-score {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.cb-level-card-score b {
    font-size: 18px;
    color: var(--text-primary);
}

.cb-level-card-score--done {
    color: #34d399;
}

.cb-level-lock-icon {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 22px;
}

/* ---------- Layar Bermain ---------- */

.cb-play-screen {
    width: 100%;
    padding: 16px 20px 30px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cb-stage-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
}

.cb-level-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-primary);
}

.cb-level-instruction {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
    max-width: 640px;
}

.cb-layout {
    display: flex;
    gap: 16px;
    align-items: stretch;
    flex-wrap: wrap;
}

.cb-panel-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* Panel Blockly */

.cb-toolbox-panel {
    flex: 1 1 380px;
    min-width: 320px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    display: flex;
    flex-direction: column;
}

.cb-blockly-div {
    width: 100%;
    height: 420px;
    border-radius: 10px;
    overflow: hidden;
    background: #1e2340;
    border: 1px solid var(--border-light);
}

.cb-workspace-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.cb-btn-run {
    flex: 1;
    font-size: 15px;
}

/* Panel Panggung / Grid */

.cb-stage-panel {
    flex: 1 1 420px;
    min-width: 320px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.cb-asset-palette {
    width: 100%;
    background: rgba(255, 190, 11, 0.08);
    border: 1px solid rgba(255, 190, 11, 0.35);
    border-radius: 10px;
    padding: 12px;
}

.cb-asset-list {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.cb-asset-chip {
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
}

.cb-asset-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

#cbPlaceModeBtn.cb-place-active {
    background: var(--warning);
    color: #1a1200;
    border-color: var(--warning);
}

.cb-grid-outer {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 6px;
}

.cb-3d-wrap {
    position: relative;
    width: 100%;
    height: 440px;
    border-radius: 14px;
    overflow: hidden;
    background: #181c34;
    border: 1px solid var(--border-light);
}

.cb-3d-wrap canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

.cb-speech-bubble {
    position: absolute;
    top: 14px;
    left: 14px;
    right: 14px;
    max-width: 320px;
    background: rgba(255, 255, 255, 0.96);
    color: #1a1a2e;
    border-radius: 14px;
    padding: 12px 14px;
    box-shadow: var(--shadow-md);
    pointer-events: none;
    z-index: 20;
}

.cb-speech-bubble::after {
    content: "";
    position: absolute;
    bottom: -8px;
    left: 24px;
    border-width: 8px 8px 0 0;
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.96) transparent transparent transparent;
}

.cb-speech-title {
    font-weight: 800;
    font-size: 13px;
    margin-bottom: 3px;
}

.cb-speech-message {
    font-size: 13px;
    line-height: 1.4;
}

.cb-hud-text {
    position: absolute;
    bottom: 14px;
    left: 14px;
    right: 14px;
    background: rgba(10, 12, 26, 0.82);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 10px 14px;
    z-index: 20;
    pointer-events: none;
}

.cb-hud-title {
    font-weight: 800;
    font-size: 14px;
    color: var(--text-primary);
}

.cb-hud-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.cb-hud-button {
    display: inline-block;
    margin-top: 6px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
}

.cb-prompt-modal {
    max-width: 420px;
}

.cb-prompt-input {
    width: 100%;
    margin-top: 6px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 2px solid var(--border-light);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 15px;
}

.cb-prompt-input:focus {
    outline: none;
    border-color: var(--accent);
}

.cb-prompt-submit {
    width: 100%;
    margin-top: 14px;
}

.cb-feedback {
    min-height: 22px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
}

.cb-feedback--fail {
    color: #ff8fa3;
}

.cb-feedback--info {
    color: var(--text-secondary);
}

/* ---------- Modal Kuis & Reward ---------- */

.cb-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 18, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.cb-modal-overlay.hidden {
    display: none;
}

.cb-modal {
    width: 100%;
    max-width: 480px;
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(131, 56, 236, 0.15) 100%);
    border: 2px solid var(--border-light);
    border-radius: 18px;
    padding: 28px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.cb-modal-badge {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 999px;
    margin-bottom: 14px;
}

.cb-quiz-question {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 18px;
    color: var(--text-primary);
}

.cb-quiz-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cb-quiz-option {
    background: var(--bg-input);
    border: 2px solid var(--border-light);
    color: var(--text-primary);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: var(--transition-fast);
}

.cb-quiz-option:hover {
    border-color: var(--accent);
}

.cb-quiz-option--correct {
    background: rgba(0, 255, 65, 0.18);
    border-color: var(--success);
}

.cb-quiz-option--wrong {
    background: rgba(255, 71, 87, 0.18);
    border-color: var(--error);
}

.cb-quiz-feedback {
    margin-top: 14px;
    font-size: 13px;
    font-weight: 600;
}

.cb-reward-emoji {
    font-size: 56px;
    margin-bottom: 6px;
}

.cb-reward-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--text-primary);
}

.cb-reward-score {
    margin: 8px 0 10px;
    line-height: 1;
}

.cb-reward-score-num {
    font-size: 56px;
    font-weight: 800;
    color: var(--text-primary);
}

.cb-reward-score-max {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-left: 6px;
}

.cb-reward-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 18px;
}

.cb-reward-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

@media (max-width: 720px) {
    .cb-layout {
        flex-direction: column;
    }
    .cb-blockly-div {
        height: 320px;
    }
    .cb-3d-wrap {
        height: 300px;
    }
}

/* ---------- Sumber soal (bawaan / Bank Soal) ---------- */

.cb-source-bar {
    display: flex;
    justify-content: center;
    margin: 8px 0 14px;
    min-width: 0;
}

.cb-source-bar--stage {
    justify-content: flex-end;
    margin: 0;
    max-width: 100%;
}

.cb-source-btn {
    display: inline-flex;
    align-items: center;
    max-width: min(100%, 460px);
    border: 1px solid var(--border-light);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
}

.cb-source-btn:hover,
.cb-source-btn:focus-visible {
    border-color: var(--accent);
    color: var(--text-primary);
    outline: none;
}

.cb-source-btn-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cb-source-modal {
    max-width: 540px;
    text-align: left;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.cb-source-title {
    font-size: 18px;
    font-weight: 800;
    margin: 0 0 12px;
    color: var(--text-primary);
}

.cb-source-opt {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 14px;
}

.cb-source-opt.is-selected {
    border-color: var(--accent);
    background: rgba(0, 217, 255, 0.08);
}

.cb-source-opt input {
    margin-top: 3px;
    accent-color: var(--accent);
}

.cb-source-opt small {
    display: block;
    margin-top: 2px;
    font-weight: 400;
    color: var(--text-secondary);
}

.cb-source-picker {
    margin: 4px 0 8px;
    transition: opacity 0.15s ease;
}

.cb-source-picker.is-off {
    opacity: 0.55;
}

.cb-source-status {
    min-height: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

.cb-source-status.is-warn {
    color: var(--warning);
}

.cb-source-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
    margin-top: 12px;
}

.cb-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    max-width: min(92vw, 560px);
    padding: 10px 16px;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    z-index: 150;            /* di bawah modal (200) supaya tidak menutupi kuis/tombol Lanjut */
    pointer-events: none;
}

/* Kuis: teks panjang boleh digulir dan dipatahkan, sumber soal tampil halus */
.cb-quiz-modal {
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.cb-quiz-source {
    font-size: 12px;
    color: var(--text-muted);
    margin: -4px 0 10px;
    overflow-wrap: anywhere;
}

.cb-quiz-question,
.cb-quiz-option,
.cb-quiz-feedback {
    overflow-wrap: anywhere;
}

.cb-quiz-question {
    white-space: pre-line;
}

.cb-quiz-next-wrap {
    margin-top: 10px;
}
