:root {
    --bg: #0e1014;
    --bg-soft: #14171d;
    --bg-card: #191d24;
    --line: #262b34;
    --text: #e9ebef;
    --muted: #8b93a1;
    --accent: #e8a33d;
    --accent-soft: rgba(232, 163, 61, 0.14);
    --radius: 12px;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    -webkit-font-smoothing: antialiased;
    line-height: 1.55;
    min-height: 100vh;
  }
  a { color: inherit; text-decoration: none; }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; }
  img { display: block; }
  ::selection { background: rgba(232, 163, 61, 0.35); }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }
  * { scrollbar-width: thin; scrollbar-color: #333a45 transparent; }
  *::-webkit-scrollbar { width: 8px; height: 8px; }
  *::-webkit-scrollbar-thumb { background: #333a45; border-radius: 4px; }
  *::-webkit-scrollbar-track { background: transparent; }

  .wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

  /* ---------- 顶栏 ---------- */
  .topbar {
    position: sticky; top: 0; z-index: 30;
    background: rgba(14, 16, 20, 0.86);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
  }
  .topbar-inner { display: flex; align-items: center; gap: 16px; height: 60px; }
  .brand { font-size: 19px; font-weight: 600; letter-spacing: 0.06em; white-space: nowrap; }
  .brand span { color: var(--accent); }
  .search { flex: 1; max-width: 420px; position: relative; }
  .search input {
    width: 100%; height: 38px; padding: 0 14px;
    background: var(--bg-soft); border: 1px solid var(--line); border-radius: 999px;
    outline: none; transition: border-color 0.18s;
  }
  .search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  .top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
  .icon-btn {
    display: inline-flex; align-items: center;
    height: 34px; padding: 0 12px; border-radius: 999px;
    background: transparent; border: 1px solid transparent; color: var(--muted);
    transition: color 0.15s, border-color 0.15s;
  }
  .icon-btn:hover { color: var(--text); border-color: var(--line); }
  .icon-btn.active { color: var(--accent); border-color: rgba(232, 163, 61, 0.3); background: var(--accent-soft); }
  .who { color: var(--muted); font-size: 13px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* ---------- 通用 ---------- */
  .page { padding-top: 26px; padding-bottom: 140px; }
  .muted { color: var(--muted); }
  .section { font-size: 15px; font-weight: 600; letter-spacing: 0.04em; color: var(--muted); margin: 28px 0 14px; text-transform: uppercase; }
  .btn {
    display: inline-flex; align-items: center; justify-content: center;
    height: 38px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--line);
    background: var(--bg-card); transition: transform 0.12s, border-color 0.18s, background 0.18s;
  }
  .btn:hover { border-color: #39404d; }
  .btn:active { transform: scale(0.98); }
  .btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
  .btn:disabled:hover { border-color: var(--line); }
  .btn.primary { background: var(--accent); border-color: var(--accent); color: #17130c; font-weight: 600; }
  .btn.primary:hover { background: #f0b357; }
  .btn.ghost { background: transparent; }
  .btn.sm { height: 30px; padding: 0 10px; font-size: 12px; }
  .btn.danger { color: #ff8a8a; border-color: rgba(255, 138, 138, 0.3); }
  .chip {
    display: inline-block; padding: 2px 9px; margin: 0 6px 6px 0; font-size: 12px;
    border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  }

  /* ---------- 登录 ---------- */
  .auth {
    min-height: 100vh; display: grid; place-items: center; padding: 24px;
    background: radial-gradient(1100px 600px at 15% 0%, rgba(232, 163, 61, 0.12), transparent 60%),
                radial-gradient(900px 500px at 90% 20%, rgba(74, 116, 255, 0.1), transparent 60%), var(--bg);
  }
  .auth-card {
    width: 100%; max-width: 336px; padding: 30px 26px 24px;
    background: var(--bg-soft); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
    animation: auth-in 0.32s ease;
  }
  @keyframes auth-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
  .auth-brand { font-size: 24px; font-weight: 700; letter-spacing: 0.08em; margin-bottom: 4px; }
  .auth-brand span { color: var(--accent); }
  .auth-tagline { font-size: 13px; }
  .auth form { margin-top: 20px; display: grid; gap: 14px; }
  .auth .field input { height: 44px; font-size: 16px; padding: 0 13px; }
  .auth .field input:focus { box-shadow: 0 0 0 3px var(--accent-soft); }
  .auth-submit { height: 44px; margin-top: 4px; font-size: 15px; }
  .auth-error {
    padding: 9px 11px; border-radius: 9px; font-size: 13px; line-height: 1.5;
    color: #ffb0b0; background: rgba(255, 107, 107, 0.1); border: 1px solid rgba(255, 107, 107, 0.28);
  }
  .auth form.shake { animation: auth-shake 0.28s ease; }
  @keyframes auth-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-3px); }
  }
  .pw-wrap { position: relative; }
  .pw-wrap input { padding-right: 44px !important; }
  .pw-toggle {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    width: 36px; height: 36px; display: grid; place-items: center;
    background: transparent; border: none; border-radius: 8px;
    color: var(--muted); font-size: 15px; opacity: 0.75;
  }
  .pw-toggle:hover { opacity: 1; background: rgba(255, 255, 255, 0.05); }
  .pw-toggle.on { color: var(--accent); opacity: 1; }
  .field { display: grid; gap: 6px; }
  .field label { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
  .field input, .field select, .field textarea {
    width: 100%; padding: 10px 13px; background: var(--bg); border: 1px solid var(--line);
    border-radius: 10px; outline: none; transition: border-color 0.16s, box-shadow 0.16s;
  }
  .field input, .field select { height: 40px; }
  .field input[type="file"] { height: auto; min-height: 42px; padding: 5px 10px; font-size: 12px; color: var(--muted); }
  .field input[type="file"]::file-selector-button {
    height: 30px; margin-right: 10px; padding: 0 10px; border-radius: 8px;
    border: 1px solid var(--line); background: var(--bg-card); color: var(--text); font-size: 12px; cursor: pointer;
  }
  .field input[type="file"]::file-selector-button:hover { border-color: var(--accent); color: var(--accent); }
  .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  .field input::placeholder, .field textarea::placeholder { color: #5b6270; }
  .field textarea { resize: vertical; min-height: 78px; }
  .auth-foot { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 10px; }
  .auth-foot a { color: var(--muted); border-bottom: 1px dashed var(--line); }

  /* ---------- 书库 / 卡片 ---------- */
  .libs { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
  .lib-card {
    display: flex; align-items: center; gap: 14px; padding: 18px;
    background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius);
    transition: border-color 0.18s, transform 0.18s;
  }
  .lib-card:hover { border-color: #39404d; transform: translateY(-2px); }
  .lib-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 20px; }
  .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 18px; }
  .card { display: block; }
  .card .cover {
    position: relative; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden;
    background: var(--bg-card); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
    transition: transform 0.2s;
  }
  .card:hover .cover { transform: translateY(-3px); }
  .card .cover img { width: 100%; height: 100%; object-fit: cover; }
  .card-title { margin-top: 10px; font-size: 14px; font-weight: 500; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mini-progress { height: 3px; background: var(--line); border-radius: 2px; margin-top: 7px; overflow: hidden; }
  .mini-progress i { display: block; height: 100%; background: var(--accent); }

  .row { display: grid; grid-auto-flow: column; grid-auto-columns: 132px; gap: 18px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
  .row .card-title { font-size: 13px; }

  /* ---------- 工具栏 ---------- */
  .toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 8px 0 22px; }
  .toolbar h1 { font-size: 24px; margin: 0 12px 0 0; font-weight: 600; }
  .toolbar .spacer { flex: 1; }
  .lib-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: -8px 0 18px; }
  .lib-tools label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
  .lib-tools select { height: 32px; padding: 0 8px; border-radius: 8px; background: var(--bg-card); border: 1px solid var(--line); color: var(--text); font-size: 12px; }
  .select {
    height: 34px; padding: 0 10px; border-radius: 8px;
    background: var(--bg-soft); border: 1px solid var(--line);
  }

  /* ---------- 详情 ---------- */
  .back { color: var(--muted); font-size: 13px; }
  .back:hover { color: var(--text); }
  .detail-top { display: flex; gap: 30px; margin-top: 18px; flex-wrap: wrap; }
  .detail-cover { width: 260px; flex: 0 0 260px; aspect-ratio: 1/1; border-radius: 14px; overflow: hidden; background: var(--bg-card); box-shadow: var(--shadow); }
  .detail-cover img { width: 100%; height: 100%; object-fit: cover; }
  .detail-meta { flex: 1; min-width: 260px; }
  .detail-meta h1 { font-family: Georgia, "Songti SC", "Noto Serif SC", serif; font-size: 32px; line-height: 1.25; margin: 0 0 10px; font-weight: 600; }
  .detail-sub { color: var(--muted); font-size: 14px; }
  .detail-actions { display: flex; gap: 10px; margin: 22px 0 8px; flex-wrap: wrap; }
  .detail-admin { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 10px; }
  .detail-admin .btn { color: var(--muted); }
  .detail-admin .btn:hover { color: var(--text); }
  .detail-admin .btn.danger { color: #ff8a8a; }
  .detail-offline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 10px; }
  .detail-offline .btn { color: var(--muted); }
  .detail-offline .muted { font-size: 12px; }
  .offline-badge { padding: 2px 7px; border-radius: 999px; font-size: 11px; color: #ffd28a; background: rgba(232, 163, 61, 0.12); border: 1px solid rgba(232, 163, 61, 0.28); }
  .offline-note { margin: 4px 0 0; padding: 9px 12px; border-radius: 10px; font-size: 12px; color: #ffd28a; background: rgba(232, 163, 61, 0.08); border: 1px solid rgba(232, 163, 61, 0.18); }
  .desc { color: #c4cad4; white-space: pre-wrap; margin-top: 24px; max-width: 760px; }
  .chapters { display: grid; gap: 2px; margin-top: 10px; max-width: 760px; }
  .chapter {
    display: flex; align-items: center; gap: 14px; padding: 10px 12px; border-radius: 8px;
    background: transparent; border: none; text-align: left; width: 100%; color: var(--text);
  }
  .chapter:hover { background: var(--bg-soft); }
  .chapter .idx { width: 26px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
  .chapter .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
  .chapter .time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
  .chapter.active { background: var(--bg-soft); box-shadow: inset 2px 0 0 var(--accent); }
  .chapter.active .idx, .chapter.active .name { color: var(--accent); }

  /* ---------- 管理 ---------- */
  .panel { background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 18px; }
  .panel h2 { font-size: 16px; margin: 0 0 16px; font-weight: 600; }
  .form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
  .form-grid .full { grid-column: 1 / -1; }
  .up-status { font-size: 12px; color: var(--muted); margin-top: 10px; min-height: 18px; white-space: pre-wrap; }
  .users { width: 100%; border-collapse: collapse; margin-top: 10px; }
  .users td, .users th { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
  .users th { color: var(--muted); font-weight: 500; }
  .access-row { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-top: 10px; }
  .access-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; margin-bottom: 10px; }
  .access-users { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; }
  .access-user { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
  .access-actions { display: flex; gap: 8px; margin-top: 12px; }

  /* ---------- 播放器 ---------- */
  .player {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    transform: translateY(110%); transition: transform 0.25s ease;
    background: rgba(20, 23, 29, 0.96);
    backdrop-filter: blur(18px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
  }
  .player.show { transform: translateY(0); }
  .player-inner { max-width: 1180px; margin: 0 auto; padding: 12px 20px calc(16px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 56px minmax(120px, 1fr) auto minmax(180px, 1.6fr) auto; gap: 16px; align-items: center; }
  .pl-cover { width: 56px; height: 56px; border-radius: 8px; overflow: hidden; background: var(--bg-card); }
  .pl-cover img { width: 100%; height: 100%; object-fit: cover; }
  .pl-title { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pl-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pl-controls { display: flex; align-items: center; gap: 6px; }
  .pl-btn { width: 36px; height: 36px; border-radius: 50%; border: none; background: transparent; color: var(--text); display: grid; place-items: center; font-size: 15px; }
  .pl-btn:hover { background: rgba(255, 255, 255, 0.06); }
  .pl-btn.main { width: 44px; height: 44px; background: var(--accent); color: #17130c; font-size: 17px; font-weight: 700; position: relative; }
  .pl-btn.main:hover { background: #f0b357; }
  .player.buffering .pl-btn.main { color: transparent; }
  .player.buffering .pl-btn.main::after {
    content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
    border: 2px solid rgba(23, 19, 12, 0.25); border-top-color: #17130c;
    animation: pl-spin 0.8s linear infinite;
  }
  @keyframes pl-spin { to { transform: rotate(360deg); } }
  .pl-timeline { display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
  .pl-bar { position: relative; flex: 1; height: 22px; display: flex; align-items: center; cursor: pointer; }
  .pl-bar::before { content: ""; position: absolute; left: 0; right: 0; height: 4px; background: #2b313b; border-radius: 2px; }
  .pl-fill { position: absolute; left: 0; height: 4px; background: var(--accent); border-radius: 2px; }
  .pl-knob { position: absolute; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(232, 163, 61, 0.18); }
  .pl-chapters { position: absolute; left: 0; right: 0; height: 12px; pointer-events: none; }
  .pl-chapters i { position: absolute; top: 3px; width: 1px; height: 6px; background: rgba(255, 255, 255, 0.22); }
  .pl-extra { display: flex; align-items: center; gap: 6px; }
  .pl-extra select { height: 30px; padding: 0 6px; border-radius: 8px; background: var(--bg-card); border: 1px solid var(--line); font-size: 12px; }
  .timer-btn { font-size: 12px; color: var(--muted); background: transparent; border: 1px solid var(--line); height: 30px; padding: 0 8px; border-radius: 8px; }

  /* ---------- 文件夹自动归档 ---------- */
  .folder-groups { display: grid; gap: 8px; }
  .folder-group {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px 10px;
    padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, 0.02);
  }
  .folder-check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
  .folder-check input { width: 16px; height: 16px; accent-color: var(--accent); }
  .folder-title {
    width: 100%; min-width: 0; height: 34px; border-radius: 8px; border: 1px solid var(--line);
    background: var(--bg-card); color: var(--text); padding: 0 10px; font-size: 14px;
  }
  .folder-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
  .folder-meta .warn { color: #e5a05a; }

  /* ---------- toast ---------- */
  #toast {
    position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%) translateY(12px);
    background: #232830; border: 1px solid #333a45; color: var(--text);
    padding: 10px 16px; border-radius: 10px; font-size: 13px; opacity: 0; pointer-events: none;
    transition: opacity 0.2s, transform 0.2s; z-index: 80; max-width: 80vw;
  }
  #toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

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

  @media (max-width: 820px) {
    .topbar-inner { height: 54px; gap: 8px; }
    .brand { font-size: 17px; letter-spacing: 0.04em; }
    .search { max-width: none; min-width: 0; }
    .search input { height: 36px; padding: 0 12px; font-size: 16px; }
    .top-actions { gap: 2px; }
    .icon-btn { padding: 0 8px; font-size: 13px; }
    .who { display: none; }
    .page { padding-top: 18px; padding-bottom: 250px; }
    .libs { grid-template-columns: 1fr 1fr; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 16px 12px; }
    .lib-tools { gap: 8px; margin-top: -4px; }
    .lib-tools select { height: 36px; }
    .detail-cover { width: 150px; flex: 0 0 150px; }
    .detail-meta h1 { font-size: 24px; }
    .field input, .field select, .field textarea { font-size: 16px; }
    .folder-group { grid-template-columns: 1fr auto; }
    .folder-check { grid-column: 1; grid-row: 1; }
    .folder-meta { grid-column: 2; grid-row: 1; }
    .folder-title { grid-column: 1 / -1; grid-row: 2; font-size: 16px; height: 38px; }
    .btn.sm { height: 34px; min-width: 34px; padding: 0 10px; }
    .detail-admin .btn { height: 34px; }
    .player-inner { grid-template-columns: 44px 1fr auto; grid-template-areas: "cover meta controls" "timeline timeline timeline" "extra extra extra"; row-gap: 6px; padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); }
    .pl-cover { grid-area: cover; width: 44px; height: 44px; }
    .pl-meta { grid-area: meta; }
    .pl-controls { grid-area: controls; }
    .pl-timeline { grid-area: timeline; }
    .pl-bar { height: 28px; }
    .pl-extra { grid-area: extra; display: flex; justify-content: space-between; gap: 8px; }
    .pl-extra select { flex: 0 0 auto; height: 32px; }
    .timer-btn { height: 32px; flex: 1; }
    #toast { bottom: 230px; }
  }
