:root {
    --bg-color: #121212;
    --primary-color: #5c9ded;
    --primary-hover: #4a8cdb;
    --secondary-color: #2c2c2c;
    --secondary-hover: #3d3d3d;
    --text-main: #e0e0e0;
    --text-light: #a0a0a0;
    --card-bg: #1e1e1e;
    --shadow: 0 10px 30px rgba(0,0,0,0.5);
    --border-color: #333333;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.app-container {
    width: 100%;
    max-width: 600px;
    padding: 20px;
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.screen {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.4s ease;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
    position: relative;
}

h1 {
    font-size: 3rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--primary-color);
}

.subtitle {
    color: var(--text-light);
    margin-bottom: 40px;
    font-size: 1.2rem;
}

/* Buttons */
.btn {
    padding: 15px 30px;
    border-radius: 12px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s ease, background-color 0.2s ease;
    font-family: inherit;
    user-select: none;
}

.btn:active {
    transform: scale(0.96);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.primary-btn {
    background-color: var(--primary-color);
    color: #121212;
}

.primary-btn:hover {
    background-color: var(--primary-hover);
}

.secondary-btn {
    background-color: var(--secondary-color);
    color: var(--text-main);
}

.secondary-btn:hover {
    background-color: var(--secondary-hover);
}

.text-btn {
    background: none;
    color: var(--text-light);
    padding: 8px 16px;
}

.text-btn:hover {
    color: var(--text-main);
}

.small-btn {
    font-size: 0.9rem;
    padding: 5px 10px;
}

/* Loader */
.loader {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.loader.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--secondary-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Game Screen */
.top-bar {
    position: absolute;
    top: 20px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-item .label {
    font-size: 0.8rem;
    color: var(--text-light);
}

#timer, #word-count {
    font-weight: 600;
    font-size: 1.1rem;
}

.card-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.word-card {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 20px;
    box-shadow: var(--shadow);
    width: 100%;
    text-align: center;
    min-height: 180px;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid var(--border-color);
}

@keyframes popIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

#current-word {
    font-size: 2.2rem;
    color: var(--text-main);
    text-transform: capitalize;
    word-break: break-word;
}

.controls {
    display: flex;
    gap: 10px;
    width: 100%;
}

.controls .btn {
    flex: 1;
    padding: 15px 10px; /* More compact padding */
    font-size: 0.95rem;
}

/* History Section */
.history-section {
    margin-top: 20px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.history-list {
    width: 100%;
    margin-top: 10px;
    max-height: 150px;
    overflow-y: auto;
    background: var(--card-bg);
    border-radius: 10px;
    padding: 10px;
    border: 1px solid var(--border-color);
    font-size: 0.9rem;
    color: var(--text-light);
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
}

.history-list.hidden {
    display: none;
}

.history-item {
    padding: 6px 0;
    border-bottom: 1px solid var(--secondary-color);
}

.history-item:last-child {
    border-bottom: none;
}

/* Stats Screen */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 30px 0;
    width: 100%;
}

.stat-box {
    background: var(--card-bg);
    padding: 15px;
    border-radius: 15px;
    box-shadow: var(--shadow);
    text-align: center;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 5px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal {
    background: var(--card-bg);
    width: 90%;
    max-width: 400px;
    border-radius: 20px;
    padding: 20px;
    box-shadow: var(--shadow);
    transform: translateY(0);
    transition: transform 0.3s;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
}

.modal-overlay.hidden .modal {
    transform: translateY(20px);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.modal-header h3 {
    color: var(--text-main);
    font-size: 1.2rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.8rem; /* Larger touch target */
    cursor: pointer;
    color: var(--text-light);
    padding: 0 10px;
}

.associations-list {
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.assoc-chip {
    background: var(--secondary-color);
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 0.9rem;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.loading-text {
    color: var(--text-light);
    text-align: center;
    width: 100%;
    padding: 20px;
}

/* MOBILE ADAPTATION */
@media (max-width: 480px) {
    .app-container {
        padding: 15px;
    }

    h1 {
        font-size: 2.2rem;
    }

    .subtitle {
        font-size: 1rem;
        margin-bottom: 30px;
    }

    .top-bar {
        padding: 0 15px;
        top: 15px;
    }

    #current-word {
        font-size: 1.8rem;
    }

    .word-card {
        padding: 20px;
        min-height: 160px;
    }

    .controls {
        gap: 8px;
    }

    .controls .btn {
        padding: 12px 8px;
        font-size: 0.85rem;
        border-radius: 10px;
    }

    /* Stack stats on very small screens */
    .stats-grid {
        gap: 8px;
    }
    
    .stat-box {
        padding: 10px;
    }
    
    .stat-value {
        font-size: 1.3rem;
    }

    /* Increase touch targets for mobile */
    .close-btn {
        padding: 5px 15px;
    }
    
    .assoc-chip {
        padding: 8px 14px; /* Easier to tap if they were clickable (they are not, but looks better) */
    }
}
