:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #16181d);
  --hint: var(--tg-theme-hint-color, #7a828e);
  --card: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --accent: var(--tg-theme-button-color, #2f80ed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 28%, transparent);
  --danger: #e5484d;
  --ok: #2fa84f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #15171a);
    --text: var(--tg-theme-text-color, #eef0f3);
    --card: var(--tg-theme-secondary-bg-color, #202328);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 0 16px calc(76px + env(safe-area-inset-bottom));
}
main { max-width: 560px; margin: 0 auto; }
h1 { font-size: 24px; margin: 20px 0 14px; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
p { margin: 10px 0; }
.hint { color: var(--hint); font-size: 13px; }
.center { text-align: center; }

.card { background: var(--card); border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; margin-top: 8px; }

.input {
  flex: 1; min-width: 0; height: 44px; padding: 0 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; outline: none;
}
.input:focus { border-color: var(--accent); }

.btn {
  height: 44px; padding: 0 18px; border: 0; border-radius: 12px; font: inherit; font-weight: 600;
  color: var(--accent-text); background: var(--accent); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
}
.btn:active { opacity: .8; }
.btn:disabled { opacity: .5; }
.btn.secondary { color: var(--text); background: var(--bg); border: 1px solid var(--line); }
.btn.danger { color: var(--danger); background: transparent; border: 1px solid var(--line); }
.btn.small { height: 36px; padding: 0 14px; font-size: 14px; }
.btn.block { display: flex; width: 100%; margin-top: 10px; }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 22px 12px;
  border: 1.5px dashed var(--line); border-radius: 14px; cursor: pointer; text-align: center;
}
.drop-title { font-weight: 600; color: var(--accent); }

.upload { margin-top: 4px; }
.upload-name { font-size: 14px; margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .4s ease; }

.note {
  display: block; width: 100%; padding: 12px; border: 0; background: none; color: var(--hint);
  font: inherit; font-size: 13px; text-align: center;
}

/* jobs */
.job { background: var(--card); border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.job-head { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.job-title { font-weight: 600; word-break: break-word; }
.badge {
  flex: none; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 20px;
  background: var(--line); color: var(--hint);
}
.badge.running { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.badge.done { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.error { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.job-sub { margin: 6px 0 0; font-size: 13px; color: var(--hint); word-break: break-word; }
.job-sub.error { color: var(--danger); }
.job .bar { margin-top: 10px; }

.parts { margin-top: 10px; }
.part { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); align-items: center; }
.part-thumb {
  position: relative; flex: none; width: 72px; aspect-ratio: 9 / 16; border-radius: 10px; overflow: hidden;
  background: #000 center / cover no-repeat; border: 0; padding: 0; cursor: pointer;
}
.part-thumb::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0,0,0,.55) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M9 7v10l8-5z'/%3E%3C/svg%3E") center / 20px no-repeat;
}
.part-info { flex: 1; min-width: 0; }
.part-title { font-weight: 500; word-break: break-word; }
.part-meta { font-size: 13px; color: var(--hint); margin: 2px 0 8px; }
.part.failed .part-title { color: var(--danger); }
.job-actions { display: flex; gap: 8px; margin-top: 10px; }
.job-actions .btn { flex: 1; }

/* tabs */
nav#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom); background: var(--bg); border-top: 1px solid var(--line);
}
nav#tabs button {
  position: relative; flex: 1; max-width: 190px; height: 62px; border: 0; background: none;
  color: var(--hint); font: inherit; font-size: 12px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
}
nav#tabs button.active { color: var(--accent); }
nav#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#jobs-dot { position: absolute; top: 10px; left: calc(50% + 8px); width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }

/* player + toast + lock */
.modal { position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; }
.modal video { max-width: 100%; max-height: 100%; }
.modal-close {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 14px; z-index: 1; width: 40px; height: 40px;
  border: 0; border-radius: 50%; background: rgba(255,255,255,.18); color: #fff; font-size: 26px; line-height: 1;
}
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 20; max-width: 520px; margin: 0 auto;
  padding: 12px 14px; border-radius: 12px; background: #23262b; color: #fff; font-size: 14px; text-align: center;
}
.toast.error { background: var(--danger); }
.lock { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; text-align: center; }
.lock p { color: var(--hint); }
