/* General Page Structure */
body {
    background:
        radial-gradient(circle at 10% 12%, rgba(244, 211, 94, 0.22), transparent 38%),
        radial-gradient(circle at 90% 85%, rgba(29, 120, 116, 0.24), transparent 36%),
        linear-gradient(145deg, #f7fff7, #e7f5f2);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    color: #343a40;
    line-height: 1.6;
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 3rem 2rem;
}

/* Game Section */
#game-section {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    padding: 2.5rem;
    margin-bottom: 3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.go-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.board-size-controls {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
}

.board-size-label {
    font-size: 1.1rem;
    font-weight: bold;
    color: #333;
}

.btn-size {
    border: 1px solid #8ecae6;
    border-radius: 10px;
    padding: 0.55rem 0.9rem;
    font-size: 0.95rem;
    font-weight: 600;
    background: #ffffff;
    color: #143642;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-size:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(13, 59, 102, 0.24);
}

.btn-size.selected {
    border: none;
    background: linear-gradient(135deg, #1d7874, #0d3b66);
    color: #ffffff;
    font-weight: 700;
}

.game-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin: 10px 0;
}

.player-turn {
    font-size: 1.2rem;
    font-weight: 500;
    color: #343a40;
}

.scores {
    display: flex;
    gap: 1rem;
}

.black-score, .white-score {
    font-size: 1rem;
    font-weight: 500;
}


:root {
    --go-cell-size: 60px;
    --go-border: 15px;
    --go-line: 2px;
    --go-board-wood-dark: #8e582c;
    --go-board-wood-mid: #ba7a41;
    --go-board-wood-light: #dca86a;
    --go-grid-color: #4a2a14;
    --go-frame: #63370e;
    --go-dragon-ornament: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 120'%3E%3Cpath d='M13 88 C28 67 45 67 54 52 C61 40 58 27 44 25 C55 19 70 21 78 31 C85 39 84 51 74 58 C95 58 106 73 98 91 C88 84 77 83 67 89 C57 95 45 99 34 95 C41 89 46 82 44 73 C36 78 26 85 13 88 Z' fill='none' stroke='%23643712' stroke-width='6' stroke-linecap='round' stroke-linejoin='round'/%3E%3Ccircle cx='78' cy='34' r='4' fill='%23643712'/%3E%3C/svg%3E");
}

#go-board {
    display: grid;
    grid-template-columns: repeat(19, var(--go-cell-size));
    grid-template-rows: repeat(19, var(--go-cell-size));
    background:
        radial-gradient(circle at 18% 14%, rgba(255, 238, 198, 0.42), transparent 34%),
        radial-gradient(circle at 82% 88%, rgba(120, 74, 33, 0.16), transparent 44%),
        repeating-linear-gradient(
            6deg,
            rgba(255, 255, 255, 0.05) 0,
            rgba(255, 255, 255, 0.05) 8px,
            rgba(89, 52, 21, 0.08) 8px,
            rgba(89, 52, 21, 0.08) 16px
        ),
        linear-gradient(145deg, var(--go-board-wood-light), var(--go-board-wood-mid) 55%, var(--go-board-wood-dark));
    border: var(--go-border) solid var(--go-frame);
    border-radius: 12px;
    padding: 0; /* No padding so lines touch border */
    box-shadow:
        0 14px 30px rgba(45, 26, 10, 0.34),
        inset 0 0 0 2px rgba(245, 220, 170, 0.28),
        inset 0 -10px 14px rgba(74, 42, 18, 0.24);
    position: relative;
    isolation: isolate;
    width: fit-content;
    max-width: 96vw;
    max-height: 82vh;
    box-sizing: border-box;
    overflow: visible;
}

#go-board::before {
    content: '';
    position: absolute;
    inset: calc(var(--go-border) * -1.12);
    border-radius: 18px;
    background:
        var(--go-dragon-ornament) top 7px left 8px / 78px 78px no-repeat,
        var(--go-dragon-ornament) top 7px right 8px / 78px 78px no-repeat,
        var(--go-dragon-ornament) bottom 7px left 8px / 78px 78px no-repeat,
        var(--go-dragon-ornament) bottom 7px right 8px / 78px 78px no-repeat,
        linear-gradient(135deg, rgba(125, 72, 30, 0.34), rgba(89, 49, 20, 0.38));
    border: 2px solid rgba(108, 58, 24, 0.56);
    box-shadow:
        0 10px 22px rgba(43, 24, 9, 0.3),
        inset 0 0 0 1px rgba(227, 187, 132, 0.22);
    z-index: -2;
    pointer-events: none;
}

#go-board::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 9px;
    background:
        linear-gradient(115deg, rgba(255, 244, 211, 0.24) 8%, rgba(255, 244, 211, 0) 34%),
        radial-gradient(circle at 85% 14%, rgba(255, 224, 176, 0.2), transparent 42%),
        radial-gradient(circle at 18% 84%, rgba(85, 49, 19, 0.14), transparent 48%);
    z-index: 0;
    pointer-events: none;
}

.go-intersection {
    width: var(--go-cell-size);
    height: var(--go-cell-size);
    position: relative;
    z-index: 1;
    cursor: pointer;
    touch-action: manipulation;
}

.go-intersection::before, .go-intersection::after {
    content: '';
    position: absolute;
    background-color: var(--go-grid-color);
    z-index: 0;
    opacity: 0.84;
}

.go-intersection::before { /* Horizontal line */
    left: 0;
    right: 0;
    top: 50%;
    height: var(--go-line);
    transform: translateY(calc(-0.5 * var(--go-line)));
}

.go-intersection::after { /* Vertical line */
    top: 0;
    bottom: 0;
    left: 50%;
    width: var(--go-line);
    transform: translateX(calc(-0.5 * var(--go-line)));
}

.go-hoshi {
    position: absolute;
    left: 50%;
    top: 50%;
    width: clamp(4px, 15%, 7px);
    height: clamp(4px, 15%, 7px);
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, #62381b, #2a1408 78%);
    z-index: 1;
    opacity: 0.92;
}

.go-stone {
    border-radius: 50%;
    position: absolute;
    z-index: 2;
    overflow: hidden;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: calc(var(--go-cell-size) - 10px);
    height: calc(var(--go-cell-size) - 10px);
    box-shadow: 0 5px 9px rgba(0, 0, 0, 0.42);
}

.go-stone::before,
.go-stone::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}

.go-stone.black {
    background:
        radial-gradient(circle at 30% 26%, rgba(181, 190, 202, 0.35) 0 9%, transparent 21%),
        radial-gradient(circle at 67% 76%, rgba(3, 6, 14, 0.88), rgba(19, 24, 31, 0.98) 54%, #06090f 100%);
    box-shadow:
        inset 0 -6px 8px rgba(0, 0, 0, 0.45),
        2px 3px 7px rgba(0, 0, 0, 0.5);
    border: none;
}

.go-stone.black::before {
    width: 44%;
    height: 32%;
    left: 16%;
    top: 12%;
    background: radial-gradient(circle at 30% 28%, rgba(239, 245, 255, 0.44), rgba(239, 245, 255, 0));
}

.go-stone.black::after {
    inset: 13%;
    border: 1px solid rgba(188, 197, 211, 0.18);
}

.go-stone.white {
    background:
        radial-gradient(circle at 29% 24%, rgba(255, 255, 255, 0.95) 0 12%, rgba(241, 241, 239, 0.9) 34%, rgba(223, 221, 214, 0.95) 74%, #cbc8bf 100%);
    box-shadow:
        inset 0 -6px 7px rgba(142, 136, 124, 0.3),
        2px 3px 7px rgba(0, 0, 0, 0.28);
    border: none;
}

.go-stone.white::before {
    width: 50%;
    height: 36%;
    left: 13%;
    top: 9%;
    background: radial-gradient(circle at 30% 26%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0));
}

.go-stone.white::after {
    inset: 11%;
    border: 1px solid rgba(255, 255, 255, 0.56);
}

.go-stone.white.last-move {
    box-shadow: none;
    animation: goldenPulse 1.6s ease-in-out infinite;
}

@keyframes goldenPulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 204, 0, 0); }
    50% { box-shadow: 0 0 18px 8px rgba(255, 204, 0, 0.8); }
    100% { box-shadow: 0 0 0 0 rgba(255, 204, 0, 0); }
}

.captured-info {
    display: flex;
    justify-content: space-between;
    width: 600px; /* Approximately match board width */
    margin: 10px 0;
    font-weight: bold;
    color: #333;
    font-size: 1.1rem;
}

.go-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
}

.primary-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    width: 100%;
}

#pass, #new-game {
    border: none;
    background: linear-gradient(135deg, #1d7874, #0d3b66);
    color: #ffffff;
    padding: 0.55rem 0.9rem;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#pass:hover, #new-game:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(13, 59, 102, 0.24);
}

#message {
    font-size: 1.1rem;
    font-weight: 500;
    min-height: 24px;
}

/* Internal Navigation / More Games */
.internal-nav {
    text-align: center;
    margin-bottom: 3rem;
}

.internal-nav h3 {
    font-size: 2.5rem;
    font-weight: 600;
    color: #003366;
    margin-top: 0;
    margin-bottom: 2rem;
}

.game-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
}

.game-btn {
    background: #f8f9fa;
    border-radius: 10px;
    text-align: center;
    padding: 1.5rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid #e9ecef;
    color: #343a40;
    text-decoration: none;
}

.game-btn:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
}

.game-btn img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.game-btn span {
    font-size: 1.3rem;
    font-weight: 600;
}

/* Info Sections & Cards */
.info-section {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    padding: 2.5rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 3rem;
}

.info-card.full-width {
    grid-column: 1 / -1;
}

.info-card h2 {
    font-size: 2rem;
    font-weight: 600;
    color: #003366;
    margin-top: 0;
    margin-bottom: 1.5rem;
}

.info-card p, .info-card li {
    color: #343a40;
}

.info-card ul, .info-card ol {
    padding-left: 20px;
}

@media (max-width: 1100px) {
    :root {
        --go-cell-size: 44px;
        --go-border: 13px;
        --go-line: 2px;
    }
}

/* Responsive Design */
@media (max-width: 992px) {
    .info-section {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    main {
        padding: 2rem 1rem;
    }
    #game-section, .info-section {
        padding: 2rem;
    }
    .internal-nav h3, .info-card h2 {
        font-size: 2rem;
    }
    :root {
        --go-cell-size: 26px;
        --go-border: 10px;
        --go-line: 1.6px;
    }
}

@media (max-width: 620px) {
    #game-section {
        padding: 1.5rem;
    }
    #go-board {
        max-width: 92vw;
        border-width: 12px;
    }
    #go-board::before {
        background-size: 60px 60px, 60px 60px, 60px 60px, 60px 60px, auto;
    }
    .captured-info {
        width: 100%;
        flex-direction: column;
        align-items: center;
        gap: 0.4rem;
        text-align: center;
    }
    .primary-controls, .board-size-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
    :root {
        --go-cell-size: 20px;
        --go-border: 10px;
        --go-line: 1.4px;
    }
    .board-size-controls {
        row-gap: 0.5rem;
    }
    .btn-size,
    #pass,
    #new-game {
        padding: 0.65rem 1.1rem;
    }
}

@media (orientation: portrait) and (max-width: 540px) {
    #game-section {
        padding: 1.25rem;
    }
    #go-board {
        max-width: 94vw;
    }
    :root {
        --go-cell-size: clamp(17px, 4.4vw, 22px);
        --go-border: 10px;
        --go-line: 1.4px;
    }
    .captured-info {
        width: 100%;
        flex-direction: column;
        gap: 0.4rem;
        text-align: center;
        align-items: center;
    }
    .primary-controls,
    .board-size-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
}

@media (orientation: portrait) and (max-width: 430px) {
    #go-board {
        width: calc(min(100vw, 100vh) - 2 * var(--go-border));
        height: calc(min(100vw, 100vh) - 2 * var(--go-border));
        max-width: none;
        max-height: none;
        grid-template-columns: repeat(19, 1fr);
        grid-template-rows: repeat(19, 1fr);
    }
    #go-board::before {
        background-size: 50px 50px, 50px 50px, 50px 50px, 50px 50px, auto;
    }
    .go-intersection {
        width: 100%;
        height: 100%;
    }
    .go-stone {
        width: calc(100% - 10px);
        height: calc(100% - 10px);
    }
    :root {
        --go-cell-size: 16px; /* Not used, but keep */
        --go-border: 8px;
        --go-line: 1.4px;
    }
    .captured-info {
        width: 100%;
        flex-direction: column;
        gap: 0.35rem;
        text-align: center;
        align-items: center;
    }
}

@media (orientation: landscape) and (max-height: 520px) {
    #go-board {
        width: calc(min(100vw, 100vh) - 2 * var(--go-border));
        height: calc(min(100vw, 100vh) - 2 * var(--go-border));
        max-width: none;
        max-height: none;
        grid-template-columns: repeat(19, 1fr);
        grid-template-rows: repeat(19, 1fr);
    }
    .go-intersection {
        width: 100%;
        height: 100%;
    }
    .go-stone {
        width: calc(100% - 10px);
        height: calc(100% - 10px);
    }
    :root {
        --go-cell-size: 15px; /* Not used */
        --go-border: 10px;
        --go-line: 1.2px;
    }
    .captured-info {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.25rem;
        justify-content: center;
    }
    .primary-controls,
    .board-size-controls {
        flex-wrap: wrap;
        justify-content: center;
    }
}

@media (max-width: 360px) {
    #game-section {
        padding: 1rem;
    }

    :root {
        --go-border: 7px;
        --go-line: 1.2px;
    }

    .btn-size,
    #pass,
    #new-game {
        font-size: 0.82rem;
        padding: 0.5rem 0.68rem;
    }

    .captured-info {
        font-size: 0.95rem;
    }
}

@media (orientation: landscape) and (max-height: 430px) {
    #game-section {
        padding: 0.85rem;
    }

    .btn-size,
    #pass,
    #new-game {
        padding: 0.45rem 0.62rem;
        font-size: 0.8rem;
    }

    .captured-info {
        font-size: 0.9rem;
        gap: 0.2rem;
    }
}