[hidden] {
    display: none !important;
}

html, body {
    margin: 0;
    height: 100%;
    overflow: auto;
    background: #1f4e79;
    font-family: system-ui, sans-serif;
}

#board {
    display: block;
    width: 100vw;
    height: 100vh;
    touch-action: auto;
}

#game-buttons {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    display: flex;
    gap: 8px;
}

#game-buttons button {
    padding: 8px 14px;
    font-size: 16px;
}

/* Both classes, so this beats .modal-card's width wherever the rules sit in the file */
.modal-card.confirm-card {
    width: min(340px, 100%);
}

.confirm-card h2 {
    margin: 0;
    font-size: 1.3rem;
}

#game-over-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px 32px;
    background: #c0c0c0;
    color: #000;
    border: 1px solid #000;
    font-size: 18px;
    font-weight: bold;
}

#game-over-winner {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 8px;
}

.game-over-baron {
    height: 42px;
    image-rendering: pixelated;
}

#game-over-ok {
    margin-top: 8px;
    padding: 4px 28px;
    font-size: 16px;
}

/* Laid out like the original's Windows message box */
#surrender-offer-card {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 18px 20px 14px;
    background: #c0c0c0;
    color: #000;
    border: 1px solid #000;
    font-size: 15px;
}

#surrender-offer-message {
    display: flex;
    align-items: center;
    gap: 14px;
}

.question-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #6fa8f0, #1c55b8);
    color: #fff;
    font-size: 22px;
    font-weight: bold;
}

#surrender-offer-buttons {
    display: flex;
    justify-content: center;
    gap: 14px;
}

#surrender-offer-buttons button {
    min-width: 80px;
    padding: 4px 16px;
    font-size: 15px;
}

#surrender-error {
    color: #a00000;
}

/* Sized to its buttons. Both, to beat .modal-card.confirm-card's width */
#game-menu-dialog .modal-card.confirm-card {
    width: auto;
}

#game-menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#game-menu-buttons button {
    padding: 8px 14px;
    font-size: 16px;
}

/* Set apart from the buttons that do something */
#game-settings,
#game-menu-close {
    margin-top: 12px;
}

#side-panels {
    position: fixed;
    top: max(60px, calc(env(safe-area-inset-top) + 48px));
    right: max(12px, env(safe-area-inset-right));
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    z-index: 10;
}

#minimap {
    display: block;
    width: 100%;
    /* Its drawing size is taken from its displayed width, so its pixel size mustn't feed back into the column's width */
    contain: inline-size;
    box-sizing: border-box;
    background: #1f4e79;
    border: 1px solid #000;
}

/* The original game's panel grey */
#region-panel,
#power-panel {
    background: #c0c0c0;
    color: #000;
}

#region-panel {
    position: relative;
    /* Fixed, so it doesn't resize as the money and buy icons change. Fits "Expenses 9999" */
    width: 140px;
    box-sizing: border-box;
    padding: 12px;
    font-size: 14px;
}

#region-details {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

/* Shown in the region details' place when nothing is selected, which keeps the panel's size */
#turn-indicator {
    position: absolute;
    inset: 0;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
}

.region-stat {
    display: flex;
    justify-content: space-between;
    align-self: stretch;
}

#power-panel {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 12px;
    font-size: 12px;
    font-family: ui-monospace, monospace;
}

/* Each man's wage, as the original shows below the scores */
#wage-panel {
    display: grid;
    grid-template-columns: auto auto;
    justify-content: space-evenly;
    gap: 4px 12px;
    padding: 8px 12px;
    background: #c0c0c0;
    color: #000;
    font-size: 12px;
    font-family: ui-monospace, monospace;
}

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

.wage-icon {
    width: 18px;
    height: 28px;
    image-rendering: pixelated;
}

/* Only on a phone, where the scores and wages aren't beside the board */
.phone-only {
    display: none;
}

/* Set apart from the buttons that do something, like Settings below them */
#menu-scores {
    margin-top: 12px;
}

/* Under the title, and below the bars once two humans are playing, sunken like the old Windows separators */
.power-rule {
    width: 100%;
    margin: 4px 0 2px;
    border: none;
    border-top: 1px solid #808080;
    border-bottom: 1px solid #fff;
}

#power-rows {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.power-turn {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.seat-icon {
    display: flex;
    flex: none;
    /* With its padding and border, the same height as a bar row was before */
    width: 12px;
    height: 12px;
    padding: 1px;
    border: 1px solid transparent;
}

.seat-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

/* The seat whose turn it is */
.seat-icon.current {
    border-color: #000;
    background: #fff;
}

.power-bar-track {
    flex: 1;
    height: 14px;
}

/* Square with a hard 1px shadow down and to the right, as in the original */
.power-bar {
    height: 100%;
    box-shadow: 1px 1px 0 #000;
}

#buy-icons {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    align-self: stretch;
    justify-content: space-evenly;
}

/* Over the buy icons, which keep their space hidden, for a region that isn't the player's */
#region-owner {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.buy-icon {
    /* Sized from code to whole screen pixels per sprite pixel */
    image-rendering: pixelated;
}

#peasant-icon {
    cursor: pointer;
}

#castle-icon {
    cursor: pointer;
}

/* Another player's held unit. Its position arrives a few times a second, so it glides between them */
#remote-held {
    position: fixed;
    display: none;
    width: auto;
    image-rendering: pixelated;
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 19;
    transition: left 125ms linear, top 125ms linear;
}

#floating-peasant {
    position: fixed;
    display: none;
    width: auto;
    image-rendering: pixelated;
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 20;
}

#turn-controls {
    position: fixed;
    bottom: max(12px, env(safe-area-inset-bottom));
    right: max(12px, env(safe-area-inset-right));
    display: flex;
    gap: 8px;
}

#undo,
#end-turn {
    padding: 8px 14px;
    font-size: 16px;
}

/* Game screen buttons, in the same grey as the side panels */
#undo,
#end-turn,
#game-buttons button {
    background: #c0c0c0;
    color: #000;
    border: 1px solid #808080;
    border-radius: 0;
    cursor: pointer;
}

#undo:hover:not(:disabled),
#end-turn:hover:not(:disabled),
#game-buttons button:hover {
    background: #d0d0d0;
}

#undo:active:not(:disabled),
#end-turn:active:not(:disabled),
#game-buttons button:active {
    background: #a8a8a8;
}

#undo:disabled,
#end-turn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* No box of its own, so its panels and buttons sit where they're placed. On a phone it's the bar along the bottom */
#hud {
    display: contents;
}

/* Phones either way up: no room beside the board for the minimap, scores or wages. The menu shows the scores and wages
   instead */
@media (max-width: 640px), (max-height: 500px) {
    #game-buttons,
    #side-panels,
    #turn-controls {
        display: contents;
    }

    #minimap,
    #side-panels > #power-panel,
    #side-panels > #wage-panel {
        display: none;
    }

    #game-menu-buttons .phone-only {
        display: block;
    }

    /* Only now and then, so it stays up top out of the bar's way */
    #accept-surrender {
        position: fixed;
        top: max(12px, env(safe-area-inset-top));
        left: max(12px, env(safe-area-inset-left));
    }
}

/* A phone held upright: the selected region and the turn's buttons go along the bottom */
@media (max-width: 640px) {
    #hud {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
        background: #c0c0c0;
        /* Raised, like the old Windows panels */
        border-top: 1px solid #fff;
        box-shadow: 0 -1px 0 #808080;
    }

    #region-panel {
        grid-column: 1 / -1;
        width: auto;
        padding: 0 4px;
    }

    /* The figures down the left, the buy icons to their right */
    #region-details {
        display: grid;
        grid-template-columns: 110px 1fr;
        column-gap: 16px;
        row-gap: 2px;
        align-items: center;
    }

    #region-details > .region-stat {
        grid-column: 1;
    }

    #buy-icons {
        grid-column: 2;
        grid-row: 1 / span 3;
    }

    #turn-indicator {
        flex-direction: row;
        gap: 12px;
    }

    #game-menu {
        grid-row: 2;
        grid-column: 1;
    }

    #undo {
        grid-row: 2;
        grid-column: 2;
    }

    #end-turn {
        grid-row: 2;
        grid-column: 3;
    }
}

/* A phone on its side: too short for a bar along the bottom, so the same things go down the right */
@media (max-height: 500px) and (min-width: 641px) {
    #hud {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
        display: flex;
        flex-direction: column;
        gap: 8px;
        box-sizing: border-box;
        padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) 8px;
        overflow-y: auto;
        background: #c0c0c0;
        /* Raised, like the old Windows panels */
        border-left: 1px solid #fff;
        box-shadow: -1px 0 0 #808080;
    }

    #region-panel {
        flex: none;
    }

    /* The buttons at the bottom, in the same order as across an upright phone */
    #game-menu {
        order: 1;
        margin-top: auto;
    }

    #undo {
        order: 2;
    }

    #end-turn {
        order: 3;
    }
}

/* The menus, like an old game's website: a fixed-width grey page on a backdrop of islands */
/* The page's own sea colour shows through around the backdrop layer below, which the body's would cover */
body.menus {
    background: transparent;
}

/* The backdrop, tilted. A layer of its own well past the window's edges, so it still covers them once turned. Darkened
   so the page stands out from it */
body.menus::before {
    content: "";
    position: fixed;
    inset: -50%;
    z-index: -1;
    background: linear-gradient(rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.35)), var(--backdrop, none) #1f4e79;
    background-size: auto, var(--backdrop-size, auto);
    transform: rotate(-15deg);
    pointer-events: none;
}

#login-screen,
.screen {
    box-sizing: border-box;
    /* Wide enough for a whole section of the island picker */
    width: min(1080px, 100%);
    min-height: 100%;
    margin: 0 auto;
    padding: 12px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    background: #c0c0c0;
    color: #000;
    font-family: Tahoma, Verdana, "MS Sans Serif", sans-serif;
    font-size: 14px;
    /* Raised edges, and a drop shadow onto the backdrop */
    border-left: 2px solid #fff;
    border-right: 2px solid #404040;
    box-shadow: 0 0 0 1px #000, 0 0 32px rgba(0, 0, 0, 0.7);
}

/* The banner along every page's top: the game's name on a sunken strip of sea */
#login-screen::before,
.screen::before {
    content: "SLAY";
    display: flex;
    align-items: center;
    justify-content: center;
    height: 96px;
    margin: max(0px, env(safe-area-inset-top)) 0 12px;
    /* Plain sea, deepening towards the bottom, so nothing competes with the name */
    background: linear-gradient(#2a6296, #12355a);
    color: #fff;
    font: bold 64px/1 "Times New Roman", Georgia, serif;
    letter-spacing: 0.2em;
    text-shadow: -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000, 5px 5px 0 rgba(0, 0, 0, 0.6);
    box-shadow: inset 1px 1px #808080, inset -1px -1px #fff, inset 2px 2px #000, inset -2px -2px #dfdfdf;
}

/* Over everything until signed in */
#login-screen {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

#login-screen::before {
    align-self: stretch;
}

#home-screen {
    position: relative;
}

/* Just under the banner, clear of the island art */
#logout-button {
    position: absolute;
    top: calc(max(0px, env(safe-area-inset-top)) + 132px);
    right: max(16px, env(safe-area-inset-right));
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: min(320px, 100%);
    margin: 48px auto;
}

/* Dialog buttons get the menus' bevel below. Each dialog sets its own sizes */
#game-over-ok,
.modal-card button,
#surrender-offer-buttons button {
    color: #000;
    background: #c0c0c0;
    border: none;
    border-radius: 0;
    box-shadow: inset -1px -1px #000, inset 1px 1px #fff, inset -2px -2px #808080, inset 2px 2px #dfdfdf;
    cursor: pointer;
}

#game-over-ok:active,
.modal-card button:active:not(:disabled),
#surrender-offer-buttons button:active {
    box-shadow: inset 1px 1px #000, inset -1px -1px #fff, inset 2px 2px #808080, inset -2px -2px #dfdfdf;
}

.modal-card button:disabled {
    color: #808080;
    text-shadow: 1px 1px #fff;
}

/* Raised grey buttons with the old Windows two-tone bevel, pressed in while held */
.screen button,
#login-screen button {
    padding: 6px 14px;
    font: inherit;
    color: #000;
    background: #c0c0c0;
    border: none;
    border-radius: 0;
    box-shadow: inset -1px -1px #000, inset 1px 1px #fff, inset -2px -2px #808080, inset 2px 2px #dfdfdf;
    cursor: pointer;
}

.screen button:active:not(:disabled),
#login-screen button:active {
    box-shadow: inset 1px 1px #000, inset -1px -1px #fff, inset 2px 2px #808080, inset -2px -2px #dfdfdf;
}

/* Greyed text with a white emboss, as old Windows showed it */
.screen button:disabled {
    color: #808080;
    text-shadow: 1px 1px #fff;
    cursor: not-allowed;
}

.screen .big-button {
    padding: 16px 24px;
    font: bold 22px "Times New Roman", Georgia, serif;
    letter-spacing: 0.04em;
}

.screen-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 10px;
    /* Etched, like the old Windows separators */
    border-bottom: 1px solid #808080;
    box-shadow: 0 1px #fff;
}

.screen-header h1 {
    margin: 0;
    font: bold 26px "Times New Roman", Georgia, serif;
}

#login-screen h1 {
    font: bold 26px "Times New Roman", Georgia, serif;
}

.screen h2 {
    font-family: "Times New Roman", Georgia, serif;
    font-size: 1.2rem;
}

/* Sunken white boxes, like old Windows list boxes */
#lobby-list,
#in-progress-list,
#ongoing-games-list,
#lobby-seats {
    background: #fff;
    box-shadow: inset 1px 1px #808080, inset -1px -1px #fff, inset 2px 2px #000, inset -2px -2px #dfdfdf;
    padding: 2px;
}

#lobby-list:empty,
#in-progress-list:empty,
#ongoing-games-list:empty {
    display: none;
}

/* Flat rows in the list boxes. Both, to beat .screen button */
.screen button.lobby-row,
.screen button.ongoing-game {
    box-shadow: none;
    background: none;
}

.screen button.lobby-row:hover,
.screen button.ongoing-game:hover {
    background: #e0e0e0;
}

#challenge-sections {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

/* Shrinks to its grid so the heading stays over the grid's left edge once centered */
.challenge-section {
    max-width: 100%;
}

.challenge-section h2 {
    margin: 0 0 0.25rem;
    font-size: 1.2rem;
}

/* Columns are set from the section size so every column holds exactly three islands */
.challenge-grid {
    display: grid;
    width: fit-content;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: auto;
    gap: 0;
    padding: 8px;
    background: #12355a;
    box-shadow: inset 1px 1px #808080, inset -1px -1px #fff, inset 2px 2px #000, inset -2px -2px #dfdfdf;
}

/* Both, to beat .screen button */
.screen button.challenge-map {
    padding: 1px;
    background: none;
    border: 1px solid transparent;
    border-radius: 0;
    box-shadow: none;
    cursor: pointer;
}

.screen button.challenge-map:hover,
.screen button.challenge-map:focus-visible {
    border-color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

.challenge-map img {
    display: block;
    /* The 18x28 sprite scaled by about 1.2 */
    width: 22px;
    height: 34px;
    image-rendering: pixelated;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.6);
}

.modal-card {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: min(760px, 100%);
    padding: 16px;
    box-sizing: border-box;
    /* The same old-Windows grey box as the end screen and the surrender offer */
    background: #c0c0c0;
    border: 1px solid #000;
    color: #000;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.3rem;
}

#cpu-delay-label,
#theme-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#cpu-delay {
    width: 100%;
    accent-color: #000080;
}

#map-preview-subtitle {
    font-size: 0.9rem;
    opacity: 0.8;
}

#map-preview-close,
#history-close {
    padding: 0 10px;
    font-size: 1.6rem;
    line-height: 1.4;
    cursor: pointer;
}

.modal-footer {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.modal-footer button {
    padding: 8px 14px;
    font-size: 16px;
    cursor: pointer;
}

.modal-footer button:disabled {
    cursor: default;
}

#map-preview-canvas {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    max-height: 70vh;
    background: #12355a;
    border: 1px solid #808080;
}

.play-button {
    font-weight: 700;
}

#history-button,
#multiplayer-history-button,
#lobby-join,
#lobby-leave,
#lobby-start {
    margin-left: auto;
}

/* As wide as its rows need, not the island preview's width */
#history-card {
    width: auto;
    max-width: 100%;
}

#history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 70vh;
    overflow-y: auto;
    margin: 0;
    padding: 0;
    list-style: none;
}

.history-row {
    display: grid;
    grid-template-columns: 72px 28px 1fr auto;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 6px 12px;
    font-size: 15px;
    text-align: left;
    cursor: pointer;
}

.history-shape {
    width: 72px;
    height: 54px;
}

.history-result {
    height: 28px;
    image-rendering: pixelated;
}

.history-when {
    opacity: 0.7;
    font-size: 13px;
}

#ongoing-games {
    margin: 1.5rem auto 0;
    width: fit-content;
    max-width: 100%;
}

#ongoing-games h2 {
    margin: 0 0 0.5rem;
    font-size: 1.2rem;
}

#ongoing-games-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin: 0;
    list-style: none;
}

.ongoing-game {
    width: 100%;
    padding: 8px 14px;
    font-size: 15px;
    text-align: left;
    cursor: pointer;
}

#lobby-body {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 16px;
}

#lobby-map {
    flex: 0 1 560px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#lobby-map-picker,
#lobby-map-buttons {
    display: flex;
    justify-content: space-between;
    gap: 6px;
}

#lobby-map-picker select {
    flex: 1;
    min-width: 0;
    font-size: 15px;
}

#lobby-map-title {
    text-align: center;
}

#lobby-map-canvas {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #12355a;
    box-sizing: border-box;
    border: 2px solid;
    border-color: #808080 #fff #fff #808080;
}

#in-progress-section h2 {
    width: min(480px, 100%);
    margin: 1.5rem auto 0.5rem;
    font-size: 1.2rem;
}

#lobby-list,
#in-progress-list,
#lobby-seats {
    display: flex;
    flex-direction: column;
    gap: 0;
    box-sizing: border-box;
    width: min(480px, 100%);
    margin: 0 auto;
    list-style: none;
}

/* Beside the map, which wraps under it when there's no room */
#lobby-seats {
    flex: 0 1 320px;
    margin: 0;
}

#lobby-list-status,
#lobby-status {
    text-align: center;
}

.lobby-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px 14px;
    font-size: 15px;
    text-align: left;
    cursor: pointer;
}

.lobby-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.host-tag {
    font-size: 13px;
    font-weight: 600;
}

/* A row of the seats' list box */
.lobby-seat {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 14px;
    font-size: 15px;
    color: #000;
}

.lobby-seat + .lobby-seat {
    border-top: 1px solid #dfdfdf;
}

.lobby-seat.empty {
    color: #606060;
}

#lobby-name-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#lobby-name {
    font-size: 16px;
    padding: 4px 6px;
}

#create-lobby-error,
#cancel-lobby-error {
    color: #800000;
}

#lobby-canceled .modal-footer,
#panel-dialog .modal-footer,
#game-notice .modal-footer {
    justify-content: center;
}
