:root {
    color-scheme: light;
    --bg: #f5f6fb;
    --surface: #ffffff;
    --surface-soft: #f0f1fb;
    --border: #d9dcef;
    --text: #25283b;
    --muted: #71758a;
    --primary: #626bd9;
    --primary-hover: #5059c8;
    --danger: #dc5a5a;
    --shadow: 0 18px 46px rgba(61, 68, 135, .14);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-height: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at 10% 0, #e9ebff 0, var(--bg) 42%);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* 搜索与管理页面使用独立浅色主题；登录页和播放页不受影响。 */
.search-page {
    --surface: #ffffff;
    --surface-soft: #f0f1fb;
    --border: #d9dcef;
    --text: #25283b;
    --muted: #71758a;
    --primary: #626bd9;
    --primary-hover: #5059c8;
    --shadow: 0 18px 46px rgba(61, 68, 135, .14);
    background: #f7f8fc;
    color: var(--text);
    color-scheme: light;
}

.search-page .site-header {
    background: rgba(235, 237, 255, .96);
    border-bottom-color: #d1d5f1;
}

.search-page input,
.search-page textarea,
.search-page select {
    background: #ffffff;
    color: var(--text);
    border-color: #d4d8eb;
}

.search-page label > span { color: #555a73; }
.search-page .user-badge { background: rgba(255, 255, 255, .76); color: #5f647c; }
.search-page .filters { background: #ffffff; }
.search-page .secondary-button { background: #f5f6fc; color: #343950; border-color: #d0d4e8; }
.search-page .secondary-button:hover { background: #ebedfa; border-color: #aeb4df; }
.search-page .video-card { box-shadow: 0 9px 24px rgba(55, 61, 114, .09); }
.search-page .video-card:hover,
.search-page .video-card:focus-visible { border-color: #aeb4df; box-shadow: 0 15px 32px rgba(55, 61, 114, .14); }
.search-page .tag { background: #eff0ff; color: #4d56bc; border-color: #cdd1f3; }
.search-page .tag-manager-row { background: #f8f8fc; }
.search-page .modal-backdrop { background: rgba(35, 38, 61, .46); }
.search-page .icon-button { background: #eef0fa; color: #3f445d; }
.search-page .description-text { color: #51566d; }

button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }

input, textarea, select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #ffffff;
    color: var(--text);
    padding: 11px 13px;
    outline: none;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(98, 107, 217, .18);
}

textarea { resize: vertical; }
select[multiple] { min-height: 92px; }
label > span { display: block; margin-bottom: 7px; color: #555a73; font-size: .9rem; }
.form-field-label { display: block; margin-bottom: 7px; color: #555a73; font-size: .9rem; }
.muted { color: var(--muted); }

.primary-button, .secondary-button, .danger-button, .danger-text-button, .icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 9px;
    padding: 10px 16px;
    cursor: pointer;
    font-weight: 650;
    transition: .18s ease;
}

.primary-button { background: var(--primary); color: #ffffff; }
.primary-button:hover { background: var(--primary-hover); transform: translateY(-1px); }
.secondary-button { background: var(--surface-soft); color: var(--text); border: 1px solid var(--border); }
.secondary-button:hover { border-color: #aeb4df; background: #ebedfa; }
.danger-button { background: var(--danger); color: #ffffff; }
.danger-text-button { background: #fff8f8; color: #c44747; border: 1px solid #efb7b7; }
button:disabled { opacity: .55; cursor: wait; transform: none !important; }
.full-width { width: 100%; }
.centered-button { text-align: center; }
.small-button { padding: 7px 11px; font-size: .83rem; }

.auth-page { display: grid; place-items: center; padding: 24px; }
.auth-card {
    width: min(430px, 100%);
    padding: 36px;
    background: rgba(255, 255, 255, .96);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
}
.auth-card h1 { margin-bottom: 8px; text-align: center; }
.auth-card > .muted { text-align: center; margin-bottom: 26px; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    margin: 0 auto 18px;
    border-radius: 16px;
    background: var(--primary);
    color: #ffffff;
    font-size: 1.35rem;
}

.stack-form { display: grid; gap: 17px; }
.alert { padding: 11px 13px; margin-bottom: 18px; border-radius: 9px; }
.error-alert { color: #a73737; background: #fff0f0; border: 1px solid #efb7b7; }

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(235, 237, 255, .94);
    border-bottom: 1px solid #d1d5f1;
    backdrop-filter: blur(16px);
}
.header-inner {
    width: min(1200px, calc(100% - 40px));
    margin: auto;
    padding: 19px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}
.header-inner h1 { margin-bottom: 4px; font-size: 1.4rem; }
.header-inner p { margin-bottom: 0; font-size: .9rem; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.user-badge { padding: 8px 11px; border-radius: 999px; background: var(--surface); color: var(--muted); font-size: .85rem; }

.page-container { width: min(1200px, calc(100% - 40px)); margin: 28px auto 60px; }
.filters {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    padding: 19px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: rgba(255, 255, 255, .9);
}
.tag-filter-field { flex: 0 1 240px; }
.keyword-field { flex: 0 1 480px; }
.nowrap-button { flex: 0 0 auto; white-space: nowrap; }
.align-end { align-self: flex-end; margin-bottom: 1px; }
.results-heading { padding: 25px 2px 10px; }

.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); grid-auto-rows: 1fr; gap: 20px; }
.video-card {
    display: flex;
    height: 100%;
    min-height: 380px;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .16);
    transition: transform .2s, border-color .2s, box-shadow .2s;
}
.video-card:hover, .video-card:focus-visible { transform: translateY(-4px); border-color: #aeb4df; box-shadow: 0 16px 34px rgba(55, 61, 114, .14); outline: none; }
.thumbnail-wrap { position: relative; display: grid; place-items: center; aspect-ratio: 16 / 9; background: #040a12; overflow: hidden; }
.video-card.compressing .thumbnail-wrap { background: #fff; }
.thumbnail-wrap img { width: 100%; height: 100%; object-fit: cover; }
.play-placeholder { font-size: 2.2rem; color: var(--primary); }
/* 压缩中：贴在卡片缩略图底部的平滑进度条（不是固定到视口） */
.thumbnail-wrap .compress-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: #e6e8f5; overflow: hidden; }
.thumbnail-wrap .compress-progress::before { content: ""; position: absolute; top: 0; bottom: 0; left: -40%; width: 40%; border-radius: 3px; background: var(--primary); animation: compress-slide 1.4s ease-in-out infinite; }
@keyframes compress-slide { from { left: -40%; } to { left: 100%; } }
.card-body { display: flex; flex: 1; flex-direction: column; padding: 16px; }
.card-body h2 { margin-bottom: 10px; overflow-wrap: anywhere; font-size: 1.05rem; }
.card-body > p {
    display: -webkit-box;
    flex: 1;
    min-height: 0;
    margin: 13px 0 0;
    overflow: hidden;
    color: var(--muted);
    font-size: .9rem;
    line-height: 1.5;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
}
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.detail-file { margin: 4px 0 10px; color: var(--muted); font-size: .82rem; word-break: break-all; }
.tag { padding: 4px 8px; border: 1px solid #cdd1f3; border-radius: 999px; background: #eff0ff; color: #4d56bc; font-size: .75rem; }
.card-admin-actions { display: flex; flex: 0 0 auto; gap: 8px; margin-top: 15px; padding-top: 13px; border-top: 1px solid var(--border); }
.card-import-date { display: block; margin-top: 8px; color: var(--muted); font-size: .78rem; text-align: right; }
/* 管理员卡片：日期与编辑/删除按钮同一行，靠右对齐、与按钮垂直居中 */
.card-admin-actions .card-import-date { margin: 0 0 0 auto; align-self: center; }
.empty-state { padding: 70px 20px; text-align: center; }
.empty-icon { color: var(--primary); font-size: 3.4rem; }

.modal-open { overflow: hidden; }
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 22px;
    background: rgba(35, 38, 61, .46);
    backdrop-filter: blur(8px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
    position: relative;
    width: min(620px, 100%);
    max-height: calc(100vh - 44px);
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}
.form-modal { width: min(680px, 100%); }
.confirm-modal { width: min(470px, 100%); }
.modal-body { padding: 26px; }
.modal-body h2 { padding-right: 34px; }
.modal-body h3 { margin: 22px 0 8px; font-size: .94rem; color: #555a73; }
.icon-button { width: 36px; height: 36px; padding: 0; background: #eef0fa; color: #3f445d; font-size: 1.45rem; }
.modal-close { position: absolute; top: 13px; right: 13px; z-index: 2; }
.detail-cover { display: block; width: 100%; max-height: 350px; object-fit: cover; background: #03070c; }
.description-text { color: #51566d; white-space: pre-wrap; line-height: 1.7; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 24px; }
.button-row { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.form-actions { display: flex; gap: 10px; margin-top: 12px; }
.form-actions .primary-button, .form-actions .secondary-button { flex: 1; }
.tag-manager-modal { width: min(760px, 100%); }
.tag-create-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.tag-create-form .alert { grid-column: 1 / -1; margin: 0; }
.tag-manager-heading { display: flex; justify-content: space-between; gap: 12px; margin: 25px 0 10px; font-size: .9rem; }
.tag-manager-list {
    display: grid;
    gap: 9px;
    max-height: 330px;
    overflow-y: auto;
    padding-right: 3px;
}
.tag-manager-row { display: grid; grid-template-columns: minmax(150px, 1fr) 85px auto auto; gap: 8px; align-items: center; padding: 10px; border: 1px solid var(--border); border-radius: 11px; background: #f8f8fc; }
.tag-usage { color: var(--muted); font-size: .82rem; text-align: center; }
.tag-manager-empty { padding: 22px 0; text-align: center; }
.field-heading { display: flex; align-items: baseline; justify-content: flex-start; gap: 8px; margin-bottom: 8px; }
.field-heading .form-field-label { margin-bottom: 0; line-height: 1.5; }
#manage-video-tags { height: auto; padding: 0; border: 0; background: transparent; color: #5962bd; font-size: .9rem; font-weight: 400; line-height: 1.5; }
#manage-video-tags:hover { background: transparent; color: #3f478f; text-decoration: underline; }
.selected-tags { display: flex; min-height: 30px; flex-wrap: wrap; gap: 7px; align-items: center; }
.tag-picker-placeholder { color: var(--muted); font-size: .88rem; }
.selected-tag {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: 5px 10px;
    border: 1px solid #d3d7ee;
    border-radius: 999px;
    background: #f0f1fa;
    color: #4d547c;
    font-size: .84rem;
}
.tag-select-modal { width: min(540px, 100%); }
.tag-select-list { display: grid; gap: 8px; max-height: 330px; overflow-y: auto; margin-top: 14px; padding-right: 3px; }
.tag-select-option { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: #fafafe; cursor: pointer; }
.tag-select-option:hover { border-color: #b7bce0; background: #f3f4fb; }
.tag-select-option:has(input:checked) { border-color: #aeb4df; background: #eef0fb; color: #49527f; font-weight: 650; }
.tag-select-option input { width: 17px; height: 17px; }

.toast { position: fixed; left: 50%; bottom: 28px; z-index: 150; transform: translateX(-50%); padding: 11px 18px; border: 1px solid #cdd1e8; border-radius: 10px; background: #ffffff; box-shadow: var(--shadow); }
.toast[hidden] { display: none; }

.player-page { background: #000; overflow: hidden; }
.player-container { width: 100vw; height: 100vh; height: 100dvh; display: grid; place-items: center; overflow: hidden; }
.player-container video { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.player-message { width: min(500px, calc(100% - 40px)); padding: 30px; border-radius: 16px; background: var(--surface); text-align: center; }
.player-message p { color: var(--muted); margin-bottom: 22px; }

@media (max-width: 720px) {
    .header-inner { width: min(100% - 28px, 1200px); align-items: flex-start; flex-direction: column; }
    .header-actions { width: 100%; justify-content: flex-start; }
    .page-container { width: min(100% - 28px, 1200px); }
    .filters { flex-direction: column; }
    .tag-filter-field, .keyword-field { width: 100%; flex-basis: auto; }
    .align-end { align-self: stretch; }
    .tag-manager-row { grid-template-columns: 1fr auto auto; }
    .tag-manager-row input { grid-column: 1 / -1; }
}
