/* ===== YouTube 風格深色主題 ===== */
:root {
  --bg: #0f0f0f;
  --bg-elevated: #212121;
  --surface: #272727;
  --surface-hover: #3d3d3d;
  --text: #f1f1f1;
  --text-dim: #aaaaaa;
  --border: #303030;
  --red: #ff0033;
  --blue: #3ea6ff;
  --header-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Roboto", "Noto Sans TC", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
svg { width: 24px; height: 24px; fill: currentColor; }

/* ===== Header ===== */
.yt-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg);
}
.header-left, .header-right { display: flex; align-items: center; gap: 8px; }
.header-center { flex: 0 1 640px; display: flex; justify-content: center; padding: 0 16px; }

.icon-btn {
  background: none; border: none; color: var(--text);
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: var(--surface); }

.logo { display: flex; align-items: center; gap: 4px; }
.logo-mark { color: var(--red); display: grid; place-items: center; }
.logo-mark svg { width: 28px; height: 28px; }
.logo-text { font-size: 20px; font-weight: 700; letter-spacing: -1px; }

.search-box {
  display: flex; width: 100%; max-width: 600px;
  height: 40px;
}
.search-box input {
  flex: 1; background: #121212; border: 1px solid var(--border);
  border-right: none; border-radius: 40px 0 0 40px;
  color: var(--text); padding: 0 16px; font-size: 16px; outline: none;
}
.search-box input:focus { border-color: var(--blue); }
.search-btn {
  width: 64px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 0 40px 40px 0; color: var(--text); cursor: pointer;
  display: grid; place-items: center;
}
.search-btn:hover { background: var(--surface-hover); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #f43f5e, #8b5cf6);
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}

/* ===== Main ===== */
.yt-main { padding: 16px 24px 60px; max-width: 1600px; margin: 0 auto; }

/* 分類膠囊 */
.chips {
  display: flex; gap: 12px; overflow-x: auto; padding-bottom: 14px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  white-space: nowrap; background: var(--surface); color: var(--text);
  border: none; padding: 8px 12px; border-radius: 8px; font-size: 14px;
  cursor: pointer;
}
.chip:hover { background: var(--surface-hover); }
.chip-active { background: var(--text); color: #0f0f0f; }

/* ===== 影片格狀清單 ===== */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px 16px;
  margin-top: 8px;
}
.video-card { display: block; }
.thumb {
  position: relative; aspect-ratio: 16 / 9; border-radius: 12px;
  overflow: hidden; background: var(--surface);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-card:hover .thumb { border-radius: 0; transition: border-radius .2s; }
.thumb-duration {
  position: absolute; right: 8px; bottom: 8px;
  background: rgba(0,0,0,.8); color: #fff; font-size: 12px; font-weight: 500;
  padding: 1px 4px; border-radius: 4px;
}
.card-body { display: flex; gap: 12px; margin-top: 12px; }
.card-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, #06b6d4, #6366f1);
  display: grid; place-items: center; font-weight: 700;
}
.card-avatar.lg { width: 40px; height: 40px; }
.card-meta { min-width: 0; }
.card-title {
  margin: 0; font-size: 16px; font-weight: 500; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-channel { margin: 4px 0 0; color: var(--text-dim); font-size: 14px; }
.card-sub { margin: 2px 0 0; color: var(--text-dim); font-size: 13px; }

/* ===== Watch 版面 ===== */
.watch-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 402px; gap: 24px;
  align-items: start;
}
.player-wrap {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #000; border-radius: 12px; overflow: hidden;
}
.player { width: 100%; height: 100%; display: block; background: #000; cursor: pointer; }

/* 中央大播放鍵 */
.big-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 3; width: 72px; height: 72px; border-radius: 50%;
  background: rgba(0,0,0,.6); border: none; color: #fff; cursor: pointer;
  display: grid; place-items: center;
}
.big-play:hover { background: var(--red); }
.big-play svg { width: 38px; height: 38px; }

/* 自製控制列(顯示假時長)*/
.vctrl {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
  display: flex; align-items: center; gap: 10px; padding: 8px 12px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  opacity: 0; transition: opacity .2s;
}
.player-wrap:hover .vctrl,
.vctrl:hover { opacity: 1; }
.vctrl-btn {
  background: none; border: none; color: #fff; cursor: pointer;
  width: 32px; height: 32px; display: grid; place-items: center; flex: none;
}
.vctrl-btn svg { width: 24px; height: 24px; }
.vctrl-time { color: #fff; font-size: 13px; font-variant-numeric: tabular-nums; flex: none; }
.vctrl-bar {
  flex: 1; height: 4px; background: rgba(255,255,255,.3); border-radius: 2px;
  position: relative; overflow: hidden;
}
.vctrl-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--red); }

/* 鎖定遮罩 */
.lock-overlay {
  position: absolute; inset: 0; z-index: 5;
  background: rgba(0,0,0,.78); backdrop-filter: blur(4px);
  display: grid; place-items: center; text-align: center;
}
.lock-card { max-width: 420px; padding: 24px; }
.lock-icon { font-size: 48px; }
.lock-card h3 { margin: 8px 0; font-size: 22px; }
.lock-card p { color: var(--text-dim); margin: 0 0 18px; }
.btn-unlock {
  background: var(--red); color: #fff; border: none; cursor: pointer;
  font-size: 15px; font-weight: 700; padding: 11px 22px; border-radius: 22px;
}
.btn-unlock:hover { filter: brightness(1.1); }

.watch-title { font-size: 20px; font-weight: 700; margin: 16px 0 12px; }
.watch-meta {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 12px;
}
.watch-channel { display: flex; align-items: center; gap: 12px; }
.btn-sub {
  background: var(--text); color: #0f0f0f; border: none; cursor: pointer;
  font-weight: 700; padding: 9px 16px; border-radius: 18px; margin-left: 8px;
}
.watch-actions { display: flex; gap: 8px; }
.pill {
  background: var(--surface); color: var(--text); border: none; cursor: pointer;
  padding: 9px 14px; border-radius: 18px; font-size: 14px; font-weight: 500;
}
.pill:hover { background: var(--surface-hover); }

/* 推薦清單 */
.watch-secondary { display: flex; flex-direction: column; gap: 8px; }
.rec-card { display: flex; gap: 8px; }
.rec-thumb {
  position: relative; width: 168px; flex: none; aspect-ratio: 16/9;
  border-radius: 8px; overflow: hidden; background: var(--surface);
}
.rec-thumb img { width: 100%; height: 100%; object-fit: cover; }
.rec-meta { min-width: 0; }
.rec-title {
  margin: 0 0 4px; font-size: 14px; font-weight: 500; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.7); }
.modal-card {
  position: relative; z-index: 1; width: min(440px, 92vw);
  max-height: 90vh; overflow-y: auto;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.modal-close {
  position: absolute; top: 12px; right: 14px; background: none; border: none;
  color: var(--text-dim); font-size: 26px; line-height: 1; cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal-title { margin: 0 0 6px; font-size: 20px; }
.modal-sub { margin: 0 0 16px; color: var(--text-dim); }
.steps { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 12px; }
.steps li { display: flex; align-items: flex-start; gap: 12px; font-size: 15px; }
.step-text { line-height: 1.5; word-break: break-word; }
.step-no {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--red); color: #fff; font-weight: 700; font-size: 14px;
  display: grid; place-items: center;
}
.copy-btn {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: 8px; vertical-align: middle; white-space: nowrap;
  background: var(--blue); color: #0f0f0f; border: none;
  border-radius: 14px; padding: 5px 12px; font-size: 13px; font-weight: 700;
  cursor: pointer; box-shadow: 0 0 0 2px rgba(62, 166, 255, .3);
}
.copy-btn:hover { filter: brightness(1.12); }
.copy-btn:active { transform: scale(.96); }
.copy-btn.copied {
  background: #2bd96b; color: #0f0f0f; box-shadow: 0 0 0 2px rgba(43, 217, 107, .35);
}
.pwd-row { display: flex; gap: 8px; }
.pwd-row input {
  flex: 1; background: #121212; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 11px 14px; font-size: 15px; outline: none;
}
.pwd-row input:focus { border-color: var(--blue); }
.unlock-msg { margin: 12px 0 0; font-size: 14px; min-height: 18px; }

/* 「為什麼要這樣做?」可展開說明 */
.why { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.why > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--blue); font-size: 14px; font-weight: 500;
}
.why > summary::-webkit-details-marker { display: none; }
.why > summary::marker { content: ""; }
.why-q {
  display: inline-grid; place-items: center; width: 20px; height: 20px;
  border-radius: 50%; background: var(--blue); color: #0f0f0f;
  font-weight: 700; font-size: 13px; flex: none;
}
.why[open] > summary { margin-bottom: 10px; }
.why-body { color: var(--text-dim); font-size: 13px; line-height: 1.7; }
.why-body p { margin: 0 0 8px; }
.why-body p:last-child { margin-bottom: 0; }
.why-body strong { color: var(--text); }
.unlock-msg.error { color: #ff6b6b; }
.unlock-msg.success { color: #51cf66; }

.hidden { display: none !important; }

/* 顯示工具:預設桌機顯示 desktop、隱藏 mobile */
.only-mobile { display: none; }
.only-desktop { display: grid; }

/* ===== RWD(行動優先,多數訪客為手機)===== */

/* 平板 / 窄視窗:watch 改單欄,推薦清單橫向縮圖列 */
@media (max-width: 1000px) {
  .watch-layout { grid-template-columns: 1fr; }
  .yt-main { padding: 12px 16px 72px; }
}

/* 手機:精簡 header、單欄影片、加大點擊區 */
@media (max-width: 640px) {
  :root { --header-h: 52px; }
  .yt-header { padding: 0 8px; }
  .header-center { display: none; }          /* 收起整條搜尋,改用 header 搜尋圖示 */
  .only-mobile { display: grid; }
  .only-desktop { display: none; }
  .logo-text { font-size: 18px; }            /* 手機也顯示站名(縮小一點)*/

  .yt-main { padding: 8px 12px 72px; }
  .chips { gap: 8px; padding-bottom: 10px; }

  /* 單欄大卡(YouTube 手機體驗)*/
  .video-grid { grid-template-columns: 1fr; gap: 18px; }
  .card-title { font-size: 15px; }

  /* watch 頁 */
  .player-wrap { border-radius: 0; margin: 0 -12px; width: calc(100% + 24px); }
  .watch-title { font-size: 17px; }
  .watch-meta { gap: 10px; }
  .watch-channel { width: 100%; }
  /* 操作列改可橫向滑動,避免擠爆 */
  .watch-actions {
    width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .watch-actions::-webkit-scrollbar { display: none; }
  .pill { flex: none; }

  /* 推薦卡:縮圖縮小一點,文字優先 */
  .watch-secondary { gap: 12px; margin-top: 8px; }
  .rec-thumb { width: 160px; }
  .rec-title { font-size: 14px; }

  /* 鎖定卡 / Modal 在小螢幕更貼合 */
  .lock-card { padding: 16px; }
  .lock-card h3 { font-size: 18px; }
  .modal-card { padding: 22px 18px; }
  .btn-unlock, .pwd-row input { font-size: 16px; }   /* 16px 防 iOS 自動放大 */
  .pwd-row { flex-direction: column; }
  .pwd-row .btn-unlock { width: 100%; padding: 13px; }
}

/* 超小螢幕:推薦卡改上下堆疊 */
@media (max-width: 400px) {
  .rec-card { flex-direction: column; }
  .rec-thumb { width: 100%; }
}
