/* Cifretto - clone italiano di Nerdle, vanilla CSS, mobile-first.
   Usa lo stesso prefisso .q-... di Lemmia per consistenza visiva e per riusare
   alcune classi (.q-modal*, .q-help-list, .q-stats-grid). Le classi specifiche
   di Cifretto sono prefissate .x-... per non collidere con Connessioni (.c-...). */

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

.x-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;
}

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

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

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

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

.x-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;
}

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

/* ===== Length selector (segmented control) ===== */

.x-length-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.4rem 0;
}

.x-length-label {
    font-size: 0.85rem;
    color: var(--c-ink-soft, #334155);
    font-weight: 600;
}

.x-length-options {
    display: inline-flex;
    border: 1px solid var(--c-line, #e2e8f0);
    border-radius: 999px;
    overflow: hidden;
    flex-wrap: wrap;
}

.x-length-pill {
    padding: 0.35rem 0.7rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    border: none;
    color: var(--c-ink-soft, #334155);
    border-right: 1px solid var(--c-line, #e2e8f0);
    transition: background 120ms, color 120ms;
    font-family: inherit;
    white-space: nowrap;
}

.x-length-pill:last-child { border-right: none; }
.x-length-pill:hover { background: var(--c-bg, #f8fafc); color: var(--c-ink, #0f172a); }

.x-length-pill.is-active {
    background: var(--c-ink, #0f172a);
    color: #fff;
}

/* ===== Board ===== */

.x-board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 5px;
    padding: 8px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

.x-row {
    display: grid;
    /* grid-template-columns is set inline by JS based on current length (6..12) */
    gap: 5px;
}

.x-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: none;
    font-weight: 700;
    line-height: 1;
    color: var(--c-ink, #0f172a);
    border: 2px solid #d3d6da;
    background: transparent;
    aspect-ratio: 1;
    user-select: none;
    transition: transform 120ms;
    /* font-size scales with tile size; clamp() keeps it readable across lengths 6..12 */
    font-size: clamp(0.75rem, 4vw, 1.7rem);
    font-family: var(--font-mono, ui-monospace, monospace);
}

.x-tile.is-filled {
    border-color: #878a8c;
    animation: x-pop 100ms ease-in-out;
}

.x-tile.is-correct {
    background: #6aaa64;
    border-color: #6aaa64;
    color: #fff;
}

.x-tile.is-present {
    background: #c9b458;
    border-color: #c9b458;
    color: #fff;
}

.x-tile.is-absent {
    background: #787c7e;
    border-color: #787c7e;
    color: #fff;
}

.x-row.is-shake { animation: x-shake 600ms; }

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

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

/* ===== Keyboard ===== */

.x-keyboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 600px;
    margin: 0.5rem auto 0;
    width: 100%;
}

.x-keyboard-row {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.x-key {
    flex: 1;
    min-width: 0;
    height: 58px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 4px;
    background: #d3d6da;
    color: #1a1a1b;
    font-weight: 700;
    font-size: 1.15rem;
    cursor: pointer;
    user-select: none;
    transition: background 120ms;
    padding: 0;
    font-family: var(--font-mono, ui-monospace, monospace);
}

.x-key:hover { background: #bbbfc1; }

.x-key.is-wide {
    flex: 1.6;
    font-size: 0.78rem;
    padding: 0 4px;
    font-family: inherit;
}

.x-key.is-correct { background: #6aaa64; color: #fff; }
.x-key.is-present { background: #c9b458; color: #fff; }
.x-key.is-absent  { background: #787c7e; color: #fff; }

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

.x-message-bar {
    text-align: center;
    min-height: 2.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--c-ink, #0f172a);
    background: var(--c-bg, #f8fafc);
    border-radius: 6px;
    padding: 0.5rem;
    transition: opacity 200ms;
}

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

/* ===== Modals (reuse Lemmia's q-modal pattern) ===== */

.q-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;
}

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

.q-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);
}

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

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

.q-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 ===== */

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

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

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

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

.x-stats-meta {
    text-align: center;
    font-size: 0.8rem;
    color: var(--c-ink-mute, #64748b);
    margin-bottom: 1rem;
    font-family: var(--font-mono, ui-monospace, monospace);
}

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

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

.x-distrib-label {
    width: 1rem;
    text-align: right;
    font-family: var(--font-mono, ui-monospace, monospace);
}

.x-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;
}

.x-distrib-bar.is-current { background: #6aaa64; }

.x-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);
}

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

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

.x-share-btn:hover { background: #5a9954; }

/* ===== Settings modal rows ===== */

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

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

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

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

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

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

.x-settings-intro {
    font-size: 0.85rem;
    color: var(--c-ink-mute, #64748b);
    margin-bottom: 1rem;
}

/* ===== Help list (reuse Lemmia's q-help-list) ===== */

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

.q-help-green  { color: #6aaa64; }
.q-help-yellow { color: #c9b458; }
.q-help-gray   { color: #787c7e; }
.q-help-note   { margin-top: 1rem; }

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

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

/* ===== Loading indicator (during equation generation) ===== */

.x-loading {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--c-ink-mute, #64748b);
    font-size: 0.95rem;
}

.x-loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--c-line, #e2e8f0);
    border-top-color: var(--c-blue, #0065c0);
    border-radius: 50%;
    animation: x-spin 800ms linear infinite;
    margin-right: 0.5rem;
    vertical-align: middle;
}

@keyframes x-spin {
    to { transform: rotate(360deg); }
}

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

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