/* =========================================================
   PediaHelper — Global Design System
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

:root {
    color-scheme: light;
    /* Brand palette (Red Theme) */
    --ph-navy:       #4c0519; /* Dark Red/Maroon */
    --ph-navy-mid:   #881337;
    --ph-blue:       #be123c;
    --ph-teal:       #e11d48; /* Primary action red */
    --ph-teal-dim:   #be123c;
    --ph-crimson:    #e11d48;
    --ph-crimson-dk: #be123c;
    --ph-rose-bg:    #fff1f2;
    /* Neutrals */
    --ph-bg:         #fafaf9; /* Softer, warmer off-white background */
    --ph-surface:    #ffffff;
    --ph-border:     #e5e7eb; /* Softer gray border */
    --ph-ink:        #1c1917; /* Warm dark gray */
    --ph-muted:      #57534e; /* Warm muted gray */
    --ph-soft:       #f5f5f4; /* Very subtle warm gray */
    /* Gradients */
    --ph-grad-hero:  linear-gradient(135deg, #4c0519 0%, #9f1239 100%);
    --ph-grad-card:  linear-gradient(145deg, #ffffff 0%, #fafaf9 100%);
    /* Shadows - Softer and more natural */
    --ph-shadow-sm:  0 1px 2px rgba(28,25,23,.05);
    --ph-shadow-md:  0 4px 6px -1px rgba(28,25,23,.05), 0 2px 4px -2px rgba(28,25,23,.05);
    --ph-shadow-lg:  0 10px 15px -3px rgba(28,25,23,.05), 0 4px 6px -4px rgba(28,25,23,.05);
}

/* ---- Base ---- */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--ph-bg);
    color: var(--ph-ink);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
a:focus-visible { outline: 2px solid var(--ph-teal); outline-offset: 2px; border-radius: 4px; }

/* ---- Header ---- */
.app-header {
    background: rgba(13, 27, 46, 0.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(14, 165, 233, 0.15);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 1020;
    box-shadow: 0 2px 20px rgba(13,27,46,.35);
}

.app-header .container {
    position: relative;
    min-height: 60px;
    padding-top: 0;
    padding-bottom: 0;
    gap: 1rem;
    max-width: 1280px;
    margin: 0 auto;
    padding-left: 1.25rem;
    padding-right: 1.25rem;
}

/* Brand */
.app-header .brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    color: #ffffff !important;
    font-weight: 800;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
    white-space: nowrap;
    margin: 0;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--ph-teal), #0369a1);
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(14,165,233,.4);
}

.brand-text-main { color: #ffffff; }
.brand-text-accent { color: var(--ph-teal); }

/* Nav */
.top-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: 0.5rem;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
}
.top-nav::-webkit-scrollbar { display: none; }

.top-nav a {
    color: rgba(255,255,255,0.75);
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.45rem 0.75rem;
    border-radius: 6px;
    white-space: nowrap;
    transition: background 0.18s, color 0.18s;
}
.top-nav a:hover,
.top-nav a:focus-visible {
    background: rgba(14,165,233,.15);
    color: var(--ph-teal);
}
.top-nav a.nav-active {
    background: rgba(14,165,233,.18);
    color: var(--ph-teal);
}

/* Search toggle */
.search-toggle {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.8);
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    transition: background 0.18s, color 0.18s, border-color 0.18s;
    flex: 0 0 auto;
    cursor: pointer;
}
.search-toggle:hover,
.search-toggle:focus-visible {
    background: rgba(14,165,233,.2);
    color: var(--ph-teal);
    border-color: rgba(14,165,233,.4);
}

/* Search overlay */
.search-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 27, 46, 0.65);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.22s ease, visibility 0.22s ease;
    z-index: 1050;
}
.search-overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}
.search-overlay-content {
    background: #fff;
    border: 1px solid var(--ph-border);
    border-radius: 14px;
    width: min(42rem, 92vw);
    padding: 2rem 1.5rem 1.25rem;
    box-shadow: var(--ph-shadow-lg);
    position: relative;
}
.search-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: var(--ph-soft);
    border: 1px solid var(--ph-border);
    color: var(--ph-muted);
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.16s, color 0.16s;
}
.search-close:hover { background: var(--ph-rose-bg); color: var(--ph-crimson); }

.search-label {
    font-weight: 700;
    display: block;
    margin-bottom: 0.6rem;
    font-size: 1.05rem;
    color: var(--ph-ink);
}
.search-input {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1.5px solid var(--ph-border);
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 1rem;
    font-family: inherit;
    transition: border-color 0.18s, box-shadow 0.18s;
}
.search-input:focus {
    outline: none;
    border-color: var(--ph-teal);
    box-shadow: 0 0 0 3px rgba(14,165,233,.15);
}
.search-results { list-style: none; padding: 0; margin: 0; max-height: 18rem; overflow-y: auto; }
.search-results li + li { margin-top: 0.3rem; }
.search-results a {
    display: block;
    padding: 0.7rem 0.85rem;
    border-radius: 8px;
    color: var(--ph-ink);
    font-weight: 600;
    background: var(--ph-soft);
    transition: background 0.16s, color 0.16s;
}
.search-result-name { display: block; }
.search-result-path { display: block; font-size: 0.82rem; color: var(--ph-muted); margin-top: 0.1rem; }
.search-results a:hover, .search-results a:focus-visible {
    background: rgba(14,165,233,.1);
    color: var(--ph-blue);
}
.search-empty { padding: 0.75rem 0.25rem; color: var(--ph-muted); }

body.search-open { overflow: hidden; }

/* ---- Main content area ---- */
.app-main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px 20px 48px;
}

/* ---- Footer ---- */
.footer {
    background: var(--ph-navy);
    border-top: 1px solid rgba(14,165,233,.12);
    padding: 1.25rem 0;
    text-align: center;
    color: rgba(255,255,255,0.5);
    font-size: 0.875rem;
}
.footer-links {
    display: flex;
    gap: 1.25rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}
.footer a { color: var(--ph-teal); transition: color 0.16s; }
.footer a:hover { color: #fff; }
.footer-donate { font-weight: 700; }

/* ---- Shared component overrides ---- */
.btn-primary {
    background: var(--ph-crimson);
    border: none;
    border-radius: 8px;
    font-weight: 700;
    transition: background 0.18s, transform 0.15s, box-shadow 0.18s;
}
.btn-primary:hover {
    background: var(--ph-crimson-dk);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(220,38,38,.3);
}
.btn-primary:focus-visible {
    box-shadow: 0 0 0 3px rgba(220,38,38,.3);
}

.card {
    border: 1px solid var(--ph-border);
    border-radius: 12px;
    box-shadow: var(--ph-shadow-sm);
    background: var(--ph-grad-card);
}
.card-header {
    background: var(--ph-soft);
    border-bottom: 1px solid var(--ph-border);
    font-weight: 700;
    border-radius: 12px 12px 0 0;
}
.form-control, .form-select {
    border-color: var(--ph-border);
    border-radius: 8px;
    font-family: inherit;
}
.form-control:focus, .form-select:focus {
    border-color: var(--ph-teal);
    box-shadow: 0 0 0 3px rgba(14,165,233,.15);
}
.table { --bs-table-border-color: var(--ph-border); font-size: 0.94rem; }
.table thead th {
    background: var(--ph-soft);
    color: #334155;
    font-weight: 700;
    border-bottom: 1px solid var(--ph-border);
}
.alert { border-radius: 10px; border-width: 1px; }

/* ---- Animations ---- */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(14,165,233,.3); }
    50%       { box-shadow: 0 0 0 8px rgba(14,165,233,.0); }
}

.fade-up { animation: fadeUp 0.5s ease both; }

/* ---- Responsive ---- */
@media (max-width: 576px) {
    .app-header .container {
        min-height: 54px;
        padding-left: 0.875rem;
        padding-right: 0.875rem;
        gap: 0.5rem;
        flex-wrap: wrap;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }
    .app-header .brand { font-size: 1rem; }
    .top-nav {
        order: 3;
        flex: 0 0 100%;
        margin-left: 0;
        padding-bottom: 0.25rem;
        scrollbar-width: thin;
        scrollbar-color: rgba(255,255,255,0.35) transparent;
    }
    .top-nav::-webkit-scrollbar { display: block; height: 3px; }
    .top-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.35); border-radius: 999px; }
    .top-nav a { font-size: 0.82rem; padding: 0.4rem 0.55rem; }
    .search-toggle { margin-left: auto; }
    .search-overlay-content { padding: 1.5rem 1rem 1rem; }
    .app-main { padding: 14px 12px 40px; }
}

/* ── Ask Textbook Perplexity-style Global Overrides ── */
.tb-app-centered { width: min(800px, calc(100% - 24px)); margin: 40px auto 60px; }
.tb-header-centered { text-align: center; margin-bottom: 2rem; }
.tb-header-centered h1 { margin: 0 0 8px 0; font-size: 2rem; font-weight: 900; letter-spacing: -0.02em; color: var(--ph-navy); }
.tb-header-centered p { margin: 0 0 20px 0; color: var(--ph-muted); font-size: 1.05rem; }
.tb-source-switch { display: inline-flex; background: var(--ph-soft); border: 1px solid var(--ph-border); border-radius: 12px; padding: 4px; gap: 4px; }
.tb-source-btn { border: 0; border-radius: 8px; background: transparent; color: var(--ph-muted); font-weight: 700; padding: 8px 16px; font-size: 0.9rem; cursor: pointer; transition: background 0.2s, color 0.2s, box-shadow 0.2s; }
.tb-source-btn.is-active { background: var(--ph-surface); color: var(--ph-teal-dim); box-shadow: 0 2px 6px rgba(13,27,46,.08); }
.tb-search-container { margin-bottom: 24px; }
.tb-search-box { position: relative; background: var(--ph-surface); border: 1px solid var(--ph-border); border-radius: 16px; box-shadow: 0 4px 16px rgba(13,27,46,.06), 0 1px 4px rgba(13,27,46,.04); transition: box-shadow 0.2s, border-color 0.2s; padding: 12px 12px 52px 12px; }
.tb-search-box:focus-within { border-color: var(--ph-teal); box-shadow: 0 8px 24px rgba(14,165,233,.15); }
.tb-input { width: 100%; min-height: 70px; resize: none; border: none; background: transparent; font-size: 1.05rem; line-height: 1.5; color: var(--ph-ink); padding: 8px; font-family: inherit; }
.tb-input:focus { outline: none; }
.tb-input::placeholder { color: rgba(100,116,139,.6); }
.tb-search-actions { position: absolute; bottom: 12px; right: 12px; left: 20px; display: flex; align-items: center; justify-content: space-between; }
.tb-status { color: var(--ph-muted); font-size: 0.85rem; font-weight: 600; }
.tb-action-buttons { display: flex; align-items: center; gap: 0.5rem; }
.tb-share {
    border: 1px solid var(--ph-border);
    border-radius: 50%;
    background: var(--ph-soft);
    color: var(--ph-muted);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.2s;
}
.tb-share:hover:not(:disabled) {
    background: rgba(14,165,233,.08);
    border-color: rgba(14,165,233,.35);
    color: var(--ph-teal);
    transform: translateY(-1px);
}
.tb-share:disabled { opacity: 0.55; cursor: not-allowed; }
.tb-submit { border: 0; border-radius: 50%; background: var(--ph-navy); color: #fff; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: background 0.2s, transform 0.2s; }
.tb-submit:hover:not(:disabled) { background: var(--ph-teal); transform: translateY(-1px); }
.tb-submit:disabled { opacity: 0.5; cursor: wait; }
.tb-examples { margin-top: 16px; }
.tb-examples-title { color: var(--ph-muted); font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; text-align: center; }
.tb-example-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.tb-example { border: 1px solid var(--ph-border); background: var(--ph-soft); border-radius: 999px; color: var(--ph-muted); padding: 6px 14px; font-size: 0.85rem; font-weight: 600; cursor: pointer; transition: border-color 0.2s, background 0.2s, color 0.2s; }
.tb-example:hover { border-color: rgba(14,165,233,.3); background: rgba(14,165,233,.05); color: var(--ph-blue); }
.tb-answer-empty { min-height: 200px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--ph-muted); padding: 28px; margin-top: 2rem; }
.tb-answer-empty i { font-size: 2.5rem; color: #cbd5e1; margin-bottom: 16px; }
.tb-result-container { margin-top: 30px; display: none; }
.tb-result-container.is-visible { display: block; animation: fadeUp 0.4s ease both; }
.tb-answer-card { background: var(--ph-surface); border: 1px solid var(--ph-border); border-radius: 16px; box-shadow: var(--ph-shadow-md); overflow: hidden; }
.tb-card-head { padding: 16px 20px; border-bottom: 1px solid var(--ph-border); display: flex; align-items: center; justify-content: space-between; background: var(--ph-soft); }
.tb-card-title { font-size: 0.85rem; color: var(--ph-navy); font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; margin: 0; display: flex; align-items: center; gap: 8px; }
.tb-badge { border-radius: 999px; padding: 4px 10px; background: rgba(14,165,233,.12); color: var(--ph-teal-dim); font-size: 0.75rem; font-weight: 800; white-space: nowrap; }
.tb-answer-body { padding: 24px; font-size: 1.05rem; line-height: 1.7; color: var(--ph-ink); }
.tb-answer-body h1,
.tb-answer-body h2,
.tb-answer-body h3,
.tb-answer-body h4 {
    color: var(--ph-navy);
    font-weight: 850;
    line-height: 1.25;
    margin: 1.35rem 0 0.65rem;
    letter-spacing: 0;
}
.tb-answer-body h1:first-child,
.tb-answer-body h2:first-child,
.tb-answer-body h3:first-child,
.tb-answer-body h4:first-child { margin-top: 0; }
.tb-answer-body h1 { font-size: 1.65rem; padding-bottom: 0.45rem; border-bottom: 1px solid var(--ph-border); }
.tb-answer-body h2 { font-size: 1.35rem; padding-bottom: 0.35rem; border-bottom: 1px solid var(--ph-border); }
.tb-answer-body h3 { font-size: 1.15rem; }
.tb-answer-body h4 { font-size: 1.05rem; }
.tb-answer-body p,
.tb-answer-body ul,
.tb-answer-body ol,
.tb-answer-body table,
.tb-answer-body blockquote { margin: 0 0 1rem; }
.tb-answer-body ul,
.tb-answer-body ol { padding-left: 1.45rem; }
.tb-answer-body li { margin: 0.25rem 0; }
.tb-answer-body li > ul,
.tb-answer-body li > ol { margin: 0.25rem 0 0.35rem; }
.tb-answer-body hr {
    border: 0;
    border-top: 1px solid var(--ph-border);
    margin: 1.5rem 0;
}
.tb-answer-body code,
.tb-note-text code,
.ev-limitations-content code,
.ev-takeaway-content code {
    background: var(--ph-soft);
    border: 1px solid var(--ph-border);
    border-radius: 4px;
    padding: 0.08em 0.32em;
    font-size: 0.92em;
}
.tb-answer-body pre {
    background: var(--ph-soft);
    border: 1px solid var(--ph-border);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
}
.tb-answer-body pre code { border: 0; padding: 0; background: transparent; }
.tb-answer-body blockquote {
    border-left: 3px solid var(--ph-teal);
    background: rgba(14,165,233,.06);
    padding: 0.75rem 1rem;
    color: var(--ph-muted);
}
.tb-answer-body table {
    width: 100%;
    border-collapse: collapse;
    display: block;
    overflow-x: auto;
}
.tb-answer-body th,
.tb-answer-body td {
    border: 1px solid var(--ph-border);
    padding: 0.55rem 0.7rem;
    vertical-align: top;
}
.tb-answer-body th {
    background: var(--ph-soft);
    color: var(--ph-navy);
    font-weight: 800;
}
.tb-answer-body p:last-child,
.tb-answer-body ul:last-child,
.tb-answer-body ol:last-child,
.tb-answer-body table:last-child,
.tb-answer-body blockquote:last-child { margin-bottom: 0; }
.tb-note-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 0 24px 24px; }
.tb-note { border: 1px solid var(--ph-border); border-radius: 12px; background: var(--ph-soft); padding: 16px; }
.tb-note-label { color: var(--ph-muted); font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.tb-note-text { font-size: 0.95rem; line-height: 1.5; color: var(--ph-ink); }

/* ── Evidence Warning and Take-away Boxes ── */
.ev-limitations-box { background: #fffcf0; border: 1px solid #fde08b; border-radius: 8px; padding: 16px; color: #78350f; font-size: 0.95rem; margin: 0 24px 16px 24px; display: flex; gap: 12px; align-items: flex-start; }
.ev-limitations-box i { color: #b45309; font-size: 1.1rem; margin-top: 2px; }
.ev-limitations-content p:last-child { margin-bottom: 0; }
.ev-takeaway-box { background: #fff1f2; border: 1px solid #ffe4e6; border-left: 3px solid #e11d48; border-radius: 8px; padding: 16px; color: #4c0519; font-size: 0.95rem; margin: 0 24px 24px 24px; display: flex; gap: 12px; align-items: baseline; }
.ev-takeaway-label { color: #e11d48; font-weight: 800; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; }
.ev-takeaway-content { flex-grow: 1; }
.ev-takeaway-content p:last-child { margin-bottom: 0; }

.tb-sources { list-style: none; padding: 20px; margin: 0; display: grid; gap: 12px; max-height: 420px; overflow: auto; }
.tb-source-item { border: 1px solid var(--ph-border); border-radius: 10px; background: var(--ph-surface); padding: 14px; }
.tb-source-title { font-weight: 800; color: var(--ph-navy); margin-bottom: 4px; font-size: 0.95rem; }
.tb-source-meta { color: var(--ph-muted); font-size: 0.85rem; margin-bottom: 10px; }
.tb-source-snippet { color: var(--ph-ink); font-size: 0.9rem; line-height: 1.55; background: var(--ph-soft); padding: 12px; border-radius: 8px; }
.cite-chip { color: var(--ph-teal-dim); font-weight: 700; text-decoration: none; background: rgba(14,165,233,.08); padding: 0 4px; border-radius: 4px; margin: 0 2px; }
.cite-chip:hover { background: rgba(14,165,233,.15); }
.tb-error { color: var(--ph-crimson); }
@media (max-width: 768px) { .tb-note-grid { grid-template-columns: 1fr; } }

/* ── Ask Textbook Loading Animation ── */
.tb-loading-container { display: flex; align-items: center; gap: 10px; }
.tb-loading-text { color: var(--ph-teal-dim); font-weight: 700; font-size: 0.85rem; animation: pulse 1.5s infinite ease-in-out; }
.tb-loading-bar { width: 120px; height: 4px; background: var(--ph-border); border-radius: 2px; overflow: hidden; position: relative; }
.tb-loading-bar::after { content: ""; position: absolute; top: 0; left: -100%; width: 50%; height: 100%; background: var(--ph-teal); border-radius: 2px; animation: slideProgress 1.5s infinite ease-in-out; }

.seo-support {
    margin: 2rem 0;
    padding: 1.35rem;
    border: 1px solid var(--ph-border);
    border-radius: 8px;
    background: #fff;
}

.seo-support h2 {
    font-size: 1.2rem;
    margin: 0 0 0.75rem;
    color: var(--ph-navy);
}

.seo-support p {
    color: var(--ph-muted);
    margin-bottom: 0.85rem;
}

.seo-references ul {
    margin: 0;
    padding-left: 1.15rem;
}

.seo-references li {
    margin-bottom: 0.55rem;
}

.seo-references li span {
    display: block;
    color: var(--ph-muted);
    font-size: 0.92rem;
}

.seo-link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 0.75rem;
}

.seo-link-grid a {
    display: block;
    padding: 0.85rem;
    border: 1px solid var(--ph-border);
    border-radius: 8px;
    color: var(--ph-text);
    text-decoration: none;
    background: var(--ph-soft);
}

.seo-link-grid a:hover {
    border-color: var(--ph-teal);
    color: var(--ph-navy);
}

.seo-link-grid span {
    display: block;
    color: var(--ph-muted);
    font-size: 0.9rem;
    margin-top: 0.2rem;
}

.seo-faq details {
    border-top: 1px solid var(--ph-border);
    padding: 0.85rem 0;
}

.seo-faq details:first-of-type {
    border-top: 0;
}

.seo-faq summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--ph-text);
}

.seo-faq details p {
    margin: 0.65rem 0 0;
}
@keyframes slideProgress { 0% { left: -50%; } 100% { left: 100%; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }
