/*
============================================================================
PROJECTE: Motor Educatiu Step Quiz (Vanilla JS)
FITXER: css/estadistica.css
ROL: Estils específics per al joc d'estadística descriptiva.
DEPENDÈNCIES: S'ha de carregar DESPRÉS de shared.css.
============================================================================
*/
:root {
    --bg-color:      #f0fdf4;
    --primary:       #059669;
    --primary-light: #d1fae5;
    --primary-dark:  #065f46;
    --primary-hover: #047857;
    --text-main:     #1e293b;
    --text-muted:    #64748b;
    --border-light:  #e2e8f0;
    --border-heavy:  #cbd5e1;
    --success:       #10b981;
    --danger:        #ef4444;
    --danger-light:  #fee2e2;
    --accent:        #0369a1;
}

h1 { color: var(--primary-dark); }
.header-info { background-color: #ecfdf5; }
.level-text  { color: var(--primary-dark); }
.score-text  { color: var(--primary); }

/* ── CONTEXT ── */
.context-box {
    padding: 16px 22px 8px;
    font-size: 1.05em;
    line-height: 1.6;
    color: var(--text-main);
    max-width: 820px;
    margin: 0 auto;
}

/* ── DADES BRUTES ── */
.data-grid {
    padding: 0 22px 12px;
    max-width: 820px;
    margin: 0 auto;
}
.data-grid-inner {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    background: #f8fafc;
    border: 2px solid var(--border-light);
    border-radius: 10px;
    padding: 14px 18px;
}
.data-cell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 34px;
    background: white;
    border: 1px solid var(--border-heavy);
    border-radius: 6px;
    font-family: monospace;
    font-size: 1em;
    font-weight: 600;
    color: var(--text-main);
    padding: 0 8px;
    cursor: pointer;
    transition: background 0.25s, border-color 0.25s, color 0.25s;
    user-select: none;
}

/* ── FASE (títol + hint) ── */
.phase-bar {
    padding: 10px 22px 4px;
    max-width: 820px;
    margin: 0 auto;
}
.phase-title {
    font-size: 1.1em;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 3px;
}
.hint-bar {
    min-height: 16px;
    margin-bottom: 4px;
}
.hint-text {
    font-size: 0.88em;
    color: #78350f;
    background: #fffbeb;
    padding: 4px 12px;
    border-radius: 6px;
    display: inline-block;
    line-height: 1.5;
}

/* ── STEP DOTS (dins la capçalera, entre títol i punts) ── */
.step-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1 1 auto;
    justify-content: center;
    padding: 0 12px;
}
.sd-dot {
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--border-heavy);
    transition: background 0.3s;
}
.sd-dot.sd-done { background: var(--success); }
.sd-dot.sd-cur  { background: var(--primary); box-shadow: 0 0 0 3px rgba(5,150,105,0.25); }
.sd-conn { width: 14px; height: 2px; background: var(--border-heavy); }

/* ── TAULA + BOTÓ OK (layout horitzontal) ── */
.table-check-row {
    display: flex;
    align-items: flex-start;
    gap: 0;
    padding: 4px 22px 12px;
    max-width: 820px;
    margin: 0 auto;
}

/* ── TAULA DE FREQÜÈNCIES ── */
.table-wrap {
    flex: 1 1 0;
    min-width: 0;
    overflow-x: auto;
    overflow-y: auto;
}
.freq-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
}
.freq-table th {
    background: var(--primary-dark);
    color: white;
    padding: 7px 10px;
    text-align: center;
    font-size: 0.88em;
    font-weight: 700;
    letter-spacing: 0.3px;
}
.freq-table td {
    padding: 5px 8px;
    text-align: center;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
.freq-table tfoot td {
    font-weight: 700;
    background: #f1f5f9;
    border-top: 2px solid var(--border-heavy);
}
.cell-label {
    font-family: monospace;
    font-weight: 600;
    color: var(--text-main);
    text-align: left !important;
    white-space: nowrap;
}
.cell-fixed {
    font-family: monospace;
    font-weight: 600;
    color: var(--accent);
}
.cell-input {
    width: 64px;
    height: 34px;
    text-align: center;
    font-family: monospace;
    font-size: 1em;
    font-weight: 600;
    border: 2px solid var(--border-heavy);
    border-radius: 6px;
    outline: none;
    color: var(--text-main);
    background: white;
    transition: border-color 0.2s, background 0.2s;
}
.cell-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(5,150,105,0.15);
}
.cell-input.cell-sm { width: 56px; }
.cell-input.cell-ok {
    border-color: var(--success) !important;
    background: #f0fdf4 !important;
    color: var(--success) !important;
}
.cell-input.cell-err {
    border-color: var(--danger) !important;
    background: #fef2f2 !important;
    color: var(--danger) !important;
    animation: shake 0.3s;
}
.freq-table-readonly .cell-fixed { color: var(--text-main); }

/* ── BOTÓ OK (al costat de la taula) ── */
.check-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    padding: 0 0 0 14px;
    align-self: stretch;
}
#btn-check {
    min-width: 56px;
    width: 56px;
    height: 56px;
    border-radius: 10px;
    font-size: 1em;
    touch-action: manipulation;
    padding: 0;
}

/* ── SELECCIÓ D'INTERVALS ── */
.interval-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 10px 0;
}
.btn-interval-option {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 20px;
    background: white;
    border: 2px solid var(--border-heavy);
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}
.btn-interval-option:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}
.btn-interval-option strong { font-size: 1.05em; color: var(--primary-dark); }
.interval-preview { font-size: 0.85em; color: var(--text-muted); font-family: monospace; }

/* ── SELECCIÓ D'INTERVAL (estadístics) ── */
.interval-select-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    padding: 10px 0;
}
.btn-interval-choice {
    padding: 12px 18px;
    font-family: monospace;
    font-size: 1em;
    font-weight: 600;
    background: white;
    border: 2px solid var(--border-heavy);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-interval-choice:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-light); }
.btn-interval-choice.choice-correct { border-color: var(--success) !important; background: #d1fae5 !important; color: var(--primary-dark) !important; }
.btn-interval-choice.choice-wrong   { border-color: var(--danger) !important; background: #fee2e2 !important; color: var(--danger) !important; opacity: 0.6; }

/* ── ESTADÍSTICS (input) ── */
.stats-wrap {
    padding: 8px 22px 16px;
    max-width: 820px;
    margin: 0 auto;
    text-align: center;
}
.stat-question { display: flex; justify-content: center; gap: 12px; align-items: center; }
.stat-input {
    width: 140px;
    height: 48px;
    text-align: center;
    font-family: monospace;
    font-size: 1.3em;
    font-weight: 700;
    border: 2px solid var(--border-heavy);
    border-radius: 10px;
    outline: none;
    color: var(--text-main);
}
.stat-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(5,150,105,0.15); }

/* ── FEEDBACK ── */
.feedback-bar {
    max-width: 780px;
    margin: 0 auto;
    padding: 10px 22px;
    text-align: center;
    font-size: 1em;
    font-weight: 600;
    border-radius: 8px;
    transition: opacity 0.3s;
}
.fb-ok   { color: #047857; background: #d1fae5; }
.fb-err  { color: #991b1b; background: #fee2e2; }
.fb-warn { color: #92400e; background: #fef3c7; }

/* ── SENSE SCROLL DE PÀGINA (PC / Tablet / Chromebook) ── */
@media (min-width: 601px) {
    html, body {
        height: 100vh;
        overflow: hidden;
    }
    body {
        padding-top: 10px;
        padding-bottom: 10px;
    }
    /* El panel ocupa tot l'espai vertical restant sota el títol */
    .panel {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }
    #game-screen {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }
    /* La taula-check-row s'expandeix per omplir l'espai */
    .table-check-row {
        flex: 1 1 auto;
        min-height: 0;
        align-items: stretch;
    }
    .table-wrap {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        max-height: none;
    }
    .check-bar {
        align-items: center;
    }
}

/* ── RESPONSIU ── */
@media (max-width: 600px) {
    .context-box, .data-grid, .phase-bar, .stats-wrap, .step-dots { padding-left: 12px; padding-right: 12px; }
    .table-check-row { padding-left: 12px; padding-right: 12px; }
    .cell-input { width: 50px; height: 32px; font-size: 16px; } /* [m11] iOS zoom fix: era 0.9em (~14.4px) */
    .cell-input.cell-sm { width: 44px; }
    .data-cell  { min-width: 32px; height: 28px; font-size: 0.9em; padding: 0 5px; }
    .stat-input { width: 110px; height: 42px; font-size: 1.1em; }
    .freq-table th { padding: 6px 4px; font-size: 0.78em; }
    .freq-table td { padding: 5px 4px; font-size: 0.85em; }
    #btn-check { width: 48px; height: 48px; font-size: 0.9em; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-4px); }
    75%      { transform: translateX(4px); }
}
