:root {
  --bg: #0d1117;
  --card: #151b23;
  --field: #11171f;
  --line: #252d37;
  --text: #f4f7fb;
  --muted: #8e9aaa;
  --accent: #b8f26a;
  --accent-ink: #11170e;
  --accent-soft: #202b24;
  --danger: #ff969d;
  --danger-soft: #542630;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(circle at 90% 0, #1d2f22 0, transparent 34rem), var(--bg);
  overflow-x: hidden;
}
body.has-player { padding-bottom: calc(110px + var(--safe-bottom)); }
button, a, input { font: inherit; }
button { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }
.icon { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-fill { fill: currentColor; stroke: none; }
.icon-xl { width: 36px; height: 36px; stroke-width: 1.6; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.shell {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(28px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.eyebrow { margin: 0; color: var(--accent); font-size: 11px; letter-spacing: .17em; text-transform: uppercase; font-weight: 800; }
.muted { color: var(--muted); line-height: 1.55; margin: 0; }
.error, .hero-card .error { color: #ff8f8f; font-size: 13px; min-height: 18px; margin: 6px 0 0; line-height: 1.4; }

.brand-mark {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 16px;
  background: var(--accent); color: var(--accent-ink); font-size: 28px; box-shadow: 0 0 40px #b8f26a33;
}
.brand-mark .icon { width: 24px; height: 24px; stroke-width: 2.2; }
.brand-mark.small { width: 38px; height: 38px; border-radius: 12px; box-shadow: none; flex: 0 0 auto; }
.brand-mark.small .icon { width: 19px; height: 19px; }

.primary {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; width: 100%; border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink);
  padding: 14px 18px; font-size: 16px; font-weight: 800; cursor: pointer;
  transition: transform .15s, filter .15s, opacity .15s;
}
.primary:active { transform: scale(.98); }
.primary:disabled { opacity: .65; cursor: wait; transform: none; }
@media (hover: hover) { .primary:not(:disabled):hover { filter: brightness(1.07); } }

.icon-button {
  display: grid; place-items: center; width: 44px; height: 44px; flex: 0 0 44px;
  border: 1px solid var(--line); border-radius: 13px; background: var(--card);
  color: var(--muted); font-size: 18px; cursor: pointer;
}
.icon-button:active { color: var(--accent); background: var(--accent-soft); }

/* ---------- Đăng nhập ---------- */
.auth-view {
  min-height: calc(100dvh - 44px - var(--safe-top) - var(--safe-bottom));
  display: flex; flex-direction: column; justify-content: center; gap: 22px;
  max-width: 420px; margin: 0 auto;
}
.auth-head h1 { font-size: clamp(34px, 11vw, 60px); line-height: 1; letter-spacing: -.06em; margin: 16px 0 12px; }
.auth-head h1 span { color: var(--accent); display: block; }
.auth-head .eyebrow { margin-top: 16px; }
.auth-form { display: grid; gap: 10px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; min-height: 18px; padding: 6px 0; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #3a4553; transition: background .12s, border-color .12s, transform .12s; }
.pin-dots span.filled { background: var(--accent); border-color: var(--accent); transform: scale(1.08); }
.pin-dots.shake { animation: shake .4s; }
.pin-dots.shake span { border-color: #ff8f8f; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.auth-form .error { text-align: center; margin: 0; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 6px; }
.keypad button {
  min-height: 58px; border: 1px solid var(--line); border-radius: 16px; background: var(--card);
  color: var(--text); font-size: 22px; font-weight: 700; cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: background .1s, transform .1s;
}
.keypad button.key-muted { color: var(--muted); font-size: 18px; display: grid; place-items: center; }
.keypad button .icon { width: 24px; height: 24px; }
.keypad button:active { background: #283628; color: var(--accent); transform: scale(.96); }

/* ---------- Màn hình chính ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 20px; }
.topbar-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h1 { font-size: 20px; letter-spacing: -.03em; margin: 4px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.hero-card {
  border: 1px solid #34402f; border-radius: 22px;
  background: linear-gradient(145deg, #1a241d, #131a19 70%);
  padding: 20px 16px 14px; position: relative; overflow: hidden;
}
.hero-card::after { content: ""; position: absolute; width: 180px; height: 180px; border-radius: 50%; right: -80px; top: -80px; background: #b8f26a0b; pointer-events: none; }
.hero-card h2 { font-size: clamp(24px, 7.5vw, 34px); line-height: 1.08; letter-spacing: -.05em; margin: 0 0 8px; max-width: 14ch; }
.hero-card p { color: var(--muted); font-size: 14px; margin: 0 0 16px; }
.download-form { display: grid; gap: 10px; position: relative; z-index: 1; }
.url-wrap {
  display: flex; align-items: center; gap: 8px; min-height: 54px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--field); padding: 0 6px 0 14px;
}
.url-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px #b8f26a1a; }
.url-icon { display: grid; color: var(--accent); }
.url-icon .icon { width: 18px; height: 18px; }
.url-wrap input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: #fff;
  padding: 14px 0; font-size: 16px; /* >= 16px để iOS không tự zoom */ outline: none;
}
.url-wrap input::placeholder { color: #66717f; }
.chip {
  flex: 0 0 auto; min-height: 40px; min-width: 40px; padding: 0 12px; border: 0; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent); font-size: 14px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.chip .icon { width: 16px; height: 16px; }
.chip:active { filter: brightness(1.2); }

.list-section { margin-top: 28px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 12px; }
.section-heading h2 { font-size: 20px; letter-spacing: -.03em; margin: 4px 0 0; }
.count-badge { display: grid; place-items: center; min-width: 30px; height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: 12px; }

.track-list { display: grid; gap: 10px; }
.track {
  display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 10px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
}
.track-icon {
  display: grid; place-items: center; flex: 0 0 46px; width: 46px; height: 46px; border: 0; border-radius: 13px;
  background: var(--accent-soft); color: var(--accent); font-size: 18px; font-weight: 800;
}
.play-button { cursor: pointer; transition: background .15s, color .15s; }
.play-button .icon { width: 18px; height: 18px; }
.play-button.is-playing { background: var(--accent); color: var(--accent-ink); }
.play-button:active { background: var(--accent); color: var(--accent-ink); }
.track-info { min-width: 0; flex: 1; }
.track-title {
  font-weight: 700; font-size: 14px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere;
}
.track-meta { color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.4; }
.action-button {
  display: grid; place-items: center; flex: 0 0 44px; width: 44px; height: 44px; border-radius: 13px;
  background: var(--accent-soft); color: var(--accent); text-decoration: none; font-size: 20px; font-weight: 700;
}
.action-button:active { background: var(--accent); color: var(--accent-ink); }
.dismiss {
  display: grid; place-items: center; flex: 0 0 36px; width: 36px; height: 36px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); font-size: 15px; cursor: pointer;
}
.dismiss .icon { width: 16px; height: 16px; }
.dismiss:active { background: #222a34; }

.has-error { border-color: #703b43; background: #24181d; }
.has-error .track-icon { background: var(--danger-soft); color: var(--danger); }
.track-icon .icon { width: 20px; height: 20px; }
.is-done .track-icon { background: var(--accent); color: var(--accent-ink); }
.job-error { color: var(--danger); font-size: 12px; line-height: 1.4; margin-top: 4px; overflow-wrap: anywhere; }
.job-spinner {
  display: block; flex: 0 0 22px; width: 22px; height: 22px; margin: 0 11px;
  border: 2px solid #3c4d40; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
}
.progress { height: 4px; margin-top: 8px; border-radius: 4px; background: #26302a; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .4s; }
.progress.indeterminate span { width: 35% !important; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

.empty-state { text-align: center; color: var(--muted); padding: 32px 12px; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty-state div { display: flex; justify-content: center; color: #566273; }
.empty-state p { line-height: 1.6; font-size: 13px; margin: 10px 0 0; }

footer { text-align: center; color: #697585; font-size: 12px; margin-top: 28px; line-height: 1.6; }
footer small { display: inline-block; margin-top: 6px; font-size: 11px; color: #56616f; }
footer .dot { color: var(--accent); padding: 0 5px; }

.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid #20300f; border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Trình phát ---------- */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px calc(12px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(12px + var(--safe-left));
  background: #10161dee; border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.player { flex-wrap: wrap; row-gap: 6px; }
.player-info { order: -1; flex: 1 0 100%; min-width: 0; }
.player-title { font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.player audio { flex: 1; min-width: 0; height: 44px; }
@media (min-width: 600px) {
  .player { justify-content: center; flex-wrap: nowrap; }
  .player-info { order: 0; flex: 0 1 220px; }
  .player-title { font-size: 13px; color: var(--text); }
  .player audio { flex: 0 1 420px; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); z-index: 30;
  max-width: min(92vw, 420px); padding: 12px 16px; border-radius: 12px;
  background: #e9f5dc; color: #11170e; font-size: 14px; font-weight: 600; text-align: center;
  box-shadow: 0 10px 30px #0008; opacity: 0; pointer-events: none;
  transform: translate(-50%, 16px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.has-player .toast { bottom: calc(118px + var(--safe-bottom)); }

/* ---------- Màn hình lớn ---------- */
@media (min-width: 600px) {
  .shell { padding-top: calc(36px + var(--safe-top)); padding-left: 24px; padding-right: 24px; }
  .hero-card { padding: 28px; }
  .download-form { grid-template-columns: 1fr 140px; }
  .topbar h1 { font-size: 24px; }
  .track { padding: 12px; }
}

/* Màn hình thấp (điện thoại xoay ngang / iPhone SE): thu gọn màn đăng nhập */
@media (max-height: 700px) {
  .auth-view { justify-content: flex-start; gap: 14px; }
  .auth-head .brand-mark { display: none; }
  .auth-head h1 { font-size: clamp(28px, 8vw, 40px); margin-top: 8px; }
  .keypad button { min-height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
