:root {
  --bg: #0f0f0f;
  --surface: #1f1f1f;
  --surface2: #272727;
  --chip: #272727;
  --text: #f1f1f1;
  --muted: #aaa;
  --red: #f03;
  --radius: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.error { color: #ff6b6b; font-size: 14px; }
.hint { color: #ffd60a; font-size: 13px; }

/* ===== Topbar kiểu YouTube ===== */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  background: rgba(15,15,15,.9);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 7px; text-decoration: none; color: var(--text); flex: 0 0 auto; }
.logo { width: 30px; height: 30px; border-radius: 7px; }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: -0.5px; white-space: nowrap; }
.searchbox {
  flex: 1; display: flex; max-width: 560px; margin: 0 auto;
  background: #121212; border: 1px solid #303030; border-radius: 999px; overflow: hidden;
}
.searchbox:focus-within { border-color: #1c62b9; }
.searchbox input {
  flex: 1; background: transparent; border: 0; color: var(--text);
  padding: 9px 16px; font-size: 15px; outline: none; min-width: 0;
}
.searchbox button {
  background: #222; border: 0; border-left: 1px solid #303030; color: var(--text);
  padding: 0 18px; font-size: 15px; cursor: pointer; flex: 0 0 auto;
}
.account-btn {
  flex: 0 0 auto; background: transparent; color: #3ea6ff; cursor: pointer;
  border: 1px solid #303030; border-radius: 999px; padding: 7px 13px;
  font-size: 13.5px; font-weight: 600; max-width: 128px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.account-btn.logged { color: var(--text); background: #272727; }

/* ===== Chips ===== */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; background: var(--chip); color: var(--text); border: 0; cursor: pointer;
  border-radius: 8px; padding: 7px 12px; font-size: 13.5px; font-weight: 500;
}
.chip.active { background: #f1f1f1; color: #0f0f0f; }

/* ===== Player ===== */
.player { background: #000; }
.video-wrap { position: relative; width: 100%; max-width: 1280px; margin: 0 auto; aspect-ratio: 16/9; background: #000; max-height: 72vh; }
.video-wrap video { width: 100%; height: 100%; display: block; background: #000; }
.audio-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  background: linear-gradient(160deg, #2b0a12, #141414 60%);
}
.audio-icon { font-size: 46px; }
.audio-placeholder small { color: var(--muted); }
.player-loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px;
  align-items: center; justify-content: center; background: rgba(0,0,0,.45);
  font-size: 14px; color: #eee; pointer-events: none;
}
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.player-info { max-width: 1280px; margin: 0 auto; padding: 12px 16px 4px; }
.player-info h2 { font-size: 18px; margin: 0 0 4px; line-height: 1.35; }
.player-info > p { margin: 0 0 10px; font-size: 13px; }
.channel-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.channel-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: #7c4dff; color: #fff; font-weight: 700; font-size: 16px;
}
.channel-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subscribe-btn {
  flex: 0 0 auto; background: #f1f1f1; color: #0f0f0f; border: 0; cursor: pointer;
  border-radius: 999px; padding: 9px 16px; font-size: 14px; font-weight: 600;
}
.subscribe-btn.subscribed { background: #272727; color: var(--text); }
.player-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 12px; }
.related { max-width: 1280px; margin: 0 auto; padding: 4px 16px 16px; }
.related h3 { margin: 8px 0 4px; font-size: 16px; }

/* ===== Layout + lưới video kiểu YouTube ===== */
main { padding: 10px 14px 8px; max-width: 1400px; margin: 0 auto; }
.view { animation: viewIn .22s ease both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.section-title { font-size: 17px; margin: 16px 0 10px; display: flex; align-items: center; justify-content: space-between; }
.video-grid { display: grid; grid-template-columns: 1fr; gap: 22px 16px; }
@media (min-width: 640px) { .video-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .video-grid { grid-template-columns: 1fr 1fr 1fr; } }
.video-card { cursor: pointer; content-visibility: auto; }
.video-card:active { opacity: .75; }
.thumb { position: relative; width: 100%; aspect-ratio: 16/9; border-radius: var(--radius); overflow: hidden; background: var(--surface2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.duration {
  position: absolute; right: 6px; bottom: 6px;
  background: rgba(0,0,0,.8); color: #fff; font-size: 12px; font-weight: 600;
  padding: 2px 6px; border-radius: 5px;
}
.duration.live { background: var(--red); }
.card-meta { display: flex; gap: 10px; padding-top: 10px; }
.card-meta .avatar { width: 34px; height: 34px; font-size: 14px; }
.card-text { flex: 1; min-width: 0; }
.card-text .t { font-size: 15px; font-weight: 600; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-text .a, .card-text .v { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== Kênh đăng ký ===== */
.sub-channels { display: flex; gap: 14px; overflow-x: auto; padding: 6px 2px 12px; scrollbar-width: none; }
.sub-channels::-webkit-scrollbar { display: none; }
.sub-channel { flex: 0 0 auto; width: 74px; text-align: center; cursor: pointer; }
.sub-channel img, .sub-channel .avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; font-size: 22px; }
.sub-channel .n { font-size: 12px; margin-top: 5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ===== Cards / forms ===== */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; border: 1px solid rgba(255,255,255,.06); }
.card-title { margin: 0 0 8px; font-size: 17px; }
.card-label { display: block; font-weight: 600; margin: 10px 0 6px; font-size: 13.5px; color: #ddd; }
.card.guide h4 { margin: 12px 0 4px; font-size: 15px; }
.card.guide h4:first-child { margin-top: 0; }
.card.guide p { margin: 0 0 6px; font-size: 14px; color: #d8d8de; line-height: 1.45; }
.center-card { text-align: center; padding: 34px 18px; }
.big-emoji { font-size: 44px; margin-bottom: 8px; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.row .grow { flex: 1; }
input[type="text"], input[type="password"], select, textarea {
  width: 100%; background: var(--surface2); color: var(--text);
  border: 1px solid rgba(255,255,255,.12); border-radius: 10px;
  padding: 11px 12px; font-size: 15px; outline: none;
}
textarea { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: #3ea6ff; }
.primary-btn {
  background: #f1f1f1; color: #0f0f0f; border: 0; border-radius: 999px;
  padding: 11px 18px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.primary-btn:active { transform: scale(.97); }
.chip-btn {
  background: var(--surface2); color: var(--text); border: 1px solid rgba(255,255,255,.1);
  border-radius: 999px; padding: 9px 15px; font-size: 14px; cursor: pointer; font-weight: 500;
}
.chip-btn.on { background: #f1f1f1; color: #0f0f0f; border-color: #f1f1f1; }
.link-btn { background: none; border: 0; color: #ff6b6b; font-size: 13px; cursor: pointer; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 14px; cursor: pointer; }
.switch { width: 46px; height: 28px; flex: 0 0 auto; accent-color: #3ea6ff; cursor: pointer; }

/* ===== Tab bar ===== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: rgba(15,15,15,.92);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid rgba(255,255,255,.08);
}
.tab { background: none; border: 0; color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; padding: 4px 10px; min-width: 68px; }
.tab span { font-size: 20px; }
.tab.active { color: #fff; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  background: rgba(40,40,42,.96); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; opacity: 0; transition: all .25s ease; z-index: 60; pointer-events: none;
  max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 520px) {
  .brand-name { display: none; }
  .topbar { gap: 9px; }
  .account-btn { padding: 7px 10px; }
}
@media (prefers-reduced-motion: reduce) { .view { animation: none; } .spinner { animation-duration: 1.6s; } }

/* v0.2.1: nút "Bấm để phát" khi trình duyệt chặn tự phát */
.tap-play { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; pointer-events: none; z-index: 5; }
.tap-play-btn { pointer-events: auto; width: 72px; height: 72px; border-radius: 50%; border: 0; background: rgba(255,0,51,.92); color: #fff; font-size: 30px; cursor: pointer; box-shadow: 0 6px 24px rgba(0,0,0,.5); }
.tap-play-btn:active { transform: scale(.94); }
.tap-play-text { color: #fff; font-size: 14px; font-weight: 600; text-shadow: 0 1px 6px rgba(0,0,0,.8); }

/* v0.2.2 */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.tabbar { z-index: 200; }
button, .tab, .chip, .video-card { touch-action: manipulation; }
#embedWrap iframe { width: 100%; max-width: 1280px; margin: 0 auto; aspect-ratio: 16/9; border: 0; display: block; background: #000; }
#embedWrap .hint { max-width: 1280px; margin: 8px auto 0; }

/* v0.2.3: thanh báo có bản mới */
.update-banner { position: sticky; top: 0; z-index: 300; display: flex; align-items: center; justify-content: center; gap: 12px; padding: 8px 12px; background: #1d4ed8; color: #fff; font-size: 13.5px; }
.update-btn { background: #fff; color: #1d4ed8; border: 0; border-radius: 999px; padding: 5px 14px; font-weight: 700; cursor: pointer; }
