:root {
    color-scheme: dark;
    --bg: #120f1f;
    --panel: #1d1836;
    --panel-2: #2a2350;
    --primary: #a78bfa;
    --primary-2: #c4b5fd;
    --text: #f3f0ff;
    --muted: #a39cc4;
    --danger: #f87171;
    --success: #47d18c;
    --cell-border: #342a5c;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    background: radial-gradient(circle at top, #2a2153 0, var(--bg) 50%);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    user-select: none;
}

button {
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #1a1030;
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    transition: filter 0.15s ease;
}

button:hover:not(:disabled) {
    filter: brightness(1.08);
}

button:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: 2px;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.game-shell {
    width: min(100%, 820px);
    min-height: 100vh;
    padding: 16px;
    display: grid;
    align-content: center;
    gap: 12px;
}

/* ─── Scorebar ─── */
.scorebar {
    display: grid;
    grid-template-columns: repeat(4, 1fr) auto;
    gap: 10px;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 10px;
    background: rgba(29, 24, 54, 0.85);
    padding: 12px;
    backdrop-filter: blur(6px);
}

.scorebar div {
    display: grid;
    gap: 2px;
}

.label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.scorebar strong {
    font-size: clamp(16px, 4.2vw, 26px);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

#restartButton {
    min-width: 90px;
    height: 40px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

/* ─── Layout principal ─── */
.play-area {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.board-wrap {
    position: relative;
    width: min(100%, 560px);
    margin: 0 auto;
    aspect-ratio: 1;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.4);
    padding: 8px;
}

.grid {
    display: grid;
    width: 100%;
    height: 100%;
    gap: 2px;
    touch-action: none;
}

.cell {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 3px;
    font-weight: 800;
    font-size: clamp(9px, 2.6vw, 17px);
    color: var(--text);
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}

.cell.selecting {
    background: var(--primary);
    color: #1a1030;
}

.cell.found {
    background: rgba(71, 209, 140, 0.35);
    color: #d9ffe9;
}

.cell.invalid {
    background: rgba(248, 113, 113, 0.5) !important;
}

/* ─── Lista de palavras ─── */
.word-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    padding: 10px;
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
}

.word-chip {
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.4px;
}

.word-chip.found {
    background: rgba(71, 209, 140, 0.25);
    color: var(--success);
    text-decoration: line-through;
    text-decoration-thickness: 2px;
}

/* ─── Overlay ─── */
.overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    gap: 14px;
    padding: 24px;
    text-align: center;
    background: rgba(18, 15, 31, 0.94);
    border-radius: 12px;
    backdrop-filter: blur(8px);
    z-index: 10;
}

.overlay[hidden] {
    display: none;
}

.overlay h1 {
    margin: 0;
    font-size: clamp(26px, 6.5vw, 42px);
    line-height: 1.1;
}

.overlay p {
    max-width: 360px;
    margin: 0 auto;
    color: var(--muted);
    line-height: 1.5;
    font-size: 14px;
}

.overlay .stats-final {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-width: 380px;
    margin: 8px auto 0;
}

.overlay .stat-card {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 8px;
    padding: 10px 6px;
}

.overlay .stat-card .label {
    margin-bottom: 4px;
}

.overlay .stat-card strong {
    font-size: 20px;
    color: var(--primary-2);
    line-height: 1;
}

.overlay button {
    justify-self: center;
    min-width: 160px;
    height: 48px;
    margin-top: 6px;
}

.overlay button.secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    margin-top: 0;
    font-size: 13px;
    height: 40px;
}

/* ─── Mobile ─── */
@media (max-width: 720px) {
    .game-shell {
        align-content: start;
    }

    .scorebar {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 10px;
    }

    #restartButton {
        grid-column: 1 / -1;
        width: 100%;
    }
}
