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

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f8f9fa;
    color: #333;
    line-height: 1.4;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
}

header {
    padding: 6px 12px;
    background: #2c3e50;
    border-bottom: none;
}

header h1 {
    font-size: 1rem;
    color: white;
    font-weight: 500;
}

.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    gap: 0;
}

.left-panel {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
    background: #f0f2f5;
    border-right: 1px solid #e0e0e0;
    overflow-y: auto;
}

.panel-section {
    background: white;
    padding: 8px;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    min-width: 320px;
}

.right-panel .preview-section {
    padding: 8px;
    border-bottom: 1px solid #eee;
    text-align: center;
    opacity: 0.5;
    transition: opacity 0.2s;
    background: #fafafa;
}

.right-panel .preview-section.active {
    opacity: 1;
}

.right-panel .preview-section #result-board-container {
    display: inline-block;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
    background: #f8f9fa;
}

.results-header h3 {
    font-size: 0.85rem;
    color: #2c3e50;
    font-weight: 600;
}

.sort-toggle {
    display: flex;
    gap: 4px;
    margin-left: auto;
    padding-left: 10px;
}

.sort-btn {
    padding: 4px 10px;
    border: 1px solid #ddd;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    color: #666;
    transition: all 0.15s;
}

.sort-btn:hover {
    background: #e9ecef;
    border-color: #ccc;
}

.sort-btn.active {
    background: #2c3e50;
    border-color: #2c3e50;
    color: white;
}

.sort-help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ccc;
    color: #666;
    font-size: 0.65rem;
    font-weight: bold;
    cursor: help;
    margin-left: 4px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.section-header h3 {
    font-size: 0.85rem;
    color: #2c3e50;
    font-weight: 600;
}

.badge {
    font-size: 0.8rem;
    color: #666;
    background: #f0f2f5;
    padding: 2px 8px;
    border-radius: 10px;
}

.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    gap: 6px;
    flex-wrap: wrap;
}

.mode-buttons {
    display: flex;
    gap: 4px;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.15s;
}

.mode-btn:hover {
    border-color: #aaa;
}

.mode-btn.active {
    border-color: #3498db;
    background: #ebf5fb;
}

.stone-icon {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.stone-icon.black {
    background: radial-gradient(circle at 30% 30%, #555, #000);
}

.stone-icon.white {
    background: radial-gradient(circle at 30% 30%, #fff, #ddd);
    border: 1px solid #999;
}

#mode-alternate .stone-icon {
    margin-right: -4px;
}

#mode-alternate .stone-icon:last-of-type {
    margin-right: 0;
}

.empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    color: #e74c3c;
    font-size: 0.9rem;
    font-weight: bold;
    line-height: 1;
}

.action-buttons {
    display: flex;
    gap: 6px;
}

button {
    padding: 4px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.15s;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.primary-btn {
    background: #3498db;
    color: white;
}

.primary-btn:hover:not(:disabled) {
    background: #2980b9;
}

.secondary-btn {
    background: #ecf0f1;
    color: #555;
}

.secondary-btn:hover:not(:disabled) {
    background: #dde4e6;
}

#board-container,
#result-board-container {
    background: linear-gradient(145deg, #8b6914, #5c4a0f);
    padding: 4px;
    border-radius: 4px;
    display: inline-block;
    box-shadow:
        0 2px 6px rgba(0, 0, 0, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

#board-container svg,
#result-board-container svg {
    border-radius: 3px;
    display: block;
}

.hint {
    text-align: center;
    color: #999;
    font-size: 0.7rem;
    margin-top: 4px;
}

#results-container {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.placeholder {
    color: #999;
    text-align: center;
    padding: 20px 15px;
    font-size: 0.8rem;
}

/* Lecture group */
.lecture-group {
    border-bottom: 1px solid #eee;
}

.lecture-header {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    cursor: pointer;
    transition: background 0.15s;
    gap: 8px;
}

.lecture-header:hover {
    background: #f8f9fa;
}

.lecture-header.expanded {
    background: #f0f2f5;
}

.expand-icon {
    color: #999;
    font-size: 0.8rem;
    width: 16px;
    transition: transform 0.2s;
}

.lecture-header.expanded .expand-icon {
    transform: rotate(90deg);
}

.season-badge {
    background: #3498db;
    color: white;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 600;
    margin-right: 4px;
    flex-shrink: 0;
}

.lecture-name {
    flex: 1;
    font-size: 0.8rem;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.position-count {
    font-size: 0.75rem;
    color: #666;
    background: #e8e8e8;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Position list */
.position-list {
    display: none;
    background: #fafafa;
}

.lecture-group.expanded .position-list {
    display: block;
}

.position-item {
    display: flex;
    align-items: center;
    padding: 5px 10px 5px 30px;
    cursor: pointer;
    transition: background 0.15s;
    gap: 8px;
    border-top: 1px solid #eee;
}

.position-item:hover {
    background: #f0f4f8;
}

.position-item.selected {
    background: #e3f2fd;
}

.stone-count-badge {
    background: #3498db;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 500;
    min-width: 24px;
    text-align: center;
}

.position-info {
    font-size: 0.8rem;
    color: #666;
}

.comment-text {
    font-size: 0.75rem;
    color: #8b6914;
    background: #fffde7;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: auto;
    white-space: nowrap;
}

.timestamp-link {
    font-size: 0.75rem;
    color: #2980b9;
    background: #e8f4fc;
    padding: 2px 8px;
    border-radius: 4px;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.timestamp-link:hover {
    background: #3498db;
    color: white;
}

.no-results {
    text-align: center;
    color: #888;
    padding: 20px 15px;
    font-size: 0.85rem;
}

footer {
    padding: 4px 10px;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    font-size: 0.65rem;
    color: #888;
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.separator {
    color: #ddd;
}

kbd {
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 1px 4px;
    font-family: inherit;
    font-size: 0.8em;
}

/* Scrollbar */
#results-container::-webkit-scrollbar {
    width: 8px;
}

#results-container::-webkit-scrollbar-track {
    background: #f5f5f5;
}

#results-container::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

#results-container::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* Responsive */
@media (max-width: 800px) {
    .main-layout {
        flex-direction: column;
    }

    .left-panel {
        flex-direction: row;
        flex-wrap: wrap;
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
    }

    .right-panel {
        min-height: 300px;
    }
}
