/* Stylesheet */

:root {
    --paper: #ECE7DB;
    --paper-2: #E4DECF;
    --ink: #1D2233;
    --ink-soft: #4B5164;
    --rule: #C9C0A8;
    --rule-soft: #DAD3BE;
    --teal: #28594B;
    --teal-soft: #DCE6DD;
    --rust: #A24B27;
    --rust-soft: #F0DFD3;
    --card: #F5F1E6;
    --shadow: 0 1px 0 rgba(29, 34, 51, 0.06);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background:
        linear-gradient(var(--paper), var(--paper)),
        repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(29, 34, 51, 0.035) 27px, rgba(29, 34, 51, 0.035) 28px);
    color: var(--ink);
    font-family: 'IBM Plex Sans', sans-serif;
    -webkit-font-smoothing: antialiased;
}

.wrap {
    max-width: 920px;
    margin: 0 auto;
    padding: 0 28px 80px;
}

/* ===== HEADER ===== */
header.hero {
    padding: 56px 0 36px;
    border-bottom: 2px solid var(--ink);
    position: relative;
}

.eyebrow {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12.5px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--teal);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
}

.eyebrow::before {
    content: "";
    width: 22px;
    height: 2px;
    background: var(--teal);
    display: inline-block;
}

h1.headline {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: clamp(34px, 5.6vw, 56px);
    line-height: 1.04;
    margin: 0 0 14px;
    letter-spacing: -0.01em;
}

h1.headline em {
    font-style: italic;
    color: var(--teal);
    font-weight: 500;
}

.sub {
    font-size: 16.5px;
    color: var(--ink-soft);
    max-width: 56ch;
    line-height: 1.6;
    margin: 0 0 30px;
}

.statline {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    border-top: 1px solid var(--rule);
}

.stat {
    flex: 1 1 140px;
    padding: 16px 22px 4px 14px;
    border-right: 1px solid var(--rule);
}

.stat:last-child {
    border-right: none;
}

.stat .num {
    font-family: 'Fraunces', serif;
    font-size: 30px;
    font-weight: 600;
    color: var(--ink);
    display: block;
}

.stat .lbl {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

/* ===== UPLOAD CORNER ===== */
.reload-box {
    text-align: right;
    margin-bottom: 34px;
}

.reload-btn {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11.5px;
    letter-spacing: .03em;
    color: var(--teal);
    background: var(--teal-soft);
    border: 1px solid var(--teal);
    padding: 7px 12px;
    border-radius: 3px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background .15s ease;
}

.reload-btn:hover {
    background: #cfe0d5;
}

#fileInput {
    display: none;
}

.reload-note {
    font-size: 10.5px;
    color: var(--ink-soft);
    margin-top: 6px;
    max-width: 200px;
    display: block;
}

.reload-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.sync-btn {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11.5px;
    letter-spacing: .03em;
    color: #fff;
    background: var(--teal);
    border: 1px solid var(--teal);
    padding: 7px 12px;
    border-radius: 3px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.sync-btn:hover {
    background: #1f463b;
}

.sync-btn:disabled {
    opacity: .6;
    cursor: default;
}

.sync-btn .spin {
    display: inline-block;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.status-line {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--rule);
    display: inline-block;
}

.status-dot.ok {
    background: var(--teal);
}

.status-dot.err {
    background: var(--rust);
}

@media (max-width:640px) {
    .reload-row {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .status-line {
        justify-content: flex-start;
    }

    .reload-box {
        text-align: left;
    }
}

/* ===== CONTROLS ===== */
.controls {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 34px 0 8px;
    position: sticky;
    top: 0;
    background: var(--paper);
    padding: 14px 0;
    z-index: 5;
    border-bottom: 1px solid var(--rule-soft);
}

.search {
    flex: 1;
    position: relative;
}

.search input {
    width: 100%;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 14px;
    padding: 11px 14px 11px 32px;
    border: 1px solid var(--ink);
    border-radius: 3px;
    background: var(--card);
    color: var(--ink);
    outline: none;
}

.search input::placeholder {
    color: #8b8672;
}

.search::before {
    content: "⌕";
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    color: var(--ink-soft);
}

.count-pill {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11.5px;
    color: var(--ink-soft);
    white-space: nowrap;
}

/* ===== LEDGER ===== */
.ledger {
    margin-top: 6px;
}

.row {
    border-bottom: 1px solid var(--rule-soft);
    padding: 16px 0;
    cursor: pointer;
}

.row:first-child {
    border-top: 1px solid var(--rule-soft);
}

.row-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 9px;
}

.row-name {
    font-family: 'Fraunces', serif;
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.row-rank {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    color: var(--rule);
    width: 22px;
    display: inline-block;
}

.row-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    color: var(--ink-soft);
    text-align: right;
    white-space: nowrap;
}

.row-years {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    color: var(--teal);
    font-size: 16px;
}

.ruler {
    position: relative;
    height: 22px;
    background:
        repeating-linear-gradient(90deg,
            var(--rule) 0, var(--rule) 1px,
            transparent 1px, transparent calc(100%/16));
    border-bottom: 1px solid var(--ink);
}

.ruler-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: linear-gradient(90deg, var(--teal), #3a7562);
    border-radius: 0 2px 2px 0;
    transition: width .5s cubic-bezier(.2, .7, .2, 1);
}

.ruler-flag {
    position: absolute;
    top: -3px;
    width: 2px;
    height: 28px;
    background: var(--rust);
}

.row-detail {
    max-height: 0;
    overflow: hidden;
    transition: max-height .3s ease;
}

.row.open .row-detail {
    max-height: 200px;
}

.row-detail-inner {
    padding-top: 12px;
    font-size: 13px;
    color: var(--ink-soft);
    line-height: 1.7;
}

.row-detail-inner b {
    color: var(--ink);
    font-weight: 600;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.chip {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    background: var(--card);
    border: 1px solid var(--rule);
    padding: 3px 8px;
    border-radius: 3px;
}

.caret {
    font-size: 11px;
    color: var(--ink-soft);
    transition: transform .2s ease;
    display: inline-block;
}

.row.open .caret {
    transform: rotate(90deg);
}

.empty {
    padding: 50px 0;
    text-align: center;
    color: var(--ink-soft);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
}

/* ===== FOOTER ===== */
footer {
    margin-top: 50px;
    padding-top: 24px;
    border-top: 2px solid var(--ink);
    font-size: 12.5px;
    color: var(--ink-soft);
    line-height: 1.7;
}

footer b {
    color: var(--ink);
}

::selection {
    background: var(--rust-soft);
}

body.exporting .reload-box,
body.exporting .controls {
    display: none;
}

body.exporting .caret {
    display: none;
}

body.exporting {
    background: var(--paper);
}

@media print {
    body {
        background: #fff;
    }

    .reload-box,
    .controls {
        display: none;
    }

    .row {
        cursor: default;
        break-inside: avoid;
    }

    .row-detail {
        max-height: none !important;
    }

    .caret {
        display: none;
    }

    .ruler-fill,
    .chip,
    .status-dot {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    a[href]::after {
        content: none;
    }
}