:root {
  color-scheme: dark;
  --bg: #070b14;
  --bg-soft: #0b1220;
  --panel: rgba(15, 23, 42, 0.86);
  --panel-solid: #0f172a;
  --panel-2: #111c33;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.28);
  --text: #e8f0ff;
  --muted: #93a7c6;
  --muted-2: #6f83a3;
  --accent: #38bdf8;
  --accent-2: #6366f1;
  --accent-3: #22c55e;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.38);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 12% -10%, rgba(56, 189, 248, 0.16), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(99, 102, 241, 0.16), transparent 55%),
    radial-gradient(800px 500px at 50% 110%, rgba(34, 197, 94, 0.08), transparent 60%),
    var(--bg);
  font-family: var(--font);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 14px 16px calc(28px + env(safe-area-inset-bottom));
}

/* ---------------- topbar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 20px;
  color: #fff;
  background: linear-gradient(145deg, #38bdf8, #4f46e5 58%, #7c3aed);
  box-shadow: 0 12px 32px rgba(56, 189, 248, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  flex: none;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: 19px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.16), transparent 45%);
  pointer-events: none;
}

.brand-mark span {
  position: relative;
  z-index: 1;
  font-size: 26px;
  line-height: 1;
  transform: translateX(2px);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.brand-mark-sm {
  width: 44px;
  height: 44px;
  border-radius: 14px;
}

.brand-mark-sm span {
  font-size: 18px;
}

.brand-mark-sm::after {
  border-radius: 13px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-name {
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-sub {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.connection-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent-3);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.12);
  transition: background 0.2s, box-shadow 0.2s;
}

.connection-dot.offline {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.14);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.6);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  color: var(--text);
  border-color: var(--line-strong);
  background: rgba(30, 41, 59, 0.72);
  outline: none;
}

/* ---------------- hero ---------------- */

.card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.hero {
  overflow: hidden;
  padding: 22px 20px 20px;
}

.hero-glow {
  position: absolute;
  top: -120px;
  right: -80px;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.22), transparent 65%);
  pointer-events: none;
}

.hero h1 {
  position: relative;
  margin: 0;
  font-size: clamp(23px, 5.4vw, 31px);
  line-height: 1.12;
  letter-spacing: -0.025em;
}

.hero-sub {
  position: relative;
  margin: 9px 0 20px;
  color: var(--muted);
  font-size: 14.5px;
}

.download-form {
  position: relative;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.url-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.text-input {
  width: 100%;
  min-width: 0;
  height: 52px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.55);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.text-input::placeholder {
  color: #5c7192;
  font-size: 14px;
}

.text-input:focus {
  border-color: rgba(56, 189, 248, 0.7);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.13);
  background: rgba(2, 6, 23, 0.78);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 14px;
  font-weight: 650;
  font-size: 15px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s, filter 0.15s, background 0.15s, border-color 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.18);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, #38bdf8, #4f46e5);
  color: #fff;
  box-shadow: 0 10px 26px rgba(56, 189, 248, 0.24);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.07);
}

.btn-paste {
  height: 52px;
  border-color: var(--line-strong);
  background: rgba(30, 41, 59, 0.68);
  color: var(--text);
}

.btn-paste:hover {
  background: rgba(30, 41, 59, 0.95);
}

.btn-paste span {
  display: none;
}

.btn-soft {
  border-color: var(--line);
  background: rgba(30, 41, 59, 0.5);
  color: var(--text);
}

.btn-soft:hover {
  border-color: var(--line-strong);
  background: rgba(30, 41, 59, 0.8);
}

.btn-danger-soft {
  border-color: rgba(248, 113, 113, 0.22);
  background: rgba(127, 29, 29, 0.18);
  color: #fca5a5;
}

.btn-danger-soft:hover {
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(127, 29, 29, 0.3);
}

.btn-sm {
  min-height: 38px;
  padding: 0 13px;
  border-radius: 11px;
  font-size: 13.5px;
}

.btn-block {
  width: 100%;
}

.options-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.select-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
}

.field-label-inline {
  color: var(--muted);
  font-size: 13px;
}

.select-input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(15, 23, 42, 0.8);
  font-size: 14px;
  outline: none;
}

.select-input:focus {
  border-color: rgba(56, 189, 248, 0.6);
}

.options-row .btn-primary {
  min-width: 140px;
  height: 48px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.hint {
  margin: 14px 0 0;
  color: var(--muted-2);
  font-size: 12.5px;
}

.hint-warn {
  color: #e7c27a;
}

.hint code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(148, 163, 184, 0.13);
  font-family: var(--mono);
  font-size: 0.95em;
}

.ios-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 11px 14px;
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: 14px;
  background: rgba(56, 189, 248, 0.08);
  color: #bfe7ff;
  font-size: 13px;
}

.ios-hint button {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

/* ---------------- jobs ---------------- */

.jobs-section {
  margin-top: 26px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 2px 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.empty-state {
  margin: 0;
  padding: 22px 18px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--muted-2);
  text-align: center;
  font-size: 14px;
}

.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.job {
  padding: 16px;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
  animation: job-in 0.22s ease-out;
}

@keyframes job-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.job-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.job-title {
  margin: 0;
  min-width: 0;
  font-size: 15.5px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.job-url {
  margin: 5px 0 0;
  color: var(--muted-2);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.badge {
  flex: none;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.badge-running,
.badge-downloading,
.badge-resolving,
.badge-processing,
.badge-retrying {
  background: rgba(56, 189, 248, 0.13);
  color: #8bdcff;
}

.badge-done {
  background: rgba(34, 197, 94, 0.13);
  color: #86efac;
}

.badge-error {
  background: rgba(248, 113, 113, 0.14);
  color: #fca5a5;
}

.badge-cancelled {
  background: rgba(251, 191, 36, 0.12);
  color: #fde68a;
}

.progress {
  position: relative;
  height: 7px;
  margin-top: 13px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  overflow: hidden;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #38bdf8, #6366f1);
  transition: width 0.45s ease;
}

.progress.indeterminate .progress-fill {
  width: 38%;
  animation: progress-slide 1.35s ease-in-out infinite;
}

@keyframes progress-slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(330%); }
}

.job-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12.5px;
}

.job-stage {
  min-width: 0;
  overflow-wrap: anywhere;
}

.job-stats {
  flex: none;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}

.job-error {
  margin: 10px 0 0;
  padding: 10px 12px;
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: 11px;
  background: rgba(127, 29, 29, 0.16);
  color: #fecaca;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.job-files {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 12px;
}

.file {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.32);
}

.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.file-name {
  min-width: 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.file-size {
  flex: none;
  color: var(--muted-2);
  font-size: 11.5px;
}

.file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 9px;
}

.file video {
  width: 100%;
  margin-top: 10px;
  border-radius: 10px;
  background: #000;
}

.job-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.job-actions:has(button:not([hidden])) {
  padding-top: 2px;
}

/* ---------------- dialog ---------------- */

.dialog {
  width: min(520px, calc(100vw - 28px));
  max-height: min(82vh, 760px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  background: #0c1526;
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  overflow: auto;
}

.dialog::backdrop {
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.dialog-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 21, 38, 0.96);
  backdrop-filter: blur(10px);
}

.dialog-head h2 {
  margin: 0;
  font-size: 18px;
}

.dialog-head .icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  font-size: 22px;
}

.dialog-section {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-section:last-child {
  border-bottom: 0;
}

.dialog-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
  letter-spacing: 0.01em;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.cookie-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.cookie-paste {
  margin-top: 12px;
}

.cookie-paste summary {
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.text-area {
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.55);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  resize: vertical;
  outline: none;
}

.text-area:focus {
  border-color: rgba(56, 189, 248, 0.6);
}

.cookie-paste .btn {
  margin-top: 8px;
}

.server-info {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px 12px;
  margin: 0 0 16px;
  font-size: 13px;
}

.server-info dt {
  color: var(--muted-2);
}

.server-info dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* ---------------- auth ---------------- */

.auth-body {
  display: grid;
  place-items: center;
  padding: 22px;
}

.auth-card {
  width: min(390px, 100%);
  padding: 30px 24px 24px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.auth-card .brand-mark {
  margin: 0 auto 16px;
}

.auth-card h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.03em;
}

.auth-sub {
  margin: 6px 0 24px;
  color: var(--muted);
  font-size: 14px;
}

.auth-form {
  text-align: left;
}

.auth-form label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.auth-form input {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: rgba(2, 6, 23, 0.55);
  font-size: 16px;
  outline: none;
}

.auth-form input:focus {
  border-color: rgba(56, 189, 248, 0.7);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.13);
}

.auth-form .btn {
  margin-top: 14px;
  height: 48px;
}

.form-error {
  margin: 10px 0 0;
  padding: 9px 11px;
  border-radius: 10px;
  background: rgba(127, 29, 29, 0.22);
  color: #fecaca;
  font-size: 13px;
}

.auth-hint {
  margin: 20px 0 0;
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1.5;
}

.auth-hint code,
.hint code {
  font-family: var(--mono);
}

/* ---------------- misc ---------------- */

.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 28px;
  color: var(--muted-2);
  font-size: 11.5px;
}

.footer-sep {
  opacity: 0.6;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: min(440px, calc(100vw - 32px));
  padding: 11px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: #111c33;
  color: var(--text);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  font-size: 13.5px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 14px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

@media (min-width: 620px) {
  .app-shell {
    padding-top: 26px;
  }

  .hero {
    padding: 26px 26px 24px;
  }

  .btn-paste span {
    display: inline;
  }

  .btn-paste {
    padding: 0 16px;
  }
}

@media (max-width: 430px) {
  .hero {
    padding: 19px 16px 17px;
  }

  .url-row {
    gap: 7px;
  }

  .btn-paste {
    flex: none;
    width: 52px;
    padding: 0;
  }

  .options-row {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .options-row .btn-primary {
    width: 100%;
  }

  .job-meta {
    flex-direction: column;
    gap: 3px;
  }

  .job-stats {
    align-self: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.badge-queued,
.badge-cancelling {
  background: rgba(148, 163, 184, 0.12);
  color: #c7d4e8;
}

.progress.is-error .progress-fill {
  background: linear-gradient(90deg, #f87171, #fb7185);
}

.progress.is-error {
  background: rgba(248, 113, 113, 0.15);
}

/* ---------------- GetCourse login ---------------- */

.gc-login,
.cookie-paste {
  margin-top: 4px;
}

.gc-login summary,
.cookie-paste summary {
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
}

.gc-login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.form-field input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: rgba(2, 6, 23, 0.55);
  color: var(--text);
  font-size: 16px;
  outline: none;
}

.form-field input:focus {
  border-color: rgba(56, 189, 248, 0.65);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
}

.gc-login-form .btn {
  align-self: flex-start;
  margin-top: 2px;
}

.muted.hint-warn {
  color: #e7c27a;
}
