/* ===== Grundlegendes Layout ===== */

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

html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(160deg, #F7F3EE 0%, #EDE8E0 50%, #E8E0D4 100%);
    color: #3A3226;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.app {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 16px 16px 24px;
    gap: 10px;
    max-width: 1200px;
    margin: 0 auto;
}


/* ===== Kopfbereich ===== */

.header {
    text-align: center;
}

.title {
    font-size: clamp(28px, 4vw, 44px);
    font-weight: 700;
    color: #4A3E2E;
    letter-spacing: 0.5px;
}

.subtitle {
    font-size: clamp(16px, 2.2vw, 22px);
    color: #6B5F4F;
    font-weight: 400;
    margin-top: 2px;
}


/* ===== Einstellungsleiste ===== */

.settings {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px 24px;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.55);
    border-radius: 14px;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.6);
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.setting-label {
    font-size: 15px;
    font-weight: 600;
    color: #5A4E3E;
}

/* Stepper (Plus/Minus) */
.stepper {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #fff;
    border-radius: 10px;
    padding: 3px;
    border: 1px solid #D5CFC5;
}

.stepper-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: #EDE8E0;
    color: #4A3E2E;
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
}

.stepper-btn:hover {
    background: #DDD6CA;
}

.stepper-btn:active {
    transform: scale(0.92);
}

.stepper-value {
    width: 36px;
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    color: #4A3E2E;
}

/* Toggle-Schalter */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    color: #5A4E3E;
}

.toggle-track {
    width: 44px;
    height: 26px;
    border-radius: 13px;
    background: #CBC4B8;
    position: relative;
    transition: background 0.25s ease;
    flex-shrink: 0;
}

.toggle-track.active {
    background: #7BB89F;
}

.toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: transform 0.25s ease;
}

.toggle-track.active .toggle-thumb {
    transform: translateX(18px);
}

.score-item {
    gap: 4px;
}

.score-value {
    font-size: 20px;
    font-weight: 700;
    color: #5BA87A;
    min-width: 24px;
    text-align: center;
}

.btn-small {
    padding: 6px 14px;
    border: 1px solid #D5CFC5;
    border-radius: 8px;
    background: #fff;
    color: #5A4E3E;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.btn-small:hover {
    background: #EDE8E0;
}

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


/* ===== Schüttelbox ===== */

.box-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 180px;
    padding: 8px 0;
}

.box-wrapper {
    /* Shake-Animation greift hier an */
}

.box-wrapper.shaking {
    animation: shake 0.7s ease-in-out;
}

.box {
    position: relative;
    width: clamp(420px, 72vw, 800px);
    height: clamp(190px, 28vh, 320px);
    /* Äußerer Rand = Schachtelkante */
    border-radius: 18px;
}

/* Innenfach / Boden */
.box-tray {
    position: absolute;
    inset: 0;
    display: flex;
    border-radius: 16px;
    overflow: hidden;
    /* Holz-/Kartonoptik */
    background: linear-gradient(180deg, #D8CCAE 0%, #CBBF9F 100%);
    box-shadow:
        inset 0 2px 6px rgba(0,0,0,0.12),
        0 2px 10px rgba(0,0,0,0.1);
    border: 3px solid #A89878;
}

.compartment {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    /* Leicht eingedrückte Innenfläche */
    background: linear-gradient(180deg, #EDE4D0 0%, #E2D8C0 100%);
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.08);
}

.box-divider {
    width: 7px;
    flex-shrink: 0;
    background: linear-gradient(180deg, #A89878 0%, #96886A 100%);
    box-shadow:
        inset -1px 0 2px rgba(0,0,0,0.15),
        inset 1px 0 2px rgba(0,0,0,0.15),
        0 0 4px rgba(0,0,0,0.1);
}

/* Deckel / Schuber */
.box-lid {
    position: absolute;
    inset: -4px;
    border-radius: 20px;
    z-index: 10;
    /* Etwas dunklere Karton-/Holzoptik */
    background: linear-gradient(145deg, #8E7E5E 0%, #7E6E4E 40%, #6E5E3E 100%);
    box-shadow:
        0 6px 20px rgba(0,0,0,0.25),
        0 2px 6px rgba(0,0,0,0.15),
        inset 0 1px 0 rgba(255,255,255,0.12),
        inset 0 -1px 0 rgba(0,0,0,0.1);
    border: 2px solid #5E4E2E;
    transition: transform 0.7s cubic-bezier(0.4, 0, 0.15, 1),
                opacity 0.4s ease;
    overflow: hidden;
}

/* Dekorative Linie auf dem Deckel */
.box-lid::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 10%;
    right: 10%;
    height: 2px;
    background: rgba(255,255,255,0.08);
    border-radius: 1px;
    transform: translateY(-50%);
}

/* Fragezeichen auf dem Deckel */
.lid-q {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: clamp(36px, 5vw, 64px);
    font-weight: 700;
    color: rgba(255, 255, 255, 0.3);
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.lid-q-left {
    left: 25%;
    transform: translate(-50%, -50%);
}

.lid-q-right {
    left: 75%;
    transform: translate(-50%, -50%);
}

/* Deckel-Zustände */
.box-lid.state-closed {
    transform: translateX(0);
    opacity: 1;
}

.box-lid.state-half-left {
    /* Deckel schiebt sich nach rechts, linke Seite wird sichtbar */
    transform: translateX(52%);
    opacity: 1;
}

.box-lid.state-half-right {
    /* Deckel schiebt sich nach links, rechte Seite wird sichtbar */
    transform: translateX(-52%);
    opacity: 1;
}

.box-lid.state-open-right {
    transform: translateX(106%);
    opacity: 0;
}

.box-lid.state-open-left {
    transform: translateX(-106%);
    opacity: 0;
}


/* ===== Kugeln ===== */

.balls-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

/* Block-Container: zentriert als Ganzes, intern linksbündig */
.balls-block {
    display: inline-flex;
    flex-direction: column;
    gap: clamp(6px, 1.2vh, 12px);
    /* align-items: stretch (Standard) sorgt dafür, dass
       beide Reihen dieselbe Breite haben */
}

.ball-row {
    display: flex;
    /* Kein justify-content: center – linksbündig (flex-start) */
    gap: clamp(5px, 0.9vw, 12px);
}

.ball {
    width: clamp(30px, 4.2vw, 50px);
    height: clamp(30px, 4.2vw, 50px);
    border-radius: 50%;
    background: radial-gradient(circle at 36% 32%, #FF8D7E, #E8604C 48%, #C4382A 100%);
    box-shadow:
        inset 0 -3px 5px rgba(0,0,0,0.18),
        inset 0 2px 4px rgba(255,255,255,0.18),
        0 2px 5px rgba(0,0,0,0.18);
    flex-shrink: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Animation beim Erscheinen */
.ball.pop-in {
    animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}


/* ===== Info-Anzeige ===== */

.info {
    font-size: clamp(16px, 2vw, 21px);
    color: #6B5F4F;
    font-weight: 500;
    text-align: center;
    min-height: 28px;
    transition: opacity 0.3s ease;
}


/* ===== Antwortbereich ===== */

.answer-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
}

/* Ausgewählte Zahl */
.selected-display {
    font-size: clamp(26px, 3.5vw, 40px);
    font-weight: 700;
    color: #4A3E2E;
    background: #fff;
    border: 2px solid #D5CFC5;
    border-radius: 14px;
    width: clamp(60px, 8vw, 80px);
    height: clamp(48px, 6vh, 64px);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    transition: border-color 0.2s ease, color 0.2s ease;
}

.selected-display.has-value {
    border-color: #6B9FC5;
    color: #3A7AAF;
}

/* Zahlbuttons */
.number-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: clamp(6px, 1vw, 12px);
}

.num-btn {
    width: clamp(48px, 6.5vw, 72px);
    height: clamp(48px, 6.5vw, 72px);
    border-radius: 50%;
    border: 3px solid #A8C8E0;
    background: #fff;
    color: #3A7AAF;
    font-size: clamp(18px, 2.5vw, 28px);
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.num-btn:hover {
    background: #EBF3FA;
    border-color: #7BB5D5;
    transform: scale(1.06);
}

.num-btn:active {
    transform: scale(0.94);
}

.num-btn.selected {
    background: #5B9DC8;
    color: #fff;
    border-color: #4A88B0;
    box-shadow: 0 3px 10px rgba(91, 157, 200, 0.35);
}

.num-btn:disabled {
    opacity: 0.35;
    cursor: default;
    transform: none;
}

/* Aktionsbuttons */
.action-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.action-btn {
    padding: clamp(10px, 1.5vh, 16px) clamp(20px, 3vw, 36px);
    border: none;
    border-radius: 14px;
    font-size: clamp(16px, 2vw, 21px);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
    letter-spacing: 0.3px;
}

.action-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.action-btn:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
    box-shadow: none;
}

.btn-shake {
    background: linear-gradient(135deg, #D9A066, #C4884E);
    color: #fff;
}

.btn-shake:hover:not(:disabled) {
    background: linear-gradient(135deg, #CF9458, #B87C44);
    box-shadow: 0 4px 14px rgba(196, 136, 78, 0.35);
}

.btn-check {
    background: linear-gradient(135deg, #6BA8D0, #5592B8);
    color: #fff;
}

.btn-check:hover:not(:disabled) {
    background: linear-gradient(135deg, #5E9AC2, #4C86AC);
    box-shadow: 0 4px 14px rgba(91, 157, 200, 0.35);
}

.btn-solution {
    background: linear-gradient(135deg, #8BBFA6, #72A88D);
    color: #fff;
}

.btn-solution:hover:not(:disabled) {
    background: linear-gradient(135deg, #7DB598, #66A080);
    box-shadow: 0 4px 14px rgba(114, 168, 141, 0.35);
}


/* ===== Rückmeldung ===== */

.feedback {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(20px, 2.8vw, 30px);
    font-weight: 700;
    text-align: center;
    transition: opacity 0.3s ease;
    padding: 4px 20px;
    border-radius: 14px;
}

.feedback.correct {
    color: #3E8F5E;
    background: rgba(91, 168, 122, 0.12);
    animation: feedbackPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.feedback.wrong {
    color: #C07A3A;
    background: rgba(208, 150, 90, 0.12);
    animation: feedbackShake 0.4s ease;
}

.feedback.solution {
    color: #5592B8;
    background: rgba(91, 157, 200, 0.1);
}

@keyframes feedbackPop {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes feedbackShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}


/* ===== Shake-Animation ===== */

@keyframes shake {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    8%  { transform: translate(-7px, 2px) rotate(-1.8deg); }
    16% { transform: translate(7px, -2px) rotate(1.8deg); }
    24% { transform: translate(-6px, 1px) rotate(-1.4deg); }
    32% { transform: translate(6px, -1px) rotate(1.4deg); }
    40% { transform: translate(-5px, 2px) rotate(-1deg); }
    48% { transform: translate(5px, -2px) rotate(1deg); }
    56% { transform: translate(-4px, 1px) rotate(-0.6deg); }
    64% { transform: translate(4px, -1px) rotate(0.6deg); }
    72% { transform: translate(-2px, 0) rotate(-0.3deg); }
    80% { transform: translate(2px, 0) rotate(0.3deg); }
    90% { transform: translate(-1px, 0) rotate(0); }
}


/* ===== Responsive Anpassungen ===== */

@media (max-width: 600px) {
    .app {
        padding: 10px 8px 16px;
        gap: 8px;
    }

    .settings {
        gap: 8px 16px;
        padding: 8px 14px;
    }

    .box {
        width: 95vw;
        height: clamp(160px, 32vh, 260px);
    }
}

@media (min-height: 900px) {
    .app {
        gap: 14px;
    }

    .box-area {
        min-height: 240px;
    }
}

/* Große Displays / Smartboard */
@media (min-width: 1400px) {
    .app {
        gap: 16px;
    }

    .title {
        font-size: 48px;
    }

    .subtitle {
        font-size: 24px;
    }

    .ball {
        width: 54px;
        height: 54px;
    }

    .num-btn {
        width: 78px;
        height: 78px;
        font-size: 30px;
    }

    .action-btn {
        padding: 18px 42px;
        font-size: 23px;
    }
}
