:root {
  --bg: #0b0b0f;
  --bg-2: #111116;
  --surface: #16171c;
  --surface-2: #1d1f25;
  --surface-3: #262931;
  --text: #f4f4f5;
  --text-muted: #9aa0a6;
  --text-dim: #6a6f78;
  --accent: #5b8dff;
  --accent-2: #8db4ff;
  --accent-soft: rgba(91, 141, 255, 0.14);
  --accent-glow: rgba(91, 141, 255, 0.35);
  --danger: #ff6b85;
  --danger-soft: rgba(255, 107, 133, 0.14);
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  --shadow-soft: 0 4px 18px rgba(0, 0, 0, 0.3);
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }
*::-webkit-tap-highlight-color { transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: contain;
}

body {
  background:
    radial-gradient(1000px 600px at 80% -10%, rgba(91, 141, 255, 0.08), transparent 60%),
    radial-gradient(800px 500px at -10% 30%, rgba(141, 91, 255, 0.05), transparent 60%),
    var(--bg);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }

/* ========= TOPBAR ========= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 12px 16px;
  background: rgba(11, 11, 15, 0.7);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.01em;
}

/* строго круглая кнопка-иконка в шапке */
.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.07s;
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn .ico { width: 22px; height: 22px; display: block; }

main {
  padding: 20px 16px calc(40px + var(--safe-bottom));
  max-width: 760px;
  margin: 0 auto;
}

.view { animation: fadein 0.18s ease-out; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ========= EMPTY ========= */
.empty {
  text-align: center;
  padding: 64px 24px 24px;
}
.empty .big { font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.muted { color: var(--text-muted); }
.small { font-size: 14px; }

/* ========= FORM ========= */
.form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-soft);
}
.lbl { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
input[type="url"], input[type="text"], textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  resize: vertical;
  transition: border-color 0.15s, background 0.15s;
}
input[type="url"]:focus, input[type="text"]:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-3);
}
.or { text-align: center; color: var(--text-muted); padding: 4px 0; font-size: 14px; }
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; min-width: 0; }
.input-row button { flex: 0 0 auto; }

.chapters-preview {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
}
.chapters-preview .ch-line { display: flex; gap: 8px; padding: 2px 0; }
.chapters-preview .ch-line::before { content: "•"; color: var(--accent-2); flex: 0 0 auto; }
.chapters-preview .ch-summary { font-weight: 500; margin-bottom: 6px; color: var(--text); }
.chapters-preview code, code {
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: ui-monospace, SFMono-Regular, monospace;
}

button, .ghost {
  font: inherit;
  cursor: pointer;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 11px 18px;
  background: var(--surface-2);
  color: var(--text);
  transition: transform 0.07s ease, background 0.15s;
}
button:active { transform: scale(0.97); }
button.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 12px var(--accent-glow);
}
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { background: #333a4a; color: #888; cursor: not-allowed; box-shadow: none; }
button.ghost, .ghost { background: transparent; border-color: var(--border-strong); color: var(--text); }
button.ghost:hover, .ghost:hover { background: var(--surface-2); }
button.ghost.danger { color: var(--danger); border-color: rgba(255, 107, 133, 0.3); }
.big-btn { padding: 14px 26px; font-size: 17px; font-weight: 600; margin-top: 16px; }

.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ========= JOBS LIST ========= */
#jobs { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.job {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.07s;
  position: relative;
  overflow: hidden;
}
.job:hover { background: var(--surface-2); }
.job:active { transform: scale(0.995); }
.job.processing { border-color: rgba(91, 141, 255, 0.3); }
.job.failed { border-color: rgba(255, 107, 133, 0.3); }

.job .meta { flex: 1; min-width: 0; }
.job .name {
  font-weight: 500;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.005em;
}
.job .sub { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.job .badge {
  flex-shrink: 0;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge.processing { color: var(--accent-2); background: var(--accent-soft); }
.badge.done { color: #5cd896; background: rgba(92, 216, 150, 0.12); }
.badge.failed { color: var(--danger); background: var(--danger-soft); }

.job .row-progress {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.job .progress {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
}
.job .progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 2px;
  transition: width 0.4s ease;
}
.job .stage-text {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.job-trash {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.job-trash:hover { color: var(--danger); background: var(--danger-soft); }
.job-trash .ico-sm { width: 18px; height: 18px; }

/* ========= PROCESSING CARD ========= */
.processing {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-soft);
  text-align: center;
}
.processing h2 { margin: 0 0 14px; font-size: 18px; font-weight: 600; }
.processing .progress {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
  margin: 0 0 10px;
  position: relative;
}
.processing .progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 4px;
  transition: width 0.5s ease;
  box-shadow: 0 0 12px var(--accent-glow);
}
.processing .stage { margin-top: 6px; }

/* ========= PLAYER ========= */
.player {
  background:
    linear-gradient(180deg, rgba(91, 141, 255, 0.06), transparent 50%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 20px 18px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  position: sticky;
  top: calc(var(--safe-top) + 60px);
  z-index: 5;
}
.player h2 {
  margin: 0 0 4px 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.005em;
}

.time {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 10px;
  margin: 16px 0 8px;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-muted);
}
.seek-wrap { position: relative; width: 100%; height: 22px; }
.chapter-ticks { position: absolute; inset: 9px 0; height: 4px; pointer-events: none; }
.chapter-ticks .tick {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 10px;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 1px;
}
.time #seek {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  inset: 0;
  width: 100%;
  background: transparent;
  height: 22px;
  margin: 0;
  cursor: pointer;
}
.time #seek::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--progress, 0%), var(--surface-2) var(--progress, 0%));
}
.time #seek::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--progress, 0%), var(--surface-2) var(--progress, 0%));
  border: none;
}
.time #seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  margin-top: -7px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  border: none;
}
.time #seek::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.chapter-now {
  text-align: center;
  margin: 6px 0 8px;
  font-weight: 500;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 1em;
}

/* ========= CONTROLS ========= */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 8px 0 14px;
}

/* строго круглые кнопки плеера */
.circle {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.07s, border-color 0.15s;
}
.circle:hover { background: var(--surface-3); }
.circle .ico { width: 22px; height: 22px; display: block; }

.circle.big {
  width: 68px;
  height: 68px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border: none;
  box-shadow: 0 6px 22px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  color: #fff;
}
.circle.big:hover { filter: brightness(1.05); }
.circle.big .ico { width: 28px; height: 28px; }

@media (min-width: 480px) {
  .controls { gap: 18px; }
}

/* ========= SPEED ========= */
.speed-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}
.speed-row > span { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: 0 0 auto;
  padding: 6px 12px;
  font-size: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
}
.chips button.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}

.player-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}
.player-actions .ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 10px;
}
.ico-sm { width: 16px; height: 16px; display: block; }

/* ========= CHAPTERS ========= */
.chapters-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 14px 8px;
  margin-bottom: 16px;
}
.chapters-title {
  margin: 0 0 8px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.chapters {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: ch;
}
.chapters li {
  counter-increment: ch;
  display: flex;
  gap: 12px;
  align-items: baseline;
  padding: 11px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.12s;
}
.chapters li:hover { background: var(--surface-2); }
.chapters li::before {
  content: counter(ch);
  flex: 0 0 auto;
  min-width: 22px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--text-dim);
}
.chapters li .ch-name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chapters li .ch-time {
  flex: 0 0 auto;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}
.chapters li.active { background: var(--accent-soft); }
.chapters li.active .ch-name { color: var(--accent-2); font-weight: 500; }
.chapters li.played .ch-name { color: var(--text-dim); }

/* ========= ARTICLE ========= */
#article-text {
  font-size: 17px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 20px;
  letter-spacing: 0.01em;
}
#article-text p { margin: 0 0 14px; }
#article-text h2 {
  font-size: 19px;
  font-weight: 600;
  margin: 18px 0 10px;
  color: var(--accent-2);
}
#article-text h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 14px 0 8px;
  color: var(--text);
}

@media (min-width: 800px) {
  body { font-size: 18px; }
  .player h2 { font-size: 20px; }
  #article-text { font-size: 18px; }
}

/* Telegram Mini App: нативная back-кнопка в шапке Telegram, нашу скрываем */
body.in-telegram #back-btn { display: none; }
body.in-telegram .topbar { padding-top: calc(8px + var(--safe-top)); }
body.in-telegram .player { top: calc(var(--safe-top) + 50px); }
