/* Minesweeper-specific styles */

@font-face {
    font-family: 'PixelOperator8';
    src: url('fonts/Pixel-Operator-8/PixelOperator8.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

.minesweeper-window {
    width: auto;
    margin: 10px auto 0 !important;
    position: relative;
    visibility: hidden;
}

.minesweeper-window.ready {
    visibility: visible;
}

.minesweeper-content {
    padding: 3px 1px;
    background: #c0c0c0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.field-frame {
    display: inline-block;
    background: #c0c0c0;
    padding: 5px;
    border: 3px solid;
    border-color: #ffffff #808080 #808080 #ffffff;
    position: relative;
}

.field-frame::before {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    border: 2px solid;
    border-color: #dfdfdf #404040 #404040 #dfdfdf;
    pointer-events: none;
    z-index: -1;
}

.controls-frame {
    width: 100%;
    box-sizing: border-box;
    background: #c0c0c0;
    border: 3px solid;
    border-color: #808080 #ffffff #ffffff #808080;
    padding: 2px 5px;
    margin-bottom: 6px;
    position: relative;
}

.controls-frame::before {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    border: 2px solid;
    border-color: #808080 #dfdfdf #dfdfdf #808080;
    pointer-events: none;
    z-index: -1;
}

.minesweeper-controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    background: transparent;
}

.mine-counter, .timer {
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid;
    border-color: #808080 #ffffff #ffffff #808080;
    gap: 0;
    height: 23px;
    line-height: 0;
    font-size: 0;
    position: relative;
    box-shadow: inset -1px -1px 0 #dfdfdf, inset 1px 1px 0 #000000;
}

.mine-counter {
    justify-self: start;
    margin: 0;
}

.timer {
    justify-self: end;
    margin: 0;
}

.mine-counter span, .timer span {
    display: block;
    width: 13px;
    height: 23px;
    background-image: url('images/minesweeper/sprite100.gif');
    background-repeat: no-repeat;
    background-size: 144px 91px;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    float: left;
    /* Prevent subpixel rendering shifts in Firefox */
    transform: translateZ(0);
    will-change: background-position;
    backface-visibility: hidden;
}

.mine-counter span:first-child {
    margin-left: 0;
}

.mine-counter span:not(:first-child) {
    margin-left: 0;
}

.timer span:last-child {
    margin-right: 0;
}

.face-button {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid;
    border-color: #ffffff #808080 #808080 #ffffff;
    background: #c0c0c0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    min-width: unset;
    justify-self: center;
    margin: 0;
    position: relative;
    box-sizing: border-box;
}

.face-button::after {
    content: '';
    width: 26px;
    height: 26px;
    background-image: url('images/minesweeper/sprite100.gif');
    background-size: 144px 91px;
    background-repeat: no-repeat;
    background-position: 0 -55px;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.face-button:active {
    border-color: #808080 #ffffff #ffffff #808080;
}

.face-button:active::after {
    background-position: -26px -55px;
}

.face-button.game-active::after {
    background-position: -52px -55px;
}

.face-button.game-won::after {
    background-position: -104px -55px;
}

.face-button.game-lost::after {
    background-position: -78px -55px;
}

.face-button span {
    display: none;
}

.minesweeper-board-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    position: relative;
    line-height: 0;
    font-size: 0;
    background: #c0c0c0;
    border: 3px solid;
    border-color: #808080 #ffffff #ffffff #808080;
    padding: 0;
    box-sizing: border-box;
}

.minesweeper-board-wrapper::before {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    border: 2px solid;
    border-color: #808080 #dfdfdf #dfdfdf #808080;
    pointer-events: none;
    z-index: -1;
}

.minesweeper-board {
    background-color: #c0c0c0;
    display: inline-block;
    padding: 0;
    margin: 0;
    border: none;
    position: relative;
    line-height: 0;
    font-size: 0;
    white-space: nowrap;
}

.minesweeper-row {
    display: block;
    line-height: 0;
    font-size: 0;
    white-space: nowrap;
}

.minesweeper-cell {
    width: 20px;
    height: 20px;
    border: none;
    background-image: url('images/minesweeper/sprite100.gif');
    background-repeat: no-repeat;
    background-size: 180px 114px;
    background-position: 0 -49px;
    display: inline-block;
    vertical-align: top;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    position: relative;
    padding: 0;
    margin: 0;
    line-height: 0;
    font-size: 0;
    box-sizing: border-box;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* When pressing down on unrevealed cell - shows pressed/open look (only left-click on plain cells) */
.minesweeper-board:not(.right-clicking) .minesweeper-cell:active:not(.revealed):not(.flagged):not(.question) {
    background-position: 0 -29px;
}

/* Revealed empty cell - shows flat empty tile (open0) */
.minesweeper-cell.revealed {
    background-position: 0 -29px;
}

/* Revealed numbered cells */
.minesweeper-cell.revealed.number-1 {
    background-position: -20px -29px;
}

.minesweeper-cell.revealed.number-2 {
    background-position: -40px -29px;
}

.minesweeper-cell.revealed.number-3 {
    background-position: -60px -29px;
}

.minesweeper-cell.revealed.number-4 {
    background-position: -80px -29px;
}

.minesweeper-cell.revealed.number-5 {
    background-position: -100px -29px;
}

.minesweeper-cell.revealed.number-6 {
    background-position: -120px -29px;
}

.minesweeper-cell.revealed.number-7 {
    background-position: -140px -29px;
}

.minesweeper-cell.revealed.number-8 {
    background-position: -160px -29px;
}

/* Flagged cell */
.minesweeper-cell.flagged {
    background-position: -20px -49px;
}

/* Question mark cell */
.minesweeper-cell.question {
    background-position: -100px -49px;
}

/* Revealed mine (on game over) */
.minesweeper-cell.mine {
    background-position: -80px -49px;
}

/* Exploded mine (the one clicked) */
.minesweeper-cell.exploded {
    background-position: -40px -49px;
}

/* Wrong flag (flagged a non-mine) */
.minesweeper-cell.wrong-flag {
    background-position: -60px -49px;
}


/* Number colors are now handled by images, but keep for text fallback */
.minesweeper-cell.revealed.number-1,
.minesweeper-cell.revealed.number-2,
.minesweeper-cell.revealed.number-3,
.minesweeper-cell.revealed.number-4,
.minesweeper-cell.revealed.number-5,
.minesweeper-cell.revealed.number-6,
.minesweeper-cell.revealed.number-7,
.minesweeper-cell.revealed.number-8 {
    color: transparent;
}

/* Best Times Dialog */
.best-times-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.best-times-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.best-times-label {
    font-weight: bold;
    font-family: 'MS Sans Serif', Arial, sans-serif;
}

.best-times-value {
    font-family: 'MS Sans Serif', Arial, sans-serif;
    margin-left: 16px;
}

.best-times-name {
    font-family: 'MS Sans Serif', Arial, sans-serif;
    margin-left: 16px;
    color: #000080;
}


#bestTimesDialog .dialog-buttons {
    flex-direction: row;
    position: static;
    transform: none;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
}

#bestTimesDialog .dialog-button {
    width: auto;
    min-width: 90px;
}

/* Face button states */
.face-button.game-won .face-happy,
.face-button.game-won .face-scared,
.face-button.game-won .face-dead {
    display: none;
}

.face-button.game-won .face-cool {
    display: inline-block;
}

.face-button.game-lost .face-happy,
.face-button.game-lost .face-scared,
.face-button.game-lost .face-cool {
    display: none;
}

.face-button.game-lost .face-dead {
    display: inline-block;
}

.face-button.game-active .face-happy,
.face-button.game-active .face-dead,
.face-button.game-active .face-cool {
    display: none;
}

.face-button.game-active .face-scared {
    display: inline-block;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    body {
        padding: 0;
        margin: 0;
        display: flex;
        justify-content: center;
        align-items: flex-start;
        min-height: 100vh;
        padding-top: 10px;
        padding-bottom: 40px; /* Space for taskbar */
    }
    
    /* Ensure taskbar is fixed at bottom on mobile */
    .taskbar {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 9999 !important;
    }
    
    /* Ensure leaderboard dialogs are above taskbar */
    #seasonLeaderboardDialog, #globalLeaderboardDialog {
        z-index: 10000 !important;
    }

    .minesweeper-window {
        width: auto;
        max-width: 100vw;
        min-height: auto;
        height: auto;
    }

    .title-bar {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    /* Mobile flag toggle button */
    .mobile-controls {
        display: flex;
        justify-content: center;
        padding: 8px;
        gap: 10px;
        background: #c0c0c0;
    }

    .flag-toggle {
        padding: 6px 16px;
        font-family: 'MS Sans Serif', 'Segoe UI', Tahoma, sans-serif;
        font-size: 12px;
        background: #c0c0c0;
        border: 2px solid;
        border-color: #ffffff #808080 #808080 #ffffff;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .flag-toggle:active {
        border-color: #808080 #ffffff #ffffff #808080;
    }

    .flag-toggle.active {
        border-color: #808080 #ffffff #ffffff #808080;
        background: #a0a0a0;
    }

    .flag-toggle .flag-icon {
        width: 16px;
        height: 16px;
        background: url('images/minesweeper/sprite100.gif');
        background-size: 180px 114px;
        background-position: -40px 0;
        image-rendering: pixelated;
    }

    /* Prevent text selection and callouts on touch */
    .minesweeper-board {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        touch-action: none; /* Prevent scrolling while interacting with board */
    }
    
    /* Allow dragging on title bar */
    .title-bar {
        touch-action: none;
    }

    .minesweeper-cell {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        width: 18px;
        height: 18px;
        background-size: 162px 103px;
        background-position: 0 -44px; /* Scaled from 0 -49px */
    }
    
    /* Beginner and intermediate stay at 20px on mobile */
    .difficulty-beginner .minesweeper-cell,
    .difficulty-intermediate .minesweeper-cell {
        width: 20px;
        height: 20px;
        background-size: 180px 114px;
        background-position: 0 -49px;
    }
    
    .difficulty-beginner .minesweeper-board:not(.right-clicking) .minesweeper-cell:active:not(.revealed):not(.flagged):not(.question),
    .difficulty-intermediate .minesweeper-board:not(.right-clicking) .minesweeper-cell:active:not(.revealed):not(.flagged):not(.question) {
        background-position: 0 -29px;
    }
    
    .difficulty-beginner .minesweeper-cell.revealed,
    .difficulty-intermediate .minesweeper-cell.revealed {
        background-position: 0 -29px;
    }
    
    .difficulty-beginner .minesweeper-cell.revealed.number-1,
    .difficulty-intermediate .minesweeper-cell.revealed.number-1 {
        background-position: -20px -29px;
    }
    
    .difficulty-beginner .minesweeper-cell.revealed.number-2,
    .difficulty-intermediate .minesweeper-cell.revealed.number-2 {
        background-position: -40px -29px;
    }
    
    .difficulty-beginner .minesweeper-cell.revealed.number-3,
    .difficulty-intermediate .minesweeper-cell.revealed.number-3 {
        background-position: -60px -29px;
    }
    
    .difficulty-beginner .minesweeper-cell.revealed.number-4,
    .difficulty-intermediate .minesweeper-cell.revealed.number-4 {
        background-position: -80px -29px;
    }
    
    .difficulty-beginner .minesweeper-cell.revealed.number-5,
    .difficulty-intermediate .minesweeper-cell.revealed.number-5 {
        background-position: -100px -29px;
    }
    
    .difficulty-beginner .minesweeper-cell.revealed.number-6,
    .difficulty-intermediate .minesweeper-cell.revealed.number-6 {
        background-position: -120px -29px;
    }
    
    .difficulty-beginner .minesweeper-cell.revealed.number-7,
    .difficulty-intermediate .minesweeper-cell.revealed.number-7 {
        background-position: -140px -29px;
    }
    
    .difficulty-beginner .minesweeper-cell.revealed.number-8,
    .difficulty-intermediate .minesweeper-cell.revealed.number-8 {
        background-position: -160px -29px;
    }
    
    .difficulty-beginner .minesweeper-cell.flagged,
    .difficulty-intermediate .minesweeper-cell.flagged {
        background-position: -20px -49px;
    }
    
    .difficulty-beginner .minesweeper-cell.question,
    .difficulty-intermediate .minesweeper-cell.question {
        background-position: -100px -49px;
    }
    
    .difficulty-beginner .minesweeper-cell.mine,
    .difficulty-intermediate .minesweeper-cell.mine {
        background-position: -80px -49px;
    }
    
    .difficulty-beginner .minesweeper-cell.exploded,
    .difficulty-intermediate .minesweeper-cell.exploded {
        background-position: -40px -49px;
    }
    
    .difficulty-beginner .minesweeper-cell.wrong-flag,
    .difficulty-intermediate .minesweeper-cell.wrong-flag {
        background-position: -60px -49px;
    }
    
    /* Scale all background positions for 18px cells (0.9x scale) */
    .minesweeper-board:not(.right-clicking) .minesweeper-cell:active:not(.revealed):not(.flagged):not(.question) {
        background-position: 0 -26px; /* Scaled from 0 -29px */
    }
    
    .minesweeper-cell.revealed {
        background-position: 0 -26px; /* Scaled from 0 -29px */
    }
    
    .minesweeper-cell.revealed.number-1 {
        background-position: -18px -26px; /* Scaled from -20px -29px */
    }
    
    .minesweeper-cell.revealed.number-2 {
        background-position: -36px -26px; /* Scaled from -40px -29px */
    }
    
    .minesweeper-cell.revealed.number-3 {
        background-position: -54px -26px; /* Scaled from -60px -29px */
    }
    
    .minesweeper-cell.revealed.number-4 {
        background-position: -72px -26px; /* Scaled from -80px -29px */
    }
    
    .minesweeper-cell.revealed.number-5 {
        background-position: -90px -26px; /* Scaled from -100px -29px */
    }
    
    .minesweeper-cell.revealed.number-6 {
        background-position: -108px -26px; /* Scaled from -120px -29px */
    }
    
    .minesweeper-cell.revealed.number-7 {
        background-position: -126px -26px; /* Scaled from -140px -29px */
    }
    
    .minesweeper-cell.revealed.number-8 {
        background-position: -144px -26px; /* Scaled from -160px -29px */
    }
    
    .minesweeper-cell.flagged {
        background-position: -18px -44px; /* Scaled from -20px -49px */
    }
    
    .minesweeper-cell.question {
        background-position: -90px -44px; /* Scaled from -100px -49px */
    }
    
    .minesweeper-cell.mine {
        background-position: -72px -44px; /* Scaled from -80px -49px */
    }
    
    .minesweeper-cell.exploded {
        background-position: -36px -44px; /* Scaled from -40px -49px */
    }
    
    .minesweeper-cell.wrong-flag {
        background-position: -54px -44px; /* Scaled from -60px -49px */
    }
}

/* Leaderboard Styles - Matching Dope Wars exactly */
#seasonLeaderboardDialog, #globalLeaderboardDialog {
    width: 470px !important;
    height: 550px !important;
    min-width: 470px;
    max-width: 470px;
    min-height: 550px;
    max-height: 550px;
    top: 42%;
    box-sizing: border-box;
    z-index: 10000 !important; /* Above taskbar (9999) */
}

/* Prevent page scrolling when dragging leaderboard dialogs on mobile */
#seasonLeaderboardDialog .title-bar,
#globalLeaderboardDialog .title-bar,
#seasonLeaderboardDialog .dialog-title-bar,
#globalLeaderboardDialog .dialog-title-bar {
    touch-action: none;
}

#seasonLeaderboardDialog .dialog-content,
#globalLeaderboardDialog .dialog-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    height: calc(100% - 50px);
    overflow: hidden;
    min-height: 400px; /* Ensure enough space for at least 4 score rows */
}

.leaderboard-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 12px;
}

.leaderboard-tab {
    background: #c0c0c0;
    border: 2px solid;
    border-color: #ffffff #808080 #404040 #dfdfdf;
    border-bottom: none;
    color: black;
    font-family: 'MS Sans Serif', Arial, sans-serif;
    font-size: 13px;
    padding: 2px 6px;
    cursor: pointer;
    min-width: 90px;
    position: relative;
    top: 2px;
    text-align: center;
    user-select: none;
}

.leaderboard-tab:hover {
    background: #d4d0c8;
}

.leaderboard-tab:active {
    border-color: #404040 #dfdfdf #dfdfdf #404040;
    padding: 3px 5px 1px 7px;
}

.leaderboard-tab.active {
    font-weight: bold;
    color: #000080;
    border-bottom: 2px solid #c0c0c0;
    background: #c0c0c0;
    z-index: 1;
    border-color: #808080 #ffffff #c0c0c0 #808080;
    top: 0;
    padding: 2px 6px;
}

.leaderboard-tab.active:active {
    border-color: #404040 #dfdfdf #dfdfdf #404040;
    padding: 3px 5px 1px 7px;
    top: 0;
}

.high-scores-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    table-layout: fixed;
    background: white;
    border: 2px solid;
    border-color: #808080 #ffffff #ffffff #808080;
    box-shadow: inset 1px 1px #808080, inset -1px -1px #ffffff;
    flex: 1;
    overflow-y: auto;
    display: block;
    max-height: calc(100% - 50px);
    min-height: 120px; /* Ensure at least 4 rows are visible (4 * 20px + header ~20px = 100px, plus padding) */
}

.high-scores-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #c0c0c0;
    display: table;
    width: 100%;
}

.high-scores-table tbody {
    display: block;
    overflow-y: auto;
    width: 100%;
}

.high-scores-table tr {
    display: table;
    width: 100%;
    table-layout: fixed;
    height: 20px;
    line-height: 20px;
}

.high-scores-table th:first-child,
.high-scores-table td:first-child {
    width: 10%;
    text-align: center;
}

.high-scores-table th:nth-child(2),
.high-scores-table td:nth-child(2) {
    width: 40%;
    text-align: left;
}

.high-scores-table th:nth-child(3),
.high-scores-table td:nth-child(3) {
    width: 25%;
    text-align: right;
}

.high-scores-table th:last-child,
.high-scores-table td:last-child {
    width: 25%;
    text-align: center;
}

.high-scores-table th {
    background: #c0c0c0;
    text-align: left;
    font-weight: normal;
    border: 1px solid;
    border-color: #ffffff #808080 #808080 #ffffff;
    padding: 0 5px;
    height: 20px;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.high-scores-table td {
    padding: 0 5px;
    height: 20px;
    border: none;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.high-scores-table tr.empty-row td {
    background: white;
}

#seasonLeaderboardDialog .dialog-buttons,
#globalLeaderboardDialog .dialog-buttons {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    margin-top: auto;
    position: static;
    transform: none;
    padding: 0;
    background: transparent;
    width: 100%;
}

#seasonLeaderboardDialog .dialog-button,
#globalLeaderboardDialog .dialog-button {
    min-width: 90px;
    height: 32px;
    padding: 2px 6px;
}

#seasonScoreSubmission .dialog-buttons {
    display: flex;
    justify-content: center;
    margin-top: 8px;
}

.dialog-button#seasonSubmitScore {
    min-width: 126px;
    width: auto;
    padding: 11px 20px;
    height: 45px;
    line-height: 22px;
}

/* Center OK button at bottom for simple dialogs */
#aboutDialog .dialog-buttons,
#howToPlayDialog .dialog-buttons {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    margin-top: 16px;
    position: static;
    transform: none;
    padding: 0;
    background: transparent;
    width: 100%;
}

/* Hide mobile controls on desktop */
.mobile-controls {
    display: none;
}

/* Small phones - scale down cells */
/* Mobile leaderboard dialog sizing */
@media (max-width: 768px) {
    #seasonLeaderboardDialog, #globalLeaderboardDialog {
        width: 90vw !important;
        max-width: 90vw !important;
        min-width: 90vw !important;
        height: 70vh !important;
        max-height: 70vh !important;
        min-height: 70vh !important;
        top: 20px !important;
        transform: translate(-50%, 0) !important; /* Center horizontally, no vertical centering */
        left: 50% !important;
    }
    
    #seasonLeaderboardDialog .dialog-content,
    #globalLeaderboardDialog .dialog-content {
        padding: 12px;
    }
    
    .leaderboard-tab {
        font-size: 11px;
        padding: 2px 4px;
        min-width: 70px;
    }
    
    .high-scores-table {
        font-size: 12px;
    }
    
    .high-scores-table th,
    .high-scores-table td {
        padding: 4px 2px;
    }
}

@media (max-width: 400px) {
    .minesweeper-cell {
        width: 18px;
        height: 18px;
        background-size: 162px 103px;
    }
    
    #seasonLeaderboardDialog, #globalLeaderboardDialog {
        width: 95vw !important;
        max-width: 95vw !important;
        min-width: 95vw !important;
        height: 75vh !important;
        max-height: 75vh !important;
        min-height: 75vh !important;
        top: 20px !important;
        transform: translate(-50%, 0) !important; /* Center horizontally, no vertical centering */
        left: 50% !important;
    }
    
    .leaderboard-tab {
        font-size: 10px;
        padding: 2px 3px;
        min-width: 60px;
    }
}

    .face-button {
        width: 26px;
        height: 26px;
    }

    .mine-counter, .timer {
        width: 39px;
        height: 23px;
    }

    .digit {
        width: 12px;
        height: 21px;
    }
}

