/* PulseCore Lexicon: the index (/lexicon/) and a term (/lexicon/<slug>).
   Loaded after public/home.css, which supplies the tokens (--bg, --line,
   --phase-*), body.home, .wrap, .eyebrow, .lede and .btn. The look follows
   the book's glossary (public/book.css, .gl-*) and the data pages
   (public/data.css): flat near-black, thin lines, accents only from the
   three phase colours. (2026-10-28: replaced the gradient-panel styles that
   lived inline in both pages.) */

.lexicon-page {
    /* Symbols and formulas are set in the body face, as in the glossary: a
       monospace face spaced them out and lacked most of the book's glyphs. */
    --lx-mono: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Arial, "PC Glyphs", sans-serif;
    --lx-r: 10px;
}
.lexicon-page .wrap { width: 100%; }

/* Category colours, three phases only: the foundations in pink, the
   mathematics in cyan, the rest in the purple between them. */
.lexicon-page [data-category],
.lexicon-page .category-badge { --cat: var(--text-dim); }
.lexicon-page [data-category="fundamental"], .lexicon-page .category-badge.fundamental,
.lexicon-page [data-category="principle"],   .lexicon-page .category-badge.principle,
.lexicon-page [data-category="law"],         .lexicon-page .category-badge.law { --cat: var(--phase-0); }
.lexicon-page [data-category="equation"],    .lexicon-page .category-badge.equation,
.lexicon-page [data-category="constant"],    .lexicon-page .category-badge.constant,
.lexicon-page [data-category="symbol"],      .lexicon-page .category-badge.symbol,
.lexicon-page [data-category="operator"],    .lexicon-page .category-badge.operator,
.lexicon-page [data-category="function"],    .lexicon-page .category-badge.function { --cat: var(--phase-1); }
.lexicon-page [data-category="structure"],   .lexicon-page .category-badge.structure,
.lexicon-page [data-category="process"],     .lexicon-page .category-badge.process,
.lexicon-page [data-category="property"],    .lexicon-page .category-badge.property,
.lexicon-page [data-category="concept"],     .lexicon-page .category-badge.concept,
.lexicon-page [data-category="manuscript"],  .lexicon-page .category-badge.manuscript { --cat: var(--phase-mid); }

/* Chips, as on the data pages. */
.lexicon-page .category-badge,
.lexicon-page .chapter-badge {
    display: inline-block;
    padding: 2px 9px;
    font-size: 0.72rem;
    font-weight: 500;
    line-height: 1.5;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
}
.lexicon-page .category-badge { color: var(--cat); border-color: color-mix(in srgb, var(--cat) 40%, var(--line)); }
.lexicon-page .chapter-badge { color: var(--text-dim); letter-spacing: 0.02em; text-transform: none; }
.lexicon-page .category-badge:empty, .lexicon-page .chapter-badge:empty { display: none; }

/* Importance: five small marks, filled in cyan. */
.lexicon-page .importance-stars { display: inline-flex; gap: 2px; line-height: 1; }
.lexicon-page .star { color: var(--phase-1); font-size: 0.78rem; }
.lexicon-page .star.empty { color: var(--line); }

/* =================================================================
   Index
   ================================================================= */

.lexicon-container {
    padding-top: 54px;
    /* The consent bar sits over the bottom of the page and hid the load-more
       button behind it. The site bar publishes how much of it is showing;
       this keeps the end of the list clear of it. */
    padding-bottom: calc(var(--pc-consent-h, 0px) + 72px);
    min-height: 70vh;
}

.lexicon-header {
    margin-bottom: 34px;
    padding-bottom: 26px;
    border-bottom: 1px solid var(--line);
}
.lexicon-header h1 {
    margin: 0 0 14px;
    font-size: clamp(2.1rem, 5.4vw, 3.3rem);
    line-height: 1.08;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}
.lexicon-subtitle { margin: 0; max-width: 62ch; }
.lexicon-links { margin: 12px 0 0; font-size: 0.9rem; color: var(--text-mute); }
.lexicon-links a { color: var(--phase-1); }
.lexicon-links a:hover { color: var(--text); }

/* Search and filters, in one raised strip like the data pages'. */
.control-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
    margin: 0 0 14px;
    padding: 14px 16px;
    background: var(--bg-raise);
    border: 1px solid var(--line);
    border-radius: 12px;
}
.search-container { position: relative; flex: 1 1 320px; min-width: 0; }
.search-icon {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    color: var(--text-mute);
    pointer-events: none;
}
.search-icon svg { width: 16px; height: 16px; }
.search-input,
.filter-select {
    font-family: inherit;
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: 9px;
}
.search-input {
    width: 100%;
    padding: 11px 14px 11px 38px;
    font-size: 0.98rem;
}
.search-input::placeholder { color: var(--text-mute); }
.search-input:focus,
.filter-select:focus {
    outline: none;
    border-color: var(--phase-1);
    box-shadow: 0 0 0 3px rgba(53, 232, 224, 0.12);
}
.filter-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.filter-select {
    padding: 10px 34px 10px 12px;
    font-size: 0.9rem;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239aa1ad' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}
.filter-select option { background: var(--bg-card); color: var(--text); }

/* Grid / Table, as a pair of the glossary's tabs. */
.view-toggle {
    display: inline-flex;
    gap: 4px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--bg-card);
}
.view-btn {
    padding: 6px 14px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.86rem;
    cursor: pointer;
}
.view-btn:hover { color: var(--text); }
.view-btn.active { color: var(--bg); background: var(--phase-1); }
.view-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(53, 232, 224, 0.35); }

.stats-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 18px;
    margin: 0 0 22px;
    padding: 0 2px;
    font-size: 0.88rem;
}
.stats-info { color: var(--text-mute); }
.stats-count { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.lexicon-content { min-height: 50vh; }

/* Cards */
.terms-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
}
.term-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 18px 18px 16px;
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--lx-r);
    transition: border-color .15s ease, background-color .15s ease;
}
.term-card:hover { border-color: color-mix(in srgb, var(--cat) 55%, var(--line)); }
.term-card .term-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 10px;
}
.term-card .term-header > div:first-child { min-width: 0; }
.term-name {
    display: block;
    color: var(--text);
    font-size: 1.06rem;
    font-weight: 600;
    line-height: 1.32;
    overflow-wrap: anywhere;
}
.term-name:hover { color: var(--phase-1); }
/* The book's own glyphs lead, as in the glossary. */
.term-card .term-symbol {
    display: inline-block;
    margin-top: 8px;
    padding: 1px 8px;
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-family: var(--lx-mono);
    font-size: 1rem;
    color: var(--phase-0);
    overflow-wrap: anywhere;
}
.term-card .term-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
}
.term-definition {
    margin: 0 0 12px;
    color: var(--text-dim);
    font-size: 0.93rem;
    line-height: 1.6;
}
.term-equation {
    margin-top: auto;
    padding: 9px 12px;
    border-left: 2px solid var(--phase-0);
    border-radius: 0 7px 7px 0;
    background: rgba(255, 255, 255, 0.03);
    font-family: var(--lx-mono);
    font-size: 0.86rem;
    color: var(--text);
    overflow-x: auto;
    overflow-wrap: anywhere;
}

/* Table, as the notation table. */
.terms-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.terms-table {
    display: none;
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
.terms-table.active { display: table; }
.terms-table th,
.terms-table td {
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--line);
}
.terms-table th {
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-mute);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
.terms-table th:hover { color: var(--text); }
.terms-table th:last-child { cursor: default; }
.terms-table th:last-child:hover { color: var(--text-mute); }
.terms-table tbody tr:hover td { background: rgba(255, 255, 255, 0.025); }
.terms-table td { color: var(--text-dim); }
.table-term-name { color: var(--text); font-weight: 600; }
.table-term-name:hover { color: var(--phase-1); }
.table-definition { max-width: 440px; font-size: 0.88rem; }
.terms-table td:nth-child(3), .terms-table td:nth-child(4) { white-space: nowrap; }
.sort-indicator { margin-left: 4px; color: var(--phase-1); }

.loading-state,
.empty-state {
    padding: 56px 16px;
    text-align: center;
    color: var(--text-dim);
}
.empty-state h3 { margin: 0 0 8px; font-size: 1.2rem; font-weight: 600; color: var(--text); }
.empty-state p { margin: 0; }

#loadMoreContainer { margin-top: 30px; }

@media (max-width: 768px) {
    .lexicon-container { padding-top: 34px; }
    .lexicon-header { margin-bottom: 24px; padding-bottom: 20px; }
    .control-panel { flex-direction: column; align-items: stretch; padding: 12px; }
    .search-container { flex: 0 0 auto; width: 100%; }
    /* 16px controls so iOS does not zoom on focus, and targets a thumb can hit. */
    .search-input { font-size: 16px; min-height: 44px; }
    .filter-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .filter-select { width: 100%; min-width: 0; font-size: 16px; min-height: 44px; }
    #categoryFilter { grid-column: 1 / -1; }
    .view-toggle { grid-column: 1 / -1; justify-self: start; }
    .view-btn { min-height: 38px; padding: 6px 18px; font-size: 0.95rem; }
    .terms-grid { grid-template-columns: 1fr; gap: 10px; }
    .term-card { padding: 15px 14px 14px; }
    .terms-table { font-size: 0.86rem; }
    .terms-table th, .terms-table td { padding: 8px; }
    .terms-table th { padding-top: 12px; padding-bottom: 12px; }
}

@media (max-width: 480px) {
    /* Category, chapter and importance give way to the term and its
       meaning; the grid view still shows all three. */
    .terms-table th:nth-child(2), .terms-table td:nth-child(2),
    .terms-table th:nth-child(3), .terms-table td:nth-child(3),
    .terms-table th:nth-child(4), .terms-table td:nth-child(4) { display: none; }
    .terms-table td:first-child { width: 40%; }
}

/* =================================================================
   A term
   ================================================================= */

.page-container {
    max-width: calc(880px + 2 * var(--gutter));
    padding-top: 38px;
    padding-bottom: calc(var(--pc-consent-h, 0px) + 72px);
    min-height: 70vh;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px 16px;
    margin-bottom: 26px;
}
.header-left { display: flex; align-items: baseline; gap: 9px; font-size: 0.86rem; color: var(--text-mute); }
.back-link { color: var(--phase-1); }
.back-link:hover { color: var(--text); }
.header-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Buttons, on home.css's .btn. */
.lexicon-term .btn { padding: 9px 18px; font-size: 0.9rem; border-radius: 9px; }
.btn-edit { border-color: var(--line); color: var(--text); }
.btn-edit:hover { border-color: var(--phase-1); background: rgba(53, 232, 224, 0.06); }
.btn-save { color: var(--bg); background: var(--phase-1); border-color: var(--phase-1); display: none; }
.btn-save:hover { filter: brightness(1.08); }
.btn-save:disabled { opacity: 0.6; cursor: wait; }
.btn-cancel { border-color: rgba(255, 51, 102, 0.45); color: var(--phase-0); display: none; }
.btn-cancel:hover { background: rgba(255, 51, 102, 0.08); }
.back-link.btn-ghost { display: inline-block; padding: 9px 18px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); }
.back-link.btn-ghost:hover { border-color: var(--phase-1); }

.status-message {
    display: none;
    margin: 0 0 18px;
    padding: 11px 15px;
    border-radius: 9px;
    font-size: 0.92rem;
}
.status-success { color: var(--phase-1); background: rgba(53, 232, 224, 0.07); border: 1px solid rgba(53, 232, 224, 0.35); }
.status-error { color: var(--phase-0); background: rgba(255, 51, 102, 0.07); border: 1px solid rgba(255, 51, 102, 0.35); }

.lexicon-term .term-header {
    margin-bottom: 8px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--line);
}
.lexicon-term .term-header .eyebrow { margin-bottom: 14px; }
.term-title {
    margin: 0 0 16px;
    font-size: clamp(1.9rem, 4.6vw, 2.9rem);
    line-height: 1.12;
    font-weight: 700;
    letter-spacing: -0.018em;
    color: var(--text);
    overflow-wrap: anywhere;
}
.lexicon-term .term-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
}
.lexicon-term .meta-badge { font-size: 0.76rem; padding: 3px 11px; }
.lexicon-term .star { font-size: 0.95rem; }
.lexicon-term .term-symbol {
    order: -1;
    max-width: 100%;
    padding: 4px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg-card);
    font-family: var(--lx-mono);
    font-size: 1.7rem;
    line-height: 1.3;
    color: var(--phase-0);
    overflow-wrap: anywhere;
}

.content-body { padding: 0; }
.content-section { padding: 26px 0; border-bottom: 1px solid var(--line); }
.content-section:last-child { border-bottom: 0; }
.section-title {
    margin: 0 0 14px;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--phase-1);
}
.definition-text {
    font-size: 1.07rem;
    line-height: 1.78;
    color: #d7dae1;
    /* A definition is paragraphs separated by a blank line (2026-09-28). */
    white-space: pre-line;
    overflow-wrap: break-word;
}
.equation-display {
    padding: 14px 18px;
    border-left: 2px solid var(--phase-0);
    border-radius: 0 8px 8px 0;
    background: rgba(255, 255, 255, 0.03);
    font-family: var(--lx-mono);
    font-size: 1.12rem;
    line-height: 1.7;
    color: var(--text);
    overflow-x: auto;
    overflow-wrap: anywhere;
}

/* Technical details, as a row of the data pages' stat tiles. */
.lexicon-term .tech-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 10px;
    white-space: normal;
    font-size: 1rem;
}
.lexicon-term .tech-details p {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 12px 15px;
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--lx-r);
    color: var(--text);
}
.lexicon-term .tech-details strong {
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-mute);
}

.related-terms {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
}
.related-term {
    display: block;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--lx-r);
    transition: border-color .15s ease;
}
.related-term:hover { border-color: var(--phase-1); }
.related-term-name { margin-bottom: 4px; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.related-term:hover .related-term-name { color: var(--phase-1); }
.related-term-desc { font-size: 0.88rem; line-height: 1.55; color: var(--text-dim); }

.lexicon-term .loading-state,
.error-state { padding: 56px 0; text-align: center; color: var(--text-dim); }
.error-state h3 { margin: 0 0 8px; font-size: 1.3rem; color: var(--text); }
.error-state p { margin: 0; }

#viewMode.hidden, #editMode.hidden { display: none; }

/* Editing (editors only). */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-mute);
}
.form-input, .form-textarea, .form-select {
    width: 100%;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.98rem;
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: 9px;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
    outline: none;
    border-color: var(--phase-1);
    box-shadow: 0 0 0 3px rgba(53, 232, 224, 0.12);
}
.form-textarea { min-height: 180px; resize: vertical; line-height: 1.6; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

.edit-bar { display: none; }

@media (max-width: 768px) {
    .page-container { padding-top: 26px; }
    .form-row { grid-template-columns: 1fr; }
    .related-terms { grid-template-columns: 1fr; }
    .equation-display { padding: 11px 12px; font-size: 1rem; }
    .definition-text { font-size: 1rem; }
    .lexicon-term .term-symbol { font-size: 1.4rem; }
    .form-input, .form-textarea, .form-select { font-size: 16px; min-height: 44px; }

    /* Save and Cancel at the thumb while editing: the header's pair is a
       long scroll back up from the definition. (Its buttons were hidden by
       the .btn-save/.btn-cancel rule until 2026-10-28.) */
    .edit-bar {
        display: flex; gap: 0.6rem; position: sticky; bottom: calc(0.5rem + var(--pc-consent-h, 0px)); z-index: 50;
        margin: 0 0 1rem; padding: 0.6rem; border-radius: 12px;
        background: var(--bg-raise); border: 1px solid var(--line);
        box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.4);
    }
    .edit-bar .btn { display: block; flex: 1 1 0; min-height: 44px; }
}

/* The term's math, carded like the book's (2026-10-28). */
.lex-math { padding: 0; background: none; border: 0; font-family: inherit; white-space: normal; text-align: left; }
.lex-from { margin: 0 0 14px; font-size: 0.78rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-mute); }
.lex-from a { color: var(--phase-1); text-decoration: none; }
.lex-from a:hover { text-decoration: underline; }
.lex-law { max-width: none; font-size: 1rem; }
.lex-eq-note { text-align: center; color: var(--text-dim); font-style: italic; }
