:root {
    --m3-ink: #17213b;
    --m3-panel: #f8fbff;
    --m3-line: #d9e3f1;
    --m3-accent: #6d4aff;
    --m3-accent-dark: #4b2dcc;
    --m3-teal: #087f8c;
}

body {
    min-height: 100vh;
    background:
        radial-gradient(circle at 12% 18%, rgba(109, 74, 255, 0.09), transparent 27rem),
        radial-gradient(circle at 88% 72%, rgba(8, 127, 140, 0.08), transparent 25rem),
        var(--background-color);
}

.game-container {
    max-width: 1160px;
}

.eyebrow {
    margin: 0 0 2px;
    color: var(--m3-accent-dark);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.header h1 {
    margin-top: 0;
}

.setup-screen,
.game-area {
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(217, 227, 241, 0.9);
    border-radius: 22px;
    box-shadow: 0 18px 55px rgba(23, 33, 59, 0.12);
}

.setup-screen {
    max-height: 85vh;
    overflow-y: auto;
}

#back-to-modes,
#back-to-modes-from-setup {
    margin-top: 14px;
}

.game-area {
    position: relative;
    overflow: hidden;
    padding: 24px;
}

.game-area::before {
    content: '';
    position: absolute;
    inset: 0 0 auto;
    height: 6px;
    background: linear-gradient(90deg, #7357ff, #14a8a0, #f3a42b, #e85672);
}

.battle-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 36px;
    margin: 0 0 12px;
}

.mode-badge {
    display: inline-flex;
    align-items: center;
    min-height: 27px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #ece8ff;
    color: #5337cf;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.08em;
}

.opponent-name {
    margin-left: 8px;
    color: var(--text-muted);
    font-weight: 700;
}

.reconnect-btn {
    padding: 7px 12px;
    border-radius: 999px;
    background: #9c3b48;
    box-shadow: none;
    font-size: 0.86rem;
}

.scoreboard {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 12px;
    align-items: stretch;
    max-width: 760px;
    margin: 0 auto 12px;
}

.score-card {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 12px 16px;
    border: 2px solid var(--m3-line);
    border-radius: 16px;
    background: var(--m3-panel);
    transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.score-card.active {
    transform: translateY(-2px);
    border-color: var(--m3-accent);
    box-shadow: 0 7px 20px rgba(109, 74, 255, 0.16);
}

.score-card.winner {
    border-color: #179058;
    background: #effbf5;
}

.player-marker {
    display: grid;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 13px;
    color: #fff;
    font-size: 1.35rem;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.4);
}

.marker-one {
    background: linear-gradient(145deg, #7357ff, #4b2dcc);
}

.marker-two {
    background: linear-gradient(145deg, #16a7a0, #08717d);
}

.score-card > div {
    display: grid;
    min-width: 0;
}

.score-name {
    overflow: hidden;
    color: var(--m3-ink);
    font-size: 0.9rem;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.score-value {
    color: var(--m3-ink);
    font-size: clamp(1.45rem, 4vw, 2rem);
    line-height: 1.08;
}

.turns-left {
    color: var(--text-muted);
    font-size: 0.76rem;
}

.versus {
    align-self: center;
    color: #8791a6;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.08em;
}

.turn-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 34px;
    color: var(--m3-ink);
}

.turn-pip {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--m3-accent);
    box-shadow: 0 0 0 5px rgba(109, 74, 255, 0.13);
}

.turn-indicator.waiting .turn-pip {
    background: #da8a22;
    box-shadow: 0 0 0 5px rgba(218, 138, 34, 0.15);
}

.turn-indicator.finished .turn-pip {
    background: #179058;
    box-shadow: 0 0 0 5px rgba(23, 144, 88, 0.14);
}

.status {
    min-height: 1.55em;
    margin: 2px 0 15px;
    color: #526079;
    font-weight: 700;
    text-align: center;
}

.battle-layout {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) 250px;
    gap: 20px;
    align-items: start;
}

.board-shell {
    position: relative;
    min-width: 0;
    padding: 14px;
    border: 1px solid #c9d6e7;
    border-radius: 22px;
    background:
        linear-gradient(rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.72)),
        repeating-linear-gradient(45deg, #e9eff8 0 10px, #f3f7fc 10px 20px);
    box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.65);
}

.match-board {
    --board-gap: clamp(3px, 0.65vw, 7px);
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: var(--board-gap);
    width: min(100%, 650px);
    margin: 0 auto;
    padding: clamp(7px, 1.3vw, 12px);
    border: 3px solid #263555;
    border-radius: 18px;
    background: #1c2947;
    box-shadow: 0 12px 30px rgba(23, 33, 59, 0.25), inset 0 0 22px rgba(0, 0, 0, 0.2);
    touch-action: none;
    user-select: none;
}

.gem-tile {
    position: relative;
    display: grid;
    min-width: 0;
    aspect-ratio: 1;
    place-items: center;
    padding: 0;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.34);
    border-radius: clamp(8px, 1.4vw, 14px);
    background: var(--gem-color);
    color: var(--gem-ink);
    box-shadow:
        inset 0 3px 0 rgba(255, 255, 255, 0.32),
        inset 0 -4px 0 rgba(21, 31, 54, 0.18),
        0 3px 7px rgba(0, 0, 0, 0.2);
    font-family: "Segoe UI Symbol", "Arial Unicode MS", sans-serif;
    font-size: clamp(1rem, 4.4vw, 2.3rem);
    line-height: 1;
    cursor: pointer;
    transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.gem-tile::after {
    content: '';
    position: absolute;
    inset: 8% 14% auto;
    height: 25%;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.24);
    transform: rotate(-12deg);
    pointer-events: none;
}

.gem-tile:hover:not(:disabled) {
    z-index: 2;
    transform: translateY(-2px) scale(1.035);
    filter: brightness(1.05);
}

.gem-tile:focus-visible {
    z-index: 3;
    outline: 4px solid #fff;
    outline-offset: -6px;
    box-shadow: 0 0 0 4px #f6be3e, 0 5px 12px rgba(0, 0, 0, 0.3);
}

.gem-tile.selected {
    z-index: 3;
    transform: scale(0.9);
    outline: 4px solid #fff;
    outline-offset: -7px;
    box-shadow: 0 0 0 4px #f6be3e, 0 7px 16px rgba(0, 0, 0, 0.34);
}

.gem-tile.recent {
    animation: gemPop 420ms ease;
}

.match-board.invalid {
    animation: boardNudge 240ms ease;
}

.match-board.busy .gem-tile {
    cursor: wait;
}

.shape-orbit {
    --gem-color: linear-gradient(145deg, #8bd7f2, #238bb6);
    --gem-ink: #062c3c;
}

.shape-kite {
    --gem-color: linear-gradient(145deg, #c4a8ff, #7357e9);
    --gem-ink: #2e176e;
}

.shape-bloom {
    --gem-color: linear-gradient(145deg, #ffb3c1, #e34e73);
    --gem-ink: #5b1023;
}

.shape-spark {
    --gem-color: linear-gradient(145deg, #ffe29a, #e7a622);
    --gem-ink: #4d3000;
}

.shape-block {
    --gem-color: linear-gradient(145deg, #9de0c1, #2d9c69);
    --gem-ink: #0c422b;
}

.shape-crown {
    --gem-color: linear-gradient(145deg, #ffc49b, #eb7840);
    --gem-ink: #592008;
}

.combo-banner {
    position: absolute;
    z-index: 10;
    top: 50%;
    left: 50%;
    padding: 10px 17px;
    border: 3px solid #fff;
    border-radius: 999px;
    background: linear-gradient(135deg, #6d4aff, #cf3f83);
    color: #fff;
    box-shadow: 0 9px 25px rgba(63, 35, 140, 0.34);
    font-size: clamp(1rem, 3vw, 1.5rem);
    font-weight: 900;
    transform: translate(-50%, -50%);
    animation: comboPop 680ms ease both;
}

.board-help {
    margin: 10px 0 0;
    color: #68758c;
    font-size: 0.82rem;
    text-align: center;
}

.battle-sidebar {
    display: grid;
    gap: 12px;
}

.sidebar-card {
    padding: 15px;
    border: 1px solid var(--m3-line);
    border-radius: 15px;
    background: #fff;
    box-shadow: 0 5px 17px rgba(31, 47, 78, 0.07);
}

.sidebar-card p {
    margin: 7px 0 0;
    color: #617089;
    font-size: 0.88rem;
    line-height: 1.48;
}

.sidebar-kicker {
    display: block;
    margin-bottom: 3px;
    color: var(--m3-accent-dark);
    font-size: 0.7rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.shape-legend {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
    margin-top: 9px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    color: #48566e;
    font-size: 0.76rem;
    font-weight: 700;
}

.legend-symbol {
    display: grid;
    width: 26px;
    height: 26px;
    place-items: center;
    border-radius: 8px;
    background: var(--gem-color);
    color: var(--gem-ink);
    font-family: "Segoe UI Symbol", sans-serif;
}

.move-card {
    min-height: 94px;
    background: #fffaf0;
    border-color: #f0dfb5;
}

.game-buttons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@keyframes gemPop {
    0% { transform: scale(0.76); filter: brightness(1.35); }
    65% { transform: scale(1.09); }
    100% { transform: scale(1); filter: brightness(1); }
}

@keyframes boardNudge {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes comboPop {
    0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
    25%, 70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -70%) scale(1.08); }
}

@media (max-width: 850px) {
    .battle-layout {
        grid-template-columns: 1fr;
    }

    .battle-sidebar {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 600px) {
    .game-area {
        padding: 16px 10px;
    }

    .scoreboard {
        gap: 6px;
    }

    .score-card {
        gap: 7px;
        padding: 9px;
        border-radius: 13px;
    }

    .player-marker {
        flex-basis: 32px;
        width: 32px;
        height: 32px;
        border-radius: 10px;
        font-size: 1rem;
    }

    .versus {
        font-size: 0.62rem;
    }

    .board-shell {
        padding: 7px;
        border-radius: 16px;
    }

    .match-board {
        --board-gap: 3px;
        padding: 5px;
        border-width: 2px;
        border-radius: 13px;
    }

    .gem-tile {
        border-width: 1px;
        border-radius: 7px;
        font-size: clamp(1rem, 7vw, 1.65rem);
    }

    .battle-sidebar {
        grid-template-columns: 1fr;
    }

    .objective-card,
    .legend-card {
        display: none;
    }

    .header {
        align-items: flex-start;
    }
}

@media (max-width: 390px) {
    .score-name {
        max-width: 72px;
    }

    .turns-left {
        font-size: 0.68rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
