/* Sudoku game-grade: layout single-board + toolbar + modali + highlights. */

/* ============================================================
   1. Toolbar (difficolta' + stats)
   ============================================================ */
.sk-game-section {
    max-width: 720px;
    margin: 0 auto;
}
.sk-toolbar {
    background: var(--c-bg-card);
    border: 1px solid var(--c-line);
    border-radius: var(--r-md);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-card);
}
.sk-difficulty-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.sk-toolbar-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--c-ink-mute);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.sk-difficulty-chips {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}
.sk-difficulty-chip {
    appearance: none;
    border: 1px solid var(--c-line);
    background: var(--c-bg-card);
    color: var(--c-ink-soft);
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.sk-difficulty-chip:hover { border-color: var(--c-blue); color: var(--c-blue); }
.sk-difficulty-chip.is-active {
    background: var(--c-blue);
    border-color: var(--c-blue);
    color: #fff;
}

.sk-stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 0.5rem;
}
.sk-stat {
    background: var(--c-bg);
    border-radius: var(--r-sm);
    padding: 0.45rem 0.75rem;
    text-align: center;
}
.sk-stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--c-ink-mute);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}
.sk-stat-value {
    display: block;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--c-ink);
    font-variant-numeric: tabular-nums;
}
.sk-stat-streak .sk-stat-value { color: #ea580c; }

/* ============================================================
   2. Board area (con pause overlay)
   ============================================================ */
.sk-board-wrap {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}
.sk-board-card {
    width: 100%;
    max-width: 520px;
    background: var(--c-bg-card);
    border: 1px solid var(--c-line);
    border-radius: var(--r-md);
    padding: 1.25rem;
    box-shadow: var(--shadow-card);
    overflow: hidden;
    min-width: 0;
}
.sk-board-area {
    position: relative;
    display: flex;
    justify-content: center;
}
.sk-pause-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.96);
    border-radius: var(--r-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    z-index: 5;
    cursor: pointer;
}
.sk-pause-icon {
    font-size: 2rem;
    color: var(--c-blue);
}
.sk-pause-overlay p {
    margin: 0;
    font-weight: 700;
    color: var(--c-ink);
}

/* ============================================================
   3. Board cells (table.sudoku) - single board grande
   ============================================================ */
@keyframes shake {
    0%   { margin-left: 0; }
    25%  { margin-left: 0.1rem; }
    75%  { margin-left: -0.1rem; }
    100% { margin-left: 0; }
}
@keyframes sk-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
    70%  { box-shadow: 0 0 0 12px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

table.sudoku {
    border-collapse: collapse;
    border: 2px solid #1f2937;
    margin: 0 auto;
    table-layout: fixed;
    max-width: 100%;
    background: #fff;
}
table.sudoku td {
    border: 1px solid #cbd5e1;
    width: 44px;
    min-width: 0;
    max-width: 44px;
    height: 44px;
    text-align: center;
    vertical-align: middle;
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: background 0.1s ease;
}
table.sudoku td[data-given="1"] {
    background: #f1f5f9;
    color: #0f172a;
    cursor: default;
}
table.sudoku td:nth-child(3n) { border-right: 2px solid #1f2937; }
table.sudoku tr:nth-child(3n) td { border-bottom: 2px solid #1f2937; }
table.sudoku td.solvable { background: #fff; }
table.sudoku td.solvable .input {
    display: block;
    width: 100%;
    height: 100%;
    min-width: 0;
    cursor: pointer;
    outline: none;
    line-height: 44px;
    text-align: center;
    overflow: hidden;
    color: #1d4ed8;
}
table.sudoku td.solvable .input:empty { min-height: 44px; }
table.sudoku td.solvable .input:focus { background: #dbeafe; }
table.sudoku td.solved { background: #ecfdf5; }
table.sudoku td.solved .input { color: #047857; }
table.sudoku td.wrong .input {
    animation: shake 0.1s ease-in-out 0s 4;
    color: #dc2626;
}
table.sudoku td.sk-error {
    background: #fee2e2 !important;
}
table.sudoku td.sk-error .input { color: #b91c1c; }

/* Highlight row/col/box */
table.sudoku td.sk-hl-row,
table.sudoku td.sk-hl-col,
table.sudoku td.sk-hl-box {
    background: #f0f9ff;
}
table.sudoku td.sk-hl-num {
    background: #dbeafe;
}
table.sudoku td.sk-hl-active {
    background: #bfdbfe !important;
    outline: 2px solid #1d4ed8;
    outline-offset: -2px;
    z-index: 1;
}

/* Pencil marks: 3x3 grid di candidati piccoli dentro cella */
.sk-pencil {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    line-height: 1;
}
.sk-pencil-cell {
    font-size: 10px;
    font-weight: 600;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Pencil mode active: cursor crosshair */
body.sk-pencil-mode table.sudoku td.solvable { cursor: crosshair; }
body.sk-pencil-mode #sk-btn-pencil { background: #fef3c7; color: #92400e; border-color: #fbbf24; }

/* Win state */
table.sudoku.sudoku-won {
    box-shadow: 0 0 0 3px #15803d, 0 0 30px rgba(34, 197, 94, 0.3);
    transition: box-shadow 0.5s ease;
}
table.sudoku.sudoku-won td.solvable {
    animation: sk-pulse 0.8s ease-out;
}

/* ============================================================
   4. Action bar (sotto la board)
   ============================================================ */
.sk-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    width: 100%;
    max-width: 520px;
}
.sk-modal-triggers {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    width: 100%;
}
.sk-icon-btn {
    appearance: none;
    background: transparent;
    border: 1px solid var(--c-line);
    color: var(--c-ink-soft);
    padding: 0.4rem 0.75rem;
    border-radius: var(--r-sm);
    font-size: 0.85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: background 0.15s, color 0.15s;
}
.sk-icon-btn:hover { background: #f1f5f9; color: var(--c-blue); border-color: var(--c-blue); }
.sk-icon-btn-label { font-weight: 600; }

/* ============================================================
   5. Modali
   ============================================================ */
.sk-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}
.sk-modal.is-open { display: flex; }
.sk-modal-box {
    background: #fff;
    border-radius: var(--r-md);
    max-width: 520px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.sk-modal-box--win {
    text-align: center;
}
.sk-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--c-line);
}
.sk-modal-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--c-ink);
}
.sk-modal-close {
    appearance: none;
    background: transparent;
    border: 0;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--c-ink-mute);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}
.sk-modal-close:hover { color: var(--c-ink); }
.sk-modal-body {
    padding: 1.25rem;
}

/* Help modal content */
.sk-help-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 1rem;
}
.sk-help-list li {
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--c-line);
    font-size: 0.92rem;
}
.sk-help-list li:last-child { border-bottom: 0; }
.sk-modal-body h4 {
    margin: 1rem 0 0.5rem;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--c-blue);
}

/* Stats modal */
.sk-stats-row {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--c-line);
}
.sk-stats-row:last-of-type { border-bottom: 0; }
.sk-stats-row-title {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--c-blue);
}
.sk-stats-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.25rem 1rem;
    margin: 0;
    font-size: 0.85rem;
}
.sk-stats-grid dt { color: var(--c-ink-mute); margin: 0; }
.sk-stats-grid dd { margin: 0; font-weight: 600; color: var(--c-ink); font-variant-numeric: tabular-nums; }
.sk-stats-streak-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1rem;
    padding: 0.75rem;
    background: #fef3c7;
    border-radius: var(--r-sm);
    text-align: center;
}
.sk-stats-streak-label {
    display: block;
    font-size: 0.75rem;
    color: #92400e;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
    margin-bottom: 0.25rem;
}
.sk-stats-streak-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #b45309;
}
.sk-stats-actions {
    margin-top: 1rem;
    text-align: right;
}

/* Settings modal */
.sk-settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--c-line);
}
.sk-settings-row:last-child { border-bottom: 0; }
.sk-settings-title {
    font-weight: 600;
    color: var(--c-ink);
    font-size: 0.95rem;
}
.sk-settings-desc {
    font-size: 0.8rem;
    color: var(--c-ink-mute);
    margin-top: 0.15rem;
}
.sk-settings-toggle {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
    flex-shrink: 0;
}

/* Win modal */
.sk-win-subtitle {
    font-size: 0.95rem;
    color: var(--c-ink-mute);
    margin: 0 0 1rem;
}
.sk-win-stats {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem 1rem;
    text-align: left;
    margin: 1rem auto;
    max-width: 320px;
}
.sk-win-stats dt {
    color: var(--c-ink-mute);
    font-size: 0.85rem;
}
.sk-win-stats dd {
    margin: 0;
    font-weight: 700;
    color: var(--c-ink);
    font-variant-numeric: tabular-nums;
}
.sk-win-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

/* Confirm modal */
.sk-modal-box--confirm {
    max-width: 420px;
    text-align: center;
}
.sk-modal-box--confirm .sk-modal-header {
    border-bottom: 0;
    padding-bottom: 0;
}
.sk-modal-box--confirm .sk-modal-title {
    font-size: 1rem;
    color: var(--c-ink-mute);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.sk-modal-box--confirm .sk-modal-body p {
    margin: 0.5rem 0 1.25rem;
    font-size: 1rem;
    color: var(--c-ink);
    line-height: 1.5;
}
.sk-confirm-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}
/* Variante destructive per il pulsante OK del confirm (es. reset stats) */
.sk-confirm-actions .sk-btn-danger {
    background: var(--c-danger);
    color: #fff;
    border-color: var(--c-danger);
}
.sk-confirm-actions .sk-btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

/* Body lock when modal open */
body.sk-modal-open { overflow: hidden; }

/* ============================================================
   6. Mobile responsive
   ============================================================ */
@media (max-width: 540px) {
    table.sudoku td { width: 36px; max-width: 36px; height: 36px; font-size: 18px; }
    table.sudoku td.solvable .input { line-height: 36px; }
    table.sudoku td.solvable .input:empty { min-height: 36px; }
    .sk-board-card { padding: 0.75rem; }
    .sk-pencil-cell { font-size: 8px; }
    .sk-icon-btn-label { display: none; }
    .sk-stat-value { font-size: 1rem; }
}

/* ============================================================
   7. Print mode (boards leggibili su carta)
   ============================================================ */
@media print {
    .sk-toolbar, .sk-actions, .sk-modal-triggers, .sk-pause-overlay, .sk-modal { display: none !important; }
    table.sudoku { border-color: #000 !important; }
    table.sudoku td { border-color: #999 !important; }
}
