.selection-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 300px;
    max-height: 90vh;
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.selection-panel.minimized {
    height: 40px;
    overflow: hidden;
}

.selection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #252525;
    border-bottom: 1px solid #333;
    border-radius: 8px 8px 0 0;
    color: #f2f2f2;
    flex-shrink: 0;
}

.selection-header h3 {
    margin: 0;
    padding: 0;
    font-size: 16px;
    color: #f2f2f2;
    flex: 1;
    font-weight: bold;
    display: flex;
    align-items: center;
    line-height: 1;
}

.total-count {
    flex: 1;
    text-align: center;
    font-size: 16px;
    color: #ccc;
    font-weight: normal;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.minimize-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 5px;
    color: #f2f2f2;
    flex: 0 0 auto;
}

.selection-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}
.selection-stats {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    padding: 5px;
    background: #222;
    border-radius: 4px;
    color: #f2f2f2;
    flex-shrink: 0;
    margin: 10px;
    margin-bottom: 5px;
}

.formation-count {
    color: #4CAF50;
}

.set-count {
    color: #2196F3;
}

.play-count {
    color: #FF9800;
}

.selection-list {
    font-size: 14px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 10px 10px 10px;
}

.formation-group {
    margin-bottom: 15px;
}

.formation-group h4 {
    margin: 0 0 5px 0;
    color: #f2f2f2;
}

.set-list {
    margin: 0;
    padding-left: 20px;
    list-style: none;
}

.set-item {
    margin: 5px 0;
}

.set-name {
    color: #ccc;
    font-weight: 500;
}

.play-list {
    margin: 0;
    padding-left: 20px;
    list-style: none;
}

.play-item {
    color: #aaa;
    margin: 3px 0;
}

.remove-btn {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 16px;
    padding: 0 5px;
    transition: color 0.2s;
}

.remove-btn:hover {
    color: #f2f2f2;
}

.formation-header,
.set-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.play-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #aaa;
    margin: 3px 0;
}

.history-actions {
    display: flex;
    gap: 5px;
}

.undo-btn,
.redo-btn {
    background: none;
    border: none;
    color: #f2f2f2;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.undo-btn:hover:not(:disabled),
.redo-btn:hover:not(:disabled) {
    background-color: #444;
}

.undo-btn:disabled,
.redo-btn:disabled {
    color: #666;
    cursor: not-allowed;
}

.selection-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-top: 1px solid #333;
    flex-shrink: 0;
}

.history-actions {
    display: flex;
    gap: 5px;
}

.main-actions {
    display: flex;
    gap: 10px;
}

.undo-btn, .redo-btn {
    background: none;
    border: 1px solid #444;
    color: #f2f2f2;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
}

.undo-btn:disabled, .redo-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.remove-btn {
    background: none;
    border: none;
    color: #f2f2f2;
    cursor: pointer;
    opacity: 0.7;
    font-size: 16px;
    padding: 0 4px;
    line-height: 1;
}

.remove-btn:hover {
    opacity: 1;
}

.formation-header, .set-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.formation-header h4, .set-header h5 {
    margin: 0;
}

.play-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 0;
}

.nav-link {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s;
}

.nav-link:hover {
    color: #4CAF50;
    text-decoration: underline;
}

.selection-actions button {
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s;
}

.clear-btn {
    background: #ff4444;
    color: white;
}

.clear-btn:hover {
    background: #ff0000;
}

.export-btn {
    background: #4CAF50;
    color: white;
}

.export-btn:hover {
    background: #45a049;
}

/* Checkbox styles */
.select-checkbox {
    margin-right: 8px;
    cursor: pointer;
    transform: scale(1.2);
    accent-color: #4CAF50;
}

/* Style for formation/set titles with checkboxes */
h1 .select-checkbox,
h2 .select-checkbox,
h3 .select-checkbox {
    margin-right: 10px;
}

/* Style for list items with checkboxes */
li .select-checkbox {
    margin-right: 8px;
}

/* Style for play cards with checkboxes - responsive positioning */
.play-card .select-checkbox {
    position: absolute;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 2px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    z-index: 10;
    transform: scale(1.3);
}

.play-card {
    position: relative;
}

/* Default positioning for larger screens */
.play-card .select-checkbox {
    top: 8px;
    left: 8px;
}

/* Responsive positioning for different screen sizes */
@media (max-width: 768px) {
    .play-card .select-checkbox {
        top: 5px;
        left: 5px;
        transform: scale(1.2);
    }
}

@media (max-width: 480px) {
    .play-card .select-checkbox {
        top: 3px;
        left: 3px;
        transform: scale(1.1);
        padding: 1px;
    }
}

/* For very large screens, move checkbox slightly more inward */
@media (min-width: 1200px) {
    .play-card .select-checkbox {
        top: 12px;
        left: 12px;
        transform: scale(1.4);
    }
}

/* Ensure checkbox doesn't interfere with play card interaction on touch devices */
@media (hover: none) and (pointer: coarse) {
    .play-card .select-checkbox {
        top: 5px;
        right: 5px;
        left: auto;
        transform: scale(1.3);
        /* Larger touch target for mobile */
        min-width: 20px;
        min-height: 20px;
    }
    
    /* Add more spacing for touch targets on mobile */
    .select-checkbox {
        min-width: 18px;
        min-height: 18px;
        margin-right: 10px;
    }
    
    /* Better spacing for list items on mobile */
    li .select-checkbox {
        margin-right: 12px;
    }
}

/* Add All button styling */
.add-all-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    margin-left: 10px;
    transition: background-color 0.2s ease;
}

.add-all-btn:hover {
    background: #0056b3;
}

.add-all-btn:active {
    background: #004085;
}

.add-all-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

/* Ensure play links maintain their orange color within the selection panel */
.selection-panel .play-link {
    color: #FF9800 !important;
    font-weight: normal;
    font-size: 0.95em;
    text-decoration: none;
}

.selection-panel .play-link:hover {
    color: #FFB74D !important;
    text-shadow: 0 0 8px rgba(255, 152, 0, 0.3);
}

/* Ensure formation links maintain their green color within the selection panel */
.selection-panel .formation-link {
    color: #4CAF50 !important;
    font-weight: bold;
    font-size: 1.1em;
    text-decoration: none;
}

.selection-panel .formation-link:hover {
    color: #66BB6A !important;
    text-shadow: 0 0 8px rgba(76, 175, 80, 0.3);
}

/* Ensure set links maintain their blue color within the selection panel */
.selection-panel .set-link {
    color: #2196F3 !important;
    font-weight: 600;
    font-size: 1.0em;
    text-decoration: none;
}

.selection-panel .set-link:hover {
    color: #42A5F5 !important;
    text-shadow: 0 0 8px rgba(33, 150, 243, 0.3);
}

/* Add/Added button styles */
.select-btn {
    padding: 4px 12px;
    border: 2px solid;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
    margin-left: 8px;
    vertical-align: middle;
}

/* Formation buttons - Green */
.select-btn[data-type="formation"] {
    border-color: #4CAF50;
    color: #4CAF50;
}

.select-btn[data-type="formation"].added {
    background: #4CAF50;
    color: white;
}

.select-btn[data-type="formation"]:hover {
    background: rgba(76, 175, 80, 0.1);
}

.select-btn[data-type="formation"].added:hover {
    background: #45a049;
}

/* Set buttons - Blue */
.select-btn[data-type="set"] {
    border-color: #2196F3;
    color: #2196F3;
}

.select-btn[data-type="set"].added {
    background: #2196F3;
    color: white;
}

.select-btn[data-type="set"]:hover {
    background: rgba(33, 150, 243, 0.1);
}

.select-btn[data-type="set"].added:hover {
    background: #1976D2;
}

/* Play buttons - Orange */
.select-btn[data-type="play"] {
    border-color: #FF9800;
    color: #FF9800;
}

.select-btn[data-type="play"].added {
    background: #FF9800;
    color: white;
}

.select-btn[data-type="play"]:hover {
    background: rgba(255, 152, 0, 0.1);
}

.select-btn[data-type="play"].added:hover {
    background: #F57C00;
}

/* Add All buttons for search results */
.add-all-btn {
    padding: 4px 12px;
    border: 2px solid;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
    margin-left: 8px;
    vertical-align: middle;
}

/* Add All Sets buttons - Blue */
.add-all-btn.sets {
    border-color: #2196F3;
    color: #2196F3;
}

.add-all-btn.sets:hover {
    background: rgba(33, 150, 243, 0.1);
}

/* Add All Plays buttons - Orange */
.add-all-btn.plays {
    border-color: #FF9800;
    color: #FF9800;
}

.add-all-btn.plays:hover {
    background: rgba(255, 152, 0, 0.1);
}

/* Search results spacing improvements */
#searchResults {
    line-height: 1.6;
}

#searchResults > div {
    margin-bottom: 8px;
    padding: 4px 0;
}

#searchResults h3 {
    margin: 8px 0 4px 0;
    line-height: 1.4;
}

#searchResults h4 {
    margin: 6px 0 3px 0;
    line-height: 1.3;
}

#searchResults h5 {
    margin: 4px 0 2px 0;
    line-height: 1.2;
}

#searchResults ul {
    margin: 4px 0;
    line-height: 1.5;
}

#searchResults li {
    margin: 3px 0;
    padding: 2px 0;
}

/* Reduce button size slightly for better fit */
.select-btn, .add-all-btn {
    padding: 3px 10px;
    font-size: 11px;
    margin-left: 6px;
    vertical-align: baseline;
    position: relative;
    top: -1px;
}

/* Button positioning for different contexts */
li .select-btn {
    margin-left: 8px;
}

h1 .select-btn,
h2 .select-btn,
h3 .select-btn {
    margin-left: 12px;
}

.play-card .select-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
}

/* Hide any select-btn buttons that appear within the selection panel */
.selection-panel .select-btn {
    display: none !important;
}

/* Mobile tooltip system */
.mobile-tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    max-width: 250px;
    z-index: 10000;
    pointer-events: none;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    line-height: 1.3;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.mobile-tooltip.show {
    opacity: 1;
    transform: translateY(0);
}

/* Mobile-specific styles */
@media (hover: none) and (pointer: coarse) {
    /* Slightly larger touch targets for mobile */
    .select-btn, .add-all-btn, .remove-btn {
        min-width: 44px;
        min-height: 32px;
        padding: 6px 12px;
    }
    
    /* Better spacing for mobile interactions */
    .play-item, .set-item, .formation-group {
        padding: 8px 0;
    }
    
    /* Larger minimize button for mobile */
    .minimize-btn {
        min-width: 44px;
        min-height: 32px;
        padding: 6px;
    }
    
    /* Better button spacing on mobile */
    .selection-actions button {
        padding: 12px 18px;
        margin: 4px;
        min-height: 44px;
    }
    
    /* Visual feedback for touch interactions */
    .select-btn:active,
    .add-all-btn:active,
    .remove-btn:active,
    .minimize-btn:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
}

/* Mobile responsive styles for selection panel */
@media (max-width: 768px) {
    .selection-panel {
        max-height: 60vh;
        width: 96vw;
        right: 2vw;
        bottom: 10px;
        padding: 6px;
    }
    
    .selection-content {
        max-height: 40vh;
        padding: 6px;
    }
    
    .selection-header {
        padding: 6px;
    }
}

@media (max-width: 480px) {
    .selection-panel {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
        bottom: 8px;
        right: 8px;
        left: 8px;
    }
    
    .selection-header {
        padding: 10px 12px;
    }
    
    .selection-header h3 {
        font-size: 13px;
    }
    
    .total-count {
        font-size: 13px;
    }
    
    .selection-stats {
        margin: 6px;
        margin-bottom: 3px;
        padding: 6px;
    }
    
    .selection-list {
        padding: 0 6px 6px 6px;
    }
    
    .selection-actions {
        padding: 6px;
        gap: 3px;
    }
    
    .selection-actions button {
        padding: 6px 8px;
        font-size: 10px;
        min-height: 32px;
        border-radius: 4px;
    }
    
    .minimize-btn {
        min-width: 36px;
        min-height: 24px;
        padding: 3px;
    }
    
    .main-actions {
        gap: 3px;
    }
    
    .history-actions {
        gap: 3px;
    }
}

/* Landscape orientation adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .selection-panel {
        width: calc(100vw - 24px);
        max-width: 600px;
        max-height: calc(100vh - 40px);
        bottom: 20px;
        right: 2vw;
        left: 2vw;
        display: flex;
        flex-direction: column;
    }
    
    .selection-header {
        padding: 8px 12px;
        flex-shrink: 0;
    }
    
    .selection-header h3 {
        font-size: 14px;
    }
    
    .total-count {
        font-size: 14px;
    }
    
    .selection-content {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        padding: 0;
        overflow: hidden;
    }
    
    .selection-stats {
        flex-direction: row;
        justify-content: space-around;
        gap: 6px;
        padding: 6px;
        flex-shrink: 0;
        margin-bottom: 4px;
    }
    
    .selection-stats span {
        font-size: 12px;
        text-align: center;
    }
    
    .selection-list {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding: 8px;
    }
    
    .selection-actions {
        padding: 6px;
        gap: 6px;
        flex-shrink: 0;
    }
    
    .selection-actions button {
        padding: 8px 12px;
        font-size: 11px;
        min-height: 32px;
    }
    
    .minimize-btn {
        min-width: 36px;
        min-height: 24px;
        padding: 4px;
    }
}

@media (max-width: 480px) and (orientation: landscape) {
    .selection-panel {
        width: calc(100vw - 16px);
        max-width: 700px;
        max-height: calc(100vh - 30px);
        bottom: 15px;
        right: 1vw;
        left: 1vw;
        display: flex;
        flex-direction: column;
    }
    
    .selection-header {
        padding: 6px 10px;
        flex-shrink: 0;
    }
    
    .selection-header h3 {
        font-size: 13px;
    }
    
    .total-count {
        font-size: 13px;
    }
    
    .selection-content {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        padding: 0;
        overflow: hidden;
    }
    
    .selection-stats {
        flex-direction: row;
        justify-content: space-around;
        gap: 4px;
        padding: 4px;
        flex-shrink: 0;
        margin-bottom: 3px;
    }
    
    .selection-stats span {
        font-size: 11px;
        text-align: center;
    }
    
    .selection-list {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding: 6px;
    }
    
    .selection-actions {
        padding: 4px;
        gap: 4px;
        flex-shrink: 0;
    }
    
    .selection-actions button {
        padding: 6px 10px;
        font-size: 10px;
        min-height: 28px;
    }
    
    .minimize-btn {
        min-width: 32px;
        min-height: 18px;
        padding: 2px;
    }
    
    .main-actions {
        gap: 4px;
    }
    
    .history-actions {
        gap: 4px;
    }
}

/* Ultra-compact mode for very short screens */
@media (max-height: 400px) {
    .selection-panel {
        max-height: calc(100vh - 20px) !important;
        bottom: 10px !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    .selection-header {
        padding: 3px 6px !important;
        flex-shrink: 0;
    }
    
    .selection-header h3 {
        font-size: 11px !important;
    }
    
    .total-count {
        font-size: 11px !important;
    }
    
    .selection-content {
        flex: 1 !important;
        min-height: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        padding: 0 !important;
        overflow: hidden !important;
    }
    
    .selection-stats {
        padding: 2px !important;
        flex-shrink: 0;
        margin-bottom: 2px !important;
    }
    
    .selection-stats span {
        font-size: 9px !important;
    }
    
    .selection-list {
        flex: 1 !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        padding: 3px !important;
    }
    
    .selection-actions {
        padding: 2px !important;
        gap: 2px !important;
        flex-shrink: 0;
    }
    
    .selection-actions button {
        padding: 3px 6px !important;
        font-size: 8px !important;
        min-height: 20px !important;
    }
    
    .minimize-btn {
        min-width: 24px !important;
        min-height: 14px !important;
        padding: 1px !important;
    }
}
/* === Responsive Fixes for Selection Panel on Mobile === */

/* Base: make panel width and height responsive */
.selection-panel {
    width: min(90vw, 300px);
    max-height: min(90vh, 500px);
    overflow: hidden;
}

/* Use dynamic viewport height if supported */
@supports (height: 100dvh) {
    .selection-panel {
        max-height: calc(100dvh - 40px);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Stronger mobile overrides for narrow viewports */
@media (max-width: 600px) {
    .selection-panel {
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        max-width: none !important;
        bottom: 10px !important;
        max-height: calc(100vh - 20px) !important;
        overflow-y: auto;
    }
}

/* Emergency fallback for ultra-small devices */
@media (max-width: 480px) and (max-height: 400px) {
    .selection-panel {
        all: unset;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100vw;
        height: 50vh;
        background: #2a2a2a;
        z-index: 9999;
        overflow-y: auto;
    }
}