/* Mobile First Base Styles */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'STIX Two Text', serif;
    background-color: #f8fafc;
    background-image: radial-gradient(#e2e8f0 1px, transparent 0);
    background-size: 20px 20px;
    overflow-x: hidden;
}

::selection { 
    background-color: #c7d2fe; 
    color: #312e81; 
}

/* --- Predicate & Chip Styling --- */
.chip {
    cursor: grab;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    border: 1px solid #c7d2fe;
}
.chip:active {
    cursor: grabbing;
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(49, 46, 129, 0.1);
}
.delete-chip {
    margin-left: 8px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: #e0e7ff;
    color: #4338ca;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s;
}
.delete-chip:hover { 
    background-color: #ef4444; 
    color: white; 
    transform: scale(1.1); 
}

/* --- Main Equation Dropzone Styling --- */
.equation-dropzone {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    gap: 12px;
    min-width: 220px;
    min-height: 80px;
    padding: 16px;
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.equation-dropzone.drag-over {
    background-color: #eef2ff;
    border-color: #4f46e5;
}
.equation-dropzone-placeholder { 
    font-style: italic; 
    color: #9ca3af; 
    font-weight: 500; 
    font-size: 1.25rem; 
}

/* --- Logical Clause Styling --- */
.logical-clause {
    position: relative;
    border: 1px solid #a5b4fc;
    padding: 12px;
    padding-top: 28px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background-color: rgba(238, 242, 255, 0.6);
}
.clause-header {
    position: absolute;
    top: 4px;
    left: 12px;
    font-weight: 700;
    color: #4338ca;
    font-size: 0.8rem;
    text-transform: uppercase;
}
.clause-delete-button {
    position: absolute;
    top: 4px;
    right: 8px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: #e0e7ff;
    color: #4338ca;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s;
}
.clause-delete-button:hover { 
    background-color: #ef4444; 
    color: white; 
    transform: scale(1.1); 
}

.clause-hole {
    min-width: 180px;
    height: 40px;
    border: 2px dashed #c7d2fe;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-style: italic;
    color: #a5b4fc;
    transition: all 0.2s;
}
.clause-hole.drag-over { 
    background-color: #c7d2fe; 
    color: #4338ca; 
}

/* --- Left Panel & Predicate Popup Styling --- */
.question-group {
    border-radius: 8px;
    transition: background-color 0.2s;
}
.question-header {
    padding: 10px 12px;
    cursor: default;
    font-size: 1rem;
    font-weight: 600;
    color: #374151;
    border-left: 3px solid transparent;
    transition: all 0.2s;
}
.question-group:hover .question-header {
    background-color: #f3f4f6;
    border-left-color: #6366f1;
}
.chip-container-popup {
    display: none;
    position: fixed;
    background-color: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
    z-index: 999;
    padding: 12px;
    flex-wrap: wrap;
    gap: 8px;
    width: fit-content;
    max-width: 80vw;
}

.chip-container-popup .chip {
    font-size: 0.875rem;
    padding: 6px 12px;
    background-color: #f1f5f9;
    border-color: #e2e8f0;
    color: #475569;
}
.chip-container-popup .chip:hover {
    background-color: #6366f1;
    border-color: #4f46e5;
    color: white;
    transform: translateY(-2px);
}
.logical-clause-template {
    cursor: grab;
    padding: 8px 14px;
    font-weight: 600;
    background-color: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    transition: all 0.2s;
}
.logical-clause-template:hover { 
    background-color: #4f46e5; 
    color: white; 
    border-color: #4f46e5; 
}
.logical-clause-template:active { 
    cursor: grabbing; 
}

/* --- Context Menu Styling --- */
.context-menu {
    display: none;
    position: absolute;
    background-color: white;
    border: 1px solid #e5e7eb;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-radius: 8px;
    z-index: 1000;
    padding: 8px 0;
    width: 180px;
}
.context-menu button {
    display: block;
    width: 100%;
    padding: 10px 16px;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.15s;
}
.context-menu button:hover { 
    background-color: #f3f4f6; 
}

/* --- Loading Spinner for Result --- */
.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid #e5e7eb;
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0.5rem auto;
}
@keyframes spin {
    to { 
        transform: rotate(360deg); 
    }
}

main.compare-mode {
    justify-content: space-around;
}

.equation-instance {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4rem;
    transition: all 0.3s ease-in-out;
}

main:not(.compare-mode) .equation-instance {
    flex-grow: 1;
}

main.compare-mode #equation-container-1,
main.compare-mode #equation-container-2 {
    transform: scale(0.85);
}

#save-modal-overlay {
    z-index: 1001;
}

.hidden {
    display: none !important;
}

/* --- Tab Navigation --- */
.tab-btn {
    flex-grow: 1;
    padding: 8px 12px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-weight: 600;
    color: #475569;
    transition: all 0.2s;
}
.tab-btn:hover {
    background-color: #f1f5f9;
    color: #1e293b;
}
.tab-btn.active {
    background-color: #4f46e5;
    color: white;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

/* --- Discover List Styling --- */
.discover-item {
    padding: 12px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background-color 0.2s;
}
.discover-item:hover {
    background-color: #eef2ff;
}
.discover-item-title {
    font-weight: 600;
    color: #1e293b;
    display: block;
}
.discover-item-author {
    font-size: 0.875rem;
    color: #64748b;
}

/* --- Preview Mode Styling --- */
#preview-view .preview-container {
    background-color: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 4xl;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    cursor: pointer;
}
#preview-view h2 {
    font-size: 1.875rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}
#preview-view h3 {
    font-size: 1rem;
    color: #64748b;
    margin-bottom: 2rem;
}
#preview-view .preview-equation {
    font-family: monospace;
    font-size: 1.125rem;
    background-color: #f8fafc;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    text-align: center;
}
#preview-view .preview-equation .op {
    color: #4f46e5;
    font-weight: bold;
}
#preview-view .preview-result {
    font-size: 1.5rem;
    font-weight: 700;
}
#preview-view .preview-cta {
    text-align: center;
    margin-top: 2rem;
    color: #64748b;
    font-style: italic;
}

#builder-view {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex-grow: 1;
    width: 100%;
}

#builder-view.hidden,
#preview-view.hidden {
    display: none;
}

#toast-notification {
    position: fixed;
    top: 2rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background-color: #334155;
    color: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 2000;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s ease-in-out, top 0.3s ease-in-out;
}
#toast-notification.show {
    opacity: 1;
    top: 3rem;
}

#save-icon {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    width: 4rem;
    height: 4rem;
    z-index: 999;
    background-color: #4f46e5;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    transition: all 0.2s ease-in-out;
}

#save-icon:hover {
    background-color: #4338ca;
    transform: scale(1.1);
}

.preview-share-btn {
    background-color: #4f46e5;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

.preview-share-btn:hover {
    background-color: #4338ca;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

.preview-share-btn:active {
    transform: translateY(0);
}

/* MOBILE STYLES - MUST COME LAST AND USE !important WHERE NEEDED */
@media (max-width: 768px) {
    /* Force body to show content properly */
    body {
        background-color: #f8fafc !important;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }
    
    /* Ensure the main container is visible */
    body > .flex {
        display: flex !important;
        flex-direction: column !important;
        height: 100vh !important;
        width: 100vw !important;
        overflow: hidden !important;
    }
    
    /* Make aside (left panel) visible and sized correctly */
    aside {
        width: 100% !important;
        height: 45vh !important;
        min-height: 45vh !important;
        max-height: 45vh !important;
        border-right: none !important;
        border-bottom: 1px solid #e2e8f0 !important;
        overflow-y: auto !important;
        flex-shrink: 0 !important;
        background: white !important;
        z-index: 10 !important;
        display: block !important;
    }
    
    /* Make main content area visible and sized correctly */
    main {
        width: 100% !important;
        height: 55vh !important;
        min-height: 55vh !important;
        max-height: 55vh !important;
        padding: 1rem !important;
        overflow-y: auto !important;
        background: white !important;
        flex-shrink: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Ensure tab content is visible */
    .tab-content {
        display: block !important;
        height: 100%;
        width: 100%;
        background: white !important;
    }
    
    .tab-content.hidden {
        display: none !important;
    }
    
    /* Preview container styling */
    #preview-view {
        width: 100% !important;
        height: 100% !important;
        padding: 1rem !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: white !important;
    }
    
    #preview-view .preview-container {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 1.5rem !important;
        background: white !important;
    }
    
    /* Discover list styling */
    #discover-list {
        padding: 0.5rem !important;
        height: 100% !important;
        overflow-y: auto !important;
        background: white !important;
    }
    
    .discover-item {
        padding: 16px 12px !important;
        margin: 0 !important;
        border-bottom: 1px solid #e2e8f0 !important;
        background: white !important;
    }
    
    .discover-item-title {
        font-size: 1.1rem !important;
        font-weight: 600 !important;
        color: #1e293b !important;
    }
    
    .discover-item-author {
        font-size: 0.9rem !important;
        color: #64748b !important;
    }
    
    /* Preview text sizing */
    #preview-view h2 {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
        color: #1e293b !important;
    }
    
    #preview-view h3 {
        font-size: 1rem !important;
        color: #64748b !important;
    }
    
    .preview-equation {
        font-size: 0.9rem !important;
        line-height: 1.4 !important;
        background-color: #f8fafc !important;
    }
    
    /* Hide desktop-only elements */
    .desktop-tabs,
    #discover-search,
    #builder-view,
    #compare-btn-container {
        display: none !important;
    }
    
    .preview-equation-container {
        flex-direction: column !important;
        gap: 0.5rem !important;
        margin-bottom: 1rem !important;
    }
    
    .preview-result {
        font-size: 1.25rem !important;
        text-align: center !important;
    }
}