* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

.start-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.menu-container {
    background: #1a1a2e;
    padding: 50px;
    border-radius: 30px;
    max-width: 600px;
    width: 100%;
    margin: 20px;
    border: 1px solid #333;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
}

.menu-container h1 {
    color: #e0d5c1;
    font-size: 3em;
    text-align: center;
    margin-bottom: 5px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.menu-container .subtitle {
    color: #8a7aaa;
    text-align: center;
    font-size: 1.1em;
    margin-bottom: 30px;
}

.opponent-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.opponent-btn {
    background: #252545;
    border: 2px solid #3a3a5c;
    border-radius: 12px;
    padding: 16px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 15px;
    text-align: left;
}

.opponent-btn:hover {
    background: #2f2f5a;
    border-color: #6a5a8a;
    transform: translateX(5px);
}

.opponent-btn:active {
    transform: scale(0.97);
}

.opponent-btn .icon {
    font-size: 2em;
    flex-shrink: 0;
}

.opponent-btn .label {
    color: #e0d5c1;
    font-size: 1.1em;
    font-weight: bold;
}

.opponent-btn .description {
    color: #8a7aaa;
    font-size: 0.85em;
    display: block;
    margin-top: 2px;
}

.container {
    background: #1a1a2e;
    padding: 20px 25px 25px 25px;
    border-radius: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    text-align: center;
    max-width: 900px;
    width: 100%;
    border: 1px solid #333;
    display: none;
    max-height: 98vh;
    overflow-y: auto;
    margin: auto;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.container.active {
    display: block;
}

.container::-webkit-scrollbar {
    width: 6px;
}

.container::-webkit-scrollbar-track {
    background: #1a1a2e;
}

.container::-webkit-scrollbar-thumb {
    background: #3a3a5c;
    border-radius: 3px;
}

h1 {
    color: #e0d5c1;
    margin-bottom: 10px;
    font-size: 1.6em;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.menu {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.back-btn {
    padding: 5px 14px;
    background: #3a3a5c;
    color: #e0d5c1;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    transition: background 0.3s;
}

.back-btn:hover {
    background: #4a4a7a;
}

.flip-btn {
    padding: 5px 14px;
    background: #2a4a6a;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    transition: background 0.3s;
}

.flip-btn:hover {
    background: #3a6a8a;
}

#resetBtn {
    padding: 5px 14px;
    background: #8b2f3a;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    transition: background 0.3s;
}

#resetBtn:hover {
    background: #6b1f2a;
}

.game-info {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 8px;
    padding: 6px 16px;
    background: #252545;
    border-radius: 8px;
    border: 1px solid #3a3a5c;
}

#status {
    font-size: 1em;
    font-weight: bold;
    color: #e0d5c1;
}

.arrow-left {
    display: inline-block;
    font-size: 1em;
    font-weight: 900;
    color: #3498db;
    text-shadow: 
        0 1px 0 #2980b9,
        0 2px 0 #2471a3,
        0 3px 0 #1f618d,
        0 4px 0 #1a5276,
        0 5px 0 #154360,
        0 6px 0 #0e2f4a,
        0 7px 10px rgba(0, 0, 0, 0.6);
    animation: arrowPulseBlue 2s ease-in-out infinite;
    padding: 0 8px;
    transform: scale(1);
    transition: all 0.3s ease;
}

@keyframes arrowPulseBlue {
    0%, 100% {
        transform: scale(1);
        text-shadow: 
            0 1px 0 #2980b9,
            0 2px 0 #2471a3,
            0 3px 0 #1f618d,
            0 4px 0 #1a5276,
            0 5px 0 #154360,
            0 6px 0 #0e2f4a,
            0 7px 10px rgba(0, 0, 0, 0.6);
    }
    50% {
        transform: scale(1.15);
        text-shadow: 
            0 1px 0 #5dade2,
            0 2px 0 #3498db,
            0 3px 0 #2980b9,
            0 4px 0 #2471a3,
            0 5px 0 #1f618d,
            0 6px 0 #1a5276,
            0 7px 15px rgba(52, 152, 219, 0.4),
            0 10px 30px rgba(52, 152, 219, 0.2);
    }
}

.arrow-right {
    display: inline-block;
    font-size: 1em;
    font-weight: 900;
    color: #e74c3c;
    text-shadow: 
        0 1px 0 #c0392b,
        0 2px 0 #a93226,
        0 3px 0 #922b21,
        0 4px 0 #7b241c,
        0 5px 0 #641e16,
        0 6px 0 #4a1510,
        0 7px 10px rgba(0, 0, 0, 0.6);
    animation: arrowPulseRed 2s ease-in-out infinite;
    padding: 0 8px;
    transform: scale(1);
    transition: all 0.3s ease;
    animation-delay: 0.3s;
}

@keyframes arrowPulseRed {
    0%, 100% {
        transform: scale(1);
        text-shadow: 
            0 1px 0 #c0392b,
            0 2px 0 #a93226,
            0 3px 0 #922b21,
            0 4px 0 #7b241c,
            0 5px 0 #641e16,
            0 6px 0 #4a1510,
            0 7px 10px rgba(0, 0, 0, 0.6);
    }
    50% {
        transform: scale(1.15);
        text-shadow: 
            0 1px 0 #ec7063,
            0 2px 0 #e74c3c,
            0 3px 0 #c0392b,
            0 4px 0 #a93226,
            0 5px 0 #922b21,
            0 6px 0 #7b241c,
            0 7px 15px rgba(231, 76, 60, 0.4),
            0 10px 30px rgba(231, 76, 60, 0.2);
    }
}

h1:hover .arrow-left {
    animation: arrowLeftHover 0.5s ease forwards;
}

h1:hover .arrow-right {
    animation: arrowRightHover 0.5s ease forwards;
}

@keyframes arrowLeftHover {
    0% { transform: translateX(0) scale(1); }
    50% { transform: translateX(-10px) scale(1.1); }
    100% { transform: translateX(-5px) scale(1.05); }
}

@keyframes arrowRightHover {
    0% { transform: translateX(0) scale(1); }
    50% { transform: translateX(10px) scale(1.1); }
    100% { transform: translateX(5px) scale(1.05); }
}

.board-wrapper {
    display: inline-block;
    padding: 20px 10px 10px 20px;
    position: relative;
}

#board {
    display: grid;
    grid-template-columns: repeat(8, 72px);
    grid-template-rows: repeat(8, 72px);
    border: 3px solid #2a2a4a;
    border-radius: 4px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
    width: fit-content;
    margin: 0 auto;
}

.square.light.col-left {
    background: #f0d9b5 !important;
}

.square.dark.col-left {
    background: #b58863 !important;
}

.square.light.col-right {
    background: #dcc4a0 !important;
}

.square.dark.col-right {
    background: #9a7050 !important;
}

.rank-labels {
    display: grid;
    grid-template-rows: repeat(8, 72px);
    position: absolute;
    left: 2px;
    top: 20px;
}

.rank-labels span {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: #8a7aaa;
    font-weight: bold;
    font-family: 'Arial', sans-serif;
    padding-right: 6px;
}

.square {
    width: 72px;
    height: 72px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 48px;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s, transform 0.2s;
    position: relative;
}

.square.selected {
    background: #6a9a6a !important;
}

.square.valid-move {
    background: #6a9a6a !important;
    opacity: 0.5;
}

.square.last-move-from {
    background: #3498db !important;
    box-shadow: inset 0 0 20px rgba(52, 152, 219, 0.4);
}

.square.last-move-to {
    background: #3498db !important;
    box-shadow: inset 0 0 20px rgba(52, 152, 219, 0.4);
}

.square.dark.last-move-from,
.square.dark.last-move-to {
    background: #2980b9 !important;
}

.square.light.last-move-from,
.square.light.last-move-to {
    background: #5dade2 !important;
}

.square.in-check {
    background: #e74c3c !important;
    animation: checkPulse 0.5s ease-in-out infinite;
    box-shadow: inset 0 0 40px rgba(231, 76, 60, 0.6), 0 0 30px rgba(231, 76, 60, 0.3);
}

@keyframes checkPulse {
    0%, 100% { 
        opacity: 1;
        transform: scale(1);
        background: #e74c3c;
        box-shadow: inset 0 0 40px rgba(231, 76, 60, 0.6);
    }
    50% { 
        opacity: 0.7;
        transform: scale(0.95);
        background: #c0392b;
        box-shadow: inset 0 0 60px rgba(231, 76, 60, 0.8);
    }
}

.square.ai-thinking {
    animation: pulseOnce 0.6s ease-out forwards;
}

@keyframes pulseOnce {
    0% { 
        transform: scale(1);
        background: #9b59b6;
        box-shadow: inset 0 0 20px rgba(155, 89, 182, 0.2);
    }
    30% { 
        transform: scale(0.97);
        background: #8e44ad;
        box-shadow: inset 0 0 60px rgba(155, 89, 182, 0.6);
    }
    100% { 
        transform: scale(1);
        background: transparent !important;
        box-shadow: none !important;
    }
}

.piece.white-piece {
    color: #ffffff !important;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.3), 0 2px 4px rgba(0, 0, 0, 0.3);
}

.piece.black-piece {
    color: #1a1a1a !important;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.3);
}

.square .square-label {
    position: absolute;
    font-size: 24px;
    font-weight: 900;
    bottom: 0px;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    font-family: 'Arial', sans-serif;
    user-select: none;
    text-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
    opacity: 0.95;
    letter-spacing: 0;
    line-height: 1;
}

.square .square-label.plus-label {
    color: #2196F3 !important;
    text-shadow: 0 0 30px rgba(33, 150, 243, 0.5), 0 0 60px rgba(33, 150, 243, 0.2);
}

.square .square-label.minus-label {
    color: #ff1744 !important;
    text-shadow: 0 0 30px rgba(255, 23, 68, 0.5), 0 0 60px rgba(255, 23, 68, 0.2);
}

.square.light .square-label {
    text-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.square.dark .square-label {
    text-shadow: 0 0 20px rgba(0, 0, 0, 0.9);
}

.piece {
    pointer-events: none;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
    font-size: 48px;
}

.axis-labels {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 6;
    font-size: 12px;
    font-weight: bold;
    font-family: 'Arial', sans-serif;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.axis-label-left {
    position: absolute;
    top: 50%;
    left: -40px;
    transform: translateY(-50%);
    color: rgba(0, 0, 0, 0.5);
    font-size: 13px;
    font-weight: bold;
    letter-spacing: 0.5px;
}

.axis-label-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(0, 0, 0, 0.6);
    font-size: 15px;
    font-weight: bold;
}

.axis-label-right {
    position: absolute;
    top: 50%;
    right: -40px;
    transform: translateY(-50%);
    color: rgba(0, 0, 0, 0.5);
    font-size: 13px;
    font-weight: bold;
    letter-spacing: 0.5px;
}

.axis-label-top {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(0, 0, 0, 0.4);
    font-size: 14px;
    font-weight: bold;
}

.axis-label-bottom {
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(0, 0, 0, 0.4);
    font-size: 14px;
    font-weight: bold;
}

.move-history {
    margin-top: 10px;
    padding: 6px 10px;
    background: #1f1f3a;
    border-radius: 8px;
    max-height: 80px;
    overflow-y: auto;
    border: 1px solid #3a3a5c;
}

.move-history h3 {
    color: #e0d5c1;
    font-size: 0.8em;
    margin-bottom: 4px;
}

#moveList {
    font-size: 0.8em;
    color: #b0a5a0;
    line-height: 1.4;
    text-align: left;
}

#moveList div {
    padding: 1px 6px;
    border-bottom: 1px solid #2a2a4a;
}

#moveList div:last-child {
    border-bottom: none;
}

.thinking-bar {
    width: 100%;
    height: 4px;
    background: #2a2a4a;
    border-radius: 2px;
    margin-top: 4px;
    overflow: hidden;
    display: none;
}

.thinking-bar.active {
    display: block;
}

.thinking-bar .progress {
    height: 100%;
    background: linear-gradient(90deg, #9b59b6, #8e44ad, #9b59b6);
    background-size: 200% 100%;
    width: 0%;
    border-radius: 2px;
}

@keyframes progressAnimation {
    0% { 
        width: 0%;
        background-position: 0% 50%;
    }
    100% { 
        width: 100%;
        background-position: 200% 50%;
    }
}

@media (max-width: 850px) {
    .container { padding: 15px; }
    #board { grid-template-columns: repeat(8, 55px); grid-template-rows: repeat(8, 55px); }
    .square { width: 55px; height: 55px; font-size: 36px; }
    .piece { font-size: 36px; }
    .square .square-label { font-size: 18px; bottom: 0px; }
    .rank-labels { grid-template-rows: repeat(8, 55px); }
    .rank-labels span { font-size: 9px; }
    .board-wrapper { padding: 18px 6px 6px 18px; }
    .axis-label-left { left: -34px; font-size: 11px; }
    .axis-label-right { right: -34px; font-size: 11px; }
    .axis-label-center { font-size: 13px; }
    .axis-label-top { font-size: 12px; top: -15px; }
    .axis-label-bottom { font-size: 12px; bottom: -15px; }
    h1 { font-size: 1.3em; margin-bottom: 8px; }
    #status { font-size: 0.9em; }
}

@media (max-width: 600px) {
    #board { grid-template-columns: repeat(8, 42px); grid-template-rows: repeat(8, 42px); }
    .square { width: 42px; height: 42px; font-size: 28px; }
    .piece { font-size: 28px; }
    .square .square-label { font-size: 14px; bottom: 0px; }
    .rank-labels { grid-template-rows: repeat(8, 42px); }
    .rank-labels span { font-size: 8px; }
    .board-wrapper { padding: 16px 4px 4px 16px; }
    .axis-label-left { left: -28px; font-size: 9px; }
    .axis-label-right { right: -28px; font-size: 9px; }
    .axis-label-center { font-size: 11px; }
    .axis-label-top { font-size: 10px; top: -12px; }
    .axis-label-bottom { font-size: 10px; bottom: -12px; }
    .container { padding: 10px; }
    h1 { font-size: 1.1em; margin-bottom: 6px; }
}

@media (max-width: 420px) {
    #board { grid-template-columns: repeat(8, 34px); grid-template-rows: repeat(8, 34px); }
    .square { width: 34px; height: 34px; font-size: 22px; }
    .piece { font-size: 22px; }
    .square .square-label { font-size: 11px; bottom: 0px; }
    .rank-labels { grid-template-rows: repeat(8, 34px); }
    .rank-labels span { font-size: 7px; padding-right: 3px; }
    .board-wrapper { padding: 14px 2px 2px 14px; }
    .axis-label-left { left: -22px; font-size: 8px; }
    .axis-label-right { right: -22px; font-size: 8px; }
    .axis-label-center { font-size: 9px; }
    .axis-label-top { font-size: 8px; top: -10px; }
    .axis-label-bottom { font-size: 8px; bottom: -10px; }
}