:root {
    color-scheme: light;
    --ink: #253c33;
    --muted: #7a8075;
    --green: #214d3f;
    --line: #deded2;
    --paper: #f7f6ee
}

* {
    box-sizing: border-box
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px
}

button, select {
    font: inherit
}

button, select, a {
    -webkit-tap-highlight-color: transparent
}

button {
    cursor: pointer
}

button:disabled {
    cursor: default;
    opacity: .4
}

button:focus-visible, select:focus-visible, a:focus-visible {
    outline: 3px solid #b17b31;
    outline-offset: 3px
}

.offline {
    font-size: 12px;
    color: #637064;
    display: flex;
    gap: 8px;
    align-items: center
}

main {
    width: min(100%, calc(100dvh + 156px));
    max-width: 1440px;
    padding: 12px;
    margin: auto
}

p {
    line-height: 1.6
}

.game-layout {
    display: grid;
    grid-template-columns:minmax(0, 1fr) 280px;
    gap: 16px;
    align-items: start
}

.play-area {
    min-width: 0
}

.player-line {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 2px 8px
}

.player-line strong {
    font-size: 13px
}

.player-line small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px
}

.avatar {
    background: #e8e7dd;
    border: 1px solid #dcdccf;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    font-size: 24px;
    border-radius: 50%;
    color: #35443d
}

.avatar.light {
    background: #fffcf0;
    color: #956f3a
}

.turn-badge {
    margin-left: auto;
    color: #8b8e80;
    font-size: 10px;
    padding: 6px 10px;
    border-radius: 4px
}

.turn-badge.active {
    background: #e4e9dc;
    color: #48613e
}

.board-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: url('chess-board.png') center/100% 100%;
    box-shadow: 0 15px 35px #42342220, 0 2px 4px #31201730;
    border-radius: 3px;
    margin-bottom: 8px
}

.board {
    position: absolute;
    inset: 4.65% 4.8% 4.75%;
    display: grid;
    grid-template-columns:repeat(8, 1fr);
    grid-template-rows:repeat(8, 1fr)
}

.square {
    position: relative;
    min-width: 0;
    min-height: 0;
    border: 0;
    padding: 0;
    background: transparent;
    display: grid;
    place-items: center;
    touch-action: manipulation;
    border-radius: 0
}

.square:hover {
    background: #fff6c42b
}

.square.last {
    background: #cbdc6b55
}

.square.selected {
    background: #c3df86a6;
    box-shadow: inset 0 0 0 3px #e9edaf
}

.square.check {
    background: #cf493ba1
}

.square.target:after {
    content: '';
    position: absolute;
    width: 24%;
    height: 24%;
    background: #244f3f66;
    border-radius: 50%;
    pointer-events: none
}

.square.capture:after {
    width: 85%;
    height: 85%;
    background: transparent;
    border: 4px solid #254e3e77
}

.piece {
    height: 89%;
    width: 89%;
    display: block;
    position: relative;
    pointer-events: none;
    filter: drop-shadow(0 3px 2px #0005)
}

.square:focus-visible {
    z-index: 2;
    outline-offset: -3px
}

.ranks {
    position: absolute;
    left: .5%;
    top: 4.65%;
    bottom: 4.75%;
    width: 3.8%;
    display: grid;
    grid-template-rows:repeat(8, 1fr)
}

.files {
    position: absolute;
    bottom: .2%;
    left: 4.8%;
    right: 4.8%;
    height: 4%;
    display: grid;
    grid-template-columns:repeat(8, 1fr)
}

.ranks span, .files span {
    display: grid;
    place-items: center;
    color: #e5c393;
    font-size: 10px;
    text-shadow: 0 1px 2px #241205
}

.board-hint {
    text-align: center;
    font-size: 11px;
    color: var(--muted);
    margin: 0
}

aside {
    display: grid;
    gap: 10px
}

.status-card {
    background: var(--green);
    color: #f6f4de;
    border-radius: 5px;
    padding: 14px
}

.status-card .status-card h2 {
    font-size: 19px;
    font-weight: 500;
    margin: 0 0 10px
}

.status-card p {
    font-size: 12px;
    color: #c4d0c0;
    margin: 0 0 10px
}

.status-.panel {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #faf9f3
}

h3 {
    font-size: 14px;
    margin: 0 0 12px
}

label {
    display: block;
    font-size: 12px;
    margin: 12px 0 6px;
    font-weight: 600
}

label span {
    font-size: 9px;
    font-weight: 400;
    color: var(--muted);
    float: right
}

select {
    width: 100%;
    height: 41px;
    padding: 0 9px;
    color: #455347;
    background: #f5f4eb;
    border: 1px solid #ddded1;
    border-radius: 4px;
    font-size: 11px
}

button {
    border: 1px solid #dcded2;
    background: #faf9f3;
    color: #465747;
    border-radius: 4px;
    padding: 11px 9px;
    font-size: 11px;
    transition: background .15s
}

button:hover:not(:disabled) {
    background: #eeeee2
}

.primary {
    background: var(--green);
    color: #fff;
    border-color: var(--green)
}

.primary:hover:not(:disabled) {
    background: #30634e
}

#new-game {
    width: 100%;
    margin-top: 12px;
    text-align: left;
    font-size: 12px;
    padding: 11px
}

#new-game span {
    float: right
}

.button-row {
    display: flex;
    gap: 8px;
    margin-top: 10px
}

.button-row button {
    flex: 1
}

.history-heading {
    display: flex;
    justify-content: space-between;
    align-items: baseline
}

.history-heading h3 {
    margin-bottom: 12px
}

.history-heading > span {
    font-size: 10px;
    color: var(--muted)
}

.history-columns, .history-row {
    display: grid;
    grid-template-columns:30px 1fr 1fr;
    gap: 5px
}

.history-columns {
    color: var(--muted);
    font-size: 10px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px
}

.history {
    max-height: clamp(100px, calc(100dvh - 490px), 450px);
    overflow-y: auto;
    min-height: 40px
}

.history-row {
    padding: 9px 0;
    font-size: 12px;
    border-bottom: 1px solid #ebebdf;
    font-variant-numeric: tabular-nums
}

.history-row span:first-child {
    color: var(--muted)
}

.history-row:last-child {
    color: #1c6546
}

.empty-history {
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    margin: 12px 0 0
}

dialog {
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 25px;
    background: var(--paper);
    color: var(--ink);
    max-width: 90vw
}

dialog::backdrop {
    background: #13291f88
}

dialog h2 {
    font: 25px Georgia, serif
}

#promotion-options {
    display: flex;
    gap: 8px
}

#promotion-options button {
    width: 70px;
    height: 95px
}

#promotion-options .piece {
    height: 65px;
    width: 50px;
    margin: auto
}

#promotion-options small {
    font-size: 10px
}

@media (max-width: 700px) {
    main {
        width: 100%;
        padding: 8px
    }

    .game-layout {
        grid-template-columns:1fr;
        gap: 12px
    }

    .header {
        padding: 9px 12px
    }

    .offline {
        font-size: 11px
    }

    aside {
        grid-template-columns:repeat(2, minmax(0, 1fr));
        align-items: start
    }

    .status-card {
        grid-column: 1 / -1
    }

    .status-card h2 {
        font-size: 18px
    }

    .history {
        max-height: 220px
    }

    .panel {
        padding: 12px
    }

    label span {
        float: none;
        display: block;
        margin-top: 3px
    }
}

@media (max-width: 440px) {
    aside {
        grid-template-columns:1fr
    }

    .history {
        max-height: 160px
    }
}