/* The page around the game: the window, its title bar and menus, the dialogs and the instructions (and GameHub's frame
   view) */

* {
    margin: 0;
    padding: 0;
    user-select: none;
    font-family: 'MS Sans Serif', 'Tahoma', 'Arial', sans-serif;
}

body {
    background-color: #008080; /* Classic Windows teal background */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100dvh;
    padding: 10px;
    box-sizing: border-box;
}

/* The window fits the page: its parts keep their size, and the board takes the room left, and scrolls (css/game.css) */
.game-container {
    display: flex;
    flex-direction: column;
    box-sizing: border-box; /* The limits below include the window's border */
    min-width: 0;
    max-width: 100%;
    max-height: calc(100vh - 20px); /* The page's height, less the body's padding (in browsers without dvh) */
    max-height: calc(100dvh - 20px);
    overflow: auto;
    background-color: #c0c0c0;
    border: 4px outset #d4d0c8;
    padding: 3px;
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
}

.game-area {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-width: 100%;
    overflow: hidden;
}

/* What's there for screen readers only: the counters' numbers (js/minesweeper.js showLed()) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Windows 98 title bar: navy fading to blue */
.window-title-bar {
    background-color: #000080; /* Windows blue */
    background-image: linear-gradient(90deg, #000080, #1084d0);
    color: white;
    padding: 5px 6px;
    font-weight: bold;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .title {
        display: flex;
        gap: 4px;
        align-items: center;
    }

    .title img {
        height: 18px;
        transition: scale 10s;
    }

    .title img:hover {
        scale: 1000%;
    }

    .window-controls {
        display: flex;

        /* Raised, with a pixel glyph (img/icons/window-*.svg): the _ □ × in the markup is for reading only */
        .window-button {
            box-sizing: border-box;
            width: 18px;
            height: 16px;
            background: #c0c0c0 center / 8px 7px no-repeat;
            border: 1px solid;
            border-color: #fff #000 #000 #fff;
            box-shadow: inset -1px -1px #808080, inset 1px 1px #dfdfdf;
            margin-left: 2px;
            font-size: 0;
        }

        .window-button:active:not([aria-disabled="true"]) {
            border-color: #000 #fff #fff #000;
            box-shadow: inset 1px 1px #808080, inset -1px -1px #dfdfdf;
            background-position: calc(50% + 1px) calc(50% + 1px);
        }

        .window-button.minimize {
            background-image: url("../img/icons/window-minimize.svg");
        }

        .window-button.maximize {
            background-image: url("../img/icons/window-maximize.svg");
        }

        .window-button.close {
            margin-left: 4px; /* Close stands a little apart, as on Windows */
            background-image: url("../img/icons/window-close.svg");
        }

        .window-button:hover:not([aria-disabled="true"]) {
            cursor: pointer;
        }

        .window-button[aria-disabled="true"],
        .window-button[aria-disabled="true"]:hover {
            cursor: not-allowed;
        }
    }
}

/* Menu bar styling */
.menu-bar {
    display: flex;
    background-color: #c0c0c0;
    margin-top: 2px;
    border-bottom: 1px solid #808080;
    font-size: 12px;

    .menu-item {
        position: relative;
        cursor: default;
    }

    /* The whole name opens the menu: a click, a tap, or Enter (js/buttons-handler.js) */
    .menu-title {
        display: block;
        padding: 1px 8px;
    }

    .menu-title:focus-visible {
        outline: 1px dotted currentColor;
        outline-offset: -2px;
    }

    .menu-item:hover,
    .menu-item.open {
        background-color: #000080;
        color: white;
    }

    /* Open: on hover with a mouse (a touch screen's taps would keep it open), or opened (.open) */
    @media (hover: hover) {
        .menu-item:hover .menu-dropdown {
            display: block;
        }
    }

    .menu-item.open .menu-dropdown {
        display: block;
    }

    .menu-dropdown {
        display: none;
        position: absolute;
        left: 0;
        top: 100%;
        background-color: #c0c0c0;
        color: black; /* Not the open menu's white name */
        border: 2px outset white;
        box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
        z-index: 100;
        min-width: 150px;

        .menu-option {
            padding: 4px 14px;
            font-size: 12px;

            /* The wins on a level: a star and the count */
            .win-badge {
                display: inline-flex;
                align-items: center;
                gap: 3px;
                margin-left: 6px;
                font-weight: bold;
            }

            .win-badge::before {
                content: '';
                width: 11px;
                height: 11px;
                background: url("../img/icons/star.svg") center / contain no-repeat;
            }
        }

        .menu-option:hover,
        .menu-option:focus {
            background-color: #000080;
            color: white;
            outline: none;
        }

        .menu-separator {
            height: 1px;
            background-color: #808080;
            margin: 2px 1px;
        }

        .selected::before {
            content: "✓";
            margin-right: 4px;
        }
    }
}

.controls {
    margin-left: 8px;
    padding: 1px 8px;

    /* The flag mode switch: a flag on a raised button, pressed in while flag mode is on */
    #mode-toggle {
        box-sizing: border-box;
        width: 28px;
        height: 20px;
        background: #c0c0c0 url("../img/icons/flag.svg") center / 16px 16px no-repeat;
        border: 2px solid;
        border-color: #fff #808080 #808080 #fff;
        cursor: pointer;
    }

    #mode-toggle[aria-pressed="true"] {
        background-color: #dcdcdc;
        border-color: #808080 #fff #fff #808080;
        background-position: calc(50% + 1px) calc(50% + 1px);
    }

    #mode-toggle:active {
        border-color: #808080 #fff #fff #808080;
    }
}

/* Modal overlay: a <dialog> shown with showModal() (js/buttons-handler.js), over the whole page, without the browser's
   own dialog box and backdrop */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    border: none;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: flex-start;
    justify-content: center;
    padding: 10vh 0 0;

    &[open] {
        display: flex;
    }

    /* Closed, even when dragging it gave it display: block (the close event that clears that comes a moment later) */
    &:not([open]) {
        display: none !important;
    }

    &::backdrop {
        background-color: transparent;
    }

    /* Modal window */
    .modal-window {
        position: relative;
        font-size: 12px;
        background-color: #c0c0c0;
        border: 3px outset #d4d0c8;
        box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.5);
        min-width: 300px;
        max-width: 80%;
        margin: 5% auto;
    }

    /* Modal title bar */
    .modal-title-icon {
        height: 16px;
        margin-right: 6px;
    }

    .modal-title {
        display: flex;
        align-items: center;
    }

    .modal-close {
        background-color: #c0c0c0;
        color: black;
        border: 1px outset white;
        width: 16px;
        height: 14px;
        font-size: 9px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
    }

    .modal-close:active {
        border-style: inset;
    }

    /* Modal content */
    .modal-content {
        padding: 12px;
        font-size: 12px;
        overflow-y: auto;
        max-height: 60vh;
    }

    /* Modal buttons */
    .modal-buttons {
        display: flex;
        justify-content: center;
        padding: 8px;
        gap: 10px;
    }

    .modal-button {
        background-color: #c0c0c0;
        border: 2px outset #ffffff;
        padding: 3px 12px;
        font-size: 11px;
        min-width: 70px;
        cursor: pointer;
    }

    .modal-button:active {
        border-style: inset;
    }
}

/* The instructions (in the Help dialog): the controls lined up in a table with no lines, the mouse, the touch and the
   keys on the left, what they do on the right */
.modal-content h2 {
    margin: 0 0 6px;
    font-size: 14px;
}

.modal-content h3 {
    margin: 12px 0 4px;
    font-size: 12px;
}

.modal-content ul {
    margin: 0;
    padding-left: 18px;
}

.keys {
    border-collapse: collapse;
}

.keys th {
    padding: 10px 0 3px;
    text-align: left;
}

.keys td {
    padding: 3px 0;
    vertical-align: baseline;
}

.keys td:first-child {
    padding-right: 14px;
    white-space: nowrap;
}

/* A key: a raised grey button, as Windows drew them */
.modal-content kbd {
    display: inline-block;
    min-width: 14px;
    padding: 0 4px;
    border: 2px outset #ffffff;
    background-color: #c0c0c0;
    color: black;
    font: 11px 'MS Sans Serif', 'Tahoma', 'Arial', sans-serif;
    line-height: 15px;
    text-align: center;
}

@media screen and (max-width: 400px) {
    .window-title-bar .title h1 {
        font-size: 14px;
    }
}

/* GameHub's frame view (js/gamehub.js sets data-gamehub-view on <html>): the whole window, on the teal desktop, in the
   middle of the frame. The frame's height (its sizes in GameHub's games table) fits the window at its tallest (16 rows:
   Intermediate and Expert); a board wider than the frame scrolls sideways, and in a shorter frame, up and down. */
[data-gamehub-view="frame"] body {
    padding: 8px;
}

[data-gamehub-view="frame"] .game-container {
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
}

[data-gamehub-view="frame"] .instructions {
    display: none;
}

/* In GameHub's frame, Exit (and the line above it) isn't shown: the window's buttons take the game full screen and out */
[data-gamehub-view="frame"] #exit-game,
[data-gamehub-view="frame"] .menu-separator:has(+ #exit-game) {
    display: none;
}
