/* Mathtris */

/* ==========================================================================
   Startscreen: Optionen, Switches, Schwierigkeit-Auswahl, Buttons
   ========================================================================== */

/* Schwierigkeit-Auswahl (Dropdown) */
#mathtrisDifficulty {
    width: 100%;
    max-width: 16rem;
    margin-top: 0.35rem;
    padding: 0.55rem 2.5rem 0.55rem 0.85rem;
    border: 2px solid #8a7555;
    border-radius: 10px;
    background-color: #f8f2e8;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath fill='none' stroke='%235c4a32' stroke-width='2' d='M1 1l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.9rem center;
    color: #3d3428;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#mathtrisDifficulty:hover {
    border-color: #5c4a32;
}

#mathtrisDifficulty:focus {
    outline: none;
    border-color: #5c4a32;
    box-shadow: 0 0 0 3px rgba(92, 74, 50, 0.2);
}

/* Optionen-Block (fieldset) */
.mathtris-options {
    margin-top: 1.25rem;
    padding: 1rem 1.15rem 1.15rem;
    border: 2px solid #8a7555;
    border-radius: 14px;
    background: #f4ecdd;
}

.mathtris-options legend {
    padding: 0 0.5rem;
    font-size: 1.05rem;
    font-weight: 700;
    color: #5c4a32;
}

/* eine Options-Zeile: Text links, Switch rechts */
.start-main label.mathtris-switch-option,
.mathtris-options label.mathtris-switch-option,
.mathtris-switch-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0;
    padding: 0.6rem 0.75rem;
    border-radius: 10px;
    font-weight: 600;
    color: #3d3428;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.mathtris-switch-option:hover {
    background: #ece0cb;
}

/* echte Checkbox komplett aus dem sichtbaren Bereich schieben */
.mathtris-switch-option input[type="checkbox"] {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
    margin: 0;
    padding: 0;
    border: 0;
    pointer-events: none;
}

/* Switch-Bahn */
.mathtris-switch {
    position: relative;
    flex: 0 0 52px;
    flex-shrink: 0;
    width: 52px;
    min-width: 52px;
    height: 28px;
    border: 2px solid #c4c4c4;
    border-radius: 999px;
    background: #d3d3d3;
    transition: background 0.2s ease, border-color 0.2s ease;
}

/* Switch-Knopf */
.mathtris-switch::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease;
}

/* eingeschaltet */
.mathtris-switch-option input[type="checkbox"]:checked + .mathtris-switch {
    background: #3a6b3f;
    border-color: #285030;
}

.mathtris-switch-option input[type="checkbox"]:checked + .mathtris-switch::before {
    transform: translateX(24px);
}

/* Tastatur-Fokus sichtbar */
.mathtris-switch-option input[type="checkbox"]:focus-visible + .mathtris-switch {
    box-shadow: 0 0 0 3px rgba(92, 74, 50, 0.25);
}

/* Buttons (Start + Aktionen) */
.mathtris-action-button {
    margin-top: 1rem;
    padding: 0.6rem 1.25rem;
    border: 2px solid #5c4a32;
    border-radius: 12px;
    background: #f8f2e8;
    color: #3d3428;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 3px 0 rgba(92, 74, 50, 0.35);
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
}

.mathtris-action-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 0 rgba(92, 74, 50, 0.35);
}

.mathtris-action-button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 0 rgba(92, 74, 50, 0.35);
}

.mathtris-action-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 3px 0 rgba(92, 74, 50, 0.35);
}

/* farbige Varianten - gedeckte Toene, passend zum Design */
.mathtris-button-blue {
    background: #4f7cac;
    border-color: #3a5f86;
    color: #f8f2e8;
}

.mathtris-button-orange {
    background: #c9772f;
    border-color: #9a5a23;
    color: #f8f2e8;
}

.mathtris-button-red {
    background: #b3261e;
    border-color: #8a1c16;
    color: #f8f2e8;
}

.mathtris-button-green {
    background: #4c8a52;
    border-color: #3a6b3f;
    color: #f8f2e8;
}

/* Hover fuer farbige Buttons: Farbe behalten (leicht dunkler), nicht weiss werden */
.mathtris-button-blue:hover {
    background: #456d97;
    color: #f8f2e8;
}

.mathtris-button-orange:hover {
    background: #b06827;
    color: #f8f2e8;
}

.mathtris-button-red:hover {
    background: #9c211a;
    color: #f8f2e8;
}

.mathtris-button-green:hover {
    background: #427848;
    color: #f8f2e8;
}



/* Start-Button eigene Farbe (ueberschreibt die blaue Klasse gezielt) */
#buttonStartMathtris {
    background: #3a6b3f;
    border-color: #285030;
    color: #ffffff;
}

#buttonStartMathtris:hover {
    background: #325c37;
    color: #ffffff;
}

/* Pruefen-Button: bekommt die gleichen Button-Stile wie die anderen (hat im HTML keine Klasse) */
#buttonCheckMathtris {
    margin-top: 1.75rem;
    padding: 0.7rem 1.25rem;
    border: 2px solid #256d6a;
    border-radius: 12px;
    background: #2f8f8a;
    color: #f8f2e8;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 3px 0 rgba(92, 74, 50, 0.35);
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
}

#buttonCheckMathtris:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 0 rgba(92, 74, 50, 0.35);
    background: #2a807b;
    color: #f8f2e8;
}

#buttonCheckMathtris:active {
    transform: translateY(1px);
    box-shadow: 0 2px 0 rgba(92, 74, 50, 0.35);
}

/* ==========================================================================
   Aktionen-Bereich: alle Buttons untereinander, volle Breite
   (gilt fuer Desktop und Handy gleich)
   ========================================================================== */
#MathtrisMain .game-right {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

#MathtrisMain .game-actions {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    width: 100%;
    margin-top: 0;
}

#MathtrisMain .game-right button {
    width: 100%;
    margin-top: 0;
}

/* Pruefen-Button abgesetzt: deutlich mehr Abstand nach oben */
#MathtrisMain .game-actions #buttonCheckMathtris {
    margin-top: 2rem;
}

/* Buttons im linken Panel (Neues Spiel / Spiel abbrechen) */
.mathtris-left-actions {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 1.25rem;
}

.mathtris-left-actions .mathtris-action-button {
    width: 100%;
    margin-top: 0;
}

/* Zielblock im alten Design: grosses gelbes Quadrat mit Puls-Animation */
#mathtrisTargetBlock {
    width: 120px;
    height: 120px;
    margin: 20px auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    background: linear-gradient(145deg, #ffeb3b, #fbc02d);
    color: #1a237e;
    font-size: 3rem;
    font-weight: 900;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2), inset 0 -5px 10px rgba(0, 0, 0, 0.1);
    animation: mathtrisBlockPulse 2s infinite ease-in-out;
    border: 4px solid #fff;
}

@keyframes mathtrisBlockPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    }
}

/* Flash-Animationen bei richtig / falsch */
#mathtrisTargetBlock.mathtris-target-correct {
    animation: mathtrisTargetCorrectFlash 0.45s ease;
}

#mathtrisTargetBlock.mathtris-target-wrong {
    animation: mathtrisTargetWrongFlash 0.45s ease;
}

@keyframes mathtrisTargetCorrectFlash {
    0% {
        background: linear-gradient(145deg, #ffeb3b, #fbc02d);
        transform: scale(1);
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2), inset 0 -5px 10px rgba(0, 0, 0, 0.1);
    }

    50% {
        background: linear-gradient(145deg, #4caf50, #2e7d32);
        transform: scale(1.15);
        box-shadow: 0 0 35px rgba(76, 175, 80, 1);
    }

    100% {
        background: linear-gradient(145deg, #ffeb3b, #fbc02d);
        transform: scale(1);
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2), inset 0 -5px 10px rgba(0, 0, 0, 0.1);
    }
}

@keyframes mathtrisTargetWrongFlash {
    0% {
        background: linear-gradient(145deg, #ffeb3b, #fbc02d);
        transform: scale(1);
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2), inset 0 -5px 10px rgba(0, 0, 0, 0.1);
    }

    50% {
        background: linear-gradient(145deg, #f44336, #b71c1c);
        transform: scale(1.15);
        box-shadow: 0 0 35px rgba(244, 67, 54, 1);
    }

    100% {
        background: linear-gradient(145deg, #ffeb3b, #fbc02d);
        transform: scale(1);
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2), inset 0 -5px 10px rgba(0, 0, 0, 0.1);
    }
}

#mathtrisNumberGrid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    max-width: 20rem;
    margin: 1rem auto;
}

.mathtris-number-cell {
    margin: 0;
    padding: 0.65rem;
    min-height: auto;
    background: #f8f2e8;
    border: 2px solid #8a7555;
    font-weight: 600;
}

.mathtris-number-cell.selected {
    background: #c4b08a;
    border-color: #5c4a32;
}

#mathtrisFeedback {
    margin-top: 1rem;
    min-height: 1.5rem;
}

.mathtris-live-layout {
    margin-top: 0.75rem;
}

.mathtris-status-grid {
    margin-top: 0.35rem;
}

#mathtrisClock.hidden {
    display: none;
}

#mathtrisScore.live-score {
    color: #b85c28;
}

#mathtrisLives {
    color: #b3261e;
    font-weight: 700;
}

#mathtrisTime {
    color: #2f80ed;
    font-weight: 700;
}

/* Mathtris soll sich an die sichtbare Bildschirmhöhe anpassen */
#MathtrisMain {
    max-height: calc(100dvh - 8rem);
    overflow: hidden;
}

#MathtrisMain .game-layout {
    align-items: start;
}

#MathtrisMain .panel {
    box-sizing: border-box;
}

#MathtrisMain .game-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 0;
}

#mathtrisTargetBlock {
    width: clamp(76px, 14vh, 150px);
    height: clamp(76px, 14vh, 150px);
    margin: clamp(0.35rem, 1.8vh, 1.25rem) auto;
    font-size: clamp(1.8rem, 5vh, 3rem);
}

#mathtrisNumberGrid {
    width: min(100%, 28rem);
    max-width: min(100%, 28rem);
    gap: clamp(0.25rem, 0.9vh, 0.75rem);
    margin: clamp(0.35rem, 1.2vh, 1rem) auto;
}

.mathtris-number-cell {
    min-height: clamp(34px, 6vh, 58px);
    padding: clamp(0.2rem, 1vh, 1rem);
    font-size: clamp(0.85rem, 2.1vh, 1.2rem);
}

#mathtrisFeedback {
    margin-top: clamp(0.25rem, 1vh, 1rem);
    min-height: 1.25rem;
}

/* Laptop-Optimierung: niedrige Displays, aber normale Breite */
@media (max-height: 820px) and (min-width: 700px) {
    #MathtrisMain {
        max-height: calc(100dvh - 7rem);
    }

    #MathtrisMain .game-layout {
        gap: 0.75rem;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    #MathtrisMain .panel {
        padding: 0.75rem;
    }

    #MathtrisMain .screen-title {
        margin-bottom: 0.35rem;
        font-size: 1.3rem;
    }

    .mathtris-live-layout {
        margin-top: 0.25rem;
    }

    .mathtris-status-grid,
    #MathtrisMain .stats-grid {
        margin-top: 0.2rem;
        row-gap: 0.15rem;
    }

    #mathtrisTargetBlock {
        width: 92px;
        height: 92px;
        min-width: 92px;
        min-height: 92px;
        margin: 0.45rem auto;
        font-size: 2.1rem;
        border-radius: 16px;
    }

    #mathtrisNumberGrid {
        grid-template-columns: repeat(5, 1fr);
        max-width: 25rem;
        gap: 0.35rem;
        margin: 0.45rem auto;
    }

    .mathtris-number-cell {
        min-height: 40px;
        padding: 0.35rem;
        font-size: 1rem;
    }

    #mathtrisSelectedSumContainer {
        margin-bottom: 0.25rem;
    }

    #mathtrisFeedback {
        margin-top: 0.25rem;
        min-height: 1.1rem;
        font-size: 0.9rem;
    }

    #MathtrisMain .game-actions {
        gap: 0.45rem;
    }

    #MathtrisMain .game-actions #buttonCheckMathtris {
        margin-top: 0.75rem;
    }

    #MathtrisMain .game-right button {
        padding: 0.45rem 0.75rem;
        min-height: 36px;
        font-size: 0.9rem;
    }

    .mathtris-left-actions {
        margin-top: 0.75rem;
        gap: 0.45rem;
    }
}

@media (min-width: 1200px) {
    #mathtrisTargetBlock {
        min-width: 5.5rem;
        min-height: 5.5rem;
        font-size: 2.35rem;
    }

    #mathtrisNumberGrid {
        max-width: 28rem;
        gap: 0.75rem;
    }

    .mathtris-number-cell {
        padding: 1rem;
        font-size: 1.2rem;
    }

    #mathtrisHintDisplay {
        font-size: 1.35rem;
        font-weight: 700;
    }
}