:root {
    --bg-main: #1a1612;
    --bg-panel: rgba(36, 30, 24, 0.85);
    --border-panel: rgba(212, 175, 55, 0.25);
    --gold: #d4af37;
    --gold-glow: rgba(212, 175, 55, 0.5);
    --board-border: #3b2818;
    --square-light: #e8d8b8;
    --square-dark: #8b5a2b;
    --square-highlight-from: rgba(255, 235, 59, 0.35);
    --square-highlight-to: rgba(255, 235, 59, 0.45);
    --square-valid: rgba(46, 204, 113, 0.6);
    --square-jump: rgba(231, 76, 60, 0.6);
    --p1-piece-bg: radial-gradient(circle at 35% 35%, #fffdfa 0%, #ecdcc9 45%, #bca58c 100%);
    --p1-piece-border: #8c765c;
    --p2-piece-bg: radial-gradient(circle at 35% 35%, #424242 0%, #212121 55%, #111111 100%);
    --p2-piece-border: #0d0d0d;
    --text-main: #f5eedb;
    --text-muted: #b8a99a;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Sarabun", sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

body, html {
    width: 100%;
    height: 100%;
    min-height: 100%;
    min-height: -webkit-fill-available;
    overflow: hidden;
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-family);
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 0;
}

#app-container {
    width: 100%;
    max-width: 600px;
    height: 100%;
    height: 100vh;
    height: 100dvh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    margin: 0 auto;
    position: relative;
    gap: 6px;
}

/* Header & Top Bar */
.top-nav {
    width: 100%;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--bg-panel);
    border-radius: 12px;
    border: 1px solid var(--border-panel);
    backdrop-filter: blur(8px);
}

.game-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gold);
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-actions {
    display: flex;
    gap: 6px;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(212, 175, 55, 0.4);
    color: var(--gold);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.2s;
}

.icon-btn:hover, .icon-btn:active {
    background: var(--gold);
    color: #1a1612;
    transform: scale(1.05);
}

.ui-icon {
    width: 20px;
    height: 20px;
    display: block;
    stroke: currentColor;
    transition: transform 0.2s ease;
}

.icon-btn:hover .ui-icon {
    transform: scale(1.1);
}

.lang-btn {
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    border-color: rgba(212, 175, 55, 0.4);
    color: var(--gold);
}

/* Player Info Bars */
.player-bar {
    width: 100%;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 14px;
    background: var(--bg-panel);
    border-radius: 10px;
    border: 1px solid transparent;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.player-bar.active-turn {
    border-color: var(--gold);
    box-shadow: 0 0 12px var(--gold-glow);
}

/* AI Thinking Load Spinner on Circled Avatar */
.player-bar.thinking .avatar-p2 {
    position: relative;
    border-color: rgba(241, 196, 15, 0.3) !important;
}

.player-bar.thinking .avatar-p2::after {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--gold);
    border-right-color: var(--gold);
    box-sizing: border-box;
    animation: avatar-load-spin 0.75s linear infinite;
    pointer-events: none;
}

@keyframes avatar-load-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.player-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    position: relative;
}

.avatar-p1 {
    background: var(--p1-piece-bg);
    border-color: var(--p1-piece-border);
}

.avatar-p2 {
    background: var(--p2-piece-bg);
    border-color: #666;
    transition: all 0.3s ease;
}

.player-name {
    font-weight: 600;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
}

.player-stats {
    display: flex;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.crown-stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 2px;
}

.ui-crown-mini {
    width: 17px;
    height: 17px;
    fill: var(--gold);
    display: inline-block;
    vertical-align: middle;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}

.stat-count {
    font-weight: bold;
    color: var(--gold);
}

/* Game Board Area */
.board-wrapper {
    position: relative;
    width: min(88vw, calc(100vh - 290px), calc(100dvh - 290px), 480px);
    height: min(88vw, calc(100vh - 290px), calc(100dvh - 290px), 480px);
    max-width: 52vh;
    max-width: 52dvh;
    max-height: 52vh;
    max-height: 52dvh;
    aspect-ratio: 1 / 1;
    margin: auto 0;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7), inset 0 0 10px rgba(0, 0, 0, 0.5);
    background: var(--board-border);
    padding: 10px;
    border: 2px solid #5a3e26;
    transition: box-shadow 0.4s ease, border-color 0.4s ease;
    box-sizing: border-box;
    flex-shrink: 1;
    min-height: 0;
}

/* Board Micro-Shake on Capture */
.board-wrapper.screen-shake {
    animation: board-shake 0.24s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes board-shake {
    0%, 100% { transform: translate(0, 0); }
    20% { transform: translate(-3px, 2px); }
    40% { transform: translate(3px, -2px); }
    60% { transform: translate(-2px, 1px); }
    80% { transform: translate(2px, -1px); }
}

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

.square {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

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

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

.square.last-move-from {
    background-color: #b08d4a !important;
}

.square.last-move-to {
    background-color: #c7a45d !important;
}

.square.last-move-captured {
    background-color: rgba(220, 53, 69, 0.4) !important;
    box-shadow: inset 0 0 12px rgba(220, 53, 69, 0.55);
}

.square.replay-trail {
    background-color: rgba(241, 196, 15, 0.35) !important;
    box-shadow: inset 0 0 10px rgba(241, 196, 15, 0.5);
}

/* Valid Move Indicators */
.valid-target-marker {
    width: 32%;
    height: 32%;
    border-radius: 50%;
    background: var(--square-valid);
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.8);
    pointer-events: none;
    animation: pulse-marker 1.2s infinite ease-in-out;
}

.valid-jump-marker {
    width: 38%;
    height: 38%;
    border-radius: 50%;
    background: var(--square-jump);
    box-shadow: 0 0 10px rgba(231, 76, 60, 0.9);
    pointer-events: none;
    animation: pulse-marker 0.8s infinite ease-in-out;
}

@keyframes pulse-marker {
    0%, 100% { transform: scale(0.9); opacity: 0.7; }
    50% { transform: scale(1.15); opacity: 1; }
}

/* Pieces */
.piece {
    width: 82%;
    height: 82%;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5), inset 0 2px 3px rgba(255, 255, 255, 0.4);
    position: relative;
    transition: transform 0.15s ease, filter 0.2s ease;
    z-index: 2;
}

.piece:hover {
    transform: scale(1.05);
}

.piece.p1 {
    background: var(--p1-piece-bg);
    border: 3px solid var(--p1-piece-border);
}

.piece.p2 {
    background: var(--p2-piece-bg);
    border: 3px solid var(--p2-piece-border);
}

.piece.selected {
    outline: 3px solid var(--gold);
    outline-offset: 3px;
    filter: drop-shadow(0 0 14px var(--gold));
    transform: translateY(-6px) scale(1.12);
    box-shadow: 0 14px 22px rgba(0, 0, 0, 0.65), inset 0 2px 4px rgba(255, 255, 255, 0.5);
    z-index: 10;
}

/* Piece Landing Bounce */
.piece.landed {
    animation: piece-land 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes piece-land {
    0% { transform: scale(1.22) translateY(-8px); }
    55% { transform: scale(0.9, 1.1) translateY(1px); }
    75% { transform: scale(1.05, 0.95); }
    100% { transform: scale(1) translateY(0); }
}

.piece.mandatory-jump {
    animation: pulse-mandatory 1s infinite alternate;
}

@keyframes pulse-mandatory {
    from { filter: drop-shadow(0 0 2px #e74c3c); }
    to { filter: drop-shadow(0 0 10px #e74c3c); }
}

/* Mandatory Capture Attention Shake & Invalid Piece Wiggle */
.piece.piece-invalid-wiggle {
    animation: invalid-wiggle 0.35s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes invalid-wiggle {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-5px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

.piece.piece-mandatory-shake {
    animation: mandatory-attention-shake 0.48s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes mandatory-attention-shake {
    0%, 100% {
        transform: scale(1) translate(0, 0);
        filter: drop-shadow(0 0 4px #e74c3c);
    }
    15% {
        transform: scale(1.15) translate(-3px, -3px);
        filter: drop-shadow(0 0 14px #e74c3c) brightness(1.2);
    }
    30% {
        transform: scale(1.15) translate(3px, -3px);
        filter: drop-shadow(0 0 16px #ff6b6b) brightness(1.25);
    }
    45% {
        transform: scale(1.1) translate(-2px, -1px);
        filter: drop-shadow(0 0 12px #e74c3c) brightness(1.15);
    }
    60% {
        transform: scale(1.1) translate(2px, -1px);
        filter: drop-shadow(0 0 10px #e74c3c) brightness(1.1);
    }
    80% {
        transform: scale(1.04) translate(0, 0);
        filter: drop-shadow(0 0 6px #e74c3c);
    }
}

.status-banner.status-shake {
    animation: status-shake-anim 0.36s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
    color: #ff6b6b;
}

@keyframes status-shake-anim {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-2px); }
    80% { transform: translateX(2px); }
}

/* King Crown Icon */
.crown-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--gold);
    pointer-events: none;
}

.piece-crown-svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
}

.crown-icon.drop {
    display: flex;
    animation: crown-drop 0.55s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes crown-drop {
    0% { transform: translateY(-28px) scale(0) rotate(-45deg); opacity: 0; }
    60% { transform: translateY(2px) scale(1.4) rotate(8deg); opacity: 1; filter: drop-shadow(0 0 12px #ffeaa7); }
    80% { transform: translateY(-2px) scale(1.05) rotate(-3deg); }
    100% { transform: translateY(0) scale(1) rotate(0deg); opacity: 1; }
}

.piece.p1 .crown-icon {
    color: #9c6c10;
}

.piece.p2 .crown-icon {
    color: #f1c40f;
}

/* King Promotion Celebration Aura */
.piece.king-promoted {
    animation: king-pulse 0.65s ease-out;
}

@keyframes king-pulse {
    0% { transform: scale(0.9); filter: drop-shadow(0 0 4px var(--gold)); }
    50% { transform: scale(1.22); filter: drop-shadow(0 0 24px #ffd700); }
    100% { transform: scale(1); filter: drop-shadow(0 0 8px var(--gold)); }
}

.sunburst-overlay {
    position: absolute;
    width: 220%;
    height: 220%;
    top: -60%;
    left: -60%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.7) 0%, rgba(255, 179, 0, 0.3) 45%, transparent 70%);
    pointer-events: none;
    z-index: 15;
    animation: sunburst-fade 0.75s ease-out forwards;
}

@keyframes sunburst-fade {
    0% { transform: scale(0.4) rotate(0deg); opacity: 0; }
    30% { opacity: 1; transform: scale(1.15) rotate(45deg); }
    100% { opacity: 0; transform: scale(1.6) rotate(90deg); }
}

/* Capture Shatter & Wood Chip Particles */
.capture-shatter {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    z-index: 8;
}

.capture-shatter .shatter-ring {
    position: absolute;
    width: 50%;
    height: 50%;
    border-radius: 50%;
    border: 3px solid #ff4757;
    box-shadow: 0 0 14px rgba(255, 71, 87, 0.9);
    animation: shatter-ring 0.4s ease-out forwards;
}

@keyframes shatter-ring {
    0% { transform: scale(0.6); opacity: 1; border-width: 4px; }
    100% { transform: scale(2.3); opacity: 0; border-width: 1px; }
}

.capture-shatter .wood-chip {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: #c7a45d;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.6);
    animation: wood-chip-fly 0.45s ease-out forwards;
}

@keyframes wood-chip-fly {
    0% { transform: translate(0, 0) scale(1) rotate(0deg); opacity: 1; }
    100% { transform: translate(var(--chip-dx, 20px), var(--chip-dy, -20px)) scale(0.2) rotate(var(--chip-rot, 180deg)); opacity: 0; }
}

/* Multi-Jump Combo Banner */
.combo-banner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.6rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 12px rgba(255, 71, 87, 0.9), 0 2px 6px rgba(0, 0, 0, 0.9);
    background: linear-gradient(135deg, rgba(231, 76, 60, 0.94), rgba(241, 196, 15, 0.94));
    padding: 8px 22px;
    border-radius: 30px;
    border: 2px solid #fff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 20px rgba(241, 196, 15, 0.8);
    pointer-events: none;
    z-index: 50;
    animation: combo-float 0.85s cubic-bezier(0.2, 0.9, 0.3, 1.2) forwards;
    white-space: nowrap;
}

@keyframes combo-float {
    0% { transform: translate(-50%, -20%) scale(0.5); opacity: 0; }
    25% { transform: translate(-50%, -50%) scale(1.25); opacity: 1; }
    50% { transform: translate(-50%, -55%) scale(1.1); opacity: 1; }
    100% { transform: translate(-50%, -85%) scale(0.95); opacity: 0; }
}

/* Confetti Overlay */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    pointer-events: none;
    z-index: 150;
}

/* Bottom Controls */
.bottom-controls {
    width: 100%;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 8px 0;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 24px;
    background: var(--bg-panel);
    border: 1px solid rgba(212, 175, 55, 0.4);
    color: var(--gold);
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    min-width: 100px;
    text-align: center;
    transition: all 0.2s;
}

.action-btn:hover:not(:disabled), .action-btn:active:not(:disabled) {
    background: var(--gold);
    color: #1a1612;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--gold-glow);
}

.action-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.action-btn.btn-resign {
    border-color: rgba(231, 76, 60, 0.55);
    color: #ff6b6b;
}

.action-btn.btn-resign:hover:not(:disabled), .action-btn.btn-resign:active:not(:disabled) {
    background: linear-gradient(135deg, rgba(231, 76, 60, 0.85), rgba(192, 57, 43, 0.95));
    color: #fff;
    box-shadow: 0 4px 14px rgba(231, 76, 60, 0.45);
}

/* Combo Replay Feature */
.replay-btn {
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.22), rgba(230, 126, 34, 0.32));
    border: 1.5px solid #d4af37;
    color: #ffd700;
    font-weight: 700;
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.35);
    transition: all 0.2s ease;
    animation: replay-pulse 1s ease-in-out 3;
}

.replay-btn.pulse-active {
    animation: replay-pulse 1s ease-in-out 3;
}

.replay-btn:hover:not(:disabled), .replay-btn:active:not(:disabled) {
    background: linear-gradient(135deg, #d4af37, #e67e22);
    color: #1a1612;
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 6px 18px rgba(241, 196, 15, 0.7);
}

@keyframes replay-pulse {
    0%, 100% {
        box-shadow: 0 0 8px rgba(212, 175, 55, 0.35);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 18px rgba(241, 196, 15, 0.8), 0 0 8px rgba(230, 126, 34, 0.6);
        transform: scale(1.04);
    }
}

/* Top-Right Unified Sponsor & Replay Badge (Single button containing both replay and kinjung.com) */
.replay-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(231, 76, 60, 0.65);
    border-radius: 12px;
    padding: 3px 10px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
    z-index: 60;
    pointer-events: none;
    user-select: none;
    animation: replay-badge-appear 0.25s ease-out;
}

.replay-badge-header {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.8px;
    color: #ff4757;
}

.replay-rec-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #ff4757;
    box-shadow: 0 0 6px #ff4757;
    animation: replay-rec-blink 1s infinite;
}

@keyframes replay-rec-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

@keyframes replay-badge-appear {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Subtle Branding Watermark (Line 2 inside the replay button) */
.replay-watermark {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.60rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: rgba(255, 255, 255, 0.72);
}

.replay-watermark-text {
    line-height: 1;
}

/* Level 1 Cinematic Replay Tactical SVG Overlay */
.replay-tactical-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    width: calc(100% - 20px);
    height: calc(100% - 20px);
    pointer-events: none;
    z-index: 35;
    overflow: visible;
    transition: opacity 0.25s ease-out;
}

.replay-tactical-overlay.fade-out {
    opacity: 0;
}

/* Replay Moving Piece Focal Rings (Player = Emerald Green, Opponent/Capture = Crimson Red) */
.piece.replay-focus-player {
    outline: 3.5px solid #2ecc71 !important;
    outline-offset: 3px;
    filter: drop-shadow(0 0 14px rgba(46, 204, 113, 0.95)) !important;
    transform: translateY(-6px) scale(1.12);
    z-index: 10;
}

.piece.replay-focus-opponent,
.piece.replay-focus-capture {
    outline: 3.5px solid #ff4757 !important;
    outline-offset: 3px;
    filter: drop-shadow(0 0 14px rgba(255, 71, 87, 0.95)) !important;
    transform: translateY(-6px) scale(1.12);
    z-index: 10;
}

.piece.replay-focus {
    outline: 3.5px solid #2ecc71 !important;
    outline-offset: 3px;
    filter: drop-shadow(0 0 14px rgba(46, 204, 113, 0.95)) !important;
    transform: translateY(-6px) scale(1.12);
    z-index: 10;
}

/* Replay Destination Markers (Color-matched to moving piece) */
.valid-marker-replay-player {
    width: 32%;
    height: 32%;
    border-radius: 50%;
    background: #2ecc71;
    box-shadow: 0 0 12px rgba(46, 204, 113, 0.9);
    pointer-events: none;
    animation: pulse-marker 1s infinite ease-in-out;
}

.valid-marker-replay-player-jump {
    width: 38%;
    height: 38%;
    border-radius: 50%;
    background: #2ecc71;
    box-shadow: 0 0 14px rgba(46, 204, 113, 1);
    pointer-events: none;
    animation: pulse-marker 0.8s infinite ease-in-out;
}

.valid-marker-replay-opponent {
    width: 32%;
    height: 32%;
    border-radius: 50%;
    background: #ff4757;
    box-shadow: 0 0 12px rgba(255, 71, 87, 0.9);
    pointer-events: none;
    animation: pulse-marker 1s infinite ease-in-out;
}

.valid-marker-replay-opponent-jump {
    width: 38%;
    height: 38%;
    border-radius: 50%;
    background: #ff4757;
    box-shadow: 0 0 14px rgba(255, 71, 87, 1);
    pointer-events: none;
    animation: pulse-marker 0.8s infinite ease-in-out;
}

/* Tactical Attacker Spotlight - Player Hero (Emerald Green Pulse) */
.tactical-attacker-ring {
    fill: none;
    stroke: #2ecc71;
    stroke-width: 4.5;
    filter: drop-shadow(0 0 10px rgba(46, 204, 113, 0.95));
    animation: tactical-attacker-pulse 1.1s infinite ease-in-out;
}

@keyframes tactical-attacker-pulse {
    0%, 100% {
        r: 38;
        stroke-width: 4;
        opacity: 0.85;
    }
    50% {
        r: 43;
        stroke-width: 5.5;
        opacity: 1;
        filter: drop-shadow(0 0 16px rgba(46, 204, 113, 1));
    }
}

/* Tactical Attacker Spotlight - Opponent Boss Strike (Crimson Red Pulse) */
.tactical-attacker-ring-opponent {
    fill: none;
    stroke: #ff4757;
    stroke-width: 4.5;
    filter: drop-shadow(0 0 10px rgba(255, 71, 87, 0.95));
    animation: tactical-attacker-pulse-opponent 1.1s infinite ease-in-out;
}

@keyframes tactical-attacker-pulse-opponent {
    0%, 100% {
        r: 38;
        stroke-width: 4;
        opacity: 0.85;
    }
    50% {
        r: 43;
        stroke-width: 5.5;
        opacity: 1;
        filter: drop-shadow(0 0 16px rgba(255, 71, 87, 1));
    }
}

.tactical-target-ring {
    fill: rgba(255, 56, 56, 0.18);
    stroke: #ff3838;
    stroke-width: 4.5;
    filter: drop-shadow(0 0 8px rgba(255, 56, 56, 0.9));
    animation: tactical-pulse-ring 1s infinite ease-in-out;
}

@keyframes tactical-pulse-ring {
    0%, 100% {
        r: 36;
        stroke-width: 4;
        fill-opacity: 0.15;
    }
    50% {
        r: 42;
        stroke-width: 5.5;
        fill-opacity: 0.35;
        filter: drop-shadow(0 0 14px rgba(255, 56, 56, 1));
    }
}


.tactical-target-dot {
    fill: #ff3838;
    filter: drop-shadow(0 0 6px #ff3838);
}

/* Directional Red Attack Arrows */
.tactical-arrow-path {
    stroke: #ff3838;
    stroke-width: 5.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    filter: drop-shadow(0 0 7px rgba(255, 56, 56, 0.95));
    stroke-dasharray: 8 4;
    animation: tactical-arrow-flow 0.8s linear infinite;
}

@keyframes tactical-arrow-flow {
    from { stroke-dashoffset: 24; }
    to { stroke-dashoffset: 0; }
}

/* Tactical Step Badge (1, 2, 3) */
.tactical-step-badge-bg {
    fill: #ff3838;
    stroke: #ffffff;
    stroke-width: 2.5;
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.7));
}

.tactical-step-badge-text {
    fill: #ffffff;
    font-size: 22px;
    font-weight: 900;
    font-family: inherit;
    text-anchor: middle;
    dominant-baseline: central;
}


/* Cinematic Slow-Mo Camera Impact */
.board-wrapper.cinematic-impact {
    animation: cinematic-shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes cinematic-shake {
    0% { transform: scale(1); }
    20% { transform: scale(1.025) translate(-2px, 2px); }
    40% { transform: scale(1.025) translate(2px, -2px); }
    60% { transform: scale(1.01) translate(-1px, 1px); }
    100% { transform: scale(1) translate(0, 0); }
}

/* Status Banner */
.status-banner {
    flex-shrink: 0;
    font-size: 0.88rem;
    color: var(--gold);
    font-weight: 500;
    min-height: 1.4rem;
    text-align: center;
    line-height: 1.4;
}


/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
    backdrop-filter: blur(5px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #241e18;
    border: 2px solid var(--gold);
    border-radius: 16px;
    padding: 24px;
    max-width: 420px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    color: var(--text-main);
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    position: relative;
}

.modal-title {
    font-size: 1.3rem;
    color: var(--gold);
    margin-bottom: 14px;
    text-align: center;
}

.modal-body {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #e0d5c5;
    margin-bottom: 20px;
}

.modal-body h4 {
    color: var(--gold);
    margin: 12px 0 6px 0;
}

.modal-body ul {
    margin-left: 20px;
    margin-bottom: 10px;
}

.modal-body li {
    margin-bottom: 4px;
}

.modal-footer {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.settings-modal-footer {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.settings-version {
    position: absolute;
    right: 0;
    bottom: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.45);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    letter-spacing: 0.5px;
    pointer-events: none;
    user-select: none;
}

.primary-btn {
    background: var(--gold);
    color: #1a1612;
    border: none;
    border-radius: 8px;
    padding: 10px 24px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s;
}

.primary-btn:hover {
    transform: scale(1.05);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 10px 22px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.35);
    transform: scale(1.03);
}

.modal-close-btn {
    position: absolute;
    top: 12px;
    right: 14px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s, transform 0.15s;
}

.modal-close-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.12);
}

.close-svg {
    display: block;
}

.option-group {
    margin-bottom: 16px;
}

.option-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--gold);
    font-weight: 600;
}

.option-select {
    width: 100%;
    padding: 8px 12px;
    background: #1a1612;
    color: #fff;
    border: 1px solid #5a3e26;
    border-radius: 8px;
    font-size: 0.95rem;
}

/* Black Player Mode */
body.player-black {
    --p1-piece-bg: radial-gradient(circle at 35% 35%, #424242 0%, #212121 55%, #111111 100%);
    --p1-piece-border: #0d0d0d;
    --p2-piece-bg: radial-gradient(circle at 35% 35%, #fffdfa 0%, #ecdcc9 45%, #bca58c 100%);
    --p2-piece-border: #8c765c;
}

body.player-black .avatar-p1 {
    border-color: #666;
}

body.player-black .avatar-p2 {
    border-color: var(--p2-piece-border);
}

body.player-black .piece.p1 .crown-icon {
    color: #f1c40f;
}

body.player-black .piece.p2 .crown-icon {
    color: #9c6c10;
}

/* Stats Modal Styling */
.stats-modal-content {
    max-width: 440px;
}

.stats-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.stats-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(212, 175, 55, 0.22);
    border-radius: 10px;
    padding: 8px 10px;
    text-align: center;
}

.stats-card-val {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stats-card-label {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.stats-section-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--gold);
    margin: 14px 0 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.stats-diff-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stats-diff-card {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 8px;
    padding: 8px 12px;
}

.stats-diff-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    font-size: 0.85rem;
}

.stats-diff-name {
    font-weight: 700;
    color: #fff;
}

.stats-diff-record {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.stats-diff-rate {
    font-weight: 700;
    color: var(--gold);
}

.stats-bar-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    overflow: hidden;
}

.stats-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #e67e22, var(--gold));
    border-radius: 4px;
    transition: width 0.4s ease;
}


/* ==========================================================================
   Kinjung Pop (Neo-Brutalism / Cozy Pop) Scoped Theme
   ========================================================================== */
body.theme-pop {
    --bg-main: #fff8ec;
    --bg-panel: #ffffff;
    --border-panel: #231d32;
    --gold: #231d32;
    --gold-glow: rgba(255, 225, 117, 0.6);
    --board-border: #231d32;
    --square-light: #fffcf4;
    --square-dark: #756687;
    --square-highlight-from: #ffe175;
    --square-highlight-to: #ffd13b;
    --square-valid: #20c997;
    --square-jump: #ff5252;
    --p1-piece-bg: #ffffff;
    --p1-piece-border: #231d32;
    --p2-piece-bg: #231d32;
    --p2-piece-border: #ffe175;
    --text-main: #231d32;
    --text-muted: #5f576e;
    background-color: #fff8ec;
    background-image: radial-gradient(rgba(35, 29, 50, 0.08) 1.5px, transparent 1.5px);
    background-size: 20px 20px;
    color: #231d32;
}


body.theme-pop,
body.theme-pop.theme-slate {
    --square-dark: #756687;
}

body.theme-pop.theme-terracotta {
    --square-dark: #c27d66;
}

body.theme-pop.theme-sage {
    --square-dark: #52796f;
}

body.theme-pop.player-black {
    --p1-piece-bg: #231d32;
    --p1-piece-border: #ffe175;
    --p2-piece-bg: #ffffff;
    --p2-piece-border: #231d32;
}

/* Header & Top Bar */
body.theme-pop .top-nav {
    background: #ffffff;
    border: 1.5px solid #231d32;
    box-shadow: 0 2px 8px rgba(35, 29, 50, 0.08);
    border-radius: 12px;
}

body.theme-pop .game-title {
    color: #231d32;
}

body.theme-pop .icon-btn {
    background: #ffffff;
    border: 1.5px solid #231d32;
    color: #231d32;
    box-shadow: 0 2px 4px rgba(35, 29, 50, 0.08);
    border-radius: 8px;
}

body.theme-pop .icon-btn:hover:not(:disabled),
body.theme-pop .icon-btn:active:not(:disabled) {
    background: #ffe175;
    color: #231d32;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(35, 29, 50, 0.14);
}

/* Status Banner */
body.theme-pop .status-banner {
    color: #231d32;
    font-weight: 700;
}

/* Player Info Bars */
body.theme-pop .player-bar {
    background: #ffffff;
    border: 1.5px solid #231d32;
    box-shadow: 0 2px 8px rgba(35, 29, 50, 0.08);
    border-radius: 12px;
}

body.theme-pop .player-name {
    color: #231d32;
}

body.theme-pop .player-stats {
    color: #5f576e;
}

body.theme-pop .stat-count {
    color: #e06c1b;
}

body.theme-pop .ui-crown-mini {
    fill: #f59f00;
}

body.theme-pop .player-bar.active {
    border-color: #ff6b4a;
    box-shadow: 0 2px 8px rgba(35, 29, 50, 0.08), 0 0 0 2px #ff6b4a;
}

/* Game Board */
body.theme-pop .board-wrapper {
    background: #231d32;
    border: 2px solid #231d32;
    box-shadow: 0 6px 20px rgba(35, 29, 50, 0.16);
    border-radius: 14px;
}

body.theme-pop .square.light {
    background-color: #fffcf4;
}

body.theme-pop .square.dark {
    background-color: var(--square-dark);
}

body.theme-pop .square.last-move-from {
    background-color: #ffe175 !important;
}

body.theme-pop .square.last-move-to {
    background-color: #ffd13b !important;
}

body.theme-pop .square.last-move-captured {
    background-color: rgba(255, 107, 74, 0.45) !important;
    box-shadow: inset 0 0 10px rgba(255, 107, 74, 0.7);
}

body.theme-pop .valid-target-marker {
    background: #20c997;
    box-shadow: 0 0 0 2px #231d32, 0 2px 6px rgba(32, 201, 151, 0.6);
}

body.theme-pop .valid-jump-marker {
    background: #ff5252;
    box-shadow: 0 0 0 2px #231d32, 0 2px 8px rgba(255, 82, 82, 0.7);
}

/* Pieces with high contrast tactile rims */
body.theme-pop .piece {
    border: 2px solid #231d32;
    box-shadow: 0 3px 6px rgba(35, 29, 50, 0.2);
}

body.theme-pop .piece.p1 {
    background: #ffffff;
    border: 2px solid #231d32;
    box-shadow: 0 3px 6px rgba(35, 29, 50, 0.18), inset 0 0 0 1px rgba(35, 29, 50, 0.1);
}

body.theme-pop .piece.p2 {
    background: #231d32;
    border: 2px solid #ffffff;
    box-shadow: 0 3px 6px rgba(18, 14, 28, 0.3), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

body.theme-pop.player-black .piece.p1 {
    background: #231d32;
    border: 2px solid #ffffff;
    box-shadow: 0 3px 6px rgba(18, 14, 28, 0.3), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

body.theme-pop.player-black .piece.p2 {
    background: #ffffff;
    border: 2px solid #231d32;
    box-shadow: 0 3px 6px rgba(35, 29, 50, 0.18), inset 0 0 0 1px rgba(35, 29, 50, 0.1);
}

body.theme-pop .avatar-p2 {
    border-color: #ffffff;
}

body.theme-pop .crown-icon {
    color: #f59f00;
}

body.theme-pop .piece.p1 .crown-icon {
    color: #d97706;
}

body.theme-pop .piece.p2 .crown-icon {
    color: #f59f00;
}

body.theme-pop.player-black .piece.p1 .crown-icon {
    color: #f59f00;
}

body.theme-pop.player-black .piece.p2 .crown-icon {
    color: #d97706;
}

/* Bottom Controls */
body.theme-pop .action-btn {
    background: #ffffff;
    border: 1.5px solid #231d32;
    color: #231d32;
    box-shadow: 0 2px 6px rgba(35, 29, 50, 0.08);
    border-radius: 10px;
    font-weight: 700;
}

body.theme-pop .action-btn:hover:not(:disabled),
body.theme-pop .action-btn:active:not(:disabled) {
    background: #ffe175;
    color: #231d32;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(35, 29, 50, 0.14);
}

body.theme-pop .action-btn:disabled {
    background: #f0ede6;
    border-color: #beb8ab;
    color: #9c9485;
    box-shadow: none;
    opacity: 0.6;
}

body.theme-pop .action-btn.btn-resign {
    color: #d6336c;
}

body.theme-pop .action-btn.btn-resign:hover:not(:disabled) {
    background: #ff6b6b;
    color: #ffffff;
    border-color: #ff6b6b;
    box-shadow: 0 4px 10px rgba(255, 107, 107, 0.3);
}

body.theme-pop .replay-btn {
    background: #ffe175;
    color: #231d32;
}

/* Modals */
body.theme-pop .modal-content {
    background: #ffffff;
    border: 1.5px solid #231d32;
    box-shadow: 0 12px 32px rgba(35, 29, 50, 0.2);
    border-radius: 16px;
    color: #231d32;
}

body.theme-pop .modal-title {
    color: #231d32;
    font-weight: 800;
}

body.theme-pop .modal-body {
    color: #3b3548;
}

body.theme-pop .modal-body h4 {
    color: #231d32;
}

body.theme-pop .option-group label {
    color: #231d32;
}

body.theme-pop .option-select {
    background: #fff8ec;
    color: #231d32;
    border: 1.5px solid #231d32;
    border-radius: 8px;
    font-weight: 600;
}

body.theme-pop .primary-btn {
    background: #ffe175;
    color: #231d32;
    border: 1.5px solid #231d32;
    box-shadow: 0 2px 6px rgba(35, 29, 50, 0.1);
    border-radius: 10px;
    font-weight: 800;
}

body.theme-pop .primary-btn:hover {
    background: #ffd13b;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(35, 29, 50, 0.16);
}

body.theme-pop .modal-close-btn {
    color: #231d32;
}

body.theme-pop .modal-close-btn:hover {
    color: #231d32;
    background: #ffe175;
}

body.theme-pop .settings-version {
    color: #8c839f;
    font-weight: 700;
}

body.theme-pop .stats-diff-card {
    background: #fff8ec;
    border: 1.5px solid #231d32;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(35, 29, 50, 0.06);
}

body.theme-pop .stats-diff-name {
    color: #231d32;
}

body.theme-pop .stats-diff-record {
    color: #5f576e;
}

body.theme-pop .stats-diff-rate {
    color: #e06c1b;
}

body.theme-pop .stats-bar-track {
    background: #e8e2d5;
    border: 1px solid #231d32;
}

body.theme-pop .stats-bar-fill {
    background: linear-gradient(90deg, #ff6b4a, #ffe175);
}


/* AI Bar Clickable Affordance */
.p2-info-clickable {
    cursor: pointer;
    border-radius: 8px;
    padding: 3px 8px;
    margin: -3px -8px;
    transition: background 0.2s ease, transform 0.15s ease;
    user-select: none;
}

.p2-info-clickable:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-1px);
}

.diff-dropdown-arrow {
    font-size: 0.8rem;
    color: var(--gold);
    opacity: 0.75;
    margin-left: 4px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.p2-info-clickable:hover .diff-dropdown-arrow {
    opacity: 1;
    transform: translateY(1px);
}

/* Quick Difficulty Picker Modal */
.diff-modal-content {
    max-width: 320px;
    padding: 22px 20px;
}

.diff-picker-list {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-top: 10px;
}

.diff-picker-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 12px 18px;
    background: rgba(255, 255, 255, 0.06);
    border: 1.5px solid rgba(212, 175, 55, 0.3);
    color: var(--text-main);
    border-radius: 10px;
    font-size: 0.98rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.diff-picker-btn:hover {
    background: rgba(212, 175, 55, 0.2);
    border-color: var(--gold);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--gold-glow);
}

.diff-picker-btn.active {
    background: var(--gold);
    color: #1a1612;
    border-color: var(--gold);
    font-weight: 800;
}

.diff-picker-btn .diff-picker-check {
    font-size: 1rem;
    font-weight: 800;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.diff-picker-btn.active .diff-picker-check {
    opacity: 1;
}

/* Kinjung Pop Scoped Overrides */
body.theme-pop .p2-info-clickable:hover {
    background: rgba(35, 29, 50, 0.08);
}

body.theme-pop .diff-dropdown-arrow {
    color: #231d32;
    opacity: 0.8;
}

body.theme-pop .diff-picker-btn {
    background: #ffffff;
    border: 1.5px solid #231d32;
    color: #231d32;
    box-shadow: 0 2px 6px rgba(35, 29, 50, 0.08);
    border-radius: 10px;
}

body.theme-pop .diff-picker-btn:hover {
    background: #ffe175;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(35, 29, 50, 0.12);
}

body.theme-pop .diff-picker-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(35, 29, 50, 0.1);
}

body.theme-pop .diff-picker-btn.active {
    background: #ffe175;
    color: #231d32;
    border-color: #231d32;
    box-shadow: 0 2px 6px rgba(35, 29, 50, 0.12);
}

body.theme-pop .diff-picker-btn.active .diff-picker-check {
    color: #231d32;
}

/* Responsive adjustments for compact / short viewports (e.g. mobile Safari with toolbars) */
@media (max-height: 740px) {
    #app-container {
        gap: 4px;
        padding-top: max(4px, env(safe-area-inset-top));
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }
    .top-nav {
        padding: 4px 10px;
    }
    .player-bar {
        padding: 4px 10px;
    }
    .status-banner {
        font-size: 0.82rem;
        min-height: 1.2rem;
    }
    .action-btn {
        padding: 8px 18px;
        font-size: 0.88rem;
        min-width: 90px;
    }
    .bottom-controls {
        padding: 4px 0;
    }
}

@media (max-height: 620px) {
    #app-container {
        gap: 2px;
        padding-top: max(2px, env(safe-area-inset-top));
        padding-bottom: max(4px, env(safe-area-inset-bottom));
    }
    .top-nav {
        padding: 2px 8px;
    }
    .player-bar {
        padding: 2px 8px;
    }
    .player-name {
        font-size: 0.85rem;
    }
    .status-banner {
        font-size: 0.78rem;
        min-height: 1.1rem;
    }
    .action-btn {
        padding: 6px 14px;
        font-size: 0.82rem;
        min-width: 80px;
    }
    .bottom-controls {
        padding: 2px 0;
    }
}
