/* Globalne zabezpieczenie przed wychodzeniem tekstu z przycisków */
#main-content button,
.site-main button {
    box-sizing: border-box !important;
    max-width: 100% !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    line-height: 1.25 !important;
}

.btn-back-to-menu, 
.btn-mzk-mute-toggle, 
.sudoku-numpad-btn,
.tab-top10 {
    white-space: nowrap !important;
}

/* Paski nagłówkowe w grach - zawsze na samej górze, klikalne */
.game-header-bar {
    position: relative !important;
    z-index: 50 !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

/* Przycisk Wróć - wyrazisty, łatwy do kliknięcia na telefonach */
.btn-back-to-menu {
    position: relative !important;
    z-index: 51 !important;
    white-space: nowrap !important;
    min-height: 44px !important;
    padding: 5px 12px !important;
    font-size: 0.88rem !important;
    font-weight: 600 !important;
    touch-action: manipulation !important;
    cursor: pointer !important;
}

/* Kontener canvasa ograniczający nakładkę dokładnie do obszaru gry */
.mzk-canvas-wrapper {
    position: relative !important;
    width: 100% !important;
    overflow: hidden !important;
    line-height: normal !important;
}
.mzk-canvas-wrapper canvas {
    display: block !important;
}

/* Nakładka menu i Game Over - przewijalna na małych ekranach, nie wychodzi poza canvas */
.game-ui-overlay {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    z-index: 10 !important;
    display: flex;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 14px 12px 18px 12px !important;
    box-sizing: border-box !important;
    line-height: 1.35 !important;
}

/* Bezwzględne ukrycie nakładki, gdy JS ustawi display: none lub klasę .is-hidden */
.game-ui-overlay[style*="display: none"],
.game-ui-overlay.is-hidden {
    display: none !important;
}

/* Zawartość nakładki z wyśrodkowaniem margin: auto 0 */
.mzk-overlay-content {
    margin: auto 0 !important;
    width: 100% !important;
    max-width: 330px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    text-align: center !important;
    line-height: 1.35 !important;
}

.mzk-overlay-content h2 {
    line-height: 1.25 !important;
    margin: 0 0 6px 0 !important;
}

.mzk-overlay-content p {
    line-height: 1.35 !important;
    margin: 6px 0 12px 0 !important;
}

.mzk-tip-box {
    line-height: 1.35 !important;
}

/* Wtórny przycisk powrotu do menu na ekranie Game Over */
.btn-back-to-menu-overlay {
    margin-top: 8px !important;
    background: rgba(255,255,255,0.18) !important;
    border: 1px solid rgba(255,255,255,0.45) !important;
    color: #fff !important;
    padding: 8px 16px !important;
    border-radius: 25px !important;
    font-size: 0.88rem !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    width: 100% !important;
    max-width: 240px !important;
    min-height: 40px !important;
    box-sizing: border-box !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    transition: background 0.15s !important;
}
.btn-back-to-menu-overlay:hover,
.btn-back-to-menu-overlay:active {
    background: rgba(255,255,255,0.3) !important;
}

/* Responsywność dla małych ekranów mobilnych */
@media (max-width: 480px) {
    .game-ui-overlay h2 {
        font-size: 1.7rem !important;
    }
    .game-ui-overlay p {
        font-size: 0.82rem !important;
        margin: 6px 0 10px 0 !important;
    }
    .mzk-tip-box {
        font-size: 0.72rem !important;
        padding: 6px 10px !important;
        margin-top: 10px !important;
    }
}

.sudoku-board-container { display: flex; justify-content: center; background: #fff; padding: 10px; border-radius: 8px; }
.sudoku-board { border-collapse: collapse; border: 3px solid #004e92; background: #fff; margin: 0 auto; user-select: none; }
.sudoku-cell { width: 38px; height: 38px; text-align: center; font-size: 19px; font-weight: bold; color: #2c3e50; border: 1px solid #d5dbdb; cursor: pointer; transition: background 0.15s, transform 0.1s; font-family: 'Segoe UI', Arial, sans-serif; }
.sudoku-cell.fixed { background: #f2f4f4; color: #003666; font-weight: 800; }
.sudoku-cell.selected { background: #d4e6f1 !important; outline: 3px solid #2980b9; outline-offset: -2px; }
.sudoku-cell.related { background: #ebf5fb; }
.sudoku-cell.same-num { background: #d5f5e3; color: #145a32; }
.sudoku-cell.error { background: #fadbd8 !important; color: #c0392b !important; font-weight: 900; }

/* Obramowania bloków w zależności od rozmiaru */
.sudoku-grid-4 td:nth-child(2n) { border-right: 2px solid #004e92; }
.sudoku-grid-4 tr:nth-child(2n) td { border-bottom: 2px solid #004e92; }
.sudoku-grid-4 .sudoku-cell { width: 56px; height: 56px; font-size: 26px; }

.sudoku-grid-6 td:nth-child(3n) { border-right: 2px solid #004e92; }
.sudoku-grid-6 tr:nth-child(2n) td { border-bottom: 2px solid #004e92; }
.sudoku-grid-6 .sudoku-cell { width: 46px; height: 46px; font-size: 22px; }

.sudoku-grid-9 td:nth-child(3n) { border-right: 2px solid #004e92; }
.sudoku-grid-9 tr:nth-child(3n) td { border-bottom: 2px solid #004e92; }
.sudoku-grid-9 .sudoku-cell { width: 36px; height: 36px; font-size: 18px; }

@media (max-width: 400px) {
    .sudoku-grid-9 .sudoku-cell { width: 32px; height: 32px; font-size: 16px; }
    .sudoku-grid-6 .sudoku-cell { width: 42px; height: 42px; font-size: 20px; }
    .sudoku-grid-4 .sudoku-cell { width: 52px; height: 52px; font-size: 24px; }
}

.sudoku-numpad-btn { width: 34px; height: 38px; border-radius: 6px; border: 1px solid #bdc3c7; background: #fff; color: #003666; font-size: 1.15rem; font-weight: bold; cursor: pointer; transition: all 0.15s; display: flex; align-items: center; justify-content: center; box-sizing: border-box; }
.sudoku-numpad-btn:hover, .sudoku-numpad-btn:active { background: #004e92; color: #fff; border-color: #004e92; transform: translateY(-2px); }
body:not(.high-contrast) .mzk-pin-interactive:hover { transform: scale(1.12); color: #9e1926 !important; }
.mzk-pin-interactive:focus-visible { outline: 3px solid #004e92; outline-offset: 4px; border-radius: 8px; }
html[data-theme="dark"] body:not(.high-contrast) .mzk-pin-interactive:focus-visible { outline-color: #93c5fd !important; }

/* Dark mode overrides for games UI */
html[data-theme="dark"] body:not(.high-contrast) #game-sudoku-container {
    background: #131d31 !important;
    color: #e2e8f0 !important;
}
html[data-theme="dark"] body:not(.high-contrast) .sudoku-board-container {
    background: #0f172a !important;
    border: 1px solid #26344d;
}
html[data-theme="dark"] body:not(.high-contrast) .sudoku-board {
    background: #0f172a !important;
    border-color: #60a5fa !important;
}
html[data-theme="dark"] body:not(.high-contrast) .sudoku-cell {
    color: #f1f5f9 !important;
    border-color: #334155 !important;
    background: #131d31;
}
html[data-theme="dark"] body:not(.high-contrast) .sudoku-cell.fixed {
    background: #1e293b !important;
    color: #93c5fd !important;
}
html[data-theme="dark"] body:not(.high-contrast) .sudoku-cell.selected {
    background: #1d4ed8 !important;
    outline: 3px solid #facc15 !important;
    color: #ffffff !important;
}
html[data-theme="dark"] body:not(.high-contrast) .sudoku-cell.related {
    background: #1a2740 !important;
}
html[data-theme="dark"] body:not(.high-contrast) .sudoku-cell.same-num {
    background: #14532d !important;
    color: #bbf7d0 !important;
}
html[data-theme="dark"] body:not(.high-contrast) .sudoku-cell.error {
    background: #7f1d1d !important;
    color: #fecaca !important;
}
html[data-theme="dark"] body:not(.high-contrast) .sudoku-numpad-btn,
html[data-theme="dark"] body:not(.high-contrast) .btn-sudoku-size {
    background: #1e293b !important;
    border-color: #475569 !important;
    color: #e2e8f0 !important;
}
html[data-theme="dark"] body:not(.high-contrast) .btn-sudoku-size.is-active {
    background: #7c3aed !important;
    border-color: #a78bfa !important;
    color: #ffffff !important;
}
html[data-theme="dark"] body:not(.high-contrast) .sudoku-numpad-btn:hover,
html[data-theme="dark"] body:not(.high-contrast) .sudoku-numpad-btn:active {
    background: #2563eb !important;
    border-color: #60a5fa !important;
    color: #ffffff !important;
}
html[data-theme="dark"] body:not(.high-contrast) .inline-top10-wrapper h3 {
    color: #93c5fd !important;
}
html[data-theme="dark"] body:not(.high-contrast) #sudoku-status.is-success {
    color: #86efac !important;
}
html[data-theme="dark"] body:not(.high-contrast) #sudoku-status.is-error {
    color: #fca5a5 !important;
}
html[data-theme="dark"] body:not(.high-contrast) #sudoku-status.is-info {
    color: #93c5fd !important;
}
html[data-theme="dark"] body:not(.high-contrast) #sudoku-status.is-warn {
    color: #fde047 !important;
}
html[data-theme="dark"] body:not(.high-contrast) #top10-list-container,
html[data-theme="dark"] body:not(.high-contrast) #top10-list-container * {
    color: #e2e8f0 !important;
}
html[data-theme="dark"] body:not(.high-contrast) #location-status span {
    color: #93c5fd !important;
}
html[data-theme="dark"] body:not(.high-contrast) #location-status span[style*="color:#145a32"],
html[data-theme="dark"] body:not(.high-contrast) #location-status span[style*="color: #145a32"] {
    color: #86efac !important;
}
html[data-theme="dark"] body:not(.high-contrast) #location-status div[style*="color:#9e1926"],
html[data-theme="dark"] body:not(.high-contrast) #location-status div[style*="color: #9e1926"],
html[data-theme="dark"] body:not(.high-contrast) .inline-top10-content div[style*="color:#9e1926"],
html[data-theme="dark"] body:not(.high-contrast) .inline-top10-content div[style*="color: #9e1926"] {
    color: #fca5a5 !important;
}
html[data-theme="dark"] body:not(.high-contrast) .inline-top10-content div[style*="color:#555"],
html[data-theme="dark"] body:not(.high-contrast) .inline-top10-content div[style*="color: #555"],
html[data-theme="dark"] body:not(.high-contrast) .inline-top10-content td,
html[data-theme="dark"] body:not(.high-contrast) .inline-top10-content th {
    color: #cbd5e1 !important;
    border-color: #26344d !important;
}
html[data-theme="dark"] body:not(.high-contrast) .inline-top10-content .btn-show-top10 {
    color: #93c5fd !important;
    border-color: #3b82f6 !important;
}
html[data-theme="dark"] body:not(.high-contrast) .mzk-games-hint {
    background: #1e293b !important;
    border-color: #334155 !important;
    color: #cbd5e1 !important;
}

/* High contrast overrides for games UI */
body.high-contrast #game-lock-screen,
body.high-contrast #game-selection-screen,
body.high-contrast #game-sudoku-container,
body.high-contrast .sudoku-board-container,
body.high-contrast .inline-top10-wrapper,
body.high-contrast #mzk-top10-modal > div {
    background: #000000 !important;
    color: #ffffff !important;
    border: 2px solid #ffff00 !important;
}
body.high-contrast #game-lock-screen h1,
body.high-contrast #game-lock-screen p,
body.high-contrast #game-selection-screen h2,
body.high-contrast .inline-top10-wrapper h3,
body.high-contrast .inline-top10-content,
body.high-contrast #top10-title,
body.high-contrast #location-status {
    color: #ffff00 !important;
}
body.high-contrast .sudoku-board {
    background: #000000 !important;
    border-color: #ffff00 !important;
}
body.high-contrast .sudoku-cell {
    background: #000000 !important;
    color: #ffffff !important;
    border-color: #ffff00 !important;
}
body.high-contrast .sudoku-cell.fixed {
    background: #1a1a00 !important;
    color: #ffff00 !important;
}
body.high-contrast .sudoku-cell.selected {
    background: #ffff00 !important;
    color: #000000 !important;
    outline: 3px solid #ffffff !important;
}
body.high-contrast .sudoku-cell.error {
    background: #990000 !important;
    color: #ffffff !important;
}
body.high-contrast .sudoku-numpad-btn,
body.high-contrast .btn-sudoku-size {
    background: #000000 !important;
    color: #ffff00 !important;
    border: 2px solid #ffff00 !important;
}
body.high-contrast .btn-sudoku-size.is-active,
body.high-contrast .sudoku-numpad-btn:hover,
body.high-contrast .sudoku-numpad-btn:active {
    background: #ffff00 !important;
    color: #000000 !important;
}
