/* Sách Nói — giao diện kiểu Fonos, mobile-first, nền tối mặc định */
:root {
  --bg: #111114;
  --surface: #1b1b20;
  --surface-2: #25252c;
  --surface-3: #30303a;
  --text: #f4f3f1;
  --muted: #a3a2ab;
  --line: #2e2e36;
  --accent: #ff6b3d;
  --accent-2: #e8453c;
  --accent-soft: rgba(255, 107, 61, .16);
  --ok: #3ecf8e;
  --warn: #f5b945;
  --danger: #ff5a5f;
  --shadow: 0 10px 28px rgba(0, 0, 0, .45);
  --cover-shadow: 0 8px 22px rgba(0, 0, 0, .5);
  --radius: 18px;
  --radius-sm: 12px;
  --mini-h: 68px;
  --top-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f7f4f1;
  --surface: #ffffff;
  --surface-2: #f0ebe6;
  --surface-3: #e4ddd6;
  --text: #1d1b1a;
  --muted: #6c6763;
  --line: #e6dfd8;
  --accent-soft: rgba(255, 107, 61, .13);
  --shadow: 0 10px 28px rgba(60, 40, 20, .15);
  --cover-shadow: 0 8px 20px rgba(60, 40, 20, .25);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px; line-height: 1.45; min-height: 100vh;
  padding-bottom: calc(var(--mini-h) + var(--safe-b) + 16px);
  overflow-x: hidden;
}
body.no-scroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 0;
  background: var(--surface-2); color: var(--text); font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { min-height: 52px; font-size: 17px; padding: 0 28px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text);
  flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg, .btn svg { width: 24px; height: 24px; fill: currentColor; }

/* ---------- thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--top-h);
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  padding-top: env(safe-area-inset-top, 0px); height: calc(var(--top-h) + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; letter-spacing: -.3px; margin-right: auto; }
.brand-logo {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
}
.brand-logo svg { width: 20px; height: 20px; fill: #fff; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; color: #fff; font-size: 15px; flex: none; border: 0;
}

main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.section-title { font-size: 20px; font-weight: 800; margin: 18px 0 12px; letter-spacing: -.2px; }

/* ---------- thư viện ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search {
  flex: 1 1 220px; min-height: 44px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); padding: 0 16px 0 42px; outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23a3a2ab'%3E%3Cpath d='M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 14px center; background-size: 20px;
}
.search:focus, .input:focus, .select:focus { border-color: var(--accent); }
.select, .input {
  min-height: 44px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); padding: 0 12px; outline: none;
}
.input { width: 100%; }

.shelf { display: flex; gap: 14px; overflow-x: auto; padding: 4px 2px 12px; scroll-snap-type: x mandatory; }
.shelf::-webkit-scrollbar { height: 6px; }
.shelf::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
.shelf .card { width: 128px; flex: none; scroll-snap-align: start; }

.grid { display: grid; gap: 18px 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1080px) { .grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

.card { display: block; background: none; border: 0; padding: 0; text-align: left; min-width: 0; }
.card-title { font-weight: 700; font-size: 15px; margin-top: 10px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cover {
  position: relative; aspect-ratio: 2 / 3; border-radius: 12px; overflow: hidden;
  box-shadow: var(--cover-shadow); background: var(--surface-2);
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-ph {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
  padding: 12px; color: #fff; font-weight: 800; line-height: 1.2; word-break: break-word;
}
.cover-ph .t { font-size: clamp(13px, 3.6vw, 18px); text-shadow: 0 1px 3px rgba(0,0,0,.3); }
.cover-ph .a { font-size: 11px; font-weight: 600; opacity: .85; }
.cover .listen-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: rgba(0,0,0,.45); }
.cover .listen-bar i { display: block; height: 100%; background: var(--accent); }
.cover .overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0, 0, 0, .5); color: #fff; font-weight: 700; font-size: 13px; text-align: center;
}
.ring { width: 58%; max-width: 72px; aspect-ratio: 1; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 4; }
.ring .bg { stroke: rgba(255,255,255,.25); }
.ring .fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .4s; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 14px; }
.badge {
  position: absolute; top: 8px; left: 8px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: rgba(0,0,0,.6); color: #fff;
}
.badge.err { background: var(--danger); }

.empty { text-align: center; padding: 56px 16px; color: var(--muted); }
.empty .btn { margin-top: 16px; }

/* ---------- chi tiết sách ---------- */
.detail-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; padding-top: 6px; }
.detail-head .cover { width: min(220px, 58vw); }
.detail-title { font-size: 24px; font-weight: 800; margin: 6px 0 0; line-height: 1.25; letter-spacing: -.3px; }
.detail-meta { color: var(--muted); font-size: 14px; }
.detail-actions { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.gen-box { width: 100%; max-width: 520px; background: var(--surface); border-radius: var(--radius-sm); padding: 12px 14px; text-align: left; font-size: 14px; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
@media (min-width: 820px) {
  .detail-head { flex-direction: row; align-items: flex-end; text-align: left; gap: 28px; }
  .detail-head .cover { width: 220px; flex: none; }
  .detail-actions { justify-content: flex-start; }
}
.back { margin-left: -8px; }

.chapters { list-style: none; margin: 8px 0 0; padding: 0; border-top: 1px solid var(--line); }
.chapter {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px; min-height: 60px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.chapter:hover { background: var(--surface); }
.chapter.playing .ch-title { color: var(--accent); }
.ch-num { width: 32px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.ch-main { flex: 1; min-width: 0; }
.ch-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-sub { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.ch-sub .ok { color: var(--ok); }
.ch-sub .gen { color: var(--warn); }
.ch-sub .err { color: var(--danger); }
.ch-actions { display: flex; align-items: center; }

/* ---------- mini player ---------- */
.mini {
  position: fixed; left: 8px; right: 8px; bottom: calc(8px + var(--safe-b)); z-index: 30;
  height: var(--mini-h); border-radius: 16px; background: var(--surface-2);
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 8px;
  overflow: hidden; cursor: pointer;
}
.mini .cover { width: 34px; border-radius: 6px; box-shadow: none; flex: none; }
.mini .cover-ph .t, .mini .cover-ph .a { display: none; }
.mini-text { flex: 1; min-width: 0; }
.mini-title { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--surface-3); }
.mini-progress i { display: block; height: 100%; width: 0; background: var(--accent); }
.mini .play-btn { width: 48px; height: 48px; }
@media (min-width: 820px) {
  .mini { left: 0; right: 0; bottom: 0; border-radius: 0; height: 76px; padding: 8px 24px; }
  body { padding-bottom: 96px; }
  .mini .cover { width: 40px; }
}

/* ---------- trình phát toàn màn hình ---------- */
.player {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; flex-direction: column; overflow: hidden;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: var(--safe-b);
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.player-bg { position: absolute; inset: -40px; background-size: cover; background-position: center; filter: blur(50px) saturate(1.3); opacity: .28; z-index: -1; }
.player-top { display: flex; align-items: center; gap: 4px; padding: 6px 8px; }
.player-top .ttl { flex: 1; text-align: center; font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 6px; justify-content: center; padding: 0 16px 8px; }
.tab { border: 0; background: transparent; color: var(--muted); font-weight: 700; padding: 8px 14px; border-radius: 999px; min-height: 40px; }
.tab.active { background: var(--surface-2); color: var(--text); }
.player-body { flex: 1; overflow-y: auto; padding: 0 20px; display: flex; flex-direction: column; min-height: 0; }
.player-main { width: 100%; max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 8px 0 16px; flex: 1; justify-content: center; }
.player-main .cover { width: min(300px, 68vw, 38vh); }
.p-title { font-size: 20px; font-weight: 800; text-align: center; line-height: 1.3; }
.p-sub { color: var(--muted); text-align: center; font-size: 14px; margin-top: 2px; }
.p-wait { background: var(--surface); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 14px; width: 100%; text-align: center; }
.seek { width: 100%; }
.seek input[type=range] { width: 100%; }
.times { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
.controls { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; }
.controls .icon-btn { width: 52px; height: 52px; }
.controls .icon-btn svg { width: 30px; height: 30px; }
.controls .main-play {
  width: 72px; height: 72px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 8px 22px rgba(232, 69, 60, .4);
}
.controls .main-play svg { width: 38px; height: 38px; }
.controls .main-play:hover { background: linear-gradient(135deg, var(--accent), var(--accent-2)); filter: brightness(1.08); }
.skip { position: relative; }
.skip b { position: absolute; font-size: 10px; font-weight: 800; top: 50%; left: 50%; transform: translate(-50%, -38%); }
.extras { display: flex; justify-content: space-around; width: 100%; gap: 6px; }
.chip {
  border: 0; background: var(--surface-2); border-radius: 999px; min-height: 40px; padding: 0 14px;
  display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 700;
}
.chip svg { width: 20px; height: 20px; fill: currentColor; }
.chip.on { background: var(--accent-soft); color: var(--accent); }

input[type=range] {
  -webkit-appearance: none; appearance: none; height: 28px; background: transparent; margin: 0;
  --pct: 0%;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--pct), var(--surface-3) var(--pct));
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--text); margin-top: -5.5px; border: 0;
}
input[type=range]::-moz-range-track { height: 5px; border-radius: 3px; background: var(--surface-3); }
input[type=range]::-moz-range-progress { height: 5px; border-radius: 3px; background: var(--accent); }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--text); border: 0; }

/* văn bản chương trong trình phát */
.reader { max-width: 680px; margin: 0 auto; padding: 8px 0 40px; font-size: 18px; line-height: 1.7; }
.reader p { margin: 0 0 14px; padding: 6px 10px; border-radius: 10px; cursor: pointer; transition: background .2s; }
.reader p:hover { background: var(--surface); }
.reader p.cur { background: var(--accent-soft); }
.reader p.title { font-weight: 800; font-size: 20px; }

/* ---------- sheet / modal ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 95; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; background: var(--surface);
  border-radius: 22px 22px 0 0; padding: 10px 18px calc(18px + var(--safe-b)); box-shadow: var(--shadow);
  animation: slideUp .22s ease;
}
@media (min-width: 820px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 22px; padding-bottom: 20px; }
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--surface-3); margin: 0 auto 10px; }
.sheet h3 { margin: 4px 0 14px; font-size: 19px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.menu-list { list-style: none; padding: 0; margin: 0; }
.menu-list button {
  width: 100%; min-height: 52px; border: 0; background: transparent; text-align: left; padding: 0 8px;
  display: flex; align-items: center; gap: 14px; border-radius: 12px; font-size: 16px;
}
.menu-list button:hover { background: var(--surface-2); }
.menu-list button.sel { color: var(--accent); font-weight: 700; }
.menu-list svg { width: 22px; height: 22px; fill: currentColor; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }

.dropzone {
  border: 2px dashed var(--surface-3); border-radius: var(--radius); padding: 26px 14px; text-align: center;
  color: var(--muted); cursor: pointer; transition: border-color .2s, background .2s;
}
.dropzone.drag, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { color: var(--text); display: block; margin-bottom: 4px; word-break: break-all; }
.voice-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.voice-item { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.voice-item:last-child { border-bottom: 0; }
.voice-item input { accent-color: var(--accent); width: 18px; height: 18px; }
.voice-item .vi-main { flex: 1; min-width: 0; }
.voice-item .vi-name { font-weight: 600; }
.voice-item .vi-desc { font-size: 12px; color: var(--muted); }
.upload-progress { margin-top: 12px; font-size: 14px; }

/* ---------- chọn người nghe ---------- */
.profiles-screen {
  position: fixed; inset: 0; z-index: 90; background: var(--bg); display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px; text-align: center;
}
.profiles-screen h1 { font-size: 26px; margin: 0 0 6px; }
.profiles { display: flex; flex-wrap: wrap; gap: 22px; justify-content: center; margin: 28px 0; max-width: 560px; }
.profile-btn { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; width: 96px; }
.profile-btn .avatar { width: 84px; height: 84px; font-size: 32px; box-shadow: var(--shadow); transition: transform .15s; }
.profile-btn:hover .avatar { transform: scale(1.06); }
.profile-btn.add .avatar { background: var(--surface-2); color: var(--muted); }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.color-dot { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; }
.color-dot.sel { border-color: var(--text); }

/* ---------- cài đặt ---------- */
.settings-card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.settings-card h2 { font-size: 17px; margin: 0 0 12px; }
.row { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.row + .row { border-top: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); display: inline-block; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- thông báo ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--mini-h) + 24px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; z-index: 100;
  font-size: 14px; font-weight: 600; max-width: calc(100vw - 32px); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; box-shadow: var(--shadow); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--surface-3); border-top-color: var(--accent);
  animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- sách dịch từ tiếng Anh ---------- */
.lang-note { font-size: 13px; color: var(--accent); margin-top: 4px; }
.badge.tr { left: auto; right: 8px; background: rgba(9, 132, 227, .85); }
.reader-tools { max-width: 680px; margin: 0 auto; display: flex; justify-content: flex-end; padding-top: 4px; }
.reader .orig { display: none; }
.reader.bilingual .orig { display: block; margin-top: 6px; font-size: 15px; line-height: 1.55; color: var(--muted); font-style: italic; }
.reader.bilingual p { border-left: 3px solid transparent; }
.reader.bilingual p.cur { border-left-color: var(--accent); }
