:root {
  --bg: #fff7e8;
  --card: #ffffff;
  --ink: #3b2f2a;
  --muted: #8a7b72;
  --accent: #ff8a3d;
  --accent-dark: #e86f1f;
  --done: #3fb37f;
  --line: #f0e3cf;
  --lock: #cfc4b8;
  --radius: 22px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans", "Helvetica Neue", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
[hidden] { display: none !important; }

#app {
  max-width: 1180px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶部 ---------- */
.head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin: 8px 4px 20px; }
.head h1 { font-size: 34px; margin: 0; letter-spacing: 1px; }
.stars { font-size: 28px; letter-spacing: 2px; flex: 1; }
.stars .off { filter: grayscale(1); opacity: .28; }
.count { font-size: 26px; font-weight: 700; color: var(--accent-dark); }

/* ---------- 卡片 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}
.card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 0 var(--line), 0 6px 18px rgba(120, 80, 30, .08);
  text-align: left;
  display: flex;
  flex-direction: column;
  transition: transform .12s;
}
.card:active { transform: scale(.97); }
.card .thumb { position: relative; aspect-ratio: 16 / 9; background: #f3e9da; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .badge {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 54px; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.card .info { padding: 12px 16px 16px; }
.card .series { font-size: 20px; font-weight: 700; }
.card .ep { font-size: 15px; color: var(--muted); margin-top: 4px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .mini-bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.card .mini-bar div { height: 100%; background: var(--accent); }

.card.done .thumb::after { content: ""; position: absolute; inset: 0; background: rgba(63, 179, 127, .55); }
.card.done .badge { z-index: 1; }
.card.locked { opacity: .55; }
.card.locked .thumb img { filter: grayscale(.8); }
.card.next { outline: 5px solid var(--accent); outline-offset: -5px; }

.next-wrap { display: flex; justify-content: center; margin: 28px 0 12px; }
.big-btn {
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  font-weight: 800;
  padding: 18px 46px;
  border-radius: 999px;
  box-shadow: 0 6px 0 var(--accent-dark);
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--accent-dark); }

.all-done { text-align: center; margin: 28px 0 8px; font-size: 32px; font-weight: 800; color: var(--done); }
.all-done small { display: block; font-size: 18px; color: var(--muted); font-weight: 500; margin-top: 6px; }

/* ---------- 学过的内容 ---------- */
.learned { margin-top: 28px; }
.learned h2 { font-size: 24px; margin: 0 4px 12px; }
.learned h2 small { font-size: 15px; color: var(--muted); font-weight: 500; margin-left: 6px; }
.learned-empty { color: var(--muted); padding: 4px 4px; font-size: 17px; }
.learned-row { background: var(--card); border-radius: 18px; padding: 14px 16px; margin-bottom: 12px; box-shadow: 0 3px 0 var(--line); }
.learned-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.learned-head b { font-size: 18px; }
.learned-head span { color: var(--muted); font-size: 14px; }
.learned-head .prog { flex: 1; max-width: 200px; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-left: auto; }
.learned-head .prog div { height: 100%; background: var(--done); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-size: 14px; padding: 6px 12px; border-radius: 999px; background: #eef8f2; color: #1f6b48; line-height: 1.3; }
.chip b { font-weight: 700; color: var(--accent-dark); }
.learned-more { background: var(--line); color: var(--ink); }

.foot { margin-top: auto; padding-top: 28px; display: flex; justify-content: flex-end; }
.records-link { font-size: 14px; color: var(--muted); padding: 10px 14px; border-radius: 12px; }
.records-link.pressing { background: var(--line); }

/* ---------- 登录 ---------- */
.login { margin: auto; text-align: center; max-width: 360px; width: 100%; }
.login h1 { font-size: 30px; }
.login input {
  width: 100%; font-size: 22px; padding: 14px 18px; border-radius: 14px;
  border: 2px solid var(--line); background: #fff; text-align: center; margin-bottom: 16px;
  -webkit-user-select: text; user-select: text;
}
.login .err { color: #d0453a; min-height: 24px; }
.msg { margin: auto; text-align: center; color: var(--muted); font-size: 20px; }

/* ---------- 播放器 ---------- */
.player {
  position: fixed; inset: 0; z-index: 10;
  background: #111; color: #fff;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.player-top { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.player-title { font-size: 20px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(255,255,255,.14); font-size: 24px; flex: none;
}
.stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.frame { position: relative; width: 100%; max-height: 100%; aspect-ratio: 16 / 9; }
.frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
/* 挡住播放器顶部的标题和链接，防止点出去 */
.shield-top { position: absolute; left: 0; right: 0; top: 0; height: 18%; z-index: 2; }
/* 开始播放后盖住整个 YouTube 画面，点一下就是暂停 / 继续 */
.shield { position: absolute; inset: 0; z-index: 3; }
.player.bili .shield { display: none; }
.player:not(.started) .shield { pointer-events: none; }

.player-bottom { padding: 12px 18px 18px; }
.controls { display: flex; align-items: center; gap: 16px; }
.play-btn {
  width: 76px; height: 76px; border-radius: 50%; background: var(--accent);
  font-size: 34px; flex: none; box-shadow: 0 4px 0 var(--accent-dark);
}
.bar { flex: 1; height: 10px; background: rgba(255,255,255,.18); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .5s linear; }
.time { font-variant-numeric: tabular-nums; font-size: 18px; min-width: 64px; text-align: right; opacity: .85; }
.hint { font-size: 17px; opacity: .8; }

.done-screen {
  position: absolute; inset: 0; z-index: 5;
  background: radial-gradient(circle at 50% 40%, #ffd36b, #ff8a3d);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.done-star { font-size: 140px; animation: pop .6s cubic-bezier(.2, 1.6, .4, 1); }
.done-text { font-size: 44px; font-weight: 900; text-shadow: 0 3px 0 rgba(0,0,0,.12); }
.done-screen .big-btn { background: #fff; color: var(--accent-dark); box-shadow: 0 6px 0 rgba(0,0,0,.15); }
@keyframes pop { from { transform: scale(.2) rotate(-30deg); } to { transform: scale(1) rotate(0); } }

/* ---------- 记录 ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 20; background: var(--bg);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 22px; flex: 1; }
.tabs { display: flex; gap: 6px; background: var(--line); padding: 4px; border-radius: 12px; }
.tabs button { padding: 8px 16px; border-radius: 9px; font-size: 16px; }
.tabs button.on { background: #fff; font-weight: 700; }
.sheet .icon-btn { background: var(--line); color: var(--ink); width: 44px; height: 44px; font-size: 20px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 8px 16px 32px; -webkit-overflow-scrolling: touch; }

.day { background: #fff; border-radius: 16px; margin: 12px 0; overflow: hidden; }
.day-head { width: 100%; display: flex; align-items: center; gap: 12px; padding: 14px 16px; text-align: left; }
.day-head .d { font-weight: 700; font-size: 17px; flex: 1; }
.day-head .s { color: var(--muted); font-size: 15px; }
.pill { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--line); }
.pill.ok { background: #d9f3e6; color: #1f7a52; }
.rows { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 15px; }
.row:last-child { border-bottom: 0; }
.row .st { width: 24px; text-align: center; flex: none; }
.row .t { flex: 1; min-width: 0; }
.row .t b { font-weight: 600; }
.row .t span { color: var(--muted); display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .m { color: var(--muted); font-size: 13px; white-space: nowrap; }
.row .act { font-size: 13px; padding: 6px 10px; border-radius: 8px; background: var(--line); white-space: nowrap; }

.series-block { background: #fff; border-radius: 16px; margin: 12px 0; overflow: hidden; }
.series-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; width: 100%; text-align: left; }
.series-head b { flex: 1; font-size: 17px; }
.series-head .prog { width: 120px; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.series-head .prog div { height: 100%; background: var(--done); }
.unseen { color: var(--lock); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }
