:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-purple: #8b5cf6;
    --secondary: #64748b;
    --accent: #f43f5e;
    --accent-light: #fca5a5;
    --text-main: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --success: #22d3ee;
    --word-bg: rgba(51, 65, 85, 0.7);
    --font-main: 'Outfit', sans-serif;
}

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

html {
    height: 100%;
    height: var(--app-height, 100%);
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    height: 100%;
    height: var(--app-height, 100%);
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 1rem;
}

@media (max-height: 500px) {
    body {
        padding: 0.5rem;
    }
    .container {
        padding: 0.5rem;
    }
    header {
        margin-bottom: 0.5rem;
    }
    header h1 {
        font-size: 1.5rem;
        margin-bottom: 0.1rem;
    }
    .score-board {
        padding: 0.2rem;
        margin-bottom: 0.2rem;
    }
    .game-bottom-area {
        gap: 0.4rem;
        padding-bottom: 0.4rem;
    }
    input[type="text"] {
        padding: 0.75rem;
    }
}

.container {
    width: 100%;
    max-width: 800px;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    background: radial-gradient(circle at top right, #1e293b 0%, #0f172a 100%);
    margin: 0 auto;
    border-radius: 1rem;
}

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

header h1 {
    font-size: 2.5rem;
    font-weight: 600;
    background: linear-gradient(to right, #60a5fa, var(--primary-purple));
    -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;
}



/* 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);
}



.primary-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-purple));
    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 */
#game-area:not(.hidden) {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    position: relative;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    transition: color 0.2s, transform 0.2s;
}

.icon-btn:hover {
    color: var(--primary);
    transform: scale(1.1);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.game-top-bar {
    flex-shrink: 0;
}

.words-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
    min-height: 0;
    width: 100%;
}

.game-bottom-area {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-bottom: calc(env(safe-area-inset-bottom, 1rem) + 0.5rem);
}



.score-board {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-bottom: 0.5rem;
    background: var(--card-bg);
    padding: 0.4rem 0.5rem;
    border-radius: 0.5rem;
    gap: 0.25rem;
}

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

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

.score-item .value {
    font-size: 1.25rem;
    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: 1.5rem;
    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: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
}

.current-words {
    margin-bottom: 0;
    text-align: center;
    width: 100%;
}

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



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

input[type="text"] {
    flex: 1;
    background: var(--card-bg);
    border: 1px solid var(--secondary);
    color: var(--text-main);
    padding: 1rem;
    padding-right: 3rem;
    border-radius: 0.5rem;
    /* Ensure iOS doesn't zoom in on focus by making the font at least 16px */
    font-size: max(16px, 1.1rem);
    font-family: var(--font-main);
    transition: border-color 0.2s;
    width: 100%;
}

.word-input-container {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.submit-inside-btn {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    padding: 0 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, color 0.2s, transform 0.2s;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.submit-inside-btn svg {
    width: 18px;
    height: 18px;
}

.submit-inside-btn:hover {
    transform: scale(1.1);
}

.submit-inside-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

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;
}



/* 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;
}

/* Start screen: center the Start button, info icon sits to its left */
.start-actions {
    margin-top: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    position: relative;
}

.start-actions #how-to-play-btn {
    position: absolute;
    /* Anchor to the left of the centered start button */
    right: calc(50% + 7rem);
}

.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;
}



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

.word-item {
    background: var(--word-bg);
    padding: 0.5rem 1.1rem;
    border-radius: 9999px;
    font-size: 1.25rem;
    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: var(--accent-light);
    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);
}



.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);
}

/* Scrollable Screens (Instructions, etc.) */
.scrollable-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-height: 100%;
    overflow-y: auto;
    padding-right: 0.5rem; /* Space for scrollbar */
    overscroll-behavior: contain;
}

.scrollable-screen h2 {
    color: var(--primary);
    margin-bottom: 1rem;
    font-size: 2rem;
    text-align: center;
}

.scrollable-screen p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

.scrollable-screen .rules-list {
    margin-left: 1.5rem;
    margin-bottom: 1.5rem;
}

.scrollable-screen .rules-list li {
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

#how-to-play-screen #how-to-play-outro {
    display: block !important;
    text-align: center !important;
    margin: 2.5rem auto 1.5rem !important;
    width: 100% !important;
    max-width: 100% !important;
}

#how-to-play-screen .menu-actions {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    width: 100% !important;
    margin: 0 auto 2.5rem !important;
    padding: 1rem 0 !important;
    gap: 0 !important;
}

#how-to-play-screen #close-instructions-btn {
    margin-left: auto !important;
    margin-right: auto !important;
}

.close-btn {
    display: none;
}

.modal-content strong {
    color: var(--primary-purple);
    /* Slightly distinct color for emphasis */
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--accent);
}

/* 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;
    width: max-content;
    max-width: 95vw;
    align-items: center;
}

.toast {
    background: rgba(30, 41, 59, 0.95);
    color: var(--text-main);
    padding: 0.75rem 1.5rem;
    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;
    justify-content: center;
    text-align: center;
    gap: 0.5rem;
    backdrop-filter: blur(8px);
    width: 100%;
}

.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 */
    }

    .score-board {
        display: flex;
        flex-direction: row;
        justify-content: space-evenly;
        align-items: center;
        gap: 0;
        padding: 0.25rem;
        flex-wrap: nowrap;
    }

    .score-board #quit-btn {
        flex: 0 0 auto;
    }

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

    .score-item .value {
        font-size: 1.1rem;
    }

    .score-item .label {
        font-size: 0.7rem;
    }

    .word-cloud {
        gap: 0.4rem;
    }

    .word-item {
        padding: 0.45rem 0.85rem;
        font-size: 0.95rem;
    }

    .input-area {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
    }

    #submit-btn {
        width: auto;
        min-height: 0;
        padding: 0.5rem;
    }

    /* Ensure stacked columns span the whole screen width on mobile */
    .menu-actions.column button {
        width: 100%;
    }

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

/* --- NOTIFICATION REDESIGN STYLES --- */

/* Error Animations */
.input-error {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 2px rgba(244, 63, 94, 0.2);
}

.shake {
    animation: shake 0.4s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-1px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(2px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-4px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}

/* Disabled Buttons */
button:disabled,
.secondary-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
    border-color: rgba(255, 255, 255, 0.1);
}

/* Countdown Overlay */
.countdown-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: rgba(15, 23, 42, 0.9);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}

.countdown-overlay.hidden {
    display: none;
}

.countdown-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.countdown-label {
    font-size: 1.5rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.countdown-text {
    font-size: 8rem;
    font-weight: 700;
    color: var(--primary);
    text-shadow: 0 0 30px rgba(59, 130, 246, 0.6);
    animation: pulseCount 1s infinite;
}

@keyframes pulseCount {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
    }

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