:root {
    --primary: #4f46e5;
    --primary-light: #e0e7ff;
    --secondary: #ec4899;
    --bg-main: #f8fafc;
    --card-bg: #ffffff;
    --text-dark: #1e293b;
    --text-muted: #64748b;
    --board-white: #f1f5f9;
    --board-black: #cbd5e1;
    --piece-white: #ffffff;
    --piece-black: #1e293b;
    --accent: #f59e0b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-dark);
    overflow-x: hidden;
    min-height: 100vh;
    background: radial-gradient(circle at top right, #f1f5f9, #ffffff);
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    min-height: 100vh;
}

header {
    text-align: center;
    animation: fadeInDown 0.8s ease-out;
}

header h1 {
    font-size: 3.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--primary);
}

header p {
    color: var(--text-muted);
    font-size: 1.2rem;
    max-width: 600px;
    margin: 0 auto;
}

.strategy-selector {
    margin-top: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.25rem 0.25rem 0.6rem;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
}

.strategy-selector::-webkit-scrollbar {
    height: 8px;
}

.strategy-selector::-webkit-scrollbar-track {
    background: #eef2ff;
    border-radius: 999px;
}

.strategy-selector::-webkit-scrollbar-thumb {
    background: #c7d2fe;
    border-radius: 999px;
}

.strategy-chip {
    padding: 0.6rem 1.5rem;
    border: 2px solid var(--primary-light);
    background: white;
    color: var(--primary);
    cursor: pointer;
    border-radius: 50px;
    font-weight: 600;
    transition: all 0.2s;
    white-space: nowrap;
    flex: 0 0 auto;
    scroll-snap-align: start;
}

.strategy-chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.main-tabs {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

.tab-btn {
    padding: 1rem 2.5rem;
    border: none;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s;
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 10px 20px rgba(79, 70, 229, 0.2);
    transform: translateY(-2px);
}

.hidden {
    display: none !important;
}

.view-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 2rem;
    flex: 1;
}

main {
    animation: fadeIn 0.5s ease-out;
}

#view-container {
    background: white;
    border-radius: 32px;
    padding: 2rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
}

.board-view {
    display: none;
    width: 100%;
    height: 100%;
}

.board-view.active {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: zoomIn 0.5s ease-out;
}

#three-container {
    width: 100%;
    height: 100%;
}

#view-container {
    position: relative;
}

/* 2D Board Styling */
.chess-board {
    width: 600px;
    height: 600px;
    max-width: 90vw;
    aspect-ratio: 1 / 1;
    background: var(--board-black);
    border: 12px solid #334155;
    border-radius: 12px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    touch-action: none;
}

.prestart-note {
    background: #ecfeff;
    color: #0f766e;
    border: 1px solid #99f6e4;
    border-radius: 12px;
    padding: 0.75rem 1rem;
    font-weight: 600;
}

.square {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    line-height: 1;
    transition: background 0.3s;
    user-select: none;
    position: relative;
}

.square.white {
    background: var(--board-white);
}

.square.black {
    background: var(--board-black);
}

.piece {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.5rem;
    font-family: 'Noto Sans Symbols 2', 'Segoe UI Symbol', 'Apple Symbols', sans-serif;
    font-weight: 400;
    cursor: grab;
    transition: transform 0.2s;
    user-select: none;
    line-height: 1;
    -webkit-user-drag: none;
}

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

.piece.drag-ghost {
    position: fixed;
    left: 0;
    top: 0;
    transform: translate(-50%, -50%);
    z-index: 9999;
    pointer-events: none;
    cursor: grabbing;
}

.hint {
    position: absolute;
    width: 16px;
    height: 16px;
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: 50%;
    pointer-events: none;
    z-index: 10;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.square.black .hint {
    background-color: rgba(0, 0, 0, 0.25);
}

.square.capture-hint {
    box-shadow: inset 0 0 0 4px rgba(239, 68, 68, 0.4);
}

/* Controls Styling */
.controls {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.strategy-info {
    background: white;
    padding: 2.5rem;
    border-radius: 32px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.05);
}

.strategy-info h2 {
    margin-bottom: 1rem;
    color: var(--text-dark);
    font-size: 1.8rem;
}

.strategy-info p {
    line-height: 1.6;
    color: var(--text-muted);
    font-size: 1.1rem;
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

button.primary-btn {
    grid-column: span 2;
    background: var(--primary);
    color: white;
    padding: 1.2rem;
    border: none;
    border-radius: 20px;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
}

button.primary-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(79, 70, 229, 0.3);
}

button.secondary-btn {
    background: var(--primary-light);
    color: var(--primary);
    padding: 1.2rem;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

button.secondary-btn:hover {
    background: #c7d2fe;
}

footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.difficulty-control {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.difficulty-control input {
    width: 100%;
    accent-color: var(--primary);
}

#level-val {
    font-weight: 700;
    color: var(--primary);
    text-align: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@media (max-width: 900px) {
    .view-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    #view-container {
        padding: 1.25rem;
    }

    .controls {
        gap: 1rem;
    }

    .strategy-info {
        padding: 1.5rem;
        border-radius: 24px;
    }

    .strategy-info h2 {
        font-size: 1.5rem;
    }

    .strategy-info p {
        font-size: 1rem;
    }

    .chess-board {
        width: min(86vw, 560px);
        height: min(86vw, 560px);
        border-width: 10px;
    }

    .piece {
        font-size: clamp(2rem, 7vw, 3.2rem);
    }

    .action-buttons {
        grid-template-columns: 1fr;
    }

    button.primary-btn {
        grid-column: auto;
    }
}

@media (max-width: 700px) {
    #app {
        padding: 1rem;
        gap: 1.25rem;
    }

    header h1 {
        font-size: 2.25rem;
    }

    header p {
        font-size: 1rem;
    }

    .main-tabs {
        flex-direction: column;
        align-items: stretch;
    }

    .tab-btn {
        width: 100%;
        padding: 0.85rem 1rem;
        font-size: 1rem;
    }

    #view-container {
        padding: 0.75rem;
        border-radius: 20px;
    }

    .chess-board {
        width: min(94vw, 520px);
        height: min(94vw, 520px);
        border-width: 8px;
    }

    .strategy-chip {
        padding: 0.5rem 0.9rem;
        font-size: 0.92rem;
    }

    .strategy-selector {
        gap: 0.5rem;
        padding-bottom: 0.4rem;
    }

    button.primary-btn,
    button.secondary-btn {
        padding: 0.95rem;
        border-radius: 14px;
        font-size: 1rem;
    }

    .prestart-note {
        font-size: 0.95rem;
        line-height: 1.45;
    }
}

@media (max-width: 420px) {
    .chess-board {
        width: 100%;
        height: auto;
        aspect-ratio: 1 / 1;
    }

    .piece {
        font-size: clamp(1.6rem, 9vw, 2.5rem);
    }
}
