:root {
  color-scheme: light;
  font: 14px/1.5 "Sarasa UI SC", "Microsoft YaHei UI", system-ui, sans-serif;
  --bg: #f2f5fb;
  --bg2: #e9eef8;
  --surface: #fff;
  --surface2: #eef2fa;
  --surface3: #dce5f2;
  --text: #17233d;
  --muted: #5d6f96;
  --dim: #8a97b8;
  --accent: #2f6fe4;
  --accent-hover: #245ec8;
  --accent-soft: #e7efff;
  --border: #d5dded;
  --green: #0ea371;
  --red: #d6455a;
  --shadow: 0 10px 32px rgba(45, 72, 118, .045);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0e15;
  --bg2: #10141f;
  --surface: #131826;
  --surface2: #1a2133;
  --surface3: #232c44;
  --text: #e9eefb;
  --muted: #9db0d4;
  --dim: #6c7ea3;
  --accent: #4f8ef7;
  --accent-hover: #73a7fa;
  --accent-soft: #1b3153;
  --border: #242e46;
  --green: #3ecf9a;
  --red: #ef6b7c;
  --shadow: 0 12px 32px rgba(0, 0, 0, .14);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); transition: background-color .2s ease, color .2s ease; }
button, input { font: inherit; }
button { cursor: pointer; transition: transform .15s ease, box-shadow .18s ease, background-color .18s ease, border-color .18s ease, color .18s ease, opacity .18s ease; }
button:not(:disabled):active { transform: translateY(1px) scale(.985); }
button:disabled { cursor: wait; opacity: .55; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.app-shell { display: flex; min-height: 100vh; }
.rail { width: 82px; flex: 0 0 82px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; gap: 24px; padding: 24px 8px; transition: background-color .2s ease, border-color .2s ease; }
.rail-brand { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; }
.rail-brand img { width: 34px; height: 34px; object-fit: contain; }
.rail-item { width: 62px; padding: 9px 2px; border: 0; border-radius: 16px; display: grid; gap: 3px; place-items: center; color: var(--muted); background: transparent; font-size: 11px; font-weight: 700; text-decoration: none; transition: transform .16s ease, color .16s ease, background-color .16s ease; }
.rail-item:hover { color: var(--accent); background: var(--surface2); text-decoration: none; }
.rail-current { color: var(--accent); background: var(--accent-soft); }
.rail-icon { font-size: 23px; line-height: 1.05; }
.rail-source { margin-top: auto; color: var(--muted); font-size: 11px; }
/* Keep page scrolling anchored to works, not panels moved by appended works. */
body[data-view="library"] .rail, body[data-view="library"] .upload-surface { overflow-anchor: none; }
.main-column { min-width: 0; flex: 1; }
.topbar { min-height: 94px; padding: 20px clamp(24px, 3vw, 48px); display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--border); transition: background-color .2s ease, border-color .2s ease; }
.topbar h1 { font-size: 23px; line-height: 1.15; letter-spacing: .2px; margin: 4px 0 0; font-weight: 800; }
.eyebrow { color: var(--dim); font-size: 10px; font-weight: 800; letter-spacing: 1.3px; }
.header-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 9px; }
.service-pill, .count-pill { display: inline-flex; align-items: center; white-space: nowrap; gap: 7px; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 7px 12px; color: var(--muted); font-size: 12px; }
.online-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 15%, transparent); }
.icon-button, .quiet-button { border: 1px solid var(--border); border-radius: 11px; min-height: 36px; padding: 7px 13px; background: var(--surface); color: var(--muted); font-weight: 600; }
a.quiet-button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.icon-button { width: 36px; padding: 0; font-size: 20px; line-height: 1; }
.icon-button:hover, .quiet-button:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
a.quiet-button:hover { text-decoration: none; }
.content { width: min(100%, 1450px); margin: 0 auto; padding: 32px clamp(20px, 3vw, 48px) 64px; }
.message:empty { display: none; }
.message:not(:empty) { position: fixed; top: 16px; left: 50%; z-index: 10; width: min(calc(100vw - 32px), 560px); margin: 0; padding: 11px 15px; transform: translateX(-50%); border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text); font-size: 13px; line-height: 1.45; animation: notice-enter .16s ease-out; }
@keyframes notice-enter { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }
.message.notice-leaving { animation: notice-leave .2s ease-in forwards; }
@keyframes notice-leave { to { opacity: 0; transform: translate(-50%, -5px); } }

body[data-view="login"] .rail, body[data-view="password"] .rail,
body[data-view="login"] .topbar, body[data-view="password"] .topbar { display: none; }
body[data-view="login"] .content, body[data-view="password"] .content { width: 100%; min-height: 100vh; display: grid; place-items: center; padding: 60px 24px; }
.auth-panel { width: min(100%, 360px); text-align: center; }
.auth-logo { width: 66px; height: 66px; object-fit: contain; margin-bottom: 12px; }
.auth-panel h2 { margin: 0; font-size: 22px; font-weight: 800; }
.auth-description { margin: 4px 0 27px; color: var(--muted); font-size: 12px; }
.auth-panel form { display: grid; gap: 12px; text-align: left; }
.auth-panel label { color: var(--muted); }
.auth-panel input { height: 48px; background: var(--surface2); }
.auth-panel .primary-button { width: 100%; margin-top: 10px; }
.auth-panel .quiet-button { width: 100%; }
.auth-github { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.auth-github:hover { text-decoration: none; }
.auth-switch { margin: 18px 0 0; font-size: 12px; }
.account-card { display: grid; justify-items: center; gap: 4px; margin-top: 6px; }
.account-avatar { width: 56px; height: 56px; margin-bottom: 4px; border-radius: 50%; background: var(--surface2); object-fit: cover; }
.account-level { color: var(--muted); font-size: 12px; }
.auth-logout { margin-top: 22px; }
.auth-footnote { margin-top: 54px; color: var(--dim); font-size: 11px; }

.overview { display: flex; align-items: end; justify-content: space-between; gap: 22px; padding: 26px 28px; border-radius: 20px; border: 1px solid var(--border); background: linear-gradient(115deg, var(--surface), var(--surface2)); box-shadow: var(--shadow); }
.overview h2 { margin: 5px 0 4px; font-size: 27px; line-height: 1.2; font-weight: 800; }
.overview p { margin: 0; color: var(--muted); }
.overview-stats { display: flex; gap: 18px; flex-shrink: 0; }
.overview-stats div { display: grid; min-width: 90px; gap: 2px; padding-left: 18px; border-left: 1px solid var(--border); }
.overview-stats strong { font-size: 25px; font-weight: 800; line-height: 1.1; color: var(--accent); }
.overview-stats span { color: var(--muted); font-size: 11px; }
.library-layout { display: grid; grid-template-columns: minmax(280px, 342px) minmax(0, 1fr); align-items: start; gap: 20px; margin-top: 20px; }
.settings-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 20px; margin-top: 20px; }
.settings-card .section-head { margin-bottom: 18px; }
.setting-current { margin: 0 0 18px; color: var(--muted); font-size: 12px; }
.setting-current strong { color: var(--text); }
.update-status { margin-top: 16px; }
.setting-note { margin: 14px 0 0; color: var(--dim); font-size: 11px; }
.setting-subform { margin-top: 17px; padding-top: 17px; border-top: 1px solid var(--border); }
.setting-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.setting-actions .primary-button, .setting-actions .quiet-button { width: auto; }
.surface { min-width: 0; padding: 23px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); transition: background-color .2s ease, border-color .18s ease, box-shadow .18s ease; }
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 25px; }
.section-icon { width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center; border-radius: 12px; background: var(--accent-soft); color: var(--accent); font-size: 23px; font-weight: 700; }
.section-head h2 { margin: 0; font-size: 17px; font-weight: 800; }
.section-head p { margin: 1px 0 0; color: var(--muted); font-size: 11px; }
.works-heading .quiet-button { margin-left: auto; }
form { display: grid; gap: 16px; }
label { display: grid; gap: 7px; font-size: 12px; font-weight: 700; }
label.check { display: flex; align-items: center; gap: 9px; color: var(--muted); font-weight: 500; cursor: pointer; }
.optional { display: inline; color: var(--dim); font-weight: 400; }
input:not([type="checkbox"]) { width: 100%; min-height: 42px; padding: 9px 12px; color: var(--text); background: var(--surface2); border: 1px solid var(--border); border-radius: 11px; outline: none; transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease; }
input:not([type="checkbox"]):focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: var(--dim); opacity: 1; }
input[type="file"] { padding: 8px; font-size: 11px; cursor: pointer; }
input[type="file"]::file-selector-button { margin-right: 10px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); cursor: pointer; }
select { width: 100%; min-height: 44px; padding: 9px 38px 9px 12px; color: var(--text); background-color: var(--surface2); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%232f6fe4' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 13px center; border: 1px solid var(--border); border-radius: 11px; font: inherit; font-weight: 600; appearance: none; cursor: pointer; transition: border-color .15s, box-shadow .15s, background-color .15s; }
select:hover { border-color: var(--accent); background-color: var(--accent-soft); }
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select option { color: var(--text); background: var(--surface); }
.zip-conflict-field { display: grid; gap: 7px; font-size: 12px; font-weight: 700; }
.zip-conflict-select { position: relative; }
.zip-conflict-trigger { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 44px; padding: 9px 13px; color: var(--text); background: var(--surface2); border: 1px solid var(--border); border-radius: 11px; text-align: left; font-size: 13px; font-weight: 600; transition: border-color .15s, background-color .15s, box-shadow .15s; }
.zip-conflict-trigger:hover, .zip-conflict-trigger[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-soft); }
.zip-conflict-trigger[aria-expanded="true"] { box-shadow: 0 0 0 3px var(--accent-soft); }
.select-chevron { width: 9px; height: 9px; flex: 0 0 9px; margin: -4px 3px 0 0; border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent); transform: rotate(45deg); transition: transform .15s, margin .15s; }
.zip-conflict-trigger[aria-expanded="true"] .select-chevron { margin-top: 5px; transform: rotate(225deg); }
.zip-conflict-menu { position: absolute; inset: calc(100% + 6px) 0 auto; z-index: 5; padding: 5px; overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); animation: menu-enter .16s ease-out; transform-origin: top center; }
@keyframes menu-enter { from { opacity: 0; transform: translateY(-5px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
.zip-conflict-menu [role="option"] { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; width: 100%; min-height: 48px; padding: 8px 10px; border: 0; border-radius: 8px; color: var(--text); background: transparent; text-align: left; font-size: 12px; font-weight: 650; transition: background-color .14s ease, color .14s ease, padding-left .14s ease; }
.zip-conflict-menu [role="option"] small { color: var(--dim); font-size: 10px; font-weight: 400; }
.zip-conflict-menu [role="option"]:hover, .zip-conflict-menu [role="option"]:focus-visible { outline: none; background: var(--surface2); }
.zip-conflict-menu [role="option"]:hover { padding-left: 13px; }
.zip-conflict-menu [role="option"][aria-selected="true"] { color: var(--accent); background: var(--accent-soft); }
.upload-heading { align-items: flex-start; }
.upload-heading > div:nth-child(2) { min-width: 0; flex: 1; }
.import-switch { display: flex; flex: 0 0 auto; gap: 2px; padding: 3px; margin-left: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface2); }
.import-switch button { min-height: 30px; padding: 4px 9px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; font-size: 11px; font-weight: 700; white-space: nowrap; }
.import-switch button.active { color: var(--accent); background: var(--surface); box-shadow: var(--shadow); }
.import-progress { margin-top: 16px; }
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.field-help { margin: -9px 0 1px; color: var(--dim); font-size: 11px; }
.primary-button { min-height: 44px; padding: 9px 16px; color: white; background: var(--accent); border: 1px solid var(--accent); border-radius: 12px; font-weight: 700; }
.primary-button:hover { background: var(--accent-hover); border-color: var(--accent-hover); box-shadow: 0 5px 14px color-mix(in srgb, var(--accent) 22%, transparent); transform: translateY(-1px); }
.upload-surface .primary-button { width: 100%; margin-top: 4px; }
/* Keep the primary action inside a short import card; the browser scrolls its fields. */
@media (min-width: 961px) {
  .upload-surface { max-height: calc(100dvh - 284px); overflow-y: auto; overscroll-behavior: contain; }
  .upload-surface #upload-form, .upload-surface #zip-form { padding-bottom: 1px; }
}
.import-progress { display: grid; gap: 8px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 11px; background: var(--accent-soft); color: var(--text); font-size: 12px; overflow-wrap: anywhere; }
.import-progress strong { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.import-progress[data-state="uploading"] strong::before, .import-progress[data-state="processing"] strong::before { content: ''; width: 12px; height: 12px; flex: 0 0 12px; border: 2px solid var(--surface3); border-top-color: var(--accent); border-radius: 50%; animation: import-spin .75s linear infinite; }
.import-progress[data-state="error"] { border-color: var(--red); }
.import-progress[data-state="error"] strong { color: var(--red); }
.import-progress span { color: var(--muted); }
.import-progress progress { width: 100%; height: 9px; accent-color: var(--accent); }
.import-progress[data-state="success"] progress { accent-color: var(--green); }
@keyframes import-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .import-progress strong::before { animation: none !important; }
}
.search-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.search-field { min-width: 0; flex: 1; position: relative; display: block; }
.search-field span { position: absolute; top: 4px; left: 13px; color: var(--dim); font-size: 27px; font-weight: 400; line-height: 1; pointer-events: none; }
.search-field input { padding-left: 37px; }
.count-pill { background: var(--surface2); border-color: transparent; }
.works-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 275px), 1fr)); grid-auto-rows: max-content; align-content: start; gap: 9px; overflow-y: auto; min-height: 0; padding: 2px 4px 4px 2px; scrollbar-gutter: stable; }
.list-status { margin-top: 10px; color: var(--muted); font-size: 11px; text-align: center; }
.work { align-self: start; min-width: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease; }
.work[open] { border-color: var(--accent); box-shadow: 0 5px 16px color-mix(in srgb, var(--accent) 10%, transparent); }
.work-summary { display: flex; align-items: center; gap: 12px; padding: 11px 13px; cursor: pointer; list-style: none; transition: background-color .16s ease; }
.work-summary::-webkit-details-marker { display: none; }
.work-summary:hover { background: var(--surface2); }
.work-art { width: 42px; height: 42px; flex: 0 0 42px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 20px; }
.work-name { min-width: 0; flex: 1; display: grid; gap: 1px; }
.work-name strong { font-size: 13px; font-weight: 800; }
.work-name small { color: var(--muted); font-size: 11px; }
.ai-pill { border-radius: 999px; padding: 3px 9px; background: var(--accent-soft); color: var(--accent); font-size: 10px; font-weight: 700; white-space: nowrap; }
.chevron { color: var(--dim); font-size: 17px; transition: transform .18s; }
.work[open] .chevron { transform: rotate(90deg); }
.file-list { padding: 4px 13px 8px 67px; border-top: 1px solid var(--border); }
.work[open] .file-list { animation: work-files-enter .18s ease-out; transform-origin: top; }
@keyframes work-files-enter { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.file { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.file:last-child { border-bottom: 0; }
.file-name { min-width: 0; overflow-wrap: anywhere; display: flex; align-items: center; gap: 8px; font-size: 12px; }
.extension { flex: 0 0 auto; padding: 2px 6px; border-radius: 5px; color: var(--muted); background: var(--surface2); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.file-actions { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.file-actions .check { font-size: 11px; }
.danger-button { padding: 4px 8px; border: 0; background: transparent; color: var(--red); border-radius: 7px; font-size: 11px; }
.danger-button:hover { background: color-mix(in srgb, var(--red) 12%, transparent); }
.import-progress:not([hidden]), .list-status:not([hidden]) { animation: panel-enter .2s ease-out; }
.auth-panel:not([hidden]), #library-panel:not([hidden]), #settings-panel:not([hidden]) { animation: panel-enter .22s ease-out; }
@keyframes panel-enter { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
@media (hover: hover) {
  .surface:hover { border-color: color-mix(in srgb, var(--accent) 28%, var(--border)); }
  .rail-item:hover { transform: translateY(-1px); }
}
.empty-state { text-align: center; padding: 52px 20px; color: var(--muted); border: 1px dashed var(--border); border-radius: 12px; }
.empty-icon { display: block; margin-bottom: 7px; color: var(--dim); font-size: 32px; }
.empty-state strong { display: block; color: var(--text); font-size: 13px; }
.empty-state p { margin: 3px 0 0; font-size: 11px; }

/* Quiet scrollbars: no arrow buttons, transparent track, soft rounded thumb. */
.upload-surface::-webkit-scrollbar, .works-list::-webkit-scrollbar { width: 12px; height: 12px; }
.upload-surface::-webkit-scrollbar-track, .works-list::-webkit-scrollbar-track { background: transparent; }
.upload-surface::-webkit-scrollbar-button, .works-list::-webkit-scrollbar-button { display: none; }
.upload-surface::-webkit-scrollbar-thumb, .works-list::-webkit-scrollbar-thumb { min-height: 40px; border: 3px solid transparent; border-radius: 999px; background: color-mix(in srgb, var(--dim) 40%, transparent) content-box; }
.upload-surface:hover::-webkit-scrollbar-thumb, .works-list:hover::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--dim) 62%, transparent) content-box; }
.upload-surface::-webkit-scrollbar-thumb:hover, .works-list::-webkit-scrollbar-thumb:hover { background: var(--dim) content-box; }
@supports not selector(::-webkit-scrollbar) {
  .upload-surface, .works-list { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--dim) 38%, transparent) transparent; }
}

@media (min-width: 961px) and (min-height: 700px) {
  body[data-view="library"] { height: 100dvh; overflow: hidden; }
  body[data-view="library"] .app-shell { height: 100dvh; min-height: 0; }
  body[data-view="library"] .main-column { display: flex; flex-direction: column; min-height: 0; }
  body[data-view="library"] .content { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-top: 22px; padding-bottom: 22px; }
  #library-panel { flex: 1; min-height: 0; }
  #library-panel { display: flex; flex-direction: column; }
  .overview { padding: 20px 24px; }
  .library-layout { flex: 1; min-height: 0; align-items: stretch; margin-top: 16px; }
  .upload-surface, .works-surface { min-height: 0; }
  .upload-surface { overflow-y: auto; }
  .works-surface { display: flex; flex-direction: column; }
  .works-list { flex: 1; }
  .settings-layout { margin-top: 16px; }
}

@media (max-width: 960px) {
  .library-layout { grid-template-columns: 1fr; }
  .settings-layout { grid-template-columns: 1fr; }
  .upload-surface { order: 2; }
  .works-surface { order: 1; }
}
@media (max-width: 640px) {
  .rail { position: fixed; inset: auto 0 0; z-index: 3; width: 100%; height: 64px; padding: 5px 12px; flex-direction: row; justify-content: center; gap: 18px; border-right: 0; border-top: 1px solid var(--border); }
  .rail-brand, .rail-source { display: none; }
  .rail-item { width: 88px; padding: 4px 8px; gap: 0; }
  .rail-icon { font-size: 21px; }
  .topbar { min-height: 78px; padding: 15px 18px; }
  .topbar h1 { font-size: 19px; }
  .topbar .eyebrow, .service-pill { display: none; }
  .header-actions { gap: 5px; }
  .content { padding: 18px 12px 92px; }
  .overview { padding: 20px; align-items: start; flex-direction: column; }
  .overview-stats { width: 100%; }
  .overview-stats div { flex: 1; min-width: 0; }
  .overview-stats div:first-child { padding-left: 0; border-left: 0; }
  .surface { padding: 18px; }
  .file-list { padding-left: 13px; }
  .file { align-items: flex-start; flex-direction: column; }
}

/* Signed-out and GitHub users browse read-only: hide admin navigation and import tools. */
body[data-access="public"] .rail,
body[data-access="public"] .upload-surface,
body[data-access="public"] .service-pill { display: none; }
body[data-access="public"] .library-layout { grid-template-columns: minmax(0, 1fr); }
body[data-access="public"] .content { width: min(100%, 1180px); }
@media (max-width: 640px) {
  body[data-access="public"] .content { padding-bottom: 40px; }
}
