:root {
    color-scheme: light;
    --ink: #241910;
    --paper: #f4ecdf;
    --table: #2a211b;
    --light: #f0d9b5;
    --dark: #b58863;
    --line: #d9cbb6;
}

html, body {
    margin: 0;
    background: var(--table);
    color: var(--paper);
    font-family: "Segoe UI", sans-serif;
}

h1, h2, p {
    margin: 0;
}

h1:focus {
    outline: none;
}

button, input, select {
    font: inherit;
}

button {
    min-height: 2.75rem;
    border: 1px solid #8c7156;
    background: #fffaf2;
    color: var(--ink);
    border-radius: 6px;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

button:focus-visible, input:focus-visible, select:focus-visible {
    outline: 3px solid #1d4e89;
    outline-offset: 2px;
}

button.primary {
    background: #1f4b32;
    color: #f7f3ea;
    border-color: #163726;
}

.app-shell {
    max-width: 1120px;
    margin: 0 auto;
    padding: 1.25rem 1rem 2rem;
}

.mast {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.mast .logo {
    width: 5.5rem;
    height: 5.5rem;
    flex: none;
    border-radius: 10px;
    object-fit: cover;
}

.mast p, .hint, .empty-log {
    color: #e6d8c6;
    margin-top: 0.35rem;
}

.panel {
    background: var(--paper);
    color: var(--ink);
    border-radius: 12px;
    padding: 1rem;
}

.setup h2, .side h2 {
    margin-bottom: 0.35rem;
}

.stat-table {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: 1rem 0;
}

.stat-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    align-items: end;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--line);
}

.piece-name {
    min-width: 7rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.85rem;
}

input, select {
    min-height: 2.5rem;
    border: 1px solid #b7a48c;
    border-radius: 6px;
    padding: 0.3rem 0.45rem;
    background: white;
    color: var(--ink);
}

.errors {
    margin: 0.75rem 0 0;
    padding-left: 1.2rem;
    color: #8d1d1d;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.play {
    display: grid;
    grid-template-columns: minmax(280px, 640px) minmax(240px, 380px);
    gap: 1rem;
    align-items: start;
}

.banner {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    border-radius: 10px;
    padding: 0.7rem 0.85rem;
    margin-bottom: 0.6rem;
}

.banner span {
    font-size: 0.92rem;
}

.banner.turn {
    background: #3a2e25;
}

.banner.win {
    background: #1f6b3a;
}

.banner.draw {
    background: #8a5a12;
}

.board {
    display: grid;
    grid-template-columns: 1.4rem repeat(8, minmax(0, 1fr));
    width: 100%;
    border: 4px solid #6b4b32;
    border-radius: 0;
    overflow: hidden;
    background: #6b4b32;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.coord, .files span {
    display: grid;
    place-items: center;
    color: #e6d3bc;
    font-size: 0.75rem;
}

.files {
    display: grid;
    grid-template-columns: 1.4rem repeat(8, minmax(0, 1fr));
    width: 100%;
}

.square {
    box-sizing: border-box;
    appearance: none;
    border: 0;
    border-radius: 0;
    margin: 0;
    padding: 0;
    min-height: 0;
    width: 100%;
    aspect-ratio: 1;
    display: block;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    container-type: inline-size;
}

.square:focus-visible {
    outline: 3px solid #1d4e89;
    outline-offset: -3px;
}

.square.light { background: var(--light); }
.square.dark { background: var(--dark); }
.square.light.last { background: #f6f669; }
.square.dark.last { background: #baca2b; }
.square.selected { box-shadow: inset 0 0 0 4px #1d4e89; }
.square.light.selected { background: #b9cde6; }
.square.dark.selected { background: #7d9cc2; }

.square.dest::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 58%;
    width: 26%;
    height: 26%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: rgba(20, 60, 30, 0.35);
}

.square.capture { box-shadow: inset 0 0 0 4px rgba(170, 28, 28, 0.85); }

.square .piece {
    position: absolute;
    left: 50%;
    bottom: 2%;
    width: 72%;
    height: 72%;
    transform: translateX(-50%);
    filter: drop-shadow(0 2px 1.5px rgba(0, 0, 0, 0.35));
    pointer-events: none;
    user-select: none;
}

.stats {
    position: absolute;
    top: 3%;
    left: 5%;
    right: 5%;
    display: flex;
    align-items: center;
    gap: 3%;
    z-index: 1;
    font-size: clamp(7px, 15cqw, 11px);
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
}

.hp-bar {
    position: relative;
    flex: 1;
    height: 1.25em;
    border-radius: 2px;
    background: rgba(28, 20, 15, 0.7);
    overflow: hidden;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.hp-fill {
    position: absolute;
    inset: 0 auto 0 0;
    transition: width 0.45s ease, background-color 0.45s ease;
}

.hp-fill.high { background: #3fa34d; }
.hp-fill.mid { background: #e0a526; }
.hp-fill.low { background: #d1382f; }

.hp-text {
    position: relative;
    display: block;
    text-align: center;
    color: #fff;
    line-height: 1.25em;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.8);
}

.ap {
    padding: 0 0.2em;
    height: 1.25em;
    line-height: 1.25em;
    border-radius: 2px;
    background: rgba(28, 20, 15, 0.78);
    color: #ffd27a;
    white-space: nowrap;
}

.square .grave {
    position: absolute;
    left: 50%;
    bottom: 6%;
    width: 70%;
    height: 70%;
    transform: translateX(-50%);
    pointer-events: none;
    animation: grave-rise 2.4s ease-out forwards;
}

@keyframes grave-rise {
    0% { opacity: 0; transform: translateX(-50%) translateY(35%) scale(0.5); }
    18% { opacity: 1; transform: translateX(-50%) translateY(-6%) scale(1.06); }
    28% { transform: translateX(-50%) translateY(0) scale(1); }
    75% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
    100% { opacity: 0; transform: translateX(-50%) translateY(0) scale(0.92); }
}

@media (prefers-reduced-motion: reduce) {
    .square .grave {
        animation: grave-fade 2.4s linear forwards;
    }

    .hp-fill {
        transition: none;
    }
}

@keyframes grave-fade {
    0%, 75% { opacity: 1; transform: translateX(-50%); }
    100% { opacity: 0; transform: translateX(-50%); }
}

.piece-icon {
    width: 1.6rem;
    height: 1.6rem;
    vertical-align: middle;
}

.promote {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    text-transform: capitalize;
}

.hint {
    font-size: 0.85rem;
}

.matchup {
    margin-bottom: 0.7rem;
}

.side .log {
    margin: 0.5rem 0 0;
    padding-left: 1.2rem;
    max-height: 24rem;
    overflow: auto;
    font-family: Georgia, "Palatino Linotype", serif;
    line-height: 1.45;
}

.side .log li + li {
    margin-top: 0.45rem;
}

.dialog {
    margin: 0.8rem 0;
    padding: 0.75rem;
    border: 1px solid #c4ad8e;
    border-radius: 8px;
    background: #fffaf2;
    color: var(--ink);
}

.dialog p {
    margin-bottom: 0.5rem;
}

.empty-log {
    color: #5e5146;
}

@media (max-width: 860px) {
    .play {
        grid-template-columns: 1fr;
    }
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: black;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: #e0e0e0;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: #1b6ec2;
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}
