:root {
    --bg-color: #0f0f1f;
    --text-color: #ffffff;
    --accent-color: #00ff9d;
    /* Neon Green */
    --accent-secondary: #ff0055;
    /* Neon Red/Pink */
    --card-bg: #1a1a2e;
    --btn-bg: #252540;
    --btn-active: #353550;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh; /* Fallback for older browsers */
    height: 100dvh; /* Dynamic viewport height to prevent Safari toolbar overflow */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Prevent scrolling on main body */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: clamp(10px, 2vh, 20px);
}

/* Victory Animation */
@keyframes pop-bounce {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
        text-shadow: 0 0 20px rgba(0, 255, 157, 0.8);
    }

    70% {
        transform: scale(0.9);
    }

    100% {
        transform: scale(1);
    }
}

.pop-active {
    animation: pop-bounce 0.6s ease-out;
}

.prediction-box.success {
    border-color: var(--accent-color);
    background: rgba(0, 255, 157, 0.1);
}

.prediction-box.impossible {
    border-color: var(--accent-secondary);
    background: rgba(255, 0, 85, 0.1);
}

/* Update Notification */
.notification {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-bg);
    padding: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--accent-color);
    z-index: 1000;
}

.notification span {
    font-size: 0.9rem;
}

.notification button {
    background: var(--accent-color);
    color: #000;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    touch-action: manipulation;
}

.status-display {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: clamp(10px, 2vh, 20px);
}

.status-item {
    background: var(--card-bg);
    padding: 16px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.status-item .label {
    display: block;
    font-size: 0.9rem;
    color: #888;
    margin-bottom: 4px;
}

.status-item .value {
    font-size: clamp(1.5rem, 4vh, 2rem);
    font-weight: bold;
    color: var(--accent-color);
}

.prediction-box {
    background: rgba(255, 255, 255, 0.05);
    padding: clamp(8px, 1.5vh, 16px);
    border-radius: 12px;
    margin-bottom: auto;
    /* Push keypad down */
    border-left: 4px solid var(--accent-secondary);
    min-height: clamp(60px, 10vh, 80px);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.prediction-box p {
    font-size: 1.1rem;
    line-height: 1.4;
}

/* Main should take available space but allow scrolling if needed (though we want to fit) */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    /* Important for flex child scroll/overflow behavior */
}

.input-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-top: 10px;
    /* Reduced from 20px to save space */
    min-height: 0;
}

/* Setup Controls - keep as is */
.controls-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    /* Allow setup to scroll if needed on small screens */
    flex: 0 0 auto;
    /* Ensure it does not stretch */
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group label {
    font-size: 0.9rem;
    color: #aaa;
}

.input-group input {
    background: var(--card-bg);
    border: 1px solid #333;
    color: white;
    padding: 12px;
    border-radius: 8px;
    font-size: 1.2rem;
}

.full-width-btn {
    background: var(--accent-color);
    color: #000;
    border: none;
    padding: 16px;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    margin-top: 10px;
    touch-action: manipulation;
}

/* Keypad - Make it fill available space */
.keypad-grid {
    display: grid;
    /* 3 columns */
    grid-template-columns: repeat(3, 1fr);
    /* 5 rows: 
       Row 1: 0 1 2
       Row 2: 3 4 5
       Row 3: 6 7 8 
       Row 4: 9 SP ST (Larger)
       Row 5: UNDO (Smaller or Standard)
    */
    grid-template-rows: 1fr 1fr 1fr 2fr 0.8fr;
    gap: clamp(4px, 1vh, 8px);
    flex: 1;
    /* Grow to fill input-area */
    min-height: 0;

    /* Constraints to prevent huge buttons on desktop */
    max-height: min(500px, 60vh);
    /* Reasonable max height for a keypad OR 60% of screen height */
    width: 100%;
    margin: 0 auto;
    /* Center horizontally if width < 100% (container constrains it anyway) */
    align-self: center;
    /* Center vertically in input-area if there is extra space */
}

.key-btn {
    background: var(--btn-bg);
    border: none;
    color: white;
    /* Remove fixed padding */
    padding: 0;
    border-radius: 8px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background 0.1s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
    height: 100%;
    touch-action: manipulation;
}

.key-btn:active {
    background: var(--btn-active);
    transform: scale(0.98);
}

.special-btn {
    background: rgba(0, 255, 157, 0.15);
    color: var(--accent-color);
    font-size: 1rem;
    font-weight: bold;
    grid-column: span 1;
}

.special-btn small {
    font-size: 0.8rem;
    opacity: 0.8;
}

#undo-btn {
    background: rgba(255, 0, 85, 0.15);
    color: var(--accent-secondary);
    font-size: 1rem;
    font-weight: bold;
    grid-column: 1 / -1;
    /* Span full width */
}

/* Large button styling - Font size only, height handled by grid row */
.large-btn {
    font-size: clamp(1.5rem, 3.5vh, 2rem);
    /* Fluid font size */
    font-weight: bold;
}

.large-btn small {
    font-size: 1.1rem;
}

.hidden {
    display: none !important;
}

h1 {
    font-size: 1.5rem;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(0, 255, 157, 0.3);
}

/* Mobile Optimizations */
@media (max-height: 750px) {
    .container {
        padding: 8px;
        /* Reduce padding */
    }

    header {
        margin-bottom: 10px;
        /* Compress header space */
    }

    h1 {
        font-size: 1.2rem;
        /* Smaller title */
    }

    .icon-btn {
        font-size: 1.2rem;
    }

    .status-display {
        gap: 8px;
        margin-bottom: 10px;
    }

    .status-item {
        padding: 8px;
    }

    .status-item .value {
        font-size: 1.5rem;
    }

    .prediction-box {
        min-height: 60px;
        padding: 8px;
        margin-bottom: 8px;
    }

    .prediction-box p {
        font-size: 1rem;
    }

    .input-area {
        margin-top: 5px;
    }

    .keypad-grid {
        gap: 4px;
        /* Tighter gap */
    }

    .key-btn {
        font-size: 1.2rem;
    }

    .large-btn {
        font-size: 1.5rem;
        /* Reduce form 2rem */
    }

    .large-btn small {
        font-size: 0.9rem;
    }
}