/* ---------------------------------------------------------------------------
   tokens, light and dark */

:root {
    --bg: #f5f4f0;
    --surface: #ffffff;
    --surface-2: #f0efea;
    --text: #1c1b19;
    --muted: #6b6963;
    --border: #e3e1da;
    --accent: #b31b1b;          /* arXiv red */
    --accent-text: #ffffff;
    --header: #b31b1b;
    --link: #1f4fbf;
    --tag: #2f5bd3;
    --tag-soft: #e6ecfb;
    --neg: #b4471a;
    --neg-soft: #fbe9e1;
    --pos-word: #1d7a3e;
    --shadow: 0 1px 2px rgba(20, 18, 12, .06), 0 1px 1px rgba(20, 18, 12, .04);
    --radius: 10px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #131312;
        --surface: #1c1c1b;
        --surface-2: #262624;
        --text: #ebe9e4;
        --muted: #a19e96;
        --border: #33322f;
        --accent: #c93a3a;
        --accent-text: #ffffff;
        --header: #7a1616;
        --link: #8fb0ff;
        --tag: #8fb0ff;
        --tag-soft: #24304d;
        --neg: #f0a07a;
        --neg-soft: #3d2a20;
        --pos-word: #6fd394;
        --shadow: none;
    }
}

/* ---------------------------------------------------------------------------
   base */

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background-color: var(--bg);
    -webkit-text-size-adjust: 100%;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

main {
    max-width: 920px;
    margin: 0 auto;
    padding: 0 16px 40px;
}

h1 { font-size: 18px; margin: 0 0 12px; }

.muted { color: var(--muted); }
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 20px;
    margin-top: 16px;
}
.card > p:first-child { margin-top: 0; }
.prose div + div { margin-top: 12px; }

/* ---------------------------------------------------------------------------
   header */

#header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px max(16px, calc((100% - 920px) / 2 + 16px));
    background: var(--header);
    color: var(--accent-text);
}
#header a { color: var(--accent-text); }
#home-link { font-weight: 700; font-size: 18px; letter-spacing: -.01em; white-space: nowrap; }
#home-link span { font-weight: 400; opacity: .85; }
#header nav { display: flex; gap: 18px; font-size: 15px; }
#header nav a { opacity: .9; white-space: nowrap; }
#header nav a:hover { opacity: 1; text-decoration: none; }
.nav-user { font-weight: 600; max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------------------
   buttons and form fields */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 36px;
    padding: 6px 14px;
    font: inherit;
    font-size: 15px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-small { min-height: 30px; padding: 3px 10px; font-size: 14px; }

.linkbtn {
    padding: 0;
    font: inherit;
    color: var(--link);
    background: none;
    border: 0;
    cursor: pointer;
}
.linkbtn:hover { text-decoration: underline; }

input[type=text], input[type=password], input[type=email], input[type=search], input[type=number], select {
    width: 100%;
    min-height: 36px;
    padding: 6px 10px;
    font: inherit;
    font-size: 15px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
input:focus, select:focus, .btn:focus-visible, .iconbtn:focus-visible {
    outline: 2px solid var(--link);
    outline-offset: 1px;
}

/* ---------------------------------------------------------------------------
   index: search, options, shortcuts */

#log-fun-warn {
    margin: 16px 0 0;
    padding: 10px 14px;
    font-size: 15px;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--muted);
}

#controls { margin-top: 16px; }

#searchrow { display: flex; gap: 8px; }
#qfield {
    flex: 1;
    min-height: 44px;
    padding-left: 40px;
    font-size: 17px;
    background: var(--surface) url('/static/search.png') no-repeat 10px center;
    background-size: 20px;
}

#options {
    margin-top: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
#options summary {
    padding: 8px 14px;
    font-size: 15px;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
}
#options[open] summary { border-bottom: 1px solid var(--border); }
.optsummary { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#options .btn { margin: 0 14px 14px; }
#optgrid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
    padding: 14px;
}
#optgrid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

#cbox_fast { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
#cbox_fast a {
    padding: 5px 12px;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
}
#cbox_fast a:hover { border-color: var(--link); text-decoration: none; }
#cbox_fast a.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------------------
   tags and chips */

#tagwrap { margin-top: 16px; }
#tagList { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.taglabel { font-size: 13px; color: var(--muted); margin-right: 4px; }
#inspect_svm { font-size: 14px; margin-left: 6px; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 26px;
    padding: 1px 10px;
    font: inherit;
    font-size: 14px;
    line-height: 1.4;
    border-radius: 999px;
    border: 1px solid transparent;
    white-space: nowrap;
}
.chip-tag, .chip-tag a { color: var(--tag); background: var(--tag-soft); }
.chip-tag:hover, .chip-tag a:hover { text-decoration: none; }
.chip-count small { color: var(--muted); font-size: 12px; }
.chip.active { border-color: var(--tag); }
.rel_utag_all, .rel_utag_all a { color: var(--accent); background: var(--surface-2); }
.chip-x {
    padding: 0 0 0 2px;
    font-size: 15px;
    line-height: 1;
    color: var(--muted);
    background: none;
    border: 0;
    cursor: pointer;
}
.chip-x:hover { color: var(--neg); }
.chip-neg {
    color: var(--neg);
    background: var(--neg-soft);
}
.chip-removable { padding-right: 4px; }
.chip-removable .chip-x { padding: 0 4px; font-size: 16px; }

/* the tfidf words of the model */
#wordwrap { margin-top: 4px; }
#wordwrap p { margin-top: 0; font-size: 14px; }
#wordList { display: flex; flex-wrap: wrap; gap: 6px; }
.rel_word {
    display: inline-flex;
    gap: 6px;
    padding: 2px 8px;
    font-size: 13px;
    background: var(--surface-2);
    border-radius: 6px;
}
.rel_word_weight { font-variant-numeric: tabular-nums; }
.rel_word.pos .rel_word_weight { color: var(--pos-word); }
.rel_word.neg .rel_word_weight { color: var(--neg); }

/* ---------------------------------------------------------------------------
   papers */

#wrap { margin-top: 16px; }
.rel_papers { display: flex; flex-direction: column; gap: 12px; }
.empty { padding: 40px 0; text-align: center; color: var(--muted); }

.rel_paper {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 20px;
}
.rel_paper::after { content: ""; display: table; clear: both; }

.rel_head { display: flex; align-items: baseline; gap: 10px; }
.rel_score {
    flex: none;
    padding: 1px 7px;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    background: var(--surface-2);
    border-radius: 6px;
}
.rel_title {
    margin: 0;
    font-size: 19px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -.01em;
}
.rel_title a { color: var(--text); }
.rel_title a:hover { color: var(--accent); text-decoration: none; }

.rel_authors {
    margin-top: 4px;
    font-size: 14px;
    color: var(--muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.rel_meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 2px; font-size: 13px; color: var(--muted); }
.rel_time { font-variant-numeric: tabular-nums; }

.rel_utags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.iconbtn {
    width: 30px;
    height: 30px;
    padding: 0;
    font-size: 16px;
    line-height: 1;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}
.iconbtn:hover:not(:disabled) { color: var(--text); border-color: var(--muted); }
.iconbtn:disabled { opacity: .35; cursor: default; }
.rel_utag_add:hover:not(:disabled) { color: var(--tag); border-color: var(--tag); }
.rel_utag_neg:hover:not(:disabled) { color: var(--neg); border-color: var(--neg); }

.rel_utag_add { color: var(--tag); }
.rel_utag_neg { color: var(--muted); }
.rel_utag_add.on { background: var(--tag-soft); border-color: var(--tag); }
.rel_utag_neg.on { color: var(--neg); background: var(--neg-soft); border-color: var(--neg); }
.tag-picker {
    margin-top: 10px;
    padding: 10px 12px;
    background: var(--surface-2);
    border-radius: 8px;
}
.tag-picker-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.tag-picker-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip-pick { color: var(--tag); background: var(--surface); border-color: var(--tag); cursor: pointer; }
.chip-pick:hover { background: var(--tag-soft); }
.tag-picker-neg .chip-pick { color: var(--neg); border-color: var(--neg); }
.tag-picker-neg .chip-pick:hover { background: var(--neg-soft); }
.tag-picker-new { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-picker-new input { flex: 1 1 160px; width: auto; min-height: 32px; padding: 3px 10px; font-size: 14px; }

.rel_abs {
    margin-top: 10px;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
}
.rel_abs.clamped {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    cursor: pointer;
}
.rel_links { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; font-size: 14px; }

.rel_img { float: right; margin: 0 0 8px 16px; }
.rel_img img { display: block; max-height: 120px; border-radius: 6px; border: 1px solid var(--border); }

/* KaTeX output should flow with the text */
.rel_abs .katex, .rel_title .katex { font-size: 1.05em; }
.rel_abs .katex-display { margin: .5em 0; overflow-x: auto; overflow-y: hidden; }

#pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: 24px 0 8px;
    color: var(--muted);
    font-size: 15px;
}

/* ---------------------------------------------------------------------------
   profile, stats */

#profile-warning { color: var(--muted); font-size: 15px; }
#profile-warning p { margin: 0 0 8px; }
#profile-login-form, #email-form { max-width: 420px; margin-top: 16px; }
#profile-login-form label { font-size: 14px; color: var(--muted); }
.form-error { color: var(--neg); font-weight: 600; }
textarea.form-control {
    width: 100%;
    padding: 8px 10px;
    font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    resize: vertical;
}
#import-form { margin-top: 16px; }
#import-form label { font-size: 14px; color: var(--muted); }
.import-results { width: 100%; }
.import-results td { vertical-align: top; overflow-wrap: anywhere; }
.form-group { margin-bottom: 10px; }
.form-control { margin-top: 4px; }

.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.statgrid div { display: flex; flex-direction: column; }
.statnum { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stattable { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stattable td { padding: 4px 24px 4px 0; border-bottom: 1px solid var(--border); }
.stattable td:last-child { text-align: right; font-weight: 600; }

/* ---------------------------------------------------------------------------
   phones */

@media (max-width: 600px) {
    body { font-size: 15px; }
    #header nav { gap: 12px; font-size: 14px; }
    .rel_paper, .card { padding: 14px; border-radius: 8px; }
    .rel_title { font-size: 17px; }
    .rel_img { display: none; }
    #searchrow .btn { padding: 6px 12px; }
    #optgrid { grid-template-columns: 1fr 1fr; }
    .iconbtn { width: 36px; height: 36px; }
}

/* after .stattable, which right-aligns its last column */
.stattable.import-results td:last-child { text-align: left; font-weight: normal; padding-right: 0; width: 40%; }

/* digest */
.digest-section { margin-top: 24px; }
.digest-tag { margin: 0 0 10px; font-size: 20px; }
.digest-tag a { color: var(--tag); }
.quickvote { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.vote-like.on { color: var(--tag); background: var(--tag-soft); border-color: var(--tag); }
.vote-seen.on { color: var(--text); background: var(--surface-2); border-color: var(--muted); }
.vote-down.on { color: var(--neg); background: var(--neg-soft); border-color: var(--neg); }

/* narrow screens: about/stats move from the header to the footer */
#footer { padding: 24px 16px 32px; text-align: center; font-size: 14px; color: var(--muted); }
.footer-mobile { display: none; }
@media (max-width: 480px) {
    .nav-secondary { display: none; }
    .footer-mobile { display: inline; }
}

/* first visit after signing up */
.onboarding { margin-bottom: 14px; }
.onboarding h1 { font-size: 18px; }
.onboarding ol { margin: 8px 0 0; padding-left: 22px; }
.onboarding li { margin: 6px 0; line-height: 1.5; }

label.check { display: flex; gap: 10px; align-items: flex-start; line-height: 1.4; cursor: pointer; }
label.check input { margin-top: 3px; width: 18px; height: 18px; flex: none; }
.muted.small { font-size: 13px; margin: 10px 0 0; }
@media (max-width: 380px) {
    #home-link { font-size: 16px; }
    #header nav { gap: 10px; }
    .nav-user { max-width: 8ch; }
}

/* tag check */
#tagcheckwrap:empty { display: none; }
.tagcheck { margin: 10px 0 14px; }
.tagcheck.card p { margin: 0 0 8px; line-height: 1.5; }
.misfits { margin: 0 0 8px; padding-left: 20px; }
.misfits li { margin: 4px 0; }
.rel_fit { margin-top: 4px; font-size: 13px; color: var(--tag); }
.rel_fit.misfit { color: var(--neg); font-weight: 600; }

.btn-danger { color: #fff; background: var(--neg); border-color: var(--neg); }
details.danger { margin-top: 12px; }
details.danger summary { cursor: pointer; color: var(--neg); font-size: 14px; }
details.danger form { margin-top: 10px; }
.prose h2 { font-size: 17px; margin: 20px 0 6px; }
.prose p, .prose li { line-height: 1.55; }
.prose ul { padding-left: 20px; }

/* ---------------------------------------------------------------------------
   waiting: results computed in the background, and the next page on its way */

.loading {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    max-width: 560px;
    margin: 32px auto;
    padding: 18px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.loading .muted { margin-top: 4px; font-size: 14px; }
.spinner {
    flex: none;
    width: 22px;
    height: 22px;
    margin-top: 1px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.notice {
    margin-bottom: 12px;
    padding: 10px 14px;
    font-size: 14px;
    background: var(--tag-soft);
    border-radius: 8px;
}

#busy {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 100;
    pointer-events: none;
}
#busy[hidden] { display: none; }
.busy-bar {
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    background-size: 40% 100%;
    background-repeat: no-repeat;
    animation: busybar 1.1s ease-in-out infinite;
}
@keyframes busybar { from { background-position: -40% 0; } to { background-position: 140% 0; } }
.busy-msg {
    width: fit-content;
    max-width: calc(100% - 32px);
    margin: 10px auto 0;
    padding: 6px 14px;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
@media (prefers-reduced-motion: reduce) {
    .spinner, .busy-bar { animation-duration: 3s; }
}

/* ---------------------------------------------------------------------------
   a tag's page: tabs for its recommendations and its saved papers */

#taghead { margin-top: 16px; }
#taghead h1 { margin: 0 0 8px; font-size: 24px; }
#taghead p { margin: 8px 0 0; font-size: 14px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tabs a {
    padding: 6px 14px;
    margin-bottom: -1px;
    color: var(--muted);
    border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

#optgrid label small { font-size: 11px; color: var(--muted); opacity: .85; }

/* ---------------------------------------------------------------------------
   cards or titles only */

#viewswitch { display: flex; justify-content: flex-end; gap: 4px; margin-top: 12px; }
#viewswitch .btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: 600; }
#viewswitch + #wrap, #viewswitch + #digestwrap { margin-top: 8px; }

.rel_papers:has(.rel_compact) { gap: 0; }
.rel_paper.rel_compact {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 0;
    box-shadow: none;
    border-top-width: 0;
}
.rel_paper.rel_compact:first-child { border-top-width: 1px; border-radius: var(--radius) var(--radius) 0 0; }
.rel_paper.rel_compact:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.rel_paper.rel_compact:only-child { border-radius: var(--radius); }
.rel_compact::after { content: none; }
.rel_title_c {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
    font-weight: 500;
}
.rel_title_c:hover { color: var(--accent); text-decoration: none; }
.rel_compact .rel_time { flex: none; font-size: 12px; color: var(--muted); }
.rel_compact.voted-down .rel_title_c, .rel_compact.voted-seen .rel_title_c { color: var(--muted); }
.rel_saved { flex: none; color: var(--tag); }
.rel_expand {
    flex: none;
    width: 24px;
    height: 24px;
    padding: 0;
    font-size: 14px;
    color: var(--muted);
    background: none;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}
.rel_expand:hover { color: var(--text); background: var(--surface-2); }
.quickvote.quickvote-compact { flex: none; gap: 2px; margin: 0; }
.quickvote-compact .btn { padding: 2px 6px; min-width: 0; }
@media (max-width: 600px) {
    .rel_compact .rel_time { display: none; }
    .rel_paper.rel_compact { padding: 6px 8px; }
    .rel_title_c { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 14px; }
}
.rel_for {
    flex: none;
    padding: 1px 8px;
    font-size: 12px;
    color: var(--tag);
    background: var(--tag-soft);
    border-radius: 999px;
}
.rel_for:hover { text-decoration: none; }

.copytag { margin-top: 12px; }
.copytag form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; }
.copytag label { display: flex; align-items: center; gap: 8px; }
.copytag input { width: 180px; }
.form-ok { color: var(--pos-word); font-weight: 600; }
.digest-sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.digest-sizes label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.digest-sizes label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.digest-sizes .btn { justify-self: start; }
