:root {
    --bg-fallback: #1f2f44;
    --glass-bg: rgba(255, 255, 255, 0.14);
    --glass-bg-strong: rgba(255, 255, 255, 0.22);
    --glass-border: rgba(255, 255, 255, 0.36);
    --glass-border-soft: rgba(255, 255, 255, 0.2);
    --glass-shadow: 0 18px 45px rgba(20, 29, 44, 0.42);
    --text-primary: #f4f8ff;
    --text-secondary: rgba(240, 246, 255, 0.78);
    --text-muted: rgba(231, 240, 255, 0.75);
    --btn-bg: rgba(255, 255, 255, 0.16);
    --btn-hover: rgba(255, 255, 255, 0.28);
    --accent: #77b7ff;
    --accent-soft: rgba(119, 183, 255, 0.26);
    --danger: #ff747d;
    --board-light: rgba(228, 236, 247, 0.84);
    --board-dark: rgba(53, 76, 113, 0.83);
    --glass-glint-color: rgba(255, 245, 200, 0.4);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    overflow: hidden;
    font-family: 'Outfit', sans-serif;
    color: var(--text-primary);
    background: var(--bg-fallback);
}

.app-background {
    position: fixed;
    inset: -4%;
    z-index: -1;
    background-image:
        radial-gradient(circle at 15% 20%, rgba(195, 223, 255, 0.35), transparent 32%),
        radial-gradient(circle at 85% 80%, rgba(196, 221, 255, 0.28), transparent 35%),
        linear-gradient(145deg, rgba(40, 58, 83, 0.7), rgba(31, 45, 64, 0.8)),
        url('https://images.unsplash.com/photo-1516383607781-913a19294fd1?q=80&w=2560&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
    filter: blur(10px) saturate(1.12) brightness(0.88);
}

.main-layout {
    width: 100%;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 18px;
}

.glass-element {
    background: var(--glass-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: 22px;
}

.glass-panel {
    width: min(1420px, 100%);
    height: min(95vh, 930px);
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
    border-radius: 30px;
    background: rgba(255, 255, 255, 0.13);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 24px 60px rgba(18, 30, 50, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.control-strip {
    display: grid;
    grid-template-columns: auto repeat(6, minmax(0, auto)) 1fr;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
}

.app-title {
    font-size: clamp(1rem, 1.5vw, 1.4rem);
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--text-primary);
    padding-right: 6px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.control-group label {
    font-size: 0.73rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
}

select,
input {
    border: 1px solid var(--glass-border-soft);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.16);
    color: var(--text-primary);
    font-size: 0.88rem;
    font-family: 'Outfit', sans-serif;
    padding: 8px 10px;
    min-width: 136px;
    outline: none;
}

select:focus,
input:focus {
    border-color: rgba(145, 201, 255, 0.85);
    box-shadow: 0 0 0 3px rgba(119, 183, 255, 0.22);
}

.status-line {
    justify-self: end;
    text-align: right;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    max-width: 100%;
    font-weight: 400;
    font-size: 0.9rem;
}

.typewriter {
    animation: softFade 0.35s ease;
}

.top-content {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 220px minmax(340px, 1fr) 345px;
    gap: 14px;
}

.column {
    min-height: 0;
}

.left-column {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
}

.player-card {
    padding: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 7px;
}

.player-label {
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.avatar {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.38);
    object-fit: cover;
}

.player-name {
    font-size: 1.28rem;
    font-weight: 500;
    line-height: 1.1;
}

.player-rating {
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.clock {
    width: 100%;
    border-radius: 12px;
    border: 1px solid rgba(214, 232, 255, 0.32);
    padding: 8px 10px;
    color: rgba(245, 249, 255, 0.95);
    background: rgba(29, 44, 70, 0.45);
    font-size: 1.35rem;
    font-weight: 500;
}

.clock.active {
    color: #ffffff;
    border-color: rgba(152, 208, 255, 0.75);
    background: linear-gradient(120deg, rgba(65, 135, 220, 0.7), rgba(42, 108, 197, 0.62));
    box-shadow: inset 0 0 22px rgba(121, 187, 255, 0.25);
}

.center-column {
    display: flex;
    justify-content: center;
    align-items: center;
}

.board-wrapper {
    width: 100%;
    height: 100%;
    max-height: 730px;
    padding: 12px;
    position: relative;
    border-radius: 24px;
}

.chess-board {
    width: 100%;
    height: 100%;
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.28);
    box-shadow: inset 0 0 24px rgba(26, 38, 56, 0.32);
}

.square {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
}

.square.light {
    background: var(--board-light);
}

.square.dark {
    background: var(--board-dark);
}

.square.selected {
    box-shadow: inset 0 0 0 2px rgba(255, 230, 122, 0.95);
}

.square.highlight::after {
    content: '';
    position: absolute;
    width: 25%;
    height: 25%;
    border-radius: 50%;
    background: rgba(95, 183, 255, 0.42);
}

.square.drop-target::after {
    width: 38%;
    height: 38%;
    background: rgba(255, 230, 122, 0.42);
    box-shadow: 0 0 16px rgba(255, 230, 122, 0.38);
}

.chess-piece {
    position: relative;
    width: 88%;
    height: 88%;
    overflow: hidden;
    transition: transform 0.2s ease;
    animation: pieceEnter 0.15s ease-out;
}

.piece {
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
    pointer-events: none;
    filter: drop-shadow(0 4px 9px rgba(0, 0, 0, 0.35));
}

.piece-ghost {
    position: fixed;
    width: 74px;
    height: 74px;
    pointer-events: none;
    z-index: 20;
    transform: translate(-50%, -50%);
    filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.35));
}

.piece-ghost img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.chess-piece::after {
    content: '';
    position: absolute;
    top: -150%;
    left: -150%;
    width: 300%;
    height: 300%;
    background: linear-gradient(
        45deg,
        transparent 45%,
        var(--glass-glint-color) 50%,
        transparent 55%
    );
    mix-blend-mode: screen;
    pointer-events: none;
    transform: translate(-30%, -30%);
    opacity: 0;
}

@keyframes glass-glint {
    0% {
        transform: translate(-30%, -30%);
        opacity: 0;
    }
    20% {
        opacity: 1;
    }
    80% {
        opacity: 1;
    }
    100% {
        transform: translate(30%, 30%);
        opacity: 0;
    }
}

.chess-piece:hover::after,
.chess-piece.is-dragging::after {
    animation: glass-glint 1.5s infinite;
    filter: blur(1px);
    opacity: 1;
}

.right-column {
    display: grid;
    grid-template-rows: minmax(150px, auto) auto minmax(120px, auto) auto;
    align-content: start;
    gap: 10px;
    min-height: 0;
    overflow-y: auto;
    max-height: 100%;
}

.right-column::-webkit-scrollbar {
    width: 5px;
}

.right-column::-webkit-scrollbar-thumb {
    background: rgba(182, 208, 241, 0.3);
    border-radius: 12px;
}

.history-panel,
.profile-panel,
.achievements-panel,
.donation-panel {
    padding: 9px 11px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.panel-title {
    font-size: 0.78rem;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.move-list {
    list-style: none;
    overflow-y: auto;
    flex: 0 0 auto;
    max-height: 96px;
    font-size: 0.88rem;
    padding-right: 4px;
}

.move-list::-webkit-scrollbar {
    width: 6px;
}

.move-list::-webkit-scrollbar-thumb {
    background: rgba(182, 208, 241, 0.35);
    border-radius: 12px;
}

.replay-panel {
    display: grid;
    gap: 6px;
}

.replay-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.68rem;
    color: var(--text-secondary);
}

.replay-slider {
    width: 100%;
    min-width: 0;
    appearance: none;
    height: 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.24);
    padding: 0;
}

.replay-slider::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.45);
    background: rgba(156, 208, 255, 0.95);
    box-shadow: 0 0 10px rgba(119, 183, 255, 0.4);
    cursor: pointer;
}

.replay-buttons {
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.move-row {
    display: grid;
    grid-template-columns: 34px 1fr 1fr;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    padding: 5px 0;
    gap: 6px;
}

.move-num {
    color: var(--text-muted);
}

.move-w,
.move-b {
    color: var(--text-primary);
}

.captured-pieces {
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    padding-top: 6px;
    display: grid;
    gap: 5px;
}

.tiny-label {
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.captured-row {
    min-height: 22px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.captured-row img {
    width: 18px;
    height: 18px;
}

.rank-name {
    color: #ffffff;
    font-weight: 500;
}

.xp-line {
    color: var(--text-secondary);
    font-size: 0.83rem;
}

.xp-bar {
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.24);
    overflow: hidden;
}

.xp-bar span {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, rgba(127, 194, 255, 0.35), rgba(125, 198, 255, 0.95));
    box-shadow: 0 0 14px rgba(125, 198, 255, 0.35);
    transition: width 0.35s ease;
}

.stats-grid {
    margin-top: auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    font-size: 0.74rem;
}

.achievement-list {
    list-style: none;
    overflow-y: auto;
    font-size: 0.83rem;
    display: grid;
    gap: 5px;
    padding-right: 2px;
    max-height: 150px;
}

.achievement-list li {
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 10px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.09);
}

.achievement-list li.unlocked {
    border-color: rgba(120, 198, 255, 0.62);
    box-shadow: inset 0 0 10px rgba(120, 198, 255, 0.15);
}

.achievement-list strong {
    display: block;
    font-size: 0.8rem;
    line-height: 1.15;
}

.achievement-list small {
    display: block;
    margin-top: 1px;
    color: var(--text-secondary);
    font-size: 0.66rem;
    line-height: 1.2;
}

.achievement-list .achievement-state {
    margin-top: 3px;
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(234, 241, 255, 0.72);
}

/* ── Donate button (primary CTA) ── */
.donate-btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    text-align: center;
    padding: 9px 14px;
    font-size: 0.82rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    letter-spacing: 0.04em;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, rgba(80, 140, 220, 0.55), rgba(120, 80, 210, 0.50));
    border: 1px solid rgba(119, 183, 255, 0.45);
    box-shadow: 0 0 18px rgba(119, 183, 255, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.12);
    transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
    cursor: pointer;
}

.donate-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 28px rgba(119, 183, 255, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.18);
    background: linear-gradient(135deg, rgba(80, 140, 220, 0.68), rgba(120, 80, 210, 0.62));
}

.donate-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* ── Crypto collapsible ── */
.crypto-details {
    margin-top: 2px;
}

.crypto-toggle {
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    padding: 6px 0;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.15s ease;
}

.crypto-toggle::-webkit-details-marker {
    display: none;
}

.crypto-toggle::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-right: 1.5px solid var(--text-secondary);
    border-bottom: 1.5px solid var(--text-secondary);
    transform: rotate(-45deg);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.crypto-details[open] > .crypto-toggle::before {
    transform: rotate(45deg);
}

.crypto-details[open] > .crypto-toggle {
    color: var(--text-primary);
}

/* ── Crypto tabs ── */
.crypto-tabs {
    display: flex;
    gap: 4px;
    margin: 6px 0;
}

.crypto-tab {
    flex: 1;
    padding: 5px 0;
    font-size: 0.68rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.crypto-tab:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-secondary);
}

.crypto-tab.active {
    background: rgba(119, 183, 255, 0.18);
    border-color: rgba(119, 183, 255, 0.4);
    color: var(--accent);
    box-shadow: 0 0 10px rgba(119, 183, 255, 0.1);
}

/* ── Crypto panes ── */
.crypto-pane {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 6px 0 2px;
}

.crypto-pane.active {
    display: flex;
}

.crypto-qr {
    width: 88px;
    height: 88px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.92);
    object-fit: cover;
    cursor: zoom-in;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.crypto-qr:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(11, 20, 34, 0.36);
}

.crypto-addr-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.crypto-addr-row code {
    width: 100%;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.66rem;
    color: #f0f4ff;
    background: rgba(20, 30, 50, 0.55);
    padding: 5px 8px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.crypto-addr-row .glass-btn.mini {
    width: 100%;
    padding: 6px 10px;
    font-size: 0.63rem;
    min-width: 0;
}

.qr-modal {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 36, 0.64);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.qr-modal-card {
    position: relative;
    z-index: 1;
    width: min(360px, 90vw);
    padding: 14px;
    display: grid;
    gap: 10px;
    justify-items: center;
}

.qr-modal-image {
    width: min(290px, 74vw);
    height: auto;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.94);
}

.qr-modal-address {
    display: block;
    width: 100%;
    max-width: 100%;
    text-align: center;
    font-size: 0.72rem;
    line-height: 1.4;
    color: var(--text-primary);
    word-break: break-all;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 8px 10px;
}

.bottom-actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
}

.glass-btn {
    background: var(--btn-bg);
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 999px;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
    letter-spacing: 0.05em;
    padding: 10px 18px;
    cursor: pointer;
    transition: transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.glass-btn:hover {
    transform: translateY(-1px);
    background: var(--btn-hover);
    box-shadow: 0 8px 16px rgba(24, 38, 58, 0.22);
}

.glass-btn.mini {
    padding: 7px 11px;
    border-radius: 12px;
    font-size: 0.74rem;
}

.btn-danger {
    border-color: rgba(255, 145, 154, 0.72);
    color: #ffe8ec;
}

.result-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    background: rgba(34, 47, 66, 0.5);
}

.overlay-core {
    width: min(540px, 92%);
    padding: 22px;
    text-align: center;
    border-width: 2px;
}

.overlay-core.win {
    border-color: rgba(140, 220, 255, 0.7);
    box-shadow: 0 0 44px rgba(120, 198, 255, 0.3);
}

.overlay-core.loss {
    border-color: rgba(255, 130, 132, 0.78);
    box-shadow: 0 0 44px rgba(255, 110, 122, 0.24);
    animation: shake 0.35s linear 2;
}

.overlay-core.draw {
    border-color: rgba(197, 225, 255, 0.64);
}

.result-title {
    font-size: clamp(1.3rem, 3vw, 2rem);
    letter-spacing: 0.07em;
    color: #ffffff;
}

.result-subtitle {
    margin: 10px 0 18px;
    color: var(--text-secondary);
}

.fx-particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.fx-particle {
    position: absolute;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(157, 220, 255, 0.95);
    animation: rise 1.5s ease-out forwards;
}

.fx-particle.loss {
    background: rgba(255, 108, 120, 0.95);
}

.hidden {
    display: none !important;
}

@keyframes softFade {
    from {
        opacity: 0.4;
    }
    to {
        opacity: 1;
    }
}

@keyframes rise {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(-180px) scale(0.35);
        opacity: 0;
    }
}

@keyframes shake {
    0% {
        transform: translate(0);
    }
    25% {
        transform: translate(-2px, 2px);
    }
    50% {
        transform: translate(2px, -2px);
    }
    75% {
        transform: translate(-1px, 1px);
    }
    100% {
        transform: translate(0);
    }
}

@media (max-width: 1250px) {
    body {
        overflow-y: auto;
    }

    .glass-panel {
        height: auto;
    }

    .control-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .app-title {
        grid-column: 1 / -1;
    }

    .status-line {
        grid-column: 1 / -1;
        justify-self: start;
        text-align: left;
    }

    .top-content {
        grid-template-columns: 1fr;
    }

    .left-column {
        flex-direction: row;
    }

    .right-column {
        grid-template-rows: repeat(4, auto);
    }

    .replay-buttons {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .board-wrapper {
        max-height: min(82vw, 620px);
    }
}

@media (max-width: 720px) {
    .left-column {
        flex-direction: column;
    }

    .control-strip {
        grid-template-columns: 1fr;
    }

    .crypto-qr {
        width: 90px;
        height: 90px;
    }

    .crypto-addr-row code {
        white-space: normal;
        word-break: break-all;
    }

    .donate-btn-primary {
        font-size: 0.8rem;
    }

    .move-list {
        max-height: 120px;
    }

    .achievement-list {
        max-height: 180px;
    }

    .crypto-addr-row .glass-btn.mini {
        width: auto;
        min-width: 80px;
    }
}

/* ── Native <dialog> reset ───────────────────────────────── */
dialog {
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;
    max-width: none;
    max-height: none;
}

/* Shared backdrop for both modals */
dialog.promotion-modal::backdrop {
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ── Promotion modal ─────────────────────────────────────── */
dialog.promotion-modal {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: none;
    align-items: center;
    justify-content: center;
}

dialog.promotion-modal[open] {
    display: flex;
}

.promotion-card {
    position: relative;
    z-index: 1;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    min-width: 260px;
}

.promotion-choices {
    display: flex;
    gap: 0.75rem;
}

.promotion-piece-btn {
    background: none;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 6px;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
}

.promotion-piece-btn:hover,
.promotion-piece-btn:focus-visible {
    border-color: var(--accent, #7dd3fc);
    transform: scale(1.1);
    outline: none;
}

.promotion-piece-btn img {
    width: 56px;
    height: 56px;
    display: block;
}

/* ── Focus-visible rings ─────────────────────────────────── */
:focus-visible {
    outline: 2px solid var(--accent, #7dd3fc);
    outline-offset: 2px;
    border-radius: 4px;
}

.square:focus-visible {
    outline: 3px solid var(--accent, #7dd3fc);
    outline-offset: -3px;
    z-index: 1;
}

/* ── Move animations ─────────────────────────────────────── */
@keyframes pieceEnter {
    from { opacity: 0; transform: scale(0.72); }
    to   { opacity: 1; transform: scale(1); }
}

.chess-piece.is-dragging {
    animation: none;
    opacity: 0;
}

@keyframes squareFlash {
    0%   { background-color: rgba(255, 220, 100, 0.55); }
    100% { background-color: transparent; }
}

.square.last-move {
    animation: squareFlash 0.5s ease-out forwards;
}

/* ── Clock low-time warning ──────────────────────────────── */
.clock.clock-low {
    border-color: rgba(255, 100, 100, 0.8) !important;
    color: #ff9090 !important;
    animation: clockPulse 1s ease-in-out infinite;
}

@keyframes clockPulse {
    0%, 100% { box-shadow: none; }
    50% { box-shadow: inset 0 0 18px rgba(255, 80, 80, 0.3); }
}

/* ── Board flip (playing as black) ──────────────────────── */
.chess-board.board-flipped {
    transform: rotate(180deg);
}

/* Counter-rotate each square so pieces and labels stay upright */
.chess-board.board-flipped .square {
    transform: rotate(180deg);
}

/* ── Mobile touch targets (min 48px) ────────────────────── */
@media (pointer: coarse) {
    .glass-btn {
        min-height: 48px;
    }

    .glass-btn.mini {
        min-height: 44px;
    }

    .square {
        min-height: 0; /* grid handles sizing */
        touch-action: none;
    }

    select,
    input {
        min-height: 44px;
    }

    .crypto-tab {
        min-height: 44px;
    }

    .replay-slider::-webkit-slider-thumb {
        width: 22px;
        height: 22px;
    }
}

/* ── Landscape phone layout ──────────────────────────────── */
@media (max-width: 720px) and (orientation: landscape) {
    body {
        overflow-y: auto;
    }

    .glass-panel {
        height: auto;
    }

    .top-content {
        grid-template-columns: 1fr 2fr;
    }

    .left-column {
        flex-direction: column;
        overflow-y: auto;
        max-height: 80vh;
    }

    .right-column {
        display: none; /* hide sidebar in landscape phone to maximise board */
    }

    .board-wrapper {
        max-height: 80vw;
    }
}
