:root {
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --accent: #4a7c59;
    --accent-hover: #3b6346;
    
    /* Colori di gioco */
    --color-correct: #38a169;  /* Verde */
    --color-present: #d69e2e;  /* Giallo */
    --color-absent:  #e53e3e;  /* Rosso */
    --color-tile-bg: #ffffff;
    --color-tile-border: #cbd5e0;

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
}

/* HEADER */
.app-header {
    width: 100%;
    max-width: 600px;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--card-bg);
    box-shadow: var(--shadow);
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
}

.header-title {
    text-align: center;
}

.header-title h1 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: -0.5px;
}

.mode-toggle {
    display: inline-flex;
    background: #e2e8f0;
    padding: 2px;
    border-radius: 20px;
    margin-top: 4px;
}

.mode-btn {
    border: none;
    background: transparent;
    padding: 3px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 16px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.mode-btn.active {
    background: #ffffff;
    color: var(--accent);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.icon-btn {
    background: #edf2f7;
    border: none;
    font-size: 1.2rem;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: #e2e8f0;
}

.coffee-btn {
    display: inline-flex;
    align-items: center;
    background-color: #ffdd00;
    color: #000;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.8rem;
    padding: 6px 12px;
    border-radius: 20px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    transition: transform 0.15s ease;
}

.coffee-btn:hover {
    transform: scale(1.04);
}

/* MAIN CONTAINER */
.game-container {
    width: 100%;
    max-width: 450px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

/* TABELLONE BOARD */
.board {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.board-row {
    display: flex;
    gap: 8px;
    perspective: 1000px;
}

.tile {
    width: 60px;
    height: 60px;
    border: 2px solid var(--color-tile-border);
    border-radius: var(--radius-sm);
    background-color: var(--color-tile-bg);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: 800;
    text-transform: uppercase;
    user-select: none;
    transition: transform 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.tile.filled {
    border-color: #a0aec0;
    animation: pop 0.1s ease-in-out;
}

/* ANIMAZIONE RUOTA DELLA FORTUNA / FLIP */
.tile.flip {
    animation: flipWheel 0.6s ease forwards;
}

.tile.correct {
    background-color: var(--color-correct) !important;
    color: #ffffff !important;
    border-color: var(--color-correct) !important;
}

.tile.present {
    background-color: var(--color-present) !important;
    color: #ffffff !important;
    border-color: var(--color-present) !important;
}

.tile.absent {
    background-color: var(--color-absent) !important;
    color: #ffffff !important;
    border-color: var(--color-absent) !important;
}

/* BARRETTA ANTEPRIMA INPUT */
.input-preview-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--card-bg);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    width: 100%;
    justify-content: space-between;
}

.preview-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.preview-box {
    display: flex;
    gap: 6px;
}

.preview-char {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--accent);
    width: 20px;
    text-align: center;
}

.action-btn {
    border: none;
    background-color: var(--accent);
    color: white;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 700;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.action-btn.secondary {
    background-color: #e2e8f0;
    color: var(--text-primary);
}

/* TASTIERA */
.keyboard {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 5px;
}

.kb-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    width: 100%;
}

.key {
    background-color: #e2e8f0;
    border: none;
    border-radius: 4px;
    height: 48px;
    flex: 1;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.05s;
}

.key:active {
    transform: scale(0.95);
}

.key.wide {
    flex: 1.5;
    font-size: 0.75rem;
}

.key.correct {
    background-color: var(--color-correct) !important;
    color: white !important;
}

.key.present {
    background-color: var(--color-present) !important;
    color: white !important;
}

.key.absent {
    background-color: var(--color-absent) !important;
    color: white !important;
    opacity: 0.7;
}

/* NUOVA PARTITA BUTTON */
.new-game-container {
    margin-top: 10px;
    width: 100%;
    text-align: center;
}

.btn-primary {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--radius-md);
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(74, 124, 89, 0.3);
    transition: background 0.2s ease;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
}

.full-width {
    width: 100%;
    margin-top: 15px;
}

/* MODALE REGOLE E STATISTICHE */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-card {
    background: var(--card-bg);
    width: 90%;
    max-width: 420px;
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-card h2 {
    margin-bottom: 12px;
    font-size: 1.4rem;
    color: var(--accent);
}

.rules-examples {
    margin: 15px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.example-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
}

.example-tiles {
    display: flex;
    gap: 4px;
}

.example-row .tile {
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.rules-tip {
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: #f7fafc;
    padding: 10px;
    border-left: 3px solid var(--accent);
    margin-top: 10px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin: 20px 0;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #f7fafc;
    padding: 10px 5px;
    border-radius: var(--radius-sm);
}

.stat-val {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--accent);
}

.stat-lbl {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    text-align: center;
    margin-top: 2px;
}

/* FOOTER */
.app-footer {
    width: 100%;
    text-align: center;
    padding: 16px 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background-color: var(--card-bg);
    border-top: 1px solid #e2e8f0;
    margin-top: auto;
}

.footer-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
}

.footer-sub {
    font-size: 0.75rem;
    margin-top: 4px;
}

.footer-sub a {
    color: var(--text-secondary);
}

/* TOAST MESSAGES */
.toast-container {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
    pointer-events: none;
}

.toast {
    background: #2d3748;
    color: white;
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: fadeInOut 2s ease forwards;
}

/* KEYFRAMES ANIMAZIONI */
@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes flipWheel {
    0% { transform: rotateX(0deg); }
    50% { transform: rotateX(90deg); }
    100% { transform: rotateX(0deg); }
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translateY(-10px); }
    15% { opacity: 1; transform: translateY(0); }
    85% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-10px); }
}