:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --secondary: #64748b;
    --accent: #f43f5e;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --success: #10b981;
    --font-main: 'Outfit', sans-serif;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    /* Changed from center to prevent clipping */
    padding: 1rem;
    /* Padding for mobile edges */
}

.container {
    width: 100%;
    max-width: 800px;
    padding: 2rem;
    background: radial-gradient(circle at top right, #1e293b 0%, #0f172a 100%);
    margin: auto;
    /* Vertically center if space allows */
    border-radius: 1rem;
    /* Ensure radius is consistent */
}

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

header h1 {
    font-size: 2.5rem;
    font-weight: 600;
    background: linear-gradient(to right, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-muted);
}

.hidden {
    display: none !important;
}

#instruction-text {
    margin: 1.5rem 0;
    padding: 1.25rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 0.75rem;
    border-left: 3px solid var(--primary);
    text-align: left;
    font-size: 1.1rem;
    color: var(--text-main);
    line-height: 1.4;
    max-width: 100%;
}

/* Start Screen */
#start-screen,
#game-over-screen {
    text-align: center;
    padding: 3rem;
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

.tutorial-wrapper {
    margin: 1rem 0 2rem;
    text-align: center;
}

.tutorial-img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.tutorial-title {
    font-size: 1.4rem;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.tutorial-desc {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    max-width: 80%;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.4;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: var(--font-main);
    font-weight: 600;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

/* Game Area */
.score-board {
    display: flex;
    justify-content: space-around;
    margin-bottom: 2rem;
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 0.5rem;
}

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

.score-item .label {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.score-item .value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
}

/* Score Styling */
.score-combined {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.value-mini {
    position: absolute;
    top: -0.8rem;
    right: -2.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--success);
    white-space: nowrap;
    opacity: 0.9;
}

/* Lives Filling Heart */
.lives-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.lives-heart {
    font-size: 2rem;
    line-height: 1;
    /* Default to 100% fill if variable not set */
    background: linear-gradient(to top, var(--accent) var(--fill-percent, 100%), var(--secondary) var(--fill-percent, 100%));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    /* Required for some browsers */
    color: transparent;
    transition: background 0.5s ease;
    text-shadow: 0 0 10px rgba(244, 63, 94, 0.2);
}

.lives-count {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
}

.current-words {
    margin-bottom: 2rem;
    text-align: center;
}

.word-cloud {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1rem;
}

.word-tag {
    background: rgba(59, 130, 246, 0.1);
    color: #60a5fa;
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    border: 1px solid rgba(59, 130, 246, 0.2);
    font-size: 1.1rem;
    animation: fadeIn 0.5s ease-out;
}

.input-area {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

input[type="text"] {
    flex: 1;
    background: var(--card-bg);
    border: 1px solid var(--secondary);
    color: var(--text-main);
    padding: 1rem;
    border-radius: 0.5rem;
    font-size: 1.1rem;
    font-family: var(--font-main);
    transition: border-color 0.2s;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
}

#submit-btn {
    padding: 0 2rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-main);
}

.feedback-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.section h3 {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

.word-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.removed-item,
.added-item {
    font-size: 0.9rem;
    padding: 0.25rem 0;
    animation: slideIn 0.3s ease-out;
}

.removed-item {
    color: var(--accent);
    text-decoration: line-through;
    opacity: 0.7;
}

.added-item {
    color: var(--success);
}

/* Main Menu & Screen Transitions */
.screen-center {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 300px;
}

.menu-actions {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
}

.menu-actions.column {
    flex-direction: column;
    width: 100%;
}

.lang-btn {
    width: 100%;
    margin-bottom: 0.5rem;
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.small-btn {
    padding: 0.5rem 1rem;
    font-size: 1.2rem;
    line-height: 1;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.game-header h2 {
    font-size: 1.5rem;
    color: var(--text-muted);
}

.large-btn {
    padding: 1.25rem 3rem;
    font-size: 1.5rem;
}

.word-item {
    background: rgba(30, 41, 59, 0.6);
    padding: 0.75rem 1.5rem;
    border-radius: 9999px;
    font-size: 1.1rem;
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.word-item.removed {
    background: transparent;
    border: 1px solid rgba(220, 38, 38, 0.1);
    color: #fca5a5;
    opacity: 0.7;
}

.word-item.new-word {
    /* Subtle border to differentiate, but mostly rely on the badge */
    border-color: rgba(59, 130, 246, 0.4);
    position: relative;
    /* Ensure positioning context for the badge */
    overflow: visible;
    /* Allow badge to sit on the edge */
}

.word-item.new-word::after {
    content: "NEW";
    position: absolute;
    top: -0.2rem;
    right: 0;
    background: transparent;
    color: white;
    font-size: 0.65rem;
    font-weight: 800;
    padding: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--secondary);
    color: var(--text-main);
    padding: 1rem 2rem;
    font-size: 1.2rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-family: var(--font-main);
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--text-main);
}

.text-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: underline;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.text-btn:hover {
    opacity: 1;
    color: var(--accent);
}

.final-score {
    margin: 2rem 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.final-score .label {
    font-size: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.final-score .value {
    font-size: 3rem;
    font-weight: 700;
    color: var(--success);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.stats-grid {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
}

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

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

/* Toast Messages */
#toast-container {
    position: fixed;
    top: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    pointer-events: none;
}

.toast {
    background: rgba(30, 41, 59, 0.95);
    color: var(--text-main);
    padding: 1rem 2rem;
    border-radius: 0.5rem;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-weight: 500;
    animation: slideDown 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    backdrop-filter: blur(8px);
}

.toast.warning {
    border-left: 4px solid var(--accent);
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.info {
    border-left: 4px solid var(--primary);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

.game-over-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
}

.game-over-actions button {
    width: 100%;
}

/* --- RESPONSIVE ADJUSTMENTS --- */
@media (max-width: 600px) {
    .container {
        padding: 1rem;
        /* reduce side padding on mobile */
    }

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

    .game-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .score-board {
        display: flex;
        flex-direction: row;
        justify-content: space-evenly;
        /* Even spacing */
        gap: 0;
        /* Remove gap to ensure fit */
        padding: 0.25rem;
        /* Minimal padding */
        flex-wrap: nowrap;
        /* Force single row */
    }

    .score-item {
        margin-bottom: 0;
        flex: 1;
        padding: 0 2px;
        /* Minimal internal padding */
    }

    .score-item .value {
        font-size: 1.1rem;
        /* Smaller font to fit */
    }

    .score-item .label {
        font-size: 0.7rem;
        /* Smaller labels */
    }

    .input-area {
        flex-direction: column;
        /* Stack input and button */
    }

    #submit-btn {
        width: 100%;
        min-height: 70px;
        /* Explicit minimum height */
        padding: 0;
        /* Remove padding dependency */
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 1.3rem;
    }

    /* Stack buttons in menus if needed */
    .menu-actions {
        flex-direction: column;
        width: 100%;
    }

    .menu-actions button {
        width: 100%;
    }

    .feedback-area {
        grid-template-columns: 1fr;
        /* Stack feedback columns */
    }
}