:root {
    --bg-wood: #deb887;
    --bg-wood-dark: #cd853f;
    --hole-color: #5d4037;
    --piece-shadow: rgba(0, 0, 0, 0.4);

    --color-circle: #e74c3c;
    --color-triangle: #3498db;
    --color-square: #2ecc71;
    --color-rhombus: #9b59b6;
    --color-pentagon: #f1c40f;
    --color-cross: #e67e22;
}

* {
    box-sizing: border-box;
    user-select: none;
    /* Prevent selection text while dragging */
}

body {
    margin: 0;
    padding: 0;
    font-family: 'M PLUS Rounded 1c', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #f5f5f5;
    background-image: radial-gradient(#ddd 1px, transparent 1px);
    background-size: 20px 20px;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 800px;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 10px;
    position: relative;
    width: 100%;
}

/* Settings Button */
#settings-btn {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    transition: transform 0.2s;
    padding: 5px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.5);
}

#settings-btn:hover {
    transform: translateY(-50%) rotate(45deg);
    background-color: rgba(255, 255, 255, 0.8);
}

h1 {
    color: #5d4037;
    font-size: 2.5rem;
    margin: 0 0 10px 0;
    text-shadow: 2px 2px 0px rgba(255, 255, 255, 0.5);
}

#board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 20px;
    background-color: var(--bg-wood);
    /* Simple wood texture using repeating linear gradient */
    background-image:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0px, transparent 2px, transparent 10px),
        linear-gradient(to bottom, var(--bg-wood), var(--bg-wood-dark));
    padding: 30px;
    border-radius: 20px;
    box-shadow:
        0 10px 20px rgba(0, 0, 0, 0.3),
        inset 0 2px 5px rgba(255, 255, 255, 0.3);
    border: 8px solid #8d6e63;
}

.hole {
    width: 120px;
    height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    /* Inset style to look like a cutout */

}

.hole svg {
    width: 100%;
    height: 100%;
    fill: var(--hole-color);
    filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.5)) inset;
    /* Inner shadow check logic below */
}

#tray {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    min-height: 140px;
    padding: 20px;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    border: 2px dashed #aaa;
    width: 100%;
}

.piece {
    width: 120px;
    height: 120px;
    cursor: grab;
    transition: transform 0.2s, filter 0.2s;
    /* 3D wooden piece effect */
    filter: drop-shadow(0 5px 0px rgba(0, 0, 0, 0.2));
    touch-action: none;
    /* Important for custom drag handling if needed */
}

.piece:active {
    cursor: grabbing;
    transform: scale(1.1);
    filter: drop-shadow(0 15px 10px rgba(0, 0, 0, 0.3));
    z-index: 100;
}

.piece.placed {
    cursor: default;
    filter: none;
    pointer-events: none;
}

/* Shape Colors - Default, updated by JS */
.piece[data-shape="circle"] svg {
    fill: var(--color-circle);
}

.piece[data-shape="triangle"] svg {
    fill: var(--color-triangle);
}

.piece[data-shape="square"] svg {
    fill: var(--color-square);
}

.piece[data-shape="rhombus"] svg {
    fill: var(--color-rhombus);
}

.piece[data-shape="pentagon"] svg {
    fill: var(--color-pentagon);
}

.piece[data-shape="cross"] svg {
    fill: var(--color-cross);
}

.piece svg {
    stroke: rgba(255, 255, 255, 0.4);
    stroke-width: 3px;
    width: 100%;
    height: 100%;
}

#reset-btn,
#play-again-btn {
    background-color: #27ae60;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 1.2rem;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 0 #219150;
    transition: transform 0.1s;
    font-family: inherit;
    margin-top: 10px;
}

#reset-btn:active,
#play-again-btn:active,
#save-settings:active,
#cancel-settings:active {
    transform: translateY(4px);
    box-shadow: none;
}

.hidden {
    display: none !important;
}

/* Animation for success */
@keyframes pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.pop-anim {
    animation: pop 0.3s ease-out;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-content {
    background-color: #fefefe;
    padding: 20px;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 500px;
    border: 5px solid #deb887;
}

.win-content {
    text-align: center;
    background-color: #fff8e1;
    border-color: #f1c40f;
}

.win-content h2 {
    color: #e67e22;
    font-size: 2rem;
}

.setting-group {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.setting-group h3 {
    margin-top: 0;
    color: #5d4037;
}

#shape-settings-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.shape-option {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f9f9f9;
    padding: 8px;
    border-radius: 8px;
}

.shape-option input[type="color"] {
    border: none;
    width: 30px;
    height: 30px;
    cursor: pointer;
    background: none;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

#save-settings {
    background-color: #2980b9;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 3px 0 #1c5980;
}

#cancel-settings {
    background-color: #ccc;
    color: #333;
    border: none;
    padding: 10px 20px;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 3px 0 #999;
}