/* Mobile-First Basketball Playbook Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #ff6b35, #f7931e, #ff4081);
    min-height: 100vh;
    color: #333;
    overflow-x: hidden;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 100vw;
}

/* Header Styles */
.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.basketball-icon {
    font-size: 1.5rem;
}

.header h1 {
    font-size: 1.2rem;
    color: #d32f2f;
    text-align: center;
    background: linear-gradient(45deg, #d32f2f, #ff6f00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Mobile Toolbar */
.mobile-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.tool-group {
    display: flex;
    gap: 0.25rem;
    flex: 1;
    justify-content: flex-start;
}

.action-group {
    display: flex;
    gap: 0.25rem;
}

.tool-btn, .action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    min-height: 60px;
    padding: 0.5rem;
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.75rem;
    font-weight: 500;
    color: #666;
    touch-action: manipulation;
}

.tool-btn:active, .action-btn:active {
    transform: scale(0.95);
}

.tool-btn.active {
    background: #d32f2f;
    color: white;
    border-color: #d32f2f;
}

.tool-icon, .action-icon {
    font-size: 1.2rem;
    margin-bottom: 0.2rem;
}

.tool-label, .action-label {
    font-size: 0.7rem;
    line-height: 1;
}

/* AI Actions */
.ai-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ai-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 50px;
    padding: 0.75rem 1rem;
    background: linear-gradient(45deg, #ff6f00, #ffb300) !important;
    color: white !important;
    border: none !important;
    border-radius: 25px;
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 111, 0, 0.3);
    touch-action: manipulation;
}

.ai-btn:active {
    transform: scale(0.98);
}

.ai-btn:disabled {
    background: #ccc !important;
    cursor: not-allowed;
    opacity: 0.6;
}

.ai-icon {
    font-size: 1.2rem;
}

.export-group {
    display: flex;
    gap: 0.5rem;
}

.export-btn, .share-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    min-height: 44px;
    padding: 0.6rem 0.8rem;
    background: #4caf50;
    color: white;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.export-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.export-btn:active, .share-btn:active {
    transform: scale(0.95);
}

.share-btn {
    background: #2196f3;
}

.export-icon, .share-icon {
    font-size: 1rem;
}

.export-text, .share-text {
    font-size: 0.75rem;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 100vw;
}

/* Canvas Container */
.canvas-container {
    position: relative;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    touch-action: none;
}

#basketball-court {
    display: block;
    width: 100%;
    height: auto;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.touch-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 1;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    z-index: 10;
}

.loading-overlay.hidden {
    display: none;
}

.loading-content {
    text-align: center;
    color: white;
    padding: 2rem;
}

.basketball-loader {
    font-size: 3rem;
    margin-bottom: 1rem;
    animation: bounce 1s infinite;
}

.loading-text {
    font-size: 1rem;
    margin-bottom: 1rem;
    font-weight: 500;
}

.loading-bar {
    width: 200px;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
    margin: 0 auto;
}

.loading-progress {
    height: 100%;
    background: linear-gradient(90deg, #ff6f00, #ffb300);
    border-radius: 4px;
    width: 0%;
    animation: loadingProgress 4s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

@keyframes loadingProgress {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

/* Visualization Section */
.visualization-section {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.visualization-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #d32f2f;
    font-size: 1.1rem;
    font-weight: 600;
}

.section-icon {
    font-size: 1.2rem;
}

.visualization-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.mobile-select {
    padding: 0.5rem;
    border: 2px solid #ddd;
    border-radius: 20px;
    font-size: 0.8rem;
    background: white;
    color: #666;
    min-width: 140px;
}

.control-btn {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.5rem 0.8rem;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.control-btn:not(:disabled):active {
    transform: scale(0.95);
}

.control-icon {
    font-size: 1rem;
}

.control-text {
    font-size: 0.75rem;
}

/* Visualization Display */
.visualization-display {
    border: 2px dashed #ddd;
    border-radius: 12px;
    min-height: 200px;
    overflow: hidden;
}

.visualization-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 300px;
    text-align: center;
    color: #666;
    padding: 2rem;
}

.placeholder-content {
    max-width: 300px;
}

.placeholder-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.7;
}

.placeholder-title {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: #333;
}

.placeholder-steps {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.step {
    font-size: 0.9rem;
    color: #666;
    text-align: left;
}

.visualization-result {
    padding: 1rem;
}

.image-container {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
}

.image-container.zoomed .visualization-image {
    transform: scale(1.5);
    transition: transform 0.3s ease;
}

.visualization-image {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.3s ease;
    touch-action: pinch-zoom;
}

.image-controls {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

.zoom-btn {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.4rem 0.8rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    touch-action: manipulation;
}

.zoom-icon {
    font-size: 1rem;
}

.zoom-text {
    font-size: 0.75rem;
}

.visualization-info {
    margin-top: 1rem;
}

.visualization-prompt {
    font-size: 0.85rem;
    color: #666;
    font-style: italic;
    line-height: 1.4;
}

.visualization-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 300px;
    text-align: center;
    color: #666;
    padding: 2rem;
}

.error-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.7;
}

.error-title {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: #333;
}

.error-message {
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    line-height: 1.4;
}

.retry-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    background: #ff6f00;
    color: white;
    border: none;
    border-radius: 25px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.retry-btn:active {
    transform: scale(0.95);
}

.retry-icon {
    font-size: 1rem;
}

.retry-text {
    font-size: 0.9rem;
}

/* Settings Panel */
.settings-panel {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: rgba(211, 47, 47, 0.1);
    border-bottom: 1px solid #eee;
    cursor: pointer;
    touch-action: manipulation;
}

.panel-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #d32f2f;
    font-size: 1rem;
    font-weight: 600;
}

.panel-icon {
    font-size: 1.2rem;
}

.panel-toggle {
    background: none;
    border: none;
    color: #d32f2f;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem;
    touch-action: manipulation;
}

.toggle-icon {
    transition: transform 0.3s ease;
}

.panel-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.panel-content.expanded {
    max-height: 1000px;
    padding: 1rem;
}

.section {
    margin-bottom: 1.5rem;
}

.section:last-child {
    margin-bottom: 0;
}

.subsection-title {
    color: #333;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid #eee;
}

/* Instructions */
.instruction-list {
    list-style: none;
    padding: 0;
}

.instruction-list li {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem 0;
    font-size: 0.85rem;
    color: #555;
    line-height: 1.3;
}

.instruction-icon {
    font-size: 1rem;
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.instruction-text {
    flex: 1;
}

/* Players */
.player-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: rgba(211, 47, 47, 0.1);
    border-radius: 8px;
    border-left: 3px solid #d32f2f;
}

.player-circle {
    width: 28px;
    height: 28px;
    background: #d32f2f;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.8rem;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.player-name {
    font-size: 0.8rem;
    color: #333;
    font-weight: 500;
    line-height: 1.2;
}

/* Settings */
.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: #555;
    touch-action: manipulation;
}

.setting-item input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 18px;
    height: 18px;
    background: white;
    border: 2px solid #ddd;
    border-radius: 4px;
    position: relative;
    transition: all 0.2s ease;
}

.setting-item input[type="checkbox"]:checked + .checkmark {
    background: #d32f2f;
    border-color: #d32f2f;
}

.setting-item input[type="checkbox"]:checked + .checkmark::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 0.8rem;
    font-weight: bold;
}

.setting-label {
    flex: 1;
}

.ai-settings {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.setting-row {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.setting-label-block {
    font-size: 0.8rem;
    font-weight: 600;
    color: #666;
}

/* Play Library */
.play-library {
    max-height: 300px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.library-placeholder {
    text-align: center;
    padding: 2rem;
}

.library-placeholder-text {
    color: #666;
    font-style: italic;
    font-size: 0.85rem;
}

.library-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    background: rgba(255, 111, 0, 0.1);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 3px solid #ff6f00;
    touch-action: manipulation;
}

.library-item:active {
    transform: scale(0.98);
}

.library-thumbnail {
    width: 60px;
    height: 45px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #ddd;
    flex-shrink: 0;
}

.library-info {
    flex: 1;
    min-width: 0;
}

.library-title {
    font-size: 0.85rem;
    margin-bottom: 0.2rem;
    color: #333;
    font-weight: 600;
}

.library-date {
    font-size: 0.75rem;
    color: #666;
}

/* Footer */
.footer {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    text-align: center;
    padding: 1rem;
    color: #555;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.footer-tip {
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    line-height: 1.3;
}

.footer-credit {
    font-size: 0.8rem;
}

.footer a {
    color: #d32f2f;
    text-decoration: none;
    font-weight: 500;
}

.footer a:hover {
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 480px) {
    .header {
        padding: 0.75rem;
    }
    
    .header h1 {
        font-size: 1rem;
    }
    
    .tool-btn, .action-btn {
        min-width: 50px;
        min-height: 50px;
        font-size: 0.7rem;
    }
    
    .tool-icon, .action-icon {
        font-size: 1rem;
    }
    
    .tool-label, .action-label {
        font-size: 0.65rem;
    }
    
    .ai-btn {
        font-size: 0.9rem;
        padding: 0.6rem 0.8rem;
    }
    
    .export-btn, .share-btn {
        font-size: 0.75rem;
        padding: 0.5rem 0.6rem;
    }
    
    .main-content {
        padding: 0.75rem;
    }
    
    .visualization-section, .settings-panel {
        padding: 0.75rem;
    }
    
    .player-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.4rem;
    }
    
    .player-item {
        padding: 0.4rem;
    }
    
    .player-circle {
        width: 24px;
        height: 24px;
        font-size: 0.7rem;
    }
    
    .player-name {
        font-size: 0.75rem;
    }
}

@media (max-width: 360px) {
    .tool-group {
        flex-wrap: wrap;
    }
    
    .tool-btn, .action-btn {
        min-width: 45px;
        min-height: 45px;
    }
    
    .export-group {
        flex-direction: column;
        gap: 0.3rem;
    }
    
    .main-content {
        padding: 0.5rem;
    }
}

/* Landscape orientation adjustments */
@media (orientation: landscape) and (max-height: 600px) {
    .header {
        padding: 0.5rem;
    }
    
    .main-content {
        padding: 0.5rem;
    }
    
    .visualization-placeholder {
        height: 200px;
    }
    
    .placeholder-icon {
        font-size: 2rem;
    }
    
    .placeholder-title {
        font-size: 1rem;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .tool-icon, .action-icon, .ai-icon, .export-icon {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .header, .visualization-section, .settings-panel, .footer {
        background: rgba(30, 30, 30, 0.95);
        color: #e0e0e0;
    }
    
    .header h1, .section-title, .panel-title {
        color: #ff6b35;
    }
    
    .tool-btn, .action-btn {
        background: #333;
        color: #e0e0e0;
        border-color: #555;
    }
    
    .tool-btn.active {
        background: #ff6b35;
        border-color: #ff6b35;
    }
    
    .mobile-select, .control-btn {
        background: #333;
        color: #e0e0e0;
        border-color: #555;
    }
    
    .canvas-container {
        background: #2a2a2a;
    }
    
    .visualization-display {
        border-color: #555;
    }
    
    .player-item, .library-item {
        background: rgba(255, 107, 53, 0.15);
        color: #e0e0e0;
    }
    
    .instruction-text, .player-name, .library-title, .setting-label {
        color: #e0e0e0;
    }
    
    .subsection-title {
        color: #e0e0e0;
        border-bottom-color: #555;
    }
    
    .checkmark {
        background: #333;
        border-color: #555;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .basketball-loader {
        animation: none;
    }
    
    .loading-progress {
        animation: none;
    }
}

/* Focus styles for accessibility */
.tool-btn:focus,
.action-btn:focus,
.ai-btn:focus,
.export-btn:focus,
.share-btn:focus,
.control-btn:focus,
.retry-btn:focus,
.zoom-btn:focus,
.panel-toggle:focus,
.library-item:focus {
    outline: 2px solid #ff6b35;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .tool-btn, .action-btn {
        border-width: 3px;
    }
    
    .tool-btn.active {
        background: #000;
        color: #fff;
        border-color: #000;
    }
    
    .ai-btn {
        background: #000 !important;
        border: 3px solid #fff !important;
    }
    
    .export-btn {
        background: #000 !important;
        border: 2px solid #fff !important;
    }
}