:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e3e6ec;
  --accent: #c8871f;
  --accent-soft: #f6ecd9;
  --player-h: 148px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --text: #e8eaee;
    --muted: #9aa2b0;
    --line: #272c36;
    --accent: #e0a33c;
    --accent-soft: #2a2318;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  padding-bottom: calc(var(--player-h) + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

/* 登录页 */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: min(360px, 100%);
  padding: 28px 26px 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.08);
  text-align: center;
}

.login-brand {
  font-size: 34px;
  line-height: 1;
}

.login-card h1 {
  margin: 10px 0 2px;
  font-size: 18px;
  font-weight: 650;
}

.login-sub {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--muted);
}

.login-field {
  display: block;
  margin-bottom: 12px;
  text-align: left;
}

.login-field span {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  color: var(--muted);
}

.login-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: inherit;
  font-size: 15px;
  outline: none;
}

.login-field input:focus {
  border-color: var(--accent);
}

.login-error {
  margin: 0 0 10px;
  font-size: 13px;
  color: #d84a4a;
}

.login-submit {
  width: 100%;
  padding: 11px 0;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  letter-spacing: 2px;
  cursor: pointer;
}

.login-submit:hover {
  filter: brightness(1.06);
}

.login-submit:disabled {
  opacity: 0.6;
  cursor: default;
}

/* 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  font-size: 26px;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logout {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.logout:hover {
  color: var(--accent);
}

.search input {
  width: min(320px, 46vw);
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: inherit;
  font-size: 14px;
  outline: none;
}

.search input:focus {
  border-color: var(--accent);
}

/* 列表 */
main {
  max-width: 940px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

.playlist {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
}

.track {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.12s ease;
  /* 自动滚动定位时别被吸顶栏和底部播放器盖住 */
  scroll-margin: 80px 0 calc(var(--player-h) + 16px);
}

.track:last-child {
  border-bottom: none;
}

.track:hover {
  background: var(--surface-2);
}

.track.active {
  background: var(--accent-soft);
}

.track.active .track-title {
  color: var(--accent);
  font-weight: 600;
}

.track-no {
  flex: none;
  width: 74px;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

.track-body {
  flex: 1;
  min-width: 0;
}

.track-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-meta {
  font-size: 12px;
  color: var(--muted);
}

.track-state {
  flex: none;
  width: 18px;
  color: var(--accent);
  text-align: center;
}

.pdf-link {
  flex: none;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}

.pdf-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.extras {
  margin-top: 22px;
}

.extras h2 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.extras ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.extras a {
  display: inline-block;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
  font-size: 13px;
  text-decoration: none;
}

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

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

/* 讲义阅读面板 */
.viewer {
  width: min(1000px, 94vw);
  height: min(86vh, 1000px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: inherit;
  overflow: hidden;
}

.viewer::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.viewer[open] {
  display: flex;
  flex-direction: column;
}

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.viewer-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
}

.viewer-link {
  flex: none;
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.viewer-close {
  flex: none;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  cursor: pointer;
}

.viewer-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}

.viewer-fallback {
  margin: 0;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

/* 播放器 */
.player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
}

.now,
.progress,
.controls {
  max-width: 940px;
  margin: 0 auto;
}

.now {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.now-no {
  flex: none;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
}

.now-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.now-pdf {
  flex: none;
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.time {
  flex: none;
  width: 46px;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

input[type="range"] {
  flex: 1;
  height: 4px;
  appearance: none;
  border-radius: 999px;
  background: var(--surface-2);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 13px;
  height: 13px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.icon {
  min-width: 40px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: inherit;
  font-size: 13px;
  cursor: pointer;
}

.icon:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icon.play {
  min-width: 52px;
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
}

.icon.play:hover {
  color: #fff;
  filter: brightness(1.06);
}

.icon:disabled {
  opacity: 0.4;
  cursor: default;
}

.rate,
.volume,
.autoplay {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.rate select {
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  font-size: 12px;
}

.volume {
  flex: 1;
  min-width: 110px;
  max-width: 190px;
}

.autoplay {
  margin-left: auto;
  cursor: pointer;
}

@media (max-width: 640px) {
  :root {
    --player-h: 168px;
  }

  .topbar {
    padding: 12px 14px;
  }

  .search {
    width: 100%;
  }

  .search input {
    width: 100%;
  }

  .track-no {
    width: 58px;
  }

  .volume {
    display: none;
  }
}
