:root {
    --bg-color: #f4e4bc;
    /* Parchment/Wood light */
    --board-line-color: #5d4037;
    --sow-color: #d32f2f;
    /* Red */
    --piglet-color: #ffffff;
    /* White/Cream */
    --piglet-border: #3e2723;
    --highlight-color: rgba(255, 215, 0, 0.6);
    --valid-move-color: rgba(76, 175, 80, 0.5);
    --text-color: #3e2723;
    --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    overflow-x: hidden;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 600px;
    padding: 24px 20px 32px;
    box-sizing: border-box;
}

h1 {
    font-size: 2rem;
    margin: 0 0 16px;
    letter-spacing: 2px;
}

.game-info {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px 16px;
    width: 100%;
    margin-bottom: 12px;
    font-weight: bold;
    font-size: 1.05rem;
    line-height: 1.6;
}

.highlight {
    color: var(--sow-color);
}

.piece-legend {
    display: flex;
    gap: 24px;
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.piece-legend > span {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.legend-piece {
    width: 14px;
    height: 14px;
    border-radius: 50%;
}

.legend-sow {
    background-color: var(--sow-color);
    border: 2px solid white;
}

.legend-piglet {
    background-color: var(--piglet-color);
    border: 2px solid var(--piglet-border);
}

.board {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    /* Square board */
    max-width: 500px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

#board-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to nodes */
}

.board-line {
    stroke: var(--board-line-color);
    stroke-width: 0.1;
    /* Relative to viewBox coords */
    stroke-linecap: round;
}

#nodes-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.node {
    position: absolute;
    width: 8%;
    /* Relative size */
    height: 8%;
    transform: translate(-50%, -50%);
    /* Center on coordinate */
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
}

/* Invisible hit area for empty nodes, visible pieces */
.node.empty {
    background-color: transparent;
}

.node.empty.valid-move::after {
    content: '';
    position: absolute;
    width: 50%;
    height: 50%;
    background-color: var(--valid-move-color);
    border-radius: 50%;
    top: 25%;
    left: 25%;
    animation: pulse 1.5s infinite;
}

.node.piece {
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.node.sow {
    background-color: var(--sow-color);
    border: 2px solid white;
}

.node.piglet {
    background-color: var(--piglet-color);
    border: 2px solid var(--piglet-border);
}

.node.selected {
    box-shadow: 0 0 0 4px var(--highlight-color);
    z-index: 20;
}

.controls {
    width: 100%;
    margin-top: 16px;
    text-align: center;
}

#message-area {
    min-height: 1.6em;
    margin-top: 12px;
    line-height: 1.6;
}

.game-rules {
    width: 100%;
    margin-top: 24px;
    padding: 20px;
    box-sizing: border-box;
    border: 1px solid rgba(93, 64, 55, 0.2);
    border-radius: 10px;
    background-color: rgba(255, 255, 255, 0.35);
    font-size: 0.95rem;
    line-height: 1.8;
}

.game-rules h2 {
    margin: 0 0 12px;
    font-size: 1.25rem;
}

.game-rules p {
    margin: 0;
}

.game-rules ol {
    margin: 12px 0;
    padding-left: 1.5em;
}

.game-rules li + li {
    margin-top: 10px;
}

.rules-tip {
    padding-top: 12px;
    border-top: 1px solid rgba(93, 64, 55, 0.2);
}

.btn {
    padding: 10px 20px;
    font-size: 1rem;
    font-family: inherit;
    background-color: var(--text-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.4;
    }

    100% {
        transform: scale(1);
        opacity: 0.8;
    }
}

@media (max-width: 500px) {
    h1 {
        font-size: 1.5rem;
    }

    .game-info {
        font-size: 1rem;
    }

    .game-rules {
        padding: 16px;
    }
}
