/* ===== Màu & biến ===== */
:root {
  --brand: #16a36a;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface2: #f1f3f5;
  --line: #e4e7eb;
  --text: #1c1f23;
  --muted: #6b7280;
  --live: #129a5f;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 2px 10px rgba(16, 24, 40, .05);
  --radius: 16px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --surface: #1b1e22;
    --surface2: #24282d;
    --line: #2e3339;
    --text: #e8eaed;
    --muted: #9aa1a9;
    --live: #3fd08f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}
body.has-player { padding-bottom: calc(72px + var(--safe-b)); }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
svg { width: 1em; height: 1em; fill: currentColor; flex: none; }
[hidden] { display: none !important; }

/* ===== Thanh trên ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 750; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; min-width: 0; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; }
.brand img { height: 28px; width: auto; border-radius: 6px; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 20%, transparent); flex: none; }
.topsearch { flex: 1; max-width: 420px; margin-left: auto; position: relative; }
.topsearch svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 17px; }
.topsearch input {
  width: 100%; height: 40px; padding: 0 12px 0 38px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.topsearch input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }

/* ===== Bố cục ===== */
.wrap { max-width: 980px; margin: 0 auto; padding: 20px 16px 8px; }
.wrap.narrow { max-width: 680px; }
.center { text-align: center; }
.h1 { font-size: clamp(24px, 6vw, 32px); line-height: 1.2; letter-spacing: -.02em; margin: 6px 0 4px; }
.h2 { font-size: 19px; letter-spacing: -.01em; margin: 28px 0 12px; }
.sub { margin: 0 0 18px; color: var(--muted); font-family: var(--mono); font-size: 12.5px; }
.empty { color: var(--muted); padding: 12px 0; }
.back { display: inline-block; color: var(--muted); font-size: 14px; padding: 4px 0; margin-bottom: 10px; }

/* ===== Nhãn & số liệu ===== */
.tag {
  display: inline-block; font-family: var(--mono); font-size: 10.5px; font-weight: 700; line-height: 1;
  padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); background: var(--surface);
  white-space: nowrap;
}
.meta { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.meta svg { font-size: 13px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12px; color: var(--live); white-space: nowrap; }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--live); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 50%, transparent); } 70%, 100% { box-shadow: 0 0 0 6px transparent; } }

/* ===== Hàng thẻ cuộn ngang ===== */
.shelf { margin-top: 26px; }
.shelf-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.shelf-head h2 { font-size: 19px; margin: 0; letter-spacing: -.01em; white-space: nowrap; }
.arrows { margin-left: auto; display: none; gap: 4px; }
.arrows button { width: 32px; height: 32px; border-radius: 50%; font-size: 22px; line-height: 1; color: var(--muted); }
.arrows button:hover { background: var(--surface2); color: var(--text); }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs button { font-size: 12.5px; padding: 5px 11px; border-radius: 999px; background: var(--surface2); color: var(--muted); white-space: nowrap; border: 1px solid transparent; }
.tabs button.on { background: var(--surface); color: var(--brand); border-color: var(--brand); font-weight: 600; }

.rail {
  display: grid; grid-auto-flow: column; grid-auto-columns: 76%;
  gap: 10px; overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory; scroll-padding: 0 16px;
  margin: 0 -16px; padding: 2px 16px 8px;
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.card {
  scroll-snap-align: start;
  display: flex; gap: 10px; align-items: flex-start;
  padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s;
}
.card:active { transform: scale(.98); }
.card-body { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
.card-title { font-size: 16px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rank { font-size: 20px; font-weight: 800; color: var(--muted); min-width: 18px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.rank.r1 { color: #e0a100; } .rank.r2 { color: #8c9aa3; } .rank.r3 { color: #c07a43; }

/* ===== Danh sách ===== */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  transition: transform .15s, border-color .15s;
}
.row:active { transform: scale(.985); }
.row-icon {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 16px;
  background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand);
}
.row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.row-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row-head b { font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: flex; gap: 10px; flex-wrap: wrap; }
.dur { font-family: var(--mono); font-size: 12px; font-weight: 700; padding: 3px 7px; border-radius: 6px; background: var(--surface2); color: var(--muted); }

.pager { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 20px 0; font-size: 14px; }
.pager a, .pager .off { padding: 10px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-weight: 600; }
.pager .off { opacity: .45; }

/* ===== Trang nghe ===== */
.hero {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 16px;
  padding: 20px; border-radius: 22px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.hero-art {
  position: relative; width: 132px; height: 132px; border-radius: 20px; flex: none;
  display: grid; place-items: center;
  background: radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--brand) 18%, transparent), transparent 65%), var(--surface2);
  border: 1px solid var(--line);
}
.hero-art .dur { position: absolute; bottom: 8px; right: 8px; background: var(--surface); }
.hero-body { min-width: 0; width: 100%; }
.hero h1 { font-size: clamp(22px, 6vw, 30px); line-height: 1.2; letter-spacing: -.02em; margin: 0 0 10px; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: center; }
.hero-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: center; }
.btn-play {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; padding: 0 28px; border-radius: 14px;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 16px;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 40%, transparent);
  transition: transform .12s, filter .15s;
}
.btn-play:active { transform: scale(.96); }
.btn-play:disabled { opacity: .5; }
.btn-play.inline { height: 44px; }
.btn-ghost { display: inline-flex; align-items: center; gap: 8px; height: 50px; padding: 0 18px; border-radius: 14px; background: var(--surface2); border: 1px solid var(--line); font-weight: 600; }
.resume { margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.desc { margin-top: 16px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 14.5px; }

.parts { display: flex; flex-direction: column; gap: 8px; }
.part {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  padding: 12px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
}
.part-no { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--surface2); font-weight: 700; font-size: 14px; flex: none; }
.part-body { display: flex; flex-direction: column; min-width: 0; }
.part-body b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.part-body small { font-family: var(--mono); color: var(--muted); }
.part-prog { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; }
.part-prog span { display: block; height: 100%; width: 0; background: color-mix(in srgb, var(--brand) 55%, transparent); }
.part.on { border-color: var(--brand); }
.part.on .part-no { background: var(--brand); color: #fff; }

.prose { line-height: 1.7; }
.prose img { max-width: 100%; height: auto; }
.prose a { color: var(--brand); text-decoration: underline; }

/* ===== Chân trang ===== */
.footer { max-width: 980px; margin: 36px auto 0; padding: 20px 16px 28px; border-top: 1px solid var(--line); text-align: center; color: var(--muted); font-size: 13.5px; }
.footer nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; margin-bottom: 8px; }
.footer p { margin: 0; }

/* ===== Sóng nhạc ===== */
.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.eq i { width: 3px; height: 30%; background: var(--brand); border-radius: 2px; }
.eq.big { height: 46px; gap: 5px; }
.eq.big i { width: 7px; }
body.is-playing .eq i { animation: eq 1s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -.3s !important; height: 70%; }
.eq i:nth-child(3) { animation-delay: -.6s !important; height: 50%; }
.eq i:nth-child(4) { animation-delay: -.15s !important; height: 85%; }
.eq i:nth-child(5) { animation-delay: -.45s !important; height: 40%; }
@keyframes eq { 0%, 100% { height: 25%; } 50% { height: 100%; } }

/* ===== Trình phát mini ===== */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(16px);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  animation: up .25s ease-out;
}
@keyframes up { from { transform: translateY(100%); } }
.pl-progress-mini { height: 3px; background: var(--line); }
.pl-progress-mini span { display: block; height: 100%; width: 0; background: var(--brand); }
.pl-bar { display: flex; align-items: center; gap: 6px; max-width: 980px; margin: 0 auto; padding: 8px 10px 8px 16px; height: 66px; }
.pl-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; height: 100%; }
.pl-text { display: flex; flex-direction: column; min-width: 0; }
.pl-title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-sub { font-size: 12.5px; color: var(--muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-btn { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; flex: none; }
.pl-btn.pl-play { background: var(--brand); color: #fff; }
.pl-close { color: var(--muted); font-size: 20px; }

.pl-play::before {
  content: ""; width: 1em; height: 1em; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E") center/contain no-repeat;
}
body.is-playing .pl-play::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 5h4v14H6zm8 0h4v14h-4z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 5h4v14H6zm8 0h4v14h-4z'/%3E%3C/svg%3E");
}
body.is-loading .pl-play::before {
  -webkit-mask: none; mask: none; background: none;
  border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%;
  width: .8em; height: .8em; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Trình phát mở rộng ===== */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(5, 15, 10, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet-panel {
  width: 100%; max-width: 480px; max-height: 100%; overflow-y: auto;
  background: var(--surface); border-radius: 26px 26px 0 0;
  padding: 6px 22px calc(26px + var(--safe-b));
  text-align: center;
  animation: up .28s cubic-bezier(.2, .8, .2, 1);
}
.sheet-grip { display: block; width: 100%; padding: 10px 0 14px; }
.sheet-grip span { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto; }
.sheet-art { width: min(62vw, 220px); aspect-ratio: 1; margin: 4px auto 18px; border-radius: 26px; display: grid; place-items: center;
  background: radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--brand) 20%, transparent), transparent 65%), var(--surface2); border: 1px solid var(--line); }
.sheet-title { font-size: 21px; line-height: 1.25; margin: 0 0 4px; letter-spacing: -.01em; }
.sheet-sub { margin: 0 0 14px; color: var(--muted); font-size: 13.5px; }

.seek-range {
  --pct: 0%;
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; cursor: pointer; touch-action: none;
}
.seek-range::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--brand) var(--pct), var(--line) var(--pct)); }
.seek-range::-moz-range-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--brand) var(--pct), var(--line) var(--pct)); }
.seek-range::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--brand); margin-top: -6px; border: 3px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.seek-range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--brand); border: 3px solid var(--surface); }
.seek-time { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 12.5px; color: var(--muted); margin-top: -2px; }

.controls { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 18px; }
.c-btn { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-size: 28px; color: var(--text); }
.c-btn:active { background: var(--surface2); }
.c-btn text { fill: currentColor; font-family: system-ui, sans-serif; }
.c-btn.c-main { width: 74px; height: 74px; font-size: 32px; background: var(--brand); color: #fff; box-shadow: 0 8px 22px color-mix(in srgb, var(--brand) 45%, transparent); }
.c-btn.c-main:active { transform: scale(.95); background: var(--brand); }
.extras { display: flex; gap: 10px; justify-content: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 16px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--line); font-size: 14px; }
.chip b { font-family: var(--mono); }
.chip.on { border-color: var(--brand); color: var(--brand); }
.timer-menu { margin-top: 14px; padding: 14px; border-radius: 18px; background: var(--surface2); text-align: left; }
.timer-menu p { margin: 0 0 10px; font-weight: 700; font-size: 14px; }
.timer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.timer-grid button { height: 42px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.timer-grid button.wide { grid-column: 1 / -1; color: var(--muted); }

/* ===== Popup quảng cáo ===== */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(5, 15, 10, .55); animation: fade .2s; }
.modal-box {
  position: relative; width: 100%; max-width: 400px; max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--surface); border-radius: 22px; padding: 22px 18px 16px; text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3); animation: pop .25s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
.modal-x { position: absolute; top: 10px; right: 10px; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: var(--surface2); border: 1px solid var(--line); }
.ul-msg { margin: 34px 4px 14px; font-weight: 650; font-size: 15px; line-height: 1.45; }
.ul-card { display: block; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); background: #fff; color: #222; }
.ul-card img { display: block; width: 100%; aspect-ratio: 1; max-height: 34vh; object-fit: contain; background: #fff; }
.ul-meta { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; text-align: left; }
.ul-title { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ul-meta s { color: #999; font-size: 13px; }
.ul-meta b { color: #ee4d2d; font-size: 18px; }
.ul-btn {
  display: flex; align-items: center; justify-content: center; margin-top: 14px; min-height: 54px; padding: 8px 16px;
  border-radius: 14px; background: var(--brand); color: #fff; font-weight: 750; font-size: 16px;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--brand) 40%, transparent);
  animation: nudge 2.2s ease-in-out infinite;
}
@keyframes nudge { 0%, 85%, 100% { transform: scale(1); } 92% { transform: scale(1.03); } }
.ul-note { margin: 12px 4px 0; color: var(--muted); font-size: 13px; }

.toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 60;
  padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 14px;
  box-shadow: var(--shadow); animation: fade .2s; max-width: calc(100% - 32px);
}

/* ===== Màn hình lớn ===== */
@media (min-width: 720px) {
  .rail { grid-auto-columns: calc((100% - 30px) / 4); margin: 0; padding: 2px 0 8px; scroll-padding: 0; }
  .arrows { display: flex; }
  .shelf-head .tabs + .arrows, .shelf-head h2 + .arrows { margin-left: auto; }
  .hero { flex-direction: row; text-align: left; align-items: center; padding: 24px; }
  .hero-meta, .hero-actions { justify-content: flex-start; }
  .card:hover, .row:hover, .part:hover { border-color: color-mix(in srgb, var(--brand) 50%, var(--line)); }
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 26px; max-height: calc(100vh - 40px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
