:root {
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --board-frame-from: #433022;
    --board-frame-to: #2b1d13;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    background-color: #14161a;
    color: #f3f4f6;
    font-family: 'Inter', sans-serif;
    overflow-x: hidden;
}

/* Custom Scrollbar for Timeline & Modals */
::-webkit-scrollbar {
    height: 5px;
    width: 5px;
}
::-webkit-scrollbar-track {
    background: #181b20;
}
::-webkit-scrollbar-thumb {
    background: #363c49;
    border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
    background: #4b5366;
}

/* Responsive Square Chessboard Container */
.board-stage-row {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 6px;
    width: 100%;
    max-width: 100vw;
    padding: 0 4px;
}

/* Vertical Evaluation Bar alongside the Board */
.eval-bar-wrapper {
    width: 22px;
    height: min(80vw, 440px);
    border-radius: 8px;
    background-color: #1f242d;
    border: 1.5px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 12px 30px -6px rgba(0, 0, 0, 0.65);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    flex-shrink: 0;
    transition: transform 0.25s ease;
}

.eval-bar-wrapper.flipped {
    justify-content: flex-start;
}

.eval-bar-white-fill {
    width: 100%;
    background: linear-gradient(180deg, #ffffff 0%, #e2e8f0 100%);
    transition: height 0.55s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: height;
}

/* Center 0.00 tick mark on the Eval Bar */
.eval-bar-zero-tick {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 1.5px;
    background-color: rgba(16, 185, 129, 0.55);
    pointer-events: none;
    z-index: 5;
}

.eval-bar-score {
    position: absolute;
    left: 0;
    right: 0;
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 8.5px;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1;
    padding: 4px 1px;
    z-index: 10;
    pointer-events: none;
    user-select: none;
}

.eval-bar-score.score-bottom {
    bottom: 3px;
}

.eval-bar-score.score-top {
    top: 3px;
}

.board-wrapper {
    width: min(80vw, 440px);
    height: min(80vw, 440px);
    aspect-ratio: 1 / 1;
    position: relative;
    border-radius: 12px;
    padding: 5px;
    background: linear-gradient(145deg, var(--board-frame-from), var(--board-frame-to));
    box-shadow: 0 20px 45px -10px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.08);
    transition: background 0.25s ease;
    flex-shrink: 0;
}

@media (min-width: 640px) {
    .board-stage-row {
        gap: 8px;
    }
    .eval-bar-wrapper {
        width: 24px;
        height: min(84vw, 450px);
    }
    .board-wrapper {
        width: min(84vw, 450px);
        height: min(84vw, 450px);
        padding: 6px;
    }
}

@media (min-height: 820px) and (min-width: 768px) {
    .eval-bar-wrapper {
        width: 28px;
        height: min(56vh, 510px);
    }
    .eval-bar-score {
        font-size: 10px;
    }
    .board-wrapper {
        width: min(56vh, 510px);
        height: min(56vh, 510px);
    }
}

/* Hide scrollbar for mobile pill bar */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}
.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.chess-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.square {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease;
}

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

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

/* Last Move Subtle Highlight (Standard Mode) */
.square.last-move::before {
    content: '';
    position: absolute;
    inset: 0;
    background-color: rgba(250, 204, 21, 0.34);
    pointer-events: none;
    z-index: 1;
}

/* Selected Piece Ring Highlight */
.square.selected-piece::after {
    content: '';
    position: absolute;
    inset: 2px;
    border: 3px solid #38bdf8;
    border-radius: 6px;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.75), inset 0 0 8px rgba(56, 189, 248, 0.45);
    pointer-events: none;
    z-index: 15;
    animation: pulse-ring 1.6s infinite ease-in-out;
}

@keyframes pulse-ring {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.75; transform: scale(0.97); }
}

/* Staircase Vision Square Overlay */
.vision-tile {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 4;
    opacity: 0;
    transform: scale(0.45);
    border-radius: 2px;
}

.vision-tile.entering {
    animation: vision-staircase-in 0.32s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.vision-tile.steady {
    opacity: 1;
    transform: scale(1);
}

.vision-tile.exiting {
    animation: vision-staircase-out 0.25s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes vision-staircase-in {
    0% {
        opacity: 0;
        transform: scale(0.35);
        filter: brightness(1.6);
    }
    70% {
        opacity: 0.95;
        transform: scale(1.04);
    }
    100% {
        opacity: 0.88;
        transform: scale(1);
        filter: brightness(1.1);
    }
}

@keyframes vision-staircase-out {
    0% {
        opacity: 0.88;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(0.25);
    }
}

/* Piece Container & SVGs */
.piece-container {
    position: relative;
    width: 84%;
    height: 84%;
    z-index: 10;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.piece-container:hover {
    transform: scale(1.06);
}

.piece-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.42));
    transform-origin: 50% 80%;
}

/* Sleeping Piece Animation (Slow Gentle Sway) */
.anim-sleeping {
    animation: sleeping-rock 2.6s ease-in-out infinite;
}

@keyframes sleeping-rock {
    0%, 100% {
        transform: rotate(-8deg) translateY(1px);
    }
    50% {
        transform: rotate(8deg) translateY(-2px);
    }
}

/* Scared / Trembling Piece Animation (Nervous Fast Shiver) */
.anim-scared {
    animation: scared-tremble 0.32s linear infinite;
}

@keyframes scared-tremble {
    0% { transform: translate(0, 0) rotate(0deg); }
    20% { transform: translate(-2.2px, 1px) rotate(-3.5deg); }
    40% { transform: translate(2.2px, -1px) rotate(3.5deg); }
    60% { transform: translate(-2.2px, -1px) rotate(-2.5deg); }
    80% { transform: translate(2.2px, 1px) rotate(2.5deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

/* Move Classification Badge (Top-Right of Piece) */
.move-badge {
    position: absolute;
    top: -10%;
    right: -10%;
    width: 42%;
    height: 42%;
    min-width: 18px;
    min-height: 18px;
    z-index: 25;
    pointer-events: none;
    filter: drop-shadow(0 2px 5px rgba(0,0,0,0.55));
    animation: badge-pop-in 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes badge-pop-in {
    0% {
        opacity: 0;
        transform: scale(0.2) translateY(8px) rotate(-18deg);
    }
    75% {
        opacity: 1;
        transform: scale(1.14) translateY(-2px) rotate(4deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0) rotate(0deg);
    }
}

/* Status Indicator Badge (Zz or Sweat Drop) */
.status-badge {
    position: absolute;
    top: -14%;
    right: -12%;
    width: 46%;
    height: 46%;
    min-width: 20px;
    min-height: 20px;
    z-index: 24;
    pointer-events: none;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.65));
}

/* Offset status badge to top-left if a move badge is also active on the same piece */
.status-badge.offset-left {
    right: auto;
    left: -12%;
}

.status-zz-float {
    animation: zz-float-pulse 2.2s ease-in-out infinite;
}

@keyframes zz-float-pulse {
    0%, 100% {
        transform: translateY(0px) scale(0.95);
        opacity: 0.92;
    }
    50% {
        transform: translateY(-4px) scale(1.08);
        opacity: 1;
    }
}

.status-sweat-drip {
    animation: sweat-drip-anim 1.1s ease-in-out infinite;
}

@keyframes sweat-drip-anim {
    0%, 100% {
        transform: translateY(-2px) scale(0.96);
    }
    50% {
        transform: translateY(3px) scale(1.06);
    }
}

/* ==================== EPIC EDIT & PUNCH MODE FX ==================== */

/* Epic Move Path Trail Tile (Lights up during piece movement, then fades out cleanly) */
.epic-trail-tile {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
    opacity: 0;
    animation: epic-trail-transient 1.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes epic-trail-transient {
    0% {
        opacity: 0;
        transform: scale(0.72);
        filter: brightness(1.5);
    }
    18% {
        opacity: var(--trail-peak-opacity, 0.85);
        transform: scale(1);
        filter: brightness(1.18);
    }
    48% {
        opacity: var(--trail-peak-opacity, 0.85);
        transform: scale(1);
        filter: brightness(1.05);
    }
    100% {
        opacity: 0;
        transform: scale(0.94);
        filter: brightness(1);
    }
}

/* Circular Ripple Ring around Move Classification Badge in Epic Mode */
.badge-ripple-ring {
    position: absolute;
    inset: -45%;
    border-radius: 9999px;
    border: 2px solid currentColor;
    opacity: 0;
    pointer-events: none;
    animation: badge-ripple-expand 1.65s cubic-bezier(0.16, 1, 0.3, 1) infinite;
}

@keyframes badge-ripple-expand {
    0% {
        transform: scale(0.55);
        opacity: 0.95;
    }
    100% {
        transform: scale(1.85);
        opacity: 0;
    }
}

/* Full-Board Red Blunder Filter Overlay (Ref Photo 4) */
.board-blunder-filter {
    position: absolute;
    inset: 6px;
    border-radius: 8px;
    background: radial-gradient(circle at center, rgba(239, 68, 68, 0.28) 0%, rgba(220, 38, 38, 0.52) 100%);
    box-shadow: inset 0 0 48px rgba(239, 68, 68, 0.75);
    pointer-events: none;
    z-index: 18;
    opacity: 0;
    animation: blunder-filter-pulse 0.45s ease-out forwards;
}

@keyframes blunder-filter-pulse {
    0% { opacity: 0; transform: scale(1.02); }
    40% { opacity: 1; transform: scale(1); }
    100% { opacity: 0.92; transform: scale(1); }
}

/* Brilliant Move Vignette & Square Pulse (Ref Photo 5) */
.board-brilliant-vignette {
    position: absolute;
    inset: 6px;
    border-radius: 8px;
    background: radial-gradient(circle at center, rgba(6, 182, 212, 0.05) 25%, rgba(8, 12, 20, 0.62) 100%);
    pointer-events: none;
    z-index: 5;
    animation: fade-in-overlay 0.4s ease-out forwards;
}

.brilliant-square-pulse {
    position: absolute;
    inset: -3px;
    border: 2.5px solid #67e8f9;
    border-radius: 4px;
    box-shadow: 0 0 22px #06b6d4, inset 0 0 16px #22d3ee;
    pointer-events: none;
    z-index: 6;
    animation: brilliant-frame-pulse 1.5s ease-in-out infinite;
}

@keyframes brilliant-frame-pulse {
    0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.95; }
    50% { transform: scale(1.1) rotate(-2deg); opacity: 0.65; }
}

.brilliant-shockwave {
    position: absolute;
    inset: -35%;
    border-radius: 9999px;
    border: 2px solid rgba(165, 243, 252, 0.75);
    box-shadow: 0 0 12px rgba(34, 211, 238, 0.5);
    pointer-events: none;
    z-index: 6;
    animation: brilliant-wave-out 1.8s cubic-bezier(0.16, 1, 0.3, 1) infinite;
}

@keyframes brilliant-wave-out {
    0% { transform: scale(0.4); opacity: 0.95; }
    100% { transform: scale(2.15); opacity: 0; }
}

/* Floating Bokeh / Sparkle Particles for Brilliant & Punch Mode */
.epic-particle {
    position: absolute;
    border-radius: 9999px;
    pointer-events: none;
    z-index: 19;
    animation: epic-particle-float 1.8s ease-out forwards;
}

@keyframes epic-particle-float {
    0% {
        opacity: 0;
        transform: translate(0, 0) scale(0.3);
    }
    25% {
        opacity: 0.95;
        transform: translate(calc(var(--tx) * 0.4), calc(var(--ty) * 0.4)) scale(1.1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) scale(0.15);
    }
}

/* Capture Splatter Dots & Mini Captured Piece Icon (Fade out cleanly) */
.capture-splatter-dot {
    position: absolute;
    border-radius: 9999px;
    pointer-events: none;
    z-index: 8;
    animation: capture-splatter-burst 0.85s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes capture-splatter-burst {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(0.25);
    }
    45% {
        opacity: 0.95;
        transform: translate(calc(var(--sx) * 0.85), calc(var(--sy) * 0.85)) scale(1.08);
    }
    100% {
        opacity: 0;
        transform: translate(var(--sx), var(--sy)) scale(0);
    }
}

.captured-mini-piece {
    position: absolute;
    bottom: -4%;
    right: -6%;
    width: 38%;
    height: 38%;
    z-index: 22;
    pointer-events: none;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.65));
    animation: captured-mini-knock 0.88s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes captured-mini-knock {
    0% {
        opacity: 0;
        transform: scale(0.95) rotate(0deg) translate(-6px, -4px);
    }
    28% {
        opacity: 1;
        transform: scale(0.86) rotate(18deg) translate(4px, 2px);
    }
    68% {
        opacity: 0.85;
        transform: scale(0.55) rotate(30deg) translate(14px, 4px);
    }
    100% {
        opacity: 0;
        transform: scale(0) rotate(42deg) translate(26px, 8px);
    }
}

/* Interactive Custom Vision Paint Mode Square Styles */
.board-wrapper.vision-paint-active {
    box-shadow: 0 0 0 3px #10b981, 0 0 30px rgba(16, 185, 129, 0.45), 0 20px 45px -10px rgba(0, 0, 0, 0.7);
}

.vision-paint-candidate {
    position: absolute;
    inset: 3px;
    border: 2px dashed rgba(255, 255, 255, 0.65);
    background-color: rgba(16, 185, 129, 0.16);
    border-radius: 6px;
    z-index: 28;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.vision-paint-candidate:hover {
    background-color: rgba(16, 185, 129, 0.34);
    transform: scale(0.96);
}

.vision-paint-candidate.painted {
    border-style: solid;
    border-color: #ffffff;
    box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.55), 0 0 12px rgba(0, 0, 0, 0.35);
}

.vision-paint-origin-badge {
    position: absolute;
    inset: 2px;
    border: 3px solid #facc15;
    border-radius: 6px;
    box-shadow: 0 0 14px rgba(250, 204, 21, 0.8);
    pointer-events: none;
    z-index: 29;
}

/* Punch Drop Mode Darkening Overlay & Landing Quake (Ref Photo 6) */
.board-punch-dark-overlay {
    position: absolute;
    inset: 6px;
    border-radius: 8px;
    background: radial-gradient(circle at center, rgba(15, 23, 42, 0.48) 0%, rgba(5, 8, 15, 0.82) 100%);
    pointer-events: none;
    z-index: 9;
    opacity: 0;
    transition: opacity 0.22s ease;
}

.board-punch-dark-overlay.active-darken {
    opacity: 1;
}

@keyframes fade-in-overlay {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Piece Impact Tremble when Punch Mode Lands */
.piece-impact-quake {
    animation: punch-landing-tremble 0.48s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes punch-landing-tremble {
    0% { transform: translate(0, 0) rotate(0deg); }
    15% { transform: translate(-4px, 3px) rotate(-6deg); }
    30% { transform: translate(4px, -3px) rotate(6deg); }
    45% { transform: translate(-3.5px, -2px) rotate(-4.5deg); }
    60% { transform: translate(3px, 2.5px) rotate(4deg); }
    75% { transform: translate(-2px, 1px) rotate(-2.5deg); }
    90% { transform: translate(1.5px, -1px) rotate(1.5deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

/* Upward Drawer Popover Transition */
.upward-drawer {
    transition: opacity 0.2s ease, transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.upward-drawer.hidden-drawer {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
    pointer-events: none;
}

.upward-drawer.visible-drawer {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}