:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5f6b7a;
  --line: #dde2e8;
  --accent: #1f7a5a;
  --accent-soft: #e3f2ec;
  --danger: #c0392b;
  --warn: #b7791f;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161b;
    --surface: #1b2128;
    --text: #e6eaef;
    --muted: #9aa5b1;
    --line: #2c343e;
    --accent: #4cc39a;
    --accent-soft: #1d3a30;
    --danger: #ff7a6b;
    --warn: #f0b45a;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}
a { color: var(--accent); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* 頂欄 */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.top .wrap { display: flex; align-items: center; gap: 12px; min-height: 56px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; flex: 1 1 auto; }
.search {
  flex: 1 1 220px; max-width: 360px;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg); color: var(--text); font-size: 16px;
}

/* 篩選列 */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 16px 0 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 6px 14px; border-radius: 999px; cursor: pointer; font-size: 15px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
select, input[type=text], input[type=password], textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
.chip-sm { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }

h2.sec { font-size: 17px; margin: 24px 0 10px; }
.empty { color: var(--muted); padding: 32px 0; text-align: center; }

/* 卡片 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
@media (max-width: 480px) { .grid { grid-template-columns: 1fr 1fr; gap: 10px; } }
.card {
  display: block; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.card:hover { border-color: var(--accent); }
.thumb { position: relative; aspect-ratio: 16 / 9; background: var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dur, .badge-v {
  position: absolute; bottom: 6px; font-size: 12px; color: #fff;
  background: rgba(0, 0, 0, .7); padding: 1px 6px; border-radius: 4px;
}
.dur { right: 6px; }
.badge-v { left: 6px; }
.card-body { padding: 8px 10px 10px; }
.card-title { font-weight: 600; font-size: 15px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }

.pl-list { display: grid; gap: 8px; }
.pl-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--text);
}
.pl-item:hover { border-color: var(--accent); }
.pl-item small { color: var(--muted); }

/* 播放頁 */
.watch { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; margin-top: 16px; }
@media (max-width: 860px) { .watch { grid-template-columns: 1fr; } }
.player-box { background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; }
.player-box.vertical { aspect-ratio: 9 / 16; max-height: 80vh; max-width: calc(80vh * 9 / 16); margin: 0 auto; width: 100%; }
.player-box > div, .player-box iframe, .player-box video { width: 100%; height: 100%; display: block; border: 0; }
.v-title { font-size: 20px; margin: 14px 0 6px; }
.v-meta { color: var(--muted); font-size: 14px; }
.v-src { margin-top: 10px; font-size: 14px; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  font: inherit; font-size: 14px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 8px; text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.side-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 16px; }
.side-box h3 { margin: 0 0 8px; font-size: 15px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.side-box h3 label { font-weight: 400; font-size: 13px; color: var(--muted); }
.mini { display: flex; gap: 10px; padding: 6px; border-radius: 8px; text-decoration: none; color: var(--text); }
.mini:hover, .mini.cur { background: var(--accent-soft); }
.mini img { width: 112px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; flex: none; background: var(--line); }
.mini div { font-size: 14px; line-height: 1.4; }
.mini small { color: var(--muted); display: block; }

/* 彈窗 */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: none; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal.open { display: flex; }
.modal-box { background: var(--surface); border-radius: var(--radius); padding: 18px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; }
.modal-box h3 { margin: 0 0 12px; }
.qr-box { text-align: center; }
.qr-box img { width: 240px; height: 240px; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; display: none; z-index: 60; }

/* 後台 */
.login-card { max-width: 340px; margin: 12vh auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.login-card input { width: 100%; margin: 10px 0; }
.tabs { display: flex; gap: 6px; margin: 16px 0; }
.tbl-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
td.t { white-space: normal; min-width: 180px; }
th { color: var(--muted); font-weight: 600; }
.st-draft { color: var(--warn); }
.st-published { color: var(--accent); }
.st-archived { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
@media (max-width: 480px) { .form-grid { grid-template-columns: 1fr; } }
.checks { margin-top: 12px; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; }
.checks label { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; padding: 3px 0; }
.err { color: var(--danger); font-size: 14px; min-height: 1.4em; margin-top: 8px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.pick-list { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.pick-list div { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
.pick-list div span { flex: 1; }
.yt-preview { width: 100%; max-width: 200px; border-radius: 6px; margin-top: 6px; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 32px 0 24px; }
