:root {
    --bg-color: #0F172A;
    --bg-board: #0F172A;
    --color-correct: #3aa394;
    --color-present: #d3ad69;
    --color-absent: #312a2c;
    --color-empty: #4c4347;
    --color-text: #ffffff;
    --color-border-focus: #4c4347;

    --key-bg: #4c4347;
    --key-text: #ffffff;

    --modal-bg: #292325;
    --modal-overlay: rgba(0, 0, 0, 0.7);

    /* Variáveis dinâmicas para tamanho dos blocos */
    --block-size: 60px;
    --gap-size: 6px;
    --font-size-tile: 2rem;
}

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

html {
    height: 100%;
}

body {
    font-family: 'M PLUS Rounded 1c', sans-serif;
    background-color: var(--bg-color);
    color: var(--color-text);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    height: 100%;
    height: 100dvh;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed; /* Previne scroll do body no Safari iOS */
}

/* Header */
header {
    width: 100%;
    max-width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    height: 60px;
    flex-shrink: 0;
    background-color: #000;
}

@media (max-width: 600px) {
    header {
        height: 45px;
        padding: 5px 10px;
    }
}

header h1 {
    font-size: 2rem;
    letter-spacing: 4px;
    margin: 0;
    text-align: center;
    line-height: 1;
}

/* Global utility to hide elements */
.hidden {
    display: none !important;
}

/* Hide static hint panels removed - now handled by media queries */

@media (max-width: 600px) {
    header h1 {
        font-size: clamp(0.9rem, 4.5vw, 1.4rem);
        letter-spacing: 1px;
        white-space: nowrap;
    }
}

.header-left,
.header-center,
.header-right {
    display: flex;
    align-items: center;
    z-index: 10;
}

.header-left {
    flex: 1;
    justify-content: flex-start;
    gap: 10px;
}

.header-center {
    flex: 2;
    justify-content: center;
    gap: 12px;
}

.header-right {
    flex: 1;
    justify-content: flex-end;
    gap: 10px;
}

#header-finish-btn {
    background-color: var(--color-correct);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: transform 0.2s, background-color 0.2s;
}

#header-finish-btn:hover {
    transform: scale(1.1);
    background-color: #3aa394;
}

@media (max-width: 600px) {
    .header-left, .header-right {
        flex: 0 0 auto;
        gap: 5px;
    }
    .header-center {
        flex: 1;
        min-width: 0; /* Permite que o título encolha com ellipsis se necessário */
    }
    header h1 {
        font-size: clamp(0.7rem, 4.5vw, 1.25rem);
        letter-spacing: 0.5px;
        line-height: 0.9;
    }
}

#mode-toggle {
    background: none;
    border: none;
    color: var(--color-text);
    font-family: inherit;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

#mode-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.arrow {
    font-size: 0.8rem;
    transition: transform 0.3s;
}

#mode-toggle.open .arrow {
    transform: rotate(180deg);
}

#mode-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background-color: var(--modal-bg);
    border: 1px solid #4c4347;
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    margin-top: 10px;
    min-width: 150px;
    z-index: 1000;
}

#mode-menu.hidden {
    display: none;
}

.mode-btn {
    background-color: transparent;
    border: 2px solid #4c4347;
    color: #ccc;
    font-family: inherit;
    font-weight: 700;
    font-size: 1rem;
    padding: 12px 20px;
    border-radius: 6px;
    cursor: pointer;
    text-align: center;
    width: 100%;
    transition: all 0.2s;
}

.mode-btn:hover {
    border-color: #888;
    color: #fff;
}

/* Termo Dropdown Selector */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown.hidden {
    display: none !important;
}

#current-termo-mode,
#current-crossword-mode {
    background: rgba(0, 0, 0, 0.3);
    color: white;
    padding: 8px 12px;
    font-size: 0.9rem;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

#current-termo-mode:hover {
    background: rgba(255, 255, 255, 0.1);
}

.dropdown-content {
    position: absolute;
    top: 100%;
    left: 0;
    background-color: var(--modal-bg);
    min-width: 120px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    padding: 5px;
    z-index: 2000;
    border: 1px solid #3a3a3a;
    margin-top: 5px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dropdown-content.hidden {
    display: none;
}

.sub-mode-btn, .cw-sub-mode-btn {
    background: transparent;
    border: none;
    color: var(--color-text);
    padding: 10px;
    text-align: left;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    border-radius: 4px;
    width: 100%;
}

.sub-mode-btn:hover, .cw-sub-mode-btn:hover {
    background-color: #3a3a3a;
}

.sub-mode-btn.active, .cw-sub-mode-btn.active {
    color: var(--color-correct);
}

#current-termo-mode, #current-crossword-mode {
    background: rgba(0, 0, 0, 0.3);
    color: white;
    padding: 8px 12px;
    font-size: 0.9rem;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.sub-mode-btn:hover, .cw-sub-mode-btn:hover {
    background-color: #3a3a3a;
}

#current-crossword-mode:hover {
    background: rgba(255, 255, 255, 0.1);
}

.cw-sub-mode-btn {
    background: transparent;
    border: none;
    color: var(--color-text);
    padding: 10px;
    text-align: left;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    border-radius: 4px;
    width: 100%;
}

.cw-sub-mode-btn:hover {
    background-color: #3a3a3a;
}

.mode-btn.active {
    background-color: var(--color-correct);
    border-color: var(--color-correct);
    color: #fff;
}

/* Specific mobile adjustment */
@media (max-width: 400px) {
    .header-left {
        width: auto;
    }

    #current-mode-label {
        display: none;
    }

    /* Show only arrow on very small screens? Or abbreviations */
}

#help-btn,
#stats-btn,
#main-menu-btn,
#header-finish-btn {
    background: none;
    border: 2px solid #4c4347;
    color: var(--color-text);
    font-size: 1.2rem;
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.2s;
    padding: 0;
}

#help-btn:hover,
#stats-btn:hover,
#main-menu-btn:hover,
#header-finish-btn:hover {
    background-color: #4c4347;
    transform: scale(1.05);
}

#header-finish-btn {
    border-color: var(--color-correct);
    color: var(--color-correct);
    font-size: 1.4rem;
}

/* Game Container - Layout Dinâmico */
#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* Changed from center to allow top alignment when scrolling */
    flex: 1 1 auto; /* Grow to fill space, shrink if needed, auto basis */
    width: 100%;
    overflow-y: auto; /* Allow scrolling inside the game board area */
    padding: 5px;
    padding-bottom: 20px;
    min-height: 0; /* Crítico para flexbox não estourar em conteudos grandes */
}

@media (max-width: 600px) {
    #game-container {
        padding-bottom: 5px;
    }
}

#boards-container {
    display: grid;
    gap: 20px;
    justify-content: center;
    align-items: start;
    max-height: 100%;
    margin-bottom: 15px;
}

/* Modo 1: 1 Coluna */
.boards-1 {
    grid-template-columns: 1fr;
    --block-size: 65px;
    --gap-size: 6px;
    --font-size-tile: 2.2rem;
}

/* Modo Math: 8 Colunas */
.boards-math {
    grid-template-columns: 1fr;
    --cols: 8;
    --block-size: min(45px, 6vh);
    --gap-size: 5px;
    --font-size-tile: 1.5rem;
    max-width: 500px;
    margin: 0 auto;
}

/* Modo 2: 2 Colunas */
.boards-2 {
    grid-template-columns: 1fr 1fr;
    --block-size: 52px;
    --gap-size: 5px;
    --font-size-tile: 1.8rem;
    gap: 40px !important;
    /* Espaço maior entre os dois */
}

/* Modo 4: 4 Colunas (1x4 Grid - Layout Horizontal Estrito) */
.boards-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    /* 4 colunas estritas */
    gap: 10px !important;
    /* Espaço uniforme entre as grades */
    justify-content: center;
    width: auto;
    max-width: 100%;
    align-items: start;
    margin: 0 auto;

    /* Configuração de tamanho para caber 4 lado a lado */
    /* Aumentado AINDA MAIS conforme pedido */
    /* Limitante teórico: 100vw / 20 blocos = 5vw. Usamos 4.7vw para segurança margins */
    --block-size: min(65px, 5vh, 4.7vw);
    --gap-size: 4px;
    --font-size-tile: min(32px, 2.5vh, 2.7vw);
}

.boards-4 .board {
    width: auto;
    /* Garante que o board não estique além do necessário */
}

/* Ajuste específico para mobile no Quarteto */
@media (max-width: 600px) {
    .boards-4 {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px !important;
        --block-size: min(15px, 2.6vh, 4.3vw);
        --gap-size: 2px;
        --font-size-tile: 0.65rem;
        max-width: 98vw;
        padding: 5px;
    }
}

.board {
    display: grid;
    grid-template-rows: repeat(var(--rows), 1fr);
    grid-gap: var(--gap-size);
}

.board.solved {
    opacity: 0.7;
    /* Visualmente indicar que acabou */
    pointer-events: none;
}

.board-header {
    text-align: center;
    margin-bottom: 5px;
    font-size: 0.8rem;
    opacity: 0.7;
    display: none;
    /* Só mostrar se quiser */
}

.row {
    display: grid;
    grid-template-columns: repeat(var(--cols, 5), 1fr);
    grid-gap: var(--gap-size);
}

.tile {
    width: var(--block-size);
    height: var(--block-size);
    border: 3px solid transparent;
    /* slightly thinner border for smaller sizes */
    border-radius: 4px;
    background-color: var(--color-empty);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: var(--font-size-tile);
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    user-select: none;
    transition: transform 0.1s;
}

.tile.flip {
    transition: background-color 0.5s, border-color 0.5s, color 0.5s;
}

/* .tile.active-focus moved further down */

.tile[data-status="tbd"] {
    border-color: #818384;
    background-color: #615458;
}

.tile.correct {
    background-color: var(--color-correct);
    border-color: var(--color-correct);
}

.tile.present {
    background-color: var(--color-present);
    border-color: var(--color-present);
}

.tile.absent {
    background-color: var(--color-absent);
    border-color: var(--color-absent);
}

.tile.active-focus {
    border-color: #ffffff !important;
}

/* Animações */
@keyframes pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

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

.tile.pop {
    animation: pop 0.1s ease-in-out;
}

@keyframes flip {
    0% {
        transform: rotateX(0);
    }

    50% {
        transform: rotateX(90deg);
    }

    100% {
        transform: rotateX(0);
    }
}

.tile.flip {
    animation: flip 0.6s ease-in;
}

/* Teclado Virtual */
#keyboard-container {
    margin-bottom: 10px;
    width: 100%;
    max-width: 650px;
    padding: 0 5px;
    flex: 0 0 auto; /* Never shrink or grow, keep fixed height footprint */
}

#keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    width: 100%;
}

.key {
    background-color: var(--key-bg);
    color: var(--key-text);
    font-family: inherit;
    font-weight: 700;
    border: none;
    border-radius: 4px;
    padding: 0;
    flex: 1;
    cursor: pointer;
    text-transform: uppercase;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 50px;
    user-select: none;
    position: relative;
    /* Para gradiente dividido se precisar */
    overflow: hidden;
}

.key.wide {
    flex: 1.5;
    font-size: 0.9rem;
}

.key.correct {
    background-color: var(--color-correct);
    transition: background-color 0.5s;
}

.key.present {
    background-color: var(--color-present);
    transition: background-color 0.5s;
}

.key.absent {
    background-color: var(--color-absent);
    opacity: 0.5;
    transition: background-color 0.5s;
}

/* Teclas com multicor para Dueto/Quarteto? 
   No Term.ooo original a tecla fica dividida.
   Fazer isso em CSS puro com JS mandando classes (key-1-correct key-2-absent...) é complexo.
   SIMPLIFICAÇÃO: A tecla assume a "melhor" cor globalmente ou neutra.
   Termo Rules: Se é verde em QUALQUER um, fica verde? Nao, confunde...
   Melhor estratégia simples: Verde se acertou em TODOS? Ou verde se acertou em ALGUM?
   Geralmente: 
   - Verde se letra existe na posição correta em Pelo Menos Um jogo ATIVO.
   - Amarelo se existe deslocado em Pelo Menos Um.
   - Cinza se não existe em NENHUM jogo ATIVO.
   Vamos por essa lógica no JS.
*/

/* Mensagens */
#messages {
    position: fixed;
    top: 12%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 200;
    pointer-events: none;
}

.message {
    background-color: #fff;
    color: #000;
    padding: 10px 16px;
    border-radius: 4px;
    font-weight: 700;
    animation: fadeInOut 2s forwards;
    opacity: 0;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

@keyframes fadeInOut {
    0% {
        opacity: 0;
        transform: translateY(-10px);
    }

    10% {
        opacity: 1;
        transform: translateY(0);
    }

    90% {
        opacity: 1;
        transform: translateY(0);
    }

    100% {
        opacity: 0;
        transform: translateY(-10px);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-5px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(5px);
    }
}

.invalid {
    animation: shake 0.5s;
}

/* MODALS (Mantido inalterado essencialmente, só ajuste de z-index ou cores se precisar) */
.hidden {
    display: none !important;
}

#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--modal-overlay);
    z-index: 500;
    backdrop-filter: blur(2px);
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--modal-bg);
    width: 90%;
    max-width: 500px;
    border-radius: 8px;
    border: 1px solid #4c4347;
    padding: 30px;
    z-index: 600;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    max-height: 90vh;
    overflow-y: auto;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translate(-50%, -40%);
        opacity: 0;
    }

    to {
        transform: translate(-50%, -50%);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.close-btn {
    background: none;
    border: none;
    color: var(--color-text);
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-content p {
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 15px;
    color: #d7dadc;
}

.examples {
    border-top: 1px solid #4c4347;
    border-bottom: 1px solid #4c4347;
    padding: 15px 0;
    margin: 15px 0;
}

.row-example {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
}

.row-example .tile {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
    border-width: 2px;
}

/* Stats e Graficos */
#statistics {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
}

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

.stat-box span:first-child {
    font-size: 2rem;
    font-weight: 700;
}

.stat-box .label {
    font-size: 0.7rem;
    text-align: center;
}

#guess-distribution {
    width: 100%;
    margin-bottom: 30px;
}

.graph-row {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
    width: 100%;
}

.graph-num {
    width: 15px;
    font-size: 0.9rem;
}

.graph-bar-container {
    flex-grow: 1;
    margin-left: 5px;
}

.graph-bar {
    background-color: var(--color-empty);
    color: #fff;
    font-weight: bold;
    font-size: 0.8rem;
    padding: 4px 8px;
    text-align: right;
    min-width: 8%;
    width: 0%;
    transition: width 0.5s;
}

.graph-bar.highlight {
    background-color: var(--color-correct);
}

.footer-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #4c4347;
    padding-top: 20px;
}

#share-btn {
    background-color: var(--color-correct);
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 4px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}


/* Floating Menu Button */
/* Removed floating FAB menu button - integrated into header */

/* Game Mode Options in Modal */
.display-grid-menu {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 10px;
}

.game-mode-option {
    background-color: var(--color-empty);
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 15px;
    color: var(--color-text);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
}

.game-mode-option:hover {
    background-color: var(--color-absent);
    transform: translateY(-2px);
    border-color: var(--color-correct);
}

.game-mode-option .icon {
    font-size: 2rem;
    font-weight: 700;
}

.game-mode-option .name {
    font-size: 0.9rem;
    font-weight: 700;
}

/* Crossword Board Styles */
/* Crossword Board Styles */
.crossword-container {
    display: flex;
    flex-direction: row;
    /* Always row as requested */
    align-items: flex-start;
    /* Top alignment */
    justify-content: center;
    width: 100%;
    max-width: 1000px;
    /* Slightly wider to accommodate side-by-side */
    margin: 0 auto;
    padding: 10px;
    gap: 20px;
}

/* On very small mobile screens, we might need adjustments, 
   but user requested strict side-by-side solidity. 
   We will keep it flexible but robust. */
/* --- Classic Grid Styling --- */
.crossword-grid {
    display: grid;
    gap: 0;
    background-color: transparent;
    border: 2px solid rgba(255, 255, 255, 0.2);
    width: 80vw;
    max-width: 540px;
    margin: 0 auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    box-sizing: border-box;
}

.cw-cell {
    aspect-ratio: 1;
    width: 100%;
    min-width: 0;
    min-height: 0;
    position: relative;
    overflow: hidden;
    /* Empty outlines */
    background-color: var(--bg-color);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.6rem, 2.5vw, 1.2rem);
    font-weight: bold;
    text-transform: uppercase;
    user-select: none;
}

/* Active Word Slot (White Cell) */
.cw-cell.active-word {
    background-color: #fff;
    color: #000;
    border: 1px solid #777; /* Explicit division between white cells */
    cursor: pointer;
}

/* Numbers in cells */
.cw-num {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 0.6rem;
    line-height: 1;
    color: #444;
    pointer-events: none;
    font-weight: normal;
}

/* Highlights */
.cw-cell.highlight {
    background-color: #e3f2fd;
    /* Light Blue for current word */
}

.cw-cell.active-cell {
    background-color: #ffeb3b !important;
    /* Yellow for current cursor */
}

/* Validation States */
.cw-cell.correct {
    background-color: #6aaa64 !important;
    /* Green */
    color: #fff !important;
}

.cw-cell.correct .cw-num {
    color: rgba(255, 255, 255, 0.7);
}

.cw-cell.absent {
    background-color: #ef9a9a !important;
    /* Light Red */
    color: #000 !important;
}

/* --- Hints Panel (Card Style) --- */
.cw-right-col {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 420px;
    flex-shrink: 0;
}

.cw-hints-panel {
    /* Transparent wrapper */
    background: transparent;
    border: none;
    padding: 0;
    height: auto;
    max-height: 600px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.hints-section {
    background-color: #f8f9fa;
    /* Off-white card */
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #ccc;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    color: #333;
}

.hints-section h3 {
    margin: 0 0 10px 0;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--color-correct);
    border-bottom: 2px solid #ddd;
    padding-bottom: 5px;
}

.hint-item {
    padding: 6px 8px;
    font-size: 0.9rem;
    line-height: 1.4;
    cursor: pointer;
    border-radius: 4px;
    margin-bottom: 4px;
    display: flex;
    gap: 8px;
    color: #333;
    overflow-wrap: break-word;
    word-break: break-word;
}

.hint-item:hover {
    background-color: #e9ecef;
}

.hint-item.active-hint {
    background-color: #e3f2fd;
    font-weight: bold;
    border-left: 4px solid #2196f3;
}

.hint-item.resolved {
    text-decoration: line-through;
    opacity: 0.5;
    color: #888;
}

/* Modal specific overrides for hints (Dark Mode) */
#hints-modal-content .hint-item {
    color: #fff;
}

#hints-modal-content .hint-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

#hints-modal-content .hint-item.active-hint {
    background-color: rgba(33, 150, 243, 0.2);
    color: #fff;
    border-left: 4px solid #2196f3;
}

.hint-item.resolved .hint-num {
    color: #888;
}

.hint-num {
    font-weight: bold;
    color: #007bff;
    min-width: 20px;
}

/* Floating Finish Button */
.cw-finish-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1000;

    background-color: var(--color-correct);
    color: white;
    border: none;
    width: 65px;
    height: 65px;
    border-radius: 50%;
    /* Circle */
    font-size: 2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s, background-color 0.2s;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
}

.cw-finish-btn:hover {
    transform: scale(1.1);
    background-color: #3aa394;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5);
}

.cw-finish-btn:active {
    transform: scale(0.95);
}

/* Responsive adjustments */
@media (max-width: 850px) {
    .crossword-container {
        flex-direction: column;
        align-items: center;
        gap: 20px;
        width: 100%;
        max-width: 100vw;
        overflow: hidden;
        padding: 80px 10px 20px 10px;
        box-sizing: border-box;
    }

    /* Hide static side panels on mobile, favouring floating buttons */
    .hints-panel, .cw-right-col {
        display: none !important;
    }

    .crossword-grid {
        margin: 0 auto;
    }

    .cw-right-col {
        width: 100%;
        max-width: 500px;
    }

    /* Mirror the floating hints button with a floating confirmation button on the left */
    #header-finish-btn {
        position: fixed !important;
        left: 20px !important;
        top: 90px !important;
        width: 45px !important;
        height: 45px !important;
        border-radius: 50% !important;
        background: var(--color-correct) !important;
        color: #fff !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.4) !important;
        z-index: 999 !important;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.4rem !important;
        border: 2px solid rgba(255,255,255,0.2) !important;
        cursor: pointer !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .cw-hints-panel {
        max-height: 300px;
        width: 100%;
    }
}

@media (max-width: 500px) {

    /* Crossword Mobile */
    .cw-cell {
        width: min(24px, 7vw);
        height: min(24px, 7vw);
        font-size: clamp(0.6rem, 2.5vw, 0.8rem);
    }

    .cw-finish-btn {
        width: 50px;
        height: 50px;
        bottom: auto;
        top: 70px;
        right: 10px;
        font-size: 1.5rem;
    }

    .boards-4 {
        grid-template-columns: repeat(2, 1fr);
        gap: 25px !important;
        --block-size: min(22px, 3.5vh, 6.5vw);
        --gap-size: 2px;
        --font-size-tile: 0.95rem;
        max-width: 85vw;
        padding: 20px;
    }

    .boards-2 {
        --block-size: min(34px, 4.5vh, 9vw);
        --gap-size: 2px;
        --font-size-tile: 1.2rem;
        gap: 8px !important;
    }

    .boards-1 {
        --block-size: min(50px, 7vh, 13vw);
        --gap-size: 3px;
        --font-size-tile: 1.4rem;
    }

    #keyboard-container {
        margin-bottom: 0;
        padding-bottom: 5px;
    }

    #keyboard {
        gap: 3px;
    }

    .key {
        height: min(38px, 6.5vh);
        font-size: 0.85rem;
    }
}

/* Exatas Cruzadas Styles */
.numbers-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
    max-height: 400px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.number-group {
    width: 100%;
    margin-bottom: 15px;
}

.number-group h4 {
    margin-bottom: 8px;
    color: var(--color-correct);
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 4px;
}

.number-group-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.number-item {
    background: #2d2d2d;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-family: monospace;
    font-size: 1.1rem;
    transition: all 0.2s;
    border: 2px solid transparent;
    user-select: none;
}

.number-item:hover {
    background: #444;
}

.number-item.selected {
    border-color: var(--color-correct);
    background: #333;
    transform: scale(1.05);
}

.number-item.used {
    opacity: 0.5;
    text-decoration: line-through;
    cursor: default;
}

.number-item.correct {
    color: var(--color-correct);
    opacity: 0.8 !important;
}

.cw-cell.fixed {
    color: var(--color-correct);
    font-weight: 900;
    cursor: default !important;
}

.cw-cell.fixed::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 4px;
    height: 4px;
    background: var(--color-correct);
    border-radius: 50%;
}

/* Sudoku Styles */
.sudoku-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    margin-top: 10px;
}

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    gap: 1px;
    background-color: #444;
    border: 3px solid #fff;
    width: min(450px, 90vw);
    aspect-ratio: 1 / 1;
}

.sudoku-cell {
    background-color: #121213;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: min(1.5rem, 5vw);
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.1s;
    color: white;
}

.sudoku-cell:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.sudoku-cell.focused {
    background-color: rgba(255, 255, 255, 0.2);
    box-shadow: inset 0 0 0 2px var(--color-correct);
}

.sudoku-cell.fixed {
    color: var(--color-correct);
    cursor: default;
}

.sudoku-cell.wrong {
    background-color: #ef9a9a !important;
    color: #000 !important;
}

/* 3x3 Block Borders */
.sudoku-cell:nth-child(3n) {
    border-right: 2px solid #fff;
}

.sudoku-cell:nth-child(9n) {
    border-right: none;
}

.sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid #fff;
}

#hints-modal .modal-content {
    max-width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

#hints-modal-content {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#floating-hints-btn {
    position: fixed;
    right: 20px;
    top: 90px;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: #444;
    color: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    border: 2px solid #555;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
}

#floating-hints-btn:hover {
    transform: scale(1.1);
    background-color: #555;
}

#floating-hints-btn.hidden {
    display: none;
}

/* Hide floating hints button on desktop */
@media (min-width: 851px) {
    #floating-hints-btn {
        display: none !important;
    }
}