/* Legami - clone italiano della Ghigliottina, vanilla CSS, mobile-first.
   Prefisso .g- per non collidere con Lemmia (.q-), Cifretto (.x-), Connessioni (.c-). */

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

/* ===== Toolbar ===== */

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

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

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

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

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

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

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

/* ===== Intro view (mostrata prima dell'avvio del puzzle) ===== */

.g-intro {
    background: var(--c-bg, #f8fafc);
    border: 1px solid var(--c-line, #e2e8f0);
    border-radius: 10px;
    padding: 1.4rem 1.3rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    animation: g-slide-in 320ms ease-out;
}

.g-intro[hidden] {
    display: none;
}

.g-intro-title {
    margin: 0;
    font-size: 1.2rem;
    color: var(--c-ink, #0f172a);
    font-weight: 700;
}

.g-intro-lead {
    margin: 0;
    color: var(--c-ink, #0f172a);
    font-weight: 600;
    font-size: 0.95rem;
}

.g-intro .g-help-list {
    margin: 0;
    padding-left: 1.4rem;
    line-height: 1.65;
}

.g-intro .g-help-list li {
    margin-bottom: 0.4rem;
}

.g-intro-cta {
    align-self: stretch;
    margin-top: 0.6rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.g-play[hidden] {
    display: none;
}

/* ===== Confirm actions (modal surrender) ===== */

.g-confirm-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* ===== Status bar (round / time / score) ===== */

.g-status-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.8rem;
    background: var(--c-bg, #f8fafc);
    border: 1px solid var(--c-line, #e2e8f0);
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--c-ink, #0f172a);
}

.g-status-cell {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.9rem;
}

.g-status-cell svg {
    color: var(--c-ink-mute, #64748b);
}

.g-status-key {
    font-family: inherit;
    color: var(--c-ink-soft, #334155);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.g-score-pulse {
    animation: g-pulse 600ms ease-out;
}

@keyframes g-pulse {
    0%   { transform: scale(1);    color: var(--c-ink, #0f172a); }
    50%  { transform: scale(1.18); color: #d11; }
    100% { transform: scale(1);    color: var(--c-ink, #0f172a); }
}

/* ===== Saved area (parole salvate) ===== */

.g-saved-area {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-height: 0;
    margin-top: 0.85rem;
    transition: min-height 200ms;
}

.g-saved-header {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--c-ink-soft, #334155);
    margin-bottom: 0.45rem;
    line-height: 1.3;
}

.g-saved-header strong {
    color: var(--c-ink, #0f172a);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.g-saved-header strong.is-revealed {
    color: var(--c-blue, #0065c0);
}

.g-saved-row {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.6rem 0.85rem;
    background: #f1f5f9;
    color: var(--c-ink, #0f172a);
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.95rem;
    flex-wrap: wrap;
    animation: g-slide-in 320ms ease-out;
}

/* Outcome pill: il colore (verde/rosso) vive solo qui, non sullo sfondo riga.
   Cosi' il segnale "round vinto vs perso" e' netto, ma non si confonde con
   "questa parola appartiene o no alla catena" (tutte e 5 vi appartengono). */
.g-saved-pill {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.22rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #fff;
    white-space: nowrap;
    line-height: 1.2;
}

.g-saved-pill.is-won {
    background: #6aaa64;
}

.g-saved-pill.is-lost {
    background: #c95151;
}

.g-saved-pill-icon {
    font-size: 0.85rem;
    line-height: 1;
}

.g-saved-content {
    flex: 1 1 60%;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
    align-self: center;
}

.g-saved-text {
    font-weight: 700;
    line-height: 1.3;
}

.g-saved-mistake-pick {
    font-size: 0.78rem;
    color: var(--c-ink-mute, #64748b);
    font-weight: 500;
    line-height: 1.4;
    margin-top: 0.1rem;
}

.g-saved-mistake-pick em {
    font-style: normal;
    font-weight: 700;
    color: var(--c-ink-soft, #334155);
}

.g-saved-meta {
    flex: 0 0 auto;
    font-size: 0.72rem;
    color: #c95151;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    align-self: center;
}

@keyframes g-slide-in {
    0%   { opacity: 0; transform: translateY(-8px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* ===== Pair area (2 tessere round corrente) ===== */

.g-pair-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
    margin-top: 0.4rem;
}

.g-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    text-transform: uppercase;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--c-ink, #0f172a);
    background: #f1f5f9;
    border: 2px solid #cbd5e1;
    border-radius: 8px;
    padding: 1.2rem 0.8rem;
    cursor: pointer;
    user-select: none;
    transition: all 140ms;
    min-height: 90px;
    word-break: break-word;
    hyphens: auto;
    font-family: inherit;
}

.g-tile:hover:not(:disabled) {
    background: #e2e8f0;
    border-color: var(--c-blue, #0065c0);
    transform: translateY(-1px);
}

.g-tile:disabled {
    cursor: default;
    opacity: 0.85;
}

.g-tile.is-correct {
    background: #6aaa64;
    border-color: #6aaa64;
    color: #fff;
    animation: g-pop 240ms ease-out;
}

.g-tile.is-wrong {
    background: #c95151;
    border-color: #c95151;
    color: #fff;
    animation: g-shake 540ms;
}

.g-tile.is-fade-out {
    opacity: 0.25;
}

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

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

/* ===== Keyword area (input parola chiave) ===== */

.g-keyword-area {
    margin-top: 0.6rem;
    padding: 1rem;
    background: var(--c-bg, #f8fafc);
    border: 1px solid var(--c-line, #e2e8f0);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    animation: g-slide-in 320ms ease-out;
}

.g-keyword-area.is-hidden {
    display: none;
}

.g-keyword-prompt {
    margin: 0;
    font-weight: 600;
    color: var(--c-ink, #0f172a);
    font-size: 0.95rem;
    line-height: 1.4;
}

.g-keyword-input {
    width: 100%;
    padding: 0.8rem 1rem;
    font-size: 1.1rem;
    font-weight: 700;
    border: 2px solid var(--c-line, #e2e8f0);
    border-radius: 8px;
    background: #fff;
    color: var(--c-ink, #0f172a);
    text-align: center;
    box-sizing: border-box;
    font-family: inherit;
    text-transform: lowercase;
}

.g-keyword-input:focus {
    outline: none;
    border-color: var(--c-blue, #0065c0);
    box-shadow: 0 0 0 3px rgba(0, 101, 192, 0.18);
}

.g-keyword-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* ===== Inline review (post-game) ===== */

.g-review-inline {
    margin-top: 1rem;
    padding: 1.1rem 1rem;
    background: var(--c-bg, #f8fafc);
    border: 1px solid var(--c-line, #e2e8f0);
    border-radius: 10px;
    animation: g-slide-in 320ms ease-out;
}

.g-review-inline[hidden] {
    display: none;
}

.g-review-title {
    margin: 0 0 0.4rem 0;
    font-size: 1.25rem;
    color: var(--c-ink, #0f172a);
}

.g-review-summary {
    text-align: center;
    margin-bottom: 1rem;
    padding-bottom: 0.9rem;
    border-bottom: 1px solid var(--c-line, #e2e8f0);
}

.g-review-summary p {
    margin: 0.3rem 0;
    color: var(--c-ink-soft, #334155);
}

.g-review-explanations {
    margin-top: 0.5rem;
}

.g-review-heading {
    font-weight: 700;
    margin: 0 0 0.6rem 0;
    font-size: 0.95rem;
    color: var(--c-ink, #0f172a);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.g-review-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--c-line, #e2e8f0);
}

.g-review-row:last-child {
    border-bottom: none;
}

.g-review-row-head {
    display: flex;
    align-items: baseline;
    gap: 0.45rem;
    flex-wrap: wrap;
    font-weight: 700;
}

.g-review-word {
    color: var(--c-ink, #0f172a);
    text-transform: uppercase;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
}

.g-review-word::after {
    content: " + ";
    color: var(--c-ink-mute, #64748b);
    font-weight: 500;
    margin: 0 0.1rem;
}

.g-review-solution {
    color: var(--c-blue, #0065c0);
    font-size: 0.95rem;
    text-transform: lowercase;
}

.g-review-explanation {
    color: var(--c-ink-soft, #334155);
    font-size: 0.92rem;
    line-height: 1.5;
    margin-top: 0.15rem;
}

.g-review-action {
    margin-top: 1.1rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}

/* ===== Message bar ===== */

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

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

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

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

/* ===== Modals ===== */

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

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

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

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

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

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

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

.g-help-list li {
    margin-bottom: 0.3rem;
}

.g-help-note {
    margin-top: 1rem;
}

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

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

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

.g-stats-num {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--c-ink, #0f172a);
    line-height: 1.1;
}

.g-stats-num-small {
    font-size: 1rem;
    font-family: var(--font-mono, ui-monospace, monospace);
}

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

.g-stats-distrib {
    font-weight: 700;
    margin-top: 1rem;
    margin-bottom: 0.4rem;
}

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

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

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

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

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

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

/* ===== Share modal (multi-platform) ===== */

.g-share-text-preview {
    background: var(--c-bg, #f8fafc);
    border: 1px solid var(--c-line, #e2e8f0);
    border-radius: 6px;
    padding: 0.7rem 0.9rem;
    margin-bottom: 1rem;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--c-ink-soft, #334155);
    white-space: pre-wrap;
    word-break: break-word;
}

.g-share-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.5rem;
}

.g-share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.65rem 0.9rem;
    border: 1px solid var(--c-line, #e2e8f0);
    border-radius: 8px;
    background: #fff;
    color: var(--c-ink, #0f172a);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 140ms;
    text-decoration: none;
    font-family: inherit;
}

.g-share-btn:hover {
    background: var(--c-bg, #f8fafc);
    border-color: var(--c-blue, #0065c0);
    color: var(--c-blue, #0065c0);
    transform: translateY(-1px);
}

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

.g-share-btn-primary:hover {
    background: var(--c-blue, #0065c0);
    color: #fff;
    border-color: var(--c-blue, #0065c0);
}

.g-share-btn-icon {
    width: 1.1em;
    height: 1.1em;
    fill: currentColor;
    flex: 0 0 auto;
}

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

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

/* ===== Responsive tweaks ===== */

@media (max-width: 480px) {
    .g-status-bar {
        font-size: 0.85rem;
        padding: 0.5rem 0.6rem;
    }

    .g-tile {
        font-size: 0.95rem;
        min-height: 75px;
        padding: 1rem 0.5rem;
    }

    .g-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .g-modal-box {
        padding: 1.2rem 1rem;
    }
}
