:root {
  --bg: #fafafa; --panel: #fff; --ink: #111; --ink2: #555; --muted: #8a8a8a; --line: #e8e8e8;
  --soft: #f3f3f3; --accent: #111; --on: #fff; --rec: #e5484d; --ok: #16a34a; --warn: #b45309;
  --r: 14px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --ml: 'Noto Sans Malayalam', 'Inter', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d0d0d; --panel: #161616; --ink: #f2f2f2; --ink2: #bdbdbd; --muted: #7c7c7c;
    --line: #262626; --soft: #1f1f1f; --accent: #f2f2f2; --on: #111; --shadow: none; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 Inter, var(--ml); -webkit-font-smoothing: antialiased; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h1 { font-size: 22px; margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 22px; margin: 4px 0 6px; font-weight: 600; letter-spacing: -.01em; }
h3.sub { font-size: 14px; font-weight: 600; color: var(--ink2); margin: 28px 0 10px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 999px; padding: 9px 18px; cursor: pointer; transition: .15s; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); color: var(--on); border-color: var(--accent); }
.btn.primary:hover { opacity: .88; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.link { font: inherit; background: none; border: 0; color: var(--ink2); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--ink); }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.lbl { display: block; font-size: 13px; font-weight: 600; margin: 18px 0 8px; }
.lbl:first-child { margin-top: 0; }
input[type=text], textarea { font: inherit; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--panel); color: var(--ink); }
input[type=text]:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; }

/* gate */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.gate .card { padding: 36px; max-width: 420px; text-align: center; }
.gate .logo { margin: 0 auto 14px; width: 44px; height: 44px; }

/* shell */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100%; }
.side { border-right: 1px solid var(--line); background: var(--panel); padding: 18px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 8px 18px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--on); display: grid; place-items: center; }
.logo svg { width: 18px; height: 18px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--ink2); text-decoration: none; font-weight: 500; }
nav a:hover { background: var(--soft); color: var(--ink); }
nav a.on { background: var(--soft); color: var(--ink); }
.side-foot { margin-top: auto; font-size: 13px; }
.engine { padding: 8px 10px; border-radius: 10px; background: var(--soft); color: var(--ink2); margin-bottom: 10px; display: flex; gap: 8px; align-items: center; }
.engine .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.engine .dot.busy { background: var(--warn); animation: pulse 1.2s infinite; }
.engine .dot.idle { background: var(--ok); }
.who { padding: 0 10px; display: flex; flex-direction: column; gap: 2px; color: var(--muted); word-break: break-all; }
main { padding: 26px 36px 80px; max-width: 1180px; width: 100%; }
.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; }

/* speak */
.speak { display: grid; grid-template-columns: 1fr 300px; gap: 16px; }
.editor { display: flex; flex-direction: column; min-height: 380px; }
.editor textarea { flex: 1; border: 0; resize: none; padding: 20px 22px; font: 17px/1.75 var(--ml); background: transparent; border-radius: var(--r) var(--r) 0 0; }
.editor textarea:focus { outline: none; }
.editor-foot { display: flex; align-items: center; gap: 14px; padding: 12px 14px 12px 22px; border-top: 1px solid var(--line); }
.editor-foot #estimate { flex: 1; text-align: right; font-size: 13px; }
.editor-foot #charCount { font-size: 13px; }
.settings { padding: 18px; align-self: start; position: relative; }
.voice-pick { width: 100%; display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 10px; padding: 8px 10px; font: inherit; cursor: pointer; text-align: left; }
.voice-pick .vp-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 28px; height: 28px; border-radius: 50%; flex: none; background: conic-gradient(from 200deg, #8ec5fc, #e0c3fc, #f9d29d, #8ec5fc); }
.avatar[data-s=narration] { background: conic-gradient(from 40deg, #f6d365, #fda085, #f6d365); }
.avatar[data-s=reading] { background: conic-gradient(from 90deg, #a1c4fd, #c2e9fb, #a1c4fd); }
.avatar[data-s=energetic] { background: conic-gradient(from 10deg, #ff9a9e, #fecfef, #ff9a9e); }
.avatar[data-s=teaching] { background: conic-gradient(from 120deg, #84fab0, #8fd3f4, #84fab0); }
.avatar[data-s=english] { background: conic-gradient(from 300deg, #cfd9df, #e2ebf0, #a6c1ee); }
.menu { position: absolute; left: 18px; right: 18px; top: 76px; z-index: 5; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.12); padding: 6px; max-height: 320px; overflow: auto; }
.menu button { width: 100%; display: flex; align-items: center; gap: 10px; border: 0; background: none; color: var(--ink); padding: 8px; border-radius: 8px; cursor: pointer; font: inherit; text-align: left; }
.menu button:hover, .menu button.on { background: var(--soft); }
.menu .meta { font-size: 12px; color: var(--muted); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--soft); border-radius: 10px; padding: 3px; }
.seg button { font: inherit; font-size: 13px; font-weight: 500; border: 0; background: none; color: var(--ink2); padding: 7px 0; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.range-ends { display: flex; justify-content: space-between; margin-top: -2px; }
.tip { margin: 18px 0 0; padding-top: 14px; border-top: 1px solid var(--line); }

/* jobs */
.jobs { display: flex; flex-direction: column; gap: 10px; }
.job { padding: 14px 16px; display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; }
.job .play { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on); display: grid; place-items: center; cursor: pointer; }
.job .play:disabled { background: var(--soft); color: var(--muted); cursor: default; }
.job .play svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.job .txt { font-family: var(--ml); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.job .meta { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.job .acts { display: flex; gap: 6px; align-items: center; }
.job .acts a, .job .acts button { font-size: 12px; color: var(--ink2); background: none; border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; text-decoration: none; cursor: pointer; font-family: inherit; }
.job .acts a:hover, .job .acts button:hover { background: var(--soft); }
.prog { height: 4px; background: var(--soft); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.prog > div { height: 100%; background: var(--accent); transition: width .6s; }
.pill { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--ink2); }
.pill.run { background: #fff4e5; color: var(--warn); } .pill.err { background: #fde8e8; color: var(--rec); }
@media (prefers-color-scheme: dark) { .pill.run { background: #2a1f0f; } .pill.err { background: #2a1214; } }
.empty { padding: 40px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--r); }
.notice { padding: 10px 12px; border-radius: 10px; background: #fde8e8; color: var(--rec); font-size: 14px; }
@media (prefers-color-scheme: dark) { .notice { background: #2a1214; } }

/* voices */
.voice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.vcard { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.vcard .head { display: flex; gap: 12px; align-items: center; }
.vcard .avatar { width: 42px; height: 42px; }
.vcard .name { font-weight: 600; }
.vcard .script-mini { font-family: var(--ml); font-size: 13px; color: var(--ink2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.vcard .row { display: flex; gap: 8px; }
.vcard .row .btn { padding: 6px 12px; font-size: 13px; }
.vcard.add { border-style: dashed; align-items: center; justify-content: center; cursor: pointer; min-height: 170px; color: var(--ink2); box-shadow: none; background: transparent; font-weight: 500; }
.vcard.add:hover { background: var(--panel); color: var(--ink); }

/* wizard */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 20px; z-index: 50; backdrop-filter: blur(2px); }
.dialog { background: var(--panel); border-radius: 18px; width: min(720px, 100%); max-height: calc(100vh - 40px); overflow: auto; padding: 28px 30px; position: relative; }
.x { position: absolute; right: 14px; top: 10px; border: 0; background: none; font-size: 28px; color: var(--muted); cursor: pointer; line-height: 1; }
.styles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-top: 18px; }
.style { text-align: left; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 12px; padding: 14px; cursor: pointer; font: inherit; display: flex; flex-direction: column; gap: 4px; }
.style:hover { border-color: var(--ink); }
.style .ml { font-family: var(--ml); font-size: 18px; font-weight: 600; }
.style .en { font-weight: 600; font-size: 14px; }
.style .d { font-size: 12px; color: var(--muted); }
.style .have { font-size: 11px; color: var(--ok); font-weight: 600; }
.script { font-family: var(--ml); font-size: 22px; line-height: 1.8; margin: 16px 0 8px; padding: 18px 22px; background: var(--soft); border-radius: 12px; border: 0; }
.script.en { font-family: Inter, sans-serif; font-size: 20px; }
.script-actions { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; flex-wrap: wrap; }
.recorder { display: flex; align-items: center; gap: 20px; margin: 22px 0 10px; }
.rec { width: 72px; height: 72px; border-radius: 50%; border: 3px solid var(--line); background: var(--panel); display: grid; place-items: center; cursor: pointer; flex: none; }
.rec span { width: 30px; height: 30px; background: var(--rec); border-radius: 50%; transition: .2s; }
.rec.on span { border-radius: 6px; width: 24px; height: 24px; }
.rec.on { border-color: var(--rec); animation: ring 1.4s infinite; }
.rec-info { flex: 1; }
.timer { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.meter { height: 6px; background: var(--soft); border-radius: 6px; overflow: hidden; margin: 8px 0; }
.meter div { height: 100%; width: 0; background: var(--ok); transition: width .06s; }
.tbar { position: relative; height: 6px; background: var(--soft); border-radius: 6px; }
.tbar div { height: 100%; width: 0; background: var(--ink2); border-radius: 6px; }
.tbar i { position: absolute; top: -3px; width: 2px; height: 12px; background: var(--ok); }
.tips { padding-left: 18px; margin: 14px 0 0; }
.upload { margin-top: 16px; padding-top: 6px; border-top: 1px solid var(--line); }
.dialog audio { width: 100%; margin: 14px 0 4px; }
.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
@keyframes ring { 0%,100% { box-shadow: 0 0 0 0 rgba(229,72,77,.35); } 50% { box-shadow: 0 0 0 10px rgba(229,72,77,0); } }
@keyframes pulse { 50% { opacity: .35; } }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 12px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
  .brand { padding: 0 8px 0 0; }
  nav { display: flex; gap: 2px; }
  nav a { padding: 7px 9px; font-size: 13px; } nav a svg { display: none; }
  .side-foot { display: none; }
  main { padding: 18px 16px 60px; }
  .speak { grid-template-columns: 1fr; }
  .editor { min-height: 260px; }
  .dialog { padding: 22px 18px; }
  .brand { font-size: 0; gap: 0; }
  .side { flex-wrap: nowrap; overflow-x: auto; }
  .editor-foot { flex-wrap: wrap; padding: 12px 14px; }
  .editor-foot #estimate { order: 3; flex-basis: 100%; text-align: left; }
  .editor-foot .btn { margin-left: auto; }
  .job { grid-template-columns: auto 1fr; padding: 12px; }
  .job .acts { grid-column: 1 / -1; justify-content: flex-end; }
  .recorder { gap: 14px; }
  html, body { overflow-x: clip; }
  .script { font-size: 19px; }
}

/* wizard v2: tabs, upload, clip picker */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 10px 0 18px; }
.tabs button { font: inherit; font-weight: 500; background: none; border: 0; padding: 10px 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--ink); }
.len.seg { grid-template-columns: 1fr 1fr; max-width: 320px; }
#lenHint { margin: 8px 0 0; }
.drop { margin-top: 16px; border: 1.5px dashed var(--line); border-radius: 14px; padding: 34px 20px; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; text-align: center; transition: .15s; }
.drop:hover, .drop.over { border-color: var(--ink); background: var(--soft); }
.drop svg { width: 26px; height: 26px; color: var(--ink2); }
.busy { display: flex; align-items: center; gap: 12px; padding: 30px 4px; color: var(--ink2); }
.spin { width: 20px; height: 20px; border: 2.5px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
#srcErr { margin-top: 14px; }
.clips { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.clip { display: grid; grid-template-columns: auto auto 1fr; gap: 12px; align-items: start; border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; }
.clip.on { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.clip input[type=radio] { margin-top: 12px; accent-color: var(--ink); }
.mini-play { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on); display: grid; place-items: center; cursor: pointer; }
.mini-play svg { width: 14px; height: 14px; fill: currentColor; stroke: none; }
.clip-meta { display: flex; gap: 6px; font-size: 12px; color: var(--muted); align-items: center; margin-bottom: 6px; }
.clip textarea { font-family: var(--ml); font-size: 14px; line-height: 1.6; resize: vertical; field-sizing: content; min-height: 3.4em; }
.pill.ok { background: #e7f6ec; color: var(--ok); }
@media (prefers-color-scheme: dark) { .pill.ok { background: #10251a; } }
