/* Definition modal styles */
.definition-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.definition-modal .modal-content {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    position: relative;
}

.definition-modal .close-button {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 24px;
    cursor: pointer;
}

/* Word list grid inside the vocab selection modal */
#select-words-modal .words-list {
    margin-top: 5px;
}

/* Modal control buttons (Select All / Clear / Done) */
#select-words-modal button#select-all,
#select-words-modal button#clear-all,
#select-words-modal button#done {
    background: #3b82f6;
    /* blue */
    color: #ffffff;
    /* white text */
    border: none;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}

#select-words-modal button#select-all:hover,
#select-words-modal button#clear-all:hover,
#select-words-modal button#done:hover {
    background: #2563eb;
}

#select-words-modal button#select-all:focus-visible,
#select-words-modal button#clear-all:focus-visible,
#select-words-modal button#done:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 3px;
    box-shadow: none;
}

/* Word card keyboard focus */
.word-card {
    position: relative;
    outline: none;
}

.word-card:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 3px;
}

/* Close button in the select-words modal: red background */
#select-words-modal .close-button {
    background: #ef4444;
    /* red */
    color: #fff;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

#select-words-modal .close-button:hover {
    background: #dc2626;
}

#select-words-modal .close-button:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 3px;
    box-shadow: none;
}

@keyframes background-flash {

    0%,
    100% {
        background: linear-gradient(45deg, #2c3e50, #000000);
        box-shadow: none;
    }

    50% {
        background: #00d9ff;
        box-shadow: 0 0 20px #00d9ff;
    }
}


/* Game area background */
.game-area {
    background-image: url('/assets/images/whats-the-word/whats-the-word-bg.png');
}

/* Layout for game-area sub-containers */

/* Bring containers above game-area background and add border */
.progress-bar-container {
    position: relative;
    z-index: 10;
}

/* Ensure game elements layout */

/* Vertical layout for main game elements */
.game-elements-container {
    display: flex;
    flex-direction: column;
    height: 95%;
}

/* Ensure progress bar has minimum height */
.progress-bar-container {
    /* fixed height for progress bar */
    height: 30px;
    min-height: 30px;
    position: relative;
    overflow: visible;
    /* allow rabbit/turtle to show off-screen */
}

/* Place the main game elements above other background layers but below UI chrome */
.game-elements-container {
    z-index: 5;
    position: relative;
}

.game-elements-container .image-display {
    /* Make image display vertically flexible */
    flex: 1 1 auto;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: linear-gradient(145deg, #00000063, #00000063);
    position: relative;
    /* allow overlays to be absolutely positioned */
}

/* Overlay grid used in Guess mode: 3x3 squares covering the image */
.image-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    /* 16-square layout: 4 columns x 4 rows */
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 1px;
    /* small 1px gap between squares */
    z-index: 20;
    background: transparent;
}

.image-overlay .overlay-square {
    background: #607d8b;
    /* solid light gray */
    outline: 1px solid #000;
    /* black outline */
    box-sizing: border-box;
    cursor: pointer;
    transition: opacity 120ms ease;
    opacity: 1;
    -webkit-tap-highlight-color: transparent;
}

.image-overlay .overlay-square[aria-disabled="true"],
.image-overlay .overlay-square[disabled] {
    pointer-events: none;
}

/* Hover effect: inner shadow and slight color change for interactive squares */
.image-overlay .overlay-square:not([aria-disabled="true"]):hover {
    background: #cfd6da;
    /* a little darker */
    /* stronger inner shadow for clearer hover feedback */
    box-shadow: inset 0 6px 18px rgba(0, 0, 0, 0.28);
}

/* Make drop zone height fit content, not fixed percentage */

.game-elements-container .text-display {
    flex: 0 0 auto;
    height: fit-content;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.game-elements-container .control-and-answer-btns {
    flex: 0 0 20%;
    height: 20%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

@media (max-width: 600px) {
    .game-elements-container .control-and-answer-btns {
        height: 25%;
    }
}

.image-display img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Match mode grid: 3 images on top, 3 words below */
.match-grid {
    display: flex;
    flex-direction: column;
    gap: 18px;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
}

.match-images-row,
.match-words-row {
    display: flex;
    gap: 18px;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.match-image {
    position: relative;
    width: clamp(110px, 18vw, 180px);
    height: auto;
    /* use aspect-ratio to keep perfect circle */
    aspect-ratio: 1 / 1;
    flex: 0 0 auto;
    /* don't stretch in flex rows */
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    border: 3px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    cursor: grab;
    transition: box-shadow 120ms ease, transform 120ms ease, opacity 120ms ease;
}

.match-image.dragging {
    /* make original element mostly transparent when dragging (95% transparent) */
    opacity: 0.05;
}

.match-image.matched {
    outline: 3px solid #2ecc71;
    box-shadow: 0 6px 18px rgba(46, 204, 113, 0.18);
    cursor: default;
}

.match-image.wrong {
    /* Visual: flash an outer red outline + subtle red glow briefly on wrong answers */
    outline: 4px solid rgba(239, 68, 68, 0);
    outline-offset: 2px;
    animation: wrong-flash 420ms ease;
}

.match-image.selected {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
    /* visible cyan highlight when selected */
    outline: 5px solid #00BCD4;
    outline-offset: 2px;
}

.match-image-img {
    width: 86%;
    height: 86%;
    object-fit: contain;
    object-position: center;
    display: block;
    position: relative;
    z-index: 0;
}

.match-image-placeholder {
    padding: 10px;
    font-weight: 700;
    color: #111;
    text-align: center;
}

.match-word {
    width: clamp(110px, 18vw, 180px);
    height: auto;
    /* keep aspect ratio */
    aspect-ratio: 1 / 1;
    flex: 0 0 auto;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    /* remove default border so outlines can be used for states */
    border: none;
    /* ensure any inner content (like a square image) is clipped to the circular tile */
    overflow: hidden;
    font-weight: 700;
    /* responsive font size: slightly larger on medium+ screens */
    font-size: clamp(0.95rem, 2.2vw, 1.1rem);
    cursor: pointer;
    transition: box-shadow 120ms ease, transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

.match-word.matched {
    outline: 3px solid #2ecc71;
    outline-offset: 2px;
    background: #ffffff;
    cursor: default;
}

.match-word.wrong {
    /* Visual: flash an outer red outline + subtle red glow briefly on wrong answers */
    outline: 4px solid rgba(239, 68, 68, 0);
    outline-offset: 2px;
    animation: wrong-flash 420ms ease;
}

.match-word.flash-hint {
    /* solid cyan outline so it's fully opaque when flashing */
    outline: 5px solid #00BCD4;
    outline-offset: 2px;
    box-shadow: 0 6px 18px rgba(0, 188, 212, 0.18);
    animation: flash-accent 900ms ease-in-out infinite alternate;
}

@keyframes flash-accent {
    0% {
        outline-color: #00BCD4;
        box-shadow: 0 6px 12px rgba(0, 188, 212, 0.10);
    }

    50% {
        outline-color: #ffffff;
        box-shadow: 0 8px 22px rgba(255, 255, 255, 0.22);
    }

    100% {
        outline-color: #00BCD4;
        box-shadow: 0 6px 12px rgba(0, 188, 212, 0.10);
    }
}


/* overlay number label */
.image-overlay .overlay-number {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-weight: 700;
    color: #000000;
    font-size: clamp(1rem, 2.2vw, 1.5rem);
    pointer-events: none;
    user-select: none;
}

/* numbers toggle button in header */
.numbers-toggle-button {
    height: 38px;
    width: 50px;
    padding: 0;
    font-family: 'CustomMain', Arial, sans-serif;
    font-size: 1.05em;
    font-weight: 700;
    border: 1px solid #999;
    /* subtle gray border */
    border-radius: 12px;
    cursor: pointer;
    background-color: #3498db;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.numbers-toggle-button.active {
    background-color: #333333;
    /* dark gray when active */
}

.numbers-toggle-button:hover {
    background-color: #2980b9;
}

.image-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(0, 0, 0, 0.5);
    background: rgba(255, 255, 255, 0.6);
    border-radius: 8px;
    padding: 12px;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}

/* Text display styling */
.text-display {
    background: rgba(255, 255, 255, 80%);
    padding: 4px;
    box-sizing: border-box;
    min-height: 60px;
    flex-direction: column;
    gap: 6px;
    justify-content: center;
}

.text-display .drop-placeholder {
    color: rgba(0, 0, 0, 0.5);
    font-style: italic;
}

/* Ensure these styles apply even if  wrapper is missing */
.game-elements-container .text-display .drop-placeholder,
.text-display .drop-placeholder {
    color: rgba(0, 0, 0, 0.6);
    font-style: italic;
}

.text-display .text-line {
    font-size: clamp(1.2rem, 2.8vw, 2rem);
    font-weight: 700;
    color: #0f172a;
    text-align: center;
}

.control-and-answer-btns {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    max-width: 620px;
    margin: 0 auto;
}

.control-and-answer-btns[data-layout="phase-a"]>* {
    flex: 0 1 auto;
}

.control-and-answer-btns[data-layout="phase-b"] {
    align-items: center;
}

.control-and-answer-btns[data-layout="phase-b"]>.answer-button {
    flex: 1 1 calc(33.333% - 18px);
    max-width: calc(33.333% - 18px);
    min-width: 88px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* Quiz mode: allow buttons to be their natural width, only wrap when necessary */
.control-and-answer-btns[data-layout="phase-b"][data-mode="quiz"]>.answer-button {
    flex: 0 1 auto;
    max-width: none;
}

.next-button,
.answer-button {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    border: none;
    border-radius: 10px;
    color: #fff;
    padding: clamp(6px, 1.2vw, 10px) clamp(10px, 3vw, 18px);
    font-size: clamp(0.82rem, 2.4vw, 1rem);
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 12px rgba(37, 99, 235, 0.2);
    transition: background 0.15s ease, box-shadow 0.15s ease;
    min-height: 32px;
}

.next-button:hover,
.answer-button:hover {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
    box-shadow: 0 8px 16px rgba(30, 64, 175, 0.28);
}

.next-button:active,
.answer-button:active {
    background: linear-gradient(135deg, #1e3a8a, #1d4ed8);
    box-shadow: 0 4px 10px rgba(29, 78, 216, 0.25);
}

.answer-button.correct {
    background: linear-gradient(135deg, #16a34a, #15803d);
    box-shadow: 0 6px 12px rgba(22, 163, 74, 0.3);
}

.answer-button.incorrect {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    box-shadow: 0 6px 12px rgba(220, 38, 38, 0.3);
}

.answer-button:disabled {
    cursor: default;
    opacity: 0.85;
}

.speaker-button {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border: none;
    border-radius: 10px;
    color: #fff;
    padding: clamp(6px, 1.2vw, 10px) clamp(9px, 2.4vw, 14px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    box-shadow: 0 6px 12px rgba(217, 119, 6, 0.18);
    transition: background 0.15s ease, box-shadow 0.15s ease;
    min-height: 32px;
}

.speaker-button svg {
    display: block;
}

.speaker-button:hover {
    background: linear-gradient(135deg, #d97706, #b45309);
    box-shadow: 0 8px 16px rgba(180, 83, 9, 0.28);
}

.speaker-button:active {
    background: linear-gradient(135deg, #b45309, #92400e);
    box-shadow: 0 4px 10px rgba(146, 64, 14, 0.24);
}

/* Scale the emoji icon visually without changing button layout (transform doesn't affect layout) */
.speaker-button .speaker-emoji {
    display: inline-block;
    font-size: 18px;
    /* base size before scaling */
    line-height: 1;
    transform: scale(1.2);
    transform-origin: center;
    vertical-align: middle;
}

/* Tile and keyboard styles are defined in each game's CSS file */

.game-area {
    /* Generic game area style if needed, specific background handled above */
    position: relative;
    flex-grow: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}



/* Responsive grid for topic tiles */


.grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: minmax(80px, auto);
    gap: 10px;
    width: 100%;
    /* limit vertical growth so page chrome (start button / ads) remain visible */
    max-height: 300px;
    overflow: auto;
    overflow-x: hidden;
    padding: 5px;
}


/* Game visual assets and progress bar styles */

.progress-bar-container,
#progressBarContainer {
    background: transparent;
    position: relative;
    overflow: visible;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3px 0;
    height: 20px;
    min-height: 20px;
}

.progress-bar-container::before,
#progressBarContainer::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: repeating-linear-gradient(to right,
            #fff,
            #fff 20px,
            rgba(255, 255, 255, 0) 20px,
            rgba(255, 255, 255, 0) 40px);
    transform: translateY(-50%);
}

/* New progress road: two colors meet in the middle. The left side percent
   is set via the --left CSS variable by JS (e.g. --left: 60%). */
.progress-bar-container .progress-road,
#progressBarContainer .progress-road {
    width: 100%;
    height: 125%;
    overflow: hidden;
    position: relative;
    background: linear-gradient(to right, #3b82f6 0%, #3b82f6 var(--left, 50%), #ef4444 var(--left, 50%), #ef4444 100%);
}

/* Progress pusher image styling */
/* progress pusher removed for whats-the-word; keep style in other-game CSS files if needed */

/* Vehicle-specific rules are kept in each game's CSS; this file defines vocab visuals */

/* Inline warning styling for category selection */
.category-warning {
    color: #e74c3c;
    font-size: 0.9rem;
    margin-top: 4px;
    text-align: center;
    animation: fadeInOut 2s ease;
}

.warning-border {
    border: 2px solid #e74c3c !important;
}

@keyframes fadeInOut {
    0% {
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    90% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

/* Styles for topic tiles */
.topics-box {
    background-color: #ccc;
    color: #555;
    aspect-ratio: 1 / 1;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    cursor: pointer;
    font-size: clamp(1em, 3vw, 1.8em);
    font-weight: 600;
    font-family: 'CustomMain', Arial, sans-serif;
    text-transform: uppercase;
    transition: background-color 0.2s ease, transform 0.1s ease;
    user-select: none;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    position: relative;
}

/* Info button styling to mirror parts-of-speech selection */
.topics-box .info-button {
    position: absolute;
    top: -8px;
    right: -8px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    cursor: pointer;
}

.selection-screen * {
    /* Alias placeholder rules to preserve specificity for selection screen */
    grid-auto-rows: 60px;
}

.topics-box.selected {
    background: linear-gradient(90deg, #3498db, #2980b9);
    color: #fff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.topics-box:hover:not(.selected) {
    background-color: #bbb;
    transform: scale(1.03);
}

/* Ensure grid cells size similarly to original selection boxes */
.topics-box,
.topics-box {
    width: 100%;
    height: 100%;
    white-space: normal;
    padding: clamp(5px, 1vw, 10px);
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    font-size: clamp(0.8rem, 2vw, 1.1rem);
    line-height: 1.2;
    word-break: break-word;
    hyphens: auto;
    font-family: Arial, sans-serif;
    aspect-ratio: auto !important;
}

/* Ensure topic tiles use capitalization regardless of global rules */
.topics-box {
    text-transform: capitalize !important;
}

@media (min-width: 601px) {
    .topics-box {
        width: 95%;
        margin: 0 auto;
    }
}

/* temporary hand prompt shown over the overlay to hint user to click a square */
.image-overlay .overlay-hand {
    position: absolute;
    right: 12px;
    bottom: 12px;
    font-size: clamp(1.2rem, 2.6vw, 2rem);
    line-height: 1;
    background: transparent;
    /* no white background */
    color: #fff;
    /* white hand for visibility on images */
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
    border-radius: 10px;
    padding: 0;
    /* no padding so it's just the emoji */
    pointer-events: none;
    user-select: none;
    z-index: 30;
}

/* simple hand bob animation used when shown briefly - faster and smaller travel */
@keyframes hand-bob {
    0% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }

    100% {
        transform: translateY(0);
    }
}

/* centered hand bob keeps the centering transform while animating */
@keyframes hand-bob-centered {
    0% {
        transform: translate(-50%, -50%) translateY(0);
    }

    50% {
        transform: translate(-50%, -50%) translateY(-6px);
    }

    100% {
        transform: translate(-50%, -50%) translateY(0);
    }
}

.image-overlay .overlay-hand {
    /* default placement (fallback) uses small bob once */
    animation: hand-bob 800ms ease-in-out 1;
    font-size: clamp(1.2rem, 2.6vw, 2rem);
}

/* When the hand is placed inside an overlay-square, center it and make it slightly larger */
.image-overlay .overlay-square>.overlay-hand {
    left: 50%;
    top: 50%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, -50%);
    font-size: clamp(1.6rem, 3.8vw, 2.6rem);
    animation: hand-bob-centered 700ms ease-in-out 1;
}

/* Match-mode specific adjustments so the image area expands and the dark overlay is removed */
.image-display.match-mode {
    background: none !important;
    min-height: 100% !important;
}

@media (max-width: 480px) {

    .match-image,
    .match-word {
        width: clamp(100px, 20vw, 110px);
    }

    .match-image-img {
        width: 80%;
        height: 80%;
    }
}

@media (min-width: 900px) {
    .match-word {
        font-size: clamp(1.15rem, 1.6vw, 1.45rem);
    }
}

/* Hover on the circular image tile: inner shadow on the circle (not affecting the inner image). */
.match-image::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    z-index: 2;
    box-shadow: none;
    transition: box-shadow 140ms ease;
}

.match-image:not(.dragging):not(.matched):hover::after {
    box-shadow: inset 0 6px 18px rgba(0, 0, 0, 0.26);
}

/* Red outline flash for wrong answers in match mode */
@keyframes wrong-flash {
    0% {
        outline-color: rgba(239, 68, 68, 0);
        box-shadow: none;
        transform: none;
    }

    40% {
        outline-color: rgba(239, 68, 68, 1);
        box-shadow: 0 6px 18px rgba(239, 68, 68, 0.25);
        transform: scale(1.02);
    }

    100% {
        outline-color: rgba(239, 68, 68, 0);
        box-shadow: none;
        transform: none;
    }
}
