/* =========================================================
   NeelWin — Chess vs Computer (scoped)
   Every selector is prefixed with `.chess-` so nothing here
   can affect other pages or sections of the site.
   It only reuses the global design tokens from style.css.
   ========================================================= */

/* ---------------------------------------------
   Layout
--------------------------------------------- */

.chess-app {
    --chess-light: #E9EFF8;
    --chess-dark: #37619B;
    --chess-dark-2: #2C507F;
    --chess-gold: var(--gold, #D4A72C);
    --chess-gold-soft: var(--gold-soft, #F2D675);
    --chess-navy: var(--navy, #0B1F3A);
}

.chess-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: clamp(20px, 3vw, 38px);
    align-items: start;
}

.chess-main {
    min-width: 0;
}

.chess-panel {
    display: grid;
    gap: 16px;
    align-content: start;
}

/* ---------------------------------------------
   Status bar
--------------------------------------------- */

.chess-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin-bottom: 14px;
}

.chess-turn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-family: var(--font-display, "Manrope", sans-serif);
    font-weight: 700;
    font-size: 0.98rem;
    color: var(--navy, #0B1F3A);
}

.chess-turn__dot {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--white, #fff);
    border: 2px solid var(--navy, #0B1F3A);
    box-shadow: 0 1px 3px rgba(11, 31, 58, 0.25);
    flex-shrink: 0;
}

.chess-turn[data-side="b"] .chess-turn__dot {
    background: var(--navy, #0B1F3A);
}

.chess-turn.is-check {
    color: #C0392B;
}

.chess-turn.is-check .chess-turn__dot {
    border-color: #C0392B;
    animation: chess-pulse 1.1s ease-in-out infinite;
}

.chess-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 13px;
    border-radius: var(--r-pill, 999px);
    background: var(--blue-tint, #EEF3FB);
    border: 1px solid var(--blue-tint-2, #E3ECF9);
    font-family: var(--font-display, system-ui);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--royal, #123E73);
    white-space: nowrap;
}

.chess-badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chess-gold);
}

/* ---------------------------------------------
   Board stage
--------------------------------------------- */

.chess-stage {
    padding: clamp(13px, 2vw, 22px);
    border-radius: var(--r-lg, 22px);
    background:
        radial-gradient(120% 120% at 15% 0%, rgba(30, 99, 181, 0.55), transparent 60%),
        linear-gradient(150deg, var(--navy, #0B1F3A), var(--royal, #123E73));
    box-shadow: var(--shadow-lg, 0 30px 60px -30px rgba(11, 31, 58, 0.35));
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.chess-stage__frame {
    position: relative;
    border-radius: 12px;
    padding: 8px;
    background: linear-gradient(140deg, rgba(212, 167, 44, 0.85), rgba(183, 141, 28, 0.55));
}

.chess-board-wrap {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 18px 40px -22px rgba(0, 0, 0, 0.65) inset;
}

.chess-board {
    --sq: 60px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--chess-light);
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* ---------------------------------------------
   Squares
--------------------------------------------- */

.chess-square {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.chess-square--light {
    background: var(--chess-light);
    --chess-dot: rgba(11, 31, 58, 0.28);
    --chess-ring: rgba(11, 31, 58, 0.20);
}

.chess-square--dark {
    background: var(--chess-dark);
    --chess-dot: rgba(255, 255, 255, 0.55);
    --chess-ring: rgba(255, 255, 255, 0.42);
}

.chess-square:focus-visible {
    outline: 3px solid var(--chess-gold, #D4A72C);
    outline-offset: -3px;
    z-index: 6;
}

/* square tint layer (last move, selection, check) */
.chess-square::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    transition: opacity 160ms ease;
}

.chess-square.is-last::after {
    background: rgba(212, 167, 44, 0.34);
    opacity: 1;
}

.chess-square.is-selected::after {
    background: rgba(212, 167, 44, 0.58);
    opacity: 1;
}

.chess-square.is-check::after {
    background: radial-gradient(circle, rgba(214, 45, 45, 0.92) 0%, rgba(214, 45, 45, 0.5) 46%, rgba(214, 45, 45, 0) 74%);
    opacity: 1;
}

.chess-square.is-droptarget::after,
.chess-square.is-hover-target::after {
    background: rgba(30, 99, 181, 0.42);
    opacity: 1;
}

/* legal move marker */
.chess-square.is-legal::before {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 30%;
    height: 30%;
    border-radius: 50%;
    background: var(--chess-dot);
    z-index: 2;
    pointer-events: none;
    animation: chess-dot-in 160ms var(--ease, ease) both;
}

.chess-square.is-legal.is-capture::before {
    inset: 0;
    width: auto;
    height: auto;
    border-radius: 0;
    background: none;
    box-shadow: inset 0 0 0 6px var(--chess-ring);
    animation: none;
}

/* ---------------------------------------------
   Coordinates
--------------------------------------------- */

.chess-code {
    position: absolute;
    font-family: var(--font-display, sans-serif);
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.02em;
    pointer-events: none;
    opacity: 0.7;
    z-index: 2;
}

.chess-code--file {
    right: 4px;
    bottom: 3px;
}

.chess-code--rank {
    left: 4px;
    top: 3px;
}

.chess-square--light .chess-code {
    color: rgba(11, 31, 58, 0.62);
}

.chess-square--dark .chess-code {
    color: rgba(255, 255, 255, 0.78);
}

/* ---------------------------------------------
   Pieces
--------------------------------------------- */

.chess-piece {
    font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans",
        "Apple Symbols", "Arial Unicode MS", serif;
    font-size: calc(var(--sq, 60px) * 0.78);
    line-height: 1;
    position: relative;
    z-index: 3;
    pointer-events: none;
    transition: transform 120ms var(--ease, ease);
    will-change: transform;
}

.chess-piece--w {
    color: #FFFFFF;
    -webkit-text-stroke: 1.4px #16304F;
    filter: drop-shadow(0 2px 2px rgba(11, 31, 58, 0.35));
}

.chess-piece--b {
    color: #172A44;
    -webkit-text-stroke: 1.1px rgba(255, 255, 255, 0.6);
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.25));
}

.chess-square.is-selected .chess-piece,
.chess-square.is-dragging .chess-piece {
    transform: scale(1.06);
}

.chess-square.is-dragging .chess-piece {
    opacity: 0.35;
}

/* ---------------------------------------------
   Board overlays
--------------------------------------------- */

.chess-thinking {
    position: absolute;
    inset: 0;
    z-index: 7;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    text-align: center;
    background: rgba(11, 31, 58, 0.34);
    color: #EAF1FB;
    font-family: var(--font-display, sans-serif);
    font-weight: 700;
    font-size: 0.95rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--t, 260ms), visibility var(--t, 260ms);
}

.chess-thinking.is-on {
    opacity: 1;
    visibility: visible;
}

.chess-spinner {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.28);
    border-top-color: var(--chess-gold, #D4A72C);
    animation: chess-spin 720ms linear infinite;
    flex-shrink: 0;
}

.chess-promo {
    position: absolute;
    inset: 0;
    z-index: 9;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 14px;
    background: rgba(11, 31, 58, 0.55);
    backdrop-filter: blur(2px);
}

.chess-promo.is-open {
    display: flex;
}

.chess-promo__box {
    background: var(--white, #fff);
    border-radius: var(--r-md, 16px);
    padding: 16px 18px 18px;
    box-shadow: var(--shadow-lg, 0 30px 60px -30px rgba(11, 31, 58, 0.5));
    text-align: center;
    max-width: 100%;
}

.chess-promo__title {
    font-family: var(--font-display, sans-serif);
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--navy, #0B1F3A);
    margin-bottom: 12px;
}

.chess-promo__opts {
    display: flex;
    gap: 10px;
}

.chess-promo__btn {
    width: 54px;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif;
    font-size: 2rem;
    line-height: 1;
    color: var(--navy, #0B1F3A);
    background: var(--blue-tint, #EEF3FB);
    border: 1px solid var(--blue-tint-2, #E3ECF9);
    border-radius: 12px;
    cursor: pointer;
    transition: background-color var(--t-fast, 180ms), color var(--t-fast, 180ms),
        transform var(--t-fast, 180ms);
}

.chess-promo__btn:hover,
.chess-promo__btn:focus-visible {
    background: var(--blue, #1E63B5);
    color: var(--white, #fff);
    transform: translateY(-2px);
}

/* ---------------------------------------------
   Result banner
--------------------------------------------- */

.chess-result {
    display: none;
    margin-top: 16px;
    padding: 16px 18px;
    border-radius: var(--r-md, 16px);
    background: linear-gradient(135deg, #0B1F3A, #123E73);
    border: 1px solid rgba(212, 167, 44, 0.4);
    box-shadow: var(--shadow-md, 0 12px 30px -12px rgba(11, 31, 58, 0.18));
    text-align: center;
}

.chess-result.is-on {
    display: block;
    animation: chess-rise 320ms var(--ease, ease) both;
}

.chess-result__label {
    font-family: var(--font-display, sans-serif);
    font-weight: 800;
    font-size: clamp(1rem, 2vw, 1.2rem);
    color: #FFFFFF;
    margin-bottom: 12px;
}

.chess-result__label span {
    color: var(--chess-gold-soft, #F2D675);
}

.chess-result__actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---------------------------------------------
   Side panel
--------------------------------------------- */

.chess-card {
    background: var(--white, #fff);
    border: 1px solid var(--line, #E4E9F2);
    border-radius: var(--r-md, 16px);
    padding: 18px;
    box-shadow: var(--shadow-xs, 0 1px 2px rgba(11, 31, 58, 0.06));
}

.chess-card__title {
    font-family: var(--font-display, sans-serif);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--gold-deep, #B78D1C);
    margin-bottom: 14px;
}

.chess-field {
    display: grid;
    gap: 7px;
    margin-bottom: 14px;
}

.chess-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted, #667085);
}

.chess-select {
    width: 100%;
    padding: 11px 14px;
    border-radius: var(--r-sm, 10px);
    border: 1px solid var(--line-strong, #D6DEEC);
    background: var(--white, #fff);
    font: inherit;
    font-size: 0.94rem;
    color: var(--ink, #101828);
    cursor: pointer;
    transition: border-color var(--t-fast, 180ms);
}

.chess-select:hover {
    border-color: var(--blue, #1E63B5);
}

.chess-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 4px;
}

.chess-actions .btn {
    width: 100%;
    white-space: nowrap;
}

.chess-actions .btn:disabled,
.chess-result__actions .btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.chess-result__actions .btn[hidden] {
    display: none;
}

.chess-btn--wide {
    grid-column: 1 / -1;
}

/* ---- Captured pieces ---- */

.chess-captured {
    display: grid;
    gap: 10px;
}

.chess-captured__item {
    display: grid;
    gap: 4px;
}

.chess-captured__who {
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted, #667085);
}

.chess-captured__set {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    min-height: 26px;
    font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", serif;
    font-size: 1.35rem;
    line-height: 1;
    color: var(--navy, #0B1F3A);
}

.chess-captured__set .chess-piece--w {
    -webkit-text-stroke: 1px #16304F;
}

.chess-captured__none {
    font-family: var(--font-body, sans-serif);
    font-size: 0.82rem;
    color: var(--line-strong, #D6DEEC);
}

/* ---- Move history ---- */

.chess-moves {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 300px;
    overflow-y: auto;
    scrollbar-width: thin;
    font-variant-numeric: tabular-nums;
}

.chess-moves li {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    padding: 6px 9px;
    border-radius: 8px;
    font-size: 0.92rem;
}

.chess-moves li:nth-child(odd) {
    background: var(--blue-tint, #EEF3FB);
}

.chess-moves__no {
    color: var(--muted, #667085);
    font-weight: 600;
}

.chess-moves__san {
    font-family: var(--font-display, sans-serif);
    font-weight: 600;
    color: var(--navy, #0B1F3A);
    overflow-wrap: anywhere;
}

.chess-moves__san--last {
    color: var(--gold-deep, #B78D1C);
}

.chess-moves__san--empty {
    color: var(--line-strong, #D6DEEC);
}

.chess-empty {
    font-size: 0.9rem;
    color: var(--muted, #667085);
}

.chess-empty.is-off {
    display: none;
}

/* ---------------------------------------------
   Animations
--------------------------------------------- */

@keyframes chess-spin {
    to { transform: rotate(360deg); }
}

@keyframes chess-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.chess-square--light.is-legal {
    animation: none;
}

@keyframes chess-dot-in {
    from {
        transform: scale(0.2);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes chess-rise {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes chess-spin-slow {
    to {
        transform: rotate(360deg);
    }
}

/* ---------------------------------------------
   Responsive
--------------------------------------------- */

@media (max-width: 1020px) {
    .chess-layout {
        grid-template-columns: 1fr;
    }

    .chess-main {
        max-width: 620px;
        width: 100%;
        margin-inline: auto;
    }

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

    .chess-panel > .chess-card:last-child {
        grid-column: 1 / -1;
    }

    .chess-moves {
        max-height: 200px;
    }
}

@media (max-width: 640px) {
    .chess-panel {
        grid-template-columns: 1fr;
    }

    .chess-panel > .chess-card:last-child {
        grid-column: auto;
    }

    .chess-card {
        padding: 16px;
    }

    .chess-code {
        font-size: 0.52rem;
    }

    .chess-actions {
        gap: 9px;
    }

    .chess-result__actions .btn {
        width: 100%;
    }
}

@media (max-width: 400px) {
    .chess-stage__frame {
        padding: 5px;
    }

    .chess-promo__btn {
        width: 46px;
        height: 46px;
        font-size: 1.7rem;
    }
}
