:root {
    color-scheme: light;
    --bg: #f6f8fb;
    --bg-accent: #eaf7ff;
    --surface: rgba(255, 255, 255, 0.86);
    --surface-strong: #ffffff;
    --surface-muted: #f2f6fb;
    --text: #18202b;
    --text-muted: #687385;
    --border: rgba(34, 48, 67, 0.12);
    --brand: #1d6fb8;
    --brand-strong: #0f4d94;
    --brand-soft: rgba(29, 111, 184, 0.12);
    --accent: #d45b7f;
    --accent-soft: rgba(212, 91, 127, 0.14);
    --success: #16845b;
    --warning: #b25f00;
    --danger: #c93b4a;
    --shadow: 0 18px 48px rgba(47, 67, 94, 0.14);
    --shadow-soft: 0 10px 28px rgba(47, 67, 94, 0.1);
    --focus: 0 0 0 3px rgba(29, 111, 184, 0.25);
    --radius: 8px;
    --topbar: linear-gradient(110deg, rgba(18, 86, 150, 0.96), rgba(28, 128, 146, 0.96), rgba(194, 79, 119, 0.92));
    --button: linear-gradient(135deg, #1d6fb8, #208d9d 54%, #c24f77);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #11151b;
    --bg-accent: #182330;
    --surface: rgba(29, 35, 44, 0.88);
    --surface-strong: #1b222c;
    --surface-muted: #151b23;
    --text: #edf4fb;
    --text-muted: #a6b2c3;
    --border: rgba(223, 234, 246, 0.14);
    --brand: #76bdf2;
    --brand-strong: #9ed6ff;
    --brand-soft: rgba(118, 189, 242, 0.16);
    --accent: #ff8aa8;
    --accent-soft: rgba(255, 138, 168, 0.16);
    --success: #63d8a8;
    --warning: #ffc36a;
    --danger: #ff7b8c;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.36);
    --shadow-soft: 0 12px 34px rgba(0, 0, 0, 0.28);
    --focus: 0 0 0 3px rgba(118, 189, 242, 0.28);
    --topbar: linear-gradient(110deg, rgba(23, 47, 82, 0.96), rgba(28, 90, 99, 0.94), rgba(104, 55, 91, 0.92));
    --button: linear-gradient(135deg, #3f95d4, #2ca6a3 54%, #d46b91);
}

* { box-sizing: border-box; }

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    font-family: -apple-system, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
    background:
        linear-gradient(120deg, transparent 0%, var(--bg-accent) 42%, transparent 78%),
        linear-gradient(180deg, var(--bg), var(--surface-muted));
    background-size: 180% 180%, 100% 100%;
    animation: pageGlow 18s ease-in-out infinite alternate;
    transition: background-color 260ms ease, color 260ms ease;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255,255,255,0.08) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.08) 1px, transparent 1px);
    background-size: 42px 42px;
    mask-image: linear-gradient(to bottom, rgba(0,0,0,0.36), transparent 72%);
}

a {
    color: var(--brand-strong);
    text-decoration: none;
    transition: color 180ms ease, opacity 180ms ease;
}

a:hover { color: var(--accent); }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 14px 28px;
    color: #fff;
    background: var(--topbar);
    background-size: 220% 220%;
    box-shadow: var(--shadow-soft);
    animation: gradientShift 14s ease-in-out infinite;
    backdrop-filter: blur(16px);
}

.brand a {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 800;
    font-size: 18px;
}

.brand-mark {
    display: inline-grid;
    width: 30px;
    height: 30px;
    place-items: center;
    color: #17405f;
    background: linear-gradient(135deg, #ffffff, #c8f1ff);
    border-radius: 8px;
    box-shadow: inset 0 -8px 16px rgba(29, 111, 184, 0.18), 0 8px 24px rgba(0,0,0,0.18);
}

.nav-links {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.nav-link,
.link-btn,
.theme-toggle {
    min-height: 34px;
    border-radius: 8px;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    padding: 7px 11px;
    color: rgba(255, 255, 255, 0.92);
}

.nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.14);
}

.topbar .user {
    margin: 0 4px;
    color: rgba(255, 255, 255, 0.84);
    font-size: 14px;
}

.link-btn {
    padding: 7px 10px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    font-size: 14px;
    transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.link-btn:hover,
.theme-toggle:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.42);
}

.theme-toggle {
    position: relative;
    width: 58px;
    border: 1px solid rgba(255, 255, 255, 0.26);
    background: rgba(255, 255, 255, 0.12);
    cursor: pointer;
    transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.theme-toggle::before {
    content: "";
    position: absolute;
    top: 5px;
    left: 6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, #fff3a6, #ffb84d);
    box-shadow: 0 0 18px rgba(255, 218, 99, 0.68);
    transition: transform 260ms cubic-bezier(.2,.8,.2,1), background 260ms ease, box-shadow 260ms ease;
}

:root[data-theme="dark"] .theme-toggle::before {
    transform: translateX(23px);
    background: linear-gradient(135deg, #d8e8ff, #86a6d8);
    box-shadow: inset -5px -4px 0 rgba(45, 58, 88, 0.75), 0 0 18px rgba(133, 177, 242, 0.45);
}

.container {
    position: relative;
    max-width: 1080px;
    margin: 30px auto 22px;
    padding: 0 20px;
    animation: contentIn 420ms ease both;
}

h1 {
    margin: 0 0 18px;
    font-size: 28px;
    line-height: 1.18;
    color: var(--text);
}

h1::after {
    content: "";
    display: block;
    width: 76px;
    height: 4px;
    margin-top: 10px;
    border-radius: 999px;
    background: var(--button);
    background-size: 180% 180%;
    animation: gradientShift 10s ease-in-out infinite;
}

h2 {
    margin: 28px 0 12px;
    font-size: 19px;
    color: var(--text);
}

.flashes {
    margin: 0 0 18px;
    padding: 12px 14px;
    list-style: none;
    color: var(--warning);
    background: linear-gradient(135deg, rgba(255, 197, 94, 0.18), rgba(255, 255, 255, 0.08));
    border: 1px solid rgba(255, 178, 72, 0.32);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.form,
.meta,
.stat-summary {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.form {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 420px;
    padding: 22px;
    overflow: hidden;
}

.form::before,
table.books::before,
.stat-summary::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(110deg, transparent, rgba(255,255,255,0.22), transparent);
    transform: translateX(-100%);
    animation: sheen 7s ease-in-out infinite;
}

.form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--text-muted);
    font-size: 14px;
}

input {
    width: 100%;
    padding: 10px 12px;
    color: var(--text);
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

input:focus {
    border-color: var(--brand);
    box-shadow: var(--focus);
}

.search {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    margin-bottom: 16px;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(14px);
}

button {
    font: inherit;
}

.form button,
.search button,
table button,
.book-action button {
    position: relative;
    min-height: 38px;
    padding: 8px 15px;
    border: 0;
    color: #fff;
    background: var(--button);
    background-size: 180% 180%;
    border-radius: var(--radius);
    cursor: pointer;
    box-shadow: 0 10px 22px rgba(29, 111, 184, 0.24);
    transition: transform 180ms ease, box-shadow 180ms ease, filter 180ms ease;
    animation: gradientShift 12s ease-in-out infinite;
}

.form button:hover,
.search button:hover,
table button:hover,
.book-action button:hover {
    transform: translateY(-1px);
    filter: saturate(1.1);
    box-shadow: 0 14px 30px rgba(29, 111, 184, 0.3);
}

.form button:active,
.search button:active,
table button:active {
    transform: translateY(0);
}

.tips,
.muted {
    color: var(--text-muted);
    font-size: 14px;
}

.muted {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 3px 9px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
}

table.books {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

table.books th,
table.books td {
    padding: 12px 13px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

table.books th {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    background: linear-gradient(180deg, var(--surface-strong), var(--surface-muted));
}

table.books tbody tr {
    transition: background 180ms ease, transform 180ms ease;
}

table.books tbody tr:hover {
    background: linear-gradient(90deg, var(--brand-soft), transparent);
}

table.books tbody tr:last-child td {
    border-bottom: 0;
}

table.books tr.overdue td {
    background: linear-gradient(90deg, rgba(201, 59, 74, 0.18), transparent);
    color: var(--danger);
}

.inline { display: inline; }

dl.meta {
    display: grid;
    grid-template-columns: minmax(96px, max-content) minmax(0, 1fr);
    gap: 10px 18px;
    margin: 0 0 18px;
    padding: 20px;
}

dl.meta dt {
    margin: 0;
    color: var(--text-muted);
    font-weight: 700;
}

dl.meta dd {
    margin: 0;
    color: var(--text);
}

.stat-summary {
    position: relative;
    display: inline-flex;
    align-items: baseline;
    gap: 14px;
    margin-bottom: 10px;
    padding: 18px 22px;
    overflow: hidden;
}

.stat-number {
    font-size: 36px;
    font-weight: 850;
    line-height: 1;
    background: var(--button);
    background-size: 180% 180%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: gradientShift 9s ease-in-out infinite;
}

.footer {
    text-align: center;
    padding: 28px;
    color: var(--text-muted);
}

@keyframes pageGlow {
    from { background-position: 0% 0%, 0 0; }
    to { background-position: 100% 80%, 0 0; }
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes contentIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes sheen {
    0%, 78% { transform: translateX(-120%); opacity: 0; }
    86% { opacity: 0.65; }
    100% { transform: translateX(120%); opacity: 0; }
}

@media (max-width: 760px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        padding: 14px 16px;
    }

    .nav-links {
        justify-content: flex-start;
        width: 100%;
    }

    .container {
        margin-top: 22px;
        padding: 0 12px;
    }

    h1 { font-size: 24px; }

    .search {
        grid-template-columns: 1fr;
    }

    table.books {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    .form {
        max-width: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 1ms !important;
    }
}
