* { box-sizing: border-box; }

body {
    margin: 0; 
    width: 100vw;
    height: 100dvh;
    background: linear-gradient(135deg, #fceade 0%, #e3f2fd 100%);
    font-family: 'Comic Sans MS', Arial, sans-serif; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    flex-direction: column; 
    padding: 0;
    user-select: none;
    overflow: hidden;
    touch-action: manipulation;
}

/* 🌟 WELKOMSTSCHERM */
.welcome-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #fceade 0%, #e3f2fd 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    padding: 16px;
}
.welcome-card {
    background: white;
    padding: clamp(24px, 5vw, 40px);
    border-radius: 32px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.15);
    border: 6px solid #ffeaa7;
    width: min(450px, 92vw);
    text-align: center;
}
.welcome-emoji { font-size: clamp(54px, 12vw, 80px); margin-bottom: 10px; }
.welcome-title { font-size: clamp(32px, 8vw, 48px); color: #ff6b6b; margin: 0 0 20px 0; }
.welcome-start-btn {
    font-family: inherit;
    font-size: clamp(22px, 5vw, 28px);
    font-weight: bold;
    color: white;
    background: #27ae60;
    border: none;
    padding: 15px 36px;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 8px 0 #219653;
    transition: transform 0.1s;
}
.welcome-start-btn:active { transform: scale(0.95); }

/* 📐 DESKTOP & TABLET VIEWPORT SCALER */
.game-container-outer {
    width: 100vw;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

#scaler-wrapper {
    width: 900px;
    height: 1020px;
    transform-origin: center center;
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.game { 
    width: 850px; 
    min-height: 940px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: center; 
    background: #ffffff; 
    padding: 32px; 
    border-radius: 28px; 
    box-shadow: 0 12px 40px rgba(0,0,0,.15); 
    position: relative; 
    overflow: hidden; 
    border: 4px solid #fff; 
}

/* 📢 BOVENBALK MET INSTRUCTIE EN INSTELLINGEN */
.top-bar {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 18px;
    width: 100%;
}

.instructie-balk {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    flex: 1;
    padding: 14px;
    background: #f8fafc;
    border-radius: 18px;
    border: 2px dashed #cbd5e1;
    min-height: 70px;
}

.instructie-tekst {
    font-size: 21px;
    font-weight: bold;
    color: #2c3e50;
    text-align: left;
    flex-grow: 1;
    line-height: 1.35;
}

.speaker-btn {
    background: #e8f1ff;
    border: 2px solid #b4d3fe;
    border-radius: 50%;
    width: 52px;
    height: 52px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 0 #b4d3fe;
    transition: transform 0.1s;
    flex-shrink: 0;
}

.hidden-return-btn { 
    width: 46px; 
    height: 46px; 
    background-color: #f1f5f9; 
    border: 2px solid #cbd5e1; 
    border-radius: 50%; 
    cursor: pointer; 
    z-index: 100; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    flex-shrink: 0;
}

/* 🖼️ INTRO SCHERM */
#intro-scherm {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.img-frame { width: 460px; height: 460px; max-width: 100%; margin: 0 auto 15px; border: 4px solid #ffeaa7; border-radius: 24px; padding: 15px; background: white; display: flex; justify-content: center; align-items: center; }
.img-frame img { width: 100%; height: 100%; object-fit: contain; }

#intro-woord { font-size: 54px; color: #ff6b6b; margin: 10px 0; letter-spacing: 2px; }
.bom-container { background: none; border: none; cursor: pointer; display: inline-block; animation: bounceBom 0.6s infinite alternate; }
.bom-emoji { font-size: 90px; display: inline-block; }
@keyframes bounceBom { from { transform: scale(1); } to { transform: scale(1.08); } }

/* 🧩 PUZZEL SCHERM */
#puzzel-scherm {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.puzzel-afbeelding-strook { display: flex; justify-content: center; gap: 0; width: fit-content; max-width: 100%; height: 280px; margin: 0 auto 22px; background: #f1f5f9; border-radius: 20px; overflow: hidden; box-shadow: 0 6px 20px rgba(0,0,0,0.06); }
.puzzel-stuk { height: 100%; width: 140px; background-repeat: no-repeat; background-position: center; background-size: auto 100%; border: none; margin: 0; padding: 0; filter: grayscale(100%); opacity: 0.20; transition: filter 0.3s, opacity 0.3s; }
.puzzel-stuk.revealed { filter: grayscale(0%); opacity: 1; }

.letter-landing-zone { display: flex; justify-content: center; gap: 15px; margin-bottom: 22px; background: #edf2f7; padding: 15px; border-radius: 20px; width: 100%; }
.slot { width: 75px; height: 75px; border: 3px dashed #cbd5e1; border-radius: 18px; background: #f1f5f9; display: flex; align-items: center; justify-content: center; position: relative; }
.slot.occupied { border-style: solid; background: #fff; }
.slot.correct-piece { border-color: #28a745; background-color: #e8f8f5; }
.slot.wrong-piece { border-color: #dc3545; background-color: #fff5f5; }

.chaos-zone { width: 100%; min-height: 140px; border: 3px dashed #cbd5e1; border-radius: 20px; background: #f8fafc; padding: 20px; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 15px; }
.letter-blok { 
    width: 65px; 
    height: 65px; 
    background: #ffffff; 
    border: 3px solid #2d3436; 
    border-radius: 16px; 
    font-size: 36px; 
    font-weight: bold; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    box-shadow: 0 5px 0 #2d3436; 
    cursor: grab; 
    touch-action: none; 
    -webkit-user-select: none;
    user-select: none;
}

/* 🛠 LEERKRACHTEN PANEEL */
.teacher-panel { width: min(840px, 94vw); max-height: 92dvh; overflow-y: auto; background: #2c3e50; color: white; padding: 20px; border-radius: 18px; text-align: left; }
.control-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 15px; }
.teacher-select { padding: 8px; font-size: 15px; border-radius: 6px; font-weight: bold; border: none; }
.teacher-panel input[type="text"] { padding: 8px; font-size: 16px; border-radius: 6px; border: none; font-weight: bold; max-width: 160px; }
.teacher-panel button.start-btn { background: #27ae60; color: white; border: none; padding: 10px 20px; font-size: 16px; font-weight: bold; border-radius: 6px; cursor: pointer; }
#sound-toggle { border: 0; border-radius: 8px; padding: 8px 14px; font: bold 14px Arial; background: #e8f1ff; color: #173a63; cursor: pointer; }
#sound-toggle.on { background: #d7f5dc; color: #1d6b2b; }
.volume-setting { font-size: 15px; color: #ecf0f1; display: flex; align-items: center; gap: 8px; }
.logbook-section { background: #34495e; padding: 12px; border-radius: 10px; margin-top: 15px; }
.table-scroll { overflow-x: auto; }
#log-table { width: 100%; border-collapse: collapse; background: #fff; color: #333; border-radius: 6px; overflow: hidden; font-size: 13px; min-width: 480px; }
#log-table th, #log-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #e2e8f0; }
#log-table th { background: #cbd5e1; font-weight: bold; }
.clear-log-btn { background: #e74c3c; color: white; border: none; padding: 6px 12px; font-size: 13px; border-radius: 4px; margin-top: 10px; cursor: pointer; }

.stats-counter-container { display: flex; justify-content: center; gap: 15px; margin-bottom: 18px; }
.score-display { font-size: 24px; font-weight: bold; color: #e67e22; background: #fef9e7; padding: 10px 24px; border-radius: 30px; border: 3px solid #f1c40f; }
.clicks-display { font-size: 24px; font-weight: bold; color: #475569; background: #f1f5f9; padding: 10px 24px; border-radius: 30px; border: 3px dashed #cbd5e1; }
#message { min-height: 30px; font-size: 24px; font-weight: bold; margin-bottom: 10px; }

@keyframes pulseSpeaker {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); background-color: #d7f5dc; border-color: #a3e2ab; }
    100% { transform: scale(1); }
}
.speaker-playing { animation: pulseSpeaker 0.8s infinite ease-in-out; }

/* =====================================================================
   📱 EIGEN AANGEPASTE SMARTPHONE LAY-OUT (SCHERMEN TOT 768PX BREED)
   ===================================================================== */
@media (max-width: 768px) {
    .game-container-outer {
        padding: 0;
        background: #ffffff;
    }

    #scaler-wrapper {
        position: static;
        width: 100%;
        height: 100%;
        transform: none !important;
    }

    .game {
        width: 100%;
        height: 100%;
        min-height: 0;
        padding: 12px 14px 16px;
        border-radius: 0;
        border: none;
        box-shadow: none;
        justify-content: space-between;
    }

    /* Compacte mobiele top-bar */
    .top-bar {
        align-items: center;
        gap: 8px;
        margin-bottom: 10px;
    }

    .instructie-balk {
        padding: 8px 10px;
        min-height: 52px;
        gap: 8px;
        border-radius: 14px;
    }

    .instructie-tekst {
        font-size: 13.5px;
        line-height: 1.25;
    }
    .instructie-tekst span {
        font-size: 11.5px !important;
    }

    .speaker-btn {
        width: 40px;
        height: 40px;
        box-shadow: 0 2px 0 #b4d3fe;
    }
    .speaker-btn svg {
        width: 20px;
        height: 20px;
    }

    .hidden-return-btn {
        width: 38px;
        height: 38px;
    }
    .hidden-return-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Mobiel Intro-scherm */
    #intro-scherm {
        justify-content: space-evenly;
        padding: 4px 0;
    }

    .img-frame {
        width: min(72vw, 34dvh);
        height: min(72vw, 34dvh);
        margin: 0 auto;
        padding: 10px;
        border-radius: 22px;
        border-width: 3px;
    }

    #intro-woord {
        font-size: clamp(36px, 11vw, 48px);
        margin: 6px 0;
    }

    .bom-container {
        padding: 6px;
    }
    .bom-emoji {
        font-size: clamp(64px, 16vw, 80px);
    }

    /* Mobiel Puzzel-scherm */
    #puzzel-scherm {
        justify-content: space-between;
        gap: 8px;
    }

    .puzzel-afbeelding-strook {
        width: 100%;
        height: clamp(110px, 22dvh, 175px);
        margin: 0 auto;
        border-radius: 16px;
    }

    .puzzel-stuk {
        flex: 1 1 0;
        width: auto;
        min-width: 0;
        background-size: 100% 100%;
    }

    .letter-landing-zone {
        gap: 6px;
        padding: 10px 8px;
        margin-bottom: 0;
        border-radius: 16px;
    }

    .slot {
        flex: 1 1 0;
        max-width: 64px;
        height: auto;
        aspect-ratio: 1 / 1;
        border-radius: 13px;
        border-width: 2.5px;
    }

    .stats-counter-container {
        gap: 8px;
        margin-bottom: 0;
    }

    .score-display,
    .clicks-display {
        font-size: 14px;
        padding: 6px 12px;
        border-width: 2px;
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #message {
        display: none;
    }

    .chaos-zone {
        min-height: 92px;
        padding: 12px 10px;
        gap: 10px;
        border-radius: 16px;
        border-width: 2.5px;
    }

    .letter-blok {
        width: 52px;
        height: 52px;
        font-size: 28px;
        border-radius: 13px;
        border-width: 2.5px;
        box-shadow: 0 4px 0 #2d3436;
    }

    .slot .letter-blok {
        width: 100%;
        height: 100%;
        font-size: 24px;
        box-shadow: none;
        border-width: 2px;
    }

    /* Leerkrachtenmenu op smartphone */
    .teacher-panel {
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        padding: 16px;
    }
    .control-row {
        flex-direction: column;
        align-items: stretch;
    }
    .teacher-panel input[type="text"],
    .teacher-select {
        width: 100%;
        max-width: none;
        margin-top: 4px;
    }
}