/* Tsundoku — phone-first, plain CSS, light/dark through prefers-color-scheme. */

:root {
    --bg: #f6f3f9;
    --fg: #1f1b2e;
    --muted: #7a7490;
    --card: #ffffff;
    --accent: #6b4fbb;
    --accent-fg: #ffffff;
    --danger: #c2403a;
    --ok: #2e8b57;
    --line: #e2dcea;
    --radius: 10px;
    --nav-h: 56px;
    --shadow: 0 1px 3px rgba(31, 27, 46, 0.12);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121016;
        --fg: #ece8f2;
        --muted: #8f879f;
        --card: #1f1b2e;
        --accent: #9c84e8;
        --accent-fg: #15112a;
        --danger: #e46b63;
        --ok: #5ec48a;
        --line: #2c2740;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
}

body.obs { background: transparent; color: #fff; }

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

h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 1.1rem; margin-top: 20px; }
h3 { font-size: 1rem; }
p { margin: 0 0 8px; }

.muted { color: var(--muted); }
.error { color: var(--danger); margin: 8px 0; }
.ok { color: var(--ok); }
small, .small { font-size: 0.85rem; }

/* ---- shell ---- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}

.topbar h1 { font-size: 1.25rem; margin: 0; outline: none; }
.topbar-actions { display: flex; gap: 8px; }

.page { padding: 16px 16px calc(72px + env(safe-area-inset-bottom)); }
.page-plain { padding-bottom: 16px; }

.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    display: flex;
    background: var(--card);
    border-top: 1px solid var(--line);
    z-index: 10;
}

.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--muted);
    font-size: 0.7rem;
    text-decoration: none;
}

.bottom-nav a svg { width: 22px; height: 22px; fill: currentColor; }
.bottom-nav a.active { color: var(--accent); }

@media (min-width: 900px) {
    .page { max-width: 1100px; margin: 0 auto; }
}

/* ---- login ---- */

.login { max-width: 320px; margin: 15vh auto 0; }
.login .brand { font-size: 2rem; text-align: center; margin-bottom: 24px; }
.login .brand small { display: block; font-size: 1rem; color: var(--muted); font-weight: normal; }
.login form { display: flex; flex-direction: column; gap: 8px; }

/* ---- forms and buttons ---- */

label { font-size: 0.85rem; color: var(--muted); }

input[type="text"], input[type="password"], input[type="number"], input[type="search"], textarea, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--fg);
    font: inherit;
}

input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

textarea { min-height: 80px; resize: vertical; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--fg);
    font: inherit;
    cursor: pointer;
    min-height: 44px;
    text-decoration: none;
}

.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 0.85rem; }
.btn.block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.row { display: flex; gap: 8px; align-items: center; }
.row > * { min-width: 0; }
.row .grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

/* ---- cards and covers ---- */

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px;
    margin-bottom: 12px;
}

.cover-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 12px;
}

.book-card { display: flex; flex-direction: column; gap: 4px; position: relative; min-width: 0; }
.book-card .cover-link { display: block; position: relative; }
.book-card .cover, .book-card .cover-placeholder {
    width: 100%;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    border-radius: 6px;
    background: var(--line);
    display: block;
}
.cover-placeholder {
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 6px;
    font-size: 0.7rem;
    color: var(--muted);
    text-align: center;
    overflow: hidden;
}
.book-card .title { font-size: 0.8rem; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-card .idx {
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 0.7rem;
    padding: 1px 5px;
    border-radius: 4px;
}
.book-card .add {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: var(--accent-fg);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}
.book-card .add:disabled { opacity: 0.4; cursor: default; }

.book-card .caption { font-size: 0.7rem; line-height: 1.2; color: var(--muted); }

.view-menu .field:last-of-type { margin-bottom: 8px; }
.view-menu .btn.dir { flex: none; min-width: 44px; font-size: 1.1rem; }
.view-menu .check { display: flex; align-items: center; gap: 8px; min-height: 32px; cursor: pointer; }
.view-menu .check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

.group-header { display: flex; align-items: baseline; gap: 8px; margin: 20px 0 8px; }
.group-header h2 { margin: 0; }
.group-header .count { color: var(--muted); font-size: 0.85rem; }

/* ---- progress and badges ---- */

.progress { height: 4px; background: var(--muted); border-radius: 2px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); }
.progress.big { height: 8px; }

.badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--line);
    color: var(--fg);
    white-space: nowrap;
}
.badge.unread { background: var(--line); color: var(--muted); }
.badge.reading { background: var(--accent); color: var(--accent-fg); }
.badge.parked { background: #d9a53a; color: #1f1b2e; }
.badge.finished { background: var(--ok); color: #fff; }
.badge.dropped { background: var(--danger); color: #fff; }
.badge.stale { background: var(--danger); color: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--fg);
    font-size: 0.85rem;
    box-shadow: var(--shadow);
}
.chip b { color: var(--accent); }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
    flex: 1;
    min-width: 72px;
    padding: 8px 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--fg);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    min-height: 40px;
}
.seg button.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.stars { display: inline-flex; gap: 2px; }
.stars button {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--line);
    cursor: pointer;
    padding: 2px;
}
.stars button.on { color: #e3b341; }
.stars.readonly button { cursor: default; font-size: 1rem; }

/* ---- lists ---- */

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: none; }
.list .thumb { width: 48px; height: 72px; object-fit: cover; border-radius: 4px; background: var(--line); flex: none; }
.list .thumb.small { width: 36px; height: 54px; }
.list .body { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .drag { cursor: grab; color: var(--muted); font-size: 1.4rem; touch-action: none; padding: 8px 4px; user-select: none; }
.list .pos { color: var(--muted); font-variant-numeric: tabular-nums; width: 1.6em; text-align: right; }
.sortable-ghost { opacity: 0.4; }

.empty { color: var(--muted); text-align: center; padding: 32px 0; }

/* ---- horizontal cards (Home) ---- */

.h-scroll { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x proximity; }
.h-scroll > * { flex: 0 0 110px; scroll-snap-align: start; }

/* ---- volume strip (T18) ---- */

.strip { display: flex; gap: 4px; overflow-x: auto; padding: 8px 0; }
.strip .cell {
    flex: 0 0 auto;
    min-width: 36px;
    height: 44px;
    padding: 0 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px dashed var(--muted);
    color: var(--muted);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    text-decoration: none;
}
.strip .cell.owned { border-style: solid; border-color: var(--line); background: var(--card); color: var(--fg); }
.strip .cell.read { background: var(--ok); border-color: var(--ok); color: #fff; }
.strip .cell.queued { box-shadow: inset 0 0 0 2px var(--accent); }
.strip .cell.missing { border-color: var(--danger); color: var(--danger); }
.strip .cell.extra { font-size: 0.75rem; opacity: 0.85; }
.strip .cell.reading { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 0.75rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; border: 1px solid var(--line); }
.legend i.read { background: var(--ok); border-color: var(--ok); }
.legend i.queued { box-shadow: inset 0 0 0 2px var(--accent); }
.legend i.missing { border: 1px dashed var(--danger); }

/* ---- series rows ---- */

.series-row { display: flex; gap: 12px; align-items: center; }
.series-row .numbers { display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.8rem; color: var(--muted); }
.series-row .numbers b { color: var(--fg); font-weight: 600; }
.match { font-size: 0.8rem; }
.match.auto { color: var(--ok); }
.match.manual { color: var(--accent); }
.match.unmatched { color: var(--danger); }
.match.ignored { color: var(--muted); }

/* ---- panels, modal-ish ---- */

.panel {
    position: fixed;
    inset: auto 0 0 0;
    max-height: 80vh;
    overflow-y: auto;
    background: var(--card);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    z-index: 20;
}
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 15; }

.candidate { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.candidate img { width: 40px; height: 60px; object-fit: cover; border-radius: 4px; background: var(--line); }
.candidate .body { flex: 1; min-width: 0; }

/* ---- tables ---- */

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
td.err { color: var(--danger); font-size: 0.8rem; word-break: break-word; }

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

code, .token { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; word-break: break-all; }

/* ---- settings: reading apps (OPDS) ---- */

.opds h4 { font-size: 0.95rem; margin: 14px 0 4px; line-height: 1.2; }
.opds ol { margin: 0 0 8px; padding-left: 20px; }
.opds li { margin-bottom: 2px; }

/* ---- toast ---- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    background: var(--fg);
    color: var(--bg);
    padding: 10px 16px;
    border-radius: 999px;
    box-shadow: var(--shadow);
    z-index: 30;
    max-width: calc(100vw - 32px);
}

/* ---- OBS browser sources ---- */

.obs { font-family: system-ui, sans-serif; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7); padding: 8px; }
.obs-row { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.obs-row img { width: 96px; height: 144px; object-fit: cover; border-radius: 6px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6); flex: none; }
.obs-row .body { flex: 1; min-width: 0; }
.obs-row .title { font-size: 1.3rem; font-weight: 700; line-height: 1.2; }
.obs-row .sub { font-size: 1rem; opacity: 0.9; }
.obs-row .progress { height: 10px; background: rgba(255, 255, 255, 0.3); margin-top: 8px; border-radius: 5px; }
.obs-row .progress > i { background: #fff; }
.obs-row .pct { font-size: 0.9rem; margin-top: 4px; }
.obs-row .stars button { color: rgba(255, 255, 255, 0.3); }
.obs-row .stars button.on { color: #ffd56b; }

/* ---- Blazor boot UI (from the template) ---- */

#blazor-error-ui {
    background: lightyellow;
    color: #1f1b2e;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto 1rem auto;
}
.loading-progress circle {
    fill: none;
    stroke: var(--line);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}
.loading-progress circle:last-child {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}
.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }
