/* Connessioni - clone italiano di NYT Connections, vanilla CSS, mobile-first.
   Stile coerente con quintaria/lemmia (prefisso .q-... condiviso dove applicabile,
   prefisso .c-... per gli elementi specifici di Connessioni). */

.c-game {
    max-width: 600px;
    margin: 1rem auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
}

.c-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--c-line, #e2e8f0);
    padding-bottom: 0.6rem;
}

.c-puzzle-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    font-size: 0.85rem;
    color: var(--c-ink-soft, #334155);
}

.c-puzzle-number {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--c-ink, #0f172a);
}

.c-puzzle-mode {
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.75rem;
    color: var(--c-ink-mute, #64748b);
}

.c-toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.c-icon-btn {
    background: transparent;
    border: 1px solid var(--c-line, #e2e8f0);
    border-radius: 999px;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--c-ink-soft, #334155);
    transition: all 120ms;
    padding: 0;
}

.c-icon-btn:hover {
    background: var(--c-bg, #f8fafc);
    color: var(--c-blue, #0065c0);
    border-color: var(--c-blue, #0065c0);
}

/* ===== Solved groups (above the grid) ===== */

.c-solved-area {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 4px;
}

.c-solved-row {
    border-radius: 6px;
    padding: 0.7rem 0.9rem;
    text-align: center;
    color: #1a1a1b;
    font-size: 0.95rem;
    line-height: 1.25;
    animation: c-reveal 380ms ease-out;
}

.c-solved-category {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.85rem;
    margin-bottom: 0.15rem;
}

.c-solved-words {
    font-weight: 500;
}

/* Color theme: yellow / green / blue / purple, level 0-3.
   Stile Connections classico (non NYT-branded) con palette accessibile. */
.c-solved-row.is-level-0 { background: #f9df6d; }
.c-solved-row.is-level-1 { background: #a0c35a; }
.c-solved-row.is-level-2 { background: #b0c4ef; }
.c-solved-row.is-level-3 { background: #ba81c5; }

/* ===== Grid ===== */

.c-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 1fr;
    gap: 6px;
    width: 100%;
    aspect-ratio: 1 / 1;
    margin: 0 auto;
    box-sizing: border-box;
}

.c-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    text-transform: uppercase;
    font-weight: 700;
    line-height: 1.05;
    color: var(--c-ink, #0f172a);
    background: #efefe6;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    transition: transform 120ms, background 120ms, color 120ms;
    padding: 0.2rem 0.3rem;
    word-break: break-word;
    hyphens: auto;
    font-size: clamp(0.65rem, 2.6vw, 1.05rem);
    font-family: inherit;
    aspect-ratio: 1;
    box-sizing: border-box;
}

.c-tile:hover { background: #e3e3d8; }

.c-tile.is-selected {
    background: #5a594e;
    color: #fff;
}

.c-tile.is-shake { animation: c-shake 540ms; }

.c-tile.is-pop { animation: c-pop 200ms ease-out; }

.c-tile.is-jump-correct { animation: c-jump 480ms ease-in-out; }

@keyframes c-pop {
    0% { transform: scale(0.92); }
    100% { transform: scale(1); }
}

@keyframes c-shake {
    10%, 90% { transform: translateX(-2px); }
    20%, 80% { transform: translateX(3px); }
    30%, 50%, 70% { transform: translateX(-5px); }
    40%, 60% { transform: translateX(5px); }
}

@keyframes c-jump {
    0%   { transform: translateY(0); }
    30%  { transform: translateY(-8px); }
    60%  { transform: translateY(0); }
    80%  { transform: translateY(-3px); }
    100% { transform: translateY(0); }
}

@keyframes c-reveal {
    0%   { opacity: 0; transform: translateY(-6px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* ===== Mistakes indicator ===== */

.c-mistakes {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    color: var(--c-ink-soft, #334155);
    margin-top: 0.4rem;
}

.c-mistakes-dots {
    display: inline-flex;
    gap: 6px;
}

.c-mistake-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #5a594e;
    transition: opacity 250ms, transform 250ms;
}

.c-mistake-dot.is-spent {
    opacity: 0.18;
    transform: scale(0.7);
}

/* ===== Action buttons row ===== */

.c-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 0.6rem;
}

.c-action-btn {
    background: transparent;
    border: 1.5px solid var(--c-ink, #0f172a);
    border-radius: 999px;
    padding: 0.55rem 1.1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--c-ink, #0f172a);
    cursor: pointer;
    transition: all 120ms;
    font-family: inherit;
}

.c-action-btn:hover:not(:disabled) {
    background: var(--c-ink, #0f172a);
    color: #fff;
}

.c-action-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.c-action-btn.is-primary {
    background: var(--c-ink, #0f172a);
    color: #fff;
}

.c-action-btn.is-primary:hover:not(:disabled) {
    background: var(--c-blue, #0065c0);
    border-color: var(--c-blue, #0065c0);
}

.c-action-btn.is-primary:disabled {
    background: #c0c0b8;
    border-color: #c0c0b8;
    color: #fff;
}

/* ===== Toast / message ===== */

.c-message-bar {
    text-align: center;
    min-height: 2.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #fff;
    background: #1a1a1b;
    border-radius: 6px;
    padding: 0.5rem 0.8rem;
    transition: opacity 200ms;
}

.c-message-bar.is-hidden {
    opacity: 0;
    visibility: hidden;
}

/* ===== Modals (replicate q-modal pattern) ===== */

.c-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.c-modal.is-open { display: flex; }

.c-modal-box {
    background: var(--c-bg-card, #fff);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.25);
}

.c-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.c-modal-title {
    margin: 0;
    font-size: 1.25rem;
}

.c-modal-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--c-ink-mute, #64748b);
    line-height: 1;
    padding: 0.2rem 0.5rem;
}

/* ===== Stats modal ===== */

.c-stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
    margin-bottom: 1.2rem;
}

.c-stats-cell {
    text-align: center;
}

.c-stats-num {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--c-ink, #0f172a);
}

.c-stats-label {
    font-size: 0.65rem;
    color: var(--c-ink-mute, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.1;
}

.c-stats-distrib {
    font-weight: 700;
    margin-bottom: 0.4rem;
}

.c-distrib-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
    font-size: 0.85rem;
}

.c-distrib-label {
    width: 1.5rem;
    text-align: right;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.75rem;
}

.c-distrib-bar {
    flex: 1;
    background: #d3d6da;
    color: #fff;
    text-align: right;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 1.5rem;
    box-sizing: border-box;
}

.c-distrib-bar.is-current { background: #5a594e; }

.c-next-word {
    text-align: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--c-line, #e2e8f0);
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.9rem;
    color: var(--c-ink-soft, #334155);
}

.c-next-word-time {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--c-ink, #0f172a);
}

.c-share-btn {
    display: block;
    width: 100%;
    margin-top: 1rem;
    padding: 0.8rem 1rem;
    background: #1a1a1b;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 120ms;
    font-family: inherit;
}

.c-share-btn:hover { background: #333; }

/* ===== Help modal palette tokens ===== */

.q-help-list {
    padding-left: 1.2rem;
    line-height: 1.7;
    margin: 0.5rem 0;
}

.q-help-yellow { color: #c9a200; }
.q-help-green  { color: #6aaa64; }
.q-help-blue   { color: #4f7fc4; }
.q-help-purple { color: #9a5fb0; }
.q-help-note   { margin-top: 1rem; }

/* ===== Settings modal: color-blind toggle ===== */

.c-settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 0;
    border-bottom: 1px solid var(--c-line, #e2e8f0);
}

.c-settings-row:last-child { border-bottom: none; }

.c-settings-text { flex: 1; }

.c-settings-title { font-weight: 600; }

.c-settings-desc {
    font-size: 0.85rem;
    color: var(--c-ink-mute, #64748b);
}

.c-settings-toggle {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* ===== Color-blind mode: prefix the category label with a symbol ===== */

.c-game.is-cb .c-solved-row.is-level-0 .c-solved-category::before { content: "\25CF "; }
.c-game.is-cb .c-solved-row.is-level-1 .c-solved-category::before { content: "\25A0 "; }
.c-game.is-cb .c-solved-row.is-level-2 .c-solved-category::before { content: "\25B2 "; }
.c-game.is-cb .c-solved-row.is-level-3 .c-solved-category::before { content: "\2605 "; }

/* ===== Mode actions row ===== */

.c-mode-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--s-2, 0.5rem);
    margin-top: var(--s-3, 0.75rem);
}

/* ===== Print ===== */

@media print {
    .c-toolbar-actions,
    .c-actions,
    .c-mode-actions,
    .tools-cta,
    [data-tools-ad],
    .tools-ad-slot { display: none !important; }
}
