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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: manipulation;
}

#gameContainer {
    width: 1200px;
    height: 800px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
}

#gameArea {
    width: 100%;
    height: 100%;
    position: relative;
}

#screenFlash {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(231, 76, 60, 0.7);
    opacity: 0;
    pointer-events: none;
    z-index: 150;
}

.equation {
    position: absolute;
    font-size: 36px;
    font-weight: bold;
    color: #333;
    background: white;
    padding: 18px 30px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.1s;
    white-space: nowrap;
}

.equation.active {
    background: #c8e6c9;
    border: 3px solid #4caf50;
    transform: scale(1.05);
}

.equation.wrong {
    animation: shake 0.3s;
    background: #ffebee;
}

.equation.correct {
    animation: correctAnswer 0.8s ease-out forwards;
}

.equation.break {
    animation: breakApart 0.6s ease-out forwards;
}

@keyframes screenFlash {
    0% { opacity: 0; }
    50% { opacity: 0.7; }
    100% { opacity: 0; }
}

@keyframes breakApart {
    0% {
        transform: translate(0, 0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translate(0, 50px) rotate(15deg);
        opacity: 0;
        filter: blur(5px);
    }
}

@keyframes correctAnswer {
    0% {
        transform: scale(1) rotate(0deg);
        background: #4caf50;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    }
    50% {
        transform: scale(1.3) rotate(5deg);
        background: #81c784;
        box-shadow: 0 8px 30px rgba(76, 175, 80, 0.5);
    }
    100% {
        transform: scale(0) rotate(360deg);
        opacity: 0;
        background: #a5d6a7;
        box-shadow: 0 0 50px rgba(76, 175, 80, 0.8);
    }
}

@keyframes shake {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}

.particle {
    position: absolute;
    pointer-events: none;
    animation: particle 1s ease-out forwards;
}

@keyframes particle {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

.star-particle {
    font-size: 24px;
}

#hud {
    position: absolute;
    top: 50px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    z-index: 100;
}

.hudItem {
    background: rgba(255, 255, 255, 0.9);
    padding: 12px 25px;
    border-radius: 12px;
    font-size: 24px;
    font-weight: bold;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#lives {
    color: #e74c3c;
}

#score {
    color: #27ae60;
}

#speed {
    color: #3498db;
    font-size: 20px;
}

#inputArea {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
}

#answerInput {
    width: 250px;
    height: 70px;
    font-size: 36px;
    text-align: center;
    border: 4px solid #667eea;
    border-radius: 15px;
    outline: none;
    font-weight: bold;
}

#answerInput:focus {
    border-color: #764ba2;
    box-shadow: 0 0 25px rgba(102, 126, 234, 0.5);
}

#answerInput.invalid {
    border-color: #e74c3c;
    background: #ffebee;
}

/* Mobile Numpad */
#numpad {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.98);
    padding: 8px;
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.2);
    z-index: 150;
}

#numpad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    max-width: 400px;
    margin: 0 auto;
}

#numpad-input {
    grid-column: 1 / -1;
    width: 100%;
    height: 45px;
    font-size: 22px;
    text-align: center;
    border: 3px solid #667eea;
    border-radius: 8px;
    font-weight: bold;
    margin-bottom: 6px;
    cursor: pointer;
    background: white;
}

#numpad-input.invalid {
    border-color: #e74c3c;
    background: #ffebee;
}

.numpad-btn {
    height: 45px;
    font-size: 20px;
    font-weight: bold;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.1s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.numpad-btn:active {
    transform: scale(0.95);
    background: #f0f0f0;
}

.numpad-btn.special {
    background: #667eea;
    color: white;
    border-color: #667eea;
    font-size: 16px;
}

.numpad-btn.special:active {
    background: #5568d3;
}

.score-popup {
    position: absolute;
    font-size: 48px;
    font-weight: bold;
    color: #4caf50;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    animation: scorePopup 1.5s ease-out forwards;
    z-index: 150;
}

@keyframes scorePopup {
    0% {
        transform: translate(-50%, -50%) scale(0) rotate(-180deg);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.5) rotate(10deg);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -150%) scale(1) rotate(0deg);
        opacity: 0;
    }
}

#gameOver {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 40px;
    border-radius: 25px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: none;
    z-index: 200;
    max-width: 90%;
    max-height: 90%;
    overflow-y: auto;
}

#gameOver h1 {
    color: #e74c3c;
    margin-bottom: 20px;
    font-size: 48px;
}

#gameOver p {
    font-size: 24px;
    margin: 10px 0;
    color: #333;
}

.button-group {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

.btn {
    padding: 15px 40px;
    font-size: 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
}

.btn:hover {
    background: #764ba2;
    transform: scale(1.05);
}

.btn-secondary {
    background: #95a5a6;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

#loginScreen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 50px;
    border-radius: 25px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    z-index: 200;
    max-width: 90%;
}

#loginScreen h1 {
    color: #667eea;
    margin-bottom: 25px;
    font-size: 42px;
}

#loginScreen p {
    font-size: 18px;
    color: #666;
    margin-bottom: 30px;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
}

.form-group input {
    width: 100%;
    padding: 12px 15px;
    font-size: 18px;
    border: 2px solid #ddd;
    border-radius: 10px;
    outline: none;
    transition: border-color 0.3s;
}

.form-group input:focus {
    border-color: #667eea;
}

.form-group input.error {
    border-color: #e74c3c;
}

.error-message {
    color: #e74c3c;
    font-size: 14px;
    margin-top: 5px;
    display: none;
}

#highscoreScreen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 40px;
    border-radius: 25px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: none;
    z-index: 200;
    width: 90%;
    max-width: 900px;
    max-height: 90%;
    overflow-y: auto;
}

#highscoreScreen h1 {
    color: #667eea;
    margin-bottom: 25px;
    font-size: 42px;
}

.filter-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-bottom: 25px;
}

.filter-btn {
    padding: 10px 20px;
    font-size: 16px;
    background: #f0f0f0;
    color: #333;
    border: 2px solid #ddd;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
}

.filter-btn:hover {
    background: #e0e0e0;
    border-color: #667eea;
}

.filter-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

#highscoreTable {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    font-size: 14px;
}

#highscoreTable th {
    background: #667eea;
    color: white;
    padding: 12px;
    text-align: left;
    font-size: 16px;
}

#highscoreTable td {
    padding: 10px 12px;
    border-bottom: 1px solid #ddd;
    font-size: 15px;
}

#highscoreTable tr:hover {
    background: #f5f5f5;
}

.rank {
    font-weight: bold;
    color: #667eea;
}

.loading {
    text-align: center;
    padding: 20px;
    color: #666;
}

.highlight-row {
    background: #fff3cd !important;
    font-weight: bold;
}

#highscoreBtn {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 12px 25px;
    font-size: 18px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
    z-index: 100;
}

#highscoreBtn:hover {
    background: #764ba2;
    transform: scale(1.05);
}

/* Tablet Responsive Design (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    body {
        align-items: flex-start;
    }
    
    #gameContainer {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        box-shadow: none;
    }
    
    #gameArea {
        height: 100vh;
        height: 100dvh;
    }
    
    /* Numpad für Tablets - kompakter (Sichtbarkeit wird per JavaScript gesteuert) */
    #numpad {
        max-height: 18vh;
        min-height: 180px;
        padding-bottom: 15px;
    }
    
    #numpad-grid {
        max-width: 450px;
    }
    
    #numpad-input {
        height: 50px;
        font-size: 24px;
    }
    
    .numpad-btn {
        height: 50px;
        font-size: 22px;
    }
    
    .numpad-btn.special {
        font-size: 18px;
    }
    
    /* Desktop Input verstecken */
    #inputArea {
        display: none;
    }
    
    /* HUD für Tablets */
    #hud {
        top: 10px;
        left: 10px;
        right: 10px;
    }
    
    .hudItem {
        padding: 10px 20px;
        font-size: 20px;
    }
    
    #speed {
        font-size: 18px;
    }
    
    /* Gleichungen für Tablets */
    .equation {
        font-size: 28px;
        padding: 14px 24px;
    }
    
    /* Screens für Tablets */
    #loginScreen,
    #gameOver,
    #highscoreScreen {
        padding: 30px;
        max-width: 85%;
    }
    
    #loginScreen h1,
    #gameOver h1,
    #highscoreScreen h1 {
        font-size: 36px;
    }
}

/* Mobile Responsive Design (bis 768px) */
@media (max-width: 768px) {
    body {
        align-items: flex-start;
    }
    
    #gameContainer {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        box-shadow: none;
    }
    
    #gameArea {
        height: 100vh;
        height: 100dvh;
    }
    
    /* Numpad auf Mobile - Größe (Sichtbarkeit wird per JavaScript gesteuert) */
    #numpad {
        max-height: 22vh;
        min-height: 220px;
        padding-bottom: 20px;
    }
    
    /* Desktop Input verstecken */
    #inputArea {
        display: none;
    }
    
    /* HUD anpassen */
    #hud {
        top: 5px;
        left: 5px;
        right: 5px;
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .hudItem {
        padding: 6px 12px;
        font-size: 14px;
    }
    
    #speed {
        font-size: 12px;
    }
    
    /* Gleichungen anpassen - innerhalb des sichtbaren Bereichs halten */
    .equation {
        font-size: 20px;
        padding: 10px 16px;        
    }
    
    /* Highscore Button anpassen */
    #highscoreBtn {
        top: 5px;
        right: 5px;
        padding: 6px 12px;
        font-size: 12px;
    }
    
    /* Screens anpassen */
    #loginScreen {
        padding: 20px 15px;
        max-width: 85%;
        max-height: 80%;
        overflow-y: auto;
    }
    
    #gameOver,
    #highscoreScreen {
        padding: 20px;
        max-width: 90%;
        max-height: 75%;
    }
    
    #loginScreen h1 {
        font-size: 28px;
        margin-bottom: 15px;
    }
    
    #gameOver h1,
    #highscoreScreen h1 {
        font-size: 28px;
        margin-bottom: 12px;
    }
    
    #loginScreen p {
        font-size: 16px;
        margin-bottom: 20px;
    }
    
    #gameOver p {
        font-size: 16px;
        margin: 8px 0;
    }
    
    .form-group {
        margin-bottom: 15px;
    }
    
    .form-group label {
        font-size: 16px;
        margin-bottom: 6px;
    }
    
    .form-group input {
        padding: 10px 12px;
        font-size: 16px;
    }
    
    .btn {
        padding: 12px 25px;
        font-size: 16px;
    }
    
    /* Tabelle anpassen */
    #highscoreTable {
        font-size: 11px;
    }
    
    #highscoreTable th {
        padding: 6px;
        font-size: 12px;
    }
    
    #highscoreTable td {
        padding: 5px 6px;
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .hudItem {
        padding: 5px 10px;
        font-size: 12px;
    }
    
    .equation {
        font-size: 18px;
        padding: 8px 14px;        
    }
    
    #loginScreen h1,
    #gameOver h1,
    #highscoreScreen h1 {
        font-size: 24px;
    }
    
    #numpad-input {
        height: 40px;
        font-size: 20px;
    }
    
    .numpad-btn {
        height: 40px;
        font-size: 18px;
    }
    
    .numpad-btn.special {
        font-size: 14px;
    }
}