/* Center area in header used for word-search hint button; keep layout local to this game */
.word-search-game .game-header-center {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
}

/* Hint button: match timer display sizing and visual rhythm but keep styling local */
.word-search-game .hint-button {
    height: 44px;
    /* same height as timer-display */
    box-sizing: border-box;
    padding: 5px 15px;
    /* same as timer-display */
    border-radius: 12px;
    background-color: #3498db;
    /* blue */
    color: #fff;
    font-size: 1.4em;
    /* match timer font size */
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    /* no borders per request */
    transition: background-color 0.15s ease, box-shadow 0.12s ease, transform 0.08s ease;
    user-select: none;
}

/* Hover: darker blue and subtle inner-shadow illusion */
.word-search-game .hint-button:hover {
    background-color: #2574c8;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.12);
    transform: translateY(-1px);
}

.word-search-game .hint-button:active {
    background-color: #1f66b0;
    box-shadow: inset 0 6px 12px rgba(0, 0, 0, 0.18);
    transform: translateY(0);
}

/* When hint is unavailable briefly pulse to indicate no-op */
.word-search-game .hint-button.hint-empty {
    animation: hint-empty-pulse 340ms ease-in-out;
}

@keyframes hint-empty-pulse {
    0% {
        transform: scale(1);
    }

    40% {
        transform: scale(1.08);
    }

    100% {
        transform: scale(1);
    }
}

/* Highlight animation for a grid cell when hint flashes. No borders, only background change */
.word-search-game .word-search-cell.hint-flash {
    /* Simple flash: single dark background color with white text; transition keeps it smooth */
    background: #0b2745 !important;
    color: #ffffff !important;
    box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.6), 0 6px 14px rgba(0, 0, 0, 0.14);
    transform: scale(1.02);
    transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

/* 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/word-search/word-search-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;
}

/* 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;
}

.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="gameplay"]>* {
    flex: 0 1 auto;
}

.control-and-answer-btns[data-layout="gameplay"]>* {
    flex: 0 1 auto;
}

.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;
    /* changed both sides to grass green */
    background: linear-gradient(to right, #22c55e 0%, #22c55e var(--left, 50%), #22c55e var(--left, 50%), #22c55e 100%);
}

/* Progress pusher image styling */
.progress-bar-container .progress-road .progress-pusher,
#progressBarContainer .progress-road .progress-pusher {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    height: 25px;
    width: auto;
    z-index: 10;
    pointer-events: none;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.3));
    transition: left 0.3s ease-out;
}

/* 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;
    }
}

/* Word search grid (rows x cols) - responsive, centered */
.word-search-grid {
    display: grid;
    gap: 1px;
    /* allow rectangular grids; aspect ratio is set inline by game JS when needed */
    aspect-ratio: auto;
    max-width: 100%;
    box-sizing: border-box;
    align-self: center;
    justify-self: center;
    grid-auto-rows: 1fr;
    /* ensure rows match column fractions so cells are squares */
}

.word-search-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    user-select: none;
    cursor: default;
    font-weight: 700;
    color: #0f172a;
    font-size: clamp(0.9rem, 2.2vmin, 1.4rem);
    /* Ensure each cell is a perfect square and fills its grid area */
    width: 100%;
    height: 100%;
    /* Mobile default: prefer 37px squares but allow shrinking on short screens */
    min-width: 9vw;
    min-height: 9vw;
    max-width: 37px;
    max-height: 37px;
    box-sizing: border-box;
}

@media (min-width: 601px) {
    .word-search-cell {
        min-width: 40px;
        min-height: 40px;
        max-width: 40px;
        max-height: 40px;
        font-size: clamp(1rem, 2.2vmin, 1.6rem);
    }
}

/* Top images area above grid for gameplay previews */
.word-search-top {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin-bottom: 10px;
    box-sizing: border-box;
    padding: 0 8px;
    /* give a little side padding so images don't hug grid edges */
}

.word-search-top-img-wrap {
    width: 96px;
    /* make the image area a perfect square and place caption below */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    padding: 4px;
}

.word-search-top-img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    display: block;
    border-radius: 6px;
    cursor: pointer;
}

/* captions removed for gameplay — no visible word text */

@media (max-width: 600px) {
    .word-search-top-img-wrap {
        width: 64px;
        padding: 4px;
        gap: 4px;
    }

    .word-search-top-img {
        border-radius: 4px;
    }
}

.word-search-top-img-wrap.found {
    outline: 3px solid rgba(46, 204, 113, 0.9);
}

/* When a top image audio is playing, show a blue outline (no animation) */
.word-search-top-img-wrap.playing {
    outline: 3px solid rgba(59, 130, 246, 0.95);
}

/* Hand CTA that appears centered and pointing up on the top image to
   indicate it can be clicked. This is displayed for a brief time with
   a gentle bounce animation. Pointer-events are disabled so it won't
   interfere with clicking the image itself. */
.word-search-top-img-wrap .top-hand {
    position: absolute;
    left: 50%;
    top: 50%;
    /* Align the top of the hand at the center of the image */
    transform: translate(-50%, 0);
    width: 48px;
    height: 48px;
    display: none;
    /* shown via JS */
    z-index: 1200;
    pointer-events: none;
    /* do not block clicks */
    opacity: 0;
    /* invisible by default */
}

.word-search-top-img-wrap .top-hand.visible {
    display: block;
    opacity: 1;
    animation: hand-bounce 2s ease-in-out 1;
    /* animate each appearance */
}

@keyframes hand-bounce {
    0% {
        transform: translate(-50%, -10%) scale(0.93);
    }

    25% {
        transform: translate(-50%, -6%) scale(1.06);
    }

    50% {
        transform: translate(-50%, -4%) scale(1);
    }

    75% {
        transform: translate(-50%, -2%) scale(1.03);
    }

    100% {
        transform: translate(-50%, 0) scale(1);
    }
}

/* Provide a monochrome upward-pointing hand as an inline SVG fill. */
.word-search-top-img-wrap .top-hand .hand-emoji {
    display: inline-block;
    width: 100%;
    height: 100%;
    font-size: 32px;
    line-height: 1;
    text-align: center;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}

/* Popup showing the original word text while top-image audio plays */
.word-search-word-popup {
    position: absolute;
    z-index: 1200;
    left: 0;
    /* positioned via JS */
    top: 0;
    /* positioned via JS */
    padding: 12px 16px;
    background: rgba(15, 23, 42, 0.95);
    color: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.32);
    font-weight: 800;
    font-size: clamp(1.0rem, 2.4vw, 1.4rem);
    letter-spacing: 0.02em;
    pointer-events: none;
    white-space: normal;
    text-align: center;
    overflow: hidden;
    display: none;
}

.word-search-cell.selected {
    /* remove blue outline — keep a subtle inset glow only */
    outline: none;
    box-shadow: 0 0 6px rgba(59, 130, 246, 0.06) inset;
}

/* When the user is dragging, render cells as circles and selected letters as orange */
.word-search-grid.dragging .word-search-cell {
    border-radius: 50%;
    transition: background 120ms ease, transform 120ms ease, color 120ms ease;
}

/* Prevent page scroll while dragging on touch devices and discourage text selection */
.word-search-grid.dragging {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.word-search-grid.dragging .word-search-cell.selected {
    background: linear-gradient(180deg, #ff9b3b, #ff7a00);
    color: #fff;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.18);
    outline: none;
    /* ensure outline removed during dragging */
}

.word-search-cell.found {
    background: linear-gradient(135deg, #e6ffed, #d4ffe6);
    color: #0b6b2b;
}

/* Per-word found colors (override .found) */
.word-search-cell.found-blue {
    background: linear-gradient(135deg, #cfe9ff, #8fbffb);
    color: #042a6b;
    /* dark-blue text for contrast */
}

.word-search-cell.found-red {
    background: linear-gradient(135deg, #ffd9d9, #ff9b9b);
    color: #6b0202;
    /* dark-red text for contrast */
}

.word-search-cell.found-purple {
    background: linear-gradient(135deg, #f1e6ff, #d8b7ff);
    color: #3b0b6b;
    /* dark purple text */
}

.word-search-cell.invalid {
    animation: flash-invalid 260ms ease;
}

@keyframes flash-invalid {
    0% {
        transform: translateY(-2px);
    }

    50% {
        transform: translateY(2px);
    }

    100% {
        transform: translateY(0);
    }
}

/* Shrink grid on short mobile screens so it doesn't get cut off */
@media (max-width: 600px) and (max-height: 700px) {
    .word-search-grid {
        width: calc(65vh - 170px);
        max-width: 90vw;
    }

    /* allow cells to shrink further on very short screens */
    .word-search-cell {
        min-width: 20px;
        min-height: 20px;
    }
}

/* Responsive sizing to match .timer-display in common.css at same breakpoints (local only) */
@media (max-width: 1024px) {
    .word-search-game .hint-button {
        height: 40px;
        font-size: 1.2em;
    }
}

@media (max-width: 768px) {
    .word-search-game .hint-button {
        height: 38px;
    }
}

@media (max-width: 480px) {
    .word-search-game .hint-button {
        height: 36px;
        font-size: 1em;
        padding: 3px 8px;
    }
}

/* Goal icons at the start and end of the progress road */
.progress-bar-container .progress-road .progress-goal-left,
#progressBarContainer .progress-road .progress-goal-left,
.progress-bar-container .progress-road .progress-goal-right,
#progressBarContainer .progress-road .progress-goal-right {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 35px;
    width: auto;
    z-index: 11;
    pointer-events: none;
}

.progress-bar-container .progress-road .progress-goal-left,
#progressBarContainer .progress-road .progress-goal-left {
    left: -18px;
    transform: translate(0, -50%);
}

.progress-bar-container .progress-road .progress-goal-right,
#progressBarContainer .progress-road .progress-goal-right {
    right: -18px;
    transform: translate(0, -50%);
}
