:root {
    /* High Contrast Color Palette */
    --bg-deep: #020617;
    --bg-card: #0f172a;
    --primary: #8b5cf6; /* Electric Violet */
    --primary-glow: rgba(139, 92, 246, 0.5);
    --even-color: #10b981; /* Emerald Green */
    --odd-color: #f43f5e;  /* Rose Red */
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --accent-gold: #f59e0b;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--bg-deep);
    color: var(--text-main);
    margin: 0;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    line-height: 1.5;
}

.container {
    width: 100%;
    max-width: 1200px;
}

header {
    text-align: center;
    margin-bottom: 1.5rem;
}

h1 {
    font-size: clamp(1.8rem, 8vw, 3rem); 
    font-weight: 800;
    margin: 0.5rem 0;
    background: linear-gradient(to right, #a78bfa, #f472b6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-dim);
    font-size: clamp(0.9rem, 2vw, 1.1rem);
}

/* --- Controls Card --- */
.controls-card {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1.25rem;
    padding: 1.25rem;
    display: flex;
    flex-direction: column; 
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.5rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

@media (min-width: 640px) {
    .controls-card {
        flex-direction: row; 
        justify-content: center;
        padding: 1.5rem;
    }
}

.input-group {
    display: flex;
    align-items: center;
    background: var(--bg-deep);
    border-radius: 1rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--primary);
    width: 100%;
    max-width: 300px;
}

.input-label {
    font-size: 0.8rem; 
    font-weight: 700;
    margin-right: 0.5rem;
}

input[type="number"] {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.2rem;
    width: 100%;
    outline: none;
}

.btn-group {
    display: grid;
    grid-template-columns: 1fr 1fr; 
    gap: 0.5rem;
    width: 100%;
}

@media (min-width: 640px) {
    .btn-group {
        display: flex;
        width: auto;
    }
}

.btn {
    padding: 0.8rem 1.2rem;
    border-radius: 1rem;
    border: none;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.8rem;
    white-space: nowrap;
}

#resetBtn { grid-column: span 2; }
@media (min-width: 640px) { #resetBtn { grid-column: auto; } }

.btn-start { background: var(--primary); color: white; box-shadow: 0 0 15px var(--primary-glow); }
.btn-pause { background: #334155; color: white; }
.btn-reset { background: #475569; color: white; }

.btn:hover { transform: translateY(-2px); filter: brightness(1.2); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* --- Dashboard --- */
.dashboard {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}

@media (min-width: 1024px) {
    .dashboard { grid-template-columns: 2fr 1fr; }
}

.glass-panel {
    background: var(--bg-card);
    border-radius: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 1.25rem;
}

.chart-container {
    min-height: 280px;
    height: 45vh; 
    max-height: 450px;
    position: relative;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-box {
    background: var(--bg-deep);
    padding: 1rem;
    border-radius: 1rem;
    text-align: center;
    border-bottom: 3px solid var(--primary);
}

.stat-val { 
    display: block; 
    font-size: 1.25rem; 
    font-weight: 800; 
    color: var(--accent-gold); 
    overflow: hidden; 
    text-overflow: ellipsis; 
}

.stat-label { 
    font-size: 0.65rem; 
    color: var(--text-dim); 
    text-transform: uppercase; 
    letter-spacing: 1px; 
}

/* --- Bubble Trail --- */
.trail-container {
    margin-top: 1.5rem;
    background: var(--bg-deep);
    border-radius: 1.5rem;
    padding: 1.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 2.5rem; 
    overflow-x: auto;
    white-space: nowrap;
    min-height: 130px;
    scroll-behavior: smooth;
    border: 1px dashed rgba(255, 255, 255, 0.1);
}

.bubble {
    min-width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1rem;
    position: relative;
    flex-shrink: 0;
    box-shadow: 0 10px 20px rgba(0,0,0,0.4);
}

.bubble.even { background: var(--even-color); color: #064e3b; }
.bubble.odd { background: var(--odd-color); color: #4c0519; }
.bubble.target { border: 3px solid white; background: var(--accent-gold); }

.bubble:not(:last-child)::after {
    content: '→';
    position: absolute;
    right: -1.8rem;
    color: var(--text-dim);
    font-size: 1.2rem;
}

/* --- MODAL (FIXED FOR RESPONSIVENESS) --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(2, 6, 23, 0.95); /* Slightly darker for focus */
    backdrop-filter: blur(10px);
    display: none; 
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 1.5rem; /* Prevents content touching screen edges */
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--primary);
    padding: clamp(1.5rem, 5vw, 2.5rem); /* Responsive internal padding */
    border-radius: 2rem;
    width: 100%;
    max-width: 420px; /* Maximum readable width on desktop */
    text-align: center;
    box-shadow: 0 0 50px rgba(139, 92, 246, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: modalSlideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-icon {
    font-size: clamp(2.5rem, 10vw, 3.5rem);
    margin-bottom: 1rem;
}

.modal-content h2 {
    margin: 0 0 1rem 0;
    color: var(--odd-color);
    font-size: clamp(1.2rem, 5vw, 1.8rem);
}

.modal-content p {
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 2rem;
    font-size: clamp(0.9rem, 4vw, 1rem);
}

/* Fix: Centering the button inside the modal */
.modal-content .btn {
    width: 100%;
    max-width: 200px;
}

@keyframes modalSlideUp {
    from { transform: translateY(40px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* --- Rules & Success --- */
.rules-card { display: flex; flex-direction: column; gap: 0.75rem; }
.rule {
    padding: 0.8rem;
    border-radius: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-left: 4px solid var(--primary);
}

.success-msg {
    margin-top: 1.5rem;
    padding: 1rem;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--even-color);
    border-radius: 1rem;
    text-align: center;
    display: none;
    color: var(--even-color);
}

/* --- Footer Styles --- */
.footer {
    margin-top: 3rem;
    padding-bottom: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 2rem;
}

.footer-tag {
    font-weight: 800;
    color: var(--text-dim);
    letter-spacing: 1px;
    margin: 0;
    font-size: 0.9rem;
}

.social-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.social-icon {
    width: 24px;
    height: 24px;
    fill: var(--text-dim);
    transition: all 0.3s ease;
}

.social-links a:hover .social-icon {
    fill: var(--primary);
    transform: translateY(-3px);
    filter: drop-shadow(0 0 8px var(--primary-glow));
}

/* Ensure footer doesn't get squashed on small screens */
@media (max-width: 480px) {
    .footer {
        margin-top: 2rem;
    }
}