:root {
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --bg: #070914;
    --panel: rgba(17, 20, 37, .86);
    --panel-strong: rgba(22, 25, 46, .96);
    --line: rgba(255, 255, 255, .10);
    --line-strong: rgba(255, 255, 255, .17);
    --text: #f6f7ff;
    --muted: #929ab3;
    --accent: #8b7cff;
    --accent-2: #36dcba;
    --danger: #ff6f91;
    --shadow: 0 30px 80px rgba(0, 0, 0, .42);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background:
        radial-gradient(circle at 14% 0%, rgba(112, 89, 255, .24), transparent 34%),
        radial-gradient(circle at 92% 16%, rgba(54, 220, 186, .13), transparent 28%),
        linear-gradient(155deg, #090b18 0%, #070914 44%, #050711 100%);
    color: var(--text);
}

body {
    min-width: 0;
    min-height: 0;
}

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

button {
    font: inherit;
}

.game-shell {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: clamp(10px, 1.8vmin, 18px);
}

.game-panel {
    position: relative;
    width: min(100%, 1120px);
    height: min(100%, 760px);
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: clamp(9px, 1.4vmin, 14px);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark {
    width: clamp(40px, 6vmin, 50px);
    height: clamp(40px, 6vmin, 50px);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border: 1px solid rgba(255, 255, 255, .13);
    border-radius: 15px;
    background:
        linear-gradient(145deg, rgba(139, 124, 255, .32), rgba(54, 220, 186, .12)),
        rgba(255, 255, 255, .04);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .10), 0 10px 30px rgba(75, 61, 194, .18);
    color: #c8c1ff;
    font-size: clamp(1.1rem, 2.7vmin, 1.55rem);
}

.eyebrow {
    display: block;
    color: #8f9ab7;
    font-size: clamp(.56rem, 1.25vmin, .7rem);
    font-weight: 900;
    letter-spacing: .16em;
}

.brand h1 {
    margin: 2px 0 0;
    font-size: clamp(1.35rem, 3.7vmin, 2.2rem);
    line-height: 1;
    letter-spacing: -.05em;
}

.sound-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 14px;
    border: 1px solid var(--line-strong);
    border-radius: 13px;
    background: rgba(255, 255, 255, .055);
    color: var(--text);
    cursor: pointer;
    font-size: clamp(.7rem, 1.45vmin, .82rem);
    font-weight: 800;
    transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.sound-toggle:hover,
.sound-toggle:focus-visible {
    transform: translateY(-1px);
    border-color: rgba(139, 124, 255, .58);
    background: rgba(139, 124, 255, .11);
    outline: none;
}

.sound-toggle[aria-pressed="true"] {
    border-color: rgba(255, 111, 145, .35);
    color: #ffd6df;
}

.sound-icon {
    font-size: .95rem;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: clamp(7px, 1.1vmin, 11px);
}

.stat-card {
    min-width: 0;
    padding: clamp(9px, 1.5vmin, 13px) clamp(10px, 1.7vmin, 15px);
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(15, 18, 34, .74);
    box-shadow: 0 12px 34px rgba(0, 0, 0, .20);
}

.stat-card--accent {
    background:
        linear-gradient(145deg, rgba(139, 124, 255, .14), rgba(54, 220, 186, .055)),
        rgba(15, 18, 34, .78);
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: clamp(.58rem, 1.25vmin, .7rem);
    font-weight: 800;
}

.stat-card strong {
    display: block;
    margin-top: 2px;
    font-size: clamp(1rem, 2.6vmin, 1.45rem);
    line-height: 1.05;
    letter-spacing: -.04em;
}

.play-layout {
    min-width: 0;
    min-height: 0;
    flex: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, .66fr);
    gap: clamp(10px, 1.5vmin, 16px);
}

.board-card,
.piece-card,
.info-card {
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.board-card {
    position: relative;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 22px;
    padding: clamp(8px, 1.6vmin, 14px);
}

.board-card::before {
    content: "";
    position: absolute;
    width: 52%;
    aspect-ratio: 1;
    left: -18%;
    top: -24%;
    border-radius: 50%;
    background: rgba(139, 124, 255, .09);
    filter: blur(38px);
    pointer-events: none;
}

#board {
    position: relative;
    z-index: 1;
    display: block;
    width: auto;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1;
    outline: none;
    touch-action: none;
    cursor: crosshair;
}

.side-panel {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.3vmin, 12px);
}

.piece-card,
.info-card {
    border-radius: 18px;
}

.piece-card {
    min-height: 0;
    flex: 1;
    padding: clamp(11px, 1.8vmin, 16px);
    display: flex;
    flex-direction: column;
}

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.section-heading strong {
    display: block;
    margin-top: 3px;
    font-size: clamp(.9rem, 2.1vmin, 1.15rem);
}

.moves-hint {
    flex: 0 0 auto;
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(54, 220, 186, .08);
    color: #7ee9d2;
    font-size: clamp(.54rem, 1.1vmin, .66rem);
    font-weight: 850;
}

.piece-tray {
    min-height: 0;
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    gap: clamp(6px, 1vmin, 9px);
    margin-top: clamp(8px, 1.4vmin, 12px);
}

.piece-slot {
    position: relative;
    min-width: 0;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: 3px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 15px;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, .025), rgba(255, 255, 255, .008)),
        rgba(7, 9, 20, .40);
    cursor: grab;
    transition: border-color .18s ease, transform .18s ease, background .18s ease, opacity .18s ease;
    touch-action: none;
}

.piece-slot:not(.is-empty):hover,
.piece-slot:not(.is-empty):focus-visible {
    transform: translateY(-1px);
    border-color: rgba(139, 124, 255, .44);
    background: rgba(139, 124, 255, .06);
    outline: none;
}

.piece-slot.is-selected {
    border-color: rgba(54, 220, 186, .58);
    background: rgba(54, 220, 186, .065);
    box-shadow: inset 0 0 0 1px rgba(54, 220, 186, .11), 0 0 0 3px rgba(54, 220, 186, .035);
}

.piece-slot.is-empty {
    opacity: .27;
    cursor: default;
}

.piece-slot canvas {
    display: block;
    width: 100%;
    height: 100%;
    max-height: 105px;
    pointer-events: none;
}

.info-card {
    padding: clamp(10px, 1.7vmin, 15px);
}

.info-card p {
    margin: 7px 0 0;
    color: #b8bfd2;
    font-size: clamp(.62rem, 1.35vmin, .76rem);
    line-height: 1.5;
}

.tip-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 9px;
    padding-top: 9px;
    border-top: 1px solid rgba(255, 255, 255, .07);
    color: #8f98b0;
    font-size: clamp(.58rem, 1.25vmin, .7rem);
    line-height: 1.35;
}

.tip-icon {
    color: #f2d96e;
}

.powered {
    text-align: center;
    padding: 0 6px;
}

.powered a {
    color: #7f889f;
    text-decoration: none;
    font-size: clamp(.5rem, 1.05vmin, .62rem);
}

.powered a:hover,
.powered a:focus-visible {
    color: #b7bfd4;
    outline: none;
}

.game-overlay {
    position: absolute;
    z-index: 7;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 7px;
    padding: 24px;
    text-align: center;
    background: rgba(6, 8, 18, .74);
    backdrop-filter: blur(8px);
}

.game-overlay[hidden] {
    display: none;
}

.game-overlay strong {
    font-size: clamp(1.5rem, 5vmin, 2.8rem);
    line-height: 1;
    letter-spacing: -.055em;
}

.game-overlay span {
    max-width: 290px;
    color: #a1a9be;
    font-size: clamp(.68rem, 1.7vmin, .86rem);
    line-height: 1.5;
}

.overlay-jewel {
    width: 50px;
    height: 50px;
    display: grid;
    place-items: center;
    margin-bottom: 3px;
    border: 1px solid rgba(255, 255, 255, .13);
    border-radius: 16px;
    background: linear-gradient(145deg, rgba(139, 124, 255, .25), rgba(54, 220, 186, .10));
    color: #c9c3ff;
    font-size: 1.2rem;
}

.game-overlay--finished .overlay-jewel {
    color: #ffe184;
    background: linear-gradient(145deg, rgba(255, 195, 74, .18), rgba(255, 111, 145, .10));
}

.toast {
    position: absolute;
    z-index: 20;
    left: 50%;
    bottom: 18px;
    transform: translate(-50%, 12px);
    min-width: 160px;
    max-width: min(84%, 420px);
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 999px;
    background: rgba(12, 15, 28, .94);
    box-shadow: 0 14px 35px rgba(0, 0, 0, .34);
    color: #e9ecf6;
    font-size: .76rem;
    font-weight: 800;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
}

.toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (max-width: 720px), (max-height: 540px) {
    .game-shell {
        padding: 7px;
    }

    .game-panel {
        gap: 7px;
    }

    .topbar {
        min-height: 38px;
    }

    .brand-mark {
        width: 36px;
        height: 36px;
        border-radius: 12px;
    }

    .stats {
        gap: 5px;
    }

    .stat-card {
        padding: 7px 9px;
        border-radius: 11px;
    }

    .play-layout {
        grid-template-columns: minmax(0, 1fr) minmax(190px, .56fr);
        gap: 7px;
    }

    .board-card {
        border-radius: 16px;
        padding: 7px;
    }

    .piece-card,
    .info-card {
        border-radius: 14px;
        padding: 9px;
    }

    .piece-tray {
        gap: 5px;
        margin-top: 7px;
    }

    .piece-slot {
        border-radius: 11px;
    }

    .info-card p {
        margin-top: 4px;
    }

    .tip-row {
        margin-top: 5px;
        padding-top: 5px;
    }
}

@media (max-width: 520px) {
    .game-panel {
        height: 100%;
    }

    .sound-toggle span:last-child {
        display: none;
    }

    .sound-toggle {
        width: 40px;
        min-height: 38px;
        padding: 0;
    }

    .play-layout {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .side-panel {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: stretch;
    }

    .piece-card {
        padding: 7px;
    }

    .piece-tray {
        grid-template-columns: repeat(3, 1fr);
        gap: 5px;
    }

    .piece-slot canvas {
        max-height: 70px;
    }

    .info-card,
    .powered,
    .section-heading .moves-hint {
        display: none;
    }

    .section-heading strong {
        font-size: .76rem;
    }
}

.best-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
    padding-top: 11px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: clamp(.62rem, 1.3vmin, .74rem);
    font-weight: 800;
}

.best-row strong {
    color: var(--text);
    font-size: clamp(.78rem, 1.55vmin, .92rem);
}
