:root {
    --word-search-primary: #c125fa;
    --word-search-primary-dark: #9e18d1;
    --word-search-primary-soft: #f3f4f6;
    --word-search-text: #252525;
    --word-search-muted: #6b7280;
    --word-search-border: #d9dde3;
    --word-search-surface: #ffffff;
    --word-search-page: #f3f4f6;
    --word-search-cell: #f8f9fb;
    --word-search-cell-hover: #eceff3;
    --word-search-found: #22a35a;
    --word-search-success: #48ad61;
    --word-search-danger: #df5757;
}

* {
    box-sizing: border-box;
}

/* O Caça-Palavras usa somente cores sólidas. */
.word-search-layout,
.word-search-layout * {
    background-image: none !important;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    min-height: 100vh;
    background: var(--word-search-page);
    color: var(--word-search-text);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.word-search-layout {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.word-search-layout,
.word-search-page,
.word-search-shell {
    background: transparent;
}

.word-search-page {
    background: var(--word-search-page);
}

.word-search-brand-header {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    background: var(--word-search-primary);
    box-shadow: 0 4px 14px rgba(79, 16, 99, 0.18);
}

.word-search-brand-logo {
    width: auto;
    height: 38px;
    object-fit: contain;
}

.word-search-page {
    flex: 1;
    width: 100%;
    padding: 22px 18px 28px;
}

.word-search-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
}

.word-search-left-column {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.word-search-question-area {
    width: 100%;
    margin: 0;
}

.word-search-question-area #question-container {
    width: 100%;
    max-width: none;
    margin: 0;
    background: #ffffff;
}

.word-search-question-area .question-label {
    background: var(--word-search-primary);
}

.word-search-question-area .question-label-icon {
    background: #ffffff !important;
    color: #111827 !important;
    border: 1px solid rgba(255, 255, 255, 0.72);
}

.word-search-question-area.game-question-standard {
    position: static !important;
    inset: auto !important;
    transform: none !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    background: transparent !important;
}

.word-search-question-area.game-question-standard #question-container {
    position: relative !important;
    inset: auto !important;
    transform: none !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    margin: 0 !important;
    z-index: 1 !important;
    box-sizing: border-box !important;
    overflow: visible !important;
}

.word-search-question-area .question-label {
    top: 0 !important;
    left: 18px !important;
    z-index: 5 !important;
    transform: translateY(-50%) !important;
    background: var(--word-search-primary) !important;
    color: #ffffff !important;
    overflow: visible !important;
}

.word-search-question-area .question-label-icon {
    background: #ffffff !important;
    color: #111827 !important;
}

.word-search-question-area-empty {
    max-width: 720px;
    margin: 0 auto 18px;
}

.word-search-question-text {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
}

.word-search-question-text.is-expanded-for-measurement {
    display: block;
    -webkit-line-clamp: unset;
}

.word-search-game {
    display: grid;
    grid-template-columns: minmax(320px, 0.82fr) minmax(0, 1.18fr);
    gap: 18px;
    align-items: start;
}

.word-search-game > * {
    min-width: 0;
}

.word-search-right-column {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.word-search-board-panel {
    position: relative;
    z-index: 0;
}

.word-search-clues-panel,
.word-search-board-panel,
.word-search-empty-state {
    border: 1px solid var(--word-search-border);
    border-radius: 18px;
    background: var(--word-search-surface);
    box-shadow: 0 7px 22px rgba(31, 41, 55, 0.08);
}

.word-search-clues-panel {
    padding: 20px;
}

.word-search-board-panel {
    min-width: 0;
    padding: 12px;
}

.word-search-panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
}

.word-search-kicker {
    display: block;
    margin-bottom: 4px;
    color: var(--word-search-primary);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.75px;
    text-transform: uppercase;
}

.word-search-panel-heading h1 {
    margin: 0;
    color: var(--word-search-text);
    font-size: 20px;
    font-weight: 700;
    line-height: 1.2;
}

.word-search-progress {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 5px 10px;
    border: 1px solid #d9dde3;
    border-radius: 999px;
    background: var(--word-search-primary-soft);
    color: #374151;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.word-search-found-outside {
    display: flex;
    justify-content: center;
    padding-top: 9px;
}

.word-search-found-label {
    display: inline-block;
    color: #4b5563;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.3;
    white-space: nowrap;
}

.word-search-help {
    margin: 0 0 16px;
    color: var(--word-search-muted);
    font-size: 13px;
    font-weight: 400;
    line-height: 1.45;
}

.word-search-clues {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 560px;
    overflow-y: auto;
    padding-right: 4px;
}

.word-search-clues::-webkit-scrollbar {
    width: 6px;
}

.word-search-clues::-webkit-scrollbar-track {
    border-radius: 999px;
    background: #e9ecef;
}

.word-search-clues::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #bfc5cd;
}

.word-search-clue {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr) 24px;
    gap: 10px;
    align-items: center;
    min-height: 52px;
    padding: 10px 12px;
    border: 1px solid #dce0e5;
    border-radius: 12px;
    background: #ffffff;
    transition:
        border-color 0.2s ease,
        background 0.2s ease,
        transform 0.2s ease;
}

.word-search-clue-number {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #edf0f3;
    color: #4b5563;
    font-size: 12px;
    font-weight: 700;
}

.word-search-clue-text {
    min-width: 0;
    color: var(--word-search-text);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.38;
    overflow-wrap: anywhere;
}

.word-search-clue-check {
    opacity: 0;
    color: #ffffff;
    font-size: 15px;
    font-weight: 700;
    text-align: center;
}

.word-search-clue.found {
    border-color: var(--word-search-primary);
    background: var(--word-search-primary);
    transform: translateY(-1px);
}

.word-search-clue.found .word-search-clue-number {
    background: rgba(255, 255, 255, 0.22);
    color: #ffffff;
}

.word-search-clue.found .word-search-clue-text {
    color: #ffffff;
    text-decoration: line-through;
    text-decoration-thickness: 1px;
}

.word-search-clue.found .word-search-clue-check {
    opacity: 1;
}

.word-search-board-scroll {
    width: 100%;
    overflow: visible;
    padding: 0;
}

.word-search-grid {
    --word-search-cols: 13;
    display: grid;
    grid-template-columns: repeat(var(--word-search-cols), minmax(0, 1fr));
    gap: 3px;
    width: min(
        100%,
        580px,
        calc((100vh - 230px) * 13 / 14)
    );
    min-width: 0;
    margin: 0 auto;
    user-select: none;
    touch-action: manipulation;
}

.word-search-cell {
    position: relative;
    aspect-ratio: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid #dfe3e8;
    border-radius: 6px;
    background: var(--word-search-cell);
    color: #403544;
    cursor: pointer;
    font-family: Arial, Helvetica, sans-serif;
    font-size: clamp(13px, 1.35vw, 17px);
    font-weight: 700;
    line-height: 1;
    transition:
        transform 0.12s ease,
        background 0.16s ease,
        color 0.16s ease,
        border-color 0.16s ease,
        box-shadow 0.16s ease;
}

.word-search-cell:hover:not(:disabled) {
    border-color: #b8c0cc;
    background: var(--word-search-cell-hover);
    color: #1f2937 !important;
    transform: translateY(-1px);
}

.word-search-cell.selected:hover:not(:disabled) {
    border-color: var(--word-search-primary);
    background: var(--word-search-primary);
    color: #ffffff !important;
}

.word-search-cell.found:hover {
    border-color: var(--word-search-found);
    background: var(--word-search-found);
    color: #ffffff !important;
}

.word-search-cell.selected {
    border-color: var(--word-search-primary);
    background: var(--word-search-primary);
    color: #ffffff;
    box-shadow: 0 3px 8px rgba(193, 37, 250, 0.24);
    transform: scale(0.97);
}

.word-search-cell.found {
    border-color: var(--word-search-found);
    background: var(--word-search-found);
    color: #ffffff;
}

.word-search-cell.found.selected {
    outline: 3px solid rgba(72, 173, 97, 0.55);
    outline-offset: -2px;
}

.word-search-cell:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.25);
    outline-offset: 2px;
}

.word-search-cell:disabled {
    cursor: default;
}

.word-search-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
}

.word-search-next-button {
    min-height: 40px;
    padding: 9px 16px;
    border: 0;
    border-radius: 10px;
    background: var(--word-search-primary);
    color: #ffffff;
    cursor: pointer;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 5px 14px rgba(193, 37, 250, 0.22);
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease;
}

.word-search-next-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 7px 17px rgba(193, 37, 250, 0.28);
}

.word-search-next-button:disabled {
    opacity: 0.62;
    cursor: wait;
    transform: none;
}

.word-search-empty-state {
    max-width: 720px;
    margin: 24px auto 0;
    padding: 24px;
    text-align: center;
}

.word-search-empty-state strong {
    display: block;
    margin-bottom: 7px;
    color: #374151;
    font-size: 18px;
}

.word-search-empty-state p {
    margin: 0;
    color: var(--word-search-muted);
    font-size: 14px;
}

.word-search-toast-container {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 4000;
    width: min(360px, calc(100vw - 36px));
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.word-search-toast {
    transform: translateY(14px);
    opacity: 0;
    padding: 12px 14px;
    border: 1px solid #d9dde3;
    border-radius: 12px;
    background: #ffffff;
    color: var(--word-search-text);
    box-shadow: 0 9px 26px rgba(31, 41, 55, 0.16);
    transition:
        opacity 0.22s ease,
        transform 0.22s ease;
}

.word-search-toast.show {
    transform: translateY(0);
    opacity: 1;
}

.word-search-toast strong {
    display: block;
    margin-bottom: 2px;
    color: #374151;
    font-size: 14px;
}

.word-search-toast span {
    display: block;
    color: var(--word-search-muted);
    font-size: 13px;
    line-height: 1.35;
}

.platform-footer {
    margin-top: auto;
    padding: 14px 18px;
    background: #8f16bc;
    color: #ffffff;
    text-align: center;
}

.platform-footer p {
    margin: 0;
    font-size: 12px;
    font-weight: 400;
}

@media (max-width: 900px) {
    .word-search-page {
        padding: 18px 12px 24px;
    }

    .word-search-game {
        grid-template-columns: 1fr;
    }

    .word-search-clues-panel,
    .word-search-board-panel {
        padding: 16px;
    }

    .word-search-clues {
        max-height: 320px;
    }
}

@media (max-width: 640px) {
    .word-search-brand-header {
        min-height: 56px;
    }

    .word-search-brand-logo {
        height: 32px;
    }

    .word-search-panel-heading {
        align-items: center;
    }

    .word-search-panel-heading h1 {
        font-size: 18px;
    }

    .word-search-board-scroll {
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .word-search-grid {
        gap: 2px;
        grid-template-columns: repeat(var(--word-search-cols), minmax(23px, 1fr));
        width: min(100%, 430px);
        min-width: calc(var(--word-search-cols) * 25px);
    }

    .word-search-cell {
        border-radius: 5px;
        font-size: 12px;
    }

    .word-search-toast-container {
        right: 12px;
        bottom: 12px;
        width: calc(100vw - 24px);
    }
}


@media (min-width: 901px) and (max-height: 820px) {
    .word-search-board-panel {
        padding: 10px;
    }

    .word-search-grid {
        width: min(
            100%,
            560px,
            calc((100vh - 220px) * 13 / 14)
        );
        gap: 2px;
        grid-template-columns: repeat(var(--word-search-cols), minmax(0, 1fr));
        min-width: 0;
    }

    .word-search-cell {
        font-size: clamp(14px, 1.3vw, 17px);
    }

    .word-search-actions {
        margin-top: 8px;
    }
}

/* Garante que o atributo HTML hidden prevaleça sobre componentes compartilhados. */
.word-search-layout [hidden],
#wordSearchTextModal[hidden],
.word-search-toast-container[hidden] {
    display: none !important;
}

/* =========================================================
   V20.6 - painel direito mais compacto + contador em cápsula
   ========================================================= */

@media (min-width: 901px) {
    .word-search-right-column {
        align-items: center;
    }

    .word-search-board-panel {
        width: min(100%, 610px);
        align-self: center;
    }

    .word-search-found-outside {
        width: min(100%, 610px);
        align-self: center;
        justify-content: flex-end;
        padding-top: 10px;
    }
}

.word-search-found-outside {
    display: flex;
    justify-content: flex-end;
}

.word-search-found-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 6px 12px;
    border: 1px solid #d9dde3;
    border-radius: 999px;
    background: #ffffff;
    color: #374151;
    box-shadow: 0 3px 10px rgba(31, 41, 55, 0.08);
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

@media (min-width: 901px) and (max-height: 820px) {
    .word-search-board-panel,
    .word-search-found-outside {
        width: min(100%, 590px);
    }
}

/* =========================================================
   V20.7 - caixa da grade mais estreita e colunas mais proximas
   ========================================================= */

@media (min-width: 901px) {
    /* Mantem o tamanho da coluna esquerda, mas reduz o vao visual. */
    .word-search-game {
        gap: 12px;
    }

    /* A grade deixa de ficar centralizada dentro da coluna direita. */
    .word-search-right-column {
        align-items: flex-start;
    }

    /* Caixa mais justa em volta do caca-palavras. */
    .word-search-board-panel {
        width: min(100%, 575px);
        align-self: flex-start;
        padding: 9px;
    }

    /* A grade continua grande, usando quase toda a caixa. */
    .word-search-grid {
        width: min(
            100%,
            557px,
            calc((100vh - 230px) * 13 / 14)
        );
        margin: 0 auto;
    }

    /* O contador acompanha exatamente a largura da caixa da grade. */
    .word-search-found-outside {
        width: min(100%, 575px);
        align-self: flex-start;
        justify-content: flex-end;
        padding-top: 10px;
    }
}

@media (min-width: 901px) and (max-height: 820px) {
    .word-search-board-panel,
    .word-search-found-outside {
        width: min(100%, 560px);
    }

    .word-search-board-panel {
        padding: 8px;
    }

    .word-search-grid {
        width: min(
            100%,
            544px,
            calc((100vh - 220px) * 13 / 14)
        );
    }
}

/* =========================================================
   V20.8 - caixa do caca-palavras justa ao tamanho real da grade
   ========================================================= */

@media (min-width: 901px) {
    .word-search-right-column {
        align-items: flex-start !important;
    }

    /*
     * A caixa nao ocupa mais uma largura fixa da coluna.
     * Ela passa a medir somente o necessario para envolver a grade.
     */
    .word-search-board-panel {
        display: inline-block !important;
        width: fit-content !important;
        max-width: 100% !important;
        align-self: flex-start !important;
        padding: 8px !important;
    }

    .word-search-board-scroll {
        width: fit-content !important;
        max-width: 100% !important;
    }

    /* Mantem a grade grande; somente a caixa externa fica justa. */
    .word-search-grid {
        width: min(
            557px,
            calc((100vh - 230px) * 13 / 14)
        ) !important;
        max-width: 100% !important;
        margin: 0 !important;
    }

    /* Contador acompanha a largura real da caixa/grade. */
    .word-search-found-outside {
        width: min(
            573px,
            calc((100vh - 230px) * 13 / 14 + 16px)
        ) !important;
        max-width: 100% !important;
        align-self: flex-start !important;
        justify-content: flex-end !important;
        padding-top: 10px !important;
    }
}

@media (min-width: 901px) and (max-height: 820px) {
    .word-search-board-panel {
        padding: 7px !important;
    }

    .word-search-grid {
        width: min(
            544px,
            calc((100vh - 220px) * 13 / 14)
        ) !important;
    }

    .word-search-found-outside {
        width: min(
            558px,
            calc((100vh - 220px) * 13 / 14 + 14px)
        ) !important;
    }
}

/* =========================================================
   V20.9 - grade maior, letras maiores e contador removido
   ========================================================= */

/*
 * O contador continua no DOM apenas para manter compatibilidade com o
 * JavaScript atual, mas deixa de ocupar qualquer espaco visual.
 */
.word-search-found-outside {
    display: none !important;
}

@media (min-width: 901px) {
    /*
     * Aumenta a caixa da pergunta somente em altura.
     * A largura da coluna esquerda e o painel de dicas permanecem iguais.
     */
    .word-search-question-area #question-container {
        min-height: 114px !important;
    }

    /*
     * A caixa do caca-palavras continua justa ao conteudo, mas ganha
     * um pouco mais de area interna nas duas direcoes.
     */
    .word-search-board-panel {
        width: fit-content !important;
        max-width: 100% !important;
        padding: 8px !important;
    }

    .word-search-board-scroll {
        width: fit-content !important;
        max-width: 100% !important;
    }

    /*
     * Como cada celula e quadrada, aumentar a largura da grade aumenta
     * tambem sua altura proporcionalmente, sem distorcer as letras.
     */
    .word-search-grid {
        width: min(
            590px,
            calc((100vh - 195px) * 13 / 14)
        ) !important;
        max-width: 100% !important;
        gap: 3px !important;
        margin: 0 !important;
    }

    .word-search-cell {
        border-radius: 7px;
        font-size: clamp(15px, 1.45vw, 19px) !important;
    }

    .word-search-cell:hover:not(:disabled) {
        color: #1f2937 !important;
    }

    .word-search-cell.selected:hover:not(:disabled),
    .word-search-cell.found:hover {
        color: #ffffff !important;
    }
}

@media (min-width: 901px) and (max-height: 820px) {
    .word-search-question-area #question-container {
        min-height: 108px !important;
    }

    .word-search-grid {
        width: min(
            575px,
            calc((100vh - 185px) * 13 / 14)
        ) !important;
        gap: 3px !important;
    }

    .word-search-cell {
        font-size: clamp(15px, 1.4vw, 18px) !important;
    }
}

/* =========================================================
   V20.10 - pequeno espaco entre letras + alinhamento inferior
   ========================================================= */

@media (min-width: 901px) {
    /*
     * Faz as duas colunas ocuparem a mesma altura. A coluna esquerda
     * passa a acompanhar a altura real do painel do caca-palavras.
     */
    .word-search-game {
        align-items: stretch !important;
    }

    .word-search-left-column {
        height: 100%;
        align-self: stretch;
    }

    /*
     * A caixa de dicas cresce somente no espaco restante abaixo da
     * pergunta, fazendo sua borda inferior alinhar com a caixa da grade.
     */
    .word-search-clues-panel {
        flex: 1 1 auto;
        min-height: 0;
    }

    /*
     * Pequeno respiro entre as celulas para as letras nao parecerem
     * coladas umas nas outras.
     */
    .word-search-grid {
        gap: 5px !important;
    }
}

@media (min-width: 901px) and (max-height: 820px) {
    .word-search-grid {
        gap: 4px !important;
    }
}

/* =========================================================
   V20.11 - espacamento uniforme da caixa + letras sem negrito
   ========================================================= */

/*
 * Durante a partida o botao de proxima atividade fica oculto.
 * O container dele mantinha uma margem vazia abaixo da grade,
 * fazendo o espaco inferior parecer maior que os demais lados.
 */
.word-search-actions:has(.word-search-next-button[hidden]) {
    display: none !important;
    margin-top: 0 !important;
}

/* Letras da grade com peso normal, mantendo o tamanho atual. */
.word-search-cell {
    font-weight: 400 !important;
}

@media (min-width: 901px) {
    /* Mesmo respiro em cima, direita, baixo e esquerda. */
    .word-search-board-panel {
        padding: 16px !important;
    }
}

@media (min-width: 901px) and (max-height: 820px) {
    /* Mantem o mesmo espacamento mesmo em telas mais baixas. */
    .word-search-board-panel {
        padding: 16px !important;
    }
}
