:root {
    --bg-color: #0d1117;
    --text-color: #c9d1d9;
    --primary-color: #58a6ff;
    --secondary-color: #238636;
    --danger-color: #f85149;
    --accent-color: #8b949e;
    --block-bg: rgba(22, 27, 34, 0.9);
    --block-border: #30363d;
    --keypad-bg: #161b22;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

* {
    box-sizing: border-box;
    touch-action: manipulation;
    /* Disable double-tap zoom */
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* Prevent scrolling */
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
}

#game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    /* Dynamic viewport height for mobile browsers */
    width: 100vw;
    position: relative;
}

.game-header {
    display: flex;
    justify-content: space-between;
    padding: 1rem;
    background-color: var(--keypad-bg);
    z-index: 10;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
}

#score {
    color: #ffd700;
    font-weight: bold;
    font-size: 1.2em;
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
    margin-left: 5px;
}

#play-area {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle at center, #161b22 0%, #0d1117 100%);
}

/* Keypad Styles */
#keypad-container {
    background-color: var(--keypad-bg);
    padding: 10px;
    padding-bottom: 20px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.5);
    z-index: 20;
}

.current-input-display {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 10px;
    min-height: 3rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.cursor {
    animation: blink 1s infinite;
    color: var(--primary-color);
}

.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-width: 500px;
    margin: 0 auto;
}

.key {
    background-color: var(--block-bg);
    border: 1px solid var(--block-border);
    color: var(--text-color);
    font-size: 1.5rem;
    padding: 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.1s, transform 0.05s;
    user-select: none;
}

.key:active {
    background-color: #30363d;
    transform: scale(0.95);
}

.key.action-key {
    background-color: #21262d;
    font-weight: bold;
}

.key[data-key="ENTER"] {
    background-color: var(--secondary-color);
    color: white;
}

.key[data-key="DEL"] {
    background-color: var(--danger-color);
    color: white;
}

/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(13, 17, 23, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px 0;
    overflow-y: auto;
    z-index: 100;
    transition: opacity 0.3s;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.btn-primary,
.btn-secondary {
    padding: 12px 24px;
    margin: 10px;
    border: none;
    border-radius: 6px;
    font-size: 1.2rem;
    cursor: pointer;
    width: 80%;
    max-width: 300px;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-secondary {
    background-color: var(--block-bg);
    border: 1px solid var(--block-border);
    color: var(--text-color);
}

/* Animations */
@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Math Blocks */
.math-block {
    position: absolute;
    background-color: var(--block-bg);
    border: 2px solid var(--primary-color);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 1.5rem;
    font-weight: bold;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    transform: translateX(-50%);
    /* Center horizontally based on left position */
    white-space: nowrap;
}

.math-block.op-plus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 10px rgba(35, 134, 54, 0.4);
}

.math-block.op-minus {
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(88, 166, 255, 0.4);
}

.math-block.op-mul {
    border-color: #e3b341;
    color: #e3b341;
    box-shadow: 0 0 10px rgba(227, 179, 65, 0.4);
}

.math-block.op-div {
    border-color: var(--danger-color);
    color: var(--danger-color);
    box-shadow: 0 0 10px rgba(248, 81, 73, 0.4);
}

/* Settings Form */
.settings-form {
    width: 80%;
    max-width: 400px;
    margin-bottom: 20px;
    background: rgba(22, 27, 34, 0.8);
    padding: 20px;
    border-radius: 8px;
    text-align: left;
}

.setting-group {
    margin-bottom: 15px;
}

.setting-group label,
.setting-group .label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.setting-group input[type="number"] {
    width: 100%;
    padding: 10px;
    background: #0d1117;
    border: 1px solid #30363d;
    color: #fff;
    border-radius: 4px;
    font-size: 1rem;
}

.checkbox-group {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.checkbox-group label {
    font-weight: normal;
    background: #21262d;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Highscore */
.highscore-list {
    width: 100%;
    max-width: 400px;
    margin: 20px 0;
    text-align: center;
}

.highscore-entry {
    display: flex;
    justify-content: space-between;
    padding: 8px 15px;
    background: #21262d;
    border-bottom: 1px solid #30363d;
    font-size: 1.1rem;
}

.highscore-entry:first-child {
    background: rgba(88, 166, 255, 0.2);
    font-weight: bold;
    border-radius: 6px 6px 0 0;
}

.highscore-entry:last-child {
    border-radius: 0 0 6px 6px;
    border-bottom: none;
    border-bottom: none;
}

/* Highscore Table */
.highscore-table-container {
    overflow-x: auto;
    width: 100%;
}

.highscore-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    text-align: left;
}

.highscore-table th,
.highscore-table td {
    padding: 8px;
    border-bottom: 1px solid #30363d;
}

.highscore-table th {
    background-color: #21262d;
    font-weight: bold;
    color: var(--primary-color);
}

.highscore-table tr.latest {
    background: rgba(255, 215, 0, 0.2);
    animation: flash 1s ease-in-out infinite alternate;
}

.highscore-table tr.latest td {
    border-color: #e3b341;
}

.op-badge {
    display: inline-block;
    width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 4px;
    font-size: 0.8rem;
    margin-right: 2px;
    color: white;
    font-weight: bold;
}

.op-badge.plus {
    background-color: var(--secondary-color);
}

.op-badge.minus {
    background-color: var(--primary-color);
}

.op-badge.mul {
    background-color: #e3b341;
    color: black;
}

.op-badge.div {
    background-color: var(--danger-color);
}

.highscore-entry.latest {
    background: rgba(255, 215, 0, 0.3) !important;
    /* Gold background */
    border: 1px solid #e3b341;
    font-weight: bold;
    animation: flash 1s ease-in-out infinite alternate;
}

@keyframes flash {
    from {
        background: rgba(255, 215, 0, 0.2);
    }

    to {
        background: rgba(255, 215, 0, 0.5);
    }
}

/* Visual Feedback for Levels/Lives */
body.lives-2 #play-area {
    background: radial-gradient(circle at center, #3e3310 0%, #0d1117 100%);
}

body.lives-1 #play-area {
    background: radial-gradient(circle at center, #3e1010 0%, #0d1117 100%);
}

/* Level Up Notification */
.notification {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: bold;
    color: #58a6ff;
    text-shadow: 0 0 20px rgba(88, 166, 255, 0.8);
    pointer-events: none;
    z-index: 50;
    opacity: 0;
    transition: opacity 0.5s, transform 0.5s;
}

.notification.active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.2);
}

/* Mobile Optimizations */
@media (max-width: 600px) and (orientation: portrait) {
    #keypad-container {
        padding: 5px;
        padding-bottom: 15px;
    }

    .current-input-display {
        margin-bottom: 5px;
        font-size: 1.5rem;
        min-height: 2.5rem;
    }

    .keypad {
        gap: 4px;
    }

    .key {
        padding: 12px;
        font-size: 1.2rem;
    }

    .game-header {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
}