:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --ink: #17202b;
  --muted: #66727f;
  --accent: #4f46e5;
  --accent-2: #2563eb;
  --accent-dark: #4338ca;
  --accent-soft: #eef0fe;
  --ok: #15803d;
  --ok-soft: #e9f7ee;
  --err: #b3261e;
  --warn: #9a6a00;
  --line: #e3e8ef;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 10px 28px -16px rgba(16, 24, 40, 0.18);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1100px 380px at 15% -8%, #e3e6ff 0%, transparent 60%),
    radial-gradient(900px 320px at 95% -12%, #dcebff 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

/* ---------- top bar ---------- */
.topbar {
  max-width: 1560px; margin: 0 auto; padding: 26px 24px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 52px; height: 52px; border-radius: 16px; font-size: 26px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px -8px rgba(79, 70, 229, 0.55);
}
.brand h1 { margin: 0; font-size: 1.45rem; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 13px; font-size: 0.8rem; color: var(--muted); box-shadow: var(--shadow);
}

/* ---------- layout ---------- */
.grid {
  max-width: 1560px; margin: 0 auto; padding: 6px 24px 40px;
  display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 18px; align-items: start;
}
.col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
@media (max-width: 1180px) { .grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 820px)  { .grid { grid-template-columns: 1fr; } }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 14px; font-size: 1rem; display: flex; align-items: center; gap: 9px;
  letter-spacing: -0.01em;
}
.step {
  width: 24px; height: 24px; border-radius: 8px; flex: none;
  display: grid; place-items: center; font-size: 0.8rem; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.optional { font-size: 0.75rem; color: var(--muted); font-weight: normal; }
.dim { color: var(--muted); font-weight: normal; font-size: 0.8rem; }

/* ---------- inputs ---------- */
textarea {
  width: 100%; min-height: 300px; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; font: inherit; font-size: 0.92rem; resize: vertical; background: #fbfcfe;
}
textarea:focus, select:focus, .txt:focus, #voiceSearch:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
.txt {
  width: 100%; padding: 10px 13px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; background: #fbfcfe;
}
select {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit;
  background: #fbfcfe; max-width: 100%; min-width: 0; flex: 1;
}
.row { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.row > label:first-child { color: var(--muted); font-size: 0.88rem; min-width: 68px; }
.radio { font-size: 0.92rem; }
input[type="range"] { flex: 1; min-width: 120px; accent-color: var(--accent); }
input[type="radio"] { accent-color: var(--accent); }

.pill {
  background: var(--accent-soft); color: var(--accent-dark); border-radius: 999px;
  padding: 3px 11px; font-variant-numeric: tabular-nums; font-size: 0.85rem; font-weight: 600;
}
.filebtn {
  display: inline-block; cursor: pointer; background: #f4f6fa;
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 15px; font-size: 0.9rem;
  transition: background 0.15s;
}
.filebtn:hover { background: #eaeef5; }
.filebtn input { display: none; }
.filename { color: var(--muted); font-size: 0.85rem; word-break: break-all; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 10px 0 0; line-height: 1.45; }
.hint code { background: #f0f3f8; border-radius: 5px; padding: 1px 6px; }
.chapterinfo { color: var(--accent-dark); font-size: 0.85rem; margin: 12px 0 0; line-height: 1.5; }

/* segmented voice-source control */
.seg { gap: 8px; }
.segopt { flex: 1; min-width: 130px; }
.segopt input { display: none; }
.segopt span {
  display: flex; flex-direction: column; gap: 1px; padding: 9px 14px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; font-size: 0.9rem; font-weight: 600;
  background: #fbfcfe; transition: all 0.15s;
}
.segopt small { color: var(--muted); font-weight: 400; font-size: 0.74rem; }
.segopt input:checked + span {
  border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.segopt input:disabled + span { opacity: 0.45; cursor: not-allowed; }

/* ---------- buttons ---------- */
button { font: inherit; cursor: pointer; border: 0; border-radius: 10px; padding: 10px 18px; }
#recordBtn {
  width: 100%; padding: 15px 26px; font-size: 1.08rem; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 22px -10px rgba(79, 70, 229, 0.65);
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
}
#recordBtn:hover { filter: brightness(1.06); transform: translateY(-1px); }
#recordBtn:disabled { filter: saturate(0.35) brightness(1.05); cursor: wait; transform: none; }
.ghost {
  background: transparent; color: var(--accent-dark); border: 1px solid #c7cdf5;
  padding: 8px 15px; font-size: 0.9rem; font-weight: 600; transition: background 0.15s;
}
.ghost:hover { background: var(--accent-soft); }
.ghost.danger { color: var(--err); border-color: #ecc4c1; }
.ghost.danger:hover { background: #fdf0ef; }
#modalSave {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-weight: 600;
}

/* ---------- progress + results ---------- */
.action { text-align: center; }
.center { justify-content: center; }
.bar { height: 10px; background: #e8ecf3; border-radius: 999px; overflow: hidden; margin: 16px 0 8px; }
#barFill {
  height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.5s ease;
}
#statusMsg { color: var(--muted); font-size: 0.88rem; margin: 4px 0 0; }
.ok { color: var(--ok); font-weight: 600; font-size: 0.92rem; background: var(--ok-soft);
      border-radius: 10px; padding: 10px 14px; }
.err { color: var(--err); font-weight: 600; }
.warn { color: var(--warn); font-size: 0.85rem; text-align: left; }
audio { width: 100%; margin-top: 10px; height: 40px; }

.results h2 { margin-bottom: 6px; }
#chapterList { max-height: 52vh; overflow-y: auto; padding-right: 2px; }
.chapter {
  text-align: left; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-top: 10px; background: #fbfcfe;
  animation: pop 0.35s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }
.chapter-head { display: flex; align-items: center; gap: 10px; }
.chapter-title { font-weight: 600; flex: 1; font-size: 0.92rem; }
.chapter-mins { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.small { padding: 5px 11px; font-size: 0.8rem; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.download {
  display: block; text-align: center; text-decoration: none; color: #fff; font-weight: 700;
  background: linear-gradient(135deg, #16a34a, #15803d); border-radius: 10px; padding: 12px 20px;
  box-shadow: 0 8px 18px -10px rgba(21, 128, 61, 0.6); transition: filter 0.15s;
}
.download:hover { filter: brightness(1.07); }
.download.alt { background: linear-gradient(135deg, var(--accent), var(--accent-2));
                box-shadow: 0 8px 18px -10px rgba(79, 70, 229, 0.6); }
.hidden { display: none !important; }
.logout { display: flex; align-items: center; gap: 8px; margin: 0; }

/* ---------- library ---------- */
#libraryList { max-height: 46vh; overflow-y: auto; }
.book { border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; margin-top: 10px; background: #fbfcfe; }
.book-head { display: flex; align-items: center; gap: 10px; }
.book-title { flex: 1; font-weight: 600; font-size: 0.92rem; word-break: break-word; }
.book-meta { margin: 3px 0 0; color: var(--muted); font-size: 0.8rem; }
.book-links { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.book-links a, .book details a {
  color: var(--accent-dark); font-size: 0.82rem; font-weight: 600; text-decoration: none;
  border: 1px solid #c7cdf5; border-radius: 8px; padding: 4px 10px;
}
.book-links a:hover, .book details a:hover { background: var(--accent-soft); }
.book details { margin-top: 8px; font-size: 0.82rem; color: var(--muted); }
.book details summary { cursor: pointer; }
.book details a { display: inline-block; margin: 6px 6px 0 0; font-weight: 500; }

/* ---------- sign-in page ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 6px; padding: 26px 26px 28px; }
.login-card .brand { margin-bottom: 18px; }
.login-card .brand h1 { font-size: 1.15rem; }
.login-card label { color: var(--muted); font-size: 0.85rem; margin-top: 8px; }
.login-err { margin: 8px 0 0; font-size: 0.88rem; }
#loginBtn {
  margin-top: 16px; padding: 12px 20px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 10px 20px 34px; }

/* ---------- voice picker modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(23, 32, 43, 0.45); backdrop-filter: blur(3px); padding: 20px;
}
.modal-box {
  background: #fff; border-radius: 16px; width: min(760px, 100%); max-height: 88vh;
  display: flex; flex-direction: column; box-shadow: 0 24px 60px -20px rgba(16, 24, 40, 0.45);
  animation: pop 0.25s ease;
}
.modal-head {
  display: flex; align-items: center; gap: 12px; padding: 16px 18px 4px;
}
.modal-head h3 { margin: 0; font-size: 1.05rem; white-space: nowrap; }
#voiceSearch {
  flex: 1; padding: 9px 13px; border: 1px solid var(--line); border-radius: 10px; font: inherit;
}
#modalClose { padding: 7px 12px; }
.modal-hint { padding: 0 18px; margin: 8px 0 10px; }
.modal-list { overflow-y: auto; padding: 0 18px 10px; flex: 1; }
.vgroup-title {
  position: sticky; top: 0; background: #fff; padding: 9px 2px 6px; margin: 0;
  font-size: 0.8rem; font-weight: 700; color: var(--accent-dark);
  border-bottom: 1px solid var(--line); z-index: 1;
}
.vrow {
  display: flex; align-items: center; gap: 10px; padding: 7px 2px;
  border-bottom: 1px solid #f0f3f8; font-size: 0.9rem;
}
.vrow label { flex: 1; display: flex; align-items: center; gap: 9px; cursor: pointer; }
.vrow input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.vrow .gender { color: var(--muted); font-size: 0.8rem; }
.vplay { padding: 4px 10px; font-size: 0.78rem; }
.modal-foot {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px;
  border-top: 1px solid var(--line);
}
.modal-foot .filename { flex: 1; }
