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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #333;
}

 select {
     font-size: 1rem;
     line-height: 1.2;
 }

.container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    max-width: 1200px;
    width: 90%;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 3rem;
    color: #4a5568;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

header p {
    font-size: 1.2rem;
    color: #718096;
}

 .variant-subtitle {
     margin-top: 0.15rem;
     font-size: 0.95rem;
     color: #a0aec0;
     font-weight: 600;
 }

.play-area {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 1.5rem;
    align-items: start;
}

.play-main {
    min-width: 0;
}

.options-panel {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    margin-bottom: 0;
    text-align: left;
}

.options-panel > * {
    width: 100%;
}

.options-panel .language-controls {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    white-space: normal;
}

.options-panel .language-select {
    width: 100%;
}

.options-panel .malagasy-toggle {
    white-space: normal;
}

.options-panel select {
    padding: 0.45rem 0.6rem;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
    background: white;
    color: #2d3748;
    font-weight: 600;
    width: 100%;
    max-width: 100%;
}

.options-panel input[type="text"] {
    padding: 0.45rem 0.6rem;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
    background: white;
    color: #2d3748;
    font-weight: 600;
    width: 100%;
    max-width: 100%;
}

.options-panel select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
}

.options-panel input[type="text"]:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
}

.options-panel #language {
    max-width: 100%;
}

.game-info {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: #f7fafc;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    gap: 1rem;
    flex-wrap: wrap;
}

 .game-info > * {
     flex: 0 0 auto;
 }

.language-controls {
     display: flex;
     align-items: center;
     gap: 0.75rem;
     color: #4a5568;
     font-size: 1rem;
     white-space: nowrap;
 }

 .language-select {
     display: flex;
     align-items: center;
     gap: 0.5rem;
 }

 #language {
     padding: 0.45rem 0.6rem;
     border-radius: 8px;
     border: 2px solid #e2e8f0;
     background: white;
     color: #2d3748;
     font-weight: 600;
     max-width: 190px;
 }

 #language:focus {
     outline: none;
     border-color: #667eea;
     box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
 }

 .malagasy-toggle {
     display: flex;
     align-items: center;
     gap: 0.4rem;
     font-weight: 600;
     cursor: pointer;
 }

 .malagasy-toggle input {
     width: 16px;
     height: 16px;
 }

.current-player {
    font-size: 1.2rem;
    font-weight: bold;
    color: #2d3748;
}

#current-player {
    color: #4299e1;
}

.score {
    font-size: 1.1rem;
    color: #4a5568;
}

 .hidden {
     display: none !important;
 }

 .match-controls {
     display: flex;
     align-items: center;
     gap: 0.75rem;
     color: #4a5568;
     font-size: 1rem;
     white-space: nowrap;
 }

 .match-toggle {
     display: flex;
     align-items: center;
     gap: 0.4rem;
     font-weight: 600;
     cursor: pointer;
 }

 .match-toggle input {
     width: 16px;
     height: 16px;
 }

 .coords-toggle-label,
 .node-names-toggle-label {
     display: flex;
     align-items: center;
     gap: 0.4rem;
     font-weight: 600;
     cursor: pointer;
     color: #4a5568;
     font-size: 1rem;
     white-space: nowrap;
 }

 .coords-toggle-label input,
 .node-names-toggle-label input {
     width: 16px;
     height: 16px;
 }

 .match-status {
     min-width: 180px;
     color: #2d3748;
     font-weight: 600;
 }

 #new-match,
 #next-game {
     background: white;
     color: #2d3748;
     border: 2px solid #e2e8f0;
     padding: 0.55rem 0.9rem;
     border-radius: 8px;
     font-size: 0.95rem;
     font-weight: 700;
     cursor: pointer;
     transition: all 0.2s ease;
 }

 #end-turn {
     background: white;
     color: #2d3748;
     border: 2px solid #e2e8f0;
     padding: 0.55rem 0.9rem;
     border-radius: 8px;
     font-size: 0.95rem;
     font-weight: 700;
     cursor: pointer;
     transition: all 0.2s ease;
 }

 #new-match:hover,
 #next-game:hover {
     border-color: #667eea;
     box-shadow: 0 6px 18px rgba(102, 126, 234, 0.18);
 }

 #end-turn:hover {
     border-color: #667eea;
     box-shadow: 0 6px 18px rgba(102, 126, 234, 0.18);
 }

 #new-match:disabled,
 #next-game:disabled {
     opacity: 0.5;
     cursor: not-allowed;
 }

 .opening-select {
     display: flex;
     align-items: center;
     gap: 0.5rem;
     color: #4a5568;
     font-size: 1rem;
     white-space: nowrap;
 }

 .mode-select {
     display: flex;
     align-items: center;
     gap: 0.5rem;
     color: #4a5568;
     font-size: 1rem;
     white-space: nowrap;
 }

 #mode {
     padding: 0.45rem 0.6rem;
     border-radius: 8px;
     border: 2px solid #e2e8f0;
     background: white;
     color: #2d3748;
     font-weight: 600;
 }

 #mode:focus {
     outline: none;
     border-color: #667eea;
     box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
 }

 .bottom-color-select {
     display: flex;
     align-items: center;
     gap: 0.5rem;
     color: #4a5568;
     font-size: 1rem;
     white-space: nowrap;
 }

 #bottom-color {
     padding: 0.45rem 0.6rem;
     border-radius: 8px;
     border: 2px solid #e2e8f0;
     background: white;
     color: #2d3748;
     font-weight: 600;
 }

 #bottom-color:focus {
     outline: none;
     border-color: #667eea;
     box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
 }

 .orientation-select {
     display: flex;
     align-items: center;
     gap: 0.5rem;
     color: #4a5568;
     font-size: 1rem;
     white-space: nowrap;
 }

 .starting-player-select {
     display: flex;
     align-items: center;
     gap: 0.5rem;
     color: #4a5568;
     font-size: 1rem;
     white-space: nowrap;
 }

 #handedness {
     padding: 0.45rem 0.6rem;
     border-radius: 8px;
     border: 2px solid #e2e8f0;
     background: white;
     color: #2d3748;
     font-weight: 600;
 }

 #handedness:focus {
     outline: none;
     border-color: #667eea;
     box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
 }

 #starting-player {
     padding: 0.45rem 0.6rem;
     border-radius: 8px;
     border: 2px solid #e2e8f0;
     background: white;
     color: #2d3748;
     font-weight: 600;
 }

 #starting-player:focus {
     outline: none;
     border-color: #667eea;
     box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
 }

 #opening {
     padding: 0.45rem 0.6rem;
     border-radius: 8px;
     border: 2px solid #e2e8f0;
     background: white;
     color: #2d3748;
     font-weight: 600;
 }

 #opening:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
 }

#new-game {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

#new-game:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.game-board-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

#game-board {
    background: #f4e4c1;
    border: 3px solid #8b7355;
    border-radius: 4px;
    width: 100%;
    max-width: 900px;
    aspect-ratio: 900 / 500;
}

 #game-board.theme-stone {
     background: #bcbcbc;
     border-color: #6b6b6b;
     box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
 }

.game-status {
    text-align: center;
    padding: 1rem;
    background: #f7fafc;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
}

.game-state {
    margin-top: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.game-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.game-notations {
    margin-top: 0.75rem;
    display: flex;
    justify-content: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

#open-notation {
    padding: 0.6rem 0.9rem;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    background: #ffffff;
    cursor: pointer;
    font-weight: 600;
}

#open-notation:hover {
    border-color: #667eea;
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.18);
}

#open-builder {
    background: white;
    color: #2d3748;
    border: 2px solid #e2e8f0;
    padding: 0.45rem 0.8rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

#open-builder:hover {
    border-color: #667eea;
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.18);
}

.builder-overlay {
    display: none;
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.98);
    padding: 1rem;
    z-index: 1100;
}

body.show-builder .builder-overlay {
    display: block;
}

body.show-builder .play-area {
    display: flex;
}

.builder-panel {
    max-width: 900px;
    margin: 0 auto;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: white;
    padding: 0.9rem;
    box-shadow: 0 18px 45px rgba(45, 55, 72, 0.12);
}

.builder-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e2e8f0;
}

.builder-title {
    font-weight: 800;
    color: #2d3748;
}

.builder-body {
    padding-top: 0.75rem;
}

.builder-section-title {
    font-weight: 800;
    color: #2d3748;
    margin-bottom: 0.5rem;
}

.builder-games {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 45vh;
    overflow: auto;
    padding: 0.25rem;
}

.builder-game-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    border: 1px solid #edf2f7;
    border-radius: 10px;
    padding: 0.6rem;
    background: #f7fafc;
}

.builder-game-meta {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    color: #4a5568;
    font-size: 0.9rem;
}

.builder-actions {
    margin-top: 0.9rem;
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.builder-actions button {
    background: white;
    color: #2d3748;
    border: 2px solid #e2e8f0;
    padding: 0.45rem 0.8rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.builder-actions button:hover {
    border-color: #667eea;
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.18);
}

.builder-status {
    margin-top: 0.75rem;
    color: #4a5568;
    font-size: 0.95rem;
}

 .notation-open {
     display: none;
     margin-top: 0.75rem;
 }

 .notation-header {
     display: none;
     align-items: center;
     justify-content: space-between;
     gap: 0.75rem;
 }

 .notation-title {
     font-weight: 700;
 }

 #close-notation {
     padding: 0.5rem 0.8rem;
     border-radius: 10px;
     border: 2px solid #e2e8f0;
     background: #ffffff;
     cursor: pointer;
     font-weight: 600;
 }

#status-message {
    font-size: 1.1rem;
    color: #2d3748;
    font-weight: 500;
}

 .diagnostics {
     margin-top: 0.5rem;
     padding: 0.6rem 0.8rem;
     border-radius: 8px;
     border: 2px solid #feb2b2;
     background: #fff5f5;
     color: #742a2a;
     font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
     font-size: 0.85rem;
     white-space: pre-wrap;
     text-align: left;
 }

.notation-panel {
    margin-top: 0.9rem;
    padding-top: 0.9rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    text-align: left;
}

.notation-row {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.notation-label {
    font-weight: 700;
    color: #4a5568;
    min-width: 72px;
}

.notation-code {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.35rem 0.55rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.85rem;
    color: #2d3748;
    word-break: break-word;
    flex: 1;
}

.move-log {
    margin: 0;
    padding-left: 1.2rem;
    color: #2d3748;
    font-size: 0.9rem;
    line-height: 1.25rem;
    flex: 1;
}

.move-log li {
    margin: 0.1rem 0;
}

.move-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.82rem;
    color: #2d3748;
    background: #ffffff;
    flex: 1;
}

.move-table th,
.move-table td {
    border-bottom: 1px solid #edf2f7;
    padding: 0.35rem 0.45rem;
    vertical-align: top;
}

.move-table th {
    text-align: left;
    background: #f7fafc;
    font-weight: 800;
    color: #4a5568;
}

.move-table tbody tr:nth-child(even) {
    background: #fbfdff;
}

.move-table td:nth-child(4) {
    word-break: break-word;
}

 .highlight-toggle {
     display: flex;
     align-items: center;
 }

 .highlight-toggle-label {
     display: inline-flex;
     align-items: center;
     gap: 0.5rem;
     font-weight: 600;
     color: #4a5568;
     cursor: pointer;
 }

 .highlight-toggle-label input {
     width: 16px;
     height: 16px;
 }

 .notation-actions {
     display: flex;
     gap: 0.5rem;
     flex-wrap: wrap;
 }

 #export-text,
 #export-json,
 #save-game {
     background: white;
     color: #2d3748;
     border: 2px solid #e2e8f0;
     padding: 0.45rem 0.8rem;
     border-radius: 8px;
     font-size: 0.9rem;
     font-weight: 700;
     cursor: pointer;
     transition: all 0.2s ease;
 }

 #export-text:hover,
 #export-json:hover,
 #save-game:hover {
     border-color: #667eea;
     box-shadow: 0 6px 18px rgba(102, 126, 234, 0.18);
 }

 .capture-choice {
     margin-top: 0.75rem;
     display: flex;
     align-items: center;
     justify-content: center;
     gap: 0.6rem;
     flex-wrap: wrap;
 }

 .capture-choice-label {
     font-weight: 700;
     color: #4a5568;
 }

 #choose-approach,
 #choose-withdrawal {
     background: white;
     color: #2d3748;
     border: 2px solid #e2e8f0;
     padding: 0.55rem 0.9rem;
     border-radius: 8px;
     font-size: 0.95rem;
     font-weight: 700;
     cursor: pointer;
     transition: all 0.2s ease;
 }

 #choose-approach:hover,
 #choose-withdrawal:hover {
     border-color: #667eea;
     box-shadow: 0 6px 18px rgba(102, 126, 234, 0.18);
 }

.board-line {
    stroke: #8b7355;
    stroke-width: 3;
    opacity: 0.95;
    shape-rendering: crispEdges;
}

 #game-board.theme-stone .board-line {
     stroke: #4a4a4a;
     opacity: 0.9;
 }

 .board-outline {
     stroke: #8b7355;
     stroke-width: 4;
     opacity: 0.95;
 }

 #game-board.theme-stone .board-outline {
     stroke: #4a4a4a;
     opacity: 0.9;
 }

.board-point {
fill: #4a5568;
}

 #game-board.theme-stone .board-point {
     fill: #2f2f2f;
 }

.board-coord {
font-size: 14px;
font-weight: 700;
fill: rgba(45, 55, 72, 0.7);
}

.board-node-name {
font-size: 11px;
font-weight: 700;
fill: rgba(45, 55, 72, 0.65);
}

 .capture-trail {
     stroke: rgba(113, 128, 150, 0.65);
     stroke-width: 10;
     stroke-linecap: round;
 }

 .visited-marker {
     fill: rgba(113, 128, 150, 0.12);
     stroke: rgba(113, 128, 150, 0.6);
     stroke-width: 3;
 }

.click-target {
fill: transparent;
stroke: none;
pointer-events: all;
}

.game-piece {
    cursor: pointer;
    transition: all 0.3s ease;
}

.game-piece:hover {
    filter: brightness(1.2);
}

.white-piece {
    fill: #ffffff;
    stroke: #2d3748;
    stroke-width: 2;
}

.black-piece {
    fill: #2d3748;
    stroke: #1a202c;
    stroke-width: 2;
}

.selected-piece {
    stroke: #f6ad55;
    stroke-width: 4;
    filter: drop-shadow(0 0 8px rgba(246, 173, 85, 0.8));
}

.valid-move {
    fill: #48bb78;
    opacity: 0.6;
    cursor: pointer;
}

 .move-path {
     fill: none;
     stroke-linecap: round;
     stroke-linejoin: round;
     pointer-events: none;
 }

 .move-path-paika {
     stroke: rgba(72, 187, 120, 0.75);
     stroke-width: 6;
 }

 .move-path-capture {
     stroke: rgba(252, 129, 129, 0.85);
     stroke-width: 8;
 }

 .chain-step-badge {
     fill: rgba(26, 32, 44, 0.85);
     stroke: rgba(255, 255, 255, 0.9);
     stroke-width: 2;
     pointer-events: none;
 }

 .chain-step-text {
     fill: rgba(255, 255, 255, 0.95);
     font-size: 14px;
     font-weight: 700;
     pointer-events: none;
     -webkit-user-select: none;
     user-select: none;
 }

 .edge-step-badge {
     fill: rgba(26, 32, 44, 0.85);
     stroke: rgba(255, 255, 255, 0.9);
     stroke-width: 2;
     pointer-events: none;
 }

 .edge-step-text {
     fill: rgba(255, 255, 255, 0.95);
     font-size: 13px;
     font-weight: 700;
     pointer-events: none;
     -webkit-user-select: none;
     user-select: none;
 }

.capture-indicator {
    fill: #fc8181;
    opacity: 0.8;
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
        width: 95%;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .play-area {
        grid-template-columns: 1fr;
    }

    .game-info {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .current-player,
    .match-controls,
    .opening-select,
    .mode-select,
    .bottom-color-select,
    .orientation-select,
    .starting-player-select,
    .highlight-toggle,
    .score,
    #end-turn,
    #new-game,
    #new-match,
    #next-game {
        width: 100%;
    }

    .current-player { order: 1; }
    .match-controls { order: 2; }
    .opening-select { order: 3; }
    .mode-select { order: 4; }
    .bottom-color-select { order: 5; }
    .orientation-select { order: 6; }
    .starting-player-select { order: 7; }
    .highlight-toggle { order: 8; }
    .score { order: 9; }
    #end-turn { order: 10; }
    #new-game { order: 11; }

     .notation-open {
         display: block;
     }

     .notation-panel {
         display: none;
         position: fixed;
         left: 0;
         right: 0;
         top: 0;
         bottom: 0;
         z-index: 1000;
         margin: 0;
         border-radius: 0;
         overflow: auto;
         padding: calc(1rem + env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom));
         background: rgba(255, 255, 255, 0.98);
     }

     body.show-notation .notation-panel {
         display: block;
     }

     .notation-header {
         display: flex;
         margin-bottom: 0.75rem;
     }
}
