:root {
    color-scheme: dark;
    --bg: #0d1224;
    --panel: #161d36;
    --text: #f3f6ff;
    --muted: #9aa6c9;
    --accent: #8b5cf6;
    --accent-2: #c4b5fd;
    --correct: #16a34a;
    --present: #d97706;
    --absent: #3a4262;
    --empty: rgba(255, 255, 255, 0.06);
    --line: rgba(255, 255, 255, 0.16);
}

* { box-sizing: border-box; }

/* Tudo precisa caber na altura do quadro do jogo: a página nunca rola. */
html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: radial-gradient(circle at top, #1d2650 0, var(--bg) 55%);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    user-select: none;
    -webkit-user-select: none;
}

button {
    border: 0;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    touch-action: manipulation;
    transition: filter 0.15s ease;
}
button:hover:not(:disabled) { filter: brightness(1.08); }
button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.game-shell {
    width: min(100%, 720px);
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ─── Barra de placar ─── */
.scorebar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 12px;
    background: rgba(22, 29, 54, 0.9);
    padding: 6px 10px;
}
.scorebar div { display: grid; gap: 1px; flex: 1 1 0; min-width: 0; }
.label {
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.scorebar strong {
    font-size: clamp(14px, 3.6vw, 20px);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.muted-suffix { color: var(--muted); font-size: 0.65em; font-weight: 600; }
#restartButton {
    flex: 0 0 auto;
    height: 32px;
    padding: 0 12px;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.10);
    color: var(--text);
}
#restartButton[hidden] { display: none; }

/* ─── Área do jogo ─── */
.stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
}

.boards {
    position: absolute;
    inset: 0;
    display: grid;
    align-content: center;
    justify-content: center;
    gap: 10px 14px;
}
.boards[data-count="1"] { grid-template-columns: auto; }
.boards[data-count="2"] { grid-template-columns: repeat(2, auto); }
.boards[data-count="4"] { grid-template-columns: repeat(2, auto); }

.board {
    display: grid;
    grid-template-columns: repeat(5, var(--s, 52px));
    grid-auto-rows: var(--s, 52px);
    gap: var(--g, 5px);
    padding: 4px;
    border-radius: 12px;
    transition: opacity 0.3s ease;
}
/* Palavra já descoberta: o tabuleiro fica de lado, esperando as outras */
.board.done { opacity: 0.55; }

.tile {
    position: relative;
    display: grid;
    place-items: center;
    border: 2px solid var(--line);
    border-radius: 8px;
    background: var(--empty);
    color: #fff;
    font-size: calc(var(--s, 52px) * 0.54);
    font-weight: 900;
    line-height: 1;
    text-transform: uppercase;
    transition: transform 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}
.tile.filled { border-color: rgba(255, 255, 255, 0.4); animation: pop 0.12s ease; }
.tile.active { background: rgba(255, 255, 255, 0.10); }
/* A casa em foco só se distingue por uma linha mais grossa na base (a linha que recebe a próxima letra) */
.tile.focus { border-bottom: calc(var(--s, 52px) * 0.10) solid var(--accent-2); }
.tile.correct { background: var(--correct); border-color: var(--correct); }
.tile.present { background: var(--present); border-color: var(--present); }
.tile.absent  { background: var(--absent);  border-color: var(--absent); }
.tile.flip-out { transform: rotateX(90deg); }

@keyframes pop { from { transform: scale(0.88); } to { transform: scale(1); } }

.row-shake .tile { animation: shake 0.4s ease; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* ─── Aviso rápido ─── */
.toast {
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    padding: 8px 16px;
    border-radius: 999px;
    background: #2563eb;
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    white-space: nowrap;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.toast[hidden] { display: none; }

/* ─── Teclado ─── */
.keyboard {
    flex: 0 0 auto;
    display: grid;
    gap: 6px;
    padding-top: 2px;
}
.keyboard-row { display: flex; justify-content: center; gap: 5px; }
/* Na tela inicial o teclado fica escondido (mas ocupa o lugar, para o tabuleiro não pular quando o jogo começa) */
.game-shell.idle .keyboard { visibility: hidden; }

.key {
    position: relative;
    flex: 1 1 0;
    max-width: 44px;
    height: clamp(40px, 6.4dvh, 52px);
    padding: 0;
    overflow: hidden;
    border-radius: 7px;
    background: #4a5481;
    color: #fff;
    font-size: clamp(13px, 3.6vw, 17px);
}
.key.wide { flex: 1.5 1 0; max-width: 66px; font-size: 12px; background: #5b6696; }
.key .segs { position: absolute; inset: 0; display: grid; }
.key .seg { display: block; }
.key .seg.correct { background: var(--correct); }
.key .seg.present { background: var(--present); }
.key .seg.absent  { background: #232a45; }
.key .letter { position: relative; z-index: 1; pointer-events: none; }
/* Letra que não existe em nenhuma palavra: bloqueada */
.key.blocked { opacity: 0.35; cursor: not-allowed; }
.key.nudge { animation: shake 0.3s ease; }

/* ─── Telas por cima do jogo ─── */
.overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 16px;
    text-align: center;
    background: rgba(13, 18, 36, 0.96);
    border-radius: 12px;
    overflow: auto;
}
.overlay[hidden] { display: none; }
.overlay h1 { margin: 0; font-size: clamp(24px, 7vw, 38px); line-height: 1.1; }
.overlay p { max-width: 360px; margin: 0; color: var(--muted); line-height: 1.4; font-size: 14px; }
.overlay button { min-width: 150px; height: 44px; }
.overlay button.secondary { background: rgba(255, 255, 255, 0.10); color: var(--text); font-size: 13px; height: 38px; }
.overlay-actions { display: grid; gap: 8px; justify-items: center; }

/* ─── Tela inicial: título de peças e três modos grandes ─── */
.overlay.start {
    gap: 22px;
    background:
        radial-gradient(circle at 15% 12%, rgba(139, 92, 246, 0.28) 0, transparent 40%),
        radial-gradient(circle at 88% 85%, rgba(22, 163, 74, 0.22) 0, transparent 42%),
        radial-gradient(circle at 85% 10%, rgba(217, 119, 6, 0.20) 0, transparent 36%),
        #0d1224;
}
.start-title { display: grid; gap: 8px; justify-items: center; }
.start-kicker {
    font-size: clamp(12px, 3.4vw, 15px);
    font-weight: 900;
    letter-spacing: 0.38em;
    text-indent: 0.38em;
    text-transform: uppercase;
    color: var(--accent-2);
}
.tiles { display: flex; gap: clamp(3px, 1.2vw, 6px); }
.tiles i {
    --c: var(--correct);
    display: grid;
    place-items: center;
    width: clamp(30px, 10vw, 46px);
    height: clamp(36px, 12vw, 54px);
    border-radius: 9px;
    background: var(--c);
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.32), inset 0 -3px 0 rgba(0, 0, 0, 0.14);
    color: #fff;
    font-style: normal;
    font-size: clamp(19px, 6.4vw, 30px);
    font-weight: 900;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
    transform: rotate(var(--r, 0deg));
    animation: tile-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    animation-delay: calc(var(--n, 0) * 60ms);
}
.tiles i:nth-child(1) { --c: #16a34a; --r: -3deg; --n: 0; }
.tiles i:nth-child(2) { --c: #d97706; --r: 3deg;  --n: 1; }
.tiles i:nth-child(3) { --c: #4a5481; --r: -2deg; --n: 2; }
.tiles i:nth-child(4) { --c: #16a34a; --r: 4deg;  --n: 3; }
.tiles i:nth-child(5) { --c: #d97706; --r: -3deg; --n: 4; }
.tiles i:nth-child(6) { --c: #4a5481; --r: 2deg;  --n: 5; }
.tiles i:nth-child(7) { --c: #16a34a; --r: -4deg; --n: 6; }
@keyframes tile-in {
    from { opacity: 0; transform: translateY(-18px) rotate(calc(var(--r, 0deg) * 4)) scale(0.6); }
    to   { opacity: 1; transform: rotate(var(--r, 0deg)); }
}

.mode-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: min(100%, 360px); }
.overlay .mode-btn {
    --c1: #a78bfa; --c2: #7c3aed;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 4;
    padding: 8px 4px;
    border-radius: 18px;
    background: linear-gradient(160deg, var(--c1), var(--c2));
    box-shadow: 0 5px 0 rgba(0, 0, 0, 0.34), inset 0 2px 0 rgba(255, 255, 255, 0.28);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.overlay .mode-btn[data-mode="solo"]     { --c1: #4ade80; --c2: #16a34a; }
.overlay .mode-btn[data-mode="dueto"]    { --c1: #fbbf24; --c2: #d97706; }
.overlay .mode-btn[data-mode="quarteto"] { --c1: #f472b6; --c2: #be185d; }
.overlay .mode-btn:hover:not(:disabled) { transform: translateY(-2px); }
.overlay .mode-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.34), inset 0 2px 0 rgba(255, 255, 255, 0.28); }
.mode-btn:disabled { opacity: 0.6; cursor: wait; }

/* Mini tabuleiros: 1, 2 ou 4 quadrados mostram quantas palavras */
.mode-icon { display: grid; gap: 4px; width: 62%; aspect-ratio: 1 / 1; place-content: center; }
.mode-btn[data-mode="solo"] .mode-icon { grid-template-columns: 1fr; }
.mode-btn[data-mode="dueto"] .mode-icon,
.mode-btn[data-mode="quarteto"] .mode-icon { grid-template-columns: repeat(2, 1fr); }
.mode-icon b {
    display: block;
    aspect-ratio: 1 / 1;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}
.mode-btn[data-mode="solo"] .mode-icon b { width: 70%; justify-self: center; border-radius: 9px; }
.mode-name { color: #fff; font-size: clamp(13px, 3.8vw, 17px); font-weight: 900; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3); }
.mode-sub { color: rgba(255, 255, 255, 0.9); font-size: clamp(10px, 2.8vw, 12px); font-weight: 700; }

/* ─── Fim da palavra ─── */
.end-answers { display: grid; gap: 8px; justify-items: center; }
.end-word { display: flex; gap: 4px; }
.end-word i {
    display: grid;
    place-items: center;
    width: 34px;
    height: 40px;
    border-radius: 7px;
    background: var(--absent);
    color: #fff;
    font-style: normal;
    font-size: 20px;
    font-weight: 900;
}
.end-word.found i { background: var(--correct); }
.overlay .end-summary { color: var(--text); font-size: 15px; font-weight: 700; }
.overlay .end-summary strong { color: var(--accent-2); }

@media (prefers-reduced-motion: reduce) {
    .tiles i, .tile.filled, .row-shake .tile, .key.nudge { animation: none; }
    .tile, .overlay .mode-btn { transition: none; }
}
