/* Math Problems Database - Stylesheet */

/* Atkinson Hyperlegible Next font */
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400;1,700&display=swap');

* {
    box-sizing: border-box;
}

body {
    font-family: "Atkinson Hyperlegible", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background: #f5f5f5;
    color: #333;
}

header {
    background: #2c3e50;
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-title {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 400;
}

.byline {
    font-size: 0.85rem;
    opacity: 0.8;
    font-style: italic;
    margin-left: 0.75rem;
}

.byline-link {
    color: inherit;
    text-decoration: none;
}

.byline-link:hover {
    text-decoration: underline;
}

.header-title-link {
    color: inherit;
    text-decoration: none;
}

.header-title-link:hover {
    text-decoration: underline;
}

nav {
    display: flex;
    gap: 0.5rem;
}

.tab-btn {
    background: transparent;
    border: 2px solid rgba(255,255,255,0.3);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: rgba(255,255,255,0.1);
}

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

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Search Controls */
.search-controls {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.problem-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
}

.problem-side {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.search-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.search-row input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.search-row button {
    background: #3498db;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
}

.search-row button:hover {
    background: #2980b9;
}

.regex-help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: #95a5a6;
    color: white;
    border-radius: 50%;
    font-size: 0.85rem;
    font-weight: bold;
    text-decoration: none;
    cursor: pointer;
}

.regex-help:hover {
    background: #7f8c8d;
}

.regex-popup {
    background: #fefefe;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1rem;
    margin-top: 0.5rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    font-size: 0.9rem;
}

.regex-popup.hidden {
    display: none;
}

.regex-popup ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.regex-popup code {
    background: #f0f0f0;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-family: monospace;
}

.filter-row {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.tag-filter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 200px;
}

.tag-filter label {
    font-size: 0.9rem;
    color: #666;
}

.llm-close-btn {
    border: none;
    background: transparent;
    font-size: 0.9rem;
    cursor: pointer;
    color: #999;
    padding: 0 0.25rem;
}

.llm-close-btn:hover {
    color: #666;
}

.llm-entry-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    border: none;
    background: transparent;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0;
    color: #666;
}

.llm-entry-arrow {
    font-size: 0.7rem;
}

.llm-filter-select {
    font-size: 0.75rem;
    margin-left: 0.5rem;
}

.tag-filter input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* Course filter dropdown */
.course-filter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.course-filter label {
    font-size: 0.9rem;
    color: #666;
}

.course-dropdown {
    position: relative;
}

.course-dropdown-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 0.9rem;
    min-width: 140px;
    justify-content: space-between;
}

.course-dropdown-btn:hover {
    border-color: #bbb;
}

.dropdown-arrow {
    font-size: 0.6rem;
    color: #888;
}

.course-dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-width: 180px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100;
    margin-top: 2px;
}

.course-dropdown-content.show {
    display: block;
}

.course-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.course-dropdown-item:hover {
    background: #f5f5f5;
}

.course-dropdown-item input {
    cursor: pointer;
}

.course-dropdown-item.all-item {
    border-bottom: 1px solid #eee;
    font-weight: 500;
}

/* Results */
.results-container {
    min-height: 200px;
}

.placeholder {
    text-align: center;
    color: #999;
    padding: 3rem;
}

/* Landing panel shown when there is no active search */
.landing {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.landing h2 {
    margin-top: 0;
    font-size: 1.3rem;
}

.landing h3 {
    margin-top: 1rem;
    font-size: 1rem;
}

.landing ul {
    margin: 0.5rem 0 1rem 1.25rem;
    padding: 0;
}

.landing li {
    margin-bottom: 0.35rem;
}

.landing.hidden {
    display: none;
}

/* Problem Card */
.problem-card {
    background: white;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.problem-header {
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.problem-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid #eee;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.problem-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: #666;
}

.problem-code {
    font-family: monospace;
    color: #555;
}

.problem-source {
    color: #888;
}

.problem-meta-separator {
    color: #ccc;
}

.problem-code-link {
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.problem-code-link:hover {
    color: #3498db;
}

.problem-code-link:hover .problem-code,
.problem-code-link:hover .problem-source {
    color: #3498db;
}

.cart-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.cart-checkbox input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.cart-checkbox label {
    font-size: 0.85rem;
    color: #666;
    cursor: pointer;
}

.problem-content {
    line-height: 1.7;
    overflow-x: auto;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 12pt;
    flex: 2;
    min-width: 0;
}

.latex-content {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 12pt;
}

.problem-latex-raw {
    flex: 1;
}

.problem-latex-raw.hidden {
    display: none;
}

.problem-llm-answer.hidden {
    display: none;
}

.latex-raw-pre {
    font-family: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.8rem;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 0.5rem;
    margin: 0;
    max-height: 300px;
    overflow: auto;
    white-space: pre-wrap;
}

.llm-answer-box {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 0.9rem;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 0.5rem;
    margin: 0 auto;
    width: 100%;
    max-width: 70ch;
    max-height: min(60vh, 400px);
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: auto;
}

.llm-answer-box.hidden {
    display: none;
}

/* Constrain latex-content inside LLM answer boxes to prevent MathJax from
   creating extremely wide elements that push content off-screen. */
.llm-answer-box .latex-content {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* Force MathJax containers to respect parent width and allow scrolling */
.llm-answer-box mjx-container {
    max-width: 100% !important;
    overflow-x: auto !important;
}

.llm-answer-box mjx-container[display="true"] {
    display: block !important;
    overflow-x: auto !important;
    max-width: 100% !important;
}

/* Ensure the LLM answer entry and parent containers have constrained width */
.llm-answer-entry {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.problem-llm-answer {
    width: 100%;
    max-width: 85%;
    margin: 0.5rem auto 0.75rem auto;
    padding: 0.5rem 0.75rem;
    background: #f2f2f6;
    border: 1px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
}

.latex-raw-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
    font-size: 0.75rem;
    color: #666;
}

.llm-filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.5rem;
    align-items: center;
}

.llm-filter-option {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.7rem;
    color: #777;
}

.llm-filter-option input {
    width: 12px;
    height: 12px;
}

/* Make nested enumerate lists look better */
.problem-content ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.problem-content li {
    margin-bottom: 0.3rem;
}

.latex-section {
    margin-top: 0.75rem;
    font-size: 0.95rem;
}

.latex-subsection {
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.latex-subsubsection {
    margin-top: 0.4rem;
    font-size: 0.85rem;
    font-style: italic;
}

.problem-tags {
    flex: 1;
}

.tag {
    display: inline-block;
    background: #e8f4f8;
    color: #2980b9;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
    margin: 0.2rem;
    cursor: pointer;
}

.tag:hover {
    background: #d0e8f0;
}

/* Edit link */
.edit-link {
    font-size: 0.8rem;
    color: #888;
    text-decoration: none;
    margin-right: 8px;
}

.edit-link:hover {
    color: #4a90d9;
    text-decoration: underline;
}

/* Similar link - subtle button style matching latex-toggle-btn */
.similar-link {
    font-size: 0.75rem;
    color: #333;
    text-decoration: none;
    margin-left: 6px;
    padding: 2px 8px;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: #f8f8f8;
    cursor: pointer;
    transition: all 0.15s ease;
}

.similar-link:hover {
    color: #111;
    border-color: #999;
    background: #eee;
}

.latex-toggle-btn {
    font-size: 0.75rem;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 3px;
    border: 1px solid #ccc;
    background: #f8f8f8;
    cursor: pointer;
}

.latex-toggle-btn:hover {
    background: #eee;
    border-color: #999;
}

.latex-copy-btn {
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 3px;
    border: 1px solid #ccc;
    background: #f8f8f8;
    cursor: pointer;
}

.latex-copy-btn:hover {
    background: #eee;
    border-color: #999;
}

/* Drag and drop for cart */
.draggable-card {
    position: relative;
    cursor: grab;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    margin-left: 24px;
}

.draggable-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.draggable-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.drag-handle {
    position: absolute;
    left: -24px;
    top: 50%;
    transform: translateY(-50%);
    color: #bbb;
    font-size: 18px;
    cursor: grab;
    user-select: none;
    letter-spacing: -2px;
    padding: 8px 4px;
}

.draggable-card:hover .drag-handle {
    color: #666;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
}

.pagination.hidden {
    display: none;
}

.pagination button {
    background: #3498db;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
}

.pagination button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

#pageInfo {
    font-size: 0.9rem;
    color: #666;
}

/* Cart */
.cart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.cart-header h2 {
    margin: 0;
    margin-left: 24px; /* Align heading with draggable cart cards (which have margin-left: 24px) */
    font-weight: 400;
}

.cart-actions {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.cart-option {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: #555;
}

.cart-option input {
    margin: 0;
}

.export-btn {
    background: #27ae60;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
}

.export-btn:hover {
    background: #219a52;
}

.clear-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
}

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

/* Tags Cloud */
.tags-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    background: white;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.tag-cloud-item {
    display: inline-block;
    background: #e8f4f8;
    color: #2980b9;
    padding: 0.4rem 0.8rem;
    border-radius: 16px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.tag-cloud-item:hover {
    background: #3498db;
    color: white;
}

.tag-cloud-item .count {
    opacity: 0.7;
    font-size: 0.8rem;
}

.tags-note {
    font-size: 0.85rem;
    color: #777;
    margin: 0.25rem 0 0.75rem 0;
}

/* Problem graphics */
.problem-graphics {
    margin-top: 0.75rem;
}

.problem-graphics img {
    max-width: 100%;
    max-height: 300px;
    height: auto;
    border: 1px solid #eee;
    border-radius: 4px;
}

.graphic-container {
    display: inline-block;
    position: relative;
    margin: 0.5rem 0.5rem 0.5rem 0;
}

.download-link {
    display: block;
    font-size: 0.75rem;
    text-align: center;
    margin-top: 0.25rem;
    color: #3498db;
}

/* KaTeX overrides for better display */
.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.5rem 0;
}

/* Responsive */
@media (max-width: 600px) {
    header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .problem-header {
        flex-direction: column;
        gap: 0.5rem;
    }

    .problem-body {
        flex-direction: column;
    }
    
    .cart-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }

    /* On phones, let LLM answer boxes use full width and a taller portion
       of the viewport while slightly reducing font size for readability. */
    .llm-answer-box {
        max-width: 100%;
        max-height: 70vh;
        font-size: 0.85rem;
    }
}
