:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #5f6b7a;
  --line: #dde1e6;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --danger: #c0392b;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.eyebrow { color: var(--accent); font-weight: 600; margin: 0 0 .25rem; letter-spacing: .05em; }
.error { color: var(--danger); min-height: 1.5em; margin: .25rem 0; }

#app { min-height: 100%; }
.card {
  background: var(--card);
  max-width: 760px;
  margin: 48px auto;
  padding: 32px;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgb(0 0 0 / .08);
}
.login { max-width: 380px; }
label { display: block; margin: 0 0 12px; font-weight: 600; }
input {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
.actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

.btn {
  padding: 9px 18px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font: inherit; cursor: pointer;
}
.btn:hover { background: #f0f2f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.login .btn.primary { width: 100%; }
.admin-link { text-align: center; margin: 16px 0 0; font-size: .85em; }
.admin-link a { color: var(--muted); }

/* 大綱 */
.outline-list { list-style: none; counter-reset: pt; margin: 20px 0 0; padding: 0; }
.outline-list > li {
  counter-increment: pt;
  display: grid; grid-template-columns: 2.2em 1fr; column-gap: 4px;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.outline-list > li::before { content: counter(pt) "."; font-weight: 700; color: var(--accent); }
.pt-title { font-weight: 700; }
.pt-time { color: var(--muted); font-size: .85em; margin-left: 6px; font-variant-numeric: tabular-nums; font-weight: 400; }
.pt-summary { grid-column: 2; margin: 2px 0 0; color: var(--muted); font-size: .95em; }

.outline-list.compact > li { padding: 10px 8px; cursor: pointer; border-radius: 8px; border-top: none; margin-bottom: 2px; }
.outline-list.compact > li:hover { background: #f0f2f5; }
.outline-list.compact > li.current { background: var(--accent-soft); }
.outline-list.compact > li:focus-visible { outline: 2px solid var(--accent); }
.outline-list.compact .pt-summary { font-size: .88em; }

/* 學習頁 */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.1rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who { color: var(--muted); }
.learn {
  display: grid; grid-template-columns: 240px minmax(0, 1fr) 340px; gap: 16px;
  padding: 16px; height: calc(100vh - 57px);
}
.quiz-side { background: var(--card); border-radius: 12px; padding: 16px; overflow-y: auto; }
.quiz-side .quiz-block { margin: 0; padding: 0; border: none; }
/* Narrow outline: number and title; the summary opens on hover and for the segment being watched. */
.outline-list.compact > li { grid-template-columns: 1.8em 1fr; }
.outline-list.compact .pt-time { display: block; margin: 0; }
.outline-list.compact .pt-summary { display: none; }
.outline-list.compact > li:hover .pt-summary,
.outline-list.compact > li:focus-visible .pt-summary,
.outline-list.compact > li.current .pt-summary { display: block; }
.outline-list.compact .pt-quiz { margin: 4px 0 0; display: table; }
.segment { min-width: 0; overflow-y: auto; background: var(--card); border-radius: 12px; padding: 16px 20px; }
.seg-head { display: flex; align-items: baseline; gap: 10px; }
.seg-no { color: var(--accent); font-weight: 700; white-space: nowrap; }
.seg-title { margin: 0; font-size: 1.15rem; }
.seg-summary { color: var(--muted); margin: 6px 0 10px; }
.pretask-box {
  background: #eef6ef; border: 2px dashed #5a9a6a; border-radius: 10px;
  padding: 8px 12px; margin: 0 0 10px; font-weight: 600; color: #2f6b3e;
}
.player { position: relative; }
.player video { display: block; width: 100%; max-height: 56vh; background: #000; border-radius: 8px; }
.clip-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; font-size: .88em; color: var(--muted); }
.watch-status.done { color: #1e7b3a; font-weight: 600; }
.watch-bar { height: 6px; background: #e5e8ec; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.watch-bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.quiz-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.quiz-locked { display: flex; gap: 12px; align-items: flex-start; background: #f5f6f8; border-radius: 10px; padding: 12px 14px; color: var(--muted); }
.quiz-locked-icon { font-size: 1.4rem; line-height: 1; }
.quiz-locked-text { margin: 0; }
.side { background: var(--card); border-radius: 12px; padding: 16px; overflow-y: auto; }
.toast {
  position: absolute; left: 12px; top: 12px; margin: 0;
  background: rgb(0 0 0 / .72); color: #fff; padding: 6px 12px; border-radius: 6px; font-size: .9em;
}
.net-warning {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); margin: 0;
  background: #fff4e5; border: 1px solid #f0c27b; padding: 8px 14px; border-radius: 8px;
}

@media (max-width: 1100px) {
  .learn { grid-template-columns: 200px minmax(0, 1fr); height: auto; }
  .quiz-side { grid-column: 2; }
}
@media (max-width: 760px) {
  .learn { grid-template-columns: 1fr; height: auto; }
  .quiz-side { grid-column: auto; }
  .card { margin: 16px; padding: 20px; }
}

/* 確認視窗（不用 window.confirm） */
.modal-backdrop {
  position: fixed; inset: 0; background: rgb(0 0 0 / .4);
  display: grid; place-items: center; padding: 16px; z-index: 10;
}
.modal-backdrop[hidden] { display: none; }
.modal { background: #fff; border-radius: 12px; padding: 24px; max-width: 420px; }

/* 段落測驗 */
.quiz-question { font-weight: 700; margin: 0 0 12px; }
.quiz-choices { display: grid; gap: 8px; }
.quiz-choice {
  text-align: left; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font: inherit; cursor: pointer;
}
.quiz-choice:hover:not(:disabled) { background: #f0f2f5; }
.quiz-choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.quiz-choice:disabled { cursor: default; }
.quiz-feedback { min-height: 1.5em; margin: 12px 0 0; font-weight: 600; }
.quiz-feedback.correct { color: #1e7b3a; }
.quiz-feedback.wrong { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.pt-quiz {
  display: inline-block; margin-left: 8px; font-size: .78em; font-weight: 600;
  color: var(--muted); background: #eef0f3; border-radius: 999px; padding: 1px 8px; border: none; font-family: inherit;
}
.admin-quiz {
  grid-column: 2; margin-top: 6px; padding: 6px 10px; border: 1px dashed #c9a227;
  border-radius: 8px; background: #fffaeb; font-size: .88em; cursor: default;
}
.admin-quiz summary { cursor: pointer; color: #8a6100; font-weight: 600; }
.admin-quiz-q { font-weight: 700; margin: 6px 0 4px; }
.admin-quiz ol { margin: 0; padding-left: 20px; }
.admin-quiz li.answer { color: #1e7b3a; font-weight: 700; }
a.btn { text-decoration: none; display: inline-block; }
.pt-quiz.todo { background: var(--accent); color: #fff; }
