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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #3a2417 0%, #5c3a21 100%);
    min-height: 100vh;
    padding: 20px;
    color: #2b1a0e;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 20px;
    color: #f4e3c1;
}

.back-link {
    display: inline-block;
    margin-bottom: 10px;
    color: #f4e3c1;
    text-decoration: none;
    opacity: 0.85;
}

.back-link:hover {
    opacity: 1;
    text-decoration: underline;
}

h1 {
    font-size: 2.5rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.4);
}

.subtitle {
    color: rgba(244, 227, 193, 0.85);
    margin-top: 6px;
}

.game-layout {
    display: flex;
    gap: 24px;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
}

.board-panel {
    background: #d9a86c;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.board {
    position: relative;
    display: grid;
    background: #e3b579;
}

.cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.cell::before, .cell::after {
    content: '';
    position: absolute;
    background: #4a2f16;
}

.cell::before {
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
    transform: translateX(-0.5px);
}

.cell::after {
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    transform: translateY(-0.5px);
}

.cell.edge-top::before { top: 50%; }
.cell.edge-bottom::before { bottom: 50%; }
.cell.edge-left::after { left: 50%; }
.cell.edge-right::after { right: 50%; }

.star-point::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4a2f16;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
}

.stone {
    position: relative;
    z-index: 3;
    border-radius: 50%;
    box-shadow: 1px 2px 3px rgba(0,0,0,0.5);
    pointer-events: none;
    animation: place 0.15s ease-out;
}

.stone.black {
    background: radial-gradient(circle at 35% 30%, #555 0%, #111 70%, #000 100%);
}

.stone.white {
    background: radial-gradient(circle at 35% 30%, #fff 0%, #ddd 70%, #ccc 100%);
}

.stone.ghost {
    opacity: 0.35;
}

.stone.last-move::after {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    top: 35%;
    left: 35%;
    border-radius: 50%;
    background: #d33;
}

@keyframes place {
    from { transform: scale(0.4); }
    to { transform: scale(1); }
}

.cell:hover .stone.ghost {
    opacity: 0.5;
}

.side-panel {
    width: 300px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel-section {
    background: rgba(255,255,255,0.92);
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

#turn-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
    font-size: 1.1rem;
}

.stone-preview {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    box-shadow: 1px 2px 3px rgba(0,0,0,0.4);
    flex-shrink: 0;
}

.stone-preview.black {
    background: radial-gradient(circle at 35% 30%, #555 0%, #111 70%, #000 100%);
}

.stone-preview.white {
    background: radial-gradient(circle at 35% 30%, #fff 0%, #ddd 70%, #ccc 100%);
    border: 1px solid #999;
}

.scores {
    display: flex;
    gap: 10px;
}

.score-box {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.score-label {
    font-size: 0.75rem;
    color: #666;
}

.score-value {
    font-size: 1.3rem;
    font-weight: bold;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.controls label {
    font-size: 0.85rem;
    color: #444;
}

.controls select {
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #ccc;
    margin-bottom: 4px;
}

button {
    padding: 10px 14px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.15s ease;
}

button:hover {
    transform: scale(1.03);
}

button:active {
    transform: scale(0.97);
}

.rules-toggle button, #close-rules, #close-end {
    background: linear-gradient(135deg, #8d6e63 0%, #6d4c41 100%);
}

.message-log {
    font-size: 0.9rem;
    color: #333;
    max-height: 140px;
    overflow-y: auto;
    line-height: 1.5;
}

.message-log p {
    margin-bottom: 6px;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #fff8ec;
    padding: 28px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.modal-content h2 {
    margin-bottom: 14px;
    color: #4a2f16;
}

.modal-content ul {
    padding-left: 20px;
    margin-bottom: 16px;
    line-height: 1.6;
}

.modal-content li {
    margin-bottom: 8px;
}

#end-details {
    margin-bottom: 16px;
    line-height: 1.7;
}

@media (max-width: 700px) {
    .game-layout {
        flex-direction: column;
        align-items: center;
    }
    .side-panel {
        width: 100%;
        max-width: 500px;
    }
}
