/* ============================================
   diplomatic.wiki - Styles
   Scholarly encyclopedia / reference design
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --library-cream: #fffdf5;
    --text-black: #1c1c1c;
    --reference-blue: #1a5276;
    --margin-note: #7f8c8d;
    --highlight-yellow: #fff9c4;
    --sidebar-tint: #f5f2eb;
    --border-rule: #d5cec0;

    --font-primary: 'Literata', Georgia, 'Times New Roman', serif;
    --font-mono: 'Fira Code', 'Courier New', monospace;
    --font-accent: 'Alegreya SC', 'Georgia', serif;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-primary);
    font-weight: 400;
    line-height: 1.75;
    color: var(--text-black);
    background-color: var(--library-cream);
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
#sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    width: 260px;
    min-width: 260px;
    background-color: var(--sidebar-tint);
    border-right: 1px solid var(--border-rule);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

#sidebar-header {
    padding: 20px 20px 12px;
    border-bottom: 1px solid var(--border-rule);
}

.site-title {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 1.1rem;
    color: var(--text-black);
    letter-spacing: 0.08em;
    text-transform: lowercase;
}

#sidebar-search {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-rule);
}

#search-input {
    width: 100%;
    padding: 6px 10px;
    font-family: var(--font-primary);
    font-size: 0.85rem;
    border: 1px solid var(--border-rule);
    background: var(--library-cream);
    color: var(--text-black);
    border-radius: 2px;
    outline: none;
}

#search-input::placeholder {
    color: var(--margin-note);
}

/* Alphabetical Index */
#alpha-index {
    padding: 12px 20px 8px;
    border-bottom: 1px solid var(--border-rule);
}

#alpha-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
}

#alpha-list li {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.alpha-link {
    font-family: var(--font-accent);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--reference-blue);
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: 2px;
    transition: background-color 0.15s ease;
}

.alpha-link:hover {
    background-color: var(--highlight-yellow);
}

.alpha-link.disabled {
    color: var(--border-rule);
    pointer-events: none;
}

/* Sidebar Term List */
#sidebar-terms {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px 20px;
}

.term-group {
    margin-bottom: 14px;
}

.term-letter {
    display: block;
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--margin-note);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 4px;
    padding-bottom: 2px;
    border-bottom: 1px solid var(--border-rule);
}

.term-link {
    display: block;
    font-family: var(--font-primary);
    font-size: 0.85rem;
    color: var(--reference-blue);
    text-decoration: none;
    padding: 2px 0 2px 8px;
    transition: background-color 0.15s ease;
    line-height: 1.5;
}

.term-link:hover {
    background-color: var(--highlight-yellow);
}

.term-link.active {
    background-color: var(--highlight-yellow);
    font-weight: 700;
}

/* --- Main Content --- */
#main-content {
    flex: 1;
    max-width: 100%;
    overflow-x: hidden;
}

/* Header */
#site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: var(--library-cream);
    border-bottom: 1px solid var(--border-rule);
    padding: 12px 40px;
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 24px;
    max-width: 1100px;
}

.header-title {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-black);
    letter-spacing: 0.08em;
    text-transform: lowercase;
    white-space: nowrap;
}

#header-search {
    flex: 1;
    max-width: 360px;
}

#header-search-input {
    width: 100%;
    padding: 6px 12px;
    font-family: var(--font-primary);
    font-size: 0.85rem;
    border: 1px solid var(--border-rule);
    background: var(--library-cream);
    color: var(--text-black);
    border-radius: 2px;
    outline: none;
}

#header-search-input::placeholder {
    color: var(--margin-note);
}

#breadcrumb {
    font-family: var(--font-accent);
    font-size: 0.75rem;
    color: var(--margin-note);
    white-space: nowrap;
}

.crumb a {
    color: var(--reference-blue);
    text-decoration: none;
}

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

.crumb-sep {
    margin: 0 6px;
    color: var(--border-rule);
}

.crumb.active {
    color: var(--text-black);
}

/* Index Section */
#index-section {
    padding: 40px 40px 32px;
    border-bottom: 2px solid var(--border-rule);
}

.index-heading {
    font-family: var(--font-accent);
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--text-black);
    letter-spacing: 0.06em;
    margin-bottom: 24px;
}

#index-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

.index-letter-group {
    padding: 0;
}

.letter-heading {
    font-family: var(--font-accent);
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--reference-blue);
    border-bottom: 1px solid var(--border-rule);
    padding-bottom: 4px;
    margin-bottom: 8px;
}

.index-letter-group ul {
    list-style: none;
}

.index-letter-group li {
    padding: 2px 0;
}

/* Cross-Reference Links */
.cross-ref {
    color: var(--reference-blue);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s ease;
}

.cross-ref::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-top: 1.5px solid var(--reference-blue);
    border-right: 1.5px solid var(--reference-blue);
    transform: rotate(45deg);
    margin-left: 4px;
    vertical-align: middle;
    position: relative;
    top: -1px;
}

.cross-ref:hover {
    border-bottom-color: var(--reference-blue);
}

/* Article Area */
#article-area {
    position: relative;
    padding: 0 40px 60px;
    max-width: 1100px;
}

/* Floating TOC */
#floating-toc {
    position: fixed;
    top: 120px;
    right: 40px;
    width: 180px;
    z-index: 40;
}

.toc-label {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.7rem;
    color: var(--margin-note);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    display: block;
    margin-bottom: 8px;
}

#toc-list {
    list-style: none;
    position: relative;
    padding-left: 14px;
    border-left: 1px solid var(--border-rule);
}

#toc-list li {
    margin-bottom: 6px;
}

.toc-link {
    font-family: var(--font-primary);
    font-size: 0.75rem;
    color: var(--margin-note);
    text-decoration: none;
    transition: color 0.2s ease;
    line-height: 1.4;
    display: block;
}

.toc-link:hover {
    color: var(--reference-blue);
}

.toc-link.active {
    color: var(--reference-blue);
    font-weight: 700;
}

#toc-indicator {
    position: absolute;
    left: -4px;
    top: 0;
    width: 7px;
    height: 7px;
    background-color: var(--reference-blue);
    border-radius: 50%;
    transition: top 0.3s ease;
}

/* Wiki Articles */
.wiki-article {
    max-width: 680px;
    margin: 0 auto;
    padding: 40px 0;
    border-bottom: 1px solid var(--border-rule);
    position: relative;
}

.wiki-article:last-child {
    border-bottom: none;
}

/* Article Title with Drop Cap */
.article-title {
    font-family: var(--font-primary);
    font-weight: 700;
    font-size: 1.8rem;
    line-height: 1.3;
    color: var(--text-black);
    margin-bottom: 20px;
}

.drop-cap {
    font-family: var(--font-accent);
    font-size: 3.6rem;
    float: left;
    line-height: 0.85;
    padding-right: 8px;
    padding-top: 4px;
    color: var(--text-black);
    border-bottom: 2px solid var(--reference-blue);
}

/* Sections within articles */
.wiki-article h2 {
    font-family: var(--font-accent);
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--margin-note);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-top: 32px;
    margin-bottom: 12px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-rule);
}

.wiki-article h2:first-child {
    margin-top: 0;
}

/* Etymology block */
.etymology-text {
    font-size: 0.95rem;
    color: var(--margin-note);
    line-height: 1.7;
    padding-left: 16px;
    border-left: 2px solid var(--border-rule);
    margin-bottom: 8px;
}

/* Definition block */
.definition-block p,
.history-block p,
.protocols-block p,
.articles-block p,
.crossrefs-block p {
    margin-bottom: 16px;
    font-size: 1rem;
    line-height: 1.75;
}

/* Treaty codes */
.treaty-code {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    background-color: var(--sidebar-tint);
    padding: 1px 5px;
    border-radius: 2px;
    color: var(--text-black);
}

/* Term Highlights (for marginal notes) */
.term-highlight {
    text-decoration: underline;
    text-decoration-style: dotted;
    text-decoration-color: var(--margin-note);
    text-underline-offset: 3px;
    cursor: help;
    transition: background-color 0.15s ease;
}

.term-highlight:hover {
    background-color: var(--highlight-yellow);
}

/* Article lists */
.article-list {
    margin: 0 0 16px;
}

.article-list dt {
    font-weight: 700;
    margin-top: 16px;
    margin-bottom: 4px;
}

.article-list dd {
    margin-left: 0;
    padding-left: 24px;
    border-left: 2px solid var(--border-rule);
    margin-bottom: 8px;
    font-size: 0.95rem;
    line-height: 1.7;
}

/* Treaty stages (ordered list) */
.treaty-stages {
    padding-left: 24px;
    margin-bottom: 16px;
}

.treaty-stages li {
    margin-bottom: 10px;
    font-size: 0.95rem;
    line-height: 1.7;
}

/* Unordered lists in articles */
.protocols-block ul {
    padding-left: 24px;
    margin-bottom: 16px;
}

.protocols-block li {
    margin-bottom: 10px;
    font-size: 0.95rem;
    line-height: 1.7;
}

/* Cross-reference list */
.crossref-list {
    list-style: none;
    columns: 2;
    column-gap: 24px;
}

.crossref-list li {
    padding: 3px 0;
    font-size: 0.9rem;
}

/* Colophon */
.article-colophon {
    margin-top: 32px;
}

.colophon-divider {
    text-align: center;
    margin-bottom: 16px;
}

.colophon-divider::before {
    content: '\2022\00a0\00a0\2022\00a0\00a0\2022';
    color: var(--border-rule);
    font-size: 1rem;
    letter-spacing: 4px;
}

.colophon-meta {
    font-size: 0.75rem;
    color: var(--margin-note);
    text-align: center;
}

.meta-item {
    display: inline;
}

.meta-sep {
    margin: 0 8px;
    color: var(--border-rule);
}

/* Marginal Notes (Desktop) */
.marginal-note {
    position: absolute;
    right: -200px;
    width: 190px;
    font-size: 0.78rem;
    color: var(--margin-note);
    line-height: 1.5;
    padding: 8px 0 8px 12px;
    border-left: 1px dotted var(--border-rule);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.marginal-note.visible {
    opacity: 1;
    visibility: visible;
}

.marginal-note p {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.5;
}

.marginal-note .cross-ref::after {
    display: none;
}

/* Mobile Notes */
.mobile-notes {
    display: none;
}

/* Highlight flash animation for anchor targets */
@keyframes highlightFlash {
    0% { background-color: var(--highlight-yellow); }
    100% { background-color: transparent; }
}

.highlight-flash {
    animation: highlightFlash 1.5s ease-out;
}

/* Search highlight */
.search-highlight {
    background-color: var(--highlight-yellow);
    padding: 0 2px;
}

/* --- Responsive --- */
@media (max-width: 1280px) {
    #floating-toc {
        display: none;
    }

    .marginal-note {
        display: none;
    }

    .mobile-notes {
        display: block;
        max-width: 680px;
        margin: 0 auto;
        padding: 0 0 20px;
    }
}

@media (max-width: 1024px) {
    #sidebar {
        display: none;
    }

    body {
        display: block;
    }

    #main-content {
        max-width: 100%;
    }

    #article-area {
        padding: 0 24px 60px;
    }

    #index-section {
        padding: 24px;
    }

    .wiki-article {
        max-width: 100%;
    }

    .marginal-note {
        display: none;
    }

    .mobile-notes {
        display: block;
        max-width: 100%;
        padding: 0 0 20px;
    }

    .crossref-list {
        columns: 1;
    }
}

@media (max-width: 600px) {
    #site-header {
        padding: 10px 16px;
    }

    .header-inner {
        flex-wrap: wrap;
        gap: 8px;
    }

    #header-search {
        max-width: 100%;
        order: 3;
        flex-basis: 100%;
    }

    #breadcrumb {
        order: 2;
    }

    #article-area {
        padding: 0 16px 40px;
    }

    #index-section {
        padding: 16px;
    }

    #index-grid {
        grid-template-columns: 1fr;
    }

    .article-title {
        font-size: 1.4rem;
    }

    .drop-cap {
        font-size: 2.8rem;
    }
}

/* Mobile note details/summary */
.mobile-note {
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: var(--margin-note);
    border: 1px solid var(--border-rule);
    border-radius: 2px;
    padding: 0;
}

.mobile-note summary {
    padding: 6px 10px;
    cursor: pointer;
    font-family: var(--font-accent);
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    color: var(--reference-blue);
    background: var(--sidebar-tint);
}

.mobile-note p {
    padding: 8px 10px;
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.55;
}

/* Sidebar search filter highlight */
.term-group.hidden {
    display: none;
}

.term-link.hidden {
    display: none;
}

/* Active article highlight in sidebar */
.alpha-link.current {
    background-color: var(--highlight-yellow);
    font-weight: 700;
}
